Repository navigation
[None][perf] Reduce Gemma multimodal attention mask construction peak memory - #20405
Draft
zhaoyangwang-nvidia wants to merge 1 commit into
Draft
zhaoyangwang-nvidia wants to merge 1 commit into
zhaoyangwang-nvidia wants to merge 1 commit into
Conversation
Signed-off-by: ZhaoyangWang <265160349+zhaoyangwang-nvidia@users.noreply.github.com>
Collaborator
Author
|
/bot run |
Collaborator
|
PR_Github #78078 [ run ] triggered by Bot. Commit: |
Collaborator
|
PR_Github #78078 [ run ] completed with state
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@coderabbitai summary
Description
Long Gemma3/Gemma4 multimodal prefills can OOM while constructing a dense attention mask because the existing implementation materializes several quadratic intermediate tensors and copies per-request masks into a packed batch buffer. Construct the packed boolean mask directly with a shared Triton kernel, using only linear-sized vision-blob metadata in addition to the final output.
Preserve causal/sliding-window attention, same-blob vision bidirectionality, Gemma4 cached-prefix handling, audio causality, and the existing model-specific gating. The final dense mask still requires Q*(P+Q) bytes per request.
On one B200, warmed mask-construction peak allocated memory (including the output, window 1024, one request with no cached prefix) was:
With an artificial 1.5 GiB PyTorch allocator budget, 32K Gemma4 mask construction OOMs before this change and succeeds afterward. These are isolated mask-construction measurements, not end-to-end serving memory claims.
Test Coverage
tests/unittest/_torch/modules/test_gemma_attention_mask.py: registered inl0_b200.yml; 19 GPU cases passed using the source-isolated helper on B200. Covers exact mask values, image/video/audio, strided input and input immutability, packed requests, prefix/tile boundaries, empty inputs, CUDA graph replay, and peak allocation. The initial 10 cases also passed through the full TensorRT-LLM package before the review added boundary cases.tests/unittest/_torch/modeling/test_modeling_gemma3.py::TestGemma3::test_gemma3_allclose_to_hf[backend:flashinfer_config:1b]and...::test_gemma3_allclose_to_hf[backend:flashinfer_config:27b]: passed, including image-mask prefill/decode with reduced-layer random-weight models.git diff --check: passed.Validation limitations: the reused native build lacks SM100 FMHA kernels, so the default TRTLLM-backend Gemma3 sanity test failed in that environment. Full pretrained multimodal serving and Gemma4 full-model inference have not been validated; this PR is draft pending broader integration 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-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin 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.