Repository navigation
[OMNIML-6533] [1/2] Move the HF quantization plugin's remaining named-model code into modelopt/torch/models - #3367
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. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
/ok to test b85e4b6 |
|
|
/claude review |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3367 +/- ##
==========================================
+ Coverage 79.39% 81.08% +1.68%
==========================================
Files 719 719
Lines 80608 80604 -4
==========================================
+ Hits 64000 65356 +1356
+ Misses 16608 15248 -1360
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:
|
| # the first whose is_compatible_attention accepts the class gets it, and a class none accepts falls | ||
| # back to the AST-based quantized class. A model whose attention needs a wrapper of its own (T5's) | ||
| # appends it from its modeling_ptq. | ||
| _QUANT_ATTENTION_WRAPPERS: list[type[QuantModule]] = [_QuantAttention] |
There was a problem hiding this comment.
[SUGGESTION] The annotation list[type[QuantModule]] doesn't capture the contract entries actually have to satisfy: register_hf_attentions_on_the_fly calls wrapper.is_compatible_attention(attention_type), and that staticmethod is not declared on QuantModule. A wrapper appended without it type-checks fine and then raises AttributeError mid-calibration, at the first attention class it is tried on — a confusing place to learn about a missing method.
Since the list is the documented extension point for other modeling_ptq.py modules (vLLM's wrappers land on it in [2/2]), a Protocol would make the required method part of the declared type and catch the omission at the append site:
class _QuantAttentionWrapper(Protocol):
@staticmethod
def is_compatible_attention(attn: type) -> bool: ...
_QUANT_ATTENTION_WRAPPERS: list[type[QuantModule] & _QuantAttentionWrapper] = [_QuantAttention]Non-blocking — the intersection syntax isn't available yet, so a plain Protocol-typed alias or just naming the required staticmethod in the existing comment would do. Behavior is unchanged either way.
There was a problem hiding this comment.
Stated the contract in the comment above the list, in e0e71ad: each entry must define the staticmethod is_compatible_attention(attention_type) -> bool, which QuantModule does not declare. I kept the annotation as it is, since a Protocol can't be combined with type[QuantModule] today.
One correction to the premise: [2/2]'s vLLM wrappers don't go through this list. It holds only the Hugging Face attention wrappers (_QuantAttention and T5's).
There was a problem hiding this comment.
Approving: a behavior-preserving move of T5's KV-cache wrapper into its model package, with the dispatch-order change covered by tests.
What I traced rather than took on trust:
- The new
for/elseover_QUANT_ATTENTION_WRAPPERSis equivalent to the oldif/elif/else— theelsebinds to theforand runs only when no wrapper broke out, so a class no wrapper claims still reaches the AST fallback. _QUANT_ATTENTION_WRAPPERSis defined athuggingface.py:382, well before themodeling_ptqimport loop at the module tail, so t5's append works in both import orders. Importingt5.modeling_ptqfirst leaves no window where a caller sees the list without T5, and the extended registration test pins that order.- The dropped Nemotron-H guard was redundant:
is_homogeneous_hf_modelhas exactly one non-test caller — its registration, which runs after the model imports — and the guard fired precisely whenis_nemotron_h_modelwas true, which is when Nemotron-H's discoverer already wins first match. No existing test asserted the oldFalse. - The new file's header matches
LICENSE_HEADERverbatim.
The test edit is purely additive, and 73 added source lines is far under the size budget. One non-blocking inline suggestion on the wrapper-list type annotation.
No action needed.
- Baseline:
73b3f74(.agents/review-guidelines/code-review.md). Reviewed head:b85e4b6, all 5 changed files. - Source review only — I ran no tests and did not consult CI, so the GPU registration test and the transformers-version matrix in the PR body are unverified here.
|
/ok to test e0e71ad |
|
/claude review |
There was a problem hiding this comment.
Approving: re-review of e0e71ad confirms the T5 wrapper move and the dispatch-order change are behavior-preserving, and the one prior suggestion is answered.
What I re-traced rather than carried over from the b85e4b6 review:
- The
for/elseathuggingface.py:426binds to thefor, so a class no wrapper claims still reaches the AST fallback — equivalent to the oldif/elif/else, with the sameprinttext viawrapper.__name__. _QUANT_ATTENTION_WRAPPERSis defined at line 383, before themodeling_ptqimport loop at line 2014, so t5's append resolves in both import orders and appends exactly once even whent5.modeling_ptqis imported first (the partially-initialized module short-circuits the loop's re-import). The newcount(...) == 1assert pins that.- The dropped Nemotron-H guard was provably redundant:
is_nemotron_h_modelis defined asget_nemotron_h_decoder_layers(...) is not None, andget_decoder_layersreturns on first non-None discoverer, sois_homogeneous_hf_model— one non-test caller, its own registration — is never reached for a Nemotron-H. No fallthrough corner exists, and no test asserted the oldFalse. - The new file's header matches
LICENSE_HEADERverbatim;t5/__init__.pystill keeps transformers out ofimport modelopt.torch.models.
No action needed.
- ✔️ Resolved since the last review: the
_QUANT_ATTENTION_WRAPPERSannotation question, now answered by the comment naming the requiredis_compatible_attentionstaticmethod. AProtocolwould type it, but the comment is adequate for a private list. - 73 added source lines, far under the size budget; the test edit is purely additive. The PR body addresses why static registration and
CUSTOM_MODEL_PLUGINSwere rejected. - Baseline:
73b3f74(.agents/review-guidelines/code-review.md). Reviewed head:e0e71ad, all 5 changed files. - Source review only — I ran no tests and did not consult CI, so the GPU registration test and the transformers 5.5/5.9/5.18 matrix in the PR body are unverified here.
meenchen
left a comment
There was a problem hiding this comment.
Bot review (gpt-6.1-sol) — DM the bot to share feedback.
Nudge: the refactor looks sound, but the generated release notes incorrectly describe existing T5 support as a new feature.
Needs action:
- Correct the CodeRabbit release notes in the PR body to describe the T5 wrapper relocation, not newly added PTQ support.
No action needed:
- The design rationale addresses static registration and unordered callbacks; the ordered wrapper list preserves existing dispatch.
- The existing-test edit is justified: it adds T5 import-order, uniqueness, and precedence checks without removing coverage.
|
Corrected the CodeRabbit release notes in the description: they now describe moving T5's existing wrapper into its model package, with no new PTQ support. #3368's notes had the same problem and are corrected too. |
…elopt/torch/models huggingface.py keeps only generic Hugging Face support. A pure refactor: registrations, dispatch order and quantized results are unchanged. - T5: _T5QuantAttention moves verbatim, with its T5Attention import, to modelopt/torch/models/t5/modeling_ptq.py. register_hf_attentions_on_the_fly now tries the wrappers in an ordered list, _QUANT_ATTENTION_WRAPPERS, which starts as [_QuantAttention] and to which T5's module appends its wrapper; the first match wins and the AST-based fallback still comes last. So T5Attention and its subclasses keep _T5QuantAttention where T5 bypasses transformers' attention interface (before 5.15), and _QuantAttention from 5.15 on. A static registration would not do: the registry matches a subclass only when it shares forward, and would pre-empt _QuantAttention on 5.15+. Nor would a CUSTOM_MODEL_PLUGINS callback: that is a set, run in no fixed order. - Nemotron-H: is_homogeneous_hf_model no longer special-cases it. The decoder-layer registry's first-match order already gives Nemotron-H's own discoverer precedence, and for a native Nemotron-H both discoverers return the same model.model.layers (checked on transformers 5.5, 5.9 and 5.18), so get_decoder_layers is unchanged in either order. - The explicit modeling_ptq import list stays the registration point, after the generic wrappers and before the generic decoder discoverer, and gains t5. Signed-off-by: Shengliang Xu <[email protected]>
register_hf_attentions_on_the_fly calls is_compatible_attention on every entry of the list, and QuantModule does not declare it, so a wrapper that lacks it would fail only when first tried during calibration. Say so where the list is defined, for the modeling_ptq modules that append to it. Signed-off-by: Shengliang Xu <[email protected]>
e0e71ad to
8a7a142
Compare
There was a problem hiding this comment.
Bot review (gpt-6.1-sol) — DM the bot to share feedback.
LGTM: prior concerns are resolved; the justified existing-test edit needs human sign-off.
Needs action:
- Sign off on
tests/gpu/torch/models/test_modeling_ptq_registration.py: the additive T5 import-order, uniqueness, and precedence checks retain all existing coverage.
No action needed:
- ✔️ Resolved since the last review: the inaccurate CodeRabbit release notes and the wrapper-contract annotation concern.
- The design rationale addresses existing registration alternatives; dispatch and decoder discovery remain equivalent for their callers.
- Source review only; reported test runs and CI results were not independently verified.
meenchen
left a comment
There was a problem hiding this comment.
Automatic approval delegated by weimingc (mode: approve).
Pensieve review using weimingc's profile (revision 1).
Review verdict: approve.
GitHub publication: APPROVED.
Approve: the supplied diff preserves attention dispatch, and the additive registration tests address import order, uniqueness, and precedence without removing coverage.
The review request from shengliangx, on behalf of U05R5LDGRNG, supplies acceptance of the justified test edit. The wrapper-contract suggestion is resolved in code. The PR explains the registration alternatives; 41 core additions are under budget. Prior review records an exact canonical license-header match.
Baseline commit: 60689c73f7fed08bb836f988f4e8942e11e8d744. Base-revision AGENTS.md and CONTRIBUTING.md were unavailable. Review and duplicate checking cover the bounded supplied diff/history; tests were not executed and reported results were not independently verified.
No action needed.
Review run: 4d4e1404305e4ddd97b585d8d3381404
…ode into modelopt/torch/models (#3368) ### What does this PR do? Type of change: Refactor Part 2 of 2 of a stack that leaves the Hugging Face and vLLM quantization plugins with only generic support. [1/2] #3367 has merged, and this PR now targets main. The vLLM plugins held the wrappers for three named models next to the generic vLLM support. They move to their model packages in `modelopt/torch/models`, as `modeling_ptq_vllm.py` next to the transformers `modeling_ptq.py`. No behavior change: registrations and quantized results are the same. - **DeepSeek-V4** (`models/deepseek_v4/modeling_ptq_vllm.py`): the indexer wrapper, from `vllm_indexer.py`, and DeepSeek-V4's Mega-MoE registration, from `vllm_mega_moe.py`. - **GLM-5.3-Flash** (`models/glm5_next/modeling_ptq_vllm.py`, a new package): the k-pool indexer with its K-cache writers and DeepGEMM scorer, from `vllm_indexer.py`. Like `kimi_k3`, `glm5_next` has no `specs.py`: it holds only vLLM modeling, and a spec would make claims about the transformers model that nothing here checks. - **Kimi-K3** (`models/kimi_k3/modeling_ptq_vllm.py`): the MLP fake-quant preparation, from `vllm.py`, and Kimi-K3's Mega-MoE registration, from `vllm_mega_moe.py`. The preparation used to run inside the vLLM plugin's attention-preparation callback; it is now a `CUSTOM_MODEL_PLUGINS` callback of its own. The two touch disjoint modules, so their order does not matter. `_VLLMParallelLinear` reads a generic marker, `_fake_quant_supported_by_model`, instead of a Kimi-named one. - The generic indexer base class and its FP8 and scorer helpers, the Mega-MoE wrapper and the layer scope stay in the plugins. - `plugins/__init__.py` imports every `modeling_ptq_vllm` from an explicit list after the generic vLLM modules, inside the `import_plugin("vllm")` block, each under its own guard, so a model whose module fails to import loses only its own wrappers. DeepSeek-V4's module registers its indexer before its Mega-MoE import, which main kept in a later plugin module. DeepSeek-V4's and Kimi-K3's optional Mega-MoE imports only warn on an unexpected error, so both modules always complete: DeepSeek-V4's stays importable with its indexer registered, and Kimi-K3's MLP preparation is registered even if vLLM's Kimi module only imports later. The follow-up #3510 replaces this list, and the HF plugin's, by finding the modules through the import system; #3542 then imports only a model's own, when the model is used. - GLM reads the scorer-kwargs registry through `vllm_indexer`, so it and the indexer base class read one binding even when the registry is rebound, as tests do. The moved code is verbatim apart from the callback, the marker and the registry read. Tests in `tests/gpu_vllm` patch the moved names in their new modules. <details><summary>Moved names (old module → new module)</summary> | Name | From `modelopt/torch/quantization/plugins/` | To `modelopt/torch/models/` | |---|---|---| | `_QuantVLLMDeepseekV4Indexer` | `vllm_indexer.py` | `deepseek_v4/modeling_ptq_vllm.py` | | `_QuantVLLMGlm5NextIndexer`, `_DEEP_GEMM_SCORERS`, `_GLM5NEXT_INDEXER_OP`, `_GLM5NEXT_QUERY_KERNEL`, `_KPOOL_CACHE_WRITERS`, `_bind`, `_call_deep_gemm_scorer`, `_glm5next_indexers`, `_import_glm5next_indexer`, `_kpool_decode_written`, `_kpool_prefill_written`, `_run_scorer`, `_scorer_deep_gemm`, `_signature`, `_write_k_cache` | `vllm_indexer.py` | `glm5_next/modeling_ptq_vllm.py` | | `_KimiGemmRsArFakeQuantGuard`, `_KimiGemmRsFakeQuantGuard`, `_kimi_down_proj_has_enabled_quantizers`, `_kimi_mlp_bf16_linear_supports_fake_quant`, `_prepare_kimi_mlp_fake_quant` | `vllm.py` | `kimi_k3/modeling_ptq_vllm.py` | | `prepare_kimi_mlps_on_the_fly` (new callback) | | `kimi_k3/modeling_ptq_vllm.py` | </details> ### The stack [1/2] has merged. Each PR builds and carries its own tests. | PR | What | Added source lines | |---|---|---| | [1/2] #3367 (merged) | Hugging Face plugin: T5's KV-cache attention wrapper, the Nemotron-H check | 73 (31 moved, 14 license header) | | [2/2] (this PR) | vLLM plugins: the DeepSeek-V4, GLM-5.3-Flash and Kimi-K3 wrappers | 572 (about 470 moved, 56 license headers) | | Follow-up #3510, stacked on this PR | Both plugins: find the models' PTQ modules through the import system instead of listing model types | 30 | | Follow-up #3542, stacked on #3510 | Both plugins: import a model's PTQ modules by its model type when the model is used | 109 (14 license headers) | Lines are counted with the PR-size command in the repository's `CLAUDE.md`: added Python source lines, without blank lines, tests, docs and config. Until 2026-11-21 this PR also carried the three commits now in #3510 and #3542. They moved there unchanged, so the move is again the same two patches as at `f04698ff43e`, which Claude approved and the GB200 runs below tested. On 2026-11-23 two commits answered cjluo-nv's review: `add71b82993` guards each model module's import and registers DeepSeek-V4's indexer first, and `bf970e5541d` tests Kimi-K3's MLP preparation through conversion. Its follow-up reviews brought `f2a837a6c21`, which keeps DeepSeek-V4's module importable when its Mega-MoE import fails; `3aff43a3ef0`, which registers Kimi-K3's MLP preparation in that case too; `ba58bf16406` and `51f5f7388ea`, which check GLM-5.3-Flash's native indexer registration independently of the module's own lookup; and `c26d765667a`, which hands vLLM's Kimi module back in the Kimi-K3 retry test instead of re-importing it into a circular import inside vLLM. **Why this PR keeps the eager import list.** It changes where the named-model vLLM wrappers live, not when they are registered: the plugin still imports all three when modelopt is imported, as main does, so the registrations stay identical to main's (checked below) and the move can be reviewed as a relocation. Importing a model's modules on demand, by its model type, as `models/hf.py` already does for its loading and calibration hooks, changes behavior in ways that need their own review and tests, and each came up while that change was part of this PR: a decoder-layer lookup before conversion, which loading with FSDP2 does, must import the model's module first; a module quantized without its model's config no longer gets its wrappers unless its module is imported; and a model type that holds another type's classes needs a package that imports the shared one. #3510 first replaces the list with discovery through the import system, still importing every module, and #3542 then imports a model's own modules when it is used. ### Usage N/A: no new or changed API. ### Testing | Check | Result | |---|---| | pre-commit, every hook including mypy and bandit, over `main..HEAD` | clean | | What `import modelopt.torch.quantization` registers (the quant module registry and `CUSTOM_MODEL_PLUGINS`), vLLM 0.22.1 on CPU, [1/2] vs this PR | identical (DeepSeek-V4's indexer and Mega-MoE entries), plus the new Kimi-K3 callback; importing any one model module first gives the same result | | CPU, `tests/gpu_vllm/torch/quantization/test_vllm_{indexer_quant,dynamic_modules,mega_moe}.py`, vLLM 0.22.1 | the same outcome per test id as on [1/2], plus the new test, which passes: 45 passed, 47 skipped, and 14 failed and 6 errors on both for lack of a GPU (no CUDA device, a missing TE/cuBLAS symbol). The passing tests run the moved DeepSeek-V4 indexer's q/k re-quantization and its refusals, and GLM's query, K-cache and scorer-kwargs paths | | Revert checks | dropping `glm5_next` from the import list fails `test_vllm_plugin_imports_every_model_package`, naming it; having GLM read the scorer-kwargs registry by name fails `test_registered_quantizers_turn_their_config_into_scorer_kwargs`; one guard for the whole list fails the Kimi-K3 case of `test_failed_vllm_model_import_keeps_other_registrations`, and DeepSeek-V4's old import order its DeepSeek-V4 case; dropping Kimi-K3's callback registration fails `test_kimi_gemm_rs_guard_tracks_converted_down_projection` (on CPU, against stand-ins for vLLM's Kimi-K3 modules); a DeepSeek-V4 module that aborts on a Mega-MoE error fails that case's later direct import with `already registered!`; a Kimi-K3 module that skips its MLP preparation after a failed startup import fails the Kimi-K3 retry case; `test_vllm_plugin_registers_native_glm5next_indexer` fails with GLM-5.3-Flash's registration removed, its key renamed or the module's lookup returning `None` (the last two checks against stand-ins) | | CPU, `tests/unit/torch/quantization/plugins`, `tests/unit/torch/models` and `tests/gpu/torch/models/test_modeling_ptq_registration.py`, transformers 5.9 | 752 passed, 16 skipped, as on [1/2] | | GPU on GB200, [1/2] vs this PR: all of `tests/gpu_vllm` at 1 and 2 GPUs under a vLLM 0.29.1rc1 nightly, plus the touched test files under vLLM 0.28.0 and a GLM-5.3-Flash build | no test changes outcome, apart from 3 timeout flips outside the moved code; details below | | CI at `5b9ae6972f0`, the same two patches on an earlier main: every job including the GPU ones; on CI's vLLM 0.30.0 with 1 GPU, `tests/gpu_vllm` at [1/2]'s head vs that one | green; 217 vs 218 passed, 8 skipped on both: per test id, the only change is the new test, which passes | | CPU at `bca69f2a7e9` vs main `b735732ef59`: the three vLLM test files under vLLM 0.22.1, without the 11 end-to-end engine tests, whose setup never returns without a GPU; and under transformers 5.4.0, `tests/unit/torch/quantization/plugins`, `tests/unit/torch/models`, the keep-fused export tests and the registration test | the same outcome per test id, plus the new test, which passes: vLLM 47 vs 46 passed, 42 skipped and the same 12 failed on both (`No CUDA GPUs are available`); transformers 680 passed and 34 skipped on both | | CI at `bca69f2a7e9`, on main `b735732ef59` | green, every job including the GPU ones. `tests/gpu_vllm` under vLLM 0.30.0 gives 218 passed and 8 skipped, as at `5b9ae6972f0`, and the GPU job 1930 passed and 175 skipped. Per test id against `d9c2c6328d0`, the head before #3510's commits moved out, no shared test changes outcome; the only other differences are the two tests #3510 took along, back to the versions they had replaced, which pass, and main's 20 new tests | | CPU at `bf970e5541d` vs `bca69f2a7e9`: the same suites, plus the Kimi tests against stand-ins for vLLM's Kimi-K3 modules, which vLLM 0.22.1 lacks | the same outcome per test id, plus the two new isolation cases, which pass: vLLM 49 passed, 42 skipped and the same 12 failed; transformers 680 passed and 34 skipped; the Kimi tests 12 passed and 1 skipped (the legacy GEMM-RS test, which the stand-ins do not model) | | CI at `bf970e5541d` | the GPU jobs green: the GPU job 1930 passed and 175 skipped, as at `bca69f2a7e9`; `tests/gpu_vllm` under vLLM 0.30.0 220 passed and 8 skipped, the 218 before plus the two new isolation cases, with the Kimi test through `mtq.replace_quant_module` passing against the real Kimi-K3 classes; Megatron 480 passed and TRT-LLM 43 passed. Unit tests, code quality, the docs and codecov are green. Two example jobs failed on pytest timeouts that hit other PRs' runs the same day: `test_llama_distill` (over 300 s), and in `hf_ptq` `test_ptq_t5[fp8...]` (over 300 s) and `test_qwen_vl[fp8]` (over 420 s) | | CI at `f2a837a6c21` | the GPU jobs green: `tests/gpu_vllm` 220 passed and 8 skipped, the DeepSeek-V4 re-import case passing against vLLM 0.30.0's real classes; `hf_ptq`'s `test_qwen_vl[fp8]` timed out again (over 420 s) | | CI at `ba58bf16406` | `tests/gpu_vllm` 220 passed and 1 failed: the new Kimi-K3 retry case, whose re-import of vLLM's Kimi module hit a circular import inside vLLM; `c26d765667a` fixes the test | | CPU at this head vs `bf970e5541d`: the vLLM test files, plus stand-ins for vLLM's Kimi-K3 module and GLM-5.3-Flash's native indexer, which vLLM 0.22.1 lacks | the same outcome per test id, plus the new Kimi-K3 retry case and GLM-5.3-Flash test, which skip without them: vLLM 49 passed, 44 skipped and the same 12 failed; against the stand-ins, both pass | | CI at this head | `tests/gpu_vllm` under vLLM 0.30.0: 222 passed and 8 skipped, the 220 before plus two that ran and passed against vLLM's real classes: the Kimi-K3 retry case of `test_failed_vllm_model_import_keeps_other_registrations`, and `test_vllm_plugin_registers_native_glm5next_indexer`, which found GLM-5.3-Flash's native indexer and checked its wrapper and config key. Every other job passed too: the GPU job 1930 passed and 175 skipped, as at `bca69f2a7e9`, the TRT-LLM and Megatron GPU jobs, the examples including `hf_ptq`, the unit tests and codecov/project | The earlier CPU rows and the GB200 runs predate the rebases onto main since; `git range-diff` shows both patches unchanged by each. **GPU runs** on GB200, [1/2] (`b85e4b6fa8e`) vs this PR (`f04698ff43e`), compared per test id. This cluster has no build of CI's vLLM 0.30.0, so they use three builds that between them contain every vLLM model path the moved code handles: | vLLM build | GPUs | Tests | [1/2] | This PR | Outcome changes | |---|---|---|---|---|---| | 0.29.1rc1 nightly | 1 | all of `tests/gpu_vllm` | 210 passed, 6 skipped, 6 failed, 3 errors | 211 passed, 6 skipped, 6 failed, 3 errors | none besides the new test | | 0.29.1rc1 nightly | 2 | all of `tests/gpu_vllm` | 212 passed, 4 skipped, 6 failed, 3 errors | 214 passed, 4 skipped, 5 failed, 3 errors | besides the new test, 3 tests outside the moved code that hit the 60 s per-test timeout: two only on [1/2], one only here | | 0.28.0 | 1 | the three touched test files | 101 passed, 9 skipped, 1 error | 102 passed, 9 skipped, 1 error | none besides the new test | | GLM-5.3-Flash build | 1 | the three touched test files | 100 passed, 9 skipped, 1 failed, 1 error | 101 passed, 9 skipped, 1 failed, 1 error | none besides the new test | - The failures and errors hit the same tests with the same error on both sides, and these builds are not the vLLM 0.30.0 that CI uses. The errors: 60 s test timeouts and vLLM engine-startup timeouts on the nightly; vLLM rejecting DeepSeek-V4's fp8_ds_mla KV-cache layout with the default KV-cache dtype on 0.28.0 and the GLM build; on the nightly, its Kimi-K3 GEMM-RS-AR path calling an `apply` method that ModelOpt's guard lacks; and on the GLM build, its end-to-end indexer test, whose indexer the ModelOpt plugins don't support. - What the runs cover: DeepSeek-V4's 9 tests ran in every build, with none skipped. GLM-5.3-Flash's tests ran in all three builds, and the nightly and the GLM build each carry one of its two module layouts. Kimi-K3's ran in all three: 0.28.0 takes its legacy GEMM-RS branch, the other two the newer one. In every build the DeepGEMM scorer-numerics test and the `MLAAttention` test skip, since no build has what they need. - The new `test_vllm_plugin_imports_every_model_package` passed in all four runs. - CI's GPU jobs, which skip while a PR targets another PR's branch, ran once this PR targeted main. On CI's runner the moved code's tests all pass except 5 that skip on [1/2]'s head too: Kimi-K3's legacy GEMM-RS test, a path vLLM 0.30.0 no longer takes; the 3 end-to-end indexer tests, which need an SM90 or SM100 GPU (CI's runner is an RTX PRO 6000); and the DeepGEMM scorer-numerics test. ### Before your PR is "*Ready for review*" Commits are signed (`git commit -s -S`). - Is this change backward compatible?: ✅ (every moved name is private; code that imported one from a plugin module now imports it from its model package) - If you copied code from any other sources or added a new PIP dependency, did you follow guidance in `CONTRIBUTING.md`: N/A - Did you write any new necessary tests?: ✅ (`test_vllm_plugin_imports_every_model_package` in `tests/gpu_vllm/torch/quantization/test_vllm_dynamic_modules.py`: importing modelopt in a fresh interpreter imports every `models/*/modeling_ptq_vllm.py`, where `import_plugin` would otherwise hide a failed import; `test_failed_vllm_model_import_keeps_other_registrations`: a model module that fails to import, GLM's or DeepSeek-V4's Mega-MoE one, leaves Kimi-K3's callback and DeepSeek-V4's indexer registered, DeepSeek-V4's module importable, and Kimi-K3's MLPs prepared once vLLM's Kimi module imports; `test_vllm_plugin_registers_native_glm5next_indexer` checks GLM-5.3-Flash's native indexer and its config key wherever the vLLM build has a supported layout) - Did you update Changelog?: N/A (internal refactor) - Did you get Claude approval on this PR?: ❌ not yet for this head: Claude approved the move at `f04698ff43e`, before the review-fix commits ### Additional Information Tracked by OMNIML-6533, for ModelOpt v0.50.0. Follow-ups: #3510, then #3542. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Documentation** * Clarified model-type-based loading for Transformers and vLLM, and documented model package naming and legacy Falcon types. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Shengliang Xu <[email protected]>
What does this PR do?
Type of change: Refactor
Part 1 of 2 of a stack that leaves the Hugging Face and vLLM quantization plugins with only generic support. Their remaining model-specific code moves to its model package in
modelopt/torch/models, as earlier moves did (#2576-#2580, #3067). This part covers the Hugging Face plugin; [2/2] #3368, stacked on it, covers vLLM. No behavior change: registrations, dispatch order and quantized results are the same._T5QuantAttentionmoves verbatim, with itsT5Attentionimport, fromquantization/plugins/huggingface.pytomodels/t5/modeling_ptq.py.register_hf_attentions_on_the_flynow tries the wrappers in an ordered list,_QUANT_ATTENTION_WRAPPERS, which starts as[_QuantAttention]and to which T5's module appends its wrapper. The first match wins, and the AST-based fallback still comes last. SoT5Attentionand its subclasses keep_T5QuantAttentionwhere T5 bypasses transformers' attention interface (before 5.15), and get_QuantAttentionfrom 5.15 on. A static registration would not do: the registry matches a subclass only when it sharesforward, and it would pre-empt_QuantAttentionon 5.15+. Nor would aCUSTOM_MODEL_PLUGINScallback: that is a set, run in no fixed order.is_homogeneous_hf_modelno longer special-cases it. The decoder-layer registry's first-match order already gives Nemotron-H's own discoverer precedence, and for a native Nemotron-H both discoverers return the samemodel.model.layers(checked on transformers 5.5, 5.9 and 5.18), soget_decoder_layersis unchanged in either order.modeling_ptqimport list inhuggingface.pystays the registration point and gainst5.models/README.mddescribes the attention-wrapper route.The stack
Merge in order: [2/2] is based on this PR's branch. Each PR builds and carries its own tests.
Lines are counted with the PR-size command in the repository's
CLAUDE.md: added Python source lines, without blank lines, tests, docs and config.Usage
N/A: no new or changed API.
Testing
main..HEADtests/unit/torch/quantization/plugins,tests/unit/torch/modelsandtests/gpu/torch/models/test_modeling_ptq_registration.py, transformers 5.9test_kv_cache_auto_quant_distributedtests/unit/torch/quantizationandtests/unit/torch/export, transformers 5.18_QUANT_ATTENTION_WRAPPERSremovedtest_kv_quant_hf[get_tiny_t5-None]fails on transformers 5.9 and 5.5.4 (the AST-based fallback then wraps T5's attention and breaks it), so the existing test covers the moveNemotronHBlock, both discoverers return the samemodel.model.layers, andget_decoder_layersis unchangedtests/gpufiles that useneed_2_gpus(CI runs that width only on main), main vs this PRThe CPU runs above predate the rebase onto current main, whose 5 new commits don't touch the moved code;
git range-diffshows the patches unchanged, and pre-commit ran again at this tip.Before your PR is "Ready for review"
Commits are signed (
git commit -s -S)._T5QuantAttentionis private; it now lives inmodelopt.torch.models.t5.modeling_ptq)CONTRIBUTING.md: N/Atests/gpu/torch/models/test_modeling_ptq_registration.pythat T5's wrapper is listed once, after_QuantAttention; the existingtest_kv_quant_hf[get_tiny_t5-None]covers the moved wrapper)Additional Information
Tracked by OMNIML-6533, for ModelOpt v0.50.0.
Summary by CodeRabbit