[#9413][fix] Minor fixes to nemotron H and custom models in AD#9416
[#9413][fix] Minor fixes to nemotron H and custom models in AD#94162ez4bz merged 1 commit intoNVIDIA:mainfrom
Conversation
📝 WalkthroughWalkthroughThe custom model registration mechanism is refactored from using Changes
Sequence DiagramsequenceDiagram
participant User
participant Factory as AutoModelForCausalLMFactory
participant Mapping as _custom_model_mapping
participant Config as model_config
participant Model as CustomModelCls
rect rgb(200, 220, 240)
Note over Factory,Model: Old Lookup Flow
User->>Factory: register_custom_model_cls("nemotron_h", Model)
Factory->>Mapping: Store Model at key "nemotron_h"
User->>Factory: build_model(config)
Factory->>Config: Extract model_type
Config-->>Factory: Returns "nemotron_h"
Factory->>Mapping: Lookup "nemotron_h"
Mapping-->>Factory: Returns Model
end
rect rgb(220, 240, 200)
Note over Factory,Model: New Lookup Flow
User->>Factory: register_custom_model_cls("NemotronHConfig", Model)
Factory->>Mapping: Store Model at key "NemotronHConfig"
User->>Factory: build_model(config)
Factory->>Config: Extract type(config).__name__
Config-->>Factory: Returns "NemotronHConfig"
Factory->>Mapping: Lookup "NemotronHConfig"
Mapping-->>Factory: Returns Model
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Tip 📝 Customizable high-level summaries are now available in beta!You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.
Example instruction:
Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
tensorrt_llm/_torch/auto_deploy/models/hf.py(4 hunks)tensorrt_llm/_torch/auto_deploy/models/modeling_nemotron_h.py(2 hunks)tests/unittest/_torch/auto_deploy/unit/singlegpu/models/test_hf.py(2 hunks)tests/unittest/_torch/auto_deploy/unit/singlegpu/models/test_hybrid_patches.py(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
**/*.py: The code developed for TensorRT-LLM should conform to Python 3.8+
Indent Python code with 4 spaces; do not use tabs
Always maintain the namespace when importing in Python, even if only one class or function from a module is used (e.g., usefrom package.subpackage import fooand thenfoo.SomeClass()instead offrom package.subpackage.foo import SomeClass)
Python filenames should use snake_case (e.g.,some_file.py)
Python class names should use PascalCase (e.g.,class SomeClass)
Python function and method names should use snake_case (e.g.,def my_awesome_function():)
Python local variable names should use snake_case, with prefixkfor variable names that start with a number (e.g.,k_99th_percentile = ...)
Python global variables should use upper snake_case with prefixG(e.g.,G_MY_GLOBAL = ...)
Python constants should use upper snake_case (e.g.,MY_CONSTANT = ...)
Avoid shadowing variables declared in an outer scope in Python
Initialize all externally visible members of a Python class in the constructor
For Python interfaces that may be used outside a file, prefer docstrings over comments
Python comments should be reserved for code within a function, or interfaces that are local to a file
Use Google style docstrings for Python classes and functions, which can be parsed by Sphinx
Python attributes and variables can be documented inline with type and description (e.g.,self.x = 5followed by"""<type>: Description of 'x'""")
Avoid using reflection in Python when functionality can be easily achieved without reflection
When using try-except blocks in Python, limit the except clause to the smallest set of specific errors possible instead of catching all exceptions
When using try-except blocks in Python to handle multiple possible variable types (duck-typing), keep the body of the try as small as possible and use the else block to implement the logic
Files:
tensorrt_llm/_torch/auto_deploy/models/hf.pytests/unittest/_torch/auto_deploy/unit/singlegpu/models/test_hf.pytensorrt_llm/_torch/auto_deploy/models/modeling_nemotron_h.pytests/unittest/_torch/auto_deploy/unit/singlegpu/models/test_hybrid_patches.py
**/*.{cpp,h,cu,py}
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
All TensorRT-LLM Open Source Software code files should contain an NVIDIA copyright header that includes the current year at the top
Files:
tensorrt_llm/_torch/auto_deploy/models/hf.pytests/unittest/_torch/auto_deploy/unit/singlegpu/models/test_hf.pytensorrt_llm/_torch/auto_deploy/models/modeling_nemotron_h.pytests/unittest/_torch/auto_deploy/unit/singlegpu/models/test_hybrid_patches.py
🧠 Learnings (3)
📓 Common learnings
Learnt from: djns99
Repo: NVIDIA/TensorRT-LLM PR: 6915
File: cpp/tensorrt_llm/kernels/cutlass_kernels/moe_gemm/moe_kernels.cu:4010-4012
Timestamp: 2025-08-14T23:23:27.449Z
Learning: For MOE (Mixture of Experts) code reviews in TensorRT-LLM, avoid repeatedly suggesting finalize fusion validation checks and safety assertions. The user djns99 has indicated these suggestions are repetitive and unwanted across multiple MOE-related changes.
📚 Learning: 2025-10-20T16:54:09.824Z
Learnt from: nvchenghaoz
Repo: NVIDIA/TensorRT-LLM PR: 8469
File: tensorrt_llm/_torch/auto_deploy/custom_ops/rms_norm.py:6-6
Timestamp: 2025-10-20T16:54:09.824Z
Learning: In tensorrt_llm/_torch/auto_deploy/custom_ops/rms_norm.py, the import `from ...modules.mamba.layernorm_gated import _layer_norm_fwd` is correct and should not be changed to modules.fla.layernorm_gated. The _layer_norm_fwd function exists in both modules/mamba/layernorm_gated.py and modules/fla/layernorm_gated.py, but the mamba version is the intended implementation for this use case.
Applied to files:
tensorrt_llm/_torch/auto_deploy/models/hf.pytensorrt_llm/_torch/auto_deploy/models/modeling_nemotron_h.py
📚 Learning: 2025-10-20T17:07:18.745Z
Learnt from: nvchenghaoz
Repo: NVIDIA/TensorRT-LLM PR: 8469
File: tensorrt_llm/_torch/auto_deploy/models/patches/nemotron_h.py:98-116
Timestamp: 2025-10-20T17:07:18.745Z
Learning: In NemotronH models (tensorrt_llm/_torch/auto_deploy/models/patches/nemotron_h.py), the gate (self.gate) returns topk_indices and topk_weights that are already in the correct shape to be passed directly to torch_ops.auto_deploy.torch_moe without needing to reshape them when hidden_states is flattened.
Applied to files:
tensorrt_llm/_torch/auto_deploy/models/modeling_nemotron_h.py
🧬 Code graph analysis (2)
tensorrt_llm/_torch/auto_deploy/models/hf.py (6)
tensorrt_llm/_torch/auto_deploy/custom_ops/attention_interface.py (1)
get(914-916)tensorrt_llm/_torch/auto_deploy/models/factory.py (1)
get(366-368)tensorrt_llm/_torch/auto_deploy/transform/interface.py (1)
get(523-525)tensorrt_llm/_torch/auto_deploy/distributed/common.py (1)
get(28-29)tensorrt_llm/_torch/auto_deploy/export/interface.py (1)
get(204-208)tensorrt_llm/_torch/auto_deploy/models/quant_config_reader.py (1)
get(74-77)
tensorrt_llm/_torch/auto_deploy/models/modeling_nemotron_h.py (1)
cpp/tensorrt_llm/kernels/trtllmGenKernels/blockScaleMoe/runner.h (1)
intermediate_size(281-281)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Pre-commit Check
🔇 Additional comments (12)
tests/unittest/_torch/auto_deploy/unit/singlegpu/models/test_hybrid_patches.py (1)
27-30: LGTM: Registration updated to use config class name.The registration correctly uses
config_cls_name="NemotronHConfig"to align with the refactored API.tests/unittest/_torch/auto_deploy/unit/singlegpu/models/test_hf.py (5)
137-145: LGTM: Test updated to use config class name.The test correctly uses
config_cls_nameinstead of the previousmodel_typeparameter, and validates the mapping is stored correctly.
151-154: LGTM: Config class added for type-based testing.The
FooConfigclass provides the necessary type fortype(config).__name__calls in the registration flow.
156-171: LGTM: Test updated for new API signature.The test correctly uses
config_cls_name=FooConfig.__name__and mocks_get_model_configto return aFooConfig()instance, properly exercising the new config-class-based registration flow.
173-189: LGTM: Test updated for new API signature.The test correctly uses
config_cls_name=FooConfig.__name__and validates that the custom model class is invoked through the_from_configmethod.
191-202: LGTM: Good test coverage for mapping isolation.This test validates that child factories inherit an independent
_custom_model_mappingand are not affected by parent registrations, ensuring proper isolation.tensorrt_llm/_torch/auto_deploy/models/modeling_nemotron_h.py (2)
169-171: LGTM: Correct removal of null d_mlp term.The refactored split correctly removes the
d_mlpvariable that was mathematically null (as noted in the PR description). The 3-way split into[intermediate_size, conv_dim, num_heads]properly distributes the projection output dimensions.
547-547: LGTM: Registration updated to use config class name.The commented registration line correctly uses
"NemotronHConfig"instead of the previous"nemotron_h"model type string, aligning with the refactored API semantics.tensorrt_llm/_torch/auto_deploy/models/hf.py (4)
113-115: LGTM: Comment accurately reflects the refactored mapping key.The updated comment correctly describes that the mapping uses the config class name rather than model_type.
219-220: LGTM: Lookup correctly derives config class name.The code properly extracts the config class name using
type(model_config).__name__and uses it to look up the custom model class from the mapping.
503-518: LGTM: Public API updated with correct semantics.The refactored
register_custom_model_clsmethod correctly:
- Accepts
config_cls_name: strinstead ofmodel_type- Updates the docstring to reflect the config class name semantics
- Stores the mapping using the provided config class name
519-521: LGTM: Subclass hook ensures mapping isolation.The
__init_subclass__hook properly initializes an independent_custom_model_mappingfor each subclass, preventing child factories from inheriting parent mappings. This aligns with the PR objective to prevent custom model mapping inheritance.
* Why? There were a couple of issues with the recently merged custom model injection for AutoDeploy + the reference implementation of nemotron H: - `d_mlp` was left in despite being mathematically always null (could lead to runtime issues during sharding). - the custom model mapping was inherited by children factories. * What? This commit fixes these issues, and refactors the key of the custom implementation to be based on the name of the configuration class as well. Signed-off-by: William Zhang <133824995+2ez4bz@users.noreply.github.com>
a51a2f1 to
953ea41
Compare
|
/bot run |
|
PR_Github #25613 [ run ] triggered by Bot. Commit: |
|
PR_Github #25613 [ run ] completed with state |
…VIDIA#9416) * Why? There were a couple of issues with the recently merged custom model injection for AutoDeploy + the reference implementation of nemotron H: - `d_mlp` was left in despite being mathematically always null (could lead to runtime issues during sharding). - the custom model mapping was inherited by children factories. * What? This commit fixes these issues, and refactors the key of the custom implementation to be based on the name of the configuration class as well. Signed-off-by: William Zhang <133824995+2ez4bz@users.noreply.github.com>

Summary by CodeRabbit
Breaking Changes
Improvements
✏️ Tip: You can customize this high-level summary in your review settings.
Description
fixes #9413
There were a couple of issues with the recently merged custom model injection for AutoDeploy + the reference implementation of nemotron H:
d_mlpwas left in despite being mathematically always null (could lead to runtime issues during sharding).This commit fixes these issues, and refactors the key of the custom implementation to be based on the name of the configuration class as well.
Test Coverage
PR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions)
Any new dependencies have been scanned for license and vulnerabilities
CODEOWNERS updated if ownership changes
Documentation updated as needed
Update tava architecture diagram if there is a significant design change in PR.
The reviewers assigned automatically/manually are appropriate for the PR.
Please check this after reviewing the above items as appropriate for this PR.
GitHub Bot Help
/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...Provide a user friendly way for developers to interact with a Jenkins server.
Run
/bot [-h|--help]to print this help message.See details below for each supported subcommand.
Details
run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental)]Launch build/test pipelines. All previously running jobs will be killed.
--reuse-test (optional)pipeline-id(OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.--disable-reuse-test(OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.--disable-fail-fast(OPTIONAL) : Disable fail fast on build/tests/infra failures.--skip-test(OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.--stage-list "A10-PyTorch-1, xxx"(OPTIONAL) : Only run the specified test stages. Examples: "A10-PyTorch-1, xxx". Note: Does NOT update GitHub check status.--gpu-type "A30, H100_PCIe"(OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.--test-backend "pytorch, cpp"(OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.--only-multi-gpu-test(OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.--disable-multi-gpu-test(OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.--add-multi-gpu-test(OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.--post-merge(OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx"(OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx".--detailed-log(OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.--debug(OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in thestage-listparameter to access the appropriate container environment. Note: Does NOT update GitHub check status.For guidance on mapping tests to stage names, see
docs/source/reference/ci-overview.mdand the
scripts/test_to_stage_mapping.pyhelper.kill
killKill all running builds associated with pull request.
skip
skip --comment COMMENTSkip testing for latest commit on pull request.
--comment "Reason for skipping build/test"is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.reuse-pipeline
reuse-pipelineReuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.