Skip to content
Open
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
2 changes: 1 addition & 1 deletion .agents/skills/ptq/references/unsupported-models.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ quant_cfg["quant_cfg"]["*vision*"] = {"enable": False}
quant_cfg["quant_cfg"]["*multi_modal_projector*"] = {"enable": False}
```

**Known VLM export issue**: The export step (`requantize_resmooth_fused_llm_layers` in `unified_export_hf.py`) may try to run a dummy forward pass on the full VLM instead of the language model backbone. This currently only handles Nemotron VLMs. If hit, patch the export to use `is_multimodal_model()` for the VLM check instead of model-specific string matching.
**Known VLM export issue**: The export step (`requantize_resmooth_fused_llm_layers` in `hf_export_prep.py`) may try to run a dummy forward pass on the full VLM instead of the language model backbone. This currently only handles Nemotron VLMs. If hit, patch the export to use `is_multimodal_model()` for the VLM check instead of model-specific string matching.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One sibling of this pointer got missed. tests/_test_utils/torch/quantization/tied_modules.py:103 still says:

the model_type gate inside _reorder_canonical_first (mirrors the existing whisper / nemotron-vl dispatch in unified_export_hf.py)

That dispatch is now hf_export_prep.py:266 — same class of stale reference ee7f050 fixed in registry.py and model_utils.py, just in a file this PR didn't otherwise touch.


## Pattern 5: FP8 Checkpoint Handling

Expand Down
5 changes: 1 addition & 4 deletions modelopt/torch/export/hf_export_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from modelopt.torch.quantization.utils import fsdp2_aware_weight_update

from .hf_weight_export import _export_quantized_weight
from .layer_utils import get_expert_linear_names, is_quantlinear, set_expert_quantizer_amax
from .model_config import QUANTIZATION_NONE
from .moe_utils import _export_fused_experts
Expand All @@ -41,10 +42,6 @@ def _export_weight(
ctx: ExportContext,
weight_name: str = "weight",
) -> None:
# Imported lazily to avoid a cycle: unified_export_hf imports this module to
# install the built-in handlers while retaining this legacy helper's import path.
from .unified_export_hf import _export_quantized_weight

_export_quantized_weight(module, ctx.dtype, weight_name, _tied_cache=ctx.tied_cache)


Expand Down
457 changes: 457 additions & 0 deletions modelopt/torch/export/hf_export_prep.py

Large diffs are not rendered by default.

416 changes: 416 additions & 0 deletions modelopt/torch/export/hf_weight_export.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions modelopt/torch/export/model_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ def _reorder_canonical_first(state_dict: dict, model: nn.Module) -> dict:
name to scope the reorder to DiffusionGemma; other tied
encoder-decoder models that ship dict-style ``_tied_weights_keys``
can be added to the allowlist here. Mirrors the ``model_type``
dispatch used for the Whisper and Nemotron-VL branches elsewhere
in ``unified_export_hf.py``.
dispatch used for the Whisper and Nemotron-VL branches in
``hf_export_prep.py``.
"""
model_type = type(model).__name__.lower()
if "diffusiongemma" not in model_type and "diffusion_gemma" not in model_type:
Expand Down
3 changes: 2 additions & 1 deletion modelopt/torch/export/moe_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import torch
import torch.nn as nn

from .hf_weight_export import _export_quantized_weight


def _alias_per_expert_subtree_from_prior(module: nn.Module, prior: nn.Module, n: int) -> None:
"""Build per-expert subtree on ``module`` by aliasing ``prior``'s packed buffers.
Expand Down Expand Up @@ -114,7 +116,6 @@ def _export_fused_experts(
``_export_transformers_checkpoint``) and scoped to one export
invocation; when ``None`` the corresponding alias step is skipped.
"""
from modelopt.torch.export.unified_export_hf import _export_quantized_weight
from modelopt.torch.quantization.plugins.huggingface import _get_fused_expert_intermediate_dim

n = module.num_experts
Expand Down
2 changes: 1 addition & 1 deletion modelopt/torch/export/plugins/vllm_fakequant_hf.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
from modelopt.torch.quantization.utils.layerwise_calib import LayerActivationCollector
from modelopt.torch.utils import get_unwrapped_name, safe_save

from ..hf_export_prep import collect_shared_input_modules
from ..layer_utils import get_experts_list, is_moe
from ..quant_utils import get_quantization_format
from ..unified_export_hf import collect_shared_input_modules

__all__ = [
"export_hf_vllm_fq_checkpoint",
Expand Down
2 changes: 1 addition & 1 deletion modelopt/torch/export/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

Preparation and export use separate registries because they have independent matching
precedence. Registering a handler for a new module type replaces what previously required
editing if/elif chains inside ``unified_export_hf.py``.
editing if/elif chains inside ``hf_weight_export.py``.
"""

from collections.abc import Callable
Expand Down
Loading
Loading