Skip to content

[None][chore] Integration tests for MoE lora & bugfixes - #15271

Merged
brb-nv merged 1 commit into
NVIDIA:mainfrom
brb-nv:user/brb/restore-routed-expert-lora-test
Jun 16, 2026
Merged

[None][chore] Integration tests for MoE lora & bugfixes#15271
brb-nv merged 1 commit into
NVIDIA:mainfrom
brb-nv:user/brb/restore-routed-expert-lora-test

Conversation

@brb-nv

@brb-nv brb-nv commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Description

This MR adds integration tests and 3 bugfixes for MoE lora. Details about fixes:

  • Per-request shape fix: reshape weight_pointers from flat [num_seqs*3] to [num_seqs, 3] so the MoE op gets the table shape it expects.
  • Rank-0 crash fix: skip the out-GEMM for no-adapter (rank-0) rows so it doesn't run against a null pointer.
  • CUDA-graph staleness fix: refresh the MoE slot pointer table when slots change so replay uses current pointers, not stale ones.

To be merged after #14881.

Test Coverage

$ pytest tests/unittest/llmapi/test_llm_pytorch.py::test_qwen_moe_routed_expert_multi_lora_varying_ranks -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)

  • If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title.

  • 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

    • Fixed GEMM operation handling for inactive LoRA rows in Mixture of Experts configurations.
    • Corrected weight pointer tensor reshaping in fused MoE operations.
    • Ensured CUDA graph replay uses up-to-date cached weight pointer tables for MoE LoRA.
  • Tests

    • Added comprehensive test coverage for routed-expert Mixture of Experts LoRA with variable adapter ranks.

@brb-nv brb-nv changed the title [None][chore] Integration tests for MoE lora [None][chore] Integration tests for MoE lora & bugfixes Jun 11, 2026
@brb-nv
brb-nv force-pushed the user/brb/restore-routed-expert-lora-test branch 6 times, most recently from 5889aa7 to e043499 Compare June 11, 2026 19:41
@brb-nv
brb-nv marked this pull request as ready for review June 11, 2026 19:42
@brb-nv
brb-nv requested review from a team as code owners June 11, 2026 19:42
@brb-nv
brb-nv requested review from venkywonka and xxi-nv June 11, 2026 19:42
@brb-nv

brb-nv commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR implements rank-0 handling and CUDA graph cache management for routed-expert MoE LoRA support. CUTLASS kernels conditionally skip output GEMM operations for rank-0 rows; tensor weight pointers are reshaped to correct layout; and CUDA graph caches are refreshed after pointer updates to avoid stale references. Integration tests validate the feature across multiple execution modes.

Changes

Routed-Expert MoE LoRA Implementation

Layer / File(s) Summary
Kernel rank-0 optimization for GEMM problem sizing
cpp/tensorrt_llm/kernels/cutlass_kernels/moe_gemm/moe_lora_problem_builder.cu
Conditional output GEMM N-dimension zeroing for rank-0 rows forces grouped GEMM to skip unnecessary tiles and avoid dereferencing null B pointers.
MoE LoRA weight pointers tensor reshaping
tensorrt_llm/_torch/modules/fused_moe/fused_moe_cutlass.py
Weight pointers tensor is reshaped from flat row-major layout to [num_seqs, 3] table format before passing to fused MoE kernel.
CUDA graph cache refresh for MoE slot pointers
tensorrt_llm/_torch/peft/lora/cuda_graph_lora_params.py
New _refresh_moe_slot_ptr_cache() method repacks pinned MoE pointer buffers after host pointer updates; update_weight_pointers() calls this method to prevent stale pointer dereferences on graph replay.
Routed-expert MoE LoRA test infrastructure and validation
tests/unittest/llmapi/test_llm_pytorch.py
Helper function _write_routed_expert_lora_adapter() generates per-expert routed-expert LoRA adapters on disk; test test_qwen_moe_routed_expert_multi_lora_varying_ranks validates multi-adapter batching across eager-host, eager-device, and CUDA-graph decode modes on Qwen1.5-MoE.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • rosenrodt
  • nv-guomingz
  • xinhe-nv
  • yuxianq
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed Title follows the template format with [None][chore] prefix and clearly describes the main changes: integration tests and bugfixes for MoE LoRA.
Description check ✅ Passed Description covers all required sections: explains the issue and three specific fixes, lists test coverage command, and confirms PR checklist completion.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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: 1

🧹 Nitpick comments (1)
tests/unittest/llmapi/test_llm_pytorch.py (1)

1099-1152: ⚡ Quick win

Annotate the new helper and test entrypoint.

Both new functions are introduced untyped, which makes the adapter-shape contract here harder to follow and diverges from the repo’s Python typing rule. Please add parameter and return annotations (-> None for the test) while this helper is still small.

As per coding guidelines, Python functions should always be annotated with explicit return types.

Also applies to: 1162-1163

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unittest/llmapi/test_llm_pytorch.py` around lines 1099 - 1152, The
helper _write_routed_expert_lora_adapter and the new test entrypoint must have
explicit type annotations; update _write_routed_expert_lora_adapter signature to
something like (save_dir: str, *, moe_layers: Sequence[int], num_experts: int,
hidden_size: int, moe_intermediate_size: int, rank: int, lora_alpha: float,
seed: int) -> None and add -> None to the test entrypoint function that calls it
(the test function immediately following the helper), and if helpful annotate
local helper types (e.g. randn: Callable[[int,int,float], torch.Tensor]) — no
behavioral changes, just add parameter and return type annotations to satisfy
the repo typing rule.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/unittest/llmapi/test_llm_pytorch.py`:
- Around line 1155-1285: The test currently only checks that any adapter changed
output and never mixes a no-LoRA request nor exercises CUDA-graph replay; update
test_qwen_moe_routed_expert_multi_lora_varying_ranks to include at least one
None/no-LoRA request in lora_requests and assert that the corresponding output
token_ids equal base_tokens (verifies rank-0/skip path), change the any_differs
check to require that each non-None LoRA request produces tokens different from
base_tokens (ensuring all adapters applied), and when moe_lora_mode ==
"device_path_cudagraph" invoke llm.generate a second time with a different
adapter ordering/subset and assert the outputs reflect the new slot assignment
(i.e., outputs for the same prompts change according to the new ordering) to
exercise slot-table refresh on CUDA-graph replay.

---

Nitpick comments:
In `@tests/unittest/llmapi/test_llm_pytorch.py`:
- Around line 1099-1152: The helper _write_routed_expert_lora_adapter and the
new test entrypoint must have explicit type annotations; update
_write_routed_expert_lora_adapter signature to something like (save_dir: str, *,
moe_layers: Sequence[int], num_experts: int, hidden_size: int,
moe_intermediate_size: int, rank: int, lora_alpha: float, seed: int) -> None and
add -> None to the test entrypoint function that calls it (the test function
immediately following the helper), and if helpful annotate local helper types
(e.g. randn: Callable[[int,int,float], torch.Tensor]) — no behavioral changes,
just add parameter and return type annotations to satisfy the repo typing rule.
🪄 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: Enterprise

Run ID: 2bd517f4-3bd0-4069-986d-e8bf55e1ff8a

📥 Commits

Reviewing files that changed from the base of the PR and between be7117c and e043499.

📒 Files selected for processing (4)
  • cpp/tensorrt_llm/kernels/cutlass_kernels/moe_gemm/moe_lora_problem_builder.cu
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_cutlass.py
  • tensorrt_llm/_torch/peft/lora/cuda_graph_lora_params.py
  • tests/unittest/llmapi/test_llm_pytorch.py

Comment thread tests/unittest/llmapi/test_llm_pytorch.py Outdated
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53653 [ run ] triggered by Bot. Commit: e043499 Link to invocation

@brb-nv

brb-nv commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@brb-nv
brb-nv enabled auto-merge (squash) June 11, 2026 20:54
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53675 [ run ] triggered by Bot. Commit: 27709a5 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53653 [ run ] completed with state ABORTED. Commit: e043499

Link to invocation

@xxi-nv xxi-nv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM.

Comment thread tests/unittest/llmapi/test_llm_pytorch.py Outdated
Comment thread tests/unittest/llmapi/test_llm_pytorch.py
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53675 [ run ] completed with state SUCCESS. Commit: 27709a5
/LLM/main/L0_MergeRequest_PR pipeline #42813 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

CI Agent Failure Analysis

Link to invocation

@brb-nv

brb-nv commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53758 [ run ] triggered by Bot. Commit: f80ccb9 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53758 [ run ] completed with state FAILURE. Commit: f80ccb9
/LLM/main/L0_MergeRequest_PR pipeline #42878 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

CI Agent Failure Analysis

Link to invocation

@brb-nv
brb-nv force-pushed the user/brb/restore-routed-expert-lora-test branch from f80ccb9 to 88e868b Compare June 12, 2026 16:46
@brb-nv

brb-nv commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53919 [ run ] triggered by Bot. Commit: 88e868b Link to invocation

@brb-nv
brb-nv force-pushed the user/brb/restore-routed-expert-lora-test branch from 88e868b to 78a80fb Compare June 12, 2026 18:32
@brb-nv

brb-nv commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53939 [ run ] triggered by Bot. Commit: 78a80fb Link to invocation

@brb-nv
brb-nv force-pushed the user/brb/restore-routed-expert-lora-test branch from 78a80fb to f651594 Compare June 13, 2026 01:48
@brb-nv

brb-nv commented Jun 13, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53984 [ run ] triggered by Bot. Commit: f651594 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53939 [ run ] completed with state ABORTED. Commit: 78a80fb
/LLM/main/L0_MergeRequest_PR pipeline #43030 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

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53984 [ run ] completed with state SUCCESS. Commit: f651594
/LLM/main/L0_MergeRequest_PR pipeline #43071 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

CI Agent Failure Analysis

Link to invocation

@brb-nv
brb-nv force-pushed the user/brb/restore-routed-expert-lora-test branch from f651594 to 11c6031 Compare June 14, 2026 19:13
@brb-nv

brb-nv commented Jun 14, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54154 [ run ] triggered by Bot. Commit: 11c6031 Link to invocation

@brb-nv

brb-nv commented Jun 14, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54157 [ run ] triggered by Bot. Commit: 11c6031 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54154 [ run ] completed with state ABORTED. Commit: 11c6031

Link to invocation

@brb-nv
brb-nv force-pushed the user/brb/restore-routed-expert-lora-test branch from 11c6031 to d69f8ad Compare June 14, 2026 22:55
@brb-nv

brb-nv commented Jun 14, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54160 [ run ] triggered by Bot. Commit: d69f8ad Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54157 [ run ] completed with state ABORTED. Commit: 11c6031

Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54160 [ run ] completed with state SUCCESS. Commit: d69f8ad
/LLM/main/L0_MergeRequest_PR pipeline #43243 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

CI Agent Failure Analysis

Link to invocation

Signed-off-by: Balaram Buddharaju <169953907+brb-nv@users.noreply.github.com>
@brb-nv
brb-nv force-pushed the user/brb/restore-routed-expert-lora-test branch from d69f8ad to d398db3 Compare June 15, 2026 17:43
@brb-nv

brb-nv commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54343 [ run ] triggered by Bot. Commit: d398db3 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

CI Report

Link to invocation

@brb-nv
brb-nv merged commit e171875 into NVIDIA:main Jun 16, 2026
7 checks passed
xinhe-nv pushed a commit to tensorrt-cicd/TensorRT-LLM that referenced this pull request Jun 23, 2026
Signed-off-by: Balaram Buddharaju <169953907+brb-nv@users.noreply.github.com>
Signed-off-by: GitLab CI Bot <gitlab-ci@nvidia.com>
xinhe-nv pushed a commit to tensorrt-cicd/TensorRT-LLM that referenced this pull request Jun 24, 2026
Signed-off-by: Balaram Buddharaju <169953907+brb-nv@users.noreply.github.com>
Signed-off-by: GitLab CI Bot <gitlab-ci@nvidia.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.

4 participants