feat: Implement --swa-full as an opt-in that keeps every sliding block

Abierto
#3,257 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
22/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
rust
Área
backend

Línea de trabajo

Start in src/cli/context_args.rs at ContextCompatArgs::resolve, where the swa_full == Some(true) refusal sits, and in context_args_tests.rs where the refusal test lives. The policy switch belongs in the CachePool sliding path that depends on #3256, which is not yet merged. Done means --swa-full starts, the startup log prints both sliding estimates, and a model without sliding layers logs one warning.

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

Descripción

area:cli area:inference priority:low status:blocked type:enhancement

Part of #3259

Depends on #3256

Problem / Background

--swa-full (env LLAMA_ARG_SWA_FULL) asks llama-server for a full-size sliding-window cache (common/arg.cpp:1679-1685 at b10621 c1d0e7a0, default false). mlxcel refuses --swa-full true at startup (src/cli/context_args.rs:145-157). The refusal says the capability depends on scheduler-owned sliding caches, not on their size. Once #3256 lands, sliding layers are scheduler-owned blocks, and the flag reduces to one policy: never retire a sliding block from a live sequence.

The opt-in is still wanted for cases #3256 does not cover. With the window-bounded default, a sliding block retired under prompt-cache budget pressure is gone, so a later divergence before it falls back to an earlier d (sliding_window_evicted). With --swa-full, every block of a live sequence survives until donation. Divergence at any block boundary then reuses as on a full-attention family, for the lifetime of the entry under the normal LRU.

The cost is the full-size cache. On gemma-4-12b-it (40 sliding layers at 320 KiB per token, K and V stored), sliding KV is 2.5 GiB at 8k, 10 GiB at 32k and 40 GiB at 128k per sequence, against a fixed 320 MiB with the window.

Current Behavior

ContextCompatArgs::resolve returns Err for swa_full == Some(true) (context_args.rs:145). The accepted spellings --swa-full false and LLAMA_ARG_SWA_FULL=0 are inert. ContextCompatResolution (:119) has no SWA field.

Proposed Solution

  1. Add swa_full: bool to ContextCompatResolution and drop the refusal. Carry it through startup into the CachePool sliding policy that #3256 adds: with swa_full, Sliding layers of SchedulerOwned sequences never move blocks to the retired list. logical_start still advances, so attention numerics stay windowed and unchanged. Only the release is skipped. No separate cache type.
  2. For a model that has no scheduler-owned sliding layers (layer_state_kinds() is None, or has no Sliding entry), --swa-full true logs one warn naming the model type and stating the flag has no effect. Do not refuse, so one launch script works across models.
  3. At startup, log at info the sliding KV estimate at --ctx-size and the full-size estimate, using crate::execution::kv_arch::estimate_kv_arch_unwindowed_from_config (already imported by snapshot_sizing.rs:31). Feed the full-size figure into the memory estimate the server already prints, so --ctx-size admission and the advisor see it.
  4. Keep the default off. Document the flag in docs/llama-server-compat.md with the memory table above.

Scope

In scope: src/cli/context_args.rs and context_args_tests.rs, the startup wiring, the CachePool sliding policy switch, the memory estimate line, and docs.

Out of scope: the window-bounded design itself (#3256), and quantized sliding blocks (#3250).

Implementation Notes

  • Reuse: #3256's retired-list hook (a single branch on the policy) and kv_arch unwindowed estimation. Do not write a second estimator.
  • Edge cases: --swa-full with the prompt cache disabled still keeps blocks for the live sequence only, so it is useful only for context shift. State this in the docs. A context that does not fit at full size is refused by the existing context admission, not silently windowed.

Acceptance Criteria

  • --swa-full and LLAMA_ARG_SWA_FULL=1 start the server. The refusal test swa_full_is_refused_with_a_diagnostic_naming_the_missing_mode (context_args_tests.rs:65) is replaced by an acceptance test.
  • On a tiny Gemma 3 fixture with a prompt-cache budget small enough to evict retired blocks, divergence at a block boundary before the evicted range reuses floor_to_block(d) - block_size with --swa-full, and falls back (sliding_window_evicted) without it. Both runs' logits equal a cold run with the same partition.
  • The startup log prints both sliding estimates. A test pins the figures for the gemma-4-12b config at 8k (320 MiB windowed, 2.5 GiB full).
  • A model with no sliding layers logs the no-effect warning once, with a test.

Implement this in one PR, run the verification block once at the end, and keep pushes to a minimum.

Verification

make test-fast FILTER=context_args
make test-fast FILTER=prompt_cache
make test-fast FILTER=gemma3
make verify-test        # macOS; on Linux/NVIDIA: make verify-test-cuda
Lenguaje dominante
Rust
Estrellas
505
Forks
81
Merge medio
14 h 2 min
PR fusionados (30 d)
448

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de lablup/mlxcel

Todos los issues de lablup/mlxcel

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.