Repository navigation
feat(models): add Inkling 2 Small and Mini (inkling2, inkling2_loop) - #3367
Merged
Merged
Conversation
Port the Inkling 2 text decoder, the looped Mini core with cross-pass message controllers, and the 2-D RoPE tile ViT from mlx-vlm 466069f5, and wire them into `mlxcel generate`, `mlxcel-server` and `mlxcel arch` as `ModelType::Inkling2VLM`. - Loaders for the native mixed BF16/FP32/NVFP4/MXFP8 release, the mlx-community 4-bit Transformers layout and mlx-vlm conversions; the family keeps its checkpoint dtype at load. - Each layer visit owns its KV and f32 convolution state. Sliding visits keep `L + W - 1 + 64` keys plus a zero sink row, which is equivalent to mlx-vlm's AttentionSinkKVCache (f2956e68), and trims of up to 16 tokens rewind KV and convolution state exactly or are refused without mutation. - Inkling tool-call parser for `<|content_invoke_tool_json|>` messages, streaming and non-streaming, with the recipient header held in the stream filter. - Vision tables load through `load_dense_param`, so affine-quantized tables dequantize at load. - `MLXCEL_INKLING2_LOOP_PASSES` overrides the loop count for ablations. Closes #3228
Bilingual report for the Inkling 2 Small and Mini port: design, the AttentionSinkKVCache equivalence, checkpoint layouts, the tool-call parser, and the M3 Ultra validation against mlx-vlm.
inureyes
marked this pull request as ready for review
November 23, 2026 18:00
3 of 4 tasks
inureyes
added a commit
that referenced
this pull request
Nov 23, 2026
## Summary Ports mlx-vlm's three Inkling 2 Mini Metal kernels (02053f5c, de08fdf8, 8e80d434) on top of #3367. Each is Metal-only behind `select_kernel_port`, gated in `src/models/inkling2/kernels.rs`, and falls back to the ops path, which it matches bitwise. `MLXCEL_INKLING2_KERNELS=0` turns all three off. - Fused short convolution for every `ShortConv` call (bf16, `B <= 4`, `L <= 8`, `C % 128 == 0`, kernel 4). Instead of upstream's `W - 1 + L` window it writes mlxcel's margin history directly (the newest `min(W - 1 + margin, R + L)` rows), so the trim exactness of #3367's layout is kept on both paths. - Attention head preparation (l2 clip of q/k/r, gamma-free value norm) in one launch on looped models, reading the model's f32 scales. - Grouped NVFP4/MXFP8 expert matvec, only inside a speculative verify forward of 2 to 8 tokens (`speculative_append_active`, set by `Engine::verify`). It follows MLX `qmv` lane and sum order. It also applies to `inkling-2-mini-4bit`, whose experts keep the native planes. - Inkling 2 now reports `supports_speculative_verify_rewind` and rewinds through `trim_state`, so `--prompt-lookup` runs on it and reaches the grouped kernel. A verify block keeps `max(16, L)` extra convolution rows, so a block longer than the margin can still be dropped whole. Not ported: the sconv padding-mask variants (mlxcel's conv path has no mask; padded prefill is declined) and the training/sharding gates (no such Inkling 2 path here). ## Results (M3 Ultra) | | kernels off (A) | on (B) | |---|---|---| | Native decode, tok/s, mean of 3 | 32.07 | 35.29 | | 4-bit decode, tok/s, mean of 3 | 36.81 | 44.76 | | Native verify forward, width 4 / 8, ms | 52.0 / 60.4 | 45.7 / 51.8 | Greedy 128-token output is byte-identical across arms on both checkpoints. With the speculative scope removed, so the grouped kernel does not run, width 4 / 8 takes 46.9 / 54.5 ms. That gives the grouped kernel alone -2.6% / -5.0%. No kernel is slower than the path it replaces. Details: `docs/benchmark_results/inkling2-mini-kernels-m3ultra-2026-11-24.md`. ## Test plan - [x] `--lib models::inkling2::` and `--lib inkling` (142 passed), `--lib coverage_tests` (18), serially under the GPU lock with `--profile test-fast --features metal,accelerate` - [x] New parity and gate tests in `kernel_tests.rs` and `kernel_grouped_tests.rs`, plus `tiny_tests::a_rejected_verify_block_rewinds_exactly` - [x] `cargo clippy --lib --tests --features metal,accelerate -- -D warnings`, `cargo fmt --check`, check_used_by, check_kernel_dtype_keys, check_env_var_docs, check_crate_versions, check_kernel_port_dispatch, check_binary_assets, Apache header check - [ ] Broad gate (`make verify`, `--workspace`) left to the orchestrator Closes #3359
This was referenced Nov 24, 2026
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
Adds Thinking Machines Inkling 2 in both released forms, Small (
inkling2) and Mini (inkling2_loop), asModelType::Inkling2VLM, wired intomlxcel generate,mlxcel-serverandmlxcel arch. Ported from mlx-vlm 466069f5 (the ops path; the Metal kernels are #3359).SiTU), tanh-softcapped logits trimmed to 200058.MLXCEL_INKLING2_LOOP_PASSESoverrides the pass count (documented).KVCache. A sliding visit retains at mostL + W - 1 + 64keys and attends over the newestL + W - 1plus a zero sink row, which is the key setAttentionSinkKVCachereturns. Convolution histories keep 16 extra rows, sotrim_stateup to 16 tokens rewinds KV and convolution state exactly, and a deeper trim is refused before anything is mutated.rows * colsplaceholder expansion throughvlm_runtime. Learned tables load throughload_dense_param, so the affine 4-bit export's quantized tables work.hf_quant_config.jsonNVFP4/MXFP8 experts,2688 * amax / denominatorglobal scale), the mlx-community 4-bit Transformers layout, mlx-vlm conversions. Family keeps checkpoint dtype at load. An MTP-only directory is refused by detection.ToolCallFormat::Inkling) for<|message_model|>NAME<|content_invoke_tool_json|>{json}<|end_message|>, claimed before the thinking pass, and a stream-filter header hold so the recipient never streams. A malformed invoke message yields no call and is dropped from content (the feat(tokenizer): Kimi K3 tiktoken family and native XTML renderer #1743 rule, so streamed and non-streamed agree) rather than kept as text. Inkling 1's template emits the same marker, so it benefits too.PerRowFallback, pinned in the coverage list); padded prefill is declined.Validation (M3 Ultra, 512 GB, vs mlx-vlm 466069f5)
image_urlget_weathertool_calls, streaming and non-streaming, emptydelta.content; tool-result turn answers correctlyNarrow selectors (serial,
--profile test-fast --features metal,accelerate):inkling2(26),server::tool_calls(506),inkling(129),coverage_tests(18),models::detection(97),models::registry(21),model_metadata,model_type,loaded_model,memory_estimate.cargo clippy --lib --tests --features metal,accelerate -- -D warnings,cargo fmt --checkand thescripts/cicontract checks pass.Not included
is_varloop.Closes #3228