Skip to content

fix: restore dense source for pruned MoE experts before save (#4349) - #4363

Merged
Qubitium merged 1 commit into
mainfrom
pr/4349
Nov 16, 2026
Merged

Qubitium merged 1 commit into
mainfrom
pr/4349

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

With auto_dtype_cast=auto_nf12, the calibration forward replaces each eligible projection with an NF12 packed wrapper and records an auto_dtype_cast_source_spec. The dense source is only restored by ModuleLooper._prepare_named_module_for_quantization. When fallback=None, prune_uncovered_modules pops experts that received no calibration tokens, so those experts never reached that step: their nf12_* buffers stayed in the model tree and _validate_nf12_payload_ownership aborted save().

What Changed

  • gptqmodel/looper/stage_subset.py: before a pruned/uncovered module leaves the subset loop, run looper._prepare_named_module_for_quantization when it still carries a deferred quant source (auto_dtype_cast_source_spec or quant_source_module). This restores the dense source and releases the packed buffers. Modules without a deferred source are already dense and are left untouched. Existing dynamic-exclusion recording is unchanged; the NF12 ownership validation is not relaxed.
  • tests/test_moe_prune_nf12_save_4349.py: drives the real _run_single_subset_pass prune path with stub AUTO_NF12 packed modules and asserts every pruned expert is restored and _validate_nf12_payload_ownership passes. A negative test asserts a leftover nf12_* buffer is still rejected even when the module is recorded as dynamically excluded.

Tests

export GPTQ_BYPASS_SAFETY_CHECKS=1
export PYTHONPATH=$PWD
export CUDA_VISIBLE_DEVICES=
python3 -m pytest tests/test_moe_prune_nf12_save_4349.py -q
# 2 passed

python3 -m pytest tests/test_stage_modules.py tests/test_quantization_lifecycle_contracts.py \
  tests/test_auto_nf12_excluded_layers.py tests/test_auto_dtype_cast.py -q
# 112 passed, 25 skipped

ruff check gptqmodel/looper/stage_subset.py tests/test_moe_prune_nf12_save_4349.py
# All checks passed

Pre-fix confirmation: the new regression test fails on unmodified origin/main because the pruned experts are never passed to _prepare_named_module_for_quantization.

Not run: real AUTO_NF12 packing needs a supported CUDA/HIP device (nf12_supported_device is false on CPU), so the packed wrapper is simulated on CPU. The full Qwen3-30B-A3B repro (tests/test_moe_config.py::TestMoEConfig::test_none_moe_config) was not run (model download/network + GPU). tests/test_subset_plan.py::test_build_layer_subset_plans_merges_groups_for_single_pass_processors fails identically on unmodified origin/main and is unrelated.

Model Support / Module Plan

N/A — no new model types or registry entries.

Fixes #4349

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

Labels

None yet

Projects

None yet

1 participant