Skip to content

[None][fix] Propagate decoder extra_attrs in Gemma4 multimodal wrapper - #19511

Open
pamelap-nvidia wants to merge 2 commits into
NVIDIA:mainfrom
pamelap-nvidia:fix/gemma4mm-extra-attrs-prefill-cudagraph
Open

pamelap-nvidia wants to merge 2 commits into
NVIDIA:mainfrom
pamelap-nvidia:fix/gemma4mm-extra-attrs-prefill-cudagraph

Conversation

@pamelap-nvidia

@pamelap-nvidia pamelap-nvidia commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator

Dev Engineer Review

The change propagates the decoder ModelConfig.extra_attrs to the outer Gemma4 configuration after decoder construction. This restores attn_layers lookup during CUDA graph capture for piecewise and breakable prefill backends. Eager execution and public declarations remain unchanged. Reported Gemma4 measurements show lower TTFT and request latency, higher throughput at concurrency 1 and 4, and unchanged inter-token latency.

QA Engineer Review

No test changes.

Per-File QA Perspective

  • tensorrt_llm/_torch/models/modeling_gemma4mm.py: Verify Gemma4 multimodal CUDA graph initialization with both prefill backends. Verify attn_layers registration and confirm that eager execution remains unchanged.

Description

Gemma4Attention registers itself into the inner ModelConfig.extra_attrs that is passed to Gemma4ForCausalLM, but PyTorchModelEngine.model_forward publishes the outer wrapper's model_config.extra_attrs to the thread-local before running the model. The two are different objects, so attn_layers never reaches the thread-local and extract_extra_attrs asserts "Attention layer is not registered".

Eager execution is unaffected because the custom inplace attention op is gated on is_torch_compiling() or is_in_breakable_cuda_graph(), so the lookup only runs under CUDA graph capture. The visible symptom is that both prefill_cuda_graph_backend=piecewise and =breakable fail to initialize on Gemma4.

Propagating the inner config's extra_attrs to the outer one after the decoder is constructed fixes both paths.

Measured on gemma-4-E4B-it (BF16, TP1, 1x RTX PRO 6000 Blackwell, SM120) with prefill_cuda_graph_backend=breakable, ISL 25 / OSL 5:

concurrency 1: TTFT 48.3 -> 14.5 ms, request latency 83.0 -> 50.5 ms,
throughput 11.9 -> 19.4 req/s
concurrency 4: TTFT 93.3 -> 23.2 ms, request latency 129.8 -> 61.3 ms,
throughput 30.2 -> 63.5 req/s

Inter-token latency is unchanged, as expected: decode was already CUDA graphed and is memory-bandwidth bound. The gain is entirely prefill kernel launch overhead, which nsys showed at 1426 launches and 83% GPU idle per context forward step.

Test Coverage

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.

Gemma4Attention registers itself into the inner ModelConfig.extra_attrs
that is passed to Gemma4ForCausalLM, but PyTorchModelEngine.model_forward
publishes the outer wrapper's model_config.extra_attrs to the thread-local
before running the model. The two are different objects, so attn_layers
never reaches the thread-local and extract_extra_attrs asserts
"Attention layer is not registered".

Eager execution is unaffected because the custom inplace attention op is
gated on is_torch_compiling() or is_in_breakable_cuda_graph(), so the
lookup only runs under CUDA graph capture. The visible symptom is that
both prefill_cuda_graph_backend=piecewise and =breakable fail to
initialize on Gemma4.

Propagating the inner config's extra_attrs to the outer one after the
decoder is constructed fixes both paths.

Measured on gemma-4-E4B-it (BF16, TP1, 1x RTX PRO 6000 Blackwell, SM120)
with prefill_cuda_graph_backend=breakable, ISL 25 / OSL 5:

  concurrency 1: TTFT 48.3 -> 14.5 ms, request latency 83.0 -> 50.5 ms,
                 throughput 11.9 -> 19.4 req/s
  concurrency 4: TTFT 93.3 -> 23.2 ms, request latency 129.8 -> 61.3 ms,
                 throughput 30.2 -> 63.5 req/s

Inter-token latency is unchanged, as expected: decode was already CUDA
graphed and is memory-bandwidth bound. The gain is entirely prefill
kernel launch overhead, which nsys showed at 1426 launches and 83% GPU
idle per context forward step.

Signed-off-by: Pamela <179191831+pamelap-nvidia@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Understand this PR’s impact

Explore downstream dependencies and potential security impact with Blast Radius.

View blast radius →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: NVIDIA/TensorRT-LLM/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: bfbab03f-319a-4d69-9a4f-61fdc59b1509

📥 Commits

Reviewing files that changed from the base of the PR and between 0d4304a and 6555206.

📒 Files selected for processing (1)
  • tensorrt_llm/_torch/models/modeling_gemma4mm.py

Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review.


Walkthrough

Gemma4ForConditionalGeneration now merges the language model’s extra_attrs into the outer model configuration after constructing the language model.

Changes

Gemma4MM configuration propagation

Layer / File(s) Summary
Propagate language-model extra attributes
tensorrt_llm/_torch/models/modeling_gemma4mm.py
The outer configuration receives the language model’s extra_attrs after language-model construction.

Priority: ➖ Normal

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Bug fix

Suggested reviewers: bowenfu

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title follows the required format and clearly identifies the fix: propagating decoder extra_attrs in the Gemma4 multimodal wrapper.
Description check ✅ Passed The description clearly explains the issue, root cause, solution, affected CUDA graph paths, and performance results. The Test Coverage section is empty, and the checklist remains unchecked, but the d…
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Create a new PR

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

@pamelap-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #74865 [ run ] triggered by Bot. Commit: 6555206 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

@brnguyen2 brnguyen2 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.

The measurements predate the 2026-09-21 merge of main into this branch, so they were taken on a head where this aliasing did not yet exist. Please re-run prefill_cuda_graph_backend=breakable and =piecewise on current main without this line — if initialization succeeds and the TTFT delta reproduces, the PR can be closed. If it still fails with "Attention layer is not registered", the real defect is elsewhere, and the fix should ship with a test asserting attn_layers is present in the published extra_attrs after construction.

# PyTorchModelEngine.model_forward). Without propagating them, any CUDA
# graph capture path that takes the custom inplace attention op fails
# with "Attention layer is not registered".
self.model_config.extra_attrs.update(llm_model_config.extra_attrs)

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.

This is a no-op at the current head: self.model_config.extra_attrs and llm_model_config.extra_attrs are already the same dict object, so this is d.update(d).

Chain on this branch: line 1078 rebinds model_config_cp.extra_attrs to the top-level model_config.extra_attrs, and get_sub_model_config line 909 rebinds sub_config.extra_attrs to that same dict, so Gemma4Attention registers straight into it. Both of those lines came from #17408 (merged 2026-09-16), which this branch picked up in the 2026-09-21 merge of main — after this commit was written on 2026-09-01.

As written, the line is dead code and the comment describes a mechanism that no longer holds. Please drop both.

This branch has not been deployed

No deployments
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