Skip to content

feat(studio): draft MLX tool, video, grammar, KV and LoRA replies - #16441

Merged
danielhanchen merged 9 commits into
unslothai:mainfrom
Lyxot:mlx-speculative-limits
Nov 3, 2026
Merged

danielhanchen merged 9 commits into
unslothai:mainfrom
Lyxot:mlx-speculative-limits

Conversation

@Lyxot

@Lyxot Lyxot commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

MLX speculative decoding currently skips tool, video, grammar-constrained, KV-quantized and multimodal LoRA replies. The drafter's memory fit also needs the selected KV-cache width.

This change enables those supported replies to draft, keeps each fixed video-batch row attached to its own clip, and passes the cache width through drafter fitting. Grammar processors follow tentative tokens on a copy of their committed matcher and commit only settled output; an error in one row remains isolated to that row. Affine quantized KV caches can batch where the runtime supports them. TurboQuant, resident video batches, text-only LoRA loads, logprobs, diffusion, encoder-state models and distributed inference retain their existing restrictions.

Grammar drafting and affine KV batches require the merged unsloth-zoo #2359. On older runtimes, grammar replies decode without drafting and quantized loads reply individually. Validation also identified runtime cost-accounting and initialization defects addressed by unsloth-zoo #2365; merge that companion first.

Validation at source 37836adee with companion executable revision 027d5869:

  • The source behavioral differential has four failing-before/passing-after cases for cache-width pricing, drafter fitting and video-row routing, with no head failures. New-API-only cases and skipped tests are not counted as behavioral proof.
  • The source switchboard is current and reports no functional regression: 64 unchanged steps, one DOM-only difference and no leftover processes. The companion's remote regression smoke, SFT and inference smoke also report no regression, using Colab L4 and Kaggle T4 GPUs.
  • macOS 15 and macOS 26 each passed 84 native Metal checks without skips, passed the functional-revert controls after restoration, and completed five MLX LoRA training steps. Linux and Windows each passed 70 companion CPU checks with five explicit skips. Exact installed and imported companion revisions were verified.
  • All eight current Metal feature workers passed: packed 4-bit KV-cache updates, a loaded nonzero LoRA adapter, a single red video, and a batch of separate red and blue clips. Every paired rendered reply matched. Actual video patch tensors reached the model, and both head batch rows drafted. The harness was corrected to accept this model's valid 2D patches.
  • A three-row 8-bit KV batch preserves each rendered reply against its individual baseline, with 8, 21, and 12 proposed tokens. The Tokyo reply reaches the same 24-token budget on both arms.
  • The source review converged through the review mirror; the companion received exact-head approval. Final comment reductions passed strict AST checks. Source executable behavior has not changed from the submitted revision.

Full-stack inference performance retains diagnostic failures. The first comparison preserves all 330 rendered replies but fails late tool time to first token: 434 to 475 ms, beyond the 7.8% noise band. The unchanged repeat preserves another 330 replies and confirms a tool regression: late decode falls from 74.2 to 46.5 tokens/s, beyond the 12.5% noise band, while total response time rises from 0.599 to 0.760 seconds with a harmful paired interval. Plain chat passes every phase of the repeat; grammar remains inconclusive. Cold and first-use costs are reported separately and also include failing cells. Green collection jobs and passing correctness tests do not clear this gate.

The performance measurements above come from standard GitHub macOS VMs. A subsequent execution trace reports Apple Paravirtual device; physical GPU identity and exclusive allocation were not established for the benchmark runs. These remain diagnostic timing failures; an exclusively reserved Apple GPU would be needed to establish a final hardware performance verdict.

Release decision: proceed based on team validation and the correctness evidence above, accepting the remaining performance uncertainty. The additional exclusive-Apple-GPU benchmark is not a prerequisite for this merge. No passing hardware performance verdict or general speedup is claimed; the diagnostic VM timing failures and recorded coverage limits remain.

Three upstream style-check failures were reproduced on the exact CI base with byte-identical offending files and tests; pre-commit passed.

The contributor also reported one differing row in an earlier three-row 8-bit KV batch experiment, with its cause unconfirmed. The current native tests and small-model paired runs do not establish parity for that separate configuration or every checkpoint. That earlier report remains a limitation; a non-speculative load remains available when exact reproducibility is required.

UI before and after

The obsolete KV-cache warning is present before and absent after. Both isolated Studio builds receive the same seeded MLX loaded status; this comparison verifies presentation only. BEFORE is merge base 6401ceda2; AFTER is 95e18fe31, whose executable code matches current source head 37836adee. The composite was inspected manually, and the warning change was checked in Chromium, Firefox, WebKit and Microsoft Edge. Cross-platform Studio/Desktop validation runs in staging CI.

MLX run settings before and after: the obsolete KV-quantization warning is removed

@Lyxot Lyxot added the MLX label Nov 2, 2026
@Lyxot
Lyxot requested a review from danielhanchen as a code owner November 2, 2026 01:00
@Lyxot

Lyxot commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T01:47:22.535661Z bd805ac Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e4c08b3002

ℹ️ 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".

Lyxot added 7 commits November 2, 2026 09:38
A tool reply skipped the drafter, and chat offers tools by default, so a speculative load ran at plain speed. The target verifies every token a call is parsed from, so tool-call text does not depend on the draft.
The draft now sees the prompt as the clip's frames expand it. A speculative batch still does not decode a clip, so these replies run one at a time.
Rollback works on quantized caches on the single path. Speculative batches run on full-precision caches, so such a load declines the resident batch and replies one at a time. TurboQuant's mlx-lm notice can now apply beside a requested draft.
An adapter on a text architecture stays refused, since it loads only through mlx-lm and speculation runs on mlx-vlm.
A speculative load with mx.quantize KV rows runs its replies together again where unsloth-zoo can draft those rows. TurboQuant, whose caches a speculative batch cannot run, still replies one at a time, as does a load on an older unsloth-zoo.
A fixed multi-reply command on a speculative load now hands each row its clip, whose row resumes no cache because token ids do not vary with the clip. A resident batch still refuses a clip, and a load with a quantized KV cache declines, since only a resumed row carries the quantization.
@Lyxot

Lyxot commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@Lyxot
Lyxot force-pushed the mlx-speculative-limits branch from e4c08b3 to bd805ac Compare November 2, 2026 01:39
@Lyxot

Lyxot commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: bd805acdaf

ℹ️ 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".

@Lyxot

Lyxot commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

Review and CI are done at bd805ac.

  • Codex: no major issues, no unresolved threads.
  • CI: 69 passed, 4 skipped, 0 failed.
  • Changed during review: the drafter's memory fit prices the KV cache at its quantized width, and at full width when that width is refused. The test for drafted constrained replies skips on an unsloth-zoo without settling processors, and the removed kv_quant reason left the frontend's fallback copy test.

@danielhanchen danielhanchen self-assigned this Nov 2, 2026
@danielhanchen

Copy link
Copy Markdown
Member

Review record for #16441, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#693.

Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found.

Round 1: reviewed mirror 765811e4fe (this PR's 95e18fe31)

chatgpt-codex-connector[bot] (on the mirror)

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 765811e4fe

No triage reaction was recorded on the mirror

Verdict

The round converged at mirror 765811e4fe (this PR's 95e18fe31).

This is the review as it stood at that commit. Anything pushed to this PR afterwards was not part of it.

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 2, 2026
danielhanchen added a commit to NilayYadav/unsloth that referenced this pull request Nov 2, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 2, 2026
danielhanchen added a commit to LeoBorcherding/unsloth that referenced this pull request Nov 2, 2026
danielhanchen added a commit to NilayYadav/unsloth that referenced this pull request Nov 2, 2026
shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Nov 2, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 2, 2026
@danielhanchen
danielhanchen merged commit b0a6f4b into unslothai:main Nov 3, 2026
Penguinjanator pushed a commit to Penguinjanator/unsloth-zoo that referenced this pull request Nov 3, 2026
…les (unslothai#2365)

Short MLX streams can close without recording completed plain decoding,
and MTP initialization can allocate and replay work before the
controller chooses to draft. Replay and one-time shortlist construction
can also distort the controller's recurring cost estimates.

Record completed plain work on stream close, defer unused draft
preparation, and account for folded replay and separately timed replay
consistently. Keep full-width draft projections on the native table,
exclude shortlist construction from recurring samples, and confirm cold
plain-decoding costs before comparing rates. For settling processors,
queue the next plain step before delivering the current output and
preserve that committed output if the queued step fails.

This is a runtime dependency for
[unslothai/unsloth#16441](unslothai/unsloth#16441).
Merge this companion before Unsloth #16441.

Validation of executable revision `027d5869` (the final `8a06af54`
commit removes comments only):

- [macOS
15](https://github.com/NilayYadav/unsloth/actions/runs/41520265611) and
[macOS
26](https://github.com/NilayYadav/unsloth/actions/runs/41520265804) each
passed 84 native Metal checks without skips and completed five MLX LoRA
training steps. Installed and imported revisions were verified.
Reverting only the native-head selector failed three shape checks;
reverting only the shortlist first-use marker failed its accounting
check. Restoring the changes passed both controls and the full
selection.
-
[Linux](https://github.com/NilayYadav/unsloth/actions/runs/41520265740)
and
[Windows](https://github.com/NilayYadav/unsloth/actions/runs/41520265669)
each passed 70 CPU simulation checks, with five explicit skips. Those
checks establish portability and controller behavior; the native Metal
runs cover the skipped GPU operations.
- The latest cost-regime differential has nine
failing-before/passing-after checks and no head failures. An independent
matrix covers 4,980 replay-cost and subset-selection cells: 1,961
already correct, 3,019 corrected, zero regressions.
- The remote Core switchboard finished with no regression in regression
smoke, SFT and inference smoke, using Colab L4 and Kaggle T4 GPUs. It
left no processes behind. The final comment-only head is AST-equivalent
to the tested revision.
- All eight current Metal feature workers passed: packed 4-bit KV-cache
updates, a loaded nonzero LoRA adapter, a single red video, and a batch
of separate red and blue clips. Every paired rendered reply matched.
Actual video patch tensors reached the model, and both head batch rows
drafted. The probe was corrected to recognize this model's 2D patches.
- A three-row 8-bit KV batch preserves each rendered reply against its
individual baseline, with 8, 21, and 12 proposed tokens. The Tokyo reply
reaches the same 24-token budget on both arms.
- Exact-head review approved the executable revision. The final comment
pass removed eight comment lines and passed strict AST checks.

Full-stack inference performance retains diagnostic failures. The [first
comparison](https://github.com/NilayYadav/unsloth/actions/runs/41525979139)
preserves all 330 rendered replies but fails late tool time to first
token: 434 to 475 ms, beyond the 7.8% noise band. The [unchanged
repeat](https://github.com/danielhanchen/unsloth-staging-2/actions/runs/41551616128)
preserves another 330 replies and confirms a tool regression: late
decode falls from 74.2 to 46.5 tokens/s, beyond the 12.5% noise band,
while total response time rises from 0.599 to 0.760 seconds with a
harmful paired interval. Plain chat passes every phase of the repeat;
grammar remains inconclusive. Cold and first-use costs are reported
separately and also include failing cells. Green collection jobs and
passing correctness tests do not clear this gate.

The performance measurements above come from standard GitHub macOS VMs.
A subsequent execution trace reports `Apple Paravirtual device`;
physical GPU identity and exclusive allocation were not established for
the benchmark runs. These remain diagnostic timing failures; an
exclusively reserved Apple GPU would be needed to establish a final
hardware performance verdict.

Release decision: proceed based on team validation and the correctness
evidence above, accepting the remaining performance uncertainty. The
additional exclusive-Apple-GPU benchmark is not a prerequisite for this
merge. No passing hardware performance verdict or general speedup is
claimed; the diagnostic VM timing failures and recorded coverage limits
remain.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants