Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ Changelog
name. Those tensors already carry the hub name, so C-RADIO towers exported
``vision_model.radio_model.radio_model.input_conditioner.norm_mean``. Re-export affected
checkpoints.
- Fix unified Hugging Face export of GLM-5.3-Flash (``glm5_next``) keeping transformers'
in-memory tensor names (``conv1d``, ``forget_gate.*``) instead of the hub layout, which vLLM
cannot load. The fused KDA ``q/k/v_conv1d`` weights are now split back. Re-export affected
checkpoints.
- Fix shared ONNX export metadata and Diffusers attention policy: every ``NVFP4QuantExporter`` post-process now upgrades the default-domain opset to at least 23, all FP8 custom-op exports re-run ONNX shape/type inference after setting output metadata, and quantized SDPA derives FP8 MHA enablement from the live Q/K/V quantizers instead of honoring a caller-set ``_disable_fp8_mha`` attribute.
- Fix ONNX FP16 conversion failing to preserve public output types when type inference changes a graph output declaration before output casts are inserted.
- Fix ``examples/hf_ptq/hf_ptq.py`` discarding a completed PTQ run (no checkpoint exported) when the optional post-quantization sanity-check ``generate()`` call raised, for example because ``device_map="auto"`` placed part of the model on CPU. That failure is now caught and only skips the sanity check; export proceeds regardless.
Expand Down
13 changes: 12 additions & 1 deletion modelopt/torch/export/quant_aware_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,18 @@ def _apply_split_rule(state_dict: dict[str, torch.Tensor], rule: SplitRule) -> N
for module, leaf, key in fused_keys:
tensor = state_dict.pop(key)
# A 3-D expert tensor here means stacked experts (MergeModulelist) — out of scope.
if leaf == ".weight" and tensor.dim() >= 3:
# Unquantized dense 3-D weights (e.g. GLM-5.3 KDA depthwise conv1d [C, 1, K], fused
# from q/k/v convs) chunk cleanly along the output dim, so only reject experts or
# quantized modules.
fused_module = key[: -len(leaf)]
if (
leaf == ".weight"
and tensor.dim() >= 3
and (
".experts" in fused_module
or any(fused_module + s in state_dict for s in _QUANT_STATE_SUFFIXES)
)
):
raise QuantConversionUnsupportedError(
f"stacked 3-D expert tensor '{key}' (ndim={tensor.dim()}) is not supported; "
"un-stacking experts + their scales is a follow-up"
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/torch/export/test_quant_aware_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,31 @@ def test_stacked_3d_expert_raises_unsupported():
apply_reverse_rules(sd, [rule], [])


def test_split_unfuses_unquantized_dense_3d_weight():
"""A fused dense 3-D weight (GLM-5.3 KDA depthwise conv1d [C, 1, K]) splits on dim 0."""
q, k, v = (torch.randn(8, 1, 4, dtype=torch.bfloat16) for _ in range(3))
sd = {"m.layers.0.self_attn.conv1d.weight": torch.cat([q, k, v], dim=0)}
rule = SplitRule(".conv1d", (".q_conv1d", ".k_conv1d", ".v_conv1d"), dim=0)

out = apply_reverse_rules(sd, [rule], [])

prefix = "m.layers.0.self_attn"
assert set(out) == {f"{prefix}.{p}_conv1d.weight" for p in ("q", "k", "v")}
for part, expected in zip(("q", "k", "v"), (q, k, v)):
assert torch.equal(out[f"{prefix}.{part}_conv1d.weight"], expected)


def test_quantized_3d_weight_raises_unsupported():
"""A 3-D weight carrying quantization state still triggers the safe fallback path."""
sd = {
"m.layers.0.mlp.gate_up_proj.weight": torch.zeros(4, 8, 16, dtype=torch.uint8),
"m.layers.0.mlp.gate_up_proj.weight_scale": torch.zeros(4, 8, 2, dtype=torch.uint8),
}
rule = SplitRule(".gate_up_proj", (".gate_proj", ".up_proj"), dim=0)
with pytest.raises(QuantConversionUnsupportedError):
apply_reverse_rules(sd, [rule], [])


def test_non_divisible_split_raises():
sd = {"m.mlp.gate_up_proj.weight": torch.zeros(7, 8, dtype=torch.uint8)}
rule = SplitRule(".gate_up_proj", (".gate_proj", ".up_proj"), dim=0)
Expand Down
Loading