Skip to content

fix: native class for natively supported remote-code checkpoints; keep checkpoint dtype/device on dequant/export; accept VLM calibration metadata (#4453, #4455) - #4491

Merged
Qubitium merged 2 commits into
mainfrom
fix/remote-code-and-export-4453-4455
Nov 16, 2026
Merged

Qubitium merged 2 commits into
mainfrom
fix/remote-code-and-export-4453-4455

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #4453
Fixes #4455

#4453: explicit trust_remote_code=True ran stale remote code

_checkpoint_remote_layout_overrides_native (gptqmodel/utils/hf.py:995 at d01e8fd) kept remote code whenever the class name in the checkpoint's auto_map differed from the native class. These checkpoints then ran stale remote code and failed with an ImportError or a rope TypeError:

  • Phi-3.5-MoE and Phi-tiny-MoE (PhiMoE vs Phimoe)
  • MPT (MPT vs Mpt)
  • MiniMax-M2 (MiniMaxM2 vs MiniMax)

The class-name comparison is replaced by a declared table, _REMOTE_ONLY_LAYOUT_CONFIG_MARKERS. Its one entry is bailing_hybrid: q_lora_rank, the Ling-2.6-flash MLA branch that native BailingHybridAttention cannot represent. Native bailing_hybrid already maps attention.* → self_attn.*, so a remote class name on its own is not a layout signal.

flowchart TD
    A["resolve_trust_remote_code(path, True)"] --> C{"native AutoModelForCausalLM class?"}
    C -- no --> T["True: remote code"]
    C -- yes --> D{"auto_map.AutoModelForCausalLM?"}
    D -- "no / unreadable" --> N["False: native (warn once)"]
    D -- yes --> E{"config sets _REMOTE_ONLY_LAYOUT_CONFIG_MARKERS[model_type]?"}
    E -- no --> N
    E -- "yes (bailing_hybrid q_lora_rank)" --> T
Loading
  • Decision sweep: across all 226 local configs that have an auto_map, the result differs from def6e61 only for Ling-2.6-flash. Before this change, origin/main differed for 6.
  • Repro: GPTQModel.load(Phi-tiny-MoE, trust_remote_code=True) raised ImportError before; it now loads native PhimoeForCausalLM.
  • Docs: docs/trust-remote-code-isolation.md#native-override-of-explicit-trust.

#4455

  • VLM calibration metadata: pre-tokenized rows may now carry scalar or string metadata columns (id, url, ...). Still rejected, so the [BUG] VLM calibration silently drops pixel_values / image_grid_thw from processor-produced rows (regression from 2b51d4d, #4311) #4371 protection is kept:
    • multimodal column names (pixel_values, image_grid_thw, image_url, ...);
    • tensor, array, numeric, bytes or mapping values.
  • export(..., "hf") dtype: utils.model_dequant.dequantize_model now defaults target_dtype to the checkpoint's own float dtype, read from dtype, torch_dtype or text_config. bf16 is used only when none is declared. An fp16 checkpoint now exports as fp16, and a bf16 GPTQ Llama-3.2-1B export is bitwise identical to before.
  • In-memory dequantize_model (torch, torch_fused, torch_aten): the dense nn.Linear stays on the quantized module's device instead of moving to CPU.

Tests

  • New: tests/test_remote_code_layout_marker_4453.py, tests/test_vlm_calibration_metadata_columns_4455.py, tests/test_export_dtype_4455.py, tests/test_dequantize_model_device_4455.py (the CUDA case is marked cuda).
  • Updated: tests/test_ling_remote_code_4373.py. The Ling fixtures now carry q_lora_rank, like the real config.
  • Results:
    • 80 related CPU test files: the failure set is identical to origin/main (all pre-existing), and 42 more tests pass.
    • After rebasing on f12b66f: 52 passed, 2 skipped across the new and touched test files.

🤖 Generated with Claude Code

Qubitium and others added 2 commits November 16, 2026 19:19
The #4373 fix treated any auto_map class-name difference from the native
Transformers class as a layout override, so an explicit
trust_remote_code=True ran stale remote code for natively supported
Phi-3.5-MoE / Phi-tiny-MoE (PhiMoE vs Phimoe), MPT (MPT vs Mpt) and
MiniMax-M2 (MiniMaxM2 vs MiniMax) checkpoints.

Replace the name comparison with a declared per-model_type table of
config fields that select a layout the native class cannot load
(_REMOTE_ONLY_LAYOUT_CONFIG_MARKERS; bailing_hybrid q_lora_rank for the
Ling-2.6-flash MLA branch). Over all 226 local configs with an auto_map,
the decision now differs from def6e61 only for Ling-2.6-flash.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…alibration metadata (#4455)

- VLM calibration accepts scalar/string metadata columns (id, url, ...)
  next to input_ids; multimodal names (pixel_values, image_grid_thw,
  image_url, ...) and tensor/array/numeric/bytes/mapping values are
  still rejected.
- utils.model_dequant.dequantize_model defaults target_dtype to the
  checkpoint's own float dtype (dtype / torch_dtype / text_config), so
  GPTQModel.export(..., "hf") keeps an fp16 checkpoint fp16; bf16 only
  when the checkpoint declares none.
- torch / torch_fused / torch_aten in-memory dequantize_model build the
  dense Linear on the quantized module's device instead of CPU.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Qubitium
Qubitium merged commit ccae5e5 into main Nov 16, 2026
8 checks passed
@Qubitium
Qubitium deleted the fix/remote-code-and-export-4453-4455 branch November 16, 2026 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment