Skip to content

Conversation

brb-nv
Copy link
Collaborator

@brb-nv brb-nv commented Jul 25, 2025

Description

This MR adds text-only LoRA support for Gemma3.
Previously, I was using a custom MLP implementation to accommodate the activation function pytorch_gelu_tanh. Now, I'm switching to TRTLLM's GatedMLP so that we can take advantage of LoRA integration there.

Test Coverage

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.

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.

Summary by CodeRabbit

  • New Features

    • Added support for the "gemma_3_1b_it" model variant, including LoRA integration.
    • Introduced a new activation function combining GELU and tanh for gated MLP modules.
    • Enhanced model layers to accept and utilize LoRA parameters during inference.
  • Bug Fixes

    • Improved activation handling in gated MLP modules to support any callable activation function.
  • Tests

    • Added a new performance test for the "gemma_3_1b_it" model with dummy LoRA configuration.

@brb-nv brb-nv requested a review from a team as a code owner July 25, 2025 18:28
@brb-nv brb-nv requested review from byshiue and liji-nv July 25, 2025 18:28
Copy link
Contributor

coderabbitai bot commented Jul 25, 2025

📝 Walkthrough

Walkthrough

The changes replace a custom MLP implementation in the Gemma3 model with a standardized gated MLP module using a specific GELU activation variant. LoRA parameter support is added throughout model forward passes. Activation handling in the GatedMLP module is generalized. Integration and performance test configurations are updated to support a new model variant and a dummy LoRA test.

Changes

Cohort / File(s) Change Summary
Gemma3 Model Refactor & LoRA Support
tensorrt_llm/_torch/models/modeling_gemma3.py
Replaces custom Gemma3MLP with GatedMLP using a custom GELU activation; adds LoRA parameter support to Gemma3DecoderLayer and Gemma3TextModel forward methods; removes unused imports.
Gemma3 Vision-Language Model LoRA Forwarding
tensorrt_llm/_torch/models/modeling_gemma3vl.py
Updates Gemma3VLM.forward to accept and forward optional lora_params to the internal LLM forward call.
GatedMLP Activation Generalization
tensorrt_llm/_torch/modules/gated_mlp.py
Generalizes activation handling in GatedMLP to allow any callable activation function; improves type checking and error handling in _apply_activation.
Integration Test Model Variant Support
tests/integration/defs/perf/test_perf.py
Adds entries for the "gemma_3_1b_it" model variant to model path dictionaries for integration and LoRA testing.
Performance Test Configuration
tests/integration/test_lists/qa/trt_llm_integration_perf_test.yml
Adds a new performance test entry for the "gemma_3_1b_it" model with dummy LoRA, specifying test parameters such as batch size, tokens, and concurrency.
Accuracy Reference Updates
tests/integration/defs/accuracy/references/cnn_dailymail.yaml, tests/integration/defs/accuracy/references/mmlu.yaml
Adjusts accuracy values for the google/gemma-3-1b-it model under FP8 quantization in two benchmark reference files.

Sequence Diagram(s)

LoRA Parameter Forwarding in Gemma3 Model

sequenceDiagram
    participant User
    participant Gemma3TextModel
    participant Gemma3DecoderLayer
    participant Attention
    participant GatedMLP

    User->>Gemma3TextModel: forward(..., lora_params)
    Gemma3TextModel->>Gemma3DecoderLayer: forward(..., lora_params)
    Gemma3DecoderLayer->>Attention: forward(..., lora_params)
    Gemma3DecoderLayer->>GatedMLP: forward(..., lora_params)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–20 minutes

Possibly related PRs

Suggested reviewers

  • Wanli-Jiang
  • liji-nv
  • yilin-void
  • syuoni

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0ec13a3 and b54d7df.

📒 Files selected for processing (7)
  • tensorrt_llm/_torch/models/modeling_gemma3.py (7 hunks)
  • tensorrt_llm/_torch/models/modeling_gemma3vl.py (1 hunks)
  • tensorrt_llm/_torch/modules/gated_mlp.py (1 hunks)
  • tests/integration/defs/accuracy/references/cnn_dailymail.yaml (1 hunks)
  • tests/integration/defs/accuracy/references/mmlu.yaml (1 hunks)
  • tests/integration/defs/perf/test_perf.py (3 hunks)
  • tests/integration/test_lists/qa/trt_llm_integration_perf_test.yml (1 hunks)
✅ Files skipped from review due to trivial changes (3)
  • tests/integration/defs/accuracy/references/mmlu.yaml
  • tests/integration/defs/accuracy/references/cnn_dailymail.yaml
  • tests/integration/defs/perf/test_perf.py
🚧 Files skipped from review as they are similar to previous changes (4)
  • tensorrt_llm/_torch/models/modeling_gemma3vl.py
  • tests/integration/test_lists/qa/trt_llm_integration_perf_test.yml
  • tensorrt_llm/_torch/modules/gated_mlp.py
  • tensorrt_llm/_torch/models/modeling_gemma3.py
⏰ 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
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai bot requested a review from dc3671 July 25, 2025 18:28
@brb-nv brb-nv force-pushed the user/brb/lora-for-gemma3 branch from 1df218f to 8151fd0 Compare July 25, 2025 19:13
@brb-nv brb-nv changed the title Add LoRA support for Gemma3 feat: Add LoRA support for Gemma3 Jul 25, 2025
@brb-nv brb-nv force-pushed the user/brb/lora-for-gemma3 branch 3 times, most recently from 5cfd6c9 to 2bbe9b6 Compare July 25, 2025 19:27
@brb-nv
Copy link
Collaborator Author

brb-nv commented Jul 25, 2025

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #13034 [ run ] triggered by Bot

@coderabbitai coderabbitai bot requested review from litaotju and tijyojwad July 25, 2025 21:11
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 (2)
tests/integration/defs/accuracy/test_llm_api_pytorch.py (2)

618-618: Fix line length violation.

The comment line exceeds the 120-character limit specified in the coding guidelines.

Break the comment into multiple lines to comply with the line length limit:

-        # Disabling kv cache reuse as a WAR to deal with gaps in kernel support for Gemma3's non-inclusive sliding window size.
+        # Disabling kv cache reuse as a WAR to deal with gaps in kernel support
+        # for Gemma3's non-inclusive sliding window size.

606-607: Consider documenting future MLP module support.

The commented-out MLP modules (gate_proj, down_proj, up_proj and their TensorRT-LLM equivalents mlp_h_to_4h, mlp_4h_to_h, mlp_gate) suggest planned expansion of LoRA support beyond attention modules.

Consider adding a TODO comment to document the planned expansion:

target_modules=["q_proj", "k_proj", "v_proj"], # "gate_proj", "down_proj", "up_proj"],
+        # TODO: Add MLP modules when LoRA support for GatedMLP is fully implemented

Also applies to: 614-615

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2bbe9b6 and cb175f1.

📒 Files selected for processing (1)
  • tests/integration/defs/accuracy/test_llm_api_pytorch.py (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)

**/*.py: Python code 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 filenames should use snake_case (e.g., some_file.py).
Python classes should use PascalCase (e.g., class SomeClass).
Python functions and methods should use snake_case (e.g., def my_awesome_function():).
Python local variables should use snake_case. Prefix k for variable names that start with a number (e.g., k_99th_percentile).
Python global variables should use upper snake_case and 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 interfaces that may be used outside a Python file, prefer docstrings over comments.
Comments in Python 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.
Attributes and variables in Python can be documented inline; attribute docstrings will be rendered under the docstring for the class.
Avoid using reflection in Python when functionality can be easily achieved without it.
When using try-except blocks in Python, limit the except to the smallest set of errors possible.
When using try-except blocks to handle multiple possible variable types in Python, keep the body of the try as small as possible, using the else block to implement the logic.

Files:

  • tests/integration/defs/accuracy/test_llm_api_pytorch.py
**/*.{cpp,h,hpp,cc,cxx,cu,py}

📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)

All TensorRT-LLM Open Source Software code should contain an NVIDIA copyright header that includes the current year. This includes .cpp, .h, .cu, .py, and any other source files which are compiled or interpreted.

Files:

  • tests/integration/defs/accuracy/test_llm_api_pytorch.py
🪛 Ruff (0.12.2)
tests/integration/defs/accuracy/test_llm_api_pytorch.py

618-618: Line too long (127 > 120)

(E501)

⏰ 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 (6)
tests/integration/defs/accuracy/test_llm_api_pytorch.py (6)

26-27: LGTM! Import additions are appropriate.

The new imports for LoRA functionality are correctly placed and both are utilized in the new test method.


595-596: Good documentation and method naming.

The comment clearly indicates this is a smoke test for LoRA functionality, and the method name follows the established naming convention.


597-608: Well-structured LoRA setup with appropriate test parameters.

The dummy LoRA generation uses reasonable parameters (rank 32, zero weights for smoke testing) and targets attention modules as a good starting point for LoRA integration testing.


610-617: LoRA configuration looks correct with proper module mapping.

The mapping from HuggingFace module names (q_proj, k_proj, v_proj) to TensorRT-LLM module names (attn_q, attn_k, attn_v) appears to be correct based on the model architecture.


619-622: Appropriate workaround configuration documented.

The KV cache configuration with disabled block and partial reuse is properly documented as a workaround for kernel support gaps.


623-625: Test execution follows established patterns.

The LLM instantiation with LoRA configuration and GSM8K task evaluation follows the established testing pattern in this file.

@brb-nv brb-nv requested review from shaharmor98 and removed request for dc3671, litaotju, byshiue and liji-nv July 25, 2025 21:26
@brb-nv brb-nv force-pushed the user/brb/lora-for-gemma3 branch from cb175f1 to b3a4fde Compare July 25, 2025 21:41
@coderabbitai coderabbitai bot requested review from Naveassaf and syuoni July 25, 2025 21:42
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

♻️ Duplicate comments (1)
tests/integration/defs/accuracy/test_llm_api_pytorch.py (1)

623-625: LGTM: LLM instantiation and evaluation are correct.

The test properly instantiates the LLM with LoRA configuration and runs a meaningful evaluation task to verify functionality.

Note: This addresses the past review comment about LoRA testing approach. The test creates zero-weighted LoRAs as a smoke test, which is appropriate for verifying that the LoRA infrastructure works without affecting model outputs. The GSM8K evaluation ensures the model runs successfully with LoRA enabled.

🧹 Nitpick comments (1)
tests/integration/defs/accuracy/test_llm_api_pytorch.py (1)

618-618: Fix line length violation.

The line exceeds the 120-character limit. Consider breaking it into multiple lines for better readability.

-        # Disabling kv cache reuse as a WAR to deal with gaps in kernel support for Gemma3's non-inclusive sliding window size.
+        # Disabling kv cache reuse as a WAR to deal with gaps in kernel support 
+        # for Gemma3's non-inclusive sliding window size.
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cb175f1 and b3a4fde.

📒 Files selected for processing (4)
  • tensorrt_llm/_torch/models/modeling_gemma3.py (7 hunks)
  • tensorrt_llm/_torch/models/modeling_gemma3vl.py (1 hunks)
  • tensorrt_llm/_torch/modules/gated_mlp.py (1 hunks)
  • tests/integration/defs/accuracy/test_llm_api_pytorch.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • tensorrt_llm/_torch/models/modeling_gemma3vl.py
  • tensorrt_llm/_torch/modules/gated_mlp.py
  • tensorrt_llm/_torch/models/modeling_gemma3.py
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)

**/*.py: Python code 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 filenames should use snake_case (e.g., some_file.py).
Python classes should use PascalCase (e.g., class SomeClass).
Python functions and methods should use snake_case (e.g., def my_awesome_function():).
Python local variables should use snake_case. Prefix k for variable names that start with a number (e.g., k_99th_percentile).
Python global variables should use upper snake_case and 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 interfaces that may be used outside a Python file, prefer docstrings over comments.
Comments in Python 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.
Attributes and variables in Python can be documented inline; attribute docstrings will be rendered under the docstring for the class.
Avoid using reflection in Python when functionality can be easily achieved without it.
When using try-except blocks in Python, limit the except to the smallest set of errors possible.
When using try-except blocks to handle multiple possible variable types in Python, keep the body of the try as small as possible, using the else block to implement the logic.

Files:

  • tests/integration/defs/accuracy/test_llm_api_pytorch.py
**/*.{cpp,h,hpp,cc,cxx,cu,py}

📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)

All TensorRT-LLM Open Source Software code should contain an NVIDIA copyright header that includes the current year. This includes .cpp, .h, .cu, .py, and any other source files which are compiled or interpreted.

Files:

  • tests/integration/defs/accuracy/test_llm_api_pytorch.py
🧠 Learnings (1)
tests/integration/defs/accuracy/test_llm_api_pytorch.py (1)

Learnt from: amitz-nv
PR: #5616
File: tensorrt_llm/executor/worker.py:375-384
Timestamp: 2025-07-17T09:01:27.402Z
Learning: In tensorrt_llm/executor/worker.py, the LoRA adapter cache optimization logic that checks is_adapter_in_cpu_cache() and conditionally passes None for weights/config has a known race condition issue that cannot be solved with simple error handling or verification checks. This is a known limitation that requires a more comprehensive solution.

🪛 Ruff (0.12.2)
tests/integration/defs/accuracy/test_llm_api_pytorch.py

618-618: Line too long (127 > 120)

(E501)

🔇 Additional comments (5)
tests/integration/defs/accuracy/test_llm_api_pytorch.py (5)

26-27: LGTM: Import statements are appropriate.

The new imports for generate_dummy_loras and LoraConfig are necessary for the LoRA testing functionality and follow the existing import conventions.


595-596: LGTM: Clear test documentation.

The comment clearly identifies this as a smoke test for LoRA functionality, which sets appropriate expectations.


597-608: LGTM: LoRA generation parameters are appropriate.

The test uses reasonable parameters:

  • Rank 32 is a common LoRA rank for testing
  • Single LoRA keeps the test simple
  • Zero weights ensure safety during testing
  • Target modules cover the key attention projections

619-622: LGTM: KV cache configuration is appropriate.

The KV cache configuration correctly disables block and partial reuse as a workaround for Gemma3's sliding window limitations, consistent with other Gemma3 tests in the file.


610-617: Mapping consistency confirmed
The default mapping in tensorrt_llm/lora_manager.py:get_default_trtllm_modules_to_hf_modules() shows:

  • “attn_q” → “q_proj”
  • “attn_k” → “k_proj”
  • “attn_v” → “v_proj”

This matches the HF modules ["q_proj","k_proj","v_proj"] and TRTLLM modules ["attn_q","attn_k","attn_v"] used in the test. No changes required.

@brb-nv brb-nv force-pushed the user/brb/lora-for-gemma3 branch from b3a4fde to e618782 Compare July 25, 2025 21:46
@coderabbitai coderabbitai bot requested a review from litaotju July 25, 2025 21:47
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 (2)
tests/integration/defs/accuracy/test_llm_api_pytorch.py (2)

621-621: Fix line length violation.

The line exceeds the 120-character limit specified in the static analysis hints.

-        # Disabling kv cache reuse as a WAR to deal with gaps in kernel support for Gemma3's non-inclusive sliding window size.
+        # Disabling kv cache reuse as a WAR to deal with gaps in kernel support for 
+        # Gemma3's non-inclusive sliding window size.

595-632: Consider expanding test coverage for LoRA functionality.

While this smoke test is valuable for verifying basic LoRA integration, consider adding tests that:

  1. Verify LoRA weights are actually applied (non-zero weight LoRAs)
  2. Test multiple LoRA adapters if supported
  3. Validate LoRA ID specification mechanisms mentioned in past comments

This would provide more comprehensive coverage of the LoRA feature.

Would you like me to help design additional LoRA test cases that address the questions raised in the past review comments about LoRA ID specification and CPU LoRA handling?

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b3a4fde and e618782.

📒 Files selected for processing (4)
  • tensorrt_llm/_torch/models/modeling_gemma3.py (7 hunks)
  • tensorrt_llm/_torch/models/modeling_gemma3vl.py (1 hunks)
  • tensorrt_llm/_torch/modules/gated_mlp.py (1 hunks)
  • tests/integration/defs/accuracy/test_llm_api_pytorch.py (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • tensorrt_llm/_torch/models/modeling_gemma3vl.py
  • tensorrt_llm/_torch/modules/gated_mlp.py
  • tensorrt_llm/_torch/models/modeling_gemma3.py
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)

**/*.py: Python code 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 filenames should use snake_case (e.g., some_file.py).
Python classes should use PascalCase (e.g., class SomeClass).
Python functions and methods should use snake_case (e.g., def my_awesome_function():).
Python local variables should use snake_case. Prefix k for variable names that start with a number (e.g., k_99th_percentile).
Python global variables should use upper snake_case and 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 interfaces that may be used outside a Python file, prefer docstrings over comments.
Comments in Python 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.
Attributes and variables in Python can be documented inline; attribute docstrings will be rendered under the docstring for the class.
Avoid using reflection in Python when functionality can be easily achieved without it.
When using try-except blocks in Python, limit the except to the smallest set of errors possible.
When using try-except blocks to handle multiple possible variable types in Python, keep the body of the try as small as possible, using the else block to implement the logic.

Files:

  • tests/integration/defs/accuracy/test_llm_api_pytorch.py
**/*.{cpp,h,hpp,cc,cxx,cu,py}

📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)

All TensorRT-LLM Open Source Software code should contain an NVIDIA copyright header that includes the current year. This includes .cpp, .h, .cu, .py, and any other source files which are compiled or interpreted.

Files:

  • tests/integration/defs/accuracy/test_llm_api_pytorch.py
🧠 Learnings (1)
tests/integration/defs/accuracy/test_llm_api_pytorch.py (1)

Learnt from: amitz-nv
PR: #5616
File: tensorrt_llm/executor/worker.py:375-384
Timestamp: 2025-07-17T09:01:27.402Z
Learning: In tensorrt_llm/executor/worker.py, the LoRA adapter cache optimization logic that checks is_adapter_in_cpu_cache() and conditionally passes None for weights/config has a known race condition issue that cannot be solved with simple error handling or verification checks. This is a known limitation that requires a more comprehensive solution.

🪛 Ruff (0.12.2)
tests/integration/defs/accuracy/test_llm_api_pytorch.py

621-621: Line too long (127 > 120)

(E501)

⏰ 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 (6)
tests/integration/defs/accuracy/test_llm_api_pytorch.py (6)

18-18: LGTM! Import statements are correctly added.

The imports for generate_dummy_loras and LoraConfig are appropriate for the LoRA functionality being tested and follow Python naming conventions.

Also applies to: 27-27


595-596: Good smoke test implementation.

The comment clearly indicates this is a smoke test to verify LoRA functionality works without errors, which is appropriate for integration testing.


597-610: LoRA generation configuration looks correct.

The dummy LoRA generation with zero weights targeting q_proj, k_proj, and v_proj modules is appropriate for testing. The parameters (rank 32, zero weights) ensure the test focuses on integration rather than functional correctness.


611-620: LoRA configuration mapping is correct.

The mapping between HuggingFace module names (q_proj, k_proj, v_proj) and TensorRT-LLM target modules (attn_q, attn_k, attn_v) is appropriate and consistent with the model architecture.


622-625: KV cache configuration is consistent.

The KV cache configuration matches the pattern used in other Gemma3 tests in this class, appropriately disabling block and partial reuse as a workaround for sliding window size issues.


626-632: LLM instantiation and evaluation are appropriate.

The LLM is correctly configured with LoRA settings and the GSM8K evaluation provides a meaningful test of the LoRA-enabled model functionality.

@tensorrt-cicd
Copy link
Collaborator

PR_Github #13034 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #9737 completed with status: 'SUCCESS'

@brb-nv brb-nv force-pushed the user/brb/lora-for-gemma3 branch 2 times, most recently from 971a247 to 5d962e8 Compare July 31, 2025 22:38
@brb-nv brb-nv changed the title Add LoRA support for Gemma3 feat: Add LoRA support for Gemma3 Jul 31, 2025
Copy link
Collaborator

@venkywonka venkywonka left a comment

Choose a reason for hiding this comment

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

assuming you ran teh perf test including the dummy loras locally and it passed, LGTM! thanks for adding the perftest!

@brb-nv
Copy link
Collaborator Author

brb-nv commented Jul 31, 2025

assuming you ran teh perf test including the dummy loras locally and it passed, LGTM! thanks for adding the perftest!

Yup. Ran it locally. Adding it here: https://gitlab-master.nvidia.com/ftp/llm-models/-/merge_requests/370

@brb-nv
Copy link
Collaborator Author

brb-nv commented Jul 31, 2025

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #13730 [ run ] triggered by Bot

@brb-nv brb-nv force-pushed the user/brb/lora-for-gemma3 branch from 5d962e8 to 0ec13a3 Compare August 1, 2025 00:36
@brb-nv
Copy link
Collaborator Author

brb-nv commented Aug 1, 2025

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #13738 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #13730 [ run ] completed with state ABORTED

@brb-nv brb-nv removed the Community want to contribute PRs initiated from Community label Aug 1, 2025
@brb-nv brb-nv force-pushed the user/brb/lora-for-gemma3 branch from 0ec13a3 to 38043e8 Compare August 1, 2025 06:38
Signed-off-by: Balaram Buddharaju <[email protected]>
@brb-nv brb-nv force-pushed the user/brb/lora-for-gemma3 branch from 38043e8 to b54d7df Compare August 1, 2025 06:38
@brb-nv brb-nv changed the title feat: Add LoRA support for Gemma3 [TRTLLM-6657][feat] Add LoRA support for Gemma3 Aug 1, 2025
@brb-nv
Copy link
Collaborator Author

brb-nv commented Aug 1, 2025

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #13738 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #10325 completed with status: 'SUCCESS'

@tensorrt-cicd
Copy link
Collaborator

PR_Github #13776 [ run ] triggered by Bot

@brb-nv brb-nv enabled auto-merge (squash) August 1, 2025 06:49
@Wanli-Jiang
Copy link
Collaborator

@brb-nv can you add an unittest for lora? Example: https://github.com/NVIDIA/TensorRT-LLM/blob/main/tests/unittest/llmapi/test_llm_pytorch.py#L446

@tensorrt-cicd
Copy link
Collaborator

PR_Github #13776 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #10355 completed with status: 'SUCCESS'

@brb-nv brb-nv merged commit 7447d6e into NVIDIA:main Aug 1, 2025
4 of 5 checks passed
@brb-nv
Copy link
Collaborator Author

brb-nv commented Aug 1, 2025

@brb-nv can you add an unittest for lora? Example: https://github.com/NVIDIA/TensorRT-LLM/blob/main/tests/unittest/llmapi/test_llm_pytorch.py#L446

Hi Wanli, sorry I set the MR to auto-merge so that it merged overnight (CI is taking very long making room for frequent merge conflicts). I'll create a follow-up MR adding the unit test.

lancelly pushed a commit to lancelly/TensorRT-LLM that referenced this pull request Aug 6, 2025
Signed-off-by: Balaram Buddharaju <[email protected]>
Signed-off-by: Lanyu Liao <[email protected]>
jain-ria pushed a commit to jain-ria/TensorRT-LLM that referenced this pull request Aug 7, 2025
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.

5 participants