google / google/gemma.cpp

Reduce KV memory for local-attention layers

Abierto
#1,016 1 comentario 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
C++
Estrellas
7k
Forks
660
Merge medio
20 h 43 min
PR fusionados (30 d)
33

Descripción

## 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.

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Comienza localizando el constructor de caché consciente del runtime, la ruta predeterminada de Flash attention y los backends de tiled attention descritos en el issue. Rastrea cómo las capas locales y globales asignan y leen búferes K/V BF16 y, a continuación, verifica que el redimensionamiento, las instantáneas, la reutilización de la caché, las capas con K/V compartido y la selección del backend preserven el historial y el comportamiento existente de attention.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
cpp
Área
machine-learning, performance
Tipo de issue
Refactorización
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Activo
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.