Reduce KV memory for local-attention layers
- Langage dominant
- C++
- Étoiles
- 7k
- Forks
- 660
- Merge moyen
- 20 h 43 min
- PR mergées (30 j)
- 33
Description
## Problem
On `dev` (`1658f88`), the default `flash` attention path reserves full-context BF16 KV/K/V storage for local and global layers alike. Local layers only attend to their sliding window, so retaining capacity for the entire context wastes memory as the configured context grows.
The runtime-aware cache constructor also allocates compact tiled buffers that the default Flash path does not use. The tiled attention backends already have compact local rings; the default Flash path still reads the legacy transposed K/V buffers.
## Fix direction
- Allocate separate BF16 buffers per owning layer for the default Flash path.
- Size local rings for the attention window plus the full prefill batch and trailing SIMD padding, capped by the configured context. The extra rows prevent batch writes and padding from overwriting history needed by early queries.
- Keep global layers at the configured context capacity, with the logical context limit separate from physical alignment padding.
- Reuse the source layer's buffers for shared-KV layers and retain the largest window required by their consumers.
- Preserve live history when runtime batches require larger rings, keep snapshots independent, and clear buffers safely when reusing a cache.
- Allocate only the buffers used by the selected attention backend and preserve the existing BF16 attention arithmetic and model-specific cache layouts.
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Commencez par localiser le constructeur de cache sensible au runtime, le chemin Flash attention par défaut et les backends de tiled attention décrits dans l’issue. Suivez la manière dont les couches locales et globales allouent et lisent les buffers K/V BF16, puis vérifiez que le redimensionnement, les snapshots, la réutilisation du cache, les couches à K/V partagé et la sélection du backend préservent l’historique et le comportement d’attention existant.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- cpp
- Domaine
- machine-learning, performance
- Type d'issue
- Refactorisation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- Active
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100