[Refactor] Model-family spec registry for export: MoE expert naming#1828
[Refactor] Model-family spec registry for export: MoE expert naming#1828h-guo18 wants to merge 13 commits into
Conversation
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1828 +/- ##
==========================================
- Coverage 77.87% 74.43% -3.44%
==========================================
Files 522 544 +22
Lines 58452 61841 +3389
==========================================
+ Hits 45522 46034 +512
- Misses 12930 15807 +2877
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
|
||
|
|
||
| @dataclass | ||
| class ModelSpec: |
There was a problem hiding this comment.
trtllm export path is deprecated.
| RelativeAttentionTableConfig, | ||
| RgLruConfig, | ||
| ) | ||
| from .model_config_utils import pad_weights |
Signed-off-by: h-guo18 <67671475+h-guo18@users.noreply.github.com>
8ddd26c to
e2a32bb
Compare
|
Signed-off-by: h-guo18 <67671475+h-guo18@users.noreply.github.com>
Signed-off-by: h-guo18 <67671475+h-guo18@users.noreply.github.com>
Signed-off-by: h-guo18 <67671475+h-guo18@users.noreply.github.com>
Signed-off-by: h-guo18 <67671475+h-guo18@users.noreply.github.com>
| @@ -0,0 +1,120 @@ | |||
| # Export: Model-Specific Logic Refactor — Action Plan | |||
There was a problem hiding this comment.
Is this file meant to be checked in?
There was a problem hiding this comment.
No, it will be removed
There was a problem hiding this comment.
This PR is still messy. Need some cleaning before ready for review
What does this PR do?
Type of change: Refactor / code health
Adds a declarative per-model-family registry,
modelopt/torch/export/modeling/, andmigrates the first data category: MoE expert linear naming. Each family is one
small spec file (
families/qwen.py,deepseek.py,mixtral.py,dbrx.py,gptoss.py,nemotron.py,gemma.py); importing the package registers all specs.Two HF-path consumers now read the registry instead of branching on class names:
layer_utils.get_expert_linear_names— resolvesspec.expert_linear_namesfirst;the legacy if/elif chain is preserved verbatim as fallback, so unmatched families
are byte-for-byte unaffected.
layer_utils.get_experts_list— readsspec.expert_linear_namesgated byspec.has_iterable_experts, which reproduces the legacy "supported 4 families,else
NotImplementedError" behavior.Scope note: per
MODEL_SPECIFIC_REFACTOR.md, this series targets the unified HFpath only. The TRT-LLM checkpoint path keeps its branches (to be moved out as-is
on a separate track); the Megatron path already follows a per-family registry
pattern and is untouched.
Relationship to #1939 (why a second registry?)
The two registries are deliberate, orthogonal layers — not duplication:
ExportModuleRegistry/PrepareMoEInputsRegistrydispatch on modulestructure: which handler processes this module?
modeling/resolves family data: what are this family's values?Example: when exporting a
QuantMixtralSparseMoeBlock, #1939 matches it to theshared iterable-experts handler (the same handler serves Qwen/DeepSeek/Gemma4);
inside,
get_expert_linear_namesresolves themixtralspec and returns("w1", "w2", "w3"). One handler serves many families, and one family spec willserve many handlers — a many-to-many relation indexed from both sides. Folding one
registry into the other would either turn declarative data into per-family
functions, or turn behavior into spec fields. Sharing the matcher machinery between
the two is planned for P4 (see the doc).
Usage
Testing
tests/unit/torch/export/test_modeling_specs.py: registry matching(substring / quantized-class-name / unmatched→None), fallback preservation, and
get_experts_listgrouping + unsupported-family rejection.tests/unit/torch/export/test_layer_utils.pyexpert-naming tests passunchanged through the new spec path (equivalence check).
pytest tests/unit/torch/export/— 116 passed (test_export_diffusers.pyskipped: pre-existing CUDA/glibc collection error unrelated to this change).
--fail-on-warning(fixes the previous build-docs failure).Before your PR is "Ready for review"
test_modeling_specs.py)Additional Information
Follow-ups (see
MODEL_SPECIFIC_REFACTOR.md): P2PQS_FUSE_MODULE_MAPPING→spec.pqs_fuse_rules; P3is_moename list →spec.moe_block_names; P4 handlersconsume specs directly + unify matcher machinery with #1939's registry.