[Perf] Precompute gemma_weight to avoid redundant add on every forward #22673
Merged
ispobock merged 1 commit intosgl-project:mainfrom Apr 17, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request optimizes Gemma layer normalization by precomputing the gemma_weight (standard weight plus 1.0) and storing it as a buffer, rather than recalculating it during every forward pass. A critical issue was identified in the weight loader where self.gemma_weight is reassigned rather than updated in-place, which would break the buffer's connection to the module and cause issues when moving the model between devices.
Contributor
Author
|
/tag-and-rerun-ci |
3bd1362 to
fa5120d
Compare
Contributor
Author
|
/tag-and-rerun-ci |
1 similar comment
Contributor
Author
|
/tag-and-rerun-ci |
nvpohanh
approved these changes
Apr 16, 2026
b8zhong
approved these changes
Apr 16, 2026
Contributor
Author
|
/tag-and-rerun-ci |
2 similar comments
Contributor
Author
|
/tag-and-rerun-ci |
Contributor
Author
|
/tag-and-rerun-ci |
Collaborator
|
/rerun-stage stage-c-test-8-gpu-h200 |
Contributor
|
✅ Triggered |
jmamou
pushed a commit
to jmamou/sglang
that referenced
this pull request
Apr 20, 2026
zhangying098
pushed a commit
to zhangying098/sglang
that referenced
this pull request
Apr 23, 2026
kyx1999
pushed a commit
to KMSorSMS/sglang
that referenced
this pull request
Apr 27, 2026
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.
Motivation
GemmaRMSNormcomputes weight + 1.0 on every forward call inforward_hipandforward_with_allreduce_fusion. This repeated tensor addition is unnecessary overhead.Modifications
Replace runtime weight + 1.0 with the cached gemma_weight in forward_hip and forward_with_allreduce_fusion.
Accuracy Tests
Speed Tests and Profiling
Speed Tests
profiling

Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ci