Repository navigation
feat(detection): route vision-stripped VLM checkpoints to a text-only path - #2031
Merged
Merged
Conversation
… path A VLM model_type with the vision tower removed failed to load unless it omitted vision_config, and only for four families. An empty or null vision_config went to the VLM loader and died on the sub-config, language_model_only: true was a named error, and the Qwen-VL families had no text-only route. Detection now treats an absent, null or empty vision_config and language_model_only: true as text-only, and scans the safetensors index or shard headers for vision tower prefixes for qwen3_5, qwen3_5_moe and gemma3. The Qwen2-VL, Qwen2.5-VL, Qwen3-VL and Qwen3-VL-MoE loaders call the same decision and load with vision_encoder None; an image or video request is refused with a named error at the shared Qwen-VL media entry point. Validated with unit tests, a synthetic qwen3_vl checkpoint, and the stripped Qwen3.6-27B checkpoint under five config variants with identical greedy output. Refs #1367
inureyes
added a commit
that referenced
this pull request
Sep 29, 2026
…ence (#2037) ## Summary Adds NemotronLabs VoiceChat (`nemotron_voicechat`), a full-duplex speech model, with offline inference. One checkpoint holds four networks: a FastConformer speech encoder with an RNNT transcript branch, a Nemotron-H LLM with a text head and a function head, the EAR-TTS speech decoder, and a 31-codebook codec. `mlxcel generate -m <voicechat> --audio q.wav --output-audio a.wav -p "<system prompt>"` prints the user transcript and the answer, and writes the answer speech at 22.05 kHz in the built-in `Aria` voice. ## What changed - **Detection and loading:** `nemotron_voicechat` is detected ahead of the `nemotron_h` arm, since the checkpoint nests a `nemotron_h` text config. It maps to `ModelType::NemotronVoiceChat` and `LoadedModel::NemotronVoiceChat`, with registry capabilities (generate runtime, audio in and out) and a detection test. `mlxcel list` / `arch` report it under "Speech". - **Speech front end:** new modules `audio::nemotron_mel` (log-mel), `audio::fastconformer` (causal subsampling, rel-pos attention with a chunked-limited mask, causal conv) and `audio::rnnt` (LSTM prediction net, joint, greedy decode). - **Codec:** `audio::nemotron_codec` covers encode, decode, and the streaming `decode_step` with `CausalConv1dCache` for #1378. - **TTS:** `models::gemma3_backbone` is a reusable Gemma-3 stack on injected embeddings. `models::nemotron_voicechat::tts` has the char-aware subword encoder, gated fusion, MoG head, RVQ refinement, Aria warmup and per-step generation. - **LLM:** `NemotronHModel` gains `forward_embeds_to_hidden` and `apply_lm_head`. `VoiceChatLanguageModel` renames the checkpoint keys onto the existing loader and adds the function head. - **Offline session and CLI:** `NemotronVoiceChatModel::generate_offline` runs the timeline. `mlxcel generate` routes VoiceChat right after `-m` resolution and adds `--extra-decoding-seconds` (default 3). `--seed` makes the speech reproducible. - **Docs:** `docs/nemotron-voicechat.md`, a speech-to-speech section in `docs/supported-models.md`, and README links. ## Validation All numbers are from the real `mlx-community/NemotronLabs-VoiceChat-11B-4bit` checkpoint, compared against mlx-vlm 0.7.4 on "What is the capital of France?" with a one-sentence system prompt. The tests are env-gated (`tests/nemotron_voicechat_*_real.rs`). - The transcript "What is the capital of France?" and the answer "The capital of France is Paris." match exactly. Text and function ids match at all 62 positions. - With seed 0, all 1922 EAR-TTS codes match the reference. The codec decode of those codes matches it within 1e-7, and seeded CLI runs are byte-identical. - The answer WAV is 62 x 1764 samples. Transcribing it back through the model gives "The capital of France is Paris". - Encoder max abs diff is 5e-7. Codec tone codes match 0 of 372 differing. - The local gate passed after rebasing onto main at 830f6b6: fmt, clippy (lib+tests), the unit tests of the touched modules, `cli_help_consistency`, `dead_doc_pointers`, `llama_compat_manifest`, and the five real-checkpoint tests. GitHub CI was not awaited (self-hosted runner down). - `detection_tests::{has_vision_config_detects_vlm_configs, detect_text_or_vlm_prefers_vlm_when_vision_config_exists}` fail on main too: #2031 made an empty `vision_config` count as absent without updating these tests. They are unrelated to this PR. Performance is deferred to the orchestrator. `docs/nemotron-voicechat.md` has a clearly marked real-time-factor placeholder table (4-bit and 8-bit), because the GPU was shared during this run. The per-frame profiler lands with #1378. ## Deviations from the issue body (reference wins) - **Checkpoint layout:** the checkpoint is in torch layout (conv kernels, LSTM names, `_control_codes`). The loaders convert it with idempotent shape gates. - **Subsampling:** the frequency axis after subsampling is 17, not 16 (`pre_encode.out` is 4352 wide). - **Codec layer count:** the codec has 13 layers per side, not 16. - **Codec SNR:** the tone SNR > 20 dB target is unreachable. The reference itself gets 0.7 dB, so parity is checked against the reference reconstruction instead. - **Runtime dtypes:** perception, the TTS backbone, and the MoG head run in f32 against bf16 weights, as in the reference. - **bf16 reductions:** `mlxcel_core::sum_axis` widens bf16 to f32 and rounds once, which does not match MLX's native bf16 reduction. Code selection therefore uses a native einsum reduction (`audio::native_reduce`). - **Offline LLM mode:** the reference offline path recomputes the full history by default. This port keeps the Nemotron-H caches, which gives identical tokens and codes in the reference. ## Changes during review - VoiceChat has no chat surface: interactive `generate` without `--audio`, `mlxcel chat`, and `mlxcel serve` now refuse it with a pointer to the offline command (`/v1/realtime` is #1376). `-m` is resolved before the no-`-p` routing decision so repo ids route too. - Load-time checks for the perception projection width and TTS/codec codebook agreement turn a malformed checkpoint into an error instead of an MLX abort. `--extra-decoding-seconds` is capped at 600 s and an offline turn at 20 minutes (dense encoder mask). - Unit tests for the key renames, `forward_embeds_to_hidden` against the id path, both heads, and config validation. - Not changed: the front-end loaders pass the default `(64, 4)` quantization pair, which only matters if a future conversion quantizes the perception or RNNT layers (today they are dense and `UnifiedLinear` keys off `.scales`). Closes #1374
inureyes
added a commit
that referenced
this pull request
Sep 29, 2026
) ## Summary PR #2031 (issue #1367) changed `has_vision_config` so that an empty or null `vision_config` counts as text-only. Three existing tests still used `"vision_config": {}` as their VLM fixture, so they failed on main after the merge. The unit that implemented #1367 ran only its own test filters, so the failures surfaced in the post-merge integration gate of the auto-impl run. ## Changes - `src/models/detection_tests.rs`: `has_vision_config_detects_vlm_configs` and `detect_text_or_vlm_prefers_vlm_when_vision_config_exists` use a non-empty `vision_config`. The first also asserts that `{}` is now text-only, so the test documents the new rule. - `src/server/webui/catalog_contract_tests.rs`: `bounded_catalog_detection_reports_unknown_when_weight_index_is_required` uses a non-empty `vision_config` for `kimi_k3`, so detection still reaches the weight-index probe the test is about. No production code changes. ## Verification - `cargo test --release -p mlxcel --lib`: 8683 passed, 0 failed, 155 ignored (previously 3 failed). - `cargo fmt --all -- --check`: clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Vision-stripped VLM checkpoints now load text-only. Detection treats an absent,
nullor emptyvision_config, andlanguage_model_only: true, as text-only (the flag wins over shipped weights, with a one-line stderr notice), and forqwen3_5,qwen3_5_moeandgemma3also scans the safetensors index or shard headers for vision tower prefixes.llama4,mistral3andgemma3nget the config rules only, because a tower under an unlisted prefix would misroute to text.The Qwen2-VL, Qwen2.5-VL, Qwen3-VL and Qwen3-VL-MoE loaders call the same
vlm_has_visiondecision (theirModelTypes are unchanged) and load withvision_encoder: None. Image and video requests are refused incompute_qwen_vl_media_embeddingswithmodel <path> was loaded without a vision tower (text-only checkpoint).language_model_only: trueis no longer an error invalidate_qwen35_wrapper_config; a non-boolean value still is.Discrepancies with the issue text: line numbers were stale (
gemma4_has_vision_weightsis atdetection.rs:234), and the weight scan is a new probe method so the bounded catalog probes keep the config answer when no index is readable.mlxcel listcapability reporting is static permodel_typeand is not changed; the runtime refusal is the enforcement.Test plan
cargo test --release --lib text_only(new detection tests, syntheticqwen3_vlloader tests) andlanguage_model_onlycargo fmt --all -- --check,cargo clippy --release -p mlxcel --lib --tests -- -D warningscli_help_consistency,dead_doc_pointers,llama_compat_manifestvision_config: {},language_model_only: true, fullvision_config, both): identical greedy output;--imagereturns an error, no panicCloses #1367