[Bugfix][Gemma4] Keep image bidirectional attention within the sliding window (#47217)
Signed-off-by: Luciano Martins <lucianommartins@users.noreply.github.com> Co-authored-by: Luciano Martins <lucianommartins@users.noreply.github.com>
This commit is contained in:
co-authored by
Luciano Martins
parent
41de1380c2
commit
979f5511d7
@@ -499,6 +499,13 @@ class Gemma4Attention(nn.Module):
|
||||
logits_soft_cap=attn_logits_soft_cap,
|
||||
per_layer_sliding_window=sliding_window,
|
||||
kv_sharing_target_layer_name=kv_sharing_target_layer_name,
|
||||
# Gemma4 vision bidi: on sliding layers the bidirectional image
|
||||
# block must stay within the sliding window, matching HF's
|
||||
# (causal OR blockwise) AND sliding_window. Without this the image
|
||||
# span (~1100 soft tokens at max_soft_tokens=1120) exceeds the 1024
|
||||
# window; the runner keeps the full range and the kernel bounds it
|
||||
# per-query here.
|
||||
mm_prefix_clamp_sliding_window=self.is_sliding,
|
||||
prefix=f"{prefix}.attn",
|
||||
)
|
||||
|
||||
|
||||
@@ -978,6 +978,13 @@ class Gemma4ForConditionalGeneration(
|
||||
SupportsLoRA,
|
||||
SupportsEagle3,
|
||||
):
|
||||
# Gemma4 clamps mm_prefix bidirectional ranges to the sliding window
|
||||
# in-kernel (HF's (causal OR blockwise) AND sliding_window). The model
|
||||
# runner reads this to keep image bidirectional ranges that exceed the
|
||||
# window instead of dropping them (which would make image attention
|
||||
# causal-only for images larger than the sliding window).
|
||||
mm_prefix_clamp_sliding_window: bool = True
|
||||
|
||||
packed_modules_mapping = {
|
||||
"qkv_proj": [
|
||||
"q_proj",
|
||||
|
||||
Reference in New Issue
Block a user