Repository navigation
feat(studio): bring MLX Run settings up to GGUF parity - #18426
Conversation
Run settings show Vision for MLX models. Turning it off stops image input; where unsloth-zoo builds the text model without the tower, the load also skips the vision weights. Adapters and audio-input models keep vision. The MLX load reports disable_vision and vision_disabled_by_user, and a changed setting reloads.
Run settings show Reasoning Budget and its message for MLX models. The MLX load keeps the pair and every reply path (mlx-lm, mlx-vlm, batched rows) appends a logits processor that, once the budget is spent inside the reasoning block, forces the message and the block's closer, as llama-server's --reasoning-budget does. 0 closes the block as soon as it opens. The processor cannot follow a draft, so a budgeted mlx-vlm reply decodes without the drafter. The load echoes the pair and a changed value reloads.
Run settings show Micro-batch Size for MLX models. An MLX load takes n_ubatch as its prefill step, tokens per prefill forward, on the mlx-lm, mlx-vlm and batched paths. The mlx-vlm prompt-cache grid follows it per load, so every request of the load prefills and banks on one grid and reuse stays shape-stable. With experts read from disk the offload planner's own chunk caps it, since memory was priced there, and the memory estimate prices the same chunk. API overrides forward it to MLX loads; a changed value reloads.
A Vision-off MLX load asks unsloth_zoo to never read the vision tower and projector (drop_vision_weights), falling back to freeing them after the load on an older unsloth_zoo, and records the bytes in vision_weights_freed. The memory estimate, offload plan and context fit price such a load without those weights, so the Run settings estimate matches what the load holds.
On MLX the prompt cache was fixed at 15% of the Metal working set (overridable only by UNSLOTH_MLX_PROMPT_CACHE_BYTES) and comes out of the memory the context fit uses. Run settings now show Cache RAM for MLX loads: blank keeps the default, 0 disables the cache, and llama.cpp's -1 (unlimited) loads as the default. The load, the memory estimate, chat admission and the resident match all use the chosen size, and a cache that takes the whole budget now reports that nothing fits instead of skipping the fit.
…ompt cache in place A load that changes only these settings on the held MLX model now updates the running worker instead of reloading the weights, extending the in-place context narrowing path. A larger prompt cache, or any other load setting, still reloads, since it changes memory the load gave its context. The retune also refreshes the batching capabilities a reasoning budget decides.
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cb549fef4a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…mar and apply it to audio replies A JSON grammar that allows no reasoning masks the closer a spent budget would force, leaving no token to sample, so the budget no longer applies there. Audio-input replies on mlx-vlm now honour the load's budget like the other reply paths.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b8bdb55837
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
When a grammar that allows reasoning reaches its own prelude cap it permits only the closer; a budget forcing its message at the same step left no token to sample. The budget now yields when the token it would force is already masked.
…and keep MLX settings after autoload A retune that does not narrow the context now declines when the checkpoint files changed since the load, as narrowing does. Autoloading an MLX model mirrors the settings it applied (reasoning budget, batch sizes, Cache RAM, Vision) instead of resetting them, so a later reload does not silently revert them.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c8819d1cdb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…to speculation A Vision-off load that builds the text model looks for no automatic drafter; the estimate now classifies the route the same way instead of charging a drafter the load never attaches.
An image row admitted to an mlx-lm batch prefilled at unsloth-zoo's default step, so the load's Micro-batch Size and the expert-offload chunk the estimate prices did not bound it.
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…warding Non-GGUF model overrides now forward the batch sizes and Cache RAM, which MLX loads read, and the autoload harness stubs the MLX tuning helper the success branch uses.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d9a61b4242
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d9a61b4242
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ariaLabel="Prompt micro-batch size" | ||
| value={config.nUbatch} | ||
| onChange={(nUbatch) => update({ nUbatch })} |
There was a problem hiding this comment.
Include the loaded MLX micro-batch in resident memory estimates
For an MLX model loaded with a non-default micro-batch, the prospective memory estimate honors this setting, but the separate resident estimate used for reclaimable-memory credit does not. MLX clears loadedGpuMemoryMode, so selectResidentEstimateSettings() returns null, and resolveResidentEstimateRequest() reconstructs only the context, KV quantization, and offload settings. A model using a 512-token step is consequently credited with the compute footprint of the default step, inflating the memory reported as reclaimable and potentially suppressing a reload's memory-pressure warning. Pass the loaded micro-batch explicitly through the MLX resident-estimate path rather than relying on the unavailable GGUF baselines.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Estimate accuracy only: the reclaimable credit for a resident model differs by one prefill step's compute buffer, and nothing loads or fails because of it.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…ng, MLX batch sizes, QAT CUDA skip) (#18471) ## Summary Four tests fail on `main` in the "Repo tests (CPU, studio)" shard, so every PR that runs it is red (seen on the staging runs of #18353 and others). Reproduced on `main` at `415cdcf1be`: ``` FAILED tests/python/test_accelerator_skip_guards.py::test_no_skip_guard_reads_a_spoofable_accelerator_probe FAILED tests/studio/test_model_picker_contracts.py::test_batch_sizes_setting_wired_end_to_end FAILED tests/studio/test_model_picker_contracts.py::test_batch_sizes_reach_an_api_load_through_the_server_mirror FAILED tests/studio/test_chat_ui_picker_collapsed_row.py::test_a_loaded_model_still_opens_the_picker_collapsed ``` Each was attributed to the PR that changed the code it reads, and each was checked for whether the PR or the test is wrong. ## Root causes and changes ### Picker collapsed after a load (#18445): test was wrong #18445 added the "Show full model list" setting, so the load effect now calls `setExpanded(useChatRuntimeStore.getState().pickerExpandLoaded)` instead of a literal `?? false`. The setting defaults to off, so a fresh browser (every CI driver) still opens the picker collapsed, which is what this test protects: the drivers' expand click is still needed. `test_a_loaded_model_still_opens_the_picker_collapsed` now accepts either form, and when the setting drives it, also asserts the store default is `loadBool(PICKER_EXPAND_LOADED_KEY, false)`. Flipping that default to `true` fails the test, which the old literal check could not see. ### Batch sizes sent on a load (#18426): test was wrong #18426 brought MLX up to GGUF parity, so `n_batch` / `n_ubatch` are now sent for `(target.isGguf || mlx)` and copied for MLX overrides too. GGUF behaviour is unchanged; the tests pinned the old GGUF-only literal. - `test_batch_sizes_setting_wired_end_to_end`: matches the gate with a regex that allows widening to MLX but still requires `target.isGguf` and "only when set". Dropping the gate (sending the fields to every engine) fails it. - `test_batch_sizes_reach_an_api_load_through_the_server_mirror`: replaces the source-text check on the GGUF block with a behavioural check through `_override_load_kwargs`, which the test already imports. Dropping `n_ubatch` from the copied keys fails it. ### QAT stream test skip guard (#18434): PR was wrong `tests/test_qat_weight_memo_guards.py` gated `test_cached_weight_not_served_to_another_stream` on `torch.cuda.is_available()`, which `tests/_zoo_aggressive_cuda_spoof.py` patches to `True` process-wide, so on a CPU runner the test un-skips and calls `.cuda()` when it shares a session with the spoofing suites. The existing guard caught this. The skip now gates on `has_real_cuda()` first, as the other CUDA-only tests do. ## Testing - The four tests plus their files: `241 passed, 1 skipped` on this branch; the same four fail on `main`. - Sabotage, each against this branch: - store default `pickerExpandLoaded` set to `true`: the picker test fails; - `n_batch` sent without the GGUF/MLX gate: the end-to-end batch test fails; - `n_ubatch` dropped from the backend override copy: the server-mirror test fails; - QAT skip guard reverted: the skip-guard test fails.
Summary
Unsloth Studio's Run settings offered GGUF models controls that MLX models either lacked or accepted and silently ignored. This PR wires every Run setting MLX can honour through the load path end to end: the Run settings panel, the load request, the memory estimate, chat admission, the resident-model match and OpenAI-compatible API overrides. Controls that only make sense for llama-server stay hidden for MLX: GPU layers and tensor split, mmap/mlock, checkpoints and extra server arguments.
The Vision-off memory saving needs unslothai/unsloth-zoo#2600. With an older unsloth-zoo the new load argument is ignored. Vision off then stops image input but frees no memory.
Changes
drop_vision_weights). Where the load cannot skip them, it frees them after the load (both need the unsloth-zoo change).--reasoning-budgetdoes. A budget of 0 closes the block as soon as it opens.n_ubatch).n_batch). Caps the tokens one batched prefill forward takes across requests, like llama.cpp's logical batch. Unset keeps the current behaviour of prefilling every waiting row at once.-1(unlimited) loads as the default, because MLX shares one memory pool with the model.Risks
Validation
Peak memory of a load with Vision off:
The memory estimate is within 0.01 GiB of the measured peak.
Live
/loadtimings on Qwen3.5-0.8B-4bit:Cache RAM checked live:
UI before / after
Run settings for unsloth/Qwen2.5-VL-3B-Instruct with Advanced settings on, merge base 14111b6 (BEFORE) vs PR head 304f61e (AFTER). These rows only render on Apple Silicon, so the platform response (
/api/healthdevice_type) was set tomacon both sides identically. AFTER adds Vision, Batch Size, Micro-batch Size, Cache RAM, Reasoning Budget and Reasoning Budget Message.