Repository navigation
Conversation
Text and image input, with Metal kernels for the prefill attention and the attention residuals. The published checkpoint loads as is, and tensor and pipeline parallel work.
Split the model file into config, layers, vision, checkpoint and model modules, and move the processor and the two kernels into the package. The processor now returns a dict of inputs, as load_processor expects, and the image rows use the shared splice. The model code is otherwise unchanged.
|
Thanks for this. I'm running the PR head ( As far as I can tell, there's no tool parser for Inkling's format in Would it be in scope to add an |
I confirm - same behavior on MacBook Pro M1, 32 Gb RAM. No tool calls. If it helps here is the log line that appears on |
…ernels a visit, walked grammars and typed tool calls Thinking Machines' Inkling-2-Mini (model_type inkling2_loop) as locals/models/inkling2_loop.py (the reference, parameter names of ml-explore/mlx-lm#2086), locals/inkling.py (the fused step, passes over 2 to 16 tokens of one text, rewind for drafts) and locals/convert_inkling.py (a 15.6 GB build for a 24 GB Mac from the 19.5 GB release). On an M4 Pro with 24 GB against stock MLX on the same build: 34.5 tokens/s for one request (17.1), 54 / 72 / 82 for 2 / 4 / 8 at once (30 / 50 / 48), 45 to 50 on a turn with tools (17), and `locals run`'s two-file task with 4 slots in 55 s (170 s, two agents out of GPU memory). For agents: the reply format (formats.Inkling) with its markers as tokens in grammars and forced spans, prompts in chunks of 256, checkpoints from 192 tokens, spans and drafts in one pass for a request alone, grammars walked instead of token tables (1.7 GB a set of tools), tool calls typed by the tools' schemas, and the checkpoints' window copies counted in admission. tests/test_parked_rows.py's "no span" case fails on this Mac before and after this commit. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
just added PR on top with some perf gains I found re conversion in and out of fp32, btw - see jundot#4 |
Thinking Machines' Inkling 2 Mini (inkling2_loop: 26.4B, 3.4B active, 24 layers run as 48 visits a token) runs from its released checkpoint or from mlx-lm's layout (ml-explore/mlx-lm#2086), matching mlx-lm's model (KLD 0.003 on the 8-bit pack). - src/plugins/inkling2: the looped forward with depth attention in place of the residual, RoPE-free relative-bias attention with sinks, short convs, the sigmoid-routed MoE over NVFP4/MXFP8 or affine banks; images (its tower and merger); the bundled DSpark draft head on greedy and sampled requests (Metal, Apple9+); batched decode; sliding visits keep a ring of window + 2048 rows. - Metal kernels for the one-row visit, a verify and batched slots (pre, prep, mid, norm, router, topk, gate, gated, state, act, ups, downs, sum, oproj, relmask, relattn, relsplit, relcomb, relslots, the Markov drafter); 14 registered with the kernel contract. On CUDA the op chain serves. - Engine: native drafter rounds get the request's stop ids (Forward.stop_ids), say whether their load drafts (NativeDrafter.active), and serve sampled requests (verify/finish). - Fixes for every model: an auto context leaves the hot cache the share it was sized beside (32 GB Macs re-prefilled every long turn); --os-reserve-gib reaches admission under -Dunits; logprobs stay valid JSON for non-finite values; Inkling templates get the client's effort word; an Inkling reply cut right after its message opener ships no marker. - tests/convert_inkling2.py (mlx-lm-layout packs, optional affine experts) and tests/inkling2_kld.py (KLD against the release). - App: Inkling 2 in the supported list; Enhance on an image edit shows the source picture; 26.11.4.
|
Thanks for this PR. I've been running the PR head ( 1.
|
| Generated message | OpenAI field |
|---|---|
<|message_model|><|content_thinking|>…<|end_message|> |
reasoning_content |
<|message_model|><|content_text|>…<|end_message|> |
content |
<|message_model|>NAME<|content_invoke_tool_json|>{"name":…,"args":{…}}<|end_message|> |
tool_calls (args → JSON-string arguments, plus an id) |
Generation ends at <|content_model_end_sampling|> (the EOS), which doesn't appear in the text. When there's at least one tool call, finish_reason should be tool_calls.
For streaming, the parser is a small state machine (outside / header / body). It holds back any incomplete <|… until the closing |> arrives, since markers can be split across chunks. Thinking and text deltas are forwarded as they arrive. A tool call is emitted whole when its <|end_message|> arrives. I tested it by feeding the same output in chunks of 1, 2, 3, 7 and 13 characters, and every chunking gave identical results.
# Condensed; error handling (e.g. invalid tool JSON) omitted.
def feed(self, text):
events, self.buf = [], self.buf + text
while self.buf:
i = self.buf.find("<|")
if i == -1: # no marker: emit, but keep a trailing "<"
keep = "<" if self.buf.endswith("<") else ""
self._text(self.buf[: len(self.buf) - len(keep)], events); self.buf = keep; break
if i:
self._text(self.buf[:i], events); self.buf = self.buf[i:]
j = self.buf.find("|>", 2)
if j == -1:
break # marker split across chunks: wait for more
tok, self.buf = self.buf[: j + 2], self.buf[j + 2:]
if tok == "<|message_model|>":
self.state, self.kind, self.header, self.tool = "header", None, "", ""
elif tok.startswith("<|content_") and self.state == "header":
self.state, self.kind = "body", tok[len("<|content_"):-2] # thinking | text | invoke_tool_json
elif tok == "<|end_message|>":
if self.kind == "invoke_tool_json":
obj = json.loads(self.tool)
events.append(("tool_call", obj.get("name") or self.header, obj.get("args", {})))
self.state, self.kind = "outside", None
else:
self._text(tok, events)
return events
# _text routes by state: header -> tool name; thinking -> reasoning; invoke_tool_json -> buffer; else -> contentRequests needed no changes beyond the usual. Sending back an assistant message with tool_calls and then a tool message renders correctly with the bundled chat template, and the model answers from the tool result. With this, both streaming and non-streaming agent loops work: tool call → tool result → final answer.
Two other things anyone running this with agents should know:
mlx_lm.serverdefaults to--max-tokens 512and--temp 0.0. The model'sgeneration_config.jsonhastemperature: 1.0(the GGUF metadata also hastop_k: 50). 512 tokens cuts off agent turns, so I run with--max-tokens 32768 --temp 1.0 --top-k 50.- Prefix caching works when the conversation is appended to, which is the agent case. A request that shares a long prefix but changes the last message gets no cache hit, presumably because the looped layers' caches can't be trimmed.
I'm happy to open a PR against your branch with a model-specific output parser for the server if that would help.
3. Numbers (M5 Pro, 48 GB)
These compare 4-bit MLX (this PR, kernels on) with Q8_0 GGUF on llama.cpp master (c622f623f, -fa on -b 2048 -ub 512). The quantizations differ, so it isn't a strict apples-to-apples comparison. The prompt was 31,187 tokens.
| llama.cpp | MLX (this PR) | |
|---|---|---|
| Cold prompt (time to first token) | 122.0 s (256 tok/s) | 37.5 s (~830 tok/s) |
| Appended agent turns (time to first token) | 0.7–1.0 s | 0.5–0.6 s |
| Generation | 24.9 tok/s | 28.7 tok/s |
| Resident memory | 30.5 GB | 17.4 GB |
On llama.cpp, Inkling's compute buffer grows sharply with -ub: at 64k context it's 6,646 MiB at -ub 512, 13,296 MiB at -ub 1024 and 26,604 MiB at -ub 2048 (the last one doesn't fit on 48 GB). Larger ubatches weren't any faster anyway, so MLX is the better option on 48 GB machines right now.
This comment was AI-generated with Claude Code. The tests and benchmarks above were run on my machine.
…kling2_loop arch)
The public checkpoints declare their quantization, so load_model sets up the experts and sanitize only maps the tensors. load_model also reads fp8 with 1x32 ue8m0 blocks as mxfp8, as in Inkling-2-Small-MXFP8.
Inkling 2 Mini is a looped Inkling 2 model. Co-authored-by: Pedro Cuenca <pedro@huggingface.co>
0c4c991 to
baf42e4
Compare
…p (from bf16) - 2-3% faster prefill and 1.5-2% faster decode
Pin mlx-lm to the reviewed head of ml-explore/mlx-lm#2086, which adds the inkling2_loop architecture. Port ToolCallSplitter to the new TextStateMachine reader API from unreleased mlx-lm main. Document Inkling's limits: no tool calls, reasoning in content, no prompt-cache reuse across turns.
Inkling 2 Mini logits before and after the rebaseMeasured November 22, 2026 · MLX-LM PR #2086 MLX-LM commits Given the same token history at each position, Results by inputEach row error is the largest absolute logit difference across the vocabulary at one input
The comparison with native Transformers covered only a small random checkpoint, where the native |
…annot build, before the download (#19003) Fixes #18972. ## What happened Loading `mlx-community/Inkling-2-Mini-4bit` on Apple Silicon downloads about 17 GB, then fails with: ``` Failed to load model: Model type inkling2_loop not supported. Error: No module named 'mlx_vlm.speculative.drafters.inkling2_loop' ``` Both lines in the report come from one call, mlx-vlm's `get_model_and_args`. It looks for the model type in `mlx_vlm.models` and then in `mlx_vlm.speculative.drafters`, and the ImportError it appends is from that second lookup. Studio never tried to load an Inkling drafter here. Studio's own drafter checks (`mlx_speculative.has_builtin_head`, unsloth-zoo's `_native_mtp_head`) already catch import errors, and they look for MTP weights, which this checkpoint does not ship (its README says the DSpark draft is not included). The real problem is that no released mlx-vlm or mlx-lm can build `inkling2_loop`: - mlx-vlm 0.8.0 (2026-11-16) is the newest release and Studio's ceiling (`studio/install_python_stack.py` `_MLX_VLM_SPEC = "mlx-vlm>=0.6.4,<=0.8.0"`, same range in `utils/mlx_repair.py`). It has `models/inkling2` from Neywa-Labs/mlx-vlm#2738, which covers Inkling 2 Small (`model_type: inkling2`). It has no `inkling2_loop` entry in `MODEL_REMAPPING`. - Mini support (`"inkling2_loop": "inkling2"`) came in Neywa-Labs/mlx-vlm#2778, merged 2026-11-20, after 0.8.0. It is on main and not released yet. - mlx-lm: no release has Inkling. The checkpoint was converted with ml-explore/mlx-lm#2086, which is still open, and the model card says to install that PR branch. So a pin bump cannot fix this today. ## Change - New `core/inference/mlx_model_support.py`. It reads `config.json` and checks whether the installed mlx-vlm (`get_model_type`, falling back to `MODEL_REMAPPING`, then a `find_spec` in both packages its loader searches) or mlx-lm (`model_package`, falling back to `MODEL_REMAPPING`) has a module for the checkpoint's architecture. If the check can't decide (no config, a checkpoint-local `model_file`, a library that won't import, a resolver that raises), it returns None, so it never blocks a load. - `MLXInferenceBackend.load_model` runs this check right after the GGUF guard. That is before `FastMLXModel.from_pretrained`, so nothing is downloaded. When neither library has the architecture, the load fails with: > mlx-community/Inkling-2-Mini-4bit uses the 'inkling2_loop' architecture, which the MLX runtime in this Unsloth install (mlx-vlm 0.8.0, mlx-lm 0.32.2) cannot load. Inkling 2 Mini cannot run on MLX in Unsloth yet: it needs a newer mlx-vlm than the one installed. Use the GGUF build instead: unsloth/Inkling-2-Mini-GGUF. Other architectures get a generic hint instead (update later, or use a GGUF build). - `routes/inference.py` `_maybe_unsupported_message` also rewrites the libraries' own `Model type X not supported` error into the same message. This covers loads where the check could not decide. The text avoids `_NOT_SUPPORTED_HINTS`, so the route does not wrap it again. - When an mlx-vlm that maps `inkling2_loop` is installed, the check passes and the load goes ahead. I checked this against mlx-vlm main at 36565bc1. The model hub does not list or recommend this MLX repo, so nothing changes there. ## Tests `studio/backend/tests/test_mlx_model_support.py` (16 tests, run on Linux with fake `mlx_vlm.utils` / `mlx_lm.utils`): - refused on 0.8.0's registry, with and without the newer resolver functions; accepted once `inkling2_loop` is remapped - Inkling 2 Small, an mlx-lm remap and a plain mlx-lm type are not refused - configs the check cannot decide on, and libraries that fail to import or raise, are never refused - message content, and the route passing it through unwrapped - the route rewriting both the mlx-vlm and the mlx-lm wording - `load_model` refusing before the loader is called One fixture in `test_mlx_inference_backend.py` (`_text_family_backend`) stubs a loader that builds a made-up family (`mm_family`). It now also stubs the new check. Base (b3ecd8d) vs head, same host, failing test IDs compared: | Suite | base | head | |---|---|---| | Linux, no MLX (37 related backend test files + new file) | 17 failed: the 16 new tests + `test_each_plain_helper_stub_matches_zoos_body` | 1 failed: `test_each_plain_helper_stub_matches_zoos_body` (fails on base too) | | Linux, real mlx 0.32.4 / mlx-vlm 0.8.0 / mlx-lm 0.32.2 CPU wheels (`test_mlx_inference_backend.py`) | 8 failed | same 8 IDs failed (all present on base), new file 16/16 | The real-library check also runs over every model type installed mlx-vlm 0.8.0 / mlx-lm 0.32.2 ship (315 module and remap names) and refuses none of them. ## Apple Silicon macos-15 staging run, real mlx 0.32.4 / mlx-vlm 0.8.0 / mlx-lm 0.32.2 on Metal, real `config.json` of the reported repo. Only unsloth-zoo's `FastMLXModel` (the step that downloads and builds the weights) is a recorder: | | base (b3ecd8d) | head | |---|---|---| | mlx-vlm 0.8.0 on the real config | `Model type inkling2_loop not supported. Error: No module named 'mlx_vlm.speculative.drafters.inkling2_loop'` | same (library behaviour) | | Studio `load_model` | reaches the loader, so the download starts, then raises the raw error | refused before the loader is called | | What the load route returns | `Failed to load model: Model type inkling2_loop not supported. Error: No module named ...` (exactly what the reporter saw) | `Failed to load model: mlx-community/Inkling-2-Mini-4bit uses the 'inkling2_loop' architecture ... Use the GGUF build instead: unsloth/Inkling-2-Mini-GGUF.` | | Every installed model type checked (315) | n/a | 0 refused | | `test_mlx_model_support.py`, `test_mlx_inference_backend.py`, `test_mlx_speculative.py`, `test_unsupported_hint_reads_only_our_diagnosis.py` | 16 failed (the 16 new tests), 607 passed | 623 passed, 0 failed | Device was `Device(gpu, 0)` on both arms. Not covered: a real end-to-end load of the 17 GB checkpoint (it does not fit a hosted macOS runner). Also, Studio cannot serve Inkling 2 Mini on MLX until a released mlx-vlm maps `inkling2_loop` and the pin ceiling is raised. That is a follow-up once mlx-vlm releases.
Lab-passed recipe (all six gates, on a clean build of the launch): decode 40.2 tok/s, prefill 411 tok/s, context 58213 recalled from a 184,730-token prompt. - registry/cards/apple/apple-m4-max-64gb.json: the 64 GB M4 Max card (hardware sheet exists). - registry/models.json: inkling-2-mini model and its MLX 4-bit build. - registry/launches/mlx-lm-inkling-2-mini-4bit-256k.json + mlx-lm-inkling2-serve.py: mlx_lm.server from ml-explore/mlx-lm#2086 (pinned commit), with Inkling 2's response format (reasoning, tool calls), /v1/token/encode, and decode-only mx.compile fusion (+15-20% decode vs interleaved controls). - registry/recipes/apple/apple-m4-max-64gb/inkling-2-mini.mlx-lm.256k.json: written by lab.py try. - data/lab-runs/: the gate run. data/sources/inkling2-mini-m4-max-64gb-mlx/: hill-climb log, ceilings, ledger, tools, clean-build evidence, needles at 102K and 242K tokens. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Inkling 2 needs an mlx-lm with ml-explore/mlx-lm#2086, which no release has yet. Newer mlx-lm also moves the qwen3_5 classes the Prism (Bonsai) packs import, so mlxh's own environment stays on mlx-lm 0.31.3 and Inkling workers run from a private runtime pinned to the reviewed commit e2b5bbd (`mlxh inkling install`, offered on pull, refreshed by update). The image runtime's staged installer is generalized to serve both. Inkling's tagged messages map onto the existing reasoning split and tool-call path: thinking off asks for no effort, tool calls become the XML parse_tool_calls reads (values escaped so they round-trip), marker-shaped text is kept, and tool results keep tool_call_id/name so the template can name them.
Stacked on #2061.
This adds support for Inkling 2 Mini, a looped Inkling 2 model. It runs a group of middle layers three times for each token, and each repeat has its own cache.
M3 Ultra with 512 GB.
Benchmark script
The kernels are off when inkling2.layers._use_kernels returns False. The prompt text is Moby-Dick from Project Gutenberg.
Model information
Supported checkpoints
Verification
mlx_lm.generate --model thinkingmachines/Inkling-2-Mini -p "The secret to baking a good cake is" -m 1024