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

Open
#3,257 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
22/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
rust
Domain
backend

Research direction

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.

Written by the indexing model from the issue text.

Description

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
Dominant language
Rust
Stars
505
Forks
81
Avg merge
14h 2m
Merged PRs (30d)
448

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from lablup/mlxcel

All issues in lablup/mlxcel

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.