transformers
ca774efd - Gemma4: fix static cache attending to empty cache slots in KV-shared layers at prefill (#50528)

Commit
21 days ago
Gemma4: fix static cache attending to empty cache slots in KV-shared layers at prefill (#50528) * Gemma4: don't slice KV-shared layer inputs with a static cache and no mask At prefill, `_maybe_slice_kv_shared_inputs` keeps only the last `logits_to_keep` positions for the KV-shared layers. With a static cache and a `None` attention mask (SDPA relies on `is_causal`), these layers reuse the whole pre-allocated key/value tensors, and the single query token is not masked, so it also attends to the not-yet-written (all-zero) cache slots. The first generated token then differs between static and dynamic cache. Skip the optimization in that case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * better fix - restricted scope --------- Co-authored-by: ydshieh <ydshieh@users.noreply.github.com> Co-authored-by: Cyril Vallez <cyril.vallez@gmail.com>
Author
Parents
Loading