Repository navigation
fix(models): preserve NVFP4 scales when stacking Nemotron-H experts - #3315
Conversation
d1922e6 to
99ff9e3
Compare
|
Rebased onto |
NemotronHModel::sanitize_weights stacks the per-expert planes with drain_numbered_expert_planes, so the ModelOpt block scales and tensor scale stay beside each packed weight. The helper returns Result since lablup#3335; sanitize_weights now returns Result<WeightMap, String> and its four callers propagate the error, so a plane that disagrees with expert 0 in shape or dtype fails the load with the helper's message naming the expert key.
|
Rebased again onto |
99ff9e3 to
f38ec7c
Compare
Hardening summarySummaryMerge-ready at Reviewed (PR + issues)
Findings
FixesNone needed beyond the contributor's rebase. Security reviewNo new input surface. Malformed checkpoint planes now fail the load with a named key instead of being skipped. Performance reviewNo change on the hot path. Stacking runs once at load. Validation
|
Closes #3314
Summary
The ModelOpt export of Nemotron 3 Nano stores each routed expert as a separate linear. The repack produces a packed weight, block scales and a tensor-scale multiplier for each projection. Nemotron-H moved only the weight into
switch_mlp. The first routed forward therefore sent packed weights to the densegather_mmkernel.NemotronHModel::sanitize_weightsnow usesdrain_numbered_expert_planesfrom #3196 for bothup_proj → fc1anddown_proj → fc2. It stacks the block scales with the weights and collects the tensor scales in expert order underinv_global_scale. After constructing eachSwitchLinear, the loader releases that entry with the other consumed leaves.The helper returns
Resultsince #3335.sanitize_weightsnow returnsResult<WeightMap, String>and its four callers propagate it (NemotronHModel::load,src/loading/special.rs,src/loading/vlm_nemotron_h_nano_omni.rs,src/models/nemotron_voicechat/llm.rs). A per-expert plane that disagrees with expert 0 in shape or dtype fails the load with the helper's message naming the expert key.Real-checkpoint verification
Built main
36129ebb3and the fix withcargo build --locked --release --features cuda --bin mlxcelon a DGX Spark (GB10). Both binaries rangenerate -m "$MODEL" -n 200 --temp 0 -p "$PROMPT"withMLXCEL_SDPA_DETERMINISTIC=1andMLX_ENABLE_TF32=0.The target checkpoint was
nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-NVFP4@6efb4a2a1c1fa277ce7b3df7a1416255011b1c99.gather_mmabort, exit 134The capital run failed on main with
[gather_mm] Last dimension of first input with shape (168,1,2688) must match second to last dimension of second input with shape (128,336,1856).Both binaries exited 0 on the four control prompts below. For each pair, the generated text matched byte for byte, and the CLI reported the same token count.
lmstudio-community/NVIDIA-Nemotron-3-Nano-30B-A3B-MLX-4bit543873e66e36362182738b0d2863a766728045aanvidia/NVIDIA-Nemotron-Nano-9B-v2-NVFP48556c9164ddb43fe1f4f4ad730593b3c5e3f7328The first push of this PR ran the same comparison on base
251f08610(commitd1922e66b), with two more controls:mgoin/Qwen3-0.6B-NVFP4@545def2dd2492f4abd75435ccde6dd93d1d93e34andmlx-community/gemma-3-4b-it-4bit@93724907d4ed1745d2fe50baadf3b0b01a65abf2, capital prompt each, main and fix identical. Those two were not rerun on the current base.Test plan
CUDA verification used tree
c9a61e85fcaf26883b3fe569a59e75b9e971780a(commit99ff9e30d, base36129ebb3).cargo fmt --all -- --checkpassed.cargo test --locked --profile test-fast --features cuda --lib -- --test-threads=1 per_expert_nvfp4_planes_are_stacked_with_their_tensor_scalespassed. Three synthetic experts carry distinct up/down multipliers. The test checks their order and verifies that the model loads both projections as NVFP4 with per-expert multipliers.mismatched_per_expert_planes_fail_sanitize_with_the_expert_key(new) passed. One expert'sup_proj.weightin another dtype, and one expert'sdown_proj.weightin another shape, each makesanitize_weightsreturn the helper's error namingbackbone.layers.0.mixer.experts.2.<proj>.weight.?on the helper call while keeping the tests made the new test fail (mismatched per-expert planes must fail to sanitize, exit 101), andcargo clippy --locked --features cuda --lib -- -D warningsrefused the build withunused std::result::Result that must be used.cargo test --locked --profile test-fast --features cuda --lib -- --test-threads=1 nemotron_h switch_layerspassed (151 passed, 4 ignored).cargo clippy --locked --workspace --all-targets --features cuda -- -D warningspassed.make verify-test-cudawith a private 0700TMPDIRexited 2: 17,093 passed, 1 failed and 516 ignored. The failure ismodels::deepseek_v32::rope_tests::prefill_and_decode_cache_yarn_rotated_keys_past_the_original_context(cached k_pe at positions 16..24 must be YaRN-rotated (max diff 1.6620973)). I did not rerun the gate on unmodified36129ebb3. The same test failed with the same message on main251f08610in the first push's gate, and this PR does not touch DeepSeek-V3.2.On the first push (base
251f08610), restoring main'snemotron_h.rswhile keeping the NVFP4 test made it fail withbackbone.layers.0.mixer.switch_mlp.fc1.inv_global_scale was not stacked(exit 101). That mutation was not repeated on the current base.Verification limits
Each target run still logged 80 NVFP4 layout warnings. On the fixed capital run of the first push, 46 named shared-expert up/down projections and 34 named mixer input/output projections. The numerical effect of those warnings remains unverified. I did not compare logits against a reference implementation or run Metal or ROCm. The Nemotron-H Nano Omni and voice-chat loaders now propagate the same error; they are covered by compilation and clippy only, not by a real checkpoint.