[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:
Luciano Martins
2026-07-02 19:57:41 -07:00
committed by GitHub
co-authored by Luciano Martins
parent 41de1380c2
commit 979f5511d7
8 changed files with 89 additions and 9 deletions
+7
View File
@@ -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",
)