Repository navigation
Inkling2Loop: load the community MLX bundles - #782
Merged
Merged
Conversation
…projection, separate-expert layouts)
Community Inkling-2-Mini bundles failed with `Unhandled keys ["experts"] in ...Inkling2MoE`
(model.layers.0.mlp): their routed experts, router and some attention tensors use other names,
encodings and packings than the official checkpoint. sanitize now brings every layout to this
model's tree, so the fused decode, verify and dSpark paths see one layout:
- Routed experts: mlx-lm `mlp.experts.{gate_up_proj,down_proj}` (w13 row order kept), mlx-vlm
`switch_mlp.{gate,up,down}_proj` (gate/up re-interleaved), fused-projection `experts.{w13,w2}`.
The expert linear reads its format off the tensors (uint8 scales: NVFP4 per 16 / MXFP4 per 32
/ MXFP8; float scales: affine, bits and group from the widths) and takes affine biases. NVFP4
per-expert factors: MLX `global_scale / 2688`, ModelOpt `weight_scale_2`. gate and up with
different factors are refused rather than fused wrong.
- Affine experts run their gather in the scale dtype: MLX has no fast kernel for fp32
activations with bf16 scales (699 vs 301 us for k = 8); decode 18.9 -> 40 tok/s on a 4-bit
affine bundle.
- Quantized dense layers (attention projections, embed, lm_head, sink, sconv taps) are
dequantized at load, bits and group taken from this model's own shapes (a converter's
config can be stale: one bundle declares affine 4-bit for MXFP8 experts).
`runtimeQuantizedDenseLayers` names the layers a quantized decode path keeps quantized
(empty here).
- mlx-vlm names (`language_model.model.*`, `mlp.gate_weight`, `q_scale`, `rel_scale`,
`rel_proj`, `*.conv.weight`, `message_queries`) and the fused-projection layout (`in_proj`
row splits, loop controllers, [C, K] taps, `router_weight`) map onto the tree.
- A declared drafter without `mtp.safetensors` leaves dSpark off; the shipped drafter files are
the official ones and load as before.
Tests: Inkling2BundleLayoutTests (row order vs the official interleave, factors, refusals,
format inference, affine gather vs dense, bit-exact dense dequant, mlx-vlm names,
fused-projection round trip). M5 Max, teacher-forced vs the BF16 reference: official 31/31 and
31/31; mlx-community 4bit 31/31, 30/31; araysuter 4bit 31/31, 30/31; nativ nvfp4 31/31, 31/31;
pgm 4bit 31/31, 30/31; mlx-community fused-projection 4-bit 31/31, 31/31. dSpark drafts on the official, nativ and fused-projection
bundles (acceptance 0.54-0.74) and stays off on bundles without the drafter file.
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.
Community Inkling-2-Mini bundles fail to load in the app:
(reproduced in a dev build of Osaurus
mainwithmlx-community/Inkling-2-Mini-4bit, the most downloaded MLX conversion). The runtime only knew the official checkpoint's layout. The MLX conversions on the Hub use four others:model.language_model.*; expertsmlp.experts.{gate_up_proj,down_proj}(w13 row order kept) as native NVFP4/MXFP8 withglobal_scale, or re-quantized affine 2-8 bit; quantized attention / embed / lm_headlanguage_model.model.*; experts split intoswitch_mlp.{gate,up,down}_projwithweight_scale_2;mlp.gate_weight,q_scale,rel_proj,*.conv.weight,message_queriesswitch_mlp.{gate,up,down}_projaffine-mtpbundlesattn.in_projrow concatenation,loop_down/loop_gain_forget,router_weight,[C, K]tapssanitizenow brings every layout to this model's tree, so the fused decode, verify and dSpark paths see one layout:mlx-community/Inkling-2-Mini-4bitdeclares affine 4-bit and no overrides, yet its layer 20-23 experts are MXFP8. Affine experts take their biases. gate/up rows always end up in the official interleaved order (mlx-lm keeps it; mlx-vlm's split is re-interleaved). NVFP4 per-expert factors: MLXglobal_scale / 2688, ModelOptweight_scale_2. gate and up with different factors are refused, not fused wrong.runtimeQuantizedDenseLayerslists the layers a quantized-projection decode path keeps quantized (empty here; Inkling-2-Mini JANGH bundles: codebook routed experts, affine trunk, dSpark #781 fills it).mtp.safetensorsis the official file (same 54 tensors, dtypes and shapes); it loads as before. A bundle that declaresmtp_configwithout shipping the file leaves dSpark off and decodes plainly.Proof
Teacher-forced against the BF16 reference (31 steps, short and 2.3k-token prompts), M5 Max:
(the same-run chunking control on the official checkpoint is KL median 2.3e-3; the 4-bit-dense bundles sit above it by their own quantization.)
dSpark drafts on the official, nativ-community and fused-projection bundles (acceptance 0.54-0.74) and stays off, without error, on bundles that ship no drafter.
In a dev build of Osaurus (
mainrepinned to this branch), driven through the GUI on M5 Max:mlx-community/Inkling-2-Mini-4bit, the fused-projection 4-bit bundle,araysuter/Inkling-2-Mini-MLX-4bitand the official checkpoint each loaded and ran a cold prose turn, a second chat, a pasted 10k-token document, a tool call with its continuation, a follow-up, and a relaunch, with no load error. Prose decode 45-55 tok/s; the tool continuation restored at the tool boundary and the relaunch restored the system prefix from disk. The stockmainbuild shows the error above on the same bundle.Tests:
Inkling2BundleLayoutTests(expert row order against the official interleave, per-expert factors, mismatched-factor refusal, format inference, affine gather against the dense product, bit-exact dense dequantization, mlx-vlm names, fused-projection round trip) andInkling2FusedKernelTestspass.Not covered yet: affine experts still run MLX's gather (about 40 tok/s against about 55 for NVFP4 bundles; a batch-1 affine kernel like the NVFP4 one would close it); unquantized (BF16) routed experts are logged and skipped.