Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Default flash attention retains redundant BF16 KV projection history

Aperta
#1,029 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cpp

Direzione di ricerca

Leggi prima le righe 208-322 di gemma/attention.cc e le righe 275-297 di gemma/kv_cache.cc per seguire la proiezione, la trasposizione e le allocazioni della cache. Riproduci il carico di lavoro Gemma 3 default-flash con il prompt e le impostazioni della sequenza indicati, quindi esamina le estensioni della cache e l’RSS di picco. Il lavoro è completato quando la cronologia KV ridondante non viene conservata, mentre la lunghezza del contesto, l’arrotondamento BF16 e il comportamento del modello rimangono invariati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

Default flash attention retains two BF16 representations of KV history.
The sequence-major projection buffer remains allocated and populated after
its keys and values have been transposed into the buffers attention reads.
This increases resident memory as context length grows.

Affected path

  • Backend: default --attention_impl flash.
  • Confirmed with Gemma 3 270M, 1B, and 4B text inference.
  • Measured baseline: ffc1abc05abdf11d875d25d36c8859553ddf2641.
  • The retained-history path is also present on current dev (b68def1).
  • T5 and DeepSeek use their legacy buffers differently.

What happens

  1. ComputeQKV writes BF16 projections into sequence-major kv_cache.
  2. It applies normalization and positional encoding with BF16 rounding.
  3. It transposes the results into k_cache and v_cache.
  4. FlashAttention consumes those transposed buffers.
  5. The original projection buffer still retains every layer and position.

References:

Reproduction and observed cost

Run default-flash Gemma 3 270M with a 32,736-token text prompt,
sequence capacity 32,768, prefill batch 4,096, and 16 decode tokens.
Inspect the allocated cache extents and peak process RSS during inference.

The projection buffer occupies 578 MiB including row padding.
The transposed K/V buffers occupy another 576 MiB.
Measured peak process RSS is 1,778.59 MiB on this workload.
This is active retained data, not merely unused virtual address space.

Environment: Linux, Intel i5-12400F, six pinned threads,
Release AVX2/Haswell build, no oneDNN, and approximately 15.5 GiB RAM.

Expected behavior

Projection intermediates should not retain a second complete KV history
after attention's persistent representation has been produced.
Required context, existing BF16 rounding, and model behavior must be preserved.

Lingua principale
C++
Stelle
7k
Fork
660
Merge medio
1g 15h
PR unite (30g)
19

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di google/gemma.cpp

Tutte le issue di google/gemma.cpp

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.