Skip to content

[https://nvbugs/5448464][fix] Partially fix LoRA overallocation for Nemotron NAS#12817

Merged
brb-nv merged 1 commit into
NVIDIA:mainfrom
brb-nv:user/brb/partially-fix-lora-alloc-nemotron-nas
Apr 10, 2026
Merged

[https://nvbugs/5448464][fix] Partially fix LoRA overallocation for Nemotron NAS#12817
brb-nv merged 1 commit into
NVIDIA:mainfrom
brb-nv:user/brb/partially-fix-lora-alloc-nemotron-nas

Conversation

@brb-nv

@brb-nv brb-nv commented Apr 7, 2026

Copy link
Copy Markdown
Collaborator

Description

This is to fix https://nvbugspro.nvidia.com/bug/5448464.

Background:

  • Nemotron-NAS (DeciLM) architecture uses neural architecture search to produce models with variable per-layer structure — some layers have full attention and MLP, others use cheap linear stubs (replace_with_linear), and some skip modules entirely (no_op).
  • When LoRA is enabled, the C++ PeftCacheManager allocates a GPU cache sized by num_device_module_layer, which is computed in Python as max_lora_rank × num_lora_modules × max_loras. On Nemotron-Super-49B with LoRA rank 64, this cache requests ~2.46 GiB but only ~2.44 GiB remains after model + KV cache allocation, causing cudaMallocAsync OOM during executor creation.

Root cause

There are two forms of LoRA cache over-allocation:

  • Inflated page size: _infer_nemotron_ffn_mult uses max(ffn_mult) across all layers as a single uniform mlp_hidden_size. This inflates LoraModule dimensions and therefore cache page size, since the C++ API requires uniform module dimensions across layers. Fixing this requires C++ changes to support per-layer LoraModule dimensions (tracked by TRTLLM-5045).

  • Inflated module count: num_lora_modules is computed as num_hidden_layers × len(target_modules), assuming every layer has every module type. For Nemotron-NAS, this allocates cache slots for MLP LoRA on layers with no MLP (no_op or replace_with_linear), and attention LoRA on layers with no attention. These layers don't create those submodules in the PyTorch model, and LoRA adapters can't have weights for them — the slots are pure waste.

Fix:

  • Address inflated module count only.
  • Introduce _compute_num_lora_modules() which, for models with block_configs, inspects each layer to determine whether it has LoRA-capable attention and/or MLP. Target modules are classified as attention, MLP, or other, and only counted for layers that actually have that module type.
  • For models without block_configs, behavior is unchanged.
  • This change suffices to bring back the waived LoRA test for Nemotron NAS on H200.

Test Coverage

$ pytest tests/unittest/others/test_lora_module_count.py -s -v
$ pytest tests/unittest/llmapi/test_llm_pytorch.py::test_nemotron_nas_lora -s -v

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

To see a list of available CI bot commands, please comment /bot help.

Summary by CodeRabbit

  • Bug Fixes

    • Improved LoRA PEFT cache sizing accuracy for configurations with variable layer structures
    • Re-enabled Nemotron LoRA test case that was previously skipped
  • Tests

    • New unit test validates LoRA module counting across diverse configuration scenarios, including cases with disabled attention/FFN modules and linear replacements

@brb-nv
brb-nv requested a review from a team as a code owner April 7, 2026 21:53
@brb-nv
brb-nv requested a review from leslie-fang25 April 7, 2026 21:53
@brb-nv

brb-nv commented Apr 7, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@brb-nv
brb-nv requested a review from shaharmor98 April 7, 2026 21:54
@coderabbitai

coderabbitai Bot commented Apr 7, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR improves LoRA PEFT cache sizing calculation in TensorRT-LLM by introducing a new _compute_num_lora_modules function that dynamically accounts for per-layer block configurations. When block configurations exist, it counts only LoRA-capable attention and FFN module-layer slots; otherwise, it falls back to a uniform calculation. A comprehensive unit test module is added to validate the function across multiple structural scenarios.

Changes

Cohort / File(s) Summary
LoRA Module Computation Logic
tensorrt_llm/_torch/pyexecutor/_util.py
Replaced static LoRA cache sizing formula with new _compute_num_lora_modules function. Added _ATTN_MODULES and _MLP_MODULES sets to categorize target modules. New function intelligently computes module counts by checking block configurations, excluding layers where attention/FFN are no-op or replaced, and logging component breakdowns.
Unit Test Module
tests/unittest/others/test_lora_module_count.py
New comprehensive test suite validating _compute_num_lora_modules across nine scenarios: uniform fallback when block configs absent, equivalence with fully LoRA-capable layers, FFN/attention exclusion logic, replace-with-linear handling, variable block patterns, attention-only queries, unrecognized module names, and empty target modules.
Test Integration & Modifications
tests/integration/test_lists/test-db/l0_a10.yml, tests/unittest/llmapi/test_llm_pytorch.py
Added new unit test to l0_a10 PyTorch pre-merge test list. Removed pytest.mark.skip decorator from test_nemotron_nas_lora, allowing the test to execute under existing GPU memory and suite conditions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 70.59% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description check ✅ Passed The PR description is comprehensive and complete, covering background, root causes, the fix approach, test coverage, and all checklist items with the final checkbox marked complete.
Title check ✅ Passed The title 'Partially fix LoRA overallocation for Nemotron NAS' directly and clearly summarizes the main change—fixing an inflated LoRA module count calculation for Nemotron-NAS models. It accurately reflects the PR's primary objective without vague language.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
tensorrt_llm/_torch/pyexecutor/_util.py (2)

1574-1578: Replace Unicode multiplication sign with ASCII 'x'.

The Unicode × (MULTIPLICATION SIGN, U+00D7) may cause issues with log parsers or terminals. Use ASCII x instead.

Suggested fix
     logger.info(f"LoRA module-layer count: {total} "
-                f"(attn: {layers_with_attn}×{len(attn_modules)}, "
-                f"mlp: {layers_with_mlp}×{len(mlp_modules)}, "
-                f"other: {num_layers}×{len(other_modules)}, "
+                f"(attn: {layers_with_attn}x{len(attn_modules)}, "
+                f"mlp: {layers_with_mlp}x{len(mlp_modules)}, "
+                f"other: {num_layers}x{len(other_modules)}, "
                 f"uniform would be {num_layers * len(all_target_modules)})")
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tensorrt_llm/_torch/pyexecutor/_util.py` around lines 1574 - 1578, Log
message uses Unicode multiplication sign '×'; update the formatted string in the
logger.info call inside _util.py to replace every '×' with ASCII 'x' so log
parsers/terminals won't break. Edit the logger.info(...) invocation (referenced
by the variables total, layers_with_attn, attn_modules, layers_with_mlp,
mlp_modules, num_layers, other_modules, all_target_modules) and change the three
occurrences of '×' to 'x' in the f-string.

1538-1550: Add return type annotation.

The function should include a return type hint for consistency with coding guidelines.

Suggested fix
-def _compute_num_lora_modules(pretrained_config, all_target_modules):
+def _compute_num_lora_modules(pretrained_config, all_target_modules: list[str]) -> int:
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tensorrt_llm/_torch/pyexecutor/_util.py` around lines 1538 - 1550, The
function _compute_num_lora_modules lacks a return type annotation; update its
signature to include an explicit return type (e.g., change def
_compute_num_lora_modules(pretrained_config, all_target_modules): to def
_compute_num_lora_modules(pretrained_config, all_target_modules) -> int:) and
ensure all return paths (like the existing return num_layers *
len(all_target_modules)) are consistent with that type.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tensorrt_llm/_torch/pyexecutor/_util.py`:
- Around line 1559-1568: The code currently inspects nonexistent attributes on
AttentionConfig/FFNConfig (causing AttributeError); update the helper functions
_has_lora_capable_attn and _has_lora_capable_ffn to use the DeciLayerConfig
boolean properties (use bc.is_attention_layer in place of the old
attention.no_op/replace_with_linear checks and bc.is_mlp_layer in place of
ffn.no_op/replace_with_linear), and then compute layers_with_attn and
layers_with_mlp using those updated helpers so the logic works with Nemotron-NAS
block configs.

In `@tests/unittest/others/test_lora_module_count.py`:
- Around line 29-37: The function _compute_num_lora_modules is accessing
bc.attention.no_op and bc.attention.replace_with_linear (and similar ffn fields)
but DeciLayerConfig exposes attention.impl and ffn.impl as enum values; change
_compute_num_lora_modules to inspect bc.attention.impl and bc.ffn.impl and
compare them to the appropriate AttentionImplementation enum members (e.g.,
AttentionImplementation.NO_OP, AttentionImplementation.LINEAR or the equivalent
enum names used in the code) when deciding whether to count LoRA modules, and
remove/replace any references to no_op/replace_with_linear so real
DeciLayerConfig instances do not raise AttributeError. Ensure any logic
branching that used the old booleans maps to the same behavior using the enum
comparisons.

---

Nitpick comments:
In `@tensorrt_llm/_torch/pyexecutor/_util.py`:
- Around line 1574-1578: Log message uses Unicode multiplication sign '×';
update the formatted string in the logger.info call inside _util.py to replace
every '×' with ASCII 'x' so log parsers/terminals won't break. Edit the
logger.info(...) invocation (referenced by the variables total,
layers_with_attn, attn_modules, layers_with_mlp, mlp_modules, num_layers,
other_modules, all_target_modules) and change the three occurrences of '×' to
'x' in the f-string.
- Around line 1538-1550: The function _compute_num_lora_modules lacks a return
type annotation; update its signature to include an explicit return type (e.g.,
change def _compute_num_lora_modules(pretrained_config, all_target_modules): to
def _compute_num_lora_modules(pretrained_config, all_target_modules) -> int:)
and ensure all return paths (like the existing return num_layers *
len(all_target_modules)) are consistent with that type.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6bf88908-12c6-4cbf-aa72-2c9050e6bc69

📥 Commits

Reviewing files that changed from the base of the PR and between a1777fd and 15341ad.

📒 Files selected for processing (4)
  • tensorrt_llm/_torch/pyexecutor/_util.py
  • tests/integration/test_lists/test-db/l0_a10.yml
  • tests/unittest/llmapi/test_llm_pytorch.py
  • tests/unittest/others/test_lora_module_count.py
💤 Files with no reviewable changes (1)
  • tests/unittest/llmapi/test_llm_pytorch.py

Comment thread tensorrt_llm/_torch/pyexecutor/_util.py
Comment thread tests/unittest/others/test_lora_module_count.py
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #42191 [ run ] triggered by Bot. Commit: 15341ad Link to invocation

@brb-nv
brb-nv force-pushed the user/brb/partially-fix-lora-alloc-nemotron-nas branch from 15341ad to d0be243 Compare April 7, 2026 22:31
@brb-nv

brb-nv commented Apr 7, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #42193 [ run ] triggered by Bot. Commit: d0be243 Link to invocation

@brb-nv brb-nv changed the title [https://nvbugs/5448464][fix] Partially fix LoRA over-allocation for Nemotron NAS [https://nvbugs/5448464][fix] Partially fix LoRA overallocation for Nemotron NAS Apr 7, 2026
@brb-nv
brb-nv force-pushed the user/brb/partially-fix-lora-alloc-nemotron-nas branch from d0be243 to d43004f Compare April 8, 2026 00:07
@brb-nv

brb-nv commented Apr 8, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #42204 [ run ] triggered by Bot. Commit: d43004f Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #42204 [ run ] completed with state SUCCESS. Commit: d43004f
/LLM/main/L0_MergeRequest_PR pipeline #33022 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

Link to invocation

@brb-nv

brb-nv commented Apr 8, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@brb-nv
brb-nv enabled auto-merge (squash) April 8, 2026 12:44
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #42337 [ run ] triggered by Bot. Commit: d43004f Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #42337 [ run ] completed with state SUCCESS. Commit: d43004f
/LLM/main/L0_MergeRequest_PR pipeline #33125 completed with status: 'SUCCESS'

CI Report

Link to invocation

…Nemotron NAS

Signed-off-by: Balaram Buddharaju <169953907+brb-nv@users.noreply.github.com>
@brb-nv
brb-nv force-pushed the user/brb/partially-fix-lora-alloc-nemotron-nas branch from d43004f to 13c56d1 Compare April 8, 2026 18:21
@brb-nv

brb-nv commented Apr 8, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #42380 [ run ] triggered by Bot. Commit: 13c56d1 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #42380 [ run ] completed with state SUCCESS. Commit: 13c56d1
/LLM/main/L0_MergeRequest_PR pipeline #33159 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

Link to invocation

@brb-nv

brb-nv commented Apr 9, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #42487 [ run ] triggered by Bot. Commit: 13c56d1 Link to invocation

@brb-nv

brb-nv commented Apr 9, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #42508 [ run ] triggered by Bot. Commit: 13c56d1 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #42487 [ run ] completed with state ABORTED. Commit: 13c56d1

Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #42508 [ run ] completed with state SUCCESS. Commit: 13c56d1
/LLM/main/L0_MergeRequest_PR pipeline #33252 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

Link to invocation

@brb-nv

brb-nv commented Apr 9, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #42573 [ run ] triggered by Bot. Commit: 13c56d1 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #42573 [ run ] completed with state SUCCESS. Commit: 13c56d1
/LLM/main/L0_MergeRequest_PR pipeline #33306 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

Link to invocation

@brb-nv

brb-nv commented Apr 10, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #42607 [ run ] triggered by Bot. Commit: 13c56d1 Link to invocation

@brb-nv

brb-nv commented Apr 10, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #42696 [ run ] triggered by Bot. Commit: 13c56d1 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #42696 [ run ] completed with state SUCCESS. Commit: 13c56d1
/LLM/main/L0_MergeRequest_PR pipeline #33391 completed with status: 'SUCCESS'

CI Report

Link to invocation

@brb-nv
brb-nv merged commit 31cab8d into NVIDIA:main Apr 10, 2026
5 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