Repository navigation
feat(inkling2): load Inkling 2 checkpoints saved by mlx-vlm - #5605
Merged
Merged
Conversation
mlx-vlm's inkling2 model (inkling2 and inkling2_loop) saves checkpoints under its own module names with split tensors, for example orcarouter/Inkling-2-Mini-abliterated-MLX, and the Inkling 2 loader only mapped the published layout, so they failed with "parameters not in model". Undo mlx-vlm's sanitize in the loader: fuse the attention projections along their rows (quantizing the unquantized sink and dynamic conv rows to the fused spec), re-interleave gate/up into w13, convert weight_scale_2 back to global_scale, and map message queries and vision names. Rewrite the per-module quantization keys onto the runtime paths in load_config so nn.quantize builds matching modules. Published-layout checkpoints and oQ outputs keep their paths. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
penta2himajin
force-pushed
the
feat/inkling2-mlx-vlm-layout
branch
from
November 24, 2026 09:53
ea999c4 to
70e40e3
Compare
Mixed-precision mlx-vlm builds can quantize the rows that the runtime fuses at different affine bits; the orcarouter 12GB build has 2-bit gate and 3-bit up in 10 layers. Let a fused module take the widest affine spec among its rows when they share a group size, and re-pack narrower codes at that width with their scales and biases unchanged, which keeps the weights exactly. Other mixes still raise. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
penta2himajin
marked this pull request as ready for review
November 24, 2026 10:46
jundot
approved these changes
Nov 25, 2026
jundot
left a comment
Owner
There was a problem hiding this comment.
I merged main into the branch and pushed a smaller version that keeps your mapping logic as it is. The tests moved into test_oq.py and now use the sanitize from the pinned mlx-vlm instead of a copy. Thank you for adding this, merging.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This adds loading support for Inkling 2 checkpoints (
inkling2andinkling2_loop) saved by mlx-vlm'sinkling2model (added in Neywa-Labs/mlx-vlm#2778; checked againstd998a62). Published-layout checkpoints and oQ outputs keep their current loading paths.mlx-vlm renames the published checkpoint and splits its fused tensors, so these builds ship
language_model.model.layers.N.self_attn.q_proj,mlp.switch_mlp.{gate,up,down}_proj,vision_tower.layers.N.mlp.fc1and so on. The Inkling 2 loader maps only the publishedmodel.llm.*layout, so they fail withReceived 1849 parameters not in model: language_model.lm_head.biases, .... Example: orcarouter/Inkling-2-Mini-abliterated-MLX.loader.py:sanitize_weightsdetectslanguage_model.model.layers.*keys and undoes mlx-vlm'sModel.sanitize(mlx_vlm/models/inkling2/inkling2.py atd998a62):in_proj(sliding) orq_proj/k_proj/v_proj(global). Quantized codes are row-local, so quantized parts are concatenated as they are. Unquantized parts that share the fused module (the attention sink, the global layers' dynamic conv projections) are quantized to the fused module's spec first.switch_mlp.gate_proj/up_projare re-interleaved intow13(mlx-vlm splits even/odd rows), andweight_scale_2(amax / denominator) is converted back to the runtime'sglobal_scale(amax). Gate and up must carry the same outer scale; the loader raises otherwise.qstands forscale * q + biasat any width, so the weights stay the same. The source width comes from the tensor shapes and the target from the config. Rows with a different group size or mode raise. (Inkling Small's compat path leaves a layer unfused when its Q/K/V/R specs differ; the Inkling 2 runtime always fuses, so the loader re-packs instead.)message_queriesalready holds each core layer's rows in the runtime's (attn, k, v, mlp) order; the vision tower names go back underbackbone.model_loading.py:normalize_inkling2_mlx_vlm_quantrewrites the per-modulequantizationkeys onto the runtime module paths beforeexpand_per_layer_quant_keys, sonn.quantizebuilds the fused modules and the expert carriers with the checkpoint's specs. Modules that the runtime fuses take the widest of their affine specs when they share a group size, and raise otherwise. It only acts while the keys still name mlx-vlm's modules (self_attn,switch_mlp), so running it again on a rewritten config is a no-op.Why only Inkling 2. Other VLMs run on mlx-vlm's own model classes (or the vendored compat copies), so mlx-vlm checkpoints already match their parameter trees. Inkling 2 is the one family served by oMLX's own module through the VLM engine adapter, with its fused layout, and the mapping is specific to that layout.
Out of scope. mlx-community/Inkling-2-Mini-4bit is saved in the layout of ml-explore/mlx-lm#2086 (
model.language_model.*, fusedgate_up_proj). It fails withReceived 1556 parameters not in modelon 0.8.2 and onmain, and fails the same way with this PR. I left it out since that layout is still under review.Validation
Tests (
tests/test_inkling2_mlx_vlm_layout.py): the tiny Inkling 2 source fromtest_oq.py, rewritten by a fixture that mirrors mlx-vlm's sanitize atd998a62.global_scaletortol=1e-6.mx.quantizeof the runtime's fused BF16 weight, including the sink and dynamic-conv rows.w13/w2dequantizing exactly to the source rows.language_model.-prefixed key variants) leaves it unchanged.Without the fix, the load tests fail with
Received 218 parameters not in model. The default suite (python -m pytest -n 8): 19,446 passed, 1 failed. The failure,test_torch_stub.py::test_xgrammar_imports_against_stub_only, fails the same way onmainhere because xgrammar is not installed. I ran the tests on the oMLX 0.8.2 app bundle's Python and packages (same MLX / mlx-lm / mlx-vlm pins asmain) plus pytest, not throughmake dev.Control run on M3 Pro 36 GB, MLX 0.32.4:
main(8515583f) and this PR, each served from source with the prefix cache off, greedy,reasoning_effort=low, two prompts (Japanese prose, Python code) × 256 tokens.mainmainon both promptsReceived 1849 parameters not in modelReceived 1556 parameters not in modelReal model through the server: both orcarouter builds load and generate coherent Japanese and English text and code. The 16GB build has mixed NVFP4 / 4-bit affine experts; the 12GB build has 2- to 4-bit affine experts, with gate and up at different bits in 10 layers. On the 16GB build with Lightning MTP on, the bundled DSpark drafter (
mtp.safetensorsfrom the official release) loads against the converted target and its drafts are accepted (fixed depth 7: 69% on code, 38% on Japanese prose, 56% on English prose, 75% on rewriting given code).With other features (both orcarouter builds, and mlx-community/Inkling-2-Mini-oQ4e-mtp as the control; greedy, 200 tokens, a Japanese prose prompt and a code-edit prompt):
main.Agreement with mlx-vlm
d998a62, with the officialthinkingmachines/Inkling-2-Minicheckpoint as the control (both implementations load it without any conversion):The vision gap and the 12GB build's text gap match the control, so they lie between the two implementations rather than in this mapping. The 16GB build's text KL is above the control. Rounding the sink and dynamic-conv rows to 8 bits on the mlx-vlm side as well (what this PR does to them) only brings it to 0.0047, and I have not found the rest.
Image input: both builds answer three synthetic images correctly through the server (the colors of the left and right halves, the text "OMLX 4721", three green circles), the same as the oQ control.
Not tested: plain
inkling2checkpoints saved by mlx-vlm (only the unit tests cover them; Inkling 2 Small does not fit in 36 GB), and oQ re-quantization of mlx-vlm-layout sources.Checklist
🤖 Generated with Claude Code