Skip to content

Studio: transcribe with downloaded MLX speech-to-text models on Apple Silicon - #13443

Merged
danielhanchen merged 9 commits into
mainfrom
studio-mlx-transcribe
Oct 13, 2026
Merged

danielhanchen merged 9 commits into
mainfrom
studio-mlx-transcribe

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Fixes #10272

Problem

On a Mac, a speech-to-text model downloaded in MLX format (for example mlx-community/Qwen3-ASR-1.7B-8bit) never shows up in the Transcribe tab. The Transformers dictation engine only accepts Whisper checkpoints, and the Transcribe picker only admits Whisper rows from the cache, so the model is invisible there (the cache listed it as a chat model instead).

Fix

mlx-audio already ships with the Mac install (mlx-vlm depends on it), so the existing Transformers dictation engine now serves these checkpoints through it on Apple Silicon:

  • core/inference/stt_mlx.py: one predicate, true only on Apple Silicon with mlx-audio installed, for qwen3_asr checkpoints (the family Studio already curates as GGUF). mlx-audio loads both the mlx-community quants and the original Qwen safetensors. Whisper never goes this way.

  • The sidecar accepts such a cached snapshot and starts the same spawned dictation worker with runtime="mlx"; the child loads it with mlx_audio.stt.load and transcribes each window. Load, idle unload, cancellation, residency, status, the CPU audio preference and the frontend engine are the existing Transformers ones, so nothing new is exposed to the UI.

  • The Hugging Face cache inventory lists the repo as automatic-speech-recognition with library mlx-audio and not chattable, and the Transcribe picker admits that on-device row on a Mac only.

  • The language picked in Transcribe is passed to the model when the checkpoint lists it in support_languages; otherwise the model detects it.

  • A snapshot that ships its own code (any .py, or an auto_map in its configs) is refused before loading, since mlx-audio loads the tokenizer with trust_remote_code=True.

  • These checkpoints do not translate, so /audio/translations refuses them with the existing 400 instead of returning a transcript.

  • Qwen3-ForcedAligner checkpoints (also model_type: qwen3_asr) are excluded: they align a given transcript and cannot transcribe.

  • Picking such a cached model from the Chat model picker routes it to Transcribe, as it already does for Whisper.

  • The mlx-audio check caches only a positive answer, so a session where the MLX self-repair installed mlx-audio picks it up without a restart.

What does not change

  • Off Apple Silicon, or without mlx-audio, every new branch is skipped: the same snapshots are accepted or refused, the inventory rows are identical, and the picker shows the same rows.
  • Whisper load commands sent to the worker are byte-identical (the new key is only added for MLX).
  • Hub search and the Model Hub download flow are untouched. This covers models already on disk, which is what the issue reports.

Testing

Real Apple Silicon (GitHub macos-15, Metal), Studio's Mac pins (mlx 0.32.3, mlx-lm 0.31.3, mlx-vlm 0.7.4, mlx-audio 0.5.8, transformers 5.5.0), mlx-community/Qwen3-ASR-0.6B-8bit in the Hugging Face cache, speech rendered by macOS say, the tree's own inventory scan and dictation sidecar with nothing patched. The merge base and this branch ran on the same runner:

Check main (3075b73) this PR
Cache row task none (listed as a chat model) automatic-speech-recognition, library mlx-audio, not chattable
Dictation engine sees the download no yes
2.4 s clip STT model 'mlx-community/Qwen3-ASR-0.6B-8bit' is not downloaded. Download it in Settings, then Voice, before loading it. In the beginning, God created the heaven and the earth. (all words)
38.2 s clip (two dictation windows) same error full passage, all words, 6.0 s wall
Device / unload n/a mps, released on unload

The MLX training smoke job (Qwen3.5-2B-4bit, 5 LoRA steps) also passes on the same leg.

Unit and regression coverage:

  • studio/backend/tests/test_stt_mlx.py (28 tests, green on macOS, Ubuntu and Windows, and with torch, PyAV and transformers absent): host gate, family gate, snapshot acceptance on and off a Mac, worker command routing, no in-process Whisper fallback for MLX, child load and transcribe, a real spawned worker end to end through the sidecar windowing with mlx-audio stood in, the cache scan row and inventory flags on and off a Mac. With the functional hunks reverted, 8 of them fail.
  • studio/frontend/tests/audio-picker-policy.test.ts: picker gate (35/35 on all three OSes). Frontend typecheck and the full frontend suite (11757 tests) pass locally.
  • Studio regression switchboard on Linux (auth, settings, model picker, inference settings, crawl, upstream CI, diffusion imports), merge base vs this branch: NO_REGRESSION, every screen identical, which is the expected result off a Mac.
  • Real mlx-audio through the sidecar on Linux with the MLX CPU build (only the Apple Silicon host check patched): Genesis 1:1, in the beginning, God created the heaven and the earth.; on main the same snapshot reads as not downloaded.

Transcribe picker, Apple Silicon

Merge base vs this branch, each built from source on the same macos-15 runner with mlx-community/Qwen3-ASR-0.6B-8bit in the Hugging Face cache, Audio > Transcribe > model picker > On Device. Before: "No downloaded models yet." After: the model is listed and can be picked.

Transcribe picker on Apple Silicon, before and after

@danielhanchen danielhanchen self-assigned this Oct 12, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 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-10-13T06:27:30.644967Z 02dc715 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.

danielhanchen added a commit to LeoBorcherding/unsloth that referenced this pull request Oct 12, 2026
@danielhanchen

danielhanchen commented Oct 12, 2026 •

Copy link
Copy Markdown
Member Author

Two reds on this head (ba1b7925df), merged onto 9b8338cb10:

  1. Frontend build + bundle sanity comes from this PR: over the startup budget: transfer 1960.8 KB > 1960.1 KB. With this PR the first screen's JavaScript lands 0.7 KB over the budget (main builds to about 1958.5 KB, 1.5 KB under). Either load the new MLX speech-to-text UI on use (React.lazy or a dynamic import() where it is opened), or raise BUDGET.transferBytes in studio/frontend/scripts/check-bundle-budget.ts in this PR, with a line on what the growth is for.

  2. Repo tests (CPU, rest) is not from this PR:

    Updating the branch picks both up.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@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: a32bf52c4e

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

Comment on lines +348 to +349
if isinstance(engine, _MlxSttModel):
text, consumed = transcribe_mlx_window(engine, command["audio"])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Make MLX generation observe transcription cancellation

When an MLX transcription is stopped while generate() is still running, this branch does not pass the shared cancellation event into the MLX call; it is checked only after generation returns. For any window that runs longer than the worker's cancellation grace period, _await therefore terminates the entire child, evicting the resident model and forcing the next transcription to reload it, whereas the Whisper branch stops generation cooperatively. Poll cancellation through MLX streaming or a generation callback so Stop can preserve residency.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not changing: a window is at most 30 s of audio and Qwen3-ASR on Metal finishes one in a few seconds (38 s clip in 6 s on macos-15), well inside the 10 s cancel grace, and when it is exceeded the outcome is a reload on the next request, not lost or wrong output.

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 13, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@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: 2b122a98ce

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

Comment on lines +4355 to +4359
macMlxSttRowIsRunnable({
isMac,
isStt: c.task === "automatic-speech-recognition",
isGguf: false,
libraryName: c.library_name,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Honor non-active cache paths for MLX STT rows

When this checkpoint exists only in a legacy or otherwise non-active Hugging Face cache, the inventory intentionally supplies an absolute c.load_id, but this new gate still offers the row while the STT selection path discards meta.loadId and passes only the repository ID to ensureSttLoaded. The backend then searches only _active_hf_hub_cache(), reports the displayed model as not downloaded, and its remote download path cannot recover because validation still accepts only Whisper; either restrict this gate to active-cache rows or carry the pinned snapshot identity through the STT load.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not changing here: the Transformers dictation engine resolves every custom repo (Whisper included) in the active cache only, and a custom Whisper row from a legacy cache behaves the same on main today. Carrying load_id through STT loads is a separate change for both engines.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@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: a179564e48

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

hint = _mlx_language(engine.model, language)
result = engine.model.generate(segment, **({"language": hint} if hint else {}))
text = getattr(result, "text", result)
return (text if isinstance(text, str) else ""), len(segment)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve speech across MLX window boundaries

When an MLX transcription exceeds 30 seconds and the three-second lookback contains no qualifying silence, the sidecar hard-cuts the audio at the window boundary. Returning len(segment) here marks that entire chunk as consumed, while MLX provides no timestamps or overlap, so a word or utterance spanning the cut is decoded independently on both sides and can be omitted or mangled. Use overlapping MLX windows or let Qwen3-ASR perform its native long-audio chunking rather than consuming every hard-cut sample.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not changing: windows already end at the quietest 100 ms inside the last 3 s, so a hard cut needs 3 s of speech with no pause at all at a 30 s mark, and the cost is at most a word there. Bigger or native-chunked windows would push 30 min of PCM through one queue message and lose per-window progress and cancel, which the sidecar keeps on purpose.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Oct 13, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…ter repair, map languages without transformers
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 02dc7153e8

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

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@danielhanchen
danielhanchen merged commit cf6e3e3 into main Oct 13, 2026
@danielhanchen
danielhanchen deleted the studio-mlx-transcribe branch October 13, 2026 07:42
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.

[Feature] Transcribe does not load/recognize mlx models

1 participant