Repository navigation
Conversation
Inkling 2 Mini (mlx-community/Inkling-2-Mini-4bit, config model_type inkling2_loop): - its model, mlx-lm's models/inkling2 from ml-explore/mlx-lm#2086 (not merged), vendored into inkling/inkling2/ with only the imports changed: exo's mlx-lm pin predates mlx-lm's new models layout (exo-explore#2082), which moved the helpers it uses; moving the pin instead breaks 53 of exo's mlx-lm imports; - registered in the Inkling family (same message tokens and ids, so the same output parser and EOS rule); single node, no tensor parallelism; - a model card (262,144-token context). Long prompts on models whose per-layer cache is a CacheList of a KVCache and an ArraysCache (Inkling 2): the prefill snapshots taken after every chunk for prefix-cache rollback deep-copied the whole CacheList, keys and values included, and kept every one, so memory grew with the square of the prompt and a 185K-token prompt ran a 64 GB Mac out of GPU memory. A snapshot now keeps such a KVCache as its length only (TrimmedTo), and a restore trims the live cache back to it. Checked against a fresh prefill: next-token logits within the noise of a different prefill step size, for a plain prefill and for a prefix-cache restore; a 236K-token needle prompt now runs at a 50 GiB peak. EXO_PREFILL_STEP_SIZE sets the prefill step (default 4096, as before). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for this. I tested Inkling 2 Mini on a single M5 Ultra (96 GB), with this branch on What I checked
Benchmark (
Before merge
Smaller points
|
Motivation
Inkling 2 Mini (
mlx-community/Inkling-2-Mini-4bit, configmodel_typeinkling2_loop) didn't run on exo: the Inkling family only knows Inkling-Small'sinkling_mm_model, and exo's mlx-lm pin has no Inkling 2.While testing it, a long prompt (~185K tokens) ran a 64 GB Mac out of GPU memory:
kIOGPUCommandBufferCallbackErrorOutOfMemoryin prefill, with the footprint growing ~0.35 GiB/s for the whole prefill. The cause isn't specific to Inkling (see below).Changes
models/inkling/inkling2/: mlx-lm'smodels/inkling2/from Add Inkling 2 Mini model ml-explore/mlx-lm#2086 (commit0c4c9919, not merged yet), vendored with only its imports changed. exo's mlx-lm pin (6b572ab1) predates mlx-lm's new models layout ([BUG] Streaming chat completions emit null-valued delta fields, breaking some OpenAI clients #2082), which moved the helpers it uses; the same helpers are under their old paths at exo's pin (verified identical), andspliceis copied. Repinning mlx-lm to How to config and load the DeepSeek v3.2 model #2086 instead breaks 53 of exo's 163 mlx-lm imports.# type: ignoreand excluded from ruff, asdeepseek_v4/model.pyis.spec.py,family.py). Mini uses the same message token ids as Inkling-Small (200001/04/06/08/10/49/57, checked against its tokenizer), so it uses the sameparse_inklingparser and EOS rule. It's single node only, with no tensor-parallel strategy.mlx-community--Inkling-2-Mini-4bit.toml, 262,144-token context. The built-in card count test is now 159.cache.py)CacheList(KVCache | RotatingKVCache, ArraysCache). TheArraysCache(convolution states) makes theCacheListnon-trimmable.prefill()snapshots it after every chunk for the prefix-cache rollback._copy_cache_listdeepcopy'd the innerKVCache, and every snapshot was kept, so memory grew with the square of the prompt length.KVCacheinside aCacheListasTrimmedTo(offset), which is 0 bytes. Restoring trims the live cache back to that offset:copy_snapshot_entry(entry, live)intrim_cacheand inprefill's rollback.offsetpositions never change as it grows, so the trim is exact.get_kv_cachealready deep-copies the stored entry beforetrim_cache, so stored prefix-cache entries are never trimmed.EXO_PREFILL_STEP_SIZE(constants.py): the prefill step thatgenerate.pyandbatch_generate.pyhard-coded. The default stays 4096, so nothing changes unless it's set. I added it while chasing the OOM. Happy to drop it, or to split this PR into model support and the snapshot fix, if you prefer.Why It Works
CacheListthat is both large and trimmable. Recording its length instead of a copy keeps the rollback behaviour and removes the per-chunk copy.Test Plan
Manual Testing
Hardware: MacBook Pro, M4 Max (40-core GPU), 64 GB, macOS 26.7.1, single node.
Model matches mlx-lm: I loaded the model with exo's
load_model_checkedand with mlx-lm How to config and load the DeepSeek v3.2 model #2086's own environment. First-step logits are identical (max |Δ| 0.0), and 64/64 greedy tokens are identical.Server gates: chat, reasoning returned separately (
17 * 23→391), and tool calls (get_weather→{"city": "Paris"}) all work through exo's API with the existing Inkling parser.Snapshot fix, numerics: I ran a 9K-token prompt through exo's own
prefill()+KVPrefixCache.add_kv_cache, thenget_kv_cache+prefill()for a 9.7K-token prompt that extends it. I compared next-token logits against a fresh one-shot prefill:Snapshot fix, memory:
Speed (single request, 512-token answers, median of 6): exo 37.8–38.4 tok/s. 4 concurrent requests: 92 tok/s aggregate.
Automated Testing
pytest src: 3191 passed. The one failure was the built-in card count (158 → 159), updated here.basedpyright,ruff checkandruff format --checkare clean on the changed files. I don't have nix here, so I didn't runnix fmt.🤖 Generated with Claude Code