Apply gemma's position offset out-of-place instead of in-place (#26799)

This commit is contained in:
fzyzcjy
2026-05-31 09:47:50 +08:00
committed by GitHub
parent 13ca55afa3
commit 45194794d0
2 changed files with 7 additions and 1 deletions
+1
View File
@@ -199,6 +199,7 @@ class Envs:
SGLANG_SORT_WEIGHT_FILES = EnvBool(False) SGLANG_SORT_WEIGHT_FILES = EnvBool(False)
SGLANG_DISABLED_MODEL_ARCHS = EnvTuple(tuple()) SGLANG_DISABLED_MODEL_ARCHS = EnvTuple(tuple())
SGLANG_PREFETCH_BLOCK_SIZE_MB = EnvInt(16) SGLANG_PREFETCH_BLOCK_SIZE_MB = EnvInt(16)
SGLANG_GEMMA_OUT_OF_PLACE_POSITION_MUTATION = EnvBool(False)
# Logging Options # Logging Options
SGLANG_LOG_GC = EnvBool(False) SGLANG_LOG_GC = EnvBool(False)
+6 -1
View File
@@ -29,6 +29,7 @@ from transformers import (
) )
from sglang.srt.distributed import get_pp_group from sglang.srt.distributed import get_pp_group
from sglang.srt.environ import envs
from sglang.srt.layers.attention.triton_backend import TritonAttnBackend from sglang.srt.layers.attention.triton_backend import TritonAttnBackend
from sglang.srt.layers.layernorm import Gemma4RMSNorm from sglang.srt.layers.layernorm import Gemma4RMSNorm
from sglang.srt.layers.linear import ReplicatedLinear from sglang.srt.layers.linear import ReplicatedLinear
@@ -595,7 +596,11 @@ class Gemma4ForConditionalGeneration(PreTrainedModel):
"You must specify exactly one of input_ids or inputs_embeds" "You must specify exactly one of input_ids or inputs_embeds"
) )
positions += 1 if envs.SGLANG_GEMMA_OUT_OF_PLACE_POSITION_MUTATION.get():
positions = positions + 1
else:
positions += 1
per_layer_inputs = None per_layer_inputs = None
# PLE table and the per-layer projection live on the first rank only, # PLE table and the per-layer projection live on the first rank only,
# so non-first ranks must skip this and pull per_layer_inputs from the # so non-first ranks must skip this and pull per_layer_inputs from the