mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #2191] [CLOSED] --prefill-head-alias (opt-in, --serve, one GPU): the output head's VRAM holds the prompt buffers while a prompt is read #3913
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#3913
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/2191
Author: @Maxim-Mazurok
Created: 10/12/2026
Status: ❌ Closed
Base:
main← Head:prefill-head-alias📝 Commits (1)
f80956b--prefill-head-alias (opt-in, --serve, one GPU): the output head's VRAM holds the prompt buffers while a prompt is read📊 Changes
9 files changed (+319 additions, -33 deletions)
View changed files
📝
docs/DETAILS.md(+6 -0)➕
docs/PREFILL_HEAD_ALIAS.md(+170 -0)📝
include/strata/core/mtp.hpp(+1 -0)📝
include/strata/core/native_head.hpp(+1 -0)📝
include/strata/prefill/prefill.hpp(+2 -1)📝
src/core/native_head.cpp(+6 -0)📝
src/prefill/prefill.cpp(+12 -4)📝
src/program/generate.cpp(+116 -27)📝
sycl/src/prefill/prefill.cpp(+5 -1)📄 Description
NOTE: This is human-designed, AI-coded, we optimised memory allocation per phase, and achieved substantial measured boost in decode and prefill speed. Please check the draft, hope it helps at least as an inspiration, I might not have time to polish it up, will try to answer questions. Thanks for considering! Max.
Title
--prefill-head-alias(opt-in,--serve, one GPU): the output head's VRAM holds the prompt buffers while a prompt is readIssue: none. I searched open issues and PRs for head/prefill-workspace/phase-VRAM work and found nothing related.
Summary
On an 8 GB card the prompt chunk is as large as the free VRAM allows, and prefill speed follows the chunk closely: 185 tok/s at 256 tokens, 292 at 512, 443 at 1,024 and 631 at 1,792, all on the same 29,854-token prompt. Without this change, every chunk above 768 tokens needed a lower
--vram-reserve-mib, and that left 0 MiB free, which is where WDDM starts paging.The idea is to treat VRAM as phase-dependent storage. Two large users never work at the same time:
With
--prefill-head-alias, the head is unloaded while a prompt is read, its VRAM is used for prompt buffers, and it is read back in before the first decode window. The auto cache is also sized with the head out, so the prompt path can borrow almost the whole cache (slots 1..N) for a 2,048-token chunk. After the prompt, the cache is refilled as usual.Results. All numbers are from an RTX PRO 2000 Blackwell Laptop (8 GB, Windows 11, WDDM), IQ3_XXS, 590 MiB reserve, on a local 0.1.41 build with this change. The full tables and settings are in
docs/PREFILL_HEAD_ALIAS.md.--prefill-head-alias(chunk 2,048)The agent-loop rows come from 1,200 requests over 8 cycles (default) and 2,649 requests over 20 cycles (head alias) of OpenCode agents. A large part of the decode difference comes from the default runs' long slow stretches near 19.5 tok/s, which the head-alias run did not have. Against the default's fast stretches only, decode was about 6% faster. We do not know what caused the slow stretches.
A controlled replay held the prompt and a 3,072-token forced output fixed, with a fresh engine per trial:
The default (auto cache without the alias) was not run in that forced mode.
Cost. Short reads get slower. Every request reloads the head (median 255 ms) and lends and refills almost the whole cache. The engine's prompt time (production medians, default -> head alias) by fresh tokens read:
It pays off from somewhere between 513 and 2,048 fresh tokens.
How this was made. The direction and the idea are mine: use VRAM as phase-dependent storage, and chase bigger prompt chunks because our benchmarks showed a clear trend. I understand Strata's memory layout only in part. The code was written with an AI coding assistant ("vibe-coded"), then measured and run in production on my machine for about 26 hours (2,717 requests) with no errors or restarts. Please review it with that in mind. The areas I am least sure about are listed under Extra Notes.
What changed
src/program/generate.cpp--prefill-head-aliasoption, usage text, and refusal reasons: needs--serve, one GPU and no layer split, no--batch, no--pipeline-windows,--short-read 0,--expert-cache 1|auto,--mtp, and a native head.cudaGetLastError()retry covers a 0-byte free reading right after the unload.if (!o.prefill_head_alias).ERR(and the server restarts it) instead of running stale graphs.include/strata/core/native_head.hpp,src/core/native_head.cpp:NativeHead::unload(), which the destructor now uses.include/strata/core/mtp.hpp:MtpDrafter::set_window_R(), so the verify rows can be attached after an early bind.include/strata/prefill/prefill.hpp,src/prefill/prefill.cpp:Prefill::init(..., bool borrow_spill = false). When the borrowed region is full,Alloc::takecontinues with ownedcudaMallocbuffers (the "hybrid" layout).relayoutrefuses a hybrid layout. Withborrow_spillfalse,takebehaves exactly as before.sycl/src/prefill/prefill.cpp: the matchinginitsignature. It refusesborrow_spill, because the SYCL engine has no flag for it.docs/PREFILL_HEAD_ALIAS.md(new) and a bullet indocs/DETAILS.md.What it leaves alone: the default path. Every new branch is behind the flag or behind
borrow_spill. No defaults changed, and there are no server, setup or API changes. To use it, add--prefill-head-aliasand--short-read 0to the model config'sargs.Extra Notes
How I checked:
main@a0116b27, v0.1.43.1) for CUDA 13.0, sm_120, MSVC 14.44 on Windows. It compiles.STRATA_ARENA_PIN_GIB=auto; without it, the full sliced arena pin left 0 GiB free for the cache on this 64 GB PC (#243), with the flag off as well. The requests were a 29,842-token prompt cold, a 31-token follow-up on its prefix, two 45-token prompts, and the long prompt again. All completed with coherent answers. The cold prompt read at 276.5/277.1 tok/s with the flag off and 643.1/649.7 tok/s with it on; decode was 35.7/34.7 and 34.1/31.6 tok/s (free generation, 768 tokens). The head came back at the same address on every reload.main.Not tested: HIP (same sources; I have no AMD card), SYCL (signature only), Linux, other cards and models, multi-GPU (refused).
Open questions for review:
cudaMallocdoes not promise the same address on reload. The guard turns a moved head into a restart, but a cleaner fix would keep the address: a CUDA VMM range whose backing is swapped, or prompt buffers placed inside the head's own allocation instead of freeing it. Which do you prefer?--short-readdoes, removing the cost above for small reads: 614 of 2,717 requests read 64 or fewer.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.