[PR #4433] [CLOSED] [Engine] Fit a 512K context: give the prompt loan back to the K/V, keep big chunks staged #5042

Closed
opened 2026-11-07 16:32:15 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4433
Author: @xvcezrqpbxtpzblrt
Created: 10/28/2026
Status: ❌ Closed

Base: main ← Head: engine/loan-release-027


📝 Commits (1)

  • 60f4ab3 [Engine] Give the prompt path's loan back to the K/V before asking for new VRAM (#3998 follow-up)

📊 Changes

3 files changed (+125 additions, -1 deletions)

View changed files

📝 include/strata/prefill/prefill.hpp (+4 -0)
📝 src/prefill/prefill.cpp (+6 -0)
📝 src/program/generate.cpp (+115 -1)

📄 Description

## Problem

A 512K context on a 16 GB card could not fit in one run. The prompt path borrows part of the expert cache as a staging buffer (the loan), and the K/V's ceiling stopped at the loan's first slot: the borrowed region was excluded from the cache for the whole run. When the K/V needed those slots, the engine asked the driver for new VRAM, and on a card that has none left the request ended with and new VRAM, the cache being at its floor.

Result (measured)

k8v4, 16 GB RTX 3080 Ti Laptop, --max-context 524288, 510K prompt, 1.5 GiB reserve, --prefill 6144, staged chunks:

run prompt prefill K/V new VRAM
1 522,000 846.8 tok/s 5.30 GiB none (log checked)
2 522,000 831.7 tok/s 5.30 GiB none (K/V grown line has no and new VRAM)

The loan shrinks from 6,144 to 4,608 tokens and the freed slots become K/V cells; nothing is requested from the driver. 128K on a cool card: 1463.5 tok/s (previous build 1514.5, within run-to-run heat).

What changed

  • kvg_ensure, at its floor and before any new VRAM: asks the prompt path to re-lay out in the largest chunk whose freed granules cover the K/V's need, then unmaps the tail into the cache (kvg_fit_loan).
  • New option --prefill-stream-min N: chunks of N tokens or more stream every expert instead of staging the routed ones; an explicit value wins over the CPU share's own limit. Default behaviour is unchanged (the built-in 1,024 threshold).
  • Short contexts never take the new path (remain is 0), so their behaviour is the same as before.

Validation

  • 510K runs above, full logs kept (K/V grown without and new VRAM).
  • 32K: 1,672.7 tok/s; 128K: 1,463.5 tok/s (cool card).
  • Not run: 8 GB and 24 GB cards, multi-GPU (the path is single-participant), HIP, SYCL (this source has no such path), Metal (elastic K/V is off there).

Limits

  • CUDA and HIP only; the SYCL tree is not touched by this change.
  • Requires --kv-grow (the elastic K/V path).
  • On a 1.5 GiB reserve, int8 at 510K still asks for about 1.04 GiB of new VRAM; k8v4 does not. int8 needs a 1 GiB reserve to stay inside the cache.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/4433 **Author:** [@xvcezrqpbxtpzblrt](https://github.com/xvcezrqpbxtpzblrt) **Created:** 10/28/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `engine/loan-release-027` --- ### 📝 Commits (1) - [`60f4ab3`](https://github.com/Niko1221/Strata/commit/60f4ab3e3ce4f808b3c3358c5d2a30e7c2fc20d9) [Engine] Give the prompt path's loan back to the K/V before asking for new VRAM (#3998 follow-up) ### 📊 Changes **3 files changed** (+125 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `include/strata/prefill/prefill.hpp` (+4 -0) 📝 `src/prefill/prefill.cpp` (+6 -0) 📝 `src/program/generate.cpp` (+115 -1) </details> ### 📄 Description ## Problem A 512K context on a 16 GB card could not fit in one run. The prompt path borrows part of the expert cache as a staging buffer (the *loan*), and the K/V's ceiling stopped at the loan's first slot: the borrowed region was excluded from the cache for the whole run. When the K/V needed those slots, the engine asked the driver for new VRAM, and on a card that has none left the request ended with `and new VRAM, the cache being at its floor`. ## Result (measured) k8v4, 16 GB RTX 3080 Ti Laptop, `--max-context 524288`, 510K prompt, 1.5 GiB reserve, `--prefill 6144`, staged chunks: | run | prompt | prefill | K/V | new VRAM | |---|---|---|---|---| | 1 | 522,000 | 846.8 tok/s | 5.30 GiB | none (log checked) | | 2 | 522,000 | 831.7 tok/s | 5.30 GiB | none (`K/V grown` line has no `and new VRAM`) | The loan shrinks from 6,144 to 4,608 tokens and the freed slots become K/V cells; nothing is requested from the driver. 128K on a cool card: 1463.5 tok/s (previous build 1514.5, within run-to-run heat). ## What changed - `kvg_ensure`, at its floor and before any new VRAM: asks the prompt path to re-lay out in the largest chunk whose freed granules cover the K/V's need, then unmaps the tail into the cache (`kvg_fit_loan`). - New option `--prefill-stream-min N`: chunks of N tokens or more stream every expert instead of staging the routed ones; an explicit value wins over the CPU share's own limit. Default behaviour is unchanged (the built-in 1,024 threshold). - Short contexts never take the new path (`remain` is 0), so their behaviour is the same as before. ## Validation - 510K runs above, full logs kept (`K/V grown` without `and new VRAM`). - 32K: 1,672.7 tok/s; 128K: 1,463.5 tok/s (cool card). - Not run: 8 GB and 24 GB cards, multi-GPU (the path is single-participant), HIP, SYCL (this source has no such path), Metal (elastic K/V is off there). ## Limits - CUDA and HIP only; the SYCL tree is not touched by this change. - Requires `--kv-grow` (the elastic K/V path). - On a 1.5 GiB reserve, int8 at 510K still asks for about 1.04 GiB of new VRAM; k8v4 does not. int8 needs a 1 GiB reserve to stay inside the cache. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 16:32:15 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#5042
No description provided.