Skip to content

fix(loading): load ModelOpt NVFP4 Qwen2.5-VL checkpoints - #3166

Merged
inureyes merged 3 commits into
lablup:mainfrom
Jaeyeong-CHOI:fix/qwen25-vl-modelopt-nvfp4
Nov 19, 2026
Merged

inureyes merged 3 commits into
lablup:mainfrom
Jaeyeong-CHOI:fix/qwen25-vl-modelopt-nvfp4

Conversation

@Jaeyeong-CHOI

Copy link
Copy Markdown
Contributor

Summary

NVIDIA's ModelOpt NVFP4 export of Qwen2.5-VL failed to load: its vision config names the channel count under both in_channels and in_chans (a duplicate field to serde), the Qwen2.5-VL route did not repack ModelOpt's NVFP4 triplets, and the text config declared a bit width of 0 without an MLX quantization block. The loader now drops the alias when both names are present, repacks the triplets as the text-only and Qwen3.5 VLM routes do, and gives the text config the repacked layout.

Related issues

Closes #3165.

#3030 did the repack for the Qwen3.5 VLM route and listed the other VLM routes as not covered; this is the Qwen2.5-VL one.

Type of change

  • fix — bug fix

Cause

  1. Qwen25VLVisionConfig::in_channels carries #[serde(alias = "in_chans")]. A transformers re-export writes both keys, and serde_json then fails with duplicate field `in_channels` . The Qwen3-Omni loader already removes in_chans in that case; qwen_vision_config, which the Qwen2-VL and Qwen2.5-VL loaders share, did not.
  2. load_qwen2_5_vl passed the checkpoint's weights to the text model without sanitize_modelopt_nvfp4_weights, so each quantized linear was still a uint8 code plane with weight_scale and weight_scale_2 beside it.
  3. Qwen2VLConfig::group_size() and bits() return 0 when the config has no MLX quantization block (right for an unquantized checkpoint), and UnifiedLinear::from_weights refuses 0 bits for a quantized plane.

Change

  • qwen_vision_config (src/loading/vlm_qwen.rs): when vision_config has both in_channels and in_chans, parse a copy without the alias. One name alone is read as before.
  • prepare_qwen2_5_vl_weights (new, same file): the weight preparation load_qwen2_5_vl did inline (native-key remap, tied embedding) plus the ModelOpt NVFP4 repack when is_modelopt_nvfp4_text_checkpoint holds (quantization_config or hf_quant_config.json). It returns whether the checkpoint was one.
  • Qwen2VLConfig::declare_modelopt_nvfp4_layout (new, src/models/qwen2_vl.rs): gives a config without a quantization block the repacked layout, 4 bits at the transcode's 16-element blocks; a config that has the block is left alone. load_qwen2_5_vl calls it when the repack ran. sanitize::NVFP4_SOURCE_GROUP_SIZE becomes pub(crate) for it.
  • The vision tower is untouched: ModelOpt excludes visual*, and the tower's quantization is still inherited from the MLX block only.

Before / after

GB10 (sm_121, CUDA 13.0), release builds of e91045aa1 (main, the base of this branch) and of this PR's tree, generate -n 96 --temp 0, MLXCEL_SDPA_DETERMINISTIC=1. The image is a 448 x 448 red square with a blue square in the middle.

nvidia/Qwen2.5-VL-7B-Instruct-NVFP4 @ d13bb1f2d:

Prompt main This PR
What is the capital of France? Answer in one word. Error: Failed to parse Qwen2.5VL vision config: duplicate field `in_channels` , exit 1 Paris
What is 2 + 2? Answer with just the number. same error 4
Write one sentence about the sea. same error The vast and mysterious sea has been a source of inspiration and wonder for centuries.
(image) What are the two main colors in this image? Answer briefly. same error The two main colors in the image are red and blue.

The load reports Repacking 196 ModelOpt NVFP4 weight groups and prints no layout warning.

Each part is needed (test-fast builds of this tree with one part taken out, first prompt):

Build Result
alias dropped, no repack Error: … Unsupported packed weight: model.layers.0.self_attn.q_proj.weight is uint8 with …weight_scale (the refusal from #3019)
alias dropped and repack, text config left without a layout Error: … quantization.bits (0) must be between 1 and 32
all three (this PR) Paris

Checkpoints that load today answer the first prompt and the image prompt byte for byte as on main: mlx-community/Qwen2.5-VL-3B-Instruct-4bit @ 46d4cf06a, mlx-community/Qwen2-VL-2B-Instruct-4bit @ 01af461cd, and the raw transformers export Qwen/Qwen2.5-VL-3B-Instruct @ 66285546d.

Test plan

Run on this PR's commit (one commit on e91045aa1, tree 7ac4c74d4447) on a DGX Spark (GB10).

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --features cuda -- -D warnings
  • cargo build --release --features cuda
  • The four new tests by name: a_vision_config_naming_the_channel_count_twice_parses (the struct alone refuses the pair; through the helper it parses with and without a vision tower; either name alone still reads), a_modelopt_nvfp4_checkpoint_is_repacked_on_the_qwen2_5_vl_route (the triplet becomes a packed plane with .scales, the float text and vision tensors are routed as before, and the text config takes (16, 4) unless it declares a layout), the_qwen2_5_vl_route_repacks_only_what_the_config_declares (no config, ModelOpt FP8, another method: untouched) and the_qwen2_5_vl_route_reads_the_modelopt_sidecar_file: pass
  • cargo test --profile test-fast --features cuda --lib -- loading::vlm qwen2 modelopt nvfp4 colqwen: 374 passed
  • Negative control A, the alias left in place: the vision config test fails. Negative control B, the repack skipped: the repack test and the sidecar test fail
  • make verify-test-cuda (cargo test --workspace --profile test-fast --features cuda --no-fail-fast -- --test-threads=1): 15932 passed, 0 failed, 499 ignored
  • Self-hosted ci.yml jobs a fork PR does not get, by hand: clippy (cargo clippy -p mlxcel --lib --tests -- -D warnings, default features); license headers, env-var docs, kernel dtype keys, kernel port dispatch, cross-repo refs
  • Validated with real checkpoints: the tables above
  • xla-compile: not run (no IREE on this host). load_qwen2_5_vl_iree_host_preprocessor (feature xla-iree) is not changed, but it parses the vision config through the changed helper
  • cargo deny check: not applicable (no manifest or lockfile change)
  • Metal and ROCm: not built or run here

Notes for reviewers

  • Why the layout is set in the loader and not in group_size(). Llama, Qwen3 and others read quantization_config in their accessors (modelopt_nvfp4_group_size). That misses a checkpoint declared only through hf_quant_config.json, which is_modelopt_nvfp4_text_checkpoint accepts; for those families the 64 / 4 defaults and the shape-derived mode (fix(quant): load ModelOpt W4A16_NVFP4 checkpoints in families without a ModelOpt group size #3026) still load it, but Qwen2VLConfig defaults to 0. Setting the layout where the repack is decided covers both declarations with one condition. I can move it into the accessors if you prefer that shape.
  • Qwen2-VL. load_qwen2_vl shares the config helper, so a doubled channel name parses there too. It does not get the repack: I found no ModelOpt export of Qwen2-VL to validate one with.
  • Not covered. The IREE host-preprocessor route, and compressed-tensors nvfp4-pack-quantized exports of Qwen3-VL, which are another format (noted in the issue).

Checklist

  • PR title uses a Conventional Commits prefix
  • One logical change per PR (one checkpoint family made loadable; the three parts do nothing for it alone, see the ablation table)
  • Updated docs/: not needed (no option or documented behaviour changes)
  • Updated // Used by: ... comments: on the new config method

NVIDIA's ModelOpt NVFP4 export of Qwen2.5-VL did not load, for three reasons
in a row. Its vision config names the patch-embedding channel count under
both in_channels and the older in_chans, which serde refuses as a duplicate
field. The Qwen2.5-VL route did not repack the {weight, weight_scale,
weight_scale_2} triplets to MLX native NVFP4. And the text config, which has
no MLX quantization block, declared a bit width of 0 to the quantized loaders.
The loader now drops the alias when both names are present, repacks the
triplets as the text-only and Qwen3.5 VLM routes do, and gives the text config
the repacked layout.
@inureyes inureyes added status:review Under review type:bug Bug fixes, error corrections, or issue resolutions priority:medium Medium priority area:models Model architectures, weights, loading, metadata modeltype:vlm Vision-language model labels Nov 19, 2026
The doubled `in_channels` / `in_chans` vision config was only handled in `qwen_vision_config`. The Qwen2-VL and Qwen2.5-VL IREE host-preprocessor loaders parse `vision_config` directly with `parse_required_vlm_subconfig`, so the ModelOpt Qwen2.5-VL export still failed there with the duplicate-field error.

Move the dedupe into `without_duplicate_in_chans`, which borrows the config unchanged unless both names are present, and call it from `qwen_vision_config` and both IREE routes. The vision config test now also checks the helper directly.

Refs lablup#3165, lablup#3166
@inureyes

Copy link
Copy Markdown
Member

Hardening review of this PR against #3165.

Findings:

  • The repack reuses the shared path: prepare_qwen2_5_vl_weights calls is_modelopt_nvfp4_text_checkpoint and sanitize_modelopt_nvfp4_weights, the same pair the Qwen3.5 VLM route (fix(loading): repack ModelOpt NVFP4 weights on the Qwen3.5 VLM route #3030) and load_text_weights use. Nothing is duplicated, and the backend route choice (direct transcode, dense native, dense affine) stays in sanitize.rs.
  • Non-ModelOpt checkpoints take the same path as before: the repack and declare_modelopt_nvfp4_layout only run when the detector holds, and the in_chans dedupe borrows the config unchanged unless both names are present. A declared MLX quantization block is never overwritten. The dense-affine fallback (group 64 with biases) still loads because UnifiedLinear reconciles the group size and mode from the tensor shapes, the same as the Qwen3 and Llama families that report 16 through modelopt_nvfp4_group_size.
  • Gap fixed: the Qwen2-VL and Qwen2.5-VL IREE host-preprocessor loaders (xla-iree) parse vision_config with parse_required_vlm_subconfig directly, not through qwen_vision_config, so they would still have refused the doubled channel name. The dedupe is now a helper, without_duplicate_in_chans, called from qwen_vision_config and both IREE routes, and the vision config test checks it directly.

Not changed: load_qwen2_vl still has no repack (no ModelOpt Qwen2-VL export exists to validate it with); such a checkpoint fails with the explicit #3019 refusal rather than loading wrong weights.

Security and performance: config parsing only; the clone happens once per load and only for the doubled-name case. No new inputs or unbounded work.

Fix commit: 1b56852.

Validation (M3 Ultra, Metal): cargo fmt --all -- --check clean; cargo clippy -p mlxcel --lib --tests -- -D warnings clean; cargo test --profile test-fast --lib -- --test-threads=1 loading::vlm qwen2 modelopt nvfp4 colqwen: 374 passed, 0 failed. cargo check --features xla-iree cannot build here (no IREE distribution), so the IREE route edit relies on CI's xla-compile job.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:models Model architectures, weights, loading, metadata modeltype:vlm Vision-language model priority:medium Medium priority status:review Under review type:bug Bug fixes, error corrections, or issue resolutions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(loading): NVIDIA's ModelOpt NVFP4 Qwen2.5-VL export fails to load

2 participants