Repository navigation
Unsloth Studio: LFM3-Audio / LFM3-Omni on MLX, with spoken replies - #15889
Conversation
… 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.
Codex Review SummaryThis 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. |
e6267fb to
9c6a3ac
Compare
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.
9c6a3ac to
27c452b
Compare
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.
27c452b to
a82d6e1
Compare
|
Main itself sits right at the line. A build of main at The check asks for one of two things. Either load the new chat code on use, or raise |
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]
|
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
|
…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>
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
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'sis_visionverdict in both directions.speaksin the status. A chat completion that carriesaudio_base64and asks formodalities: ["text", "audio"]is answered through mlx-vlm's interleaved generation: the reply text, then one audio part (message.audio/delta.audiowith 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 withstopsequences (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.generate_audiohas 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.toolswere 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 undertool_choice: "none", only the named function under a forced one), a call in the reply becomestool_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,requiredis 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.
Validation
Real checkpoints through the MLX backend on mlx-vlm 0.7.11:
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|>systemno 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-15Apple 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.is_mlx: true,has_audio_input: false,audio_type: nullis_mlx: true,has_audio_input: true,audio_type: audio_vlm,speaks: true/v1/chat/completionswithaudio_base64+modalities: ["text","audio"]The loaded model cannot read audio input.message.audio24 kHz WAVAn internal error occurred.