Skip to content

Inkling2Loop: load the community MLX bundles - #782

Merged
jjang-ai merged 1 commit into
mainfrom
fix/inkling2-bundle-compat
Nov 22, 2026
Merged

jjang-ai merged 1 commit into
mainfrom
fix/inkling2-bundle-compat

Conversation

@jjang-ai

Copy link
Copy Markdown
Contributor

Community Inkling-2-Mini bundles fail to load in the app:

Error: Unhandled keys ["experts"] in model.layers.0.mlp in Inkling2LoopModel.Inkling2LoopModelInner.Inkling2DecoderLayer.Inkling2MoE

(reproduced in a dev build of Osaurus main with mlx-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:

Layout Bundles (examples) What differs
mlx-lm port (ml-explore/mlx-lm#2086) mlx-community 4bit, pipenetwork, araysuter, hermitdave, InterpreticAI, nace-ai model.language_model.*; experts mlp.experts.{gate_up_proj,down_proj} (w13 row order kept) as native NVFP4/MXFP8 with global_scale, or re-quantized affine 2-8 bit; quantized attention / embed / lm_head
mlx-vlm nativ-community nvfp4, netprojects, VisualInference, baytizzel language_model.model.*; experts split into switch_mlp.{gate,up,down}_proj with weight_scale_2; mlp.gate_weight, q_scale, rel_proj, *.conv.weight, message_queries
separate experts pgmharikrishnan official names, switch_mlp.{gate,up,down}_proj affine
fused projections mlx-community -mtp bundles attn.in_proj row concatenation, loop_down / loop_gain_forget, router_weight, [C, K] taps

sanitize now brings every layout to this model's tree, so the fused decode, verify and dSpark paths see one layout:

  • Routed experts. 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 packed widths), never off a converter's config. That matters: mlx-community/Inkling-2-Mini-4bit declares 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: MLX global_scale / 2688, ModelOpt weight_scale_2. gate and up with different factors are refused, not fused wrong.
  • Affine expert speed. MLX's affine gather has no fast kernel for fp32 activations with bf16 scales (k = 8: 699 vs 301 us); affine experts now gather in the scale dtype. A 4-bit affine bundle decodes 18.9 -> 40 tok/s.
  • Quantized dense layers are dequantized at load (bits / group from this model's own shapes), so the fused decode path runs unchanged. runtimeQuantizedDenseLayers lists 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).
  • dSpark. Every community mtp.safetensors is the official file (same 54 tensors, dtypes and shapes); it loads as before. A bundle that declares mtp_config without 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:

Bundle top-1 short top-1 long KL median long greedy short
thinkingmachines (official, regression) 31/31 31/31 1.5e-3 32/32
mlx-community 4bit 31/31 30/31 1.0e-2 32/32
araysuter 4bit (affine experts) 31/31 30/31 7.6e-3 32/32
nativ-community nvfp4 (mlx-vlm) 31/31 31/31 1.5e-3 32/32
pgmharikrishnan 4bit (separate experts) 31/31 30/31 9.6e-3 32/32
mlx-community fused-projection 4bit 31/31 31/31 1.6e-3 32/32

(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 (main repinned 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-4bit and 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 stock main build 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) and Inkling2FusedKernelTests pass.

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.

…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.
@jjang-ai
jjang-ai merged commit 8dd3139 into main Nov 22, 2026
7 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant