Skip to content

Add Inkling 2 - #2738

Merged
Blaizzy merged 14 commits into
mainfrom
pc/inkling2-distributed
Nov 15, 2026
Merged

Blaizzy merged 14 commits into
mainfrom
pc/inkling2-distributed

Conversation

@Blaizzy

@Blaizzy Blaizzy commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Adds native text and image inference for thinkingmachines/Inkling-2-Small, including its bundled DSpark head and a target model shared across two Macs. The loader preserves the checkpoint's mixed BF16/FP32 dense parameters and native NVFP4/MXFP8 expert weights.

Implementation

  • Add the language model, vision encoder, processor, checkpoint loading and model/processor regression cases.
  • Partition experts and compatible attention heads, output rows and cache state across ranks. Preserve full projection geometry at every length for numerical agreement across GPUs, and stop gradients through discrete router indices.
  • Integrate expert ownership checks with cluster preflight and honor the configured worker prefill budget.
  • Load the bundled mtp.safetensors through the standard drafter API; support captured target features, chunked prefill, transactional rollback and greedy draft-request distribution across ranks.
  • Share Mistral Large 4's native-reduction kernels, optimize masked expert routes and cache commits, and add draft controls to the distributed generation example.
  • Keep the conversion module importable on Python 3.10 while preserving the callable package-level convert(...) API and its signature.

Shared-model performance

These measurements predate extending projection padding to short decode batches for parity across GPUs. Throughput has not been remeasured with that portability fix.

Measured on two 512 GB M3 Ultras over JACCL/RDMA: one target model partitioned across the machines, with no complete target replica on either Mac. Each request has 1,025 input tokens and 128 output tokens, greedy sampling, fresh caches and a 128-token per-row prefill chunk. The draft stays resident in both modes. Results are medians of three measured repetitions after warmup, using the slower rank and counting each logical token once.

Batch DSpark off decode tok/s DSpark on decode tok/s Draft block Speedup
1 16.87 24.78 8 1.47x
4 43.28 62.54 3 1.45x

Batch-four DSpark repetitions were 62.54, 62.80 and 61.39 aggregate tok/s. Including prefill, batch-four throughput is 25.06 tok/s with DSpark versus 21.15 without; median TTFT is 12.34 versus 12.45 seconds. Peak allocation is approximately 205 GB per Mac, with no swap growth or new swap-outs.

Validation

  • Hosted CI passes on d8bd1443, including all 40 distributed-model tests, the existing BF16 parity cases and all four test suites. Lint and commit-signature checks pass.
  • Local Python 3.10 / MLX 0.32.4 suite: 7,586 passed, 52 skipped, 302 subtests passed, plus all 40 distributed-model tests passed in a separate run. The regression fixes leave every test and CI workflow unchanged. The existing BF16 projection, conversion, router, cache and supervisor checks pass; compiled router backpropagation also produces finite nonzero gradients.
  • Distributed CLI --help smoke check and formatting hooks pass. Feature commits, fixes and the integration merge are signed; git diff --check passes.
  • Released-weight validation before the projection portability fix preserved the previous MLX implementation exactly across 4,182 aligned positions per rank, including the 1,025-token input, larger verification blocks, ragged acceptance, abort and row filtering. Logits, captured states, owned cache slices and draft proposals matched; another 144 real-weight expert checks passed per rank.
  • Two-Mac cluster API validation covers RDMA checkpoint delivery, managed launch/load/shutdown, text and image streaming, long inputs, continuation and concurrent admission.

Scope and numerical limits

The performance results use the native distributed BatchGenerator; cluster API workers still reject speculative drafters. Distributed DSpark is available through the sharded Python/example path.

Exact agreement above is against retained MLX controls. Existing CPU-reference differences remain, and batch-four DSpark on/off outputs first diverge at positions 33, 43, 98 and 30 (zero-based). Single-request on/off outputs match all 128 tokens. Inference does not reproduce the reference runtime's activation quantization. Pipeline parallelism and audio input are unsupported.

Model usage and supported features.

@Blaizzy Blaizzy changed the title Add native Inkling 2 inference, distributed sharding and bundled DSpark Add Inkling 2 Nov 15, 2026
@Blaizzy
Blaizzy merged commit 820b067 into main Nov 15, 2026
11 of 12 checks passed
danielhanchen added a commit to unslothai/unsloth that referenced this pull request Nov 23, 2026
…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.
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