Skip to content

Conversation

@galagam
Copy link
Collaborator

@galagam galagam commented Jan 1, 2026

Description

When unused params are deleted after sharding, previous used of delattr on nested params caused an AttributeError. Instead, recursively search for the nested parameter name.
Standardize helper functions for handling of nested parameters.

Test Coverage

This is required to enable #10056, but requires #10308 to be merged to enable the currently skipped pytest
tests/integration/defs/accuracy/test_llm_api_autodeploy.py::TestNemotronSuperV3::test_bf16

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.

@galagam galagam requested a review from a team as a code owner January 1, 2026 08:23
@galagam galagam requested a review from QiJune January 1, 2026 08:23
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 1, 2026

📝 Walkthrough

Walkthrough

Consolidates duplicate attribute-manipulation utilities into a shared module and refactors two files to import them. The refactored module adds error-guarded attribute deletion that logs warnings instead of raising exceptions.

Changes

Cohort / File(s) Summary
New utility module
tensorrt_llm/_torch/auto_deploy/utils/attr.py
Added three functions for nested attribute operations via dotted paths: get_attr_by_name(), set_attr_by_name(), and del_attr_by_name(). Uses standard Python attribute access without special error handling.
Consolidation of utilities
tensorrt_llm/_torch/auto_deploy/transform/library/fuse_mamba_a_log.py
Removed local definitions of _get_attr_by_name(), _set_attr_by_name(), and _del_attr_by_name(). Added imports from shared utilities module with same names.
Error-guarded attribute deletion
tensorrt_llm/_torch/auto_deploy/transform/library/sharding.py
Replaced direct delattr() with guarded approach using _del_attr_by_name(). Changes from unconditional deletion to try/except with warning log when attribute does not exist.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Description check ❓ Inconclusive PR description includes core issues and test dependencies, but lacks details on solution approach and implementation rationale. Expand Description section to clearly explain how nested parameter deletion is implemented (recursive search mechanism) and why helper functions standardization improves the codebase.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: introducing utilities to handle deletion of nested parameters in the sharding module, which is the core objective of this PR.
✨ Finishing touches
  • 📝 Generate docstrings

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: 0

🧹 Nitpick comments (3)
tensorrt_llm/_torch/auto_deploy/utils/attr.py (3)

5-8: Add docstring to document the function's behavior.

This function is a public interface used by multiple modules and should have a Google-style docstring documenting its purpose, parameters, return value, and potential exceptions.

🔎 Proposed enhancement
 def get_attr_by_name(obj, name):
+    """Retrieve a nested attribute from an object using a dotted path.
+
+    Args:
+        obj: The object to retrieve the attribute from.
+        name: Dot-separated attribute path (e.g., "layer.0.weight").
+
+    Returns:
+        The attribute value at the specified path.
+
+    Raises:
+        AttributeError: If any part of the path does not exist.
+    """
     for part in name.split("."):
         obj = getattr(obj, part)
     return obj

As per coding guidelines, prefer docstrings over comments for interfaces used outside a file.


11-15: Add docstring to document the function's behavior.

This function is a public interface used by multiple modules and should have a Google-style docstring documenting its purpose, parameters, and potential exceptions.

🔎 Proposed enhancement
 def set_attr_by_name(obj, name, value):
+    """Set a nested attribute on an object using a dotted path.
+
+    Args:
+        obj: The object to set the attribute on.
+        name: Dot-separated attribute path (e.g., "layer.0.weight").
+        value: The value to set the attribute to.
+
+    Raises:
+        AttributeError: If any intermediate part of the path does not exist.
+    """
     parts = name.split(".")
     for part in parts[:-1]:
         obj = getattr(obj, part)
     setattr(obj, parts[-1], value)

As per coding guidelines, prefer docstrings over comments for interfaces used outside a file.


18-22: Add docstring to document the function's behavior.

This function is a public interface used by multiple modules and should have a Google-style docstring documenting its purpose, parameters, and potential exceptions.

🔎 Proposed enhancement
 def del_attr_by_name(obj, name):
+    """Delete a nested attribute from an object using a dotted path.
+
+    Args:
+        obj: The object to delete the attribute from.
+        name: Dot-separated attribute path (e.g., "layer.0.weight").
+
+    Raises:
+        AttributeError: If any part of the path does not exist.
+    """
     parts = name.split(".")
     for part in parts[:-1]:
         obj = getattr(obj, part)
     delattr(obj, parts[-1])

As per coding guidelines, prefer docstrings over comments for interfaces used outside a file.

📜 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 9f5b750 and c86b260.

📒 Files selected for processing (3)
  • tensorrt_llm/_torch/auto_deploy/transform/library/fuse_mamba_a_log.py
  • tensorrt_llm/_torch/auto_deploy/transform/library/sharding.py
  • tensorrt_llm/_torch/auto_deploy/utils/attr.py
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

**/*.py: 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
Python files should use snake_case naming: some_file.py
Python classes should use PascalCase naming: class SomeClass
Python functions and methods should use snake_case naming: def my_awesome_function():
Python local variables should use snake_case naming: my_variable = ...
Python variable names that start with a number should be prefixed with 'k': k_99th_percentile = ...
Python global variables should use upper snake_case with prefix 'G': G_MY_GLOBAL = ...
Python constants should use upper snake_case naming: 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 in Python for classes and functions, which can be parsed by Sphinx
Python attributes and variables can be documented inline with type and description
Avoid using reflection in Python when functionality can be easily achieved without reflection
When using try-except blocks in Python, limit the except to the smallest set of errors possible
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, using the else block for logic

Files:

  • tensorrt_llm/_torch/auto_deploy/utils/attr.py
  • tensorrt_llm/_torch/auto_deploy/transform/library/fuse_mamba_a_log.py
  • tensorrt_llm/_torch/auto_deploy/transform/library/sharding.py
**/*.{cpp,h,cu,cuh,py}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

All TensorRT-LLM Open Source Software code should contain an NVIDIA copyright header that includes the year of its latest meaningful modification

Files:

  • tensorrt_llm/_torch/auto_deploy/utils/attr.py
  • tensorrt_llm/_torch/auto_deploy/transform/library/fuse_mamba_a_log.py
  • tensorrt_llm/_torch/auto_deploy/transform/library/sharding.py
🧠 Learnings (1)
📚 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/transform/library/fuse_mamba_a_log.py
🧬 Code graph analysis (2)
tensorrt_llm/_torch/auto_deploy/transform/library/fuse_mamba_a_log.py (1)
tensorrt_llm/_torch/auto_deploy/utils/attr.py (3)
  • del_attr_by_name (18-22)
  • get_attr_by_name (5-8)
  • set_attr_by_name (11-15)
tensorrt_llm/_torch/auto_deploy/transform/library/sharding.py (1)
tensorrt_llm/_torch/auto_deploy/utils/attr.py (1)
  • del_attr_by_name (18-22)
⏰ 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 (4)
tensorrt_llm/_torch/auto_deploy/transform/library/fuse_mamba_a_log.py (1)

34-36: LGTM! Clean refactoring to shared utilities.

The refactoring successfully consolidates duplicate attribute-manipulation helpers into a shared module, reducing code duplication while preserving existing functionality. The import convention with underscore prefixes is consistent with the file's style.

tensorrt_llm/_torch/auto_deploy/transform/library/sharding.py (2)

36-36: LGTM! Import added to support nested parameter deletion.

The import of the shared del_attr_by_name utility enables proper handling of nested attribute paths for expert weight cleanup.


1471-1476: LGTM! Guarded deletion prevents failures on missing attributes.

The try-except wrapper provides graceful error handling when attempting to delete potentially missing expert parameters. This follows the coding guideline to limit except blocks to the smallest set of errors possible.

tensorrt_llm/_torch/auto_deploy/utils/attr.py (1)

1-3: Complete the copyright header.

The copyright header is incomplete. According to coding guidelines, all TensorRT-LLM code should contain a full NVIDIA copyright header including the Apache 2.0 license text.

🔎 Proposed fix
 # SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES.
 # SPDX-License-Identifier: Apache-2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.

As per coding guidelines, all Open Source Software code should contain a complete NVIDIA copyright header.

⛔ Skipped due to learnings
Learnt from: CR
Repo: NVIDIA/TensorRT-LLM PR: 0
File: CODING_GUIDELINES.md:0-0
Timestamp: 2025-12-17T22:39:44.244Z
Learning: Applies to **/*.{cpp,h,cu,cuh,py} : All TensorRT-LLM Open Source Software code should contain an NVIDIA copyright header that includes the year of its latest meaningful modification
Learnt from: xinhe-nv
Repo: NVIDIA/TensorRT-LLM PR: 8534
File: scripts/format_test_list.py:1-6
Timestamp: 2025-10-22T06:53:47.017Z
Learning: The file `scripts/format_test_list.py` in the TensorRT-LLM repository does not require the NVIDIA Apache-2.0 copyright header.
Learnt from: galagam
Repo: NVIDIA/TensorRT-LLM PR: 6487
File: tests/unittest/_torch/auto_deploy/unit/singlegpu/test_ad_trtllm_bench.py:1-12
Timestamp: 2025-08-06T13:58:07.506Z
Learning: In TensorRT-LLM, test files (files under tests/ directories) do not require NVIDIA copyright headers, unlike production source code files. Test files typically start directly with imports, docstrings, or code.
Learnt from: tburt-nv
Repo: NVIDIA/TensorRT-LLM PR: 9881
File: cpp/kernels/fmha_v2/train_ops/train_setup.py:35-36
Timestamp: 2025-12-10T19:14:58.432Z
Learning: In cpp/kernels/fmha_v2/train_ops/train_setup.py, the embedded C++ template copyright headers (fmha_dgrad_v2_flash_attention_template and fmha_fprop_v2_flash_attention_template) use copyright dates "2011-2023" because the file was imported without meaningful changes since its original creation. The original copyright dates are preserved for historical accuracy rather than updated to the current year.
Learnt from: CR
Repo: NVIDIA/TensorRT-LLM PR: 0
File: CODING_GUIDELINES.md:0-0
Timestamp: 2025-12-17T22:39:44.244Z
Learning: Applies to **/*.h : The preprocessor guard name in C++ must have prefix `TRTLLM_` followed by the filename, all in caps. Only use the file name, not directory names
Learnt from: nv-lschneider
Repo: NVIDIA/TensorRT-LLM PR: 7910
File: cpp/tensorrt_llm/kernels/nccl_device/config.cu:15-17
Timestamp: 2025-09-23T15:01:00.070Z
Learning: In TensorRT-LLM NCCL device kernels, the <sstream> header is not needed as an explicit include in config.cu because it's provided transitively through other headers. Local compilation testing confirms this works without the explicit include.
Learnt from: farshadghodsian
Repo: NVIDIA/TensorRT-LLM PR: 7101
File: docs/source/blogs/tech_blog/blog9_Deploying_GPT_OSS_on_TRTLLM.md:36-36
Timestamp: 2025-08-21T00:16:56.457Z
Learning: TensorRT-LLM container release tags in documentation should only reference published NGC container images. The README badge version may be ahead of the actual published container versions.
Learnt from: CR
Repo: NVIDIA/TensorRT-LLM PR: 0
File: CODING_GUIDELINES.md:0-0
Timestamp: 2025-12-17T22:39:44.244Z
Learning: Applies to **/*.py : Code developed for TensorRT-LLM should conform to Python 3.8+
Learnt from: CR
Repo: NVIDIA/TensorRT-LLM PR: 0
File: CODING_GUIDELINES.md:0-0
Timestamp: 2025-12-17T22:39:44.244Z
Learning: Applies to **/*.h : Use a preprocessor guard in C++ header files with the format `TRTLLM_<FILENAME>_H` derived from the filename in all caps
Learnt from: nzmora-nvidia
Repo: NVIDIA/TensorRT-LLM PR: 9163
File: tensorrt_llm/_torch/auto_deploy/custom_ops/quant.py:107-113
Timestamp: 2025-11-14T11:22:03.729Z
Learning: In TensorRT-LLM AutoDeploy custom ops, when adding hardware capability checks to select between kernel implementations (e.g., cuBLAS vs. CUDA kernel), use descriptive variable names that identify the specific GPU architectures or families being targeted (e.g., `is_blackwell_geforce_or_ada`) rather than generic names like `enable_cuda_core`. This makes it clear that the code is selecting an implementation path based on hardware capabilities, not enabling/disabling hardware features.

Signed-off-by: Gal Hubara Agam <[email protected]>
@galagam galagam changed the title [#10056][fix]: AutoDeplot: Handle deletion of nested params in sharding [#10056][fix]: AutoDeploy: Handle deletion of nested params in sharding Jan 1, 2026
@galagam
Copy link
Collaborator Author

galagam commented Jan 1, 2026

@coderabbitai generate docstrings

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 1, 2026

✅ Actions performed

Initiated docstring generation; will generate only if new commits exist.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 1, 2026

Caution

Docstrings generation - FAILED

An unexpected error occurred while opening a pull request: Reference update failed - https://docs.github.com/rest/git/refs#create-a-reference

Signed-off-by: Gal Hubara Agam <[email protected]>
@galagam galagam changed the title [#10056][fix]: AutoDeploy: Handle deletion of nested params in sharding [#10056][fix] AutoDeploy: Handle deletion of nested params in sharding Jan 1, 2026
@galagam
Copy link
Collaborator Author

galagam commented Jan 1, 2026

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #30331 [ run ] triggered by Bot. Commit: 8b1e44d

@tensorrt-cicd
Copy link
Collaborator

PR_Github #30331 [ run ] completed with state SUCCESS. Commit: 8b1e44d
/LLM/main/L0_MergeRequest_PR pipeline #23363 completed with status: 'SUCCESS'
Pipeline passed with automatic retried tests. Check the rerun report for details.

@galagam galagam merged commit 5845951 into NVIDIA:main Jan 1, 2026
8 of 9 checks passed
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.

3 participants