Sliding Window Attention Full (server/swa-full.ts)

atomic-agent · src/local-llm/server/swa-full.ts · typescript · MIT
ai, database, tag:swa, tag:local

Manages sliding-window attention full mode for local LLM, optimizing KV cache reuse and context size.

// Source: https://github.com/AtomicBot-ai/atomic-agent | License: MIT | Copyright 2026 Atomic Bot
// Provided via justclaw.it.com; keep this notice with the code.
import {
  buildKvLayout,
  countKvLayers,
  estimateKvBytesPerToken,
  MANAGED_KV_CACHE_TYPE,
  type KvCacheType,
  type KvLayoutSource,
} from "./context-size.js";

/**
 * `localModels.managed.swaFull`: whether the managed daemon launches a
 * sliding-window model with `--swa-full`.
 *
 * With sliding-window attention llama.cpp keeps only the last `window`
 * tokens of those layers' KV, which is what makes Gemma 4's cache so
 * small — and what makes it reusable only as a whole: a prompt that
 * matched for its first 19 % reused nothing, because the sliding layers
 * cannot be rolled back to the divergence point. `--swa-full` 

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key