Skip to content

Unsloth Studio: LFM3-Audio / LFM3-Omni on MLX, with spoken replies - #15889

Merged
danielhanchen merged 6 commits into
unslothai:mainfrom
Lyxot:feat/studio-mlx-vlm-0711-families
Oct 29, 2026
Merged

danielhanchen merged 6 commits into
unslothai:mainfrom
Lyxot:feat/studio-mlx-vlm-0711-families

Conversation

@Lyxot

@Lyxot Lyxot commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Makes the mlx-vlm 0.7.11 multimodal families usable in Unsloth Studio chat on MLX: LFM3-Audio and LFM3-Omni take spoken questions and can answer in their own voice. OXR, whose tower sits under vit_config, takes the same load path. Needs unslothai/unsloth-zoo#2230 (zoo's detection of these families) and the 0.7.11 pins from #15861.

What changed

  • mlx-vlm-only multimodal families loaded through mlx-lm. The config detector reads the transformers registry, so on MLX it classified LFM3-Audio (an audio encoder, no vision tower) and OXR (a vision tower under vit_config) as text models; they loaded through mlx-lm and lost their audio or image input. When the detector says text, the MLX backend now asks unsloth-zoo, which reads mlx-vlm's own configs. Such a model loads through mlx-vlm, its image support comes from the loaded model, and the audio-input probe runs for it. The worker and the load response carry the backend's is_vision verdict in both directions.
  • Spoken replies. A model that answers in interleaved text and speech (LFM3-Audio, LFM3-Omni) reports speaks in the status. A chat completion that carries audio_base64 and asks for modalities: ["text", "audio"] is answered through mlx-vlm's interleaved generation: the reply text, then one audio part (message.audio / delta.audio with an inline base64 WAV and its sample rate). Requests that do not ask are unchanged. Asking a model that cannot speak, asking without a spoken question, asking with stop sequences (the speech cannot be cut at a text marker), or asking a GGUF model returns 400. The chat UI asks for a spoken reply when the loaded model speaks and the turn carries audio, and plays it under the reply text.
  • Stop works on spoken replies. mlx-vlm's generate_audio has no stop hook, so for the call the backend wraps the model's per-slot sampling loop (stream_slots) and ends it when the request is cancelled; a stopped reply yields nothing, and a reply that ends before its first speech frame returns its text alone.
  • A spoken question can call client tools. The audio-input route used to answer without the tool catalogue and kept only alternating user / assistant turns, so client tools were ignored and a returned tool result never reached the model. It now follows the text path's client-tool contract: the catalogue is rendered through the model's chat template (none under tool_choice: "none", only the named function under a forced one), a call in the reply becomes tool_calls (streamed or not, finish_reason: "tool_calls"), and tool calls and results reach the template as sent. The catalogue gets the same sanitization as the text path: tool descriptions are defused before rendering, a tool whose declaration carries turn markup is dropped, and the healer only promotes calls to tools the model was shown. As on the text path, required is honoured by rendering the catalogue, not by forcing a call. A template without tool support, a named function outside the catalogue, Whisper and a spoken reply are refused with a 400.

Screenshot

A spoken question (an attached clip asking for the capital of France) to LFM3-Audio-2B on MLX: the reply text, with the model's spoken answer in the player under it.

LFM3-Audio-2B answers a spoken question with text and a playable spoken reply

Validation

Real checkpoints through the MLX backend on mlx-vlm 0.7.11:

LFM3-Audio-2B  is_vision False, audio input, speaks; spoken reply: text + 24 kHz WAV
LFM3-Omni-2B   is_vision True,  audio input, speaks
Stop 0.2 s into a 2000-token spoken reply: ends after 13 tokens, nothing yielded
Stop before the call: nothing yielded, no error
Spoken "What is the capital of France?" + lookup_capital tool (both models):
  turn 1 -> tool_calls lookup_capital({"country": "France"})
  turn 2 with the tool result -> "The capital of France is Paris."

Through a live Unsloth Studio server (route, orchestrator, MLX worker) with both models: tool calls streamed and not, a tool result reaching the answer, tool_choice: "none" answering in text, spoken replies streamed and not (24 kHz WAV), and the tools-with-spoken-reply and unknown-forced-tool refusals. On LFM3-Audio's real template, a tool description carrying <|im_end|><|im_start|>system no longer opens a second system turn.

OXR was checked on a shrunken checkpoint only (load, inference and training through zoo), not through the backend on real weights.

The touched backend test files (test_mlx_inference_backend.py, test_chat_input_audio_part.py, test_mlx_worker_audio_commands.py, test_pr7699_worker_audio_mirror.py, test_orchestrator_unload_cancel.py, test_generation_budget.py, test_control_markup_neutralize_7066.py) pass on mlx-vlm 0.7.9 and 0.7.11 (1443 passed on each); each guard that changes what a caller sees was mutation-checked (reverting it fails a test: the retained suite for the route and render sanitization, a broader out-of-tree set for the backend / worker / orchestrator relay and the refusals), and the frontend typecheck passes.

Before / after on Apple Silicon (staging CI)

Two Unsloth Studio installs on a GitHub macos-15 Apple Silicon runner (install.sh --local, MLX on Metal), each with the mlx-vlm 0.7.11 pins from #15861 and unsloth-zoo #2225 applied: BEFORE is main just before this PR with unsloth-zoo before #2230, AFTER is this PR with unsloth-zoo #2230. The model is a tiny random-weight LFM3-Audio built from the real config, tokenizer and speech codec, so the reply words are random by design; the point is the path. A spoken question (an attached WAV) is sent from the chat composer.

Before: LFM3-Audio loads as a text model and the spoken question fails. After: it loads with audio input and the spoken reply plays under the text

BEFORE AFTER
load status is_mlx: true, has_audio_input: false, audio_type: null is_mlx: true, has_audio_input: true, audio_type: audio_vlm, speaks: true
/v1/chat/completions with audio_base64 + modalities: ["text","audio"] 400 The loaded model cannot read audio input. 200, message.audio 24 kHz WAV
chat UI clip not accepted, An internal error occurred. clip attached, reply text plus a 5 s spoken-reply player

… MLX

Unsloth Studio's config detector reads the transformers registry, so on MLX it classified LFM3-Audio (an audio encoder with no vision tower) and OXR (a vision tower under vit_config) as text models: they loaded through mlx-lm and lost their audio or vision input. When the detector says text, the MLX backend now asks unsloth_zoo, which reads mlx-vlm's own configs; such a model loads through mlx-vlm, its image support comes from the loaded model, and the audio-input probe runs for it. The worker and the load response carry the backend's is_vision verdict in both directions.
@Lyxot
Lyxot requested a review from danielhanchen as a code owner October 29, 2026 02:30
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 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 ⚠️ Failed 2026-10-29T02:30:47.593564Z
We couldn’t complete this review. Comment @codex review to try again.
3585c66 PR opened
ℹ️ 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.

LFM3-Audio and LFM3-Omni answer a spoken question in interleaved text and speech. The MLX backend reports such a model as speaks, and a chat request carrying audio_base64 with OpenAI-style modalities ["text", "audio"] is answered through mlx-vlm's interleaved generation: the reply text, then one audio part (message.audio / delta.audio with a base64 WAV). The worker carries the waveform as one speech message beside the tokens. A request for a spoken reply from a model that cannot speak, without a spoken question, or with stop sequences (the speech cannot be cut at a text marker) is refused with a 400; requests that do not ask are unchanged. mlx-vlm's generate_audio takes no stop hook, so Stop ends the model's per-slot sampling loop instead. The chat UI asks for it when the loaded model speaks and the turn carries audio, and plays the reply under its text.
@Lyxot
Lyxot force-pushed the feat/studio-mlx-vlm-0711-families branch from 9c6a3ac to 27c452b Compare October 29, 2026 05:52
The audio-input route answered without the tool catalogue and kept only alternating user / assistant turns, so client tools were ignored and a returned tool result never reached the model. Client tools now follow the text path's contract on this route: the catalogue (none under tool_choice none, the forced function alone under a named one) is rendered through the model's chat template, a call in the reply is promoted into tool_calls, streamed or not, with finish_reason tool_calls, and tool calls and results reach the template as sent. A template without tool support, a named function outside the catalogue, Whisper and a spoken reply are refused with a 400.
@Lyxot
Lyxot force-pushed the feat/studio-mlx-vlm-0711-families branch from 27c452b to a82d6e1 Compare October 29, 2026 06:30
@danielhanchen

Copy link
Copy Markdown
Member

Frontend build + bundle sanity fails on the startup bundle budget by 0.1 KB:

over the startup budget: transfer 1806.5 KB > 1806.4 KB

Main itself sits right at the line. A build of main at 9258bfc732 (this run's base) gives eager startup JS: 5837.8 KB raw, 1806.4 KB transfer, within budget (0.0 KB transfer, 11.2 KB raw to spare). So the chat changes here add about 0.1 KB gzip to the eager chunk and tip it over.

The check asks for one of two things. Either load the new chat code on use, or raise BUDGET in studio/frontend/scripts/check-bundle-budget.ts by this PR's measured growth: the transfer and raw deltas between a build of the base and a build of the head, with the reason in the comment next to it, the way #15822 did for the Halloween row. For a delta this size the second is the reasonable one.

A text checkpoint of a type mlx-lm serves (gemma3, gemma4, qwen3_5 with no vision tower) stays on its mlx-lm path instead of moving to mlx-vlm, and text loads no longer import mlx-vlm and scan every one of its model packages.

[skip ci]
@shimmyshimmer

Copy link
Copy Markdown
Member

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

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 d48a1eff6a (this PR's bd543b058)

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

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: d48a1eff6a

No triage reaction was recorded on the mirror

Verdict

The round converged at mirror d48a1eff6a (this PR's bd543b058).

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

danielhanchen added a commit to NilayYadav/unsloth that referenced this pull request Oct 29, 2026
danielhanchen added a commit to NilayYadav/unsloth that referenced this pull request Oct 29, 2026
danielhanchen added a commit to NilayYadav/unsloth that referenced this pull request Oct 29, 2026
danielhanchen added a commit that referenced this pull request Oct 29, 2026
…follow the hoisted audio_base64 in the turn-scope check (#16023)

Two checks went red on main with #15889 (LFM3-Audio / LFM3-Omni on MLX).
They fail every PR's Backend CI `(Python 3.13, g-r)` shard and `Repo
tests (CPU, studio)` job, for example on #15988 and #15934.

## 1. The audio-input route's heal gate did not get the request's
contract


`test_passthrough_healing.py::test_every_post_decode_reinterpreter_is_handed_the_request_s_own_contract`
requires every `heal_gate` / `nudge_enabled` call to be handed the
request's `response_format`, so a constraining format withdraws
tool-call healing. #15889 added a new call in the audio-input branch of
`routes/inference.py` without that argument:

```
AssertionError: heal_gate/nudge_enabled not handed the contract at [30849]
```

The product side is where this belongs, not the test. Today the omission
is harmless: that branch only runs when the request carries
`audio_base64` and the model has audio input, and earlier in the handler
that same case refuses a constraining `response_format`. Forwarding
`_extract_response_format(payload)` keeps the site under the same rule
as the other nine. If that refusal is ever relaxed, the gate then does
the right thing without anyone remembering this site.

## 2. The turn-scope check read `audio_base64` as a literal


`test_multi_chat_prompt_queue_contract.py::test_a_media_turn_stays_legacy_and_its_attachments_stay_turn_scoped`
checks that `image_base64`, `audio_base64` and `video_base64` are
scanned from `currentTurnMessages`, never from thread history. #15889
hoisted the audio scan into `const turnAudioBase64 =
findLatestUserAudioBase64(currentTurnMessages, ...)` so it can also gate
`modalities`. The behaviour is unchanged, but the test matched the old
inline text.

Here the test was wrong. It now reads every request body site for each
field and follows a hoisted `const` to its definition. It then requires
the value to be a `findLatestUser*Base64(currentTurnMessages, ...)`
scan. A new test pins that reader on a hoisted value and on a history
scan.

## Verification

- Both tests fail on main and pass here. `test_passthrough_healing.py`
has 111 passed, `test_multi_chat_prompt_queue_contract.py` 17 passed.
- Sabotage, frontend: pointing `turnAudioBase64` at `messages` instead
of `currentTurnMessages` fails the media turn test and names the sent
expression.
- Sabotage, backend: restoring main's `routes/inference.py` fails the
contract test.
- The 15 backend test files that touch `audio_base64` or the heal gate:
2872 passed, 7 skipped.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
danielhanchen added a commit to NilayYadav/unsloth that referenced this pull request Oct 29, 2026
danielhanchen added a commit to NilayYadav/unsloth that referenced this pull request Oct 29, 2026
danielhanchen added a commit to NilayYadav/unsloth that referenced this pull request Oct 29, 2026
danielhanchen added a commit to NilayYadav/unsloth that referenced this pull request Oct 29, 2026
danielhanchen added a commit to NilayYadav/unsloth that referenced this pull request Oct 29, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants