Repository navigation
feat(models): qualify Qwen3.8-27B on the qwen3_5 path - #1174
Conversation
Qwen3.8-27B declares `model_type: "qwen3_5"` and is architecturally identical to Qwen3.5-27B, so it already loaded and ran on main with zero code changes. That was accidental rather than guaranteed: `Qwen35Config` carries no `deny_unknown_fields`, so every key the generation added was dropped silently, including three that are load-bearing upstream. This registers the checkpoint and converts those silent drops into explicit reads or named errors. Three ignored keys now fail loudly instead of loading wrong. `text_config.output_gate_type` selects the gated-delta output gate in vLLM; mlxcel hardcodes SiLU in `RMSNormGated::forward`, so `Qwen35Config::validate_supported` accepts `silu`, `swish`, and absent, and rejects anything else (notably `sigmoid`). `rope_parameters.mrope_interleaved` is rejected when explicitly `false`, since `InterleavedMRoPE` is unconditional. Top-level `language_model_only: true` is rejected by `validate_qwen35_wrapper_config` in the VLM loader only, matching the still-open upstream gap in Neywa-Labs/mlx-vlm#1812; it is not an error on the text-only path, where a vision-stripped checkpoint is what the caller asked for. Validation is wired into every Qwen3.5-family parse site: the text loader, the pipeline-stage loader, the VLM loader, the from-weights special path, and the tensor-parallel runtime. The Qwen3.5 family no longer defaults `vision_start_token_id`. The old 248045 fallback is stale for every shipped checkpoint in the family (Qwen3.5-0.8B through 27B, the 3.5/3.6 MoE builds, and Qwen3.8-27B all declare 248053), and a wrong start id mis-segments MRoPE vision spans quietly instead of failing. `qwen35_vl_token_ids` requires the key and keeps the image/video defaults, which do match. The shared `qwen_vl_token_ids` is untouched, so Qwen2-VL, Qwen2.5-VL, Qwen3-VL, Qwen3-VL MoE, and GLM-4V keep their own defaults; a new test pins that. Premise correction on the two upstream ports the issue asked for. Both were already implemented on main and neither needed porting. `apply_structured_mask_to_logits` (src/server/structured.rs:736-788) already sizes the bias from the model's logits axis and masks the padded rows, which is what Neywa-Labs/mlx-vlm#1805 fixes. `forward_with_mrope_state` already sliced the stored `position_ids` to the chunk window and additionally validated the batch dimension, a superset of Neywa-Labs/mlx-vlm#1741. What landed instead is coverage: a regression test pinning the 248077-into-248320 shape at production magnitudes, and the MRoPE reuse decision extracted into a pure `mrope_position_source` helper with four unit tests. Behavior is unchanged in both cases. Validated on the real checkpoint at models/qwen3.8-27b-4bit. CLI text answers 17x23 correctly at 18.81 tok/s, CLI image names both shapes in the synthetic fixture. Qwen3.5-27B, Qwen2.5-VL-3B, and Qwen3-VL-4B all still load and answer, proving the shared token-id path did not regress. All four rejection paths were driven end to end against config variants of the real checkpoint and produced their named errors. Refs #1163
Implementation Review SummaryIntentQualify Findings AddressedNone. No CRITICAL or HIGH finding was raised, so no auto-fix commit was made and the branch is unchanged at Verification performedShared VLM path, regression risk:
Rejection scoping:
Premise-correction pinning tests, checked by mutation:
Documentation, checked against the artifacts:
Remaining Items
Verification
|
Security and performance reviewNo CRITICAL and no HIGH findings, so nothing was auto-fixed and no commits were pushed. Three MEDIUM and three LOW items below, plus the negative results, which are the more useful half of this review. Verified cleanNo panic on adversarial config. 14 malformed No terminal escape or log injection. The only new error interpolating config content is The two Performance is neutral. All three validators run once per model load, from the five loader entry points, never per request or per token. MEDIUMM1. M2. Two of the three new guards are bypassed by a type mismatch, silently. M3. LOWL1. Availability blast radius of the mandatory L2. Unbounded config value echoed into the error. Measured: a config with a 1,002,990-byte L3. The new |
… review Wires `Qwen35Config::validate_supported()` into the MiniCPM-V 4.6 text-backbone loader, the sixth Qwen3.5-family parse site that PR #1174 deliberately skipped; the invariant belongs to `Qwen35Model`, not to the `qwen3_5` model_type string, so a MiniCPM-V 4.6 checkpoint declaring `output_gate_type: "sigmoid"` reproduced the exact silently-wrong-output failure the PR set out to close. Verified against both local MiniCPM-V 4.6 checkpoints (bf16 and mxfp4): neither declares `output_gate_type` or `mrope_interleaved`, so no working load turns into a failure. `validate_qwen35_wrapper_config` and `Qwen35Config::mrope_interleaved()` used `.as_bool()`, so a present-but-wrong-typed value (`language_model_only: "true"`, `1`, `{}`; `mrope_interleaved: "false"`, `0`) read as absent and loaded silently instead of hitting the named error the correctly-typed value would trigger. Both are now checked strictly through new named errors (`LanguageModelOnlyWrongType`, `MropeInterleavedWrongType`), with the offending value capped to 64 characters before it is echoed into the error text. `qwen35_vl_token_ids` cast `vision_start_token_id` (and `image_token_id`/`video_token_id`) from `i64` to `i32` with an unchecked `as i32`; a checkpoint value like 2^40 truncated to 0 and a negative value passed through unchanged, both loading with no diagnostic. All three ids are now converted with `i32::try_from` and bounds-checked against the checkpoint's own `vocab_size`. `output_gate_type` matching was exact and case-sensitive against `{"silu", "swish"}`; a checkpoint spelling it `"SiLU"` would have hard-failed a load the implemented path already handles correctly. Matching is now case-insensitive via `eq_ignore_ascii_case`. Validation: `cargo test --release -p mlxcel --lib --features metal,accelerate qwen3_5` (25 passed, 11 ignored, 0 failed) and `... loading::vlm` (178 passed, 0 failed), `cargo clippy --release --lib --tests --features metal,accelerate -- -D warnings` (clean), `cargo fmt --check` (clean). Both premise-correction pins from the parent PR were mutation-verified and then reverted: forcing `apply_structured_mask_to_logits` to size the bias from the matcher vocabulary instead of `vocab_size_hint` aborts the process on an MLX broadcast-shape mismatch, and dropping the `shape[1] == batch` check in `mrope_position_source` fails `mrope_position_source_rejects_a_batch_mismatch_and_a_wrong_rank`. Refs #1163, #1174
… attribution `docs/supported-models.md`: Qwen3.5-VL and Qwen3.8-VL appeared in two consecutive bullets, the family summary line and the detailed entry right after it; every other family in that list appears once, so the summary line now omits them and the detail bullet stays the only mention. The KV-footprint sentence claimed the measured 64.1 KiB/token figure was "exactly" the 65,536 B/token (64.0 KiB) architectural minimum for the 16 full-attention layers; the two differ by about 0.16%, so the wording now states the measured and theoretical numbers as the two distinct things they are instead of collapsing them into one. The weight-map key list (`model.language_model.*`, `model.visual.*`, `mtp.*`, `lm_head.weight`) described the upstream `Qwen/Qwen3.8-27B` repo, while the checkpoint named as validated in that same sentence is the `mlx-community` 4-bit conversion, whose weight map is `language_model.*` (with `lm_head.*` folded inside that prefix) and `vision_tower.*`, with `mtp.*` dropped entirely; verified against both checkpoints' `model.safetensors.index.json` locally. Each list is now attributed to the repo it actually describes. `CHANGELOG.md`: adds the `## [Unreleased]` entry for #1163, including the upgrade note that making `vision_start_token_id` mandatory for the Qwen3.5-family VLM path can turn a previously-working server deployment into a startup failure if a checkpoint's config omits the key. Refs #1163, #1174
Records the five code findings closed and three doc findings corrected during finalization, the local-checkpoint check that cleared S-M1's new validate_supported() call site before wiring it in, and the mutation-verified confirmation of both premise-correction pins (the padded-vocab structured-output mask and the chunked-MRoPE position-slice reuse condition) that PR #1174 confirmed rather than re-implemented. Refs #1163, #1174
Orchestrator verificationFull workspace suite re-run after the finalization commits, Totals: 6059 passed, 4 failed. The mlxcel lib went 5621 (pre-PR baseline) to 5665, so this PR net-added 44 tests. Both failure groups are pre-existing and attributed, neither is a regression:
Real-checkpoint validationServer surface re-verified on this branch against
Both On the premise correctionWorth restating for the record, because it changed what this PR is. Two of the issue's six deliverables asked to port Neywa-Labs/mlx-vlm#1805 and #1741. Both were already implemented in this tree, and #1741's equivalent here is strictly stronger than upstream (it also validates the batch dimension before reusing stored positions). The deliverable became confirm-and-pin, and both pins were mutation-verified twice, independently, by the reviewer and the finalizer. That correction is the orchestrator's error to own: the issue was written without checking the code closely enough. Recording it here so the next person reads the pins as deliberate rather than redundant. |
## Summary
Qualifies `mlx-community/Qwen3.8-27B-4bit` on the existing `qwen3_5` path. Qwen3.8-27B declares `model_type: "qwen3_5"` / `Qwen3_5ForConditionalGeneration` and is architecturally identical to Qwen3.5-27B down to a byte-identical weight-map key set, so it already loaded and ran on `main` with zero code changes. That was accidental rather than guaranteed: `Qwen35Config` carries no `deny_unknown_fields`, so every key the generation added was dropped silently, three of which are load-bearing upstream. This PR registers the checkpoint in the docs and the real-model tests and converts those silent drops into explicit reads or named errors. No new model family, no inference-math change.
## Premise correction: the two upstream ports were already implemented
The issue asked to port two post-pin mlx-vlm fixes. Both were verified present on `main` @ `865bede2` before any code was written, so per CLAUDE.md ("Verify the premise before building. If it does not hold, correcting the premise with evidence *is* the deliverable") the deliverable became confirm, pin, and correct the issue. Neither was re-implemented, and neither was skipped. Both pins were re-verified by mutation testing during finalization (see below): forcing the mask helper to size from the matcher's vocabulary instead of the model's logits axis aborts the process on an MLX broadcast-shape mismatch, and dropping the MRoPE reuse condition's batch check fails its own regression test.
**Neywa-Labs/mlx-vlm#1805, padded-vocab structured-output mask: already correct.** `apply_structured_mask_to_logits` at `src/server/structured.rs:736-788` already pins the bias length to `vocab_size_hint`, the model's logits axis, not to the matcher's vocabulary (`let vocab_size = vocab_size_hint;` at `:747`), and already masks every position in `[matcher_vocab, vocab_size_hint)` via `let allowed = i < mask_len && constraint.mask_buf[i];` at `:780`. Its doc comment at `:718-735` names this exact case ("the model has padded its embedding table beyond the tokenizer's natural vocabulary"). The scheduler call site at `src/server/batch/scheduler.rs:2988` passes the hint through unchanged. What this PR adds instead is `apply_mask_covers_the_qwen3_8_padded_lm_head` in `tests/structured_outputs.rs`, which builds a synthetic 248,077-entry byte-level tokenizer and pins the real 248077-into-248320 shape: the bias must come back 248320 long, and all 243 unnameable rows must be `-inf`. The pre-existing generic test used a 16-row gap; this one fails with the checkpoint's own numbers if a refactor starts sizing the bias from the matcher. It runs in 0.48s.
**Neywa-Labs/mlx-vlm#1741, chunked MRoPE position slice: already correct, and stronger.** `Qwen35Model::forward_with_mrope_state` in `src/models/qwen3_5.rs` already sliced the stored `position_ids` to `[cache_offset, cache_offset + seq_len)` during chunked prefill, already validated `pos_shape[1] == batch` before reuse (Neywa-Labs/mlx-vlm#1040, which lablup#1741 does not do), and already fell back to delta-based compute when the stored tensor no longer covered the window. The comment block already cited the upstream lineage. It was untestable without a 16 GB checkpoint, so the reuse decision moved into a pure `mrope_position_source(stored_shape, batch, seq_len, cache_offset) -> MRopePositionSource` helper covered by four unit tests. Behavior is byte-for-byte unchanged; the bare `lablup#1048` / `lablup#1040` cross-repo refs in that comment were also qualified per CLAUDE.md.
## What changed
- `src/models/qwen3_5.rs`: adds `Qwen35Config::output_gate_type` and `mrope_interleaved()`, a `Qwen35UnsupportedConfig` error enum, `Qwen35Config::validate_supported()` for the text-config keys, `validate_qwen35_wrapper_config()` for the top-level `language_model_only`, and the extracted `mrope_position_source` / `MRopePositionSource` pair that `forward_with_mrope_state` now calls.
- Validation is wired into every Qwen3.5-family parse site, all six of them: `Qwen35Model::load`, the pipeline-stage loader, `src/loading/vlm_qwen.rs` (VLM), `src/loading/special.rs` (from-weights special path), `src/distributed/tensor_parallel/llama_runtime.rs` (TP), and (added in finalization) `src/loading/vlm_special.rs`'s MiniCPM-V 4.6 text-backbone loader. MiniCPM-V 4.6 reuses `Qwen35Config` as its language backbone, and the gated-delta / MRoPE invariants `validate_supported` enforces belong to `Qwen35Model` itself, not to the `qwen3_5` model_type string, so excluding this site was a review finding (S-M1) rather than a deliberate design choice. Both local MiniCPM-V 4.6 checkpoints (bf16 and mxfp4) were checked before wiring the call in: neither declares `output_gate_type` or `mrope_interleaved`, so no working load turns into a startup failure.
- `src/loading/vlm.rs`: replaces `qwen35_vlm_token_defaults()` with `qwen35_vl_token_ids()`, which requires `vision_start_token_id` from the config for this family and keeps the image/video defaults. The stale 248045 fallback is gone. All three vision token ids are now range-checked against the checkpoint's own `vocab_size` (added in finalization; see S-M3 below). The shared `qwen_vl_token_ids` is untouched, so Qwen2-VL, Qwen2.5-VL, Qwen3-VL, Qwen3-VL MoE, and GLM-4V keep their existing defaults. `vision_end_token_id` is deliberately not read: nothing in the tree consumes it, so a field would be dead code.
- `src/models/qwen3_5_tests.rs`: a config-shape fixture pinned to the published `config.json` (inline, so it runs without the checkpoint) asserting that `output_gate_type`, `attn_output_gate`, `mamba_ssm_dtype`, `mtp_num_hidden_layers`, the duplicated top-level `partial_rotary_factor`, the absent `mlp_only_layers`, and the nested `generation_config` all still parse; plus accept and reject cases for each of the three keys, and four `mrope_position_source` tests.
- `src/loading/vlm_tests.rs`: a non-regression test walking the five families that still use `qwen_vl_token_ids`, and three tests for the new Qwen3.5 resolver.
- `tests/tensor_parallel_real_models.rs`: `qwen3_8_27b_tp4_matches_single_rank_stepwise`, next to the existing `qwen3.5-27b-4bit` entry, using the same `repo_model_dir` + skip-if-absent pattern.
- `docs/supported-models.md`: names `mlx-community/Qwen3.8-27B-4bit` as the validated checkpoint with the measured decode and cache-footprint numbers, states the three unsupported surfaces (MTP lablup#1165, video lablup#1166, no audio tower at all), and records that despite the family naming this is a vision-only VLM, not an omni model.
## Finalization (post-review hardening)
Review and security passes reported no CRITICAL or HIGH findings. This pass closed five code findings and corrected three documentation findings; commits `4e2fab1e` (code), `298b511e` (docs + `CHANGELOG.md`), `7a9c6d87` (technical reports).
- **S-M1** (Medium): `validate_supported()` was missing from the sixth `Qwen35Config` parse site, the MiniCPM-V 4.6 text backbone (`src/loading/vlm_special.rs`). Fixed by wiring the call in, right after `text_config` is parsed and before any weight is read. Confirmed safe against both local MiniCPM-V 4.6 checkpoints first (see above).
- **S-M2** (Medium): `validate_qwen35_wrapper_config` and `Qwen35Config::mrope_interleaved()` used `.as_bool()`, so a present-but-wrong-typed value (`language_model_only: "true"`/`1`/`{}`, `mrope_interleaved: "false"`/`0`) silently read as absent and loaded instead of hitting the named error. Fixed with two new `Qwen35UnsupportedConfig` variants (`LanguageModelOnlyWrongType`, `MropeInterleavedWrongType`) and a private strict accessor used only by `validate_supported`.
- **S-M3** (Medium): `qwen35_vl_token_ids` cast `vision_start_token_id`/`image_token_id`/`video_token_id` from `i64` to `i32` with an unchecked truncating `as i32`; `vision_start_token_id: 1099511627776` (2^40) used to truncate to 0 and `-5` loaded unchanged, both with no diagnostic. Fixed with `i32::try_from` plus a range check against the checkpoint's own `vocab_size`, shared by all three ids via a new `qwen35_vl_token_id_in_range` helper.
- **R-M2** (Medium): `output_gate_type` matching was exact and case-sensitive against `{"silu", "swish"}`. Fixed with `eq_ignore_ascii_case`.
- **S-L2** (Low): The `OutputGateType` error echoed the offending config value uncapped; a 1,002,990-byte value reproduced as 1,000,568 bytes of process output. Fixed with a shared `truncate_for_error` helper (64-char cap) used by all three wrong-value error variants.
- **R-M1** (doc): Qwen3.5-VL and Qwen3.8-VL appeared in two consecutive `docs/supported-models.md` bullets. Collapsed to the one detailed bullet.
- **R-L1** (doc): The KV-footprint sentence called the measured 64.1 KiB/token figure "exactly" the 65,536 B/token (64.0 KiB) architectural minimum; they differ by about 0.16%. Reworded to state both numbers as the distinct things they are.
- **R-L2** (doc): The weight-map key list in that paragraph described the upstream `Qwen/Qwen3.8-27B` repo, not the `mlx-community/Qwen3.8-27B-4bit` conversion named as validated in the same sentence. Split the list and attributed each half to the repo it actually describes, verified against both checkpoints' `model.safetensors.index.json`.
- `CHANGELOG.md` gained the `## [Unreleased]` entry for lablup#1163, including the upgrade note that making `vision_start_token_id` mandatory can turn a previously-working deployment into a startup failure if a checkpoint's config omits the key.
Finalization test plan (all commands `DEVELOPER_DIR=/Applications/Xcode-26.6.0.app/Contents/Developer`, `--release --features metal,accelerate`):
- [x] `cargo test --release -p mlxcel --lib --features metal,accelerate qwen3_5` — 25 passed, 11 ignored (pre-existing serial-MLX gates), 0 failed.
- [x] `cargo test --release -p mlxcel --lib --features metal,accelerate loading::vlm` — 178 passed, 0 failed, including a new end-to-end wiring test (`load_minicpmv4_6_vlm_rejects_an_unsupported_output_gate_type`) that drives the real `load_minicpmv4_6_vlm` entry point rather than only the shared config helper.
- [x] `cargo clippy --release --lib --tests --features metal,accelerate -- -D warnings` — clean.
- [x] `cargo fmt --check` — clean.
- [x] Mutation-verified both premise-correction pins, then reverted: forcing `apply_structured_mask_to_logits` to size from the matcher vocabulary aborts `apply_mask_covers_the_qwen3_8_padded_lm_head` on an MLX broadcast-shape mismatch; dropping the `shape[1] == batch` check in `mrope_position_source` fails `mrope_position_source_rejects_a_batch_mismatch_and_a_wrong_rank`.
## Test plan
Every command ran with `DEVELOPER_DIR=/Applications/Xcode-26.6.0.app/Contents/Developer` and `--release --features metal,accelerate` (the debug profile cannot build on this box).
- [x] `cargo test --release -p mlxcel --lib --features metal,accelerate qwen3_5_tests::` — 11 passed, 11 ignored (pre-existing serial-MLX gates), 0 failed.
- [x] `cargo test --release -p mlxcel --lib --features metal,accelerate loading::vlm` — 173 passed, 0 failed.
- [x] `cargo test --release -p mlxcel --lib --features metal,accelerate qwen35` — 10 passed, 4 ignored (need CUDA), 0 failed.
- [x] `cargo test --release --features metal,accelerate --test structured_outputs` — 16 passed, 2 ignored (need local weights), 0 failed, including the new padded-lm_head test.
- [x] `cargo clippy --release --features metal,accelerate -p mlxcel --lib --tests -- -D warnings` — clean.
- [x] `cargo fmt` on every touched file; `python3 scripts/ci/check_cross_repo_refs.py` — OK.
- [x] Real checkpoint, CLI text: `mlxcel generate -m models/qwen3.8-27b-4bit -p "What is 17 times 23?" -n 300 --temp 0` answers `391` at 18.81 tok/s, within noise of the 18.21 tok/s baseline recorded in the issue.
- [x] Real checkpoint, CLI image: 224x224 synthetic PNG (red circle, blue square), `--image ... -p "Describe the shapes and their colors" -n 400 --temp 0` inserts 49 image tokens and names both shapes with the correct colors and positions.
- [x] Shared-path non-regression, other Qwen VL families: `models/qwen3.5-27b-4bit` (49 image tokens, both shapes correct), `models/qwen3-vl-4b-4bit` (49 image tokens, both shapes correct), `models/qwen2.5-vl-3b-4bit` (64 image tokens, loads and answers; the answer quality is that 3B model's own, and the code path is untouched by this PR).
- [x] All four rejection paths driven end to end against config variants of the real 16 GB checkpoint (weights symlinked, `config.json` patched): `language_model_only: true`, `output_gate_type: "sigmoid"`, `mrope_interleaved: false`, and a removed `vision_start_token_id` each abort the load with their named error instead of loading.
Not verified here: the server surface (text and image over `/v1/chat/completions`) was not re-run, since the change is confined to config validation at load time and to token-id resolution, both of which the CLI exercises on the same code path. The TP real-model test is `#[ignore]`d in line with its Qwen3.5 sibling and was not run.
Closes lablup#1163
Summary
Qualifies
mlx-community/Qwen3.8-27B-4biton the existingqwen3_5path. Qwen3.8-27B declaresmodel_type: "qwen3_5"/Qwen3_5ForConditionalGenerationand is architecturally identical to Qwen3.5-27B down to a byte-identical weight-map key set, so it already loaded and ran onmainwith zero code changes. That was accidental rather than guaranteed:Qwen35Configcarries nodeny_unknown_fields, so every key the generation added was dropped silently, three of which are load-bearing upstream. This PR registers the checkpoint in the docs and the real-model tests and converts those silent drops into explicit reads or named errors. No new model family, no inference-math change.Premise correction: the two upstream ports were already implemented
The issue asked to port two post-pin mlx-vlm fixes. Both were verified present on
main@865bede2before any code was written, so per CLAUDE.md ("Verify the premise before building. If it does not hold, correcting the premise with evidence is the deliverable") the deliverable became confirm, pin, and correct the issue. Neither was re-implemented, and neither was skipped. Both pins were re-verified by mutation testing during finalization (see below): forcing the mask helper to size from the matcher's vocabulary instead of the model's logits axis aborts the process on an MLX broadcast-shape mismatch, and dropping the MRoPE reuse condition's batch check fails its own regression test.Neywa-Labs/mlx-vlm#1805, padded-vocab structured-output mask: already correct.
apply_structured_mask_to_logitsatsrc/server/structured.rs:736-788already pins the bias length tovocab_size_hint, the model's logits axis, not to the matcher's vocabulary (let vocab_size = vocab_size_hint;at:747), and already masks every position in[matcher_vocab, vocab_size_hint)vialet allowed = i < mask_len && constraint.mask_buf[i];at:780. Its doc comment at:718-735names this exact case ("the model has padded its embedding table beyond the tokenizer's natural vocabulary"). The scheduler call site atsrc/server/batch/scheduler.rs:2988passes the hint through unchanged. What this PR adds instead isapply_mask_covers_the_qwen3_8_padded_lm_headintests/structured_outputs.rs, which builds a synthetic 248,077-entry byte-level tokenizer and pins the real 248077-into-248320 shape: the bias must come back 248320 long, and all 243 unnameable rows must be-inf. The pre-existing generic test used a 16-row gap; this one fails with the checkpoint's own numbers if a refactor starts sizing the bias from the matcher. It runs in 0.48s.Neywa-Labs/mlx-vlm#1741, chunked MRoPE position slice: already correct, and stronger.
Qwen35Model::forward_with_mrope_stateinsrc/models/qwen3_5.rsalready sliced the storedposition_idsto[cache_offset, cache_offset + seq_len)during chunked prefill, already validatedpos_shape[1] == batchbefore reuse (Neywa-Labs/mlx-vlm#1040, which #1741 does not do), and already fell back to delta-based compute when the stored tensor no longer covered the window. The comment block already cited the upstream lineage. It was untestable without a 16 GB checkpoint, so the reuse decision moved into a puremrope_position_source(stored_shape, batch, seq_len, cache_offset) -> MRopePositionSourcehelper covered by four unit tests. Behavior is byte-for-byte unchanged; the bare#1048/#1040cross-repo refs in that comment were also qualified per CLAUDE.md.What changed
src/models/qwen3_5.rs: addsQwen35Config::output_gate_typeandmrope_interleaved(), aQwen35UnsupportedConfigerror enum,Qwen35Config::validate_supported()for the text-config keys,validate_qwen35_wrapper_config()for the top-levellanguage_model_only, and the extractedmrope_position_source/MRopePositionSourcepair thatforward_with_mrope_statenow calls.Qwen35Model::load, the pipeline-stage loader,src/loading/vlm_qwen.rs(VLM),src/loading/special.rs(from-weights special path),src/distributed/tensor_parallel/llama_runtime.rs(TP), and (added in finalization)src/loading/vlm_special.rs's MiniCPM-V 4.6 text-backbone loader. MiniCPM-V 4.6 reusesQwen35Configas its language backbone, and the gated-delta / MRoPE invariantsvalidate_supportedenforces belong toQwen35Modelitself, not to theqwen3_5model_type string, so excluding this site was a review finding (S-M1) rather than a deliberate design choice. Both local MiniCPM-V 4.6 checkpoints (bf16 and mxfp4) were checked before wiring the call in: neither declaresoutput_gate_typeormrope_interleaved, so no working load turns into a startup failure.src/loading/vlm.rs: replacesqwen35_vlm_token_defaults()withqwen35_vl_token_ids(), which requiresvision_start_token_idfrom the config for this family and keeps the image/video defaults. The stale 248045 fallback is gone. All three vision token ids are now range-checked against the checkpoint's ownvocab_size(added in finalization; see S-M3 below). The sharedqwen_vl_token_idsis untouched, so Qwen2-VL, Qwen2.5-VL, Qwen3-VL, Qwen3-VL MoE, and GLM-4V keep their existing defaults.vision_end_token_idis deliberately not read: nothing in the tree consumes it, so a field would be dead code.src/models/qwen3_5_tests.rs: a config-shape fixture pinned to the publishedconfig.json(inline, so it runs without the checkpoint) asserting thatoutput_gate_type,attn_output_gate,mamba_ssm_dtype,mtp_num_hidden_layers, the duplicated top-levelpartial_rotary_factor, the absentmlp_only_layers, and the nestedgeneration_configall still parse; plus accept and reject cases for each of the three keys, and fourmrope_position_sourcetests.src/loading/vlm_tests.rs: a non-regression test walking the five families that still useqwen_vl_token_ids, and three tests for the new Qwen3.5 resolver.tests/tensor_parallel_real_models.rs:qwen3_8_27b_tp4_matches_single_rank_stepwise, next to the existingqwen3.5-27b-4bitentry, using the samerepo_model_dir+ skip-if-absent pattern.docs/supported-models.md: namesmlx-community/Qwen3.8-27B-4bitas the validated checkpoint with the measured decode and cache-footprint numbers, states the three unsupported surfaces (MTP feat(inference): support the qwen3_5_mtp drafter for Qwen3.5/3.6/3.8 MTP speculative decoding #1165, video feat(models): video input for the Qwen VL families (Qwen3.5-VL / Qwen3.8, then the rest) #1166, no audio tower at all), and records that despite the family naming this is a vision-only VLM, not an omni model.Finalization (post-review hardening)
Review and security passes reported no CRITICAL or HIGH findings. This pass closed five code findings and corrected three documentation findings; commits
4e2fab1e(code),298b511e(docs +CHANGELOG.md),7a9c6d87(technical reports).validate_supported()was missing from the sixthQwen35Configparse site, the MiniCPM-V 4.6 text backbone (src/loading/vlm_special.rs). Fixed by wiring the call in, right aftertext_configis parsed and before any weight is read. Confirmed safe against both local MiniCPM-V 4.6 checkpoints first (see above).validate_qwen35_wrapper_configandQwen35Config::mrope_interleaved()used.as_bool(), so a present-but-wrong-typed value (language_model_only: "true"/1/{},mrope_interleaved: "false"/0) silently read as absent and loaded instead of hitting the named error. Fixed with two newQwen35UnsupportedConfigvariants (LanguageModelOnlyWrongType,MropeInterleavedWrongType) and a private strict accessor used only byvalidate_supported.qwen35_vl_token_idscastvision_start_token_id/image_token_id/video_token_idfromi64toi32with an unchecked truncatingas i32;vision_start_token_id: 1099511627776(2^40) used to truncate to 0 and-5loaded unchanged, both with no diagnostic. Fixed withi32::try_fromplus a range check against the checkpoint's ownvocab_size, shared by all three ids via a newqwen35_vl_token_id_in_rangehelper.output_gate_typematching was exact and case-sensitive against{"silu", "swish"}. Fixed witheq_ignore_ascii_case.OutputGateTypeerror echoed the offending config value uncapped; a 1,002,990-byte value reproduced as 1,000,568 bytes of process output. Fixed with a sharedtruncate_for_errorhelper (64-char cap) used by all three wrong-value error variants.docs/supported-models.mdbullets. Collapsed to the one detailed bullet.Qwen/Qwen3.8-27Brepo, not themlx-community/Qwen3.8-27B-4bitconversion named as validated in the same sentence. Split the list and attributed each half to the repo it actually describes, verified against both checkpoints'model.safetensors.index.json.CHANGELOG.mdgained the## [Unreleased]entry for feat(models): qualify and register Qwen3.8 (Qwen3.8-27B) on the existing qwen3_5 path #1163, including the upgrade note that makingvision_start_token_idmandatory can turn a previously-working deployment into a startup failure if a checkpoint's config omits the key.Finalization test plan (all commands
DEVELOPER_DIR=/Applications/Xcode-26.6.0.app/Contents/Developer,--release --features metal,accelerate):cargo test --release -p mlxcel --lib --features metal,accelerate qwen3_5— 25 passed, 11 ignored (pre-existing serial-MLX gates), 0 failed.cargo test --release -p mlxcel --lib --features metal,accelerate loading::vlm— 178 passed, 0 failed, including a new end-to-end wiring test (load_minicpmv4_6_vlm_rejects_an_unsupported_output_gate_type) that drives the realload_minicpmv4_6_vlmentry point rather than only the shared config helper.cargo clippy --release --lib --tests --features metal,accelerate -- -D warnings— clean.cargo fmt --check— clean.apply_structured_mask_to_logitsto size from the matcher vocabulary abortsapply_mask_covers_the_qwen3_8_padded_lm_headon an MLX broadcast-shape mismatch; dropping theshape[1] == batchcheck inmrope_position_sourcefailsmrope_position_source_rejects_a_batch_mismatch_and_a_wrong_rank.Test plan
Every command ran with
DEVELOPER_DIR=/Applications/Xcode-26.6.0.app/Contents/Developerand--release --features metal,accelerate(the debug profile cannot build on this box).cargo test --release -p mlxcel --lib --features metal,accelerate qwen3_5_tests::— 11 passed, 11 ignored (pre-existing serial-MLX gates), 0 failed.cargo test --release -p mlxcel --lib --features metal,accelerate loading::vlm— 173 passed, 0 failed.cargo test --release -p mlxcel --lib --features metal,accelerate qwen35— 10 passed, 4 ignored (need CUDA), 0 failed.cargo test --release --features metal,accelerate --test structured_outputs— 16 passed, 2 ignored (need local weights), 0 failed, including the new padded-lm_head test.cargo clippy --release --features metal,accelerate -p mlxcel --lib --tests -- -D warnings— clean.cargo fmton every touched file;python3 scripts/ci/check_cross_repo_refs.py— OK.mlxcel generate -m models/qwen3.8-27b-4bit -p "What is 17 times 23?" -n 300 --temp 0answers391at 18.81 tok/s, within noise of the 18.21 tok/s baseline recorded in the issue.--image ... -p "Describe the shapes and their colors" -n 400 --temp 0inserts 49 image tokens and names both shapes with the correct colors and positions.models/qwen3.5-27b-4bit(49 image tokens, both shapes correct),models/qwen3-vl-4b-4bit(49 image tokens, both shapes correct),models/qwen2.5-vl-3b-4bit(64 image tokens, loads and answers; the answer quality is that 3B model's own, and the code path is untouched by this PR).config.jsonpatched):language_model_only: true,output_gate_type: "sigmoid",mrope_interleaved: false, and a removedvision_start_token_ideach abort the load with their named error instead of loading.Not verified here: the server surface (text and image over
/v1/chat/completions) was not re-run, since the change is confined to config validation at load time and to token-id resolution, both of which the CLI exercises on the same code path. The TP real-model test is#[ignore]d in line with its Qwen3.5 sibling and was not run.Closes #1163