diff --git a/docs/DETAILS.md b/docs/DETAILS.md index 79e9f2a9..f385fb6d 100644 --- a/docs/DETAILS.md +++ b/docs/DETAILS.md @@ -71,7 +71,7 @@ attention reads in VRAM (`--kv-resident 32768`), so more experts fit on the GPU. (1,589 -> 3,872 experts in VRAM); at 128K about +6%. The attention reads exactly the same values (only where the KV lives changes); it costs ~13.7 KB of RAM per context token (1.7 GB at 128K). Existing installs: run `START-HERE.bat --setup` once to turn it on. Setup turns it on when the RAM has room for it; `--kv-streaming on|off` overrides that (on past the RAM test with a -note; never with `--kv k8v4` or under WSL, which cannot stream). +note; never under WSL, which cannot stream). **4-bit KV cache (engine 0.1.8, optional):** `START-HERE.bat --setup` asks above 8K context (or pass `--kv q4_0`). It halves the KV cache's memory with a Hadamard rotation before 4-bit rounding (PR #21), about 4% faster at 128K, but it @@ -81,8 +81,8 @@ Details: [`bench/results/2026-09-27-kv-q4`](../bench/results/2026-09-27-kv-q4/RE **Hybrid K8V4 KV cache (engine 0.1.25, optional, PR #120):** `--kv k8v4` (`START-HERE.bat --setup --kv k8v4`) keeps the keys at 8 bits and stores the values as rotated 4-bit: 23% less KV memory than 8-bit, so more experts fit in VRAM. RTX 3090, the Coder at 198K context: 99 instead of 85 tokens/s output, the same needle results, prompts 2-5% -slower. It does not stream its KV cache (KV streaming is on by default from 64K), so it pays off mostly on large -cards at long contexts. +slower. It streams its KV cache like the other formats (`--kv-resident N`): on an RTX 2060 SUPER 8 GB at 128K with +20,480 resident cells, +780 expert slots over resident K8V4, and it scores better than 4-bit KV on long documents. **Reproducible greedy output (0.1.30, opt-in, `STRATA_IQ_MT_MIN=1`):** with the IQ models, the CPU computes an expert for one token with ggml's dot product and for several tokens with Strata's multi-token kernels, which round diff --git a/setup.py b/setup.py index fa5bc4c3..8bc23ed9 100644 --- a/setup.py +++ b/setup.py @@ -116,6 +116,8 @@ CUDA12_WHEELS = ["nvidia-cublas-cu12==12.9.1.4", "nvidia-cuda-runtime-cu12==12.9 CUDA12_MIN_DRIVER = 528 if WIN else 525 ENGINE12_DIR = "engine-cuda12" MIN_ENGINE = (0, 1, 39) # v0.1.39: the #577 file-tier regression fixed, the OpenAI Responses API (#451, Codex), a reply stuck on one token ended (#606), the head before the arena (#620), effort_position (#458), --vram-reserve hot resize opt-in (#533), PR batch; v0.1.38: prompts faster (one gather per expert group #372, the first chunk's PLE rows beside layer 0 #374, DeltaNet three heads per thread #413), --kv q4_0 prompts on tensor cores (#452), Q5_0 experts on the GPU (#473), IQ4_XS on AVX-2 (#415), unbuffered expert loading on Windows (#357 #362), --peer-device (#531), a 6 GB card starts (#496), PR batch; v0.1.37: a silent engine is restarted (#481), Windows AMD counts the desktop's VRAM (#380 #377 #497), a steadier PCIe probe (#485), fixes #496 #495 #498 #505 #493; v0.1.36: a cancelled prompt logged as read so far (#471), the draft-head hint (#474), UPDATE.bat (#475), --expert-profile-save (#477); v0.1.35: Windows AMD uses its bundled HIP runtime (#468 #461), the low-RAM resident mode on Windows 32 GB (#467), fixes #460 #459 #446 #447 #457 #448 #444; v0.1.34: AMD on Windows (a ready-made HIP engine), an MCP server for AI assistants (tools/strata_mcp.py), a shorter README; v0.1.33: a portable image encoder again (#411 #412), setup recommends instead of forcing (#406 #403 #364 #384), fixes #352 #365 #369 #371 #375 #393 #408 #414; v0.1.32: split prompts faster (#340), AMD router +12%, Unsloth Q4 in setup, faster Q4 prompts, #326/#327/#342/#344 fixes, PR batch; v0.1.31: Unsloth UD-Q4_K_XL (experimental), GGUF-in-place low-RAM mode, Windows GGUF load 2x, server race + tokenizer fixes, AMD intrinsics; v0.1.30: short prompts faster (streaming from 1024 tokens), resident low-RAM variant, multi-GPU session carve, RDNA4; v0.1.29: sampled answers faster (split top-k), #154 correctness fixes; v0.1.28: the expert cache reserves the draft head, a cancelled request no longer fails the next; v0.1.27: RTX 20 (sm_75) in the ready-made engine, the HIP build without CUDA headers; v0.1.26: the draft layer's prompt pass in batches; v0.1.25: faster prompts (grouping off the copy engine, fused hyper-connection kernels), AMD HIP backend, --kv k8v4; v0.1.24: long prompts faster (QSA select on tensor cores); v0.1.23: image requests honor sampling, 8 GB cards start, batched verify window; v0.1.22: faster prompts (tensor-core attention), multi-GPU across images/steering/KV streaming; v0.1.21: multi-GPU layer split (--gpus); v0.1.20: system-prompt checkpoint, PCIe probe, hit rate; v0.1.19: penalties +# KV bytes per context token and attention layer: 8-bit 1056, rotated 4-bit 576, hybrid K8V4 (8-bit K, 4-bit V) 816 +KV_CELL_BYTES = {"q4_0": 576, "k8v4": 816} PY_PACKAGES = ["numpy", "jinja2", "regex", "pyyaml", "tqdm", "requests", "cmake", "ninja", "pillow", "psutil"] REQUIREMENTS = ROOT / "requirements.txt" # the same packages and their dependencies, pinned (#214) @@ -2509,7 +2511,7 @@ def low_ram_gpu_gb(model, vram_gb, ctx=32768, kv="int8") -> float: """About how many GB of the model's experts the GPU's cache holds: its VRAM minus ~5 GB for the dense weights, buffers and a 32K context's KV cache, minus the KV cache of a longer context (in VRAM in the low-RAM mode: its RAM has no room for KV streaming).""" - kv_tok = 13 * (576 if kv == "q4_0" else 1056) # bytes per context token: 12 QSA layers + the draft layer + kv_tok = 13 * KV_CELL_BYTES.get(kv, 1056) # bytes per context token: 12 QSA layers + the draft layer longer = max(0, ctx - 32768) * kv_tok / 1e9 return max(0.0, min(MODELS[model]["arena_gb"], vram_gb - 5 - longer)) @@ -4470,19 +4472,12 @@ def main() -> int: "--ple-io ram in the config's args keeps the table in RAM instead") # KV streaming: from 64K up the whole KV cache lives in RAM and only the part the attention reads (32K positions # per layer) stays in VRAM; the VRAM it frees holds more experts (+6% at 128K, +23% at 262K with Q2_0). It - # costs ~13.7 KB of RAM per context token with 8-bit KV (1.7 GB at 128K), 7.5 KB with 4-bit, so only when it fits. - kv_ram_gb = ctx * (13 * (576 if kv == "q4_0" else 1056)) / 1e9 # 12 QSA layers + the draft layer - # Hybrid K8V4 never streams its KV (mode 0 only, layer.hpp), so it is excluded from the WHOLE streaming - # decision rather than one threshold at a time - a future tier added to this chain cannot reintroduce the - # combination the engine refuses (PR review). - # --kv-streaming on|off overrides the RAM test (the owner's rule); k8v4 and WSL stay off - they cannot stream. + # costs ~13.7 KB of RAM per context token with 8-bit KV (1.7 GB at 128K), 10.6 KB with K8V4, 7.5 KB with 4-bit, so only + # when it fits. + kv_ram_gb = ctx * (13 * KV_CELL_BYTES.get(kv, 1056)) / 1e9 # 12 QSA layers + the draft layer + # --kv-streaming on|off overrides the RAM test (the owner's rule); WSL stays off - it cannot stream. stream_fits = ram >= MODELS[model]["ram_gb"] + kv_ram_gb + 1 - if kv == "k8v4": - if ctx >= 65536: - ok("KV streaming off: not supported with --kv k8v4; the KV cache stays in VRAM") - if a.kv_streaming == "on": - warn("--kv-streaming on: the engine has no KV streaming with --kv k8v4 (it refuses the pair): off") - elif is_wsl() and ctx >= 65536: + if is_wsl() and ctx >= 65536: ok("WSL: KV streaming off (the driver pins only about 1 GB of RAM); the KV cache stays in VRAM") if a.kv_streaming == "on": warn("--kv-streaming on: WSL cannot stream the KV cache (its RAM copy must be pinned, and the driver pins " diff --git a/tools/test_setup_risk.py b/tools/test_setup_risk.py index 0cce5269..30334cb1 100644 --- a/tools/test_setup_risk.py +++ b/tools/test_setup_risk.py @@ -444,10 +444,13 @@ class KvStreaming(unittest.TestCase): self.assertEqual(arg(cfg, "--kv-resident"), "32768") self.assertIn("Kept as you chose (--kv-streaming on)", out) - def test_on_where_it_cannot(self): + def test_k8v4_streams(self): code, out, cfg, _ = self.go("Q2_0", "--kv-streaming", "on", "--kv", "k8v4") - self.assertNotIn("--kv-resident", cfg["args"]) - self.assertIn("it refuses the pair", out) + self.assertEqual(code, 0, out) + self.assertEqual(arg(cfg, "--kv-resident"), "32768") + self.assertEqual(arg(cfg, "--kv"), "k8v4") + + def test_on_where_it_cannot(self): code, out, cfg, _ = self.go("Q2_0", "--kv-streaming", "on", "--context", "32768") self.assertNotIn("--kv-resident", cfg["args"]) self.assertIn("a context under 64K is not streamed", out)