Skip to content

[#9413][fix] Minor fixes to nemotron H and custom models in AD#9416

Merged
2ez4bz merged 1 commit intoNVIDIA:mainfrom
2ez4bz:dev-nano-ref-impl
Nov 25, 2025
Merged

[#9413][fix] Minor fixes to nemotron H and custom models in AD#9416
2ez4bz merged 1 commit intoNVIDIA:mainfrom
2ez4bz:dev-nano-ref-impl

Conversation

@2ez4bz
Copy link
Collaborator

@2ez4bz 2ez4bz commented Nov 24, 2025

Summary by CodeRabbit

  • Breaking Changes

    • Updated custom model registration API to use configuration class names instead of model type identifiers. Existing custom model registrations will need to be updated accordingly.
  • Improvements

    • Enhanced model factory with improved subclass support and isolated model mappings between parent and child factory instances.

✏️ Tip: You can customize this high-level summary in your review settings.

Description

fixes #9413

  • 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.

Test Coverage

  • added tests for custom mappings between children and parent being independent

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 the stage-list parameter 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.md
and the scripts/test_to_stage_mapping.py helper.

kill

kill

Kill all running builds associated with pull request.

skip

skip --comment COMMENT

Skip 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-pipeline

Reuse 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.

@2ez4bz 2ez4bz requested a review from a team as a code owner November 24, 2025 21:11
@2ez4bz 2ez4bz requested a review from galagam November 24, 2025 21:11
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 24, 2025

📝 Walkthrough

Walkthrough

The custom model registration mechanism is refactored from using model_type strings to config_cls_name identifiers. The public API of register_custom_model_cls is updated accordingly, an __init_subclass__ hook is added for subclass isolation, and all registrations and tests are updated to use the new config class name scheme.

Changes

Cohort / File(s) Summary
Core registration API refactoring
tensorrt_llm/_torch/auto_deploy/models/hf.py
Updated register_custom_model_cls method signature to accept config_cls_name: str instead of model_type: str. Added __init_subclass__ hook to initialize independent _custom_model_mapping for subclasses. Modified _build_model to derive config_cls_name from type(model_config).__name__ for lookups. Updated docstrings to reflect parameter changes.
Model registration update
tensorrt_llm/_torch/auto_deploy/models/modeling_nemotron_h.py
Changed registration call from register_custom_model_cls("nemotron_h", ...) to register_custom_model_cls("NemotronHConfig", ...). Modified projection split logic in NemotronHMamba2Mixer.torch_forward from dynamic d_mlp calculation to fixed split into [intermediate_size, conv_dim, num_heads].
Unit test updates
tests/unittest/_torch/auto_deploy/unit/singlegpu/models/test_hf.py
Updated all test cases to use config_cls_name parameter instead of model_type. Added FooConfig class for type-based config testing. Added two new tests: test_custom_model_mapping_in_parent_does_not_affect_children and test_custom_model_mapping_in_parent_does_not_affect_parent to verify mapping isolation between factory classes.
Integration test update
tests/unittest/_torch/auto_deploy/unit/singlegpu/models/test_hybrid_patches.py
Updated registration call to use config_cls_name="NemotronHConfig" instead of model_type="nemotron_h".

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Focus areas requiring extra attention:
    • The projection split logic change in NemotronHMamba2Mixer.torch_forward (removal of dynamic d_mlp calculation and fixed split into three segments) — verify that the new hardcoded split maintains correctness for the Nemotron model.
    • __init_subclass__ hook implementation — ensure subclass isolation of _custom_model_mapping is correct and doesn't introduce unexpected state sharing.
    • Two new test cases for mapping isolation between parent and child factories — verify these comprehensively cover edge cases.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.27% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly indicates the PR fixes issues in nemotron H and custom models in AutoDeploy, accurately summarizing the main changes.
Description check ✅ Passed PR description clearly explains the issues fixed and provides test coverage details, matching the template requirements.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1ce483c and a51a2f1.

📒 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., use from package.subpackage import foo and then foo.SomeClass() instead of from 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 prefix k for variable names that start with a number (e.g., k_99th_percentile = ...)
Python global variables should use upper snake_case with prefix G (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 = 5 followed 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.py
  • tests/unittest/_torch/auto_deploy/unit/singlegpu/models/test_hf.py
  • tensorrt_llm/_torch/auto_deploy/models/modeling_nemotron_h.py
  • tests/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.py
  • tests/unittest/_torch/auto_deploy/unit/singlegpu/models/test_hf.py
  • tensorrt_llm/_torch/auto_deploy/models/modeling_nemotron_h.py
  • tests/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.py
  • tensorrt_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_name instead of the previous model_type parameter, and validates the mapping is stored correctly.


151-154: LGTM: Config class added for type-based testing.

The FooConfig class provides the necessary type for type(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_config to return a FooConfig() 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_config method.


191-202: LGTM: Good test coverage for mapping isolation.

This test validates that child factories inherit an independent _custom_model_mapping and 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_mlp variable 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_cls method correctly:

  • Accepts config_cls_name: str instead of model_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_mapping for 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>
@lucaslie lucaslie changed the title [None][fix] Minor fixes to nemotron H and custom models in AD [#9413][fix] Minor fixes to nemotron H and custom models in AD Nov 24, 2025
Copy link
Member

@lucaslie lucaslie left a comment

Choose a reason for hiding this comment

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

lgtm

@2ez4bz
Copy link
Collaborator Author

2ez4bz commented Nov 24, 2025

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #25613 [ run ] triggered by Bot. Commit: 953ea41

@tensorrt-cicd
Copy link
Collaborator

PR_Github #25613 [ run ] completed with state SUCCESS. Commit: 953ea41
/LLM/main/L0_MergeRequest_PR pipeline #19404 completed with status: 'SUCCESS'
Pipeline passed with automatic retried tests. Check the rerun report for details.

@2ez4bz 2ez4bz merged commit a4049fc into NVIDIA:main Nov 25, 2025
9 checks passed
@2ez4bz
Copy link
Collaborator Author

2ez4bz commented Nov 25, 2025

first try

codego7250 pushed a commit to codego7250/TensorRT-LLM that referenced this pull request Dec 11, 2025
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: AutoDeploy: nano 3 custom modeling code follow-ups

3 participants