Skip to content

fix(loader/save): ported fp32 loads and remote-code metadata (#6136, #6134) - #6147

Merged
Qubitium merged 1 commit into
mainfrom
fix/6136-6134-loader-save-metadata
Nov 27, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/6136-6134-loader-save-metadata

Conversation

@Qubitium

@Qubitium Qubitium commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #6136
Fixes #6134

Two regressions introduced by #4620:

What Changed

  • gptqmodel/models/ports/native/hunyuan_v1_moe/modeling_hunyuan_v1_moe.py: declare _keep_in_fp32_modules_strict = ["mlp.gate.wg"].
  • gptqmodel/models/ports/native/zamba/modeling_zamba.py: declare _keep_in_fp32_modules_strict = ["A_log"].
  • gptqmodel/utils/hf.py: add is_transformers_native_config_type() backed by the Transformers 5.23 CONFIG_MAPPING.
  • gptqmodel/models/writer.py: add _preserve_remote_code_config(). It drops auto_map only for natively registered model types. For package ports it restores the source auto_map, copies the source checkpoint .py files as data, and keeps the released architectures name when the runtime class is a package-internal subclass. The rule is used by both the normal save and module-replacement save paths.
  • Regression tests:
    • tests/test_ported_fp32_load_6136.py: tiny released-config Hunyuan/Zamba bf16 checkpoints, Hunyuan quantize load with offload_to_disk=False, declaration/matcher checks, and a corrupted-bf16-parameter control.
    • tests/test_config_only_export.py: five-family writer round trip for MiniCPM-V, MiniCPM-o, InternVL-Chat, Ovis2.5 and DeepSeek-VL2, asserting auto_map, referenced .py files, AutoConfig resolution and the released MiniCPM-o architecture.
    • tests/test_minicpm_o_local_port.py: end-to-end RTN quantize + save() for MiniCPM-o 2.6 with the same assertions.
    • tests/fixtures/ports/hunyuan_v1_moe/released_config.json, tests/fixtures/ports/zamba/released_config.json: released configs (data) used to build the tiny checkpoints.

Tests

All green runs below use cd /root/openai-audit/w-loader-metadata/tests and
PYTHONPATH=/root/openai-audit/w-loader-metadata:/root/openai-audit/w-loader-metadata/tests.

cd /root/openai-audit/w-loader-metadata/tests
export PYTHONPATH=/root/openai-audit/w-loader-metadata:/root/openai-audit/w-loader-metadata/tests

# New #6136 regression
CUDA_VISIBLE_DEVICES=4 /root/venv/bin/python -m pytest test_ported_fp32_load_6136.py -q -rs
# 5 passed

# New #6134 writer test + existing native auto_map drop test
/root/venv/bin/python -m pytest test_config_only_export.py \
  test_checkpoint_compat.py::test_saved_config_drops_auto_map_when_remote_code_is_not_copied -q -rs
# 9 passed

# End-to-end MiniCPM-o public save
CUDA_VISIBLE_DEVICES=4 /root/venv/bin/python -m pytest \
  test_minicpm_o_local_port.py::test_public_save_keeps_released_remote_code_metadata -q -rs
# 1 passed

# Loader/port family
CUDA_VISIBLE_DEVICES=4 /root/venv/bin/python -m pytest test_load_state_assertions.py \
  test_hymba_bf16_load_4888.py test_ported_fp32_load_6136.py test_zamba_support.py -q -rs
# 38 passed

CUDA_VISIBLE_DEVICES=4 /root/venv/bin/python -m pytest test_minicpm_o_local_port.py -q -rs
# 36 passed, 3 skipped (MiniCPM-o TTS extra)

CUDA_VISIBLE_DEVICES=4 /root/venv/bin/python -m pytest test_checkpoint_compat.py -q -rs
# 22 passed

CUDA_VISIBLE_DEVICES=4 /root/venv/bin/python -m pytest test_native_port_parity.py -q -rs \
  -k "hunyuan_v1_moe or zamba"
# 6 passed

# Writer/save family
CUDA_VISIBLE_DEVICES=4 /root/venv/bin/python -m pytest test_config_only_export.py \
  test_generation_config_do_sample.py test_writer_attention.py test_writer_instance_attrs.py \
  test_writer_state_overlay.py test_writer_dynamic_order.py test_writer_quant_log.py \
  test_save_dispatch.py -q -rs
# 68 passed

CUDA_VISIBLE_DEVICES=4 /root/venv/bin/python -m pytest test_save_dispatch.py \
  test_save_kwargs_validation_4686.py test_save_loaded_quantized_model.py \
  test_save_loaded_quantized_model_dtype.py test_save_loaded_quantized_model_torch_fused.py \
  test_save_state_dict_buffer_collection.py -q -rs
# 23 passed, 1 skipped (bitblas)

CUDA_VISIBLE_DEVICES=4 /root/venv/bin/python -m pytest test_native_definition_loading_3.py \
  -q -rs -k hunyuan_v1_moe
# 1 passed

CUDA_VISIBLE_DEVICES=4 /root/venv/bin/python -m pytest \
  "test_minicpmv_local_port.py::test_public_image_awq_scaled_quantize_pack_infer_and_reload[False-4.5]" \
  "test_internvl_chat_local_port.py::test_public_awq_packs_and_reloads_actual_decoder_weights[Qwen3ForCausalLM]" \
  "test_ovis2_5_local_port.py::test_public_image_awq_capture_all_linears_and_two_exact_roundtrips[False-4-False]" \
  -q -rs
# 3 passed

CUDA_VISIBLE_DEVICES=4 \
PYTHONPATH=/root/openai-audit/w-loader-metadata:/root/openai-audit/w-loader-metadata/tests:/root/openai-audit/.model-audit-deps \
  /root/venv/bin/python -m pytest \
  "test_deepseek_vl_v2_local_port.py::test_dense_only_tied_biased_config_outputs_and_save[False]" \
  -q -rs
# 1 passed

cd /root/openai-audit/w-loader-metadata
/root/venv/bin/ruff check gptqmodel \
  gptqmodel/models/ports/native/auto/__init__.py \
  gptqmodel/models/ports/native/auto/_registry.py docs/eora tests setup.py
# All checks passed!

Red evidence at base 43b999585 (isolated worktree /tmp/wt-6136-6134-base, with only the new tests/fixtures copied in):

cd /tmp/wt-6136-6134-base/tests
export PYTHONPATH=/tmp/wt-6136-6134-base:/tmp/wt-6136-6134-base/tests

CUDA_VISIBLE_DEVICES=4 /root/venv/bin/python -m pytest test_ported_fp32_load_6136.py -q -rs
# 5 failed:
# RuntimeError: HunYuanMoEV1QModel.from_pretrained: ... mixed dtypes:
#   {'torch.bfloat16': 28, 'torch.float32': 2}
# RuntimeError: HunYuanMoEV1QModel.from_pretrained: ... mixed dtypes:
#   {'torch.bfloat16': 72, 'torch.float32': 2}
# RuntimeError: ZambaQModel.from_pretrained: ... mixed dtypes:
#   {'torch.bfloat16': 49, 'torch.float32': 4}

/root/venv/bin/python -m pytest \
  test_config_only_export.py::test_ported_config_only_save_keeps_remote_code_metadata -q -rs
# 1 failed: KeyError: 'auto_map'

CUDA_VISIBLE_DEVICES=4 /root/venv/bin/python -m  pytest \
  test_minicpm_o_local_port.py::test_public_save_keeps_released_remote_code_metadata -q -rs
# 1 failed: KeyError: 'auto_map'

Skips

  • test_save_loaded_quantized_model.py: 1 skip — BACKEND.BITBLAS unavailable (bitblas not installed).
  • test_minicpm_o_local_port.py: 3 skips — MiniCPM-o 2.6 TTS requires the optional gptqmodel[minicpm-o] extra.
  • DeepSeek-VL2 full modeling tests need einops/timm, which the brief venv does not include; the committed five-family writer test does not need them. A real tiny DeepSeek-VL2 RTN save + AutoConfig check passed when run with /root/openai-audit/.model-audit-deps on PYTHONPATH.
  • GPU kernels were not exercised; both fixes are loader/metadata paths and were qualified on CPU with CUDA_VISIBLE_DEVICES=4 set as assigned.

Model Support / Module Plan

Not applicable: no MODEL_MAP entry, alias, definition or module-plan change. The only model-code edits are two _keep_in_fp32_modules_strict declarations on existing ports.

AWQ onboarding safety

Not applicable: no model onboarding or AWQ grouping/search/replay/fold change.

Logic Flow Documentation

Not applicable: the writer change is a single metadata predicate (native vs. package-owned model type); it does not alter quantization, loading or tensor lifecycle control flow.

Review Requirements

  • Reviewed this PR.
  • Checked that the code matches existing project structure, APIs, and conventions.
  • Avoided unnecessary monkeypatching and used the project's normal extension points.
  • Minimized and compacted the impacted code surface.
  • Considered and eliminated potential regressions (native auto_map drop test remains green; mixed-load control still raises).

Kernel Accuracy Requirements

Not applicable: no kernel change.

…e-code metadata

- Hunyuan-MoE and Zamba declare their construction-time fp32 router/A_log
  modules in _keep_in_fp32_modules_strict, so bf16 loads pass the mixed-dtype
  guard without weakening it (#6136).
- The writer drops auto_map only for model types natively registered in
  Transformers. Package-owned ports keep the released auto_map, checkpoint
  .py files and released architecture name (#6134).

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