JustFit
Run a 27B model over its full 256K-token context — and share that context
across concurrent requests — inside 24 GiB of unified memory.
Built on MLX, Apple's array framework
for Apple silicon, and mlx-vlm by
Prince Canuma, which this project extends and ships in full. JustFit adds a
serving runtime on top of their work; the models, kernels, and loading paths
underneath are theirs. See Built on mlx-vlm.
Paper ·
Project page ·
Quick Start ·
Reproduction kit ·
Serving guide ·
Pinned components
JustFit is an MLX inference runtime for long-context local serving. Quantizing
the KV cache is only the first step: usable context is set by every allocation
that overlaps it — weights, resident pages, attention operands, prefill
workspace, speculative state, component lifetimes. JustFit treats their overlap
as the actual problem, and materializes each one only while it is needed.
On an Apple M4 Pro with 24 GiB, that moves Qwen3.8-27B from 30,720 completed
positions to the complete 262,144-position native window — 8.53× — with a
measured peak of 20,357 MiB under a 21,000 MiB fail-closed guard.
Install
JustFit is not on PyPI yet — install from source:
git clone https://github.com/YuhuaBillChen/justfit-mlx
cd justfit-mlx && pip install -e .
The import package is mlx_vlm, so existing mlx-vlm code keeps working.
To reproduce the paper's runs, use the pinned tree instead:
git clone --branch justfit-repro-v4 https://github.com/YuhuaBillChen/justfit-mlx
cd justfit-mlx && examples/justfit/run_server.sh
Start with the 8K+64 smoke profile in the
Quick Start. Only attempt 240K+16K after
verifying the checkpoint, component files, thermal conditions, free disk space,
and a process-footprint monitor.
How it fits
- KVExec keeps TurboQuant Q4 KV state in fixed-size pages and consumes those
pages directly for decode and short MTP verification. Eligible prefill uses a
direct-inverse reconstruction path and evaluates each layer before returning,
bounding the lifetime of floating-point attention operands.
- PhaseSwap assigns explicit leases to components whose useful lifetimes do
not cover the whole request: the output head, vision tower, input embedding
table when configured, and the deferred MTP drafter.
- StateTrans changes between singleton MTP and multi-request AR at safe
cohort boundaries while retaining surviving target KV and recurrent state.
Completed or cancelled requests return page IDs to the resident pool only
after pending state has been evaluated.
Measured results
Apple M4 Pro MacBook Pro, 24 GiB unified memory; Qwen3.8-27B with fixed MXFP4
weights; 21,000 MiB sampled process-footprint guard. K = 1,024.
| Workload | Retained positions | PP | TG | Peak footprint |
|---|
| mlx-vlm baseline, B1 24K input + 6K output | 30,720 | — | did not complete the next fixed step | below guard at this point |
| JustFit, B1 240K input + 16K output, fully cold | 262,144 | 60.546 tok/s | 5.936 tok/s | 20,357 MiB |
| JustFit, B2 2×(128K input + 16K output), fully cold | 294,912 aggregate | 81.399 tok/s | 10.341 aggregate tok/s | 20,858 MiB |
| JustFit, B2 160K+16K and 128K+16K, ordered warm-prefix restore | 327,680 aggregate | protocol-dependent incremental PP | 9.735 aggregate tok/s median | 20,432–20,953 MiB |
| JustFit, B4 128K+12K incumbent then 3×(8K+12K) | 204,800 aggregate | 85.452 tok/s | 22.570 common-active; 12.147 wall-output tok/s | 18,915 MiB |
In a separate capability protocol, paged TQ4 answered 29/30 AIME 2026 problems
correctly and generated 696,834 tokens at 15.04 token-weighted tok/s.
Full cohort detail, protocol boundaries, and the source map are in
docs/justfit.md.
What these numbers do not claim