Skip to content

feat(detection): route vision-stripped VLM checkpoints to a text-only path - #2031

Merged
inureyes merged 1 commit into
mainfrom
feature/issue-1367-text-only-vlm-detection
Sep 29, 2026
Merged

inureyes merged 1 commit into
mainfrom
feature/issue-1367-text-only-vlm-detection

Conversation

@inureyes

Copy link
Copy Markdown
Member

Summary

Vision-stripped VLM checkpoints now load text-only. Detection treats an absent, null or empty vision_config, and language_model_only: true, as text-only (the flag wins over shipped weights, with a one-line stderr notice), and for qwen3_5, qwen3_5_moe and gemma3 also scans the safetensors index or shard headers for vision tower prefixes. llama4, mistral3 and gemma3n get 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_vision decision (their ModelTypes are unchanged) and load with vision_encoder: None. Image and video requests are refused in compute_qwen_vl_media_embeddings with model <path> was loaded without a vision tower (text-only checkpoint). language_model_only: true is no longer an error in validate_qwen35_wrapper_config; a non-boolean value still is.

Discrepancies with the issue text: line numbers were stale (gemma4_has_vision_weights is at detection.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 list capability reporting is static per model_type and is not changed; the runtime refusal is the enforcement.

Test plan

  • cargo test --release --lib text_only (new detection tests, synthetic qwen3_vl loader tests) and language_model_only
  • cargo fmt --all -- --check, cargo clippy --release -p mlxcel --lib --tests -- -D warnings
  • cli_help_consistency, dead_doc_pointers, llama_compat_manifest
  • ThinkingCap-Qwen3.6-27B-3bit-mlx under five config variants (original, vision_config: {}, language_model_only: true, full vision_config, both): identical greedy output; --image returns an error, no panic

Closes #1367

… 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 inureyes added status:review Under review type:enhancement New features, capabilities, or significant additions priority:low Low priority area:models Model architectures, weights, loading, metadata area:inference Generation, sampling, decoding (incl. speculative, DRY) status:done Completed and removed status:review Under review labels Sep 29, 2026
@inureyes
inureyes merged commit 2aa3a81 into main Sep 29, 2026
25 checks passed
@inureyes
inureyes deleted the feature/issue-1367-text-only-vlm-detection branch September 29, 2026 07:22
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.
@inureyes inureyes added this to the 0.8 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:inference Generation, sampling, decoding (incl. speculative, DRY) area:models Model architectures, weights, loading, metadata priority:low Low priority status:done Completed type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(detection): route vision-stripped VLM checkpoints to a text-only path

1 participant