Repository navigation
Description
Environment
Where are you using Unsloth?
- Unsloth desktop application
- Unsloth web UI (
unsloth studio) - Unsloth CLI
- Python package or notebook
- Colab or Kaggle
Operating system and version:
macOS Golden Gate 27.2 (26B123)
GPU model(s) and accelerator backend:
- Apple M4 Pro
- 24 GB unified memory
- Apple MLX backend
Versions:
- Unsloth Desktop:
0.1.912-beta - Unsloth package, backend, and llama.cpp versions:
- llama.cpp version b11963-mix-a54b8dd
- whisper.cpp version v1.9.5-unsloth.14
- audio.cpp version v0.9.3-unsloth.1
- MLX version 0.32.4
What happened?
Unsloth Studio's MLX memory estimator reports an unexpectedly large memory requirement for a 2-bit MLX model, despite the model successfully loading and running on a Mac with substantially less physical memory.
For a model with 7.91 GiB of weights, Unsloth estimates 69.70 GiB of total memory, including 52.67 GiB of compute buffers.
Steps to reproduce:
- Open Unsloth Desktop 0.1.912-beta on an Apple Silicon Mac.
- Select
prism-ml/Ternary-Bonsai-27B-mlx-2bit. - Set context length to 262,144 tokens.
- Select 8-bit KV cache quantization.
- Expand the "Estimated Memory Usage" section.
- Observe the estimated 69.70 GiB memory requirement.
- Load the model. It successfully initializes and runs on a Mac with 24 GB unified memory.
Expected behavior:
The memory estimator should accurately distinguish between:
- Memory needed to initialize the model.
- KV cache memory for the configured context length.
- Temporary compute-buffer allocations.
- Worst-case peak memory during long-context inference.
If the estimate represents a conservative worst-case scenario rather than expected memory consumption, the UI should clearly communicate that distinction.
Actual behavior:
Unsloth reports the following memory breakdown:
| Component | Estimated memory |
|---|---|
| Model weights | 7.91 GiB |
| KV cache | 9.12 GiB |
| Compute buffers | 52.67 GiB |
| Total | 69.70 GiB |
Screenshot of the memory estimate:
Despite this estimate, the model successfully loads and runs on a 24 GB Mac.
I have not tested an actual 262K-token prompt, so I cannot confirm whether the reported peak memory is inaccurate at maximum context length.
Model and operation involved:
- Model:
prism-ml/Ternary-Bonsai-27B-mlx-2bit - Operation: Native MLX inference
- Model quantization: 2-bit
- KV cache: 8-bit
- Configured context: 262,144 tokens
- Hardware: Apple M4 Pro, 24 GB unified memory
Diagnostics and logs
Desktop application
No diagnostics collected yet.
If needed, I can provide relevant backend logs from ~/.unsloth/studio/ after removing sensitive information.
Unsloth web UI
Not applicable. Using the desktop application.
Model-specific logs, if applicable
This involves native MLX inference, not GGUF/llama.cpp.
Python package or notebook, if applicable
Not applicable.
Additional context
Possible source of the discrepancy
The MLX memory estimator is implemented in:
studio/backend/core/inference/mlx_memory.py
The _compute_bytes() function contains a fallback involving _widest_quantized_scores() when _dequantized_row_bytes() returns None:
if row is None:
total += _widest_quantized_scores(
n_ctx, quant_boundary, prefill_chunk
) * scoreAt long context lengths, this calculation may estimate extremely large temporary attention-score buffers.
It is unclear whether this represents actual peak allocations or an overly conservative estimation path.
Suggested investigation:
- Verify whether the estimated 52.67 GiB compute-buffer requirement corresponds to actual runtime allocations.
- Check whether the quantized KV cache triggers a fallback estimate that does not match the selected attention kernel.
- Consider displaying expected memory usage separately from worst-case peak usage.
- Investigate whether the estimation or underlying MLX inference path can be optimized for long contexts on Apple Silicon.
Relevant source:
Activity
debojyoti-dev commentedon Oct 29, 2026
Hi @Lyxot, I see this is assigned to you. Would it be OK if I open a PR for the estimator side of it? I traced it down:
fused_kernel_existsreturns False for a causal call with more queries than keys),_dequantized_row_bytesinmlx_memory.pyalways getsNone, because it probes with a one-token cache against a 2048-token prefill chunk. So every quantized-KV MLX estimate falls back to the full[heads, chunk, n_ctx]score matrix, even for models where zoo would really take the dequantized-copy route (head_dim 64-128 everywhere, and head_dim 256/512 on Macs with neural accelerators). For a Qwen2.5-7B-like model at 262K with 8-bit KV, that's ~64 GiB charged instead of ~1.5 GiB.The fix is to probe the route with a cache one token longer than the chunk, like every chunk after the first sees. I'll hold off if you'd rather handle it yourself.
Studio MLX estimate: ask the quantized-attention route about a cache …
danielhanchen commentedon Oct 30, 2026
Fixed! The Mac memory estimate was charging a huge attention buffer that MLX no longer builds when the KV cache is quantized, and it missed the one it really does build with the default cache. Fixed in #15970 (quantized KV cache) and #16021 (default cache). At a full 262K context this model on an M1 to M4 Mac still needs about 31 GiB of compute buffers, because MLX really allocates that for a prompt that long, so the context Studio picks for a 24 GB Mac will be shorter.
To update: Unsloth Desktop will have an update banner. For Studio, use
unsloth studio update. For Docker, usedocker exec <container> unsloth-studio-update. Reopen if it still happens.Studio MLX estimate: price attention scores where mlx really holds th…