Repository navigation
Optimize EmbeddingGemma prefill performance - #32383
Merged
Merged
Conversation
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
mickqian
marked this pull request as ready for review
July 27, 2026 01:56
mickqian
requested review from
Fridge003,
HaiShaw,
Qiaolin-Yu,
hebiao064,
ispobock and
merrymercy
as code owners
July 27, 2026 01:56
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
mickqian
requested review from
BBuf,
Edwardf0t1,
Ying1123,
b8zhong,
ch-wan,
hnyls2002 and
xiezhq-hermann
as code owners
July 27, 2026 02:40
mickqian
force-pushed
the
agent/embeddinggemma-bcg-performance
branch
from
July 27, 2026 02:48
bab1d4c to
eba1e06
Compare
mickqian
requested review from
JustinTong0323,
sogalin,
wisclmy0611 and
zijiexia
as code owners
July 27, 2026 02:49
Contributor
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
mickqian
force-pushed
the
agent/embeddinggemma-bcg-performance
branch
from
July 27, 2026 02:52
eba1e06 to
3b77fc9
Compare
Collaborator
Author
|
urgent PR but blocked by CI. will bypassing while keeping an eye on CI |
5 tasks
4 of 5 tasks
gujialiang123
added a commit
to gujialiang123/sglang
that referenced
this pull request
Jul 29, 2026
sgl-project#32383 landed fused paths for the 2-D and residual cases of Gemma3RMSNorm. Two gaps remain. 1. Higher-rank inputs still fall back to the eager path. The dispatch is guarded by x.dim() == 2, but q_norm and k_norm are called with [tokens, heads, head_dim], so on Gemma-3 that is 2 of the 6 norms per layer -- 52 of 157 norm calls per forward on gemma-3-1b. RMSNorm reduces over the last dimension only, so flattening the leading dimensions and restoring the shape is exact. 2. Both fused paths pass self.weight.data without checking it. The weight is nn.Parameter(torch.zeros(dim)), so its dtype follows whatever default is in effect at construction. Under the loader's set_default_torch_dtype that matches the activations, but a module built outside that context keeps an fp32 weight -- and the fused kernels do not raise on a mismatch, they return NaNs: gemma_rmsnorm(bf16_input, bf16_weight) -> finite gemma_rmsnorm(bf16_input, fp32_weight) -> NaN/Inf, no exception Since the loader makes production weights match, this is a robustness gap rather than a live bug, so the fix is a guard that falls back to the eager path. That keeps fp32-weight semantics intact, leaves the residual path byte-identical to main, and adds no state to the module. Benchmarks are the increment attributable to this change, not to fusing Gemma3RMSNorm from scratch. Baseline is a build whose norm coverage matches current main (2-D fused, higher rank eager); the patched arm adds the high-rank path. gemma-3-1b-it, 1x H200, BF16, 6 reps per arm, Welch t: regime baseline patched gain p low-batch decode 1.300 req/s 1.776 +36.6% 2.4e-14 concurrent decode 33.648 41.891 +24.5% 1.2e-06 4K prefill-heavy 23.385 25.085 +7.3% 0.053 (neutral) Numerics: outputs are not bit-identical to the eager path -- the fused kernel applies the weight in the activation dtype -- which is the same trade-off the 2-D path already accepted. 97.8-98.4% of elements match bit-for-bit and the rest differ at the BF16 rounding scale. Adds TestGemma3RMSNorm, which this class had none of: 2-D and 3-D inputs, bf16/fp16, fp32 and half weights, non-contiguous views, and the residual path. Mutation-checked -- dropping the dtype guard fails 68 subtests and dropping the shape restore fails 28.
3 tasks done
saturn-acc
pushed a commit
to saturn-acc/sglang
that referenced
this pull request
Aug 16, 2026
Atituiset
pushed a commit
to Atituiset/sglang
that referenced
this pull request
Sep 10, 2026
This was referenced Sep 12, 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.
Summary
sglang serveEmbeddingGemma cookbookRecommended
sglang servecommandThe standard command is the recommended command. EmbeddingGemma automatically
enables embedding mode and BCG; on H100/H200 it automatically selects FA3 and
captures the 16,384-token BCG tier:
EmbeddingGemma also uses the checkpoint BF16 dtype and enables list-request
batch tokenization automatically. No performance flags are required for the
measured 8 × 2047-token workload. To capture larger aggregate prefills, set
--cuda-graph-max-bs-prefill 32768(or another required token budget).Correctness
For the same
[BOS, hello, EOS]input, SGLang BCG vs vLLM cosine similarity is 0.999945 (maximum absolute difference 0.00126). Text and pre-tokenized API inputs both use 3 tokens.Fair H200 comparison
Both services use the same model snapshot, BF16, TP=1, OpenAI
/v1/embeddingsAPI, and separate identical H200 GPUs at the same 1980 MHz clock. Each request contains 8 explicit token-id sequences × 2047 tokens = 16,376 tokens; 3 warmups and 10 timed requests, repeated for 3 rounds.SGLang BCG is 4.37× faster for this fair long-prefill embedding workload. SGLang logs confirm every timed request is one 8-sequence / 16,376-token BCG replay.
Validation
ruff,compileall, andgit diff --checksglang serveconfirms FA3 + BCG capture through 16,384 tokensCI States
Latest PR Test (Base): 🚫 Run #30240342749
Latest PR Test (Extra): 🚫 Run #30240342532