Repository navigation
gpu: Qwen3.8 slots share a prompt prefix's KV pages and copy them on write - #1012
Conversation
…write A request whose prompt starts with a prefix another resident slot holds takes that slot's state at its nearest point below the common prefix instead of prefilling it again. The selecting layers' K/V planes, pooled keys and the MTP draft store map the other slot's pages that hold only whole rows of the prefix, and copy the page where it ends. The recurrent stores, the PLE ring and the raw key rings are loaded from the other slot's checkpoint. Every writer gives a shared page it reaches memory of its own first, and a reset gives shared pages back.
There was a problem hiding this comment.
Verdict: CLEAN: No merge-blocking defect survived the state, ownership, and error-path checks.
Non-blocking
⚠ Measure decode while pages remain shared: crates/gpu/src/room.rs:414 and crates/gpu-gates/src/bin/shared/serve_seats/qwen38.rs:2998.
own_from and shared each scan every page while sharing persists. For a plain selected-slot step that detaches no pages, M backed pages in its still-shared rooms incur at least 16M B of reference-counter loads on 64-bit hosts [derived], plus metadata and lends probes; this is not a DRAM-traffic estimate.
The timing table measures B's prefill. Add a same-card base/head decode A/B while both requests share pages, so this per-token term is bounded before wider parallel use.
Checked
Duplicates: 64 new items checked; no duplicate owner found. Both dryer functions read: different builder options, shared shape only.
Complexity: new slots_share (51) and hw_mtp_shared_store (48) combine setup, rewrites, and assertions; those are their logical stage boundaries. reuse 27→32 adds a share-selection branch; run 55→57 and spawn 41→43 add dispatch; run_walk 27→28 adds a COW check.
Silent failure: 6 fallback sites followed. Missing share points grant no reuse; refusals reset; failed thread queries surface on the next engine command. Saturated requests still select an existing source checkpoint.
Tests, static mutation check: room gate protects Room::own_from line 415 (no-op fails shared-byte counts); slots-share protects Body38::stage line 3956 (dropped COW fails store/logit equality); MTP gate protects run_walk line 1690, stage_store line 1851, and Room::settle line 314 (dropped detach/release fails isolation/reset assertions); serve test protects Slot::reuse line 802 (disabled share selection fails cache counts). GPU FAIL-first output is supplied for COW/reset mutants.
Gates: no accuracy band or tolerance moved; the added unsafe block has a dated ratchet PIN and reason.
Escape catalog: C1–C4 do not match the changed code.
Adversarial checks: rewinds, pending verifies, image prefixes, boundary pages, and three-slot sharing retain guards or independent ownership.
Notes
Review and mutation checks were static; no build or gate was run locally. The PR states GB10 and driver 595.84 and supplies gate output, but omits the required nvidia-smi output line; GPU evidence is incomplete.
Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_qwen4exp_e2e.rs, crates/gpu-gates/src/bin/gate_qwen4exp_mtp.rs, crates/gpu-gates/src/bin/shared/serve_seats/ds41.rs … and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
|
The review is done and the contribution check passed, so I'm merging this. |
Qwen3.8에서 여러 슬롯이 같은 프롬프트 앞부분의 KV 페이지를 공유하고, 쓸 때 복사하게 합니다.
What and why
Under
--parallel Non the Qwen3.8 seat, a request whose prompt starts with a prefix that another resident slot holds now takes that slot's state on the card. Before, it prefilled the prefix again unless a prompt cache entry existed, and no entry exists while the other request is still running. The recurrent state, the per-layer embedding ring and the raw key rings load from the source slot's checkpoint at the share point, so a shared slot continues from the same bits as a cut back to that point. A share is chosen only when it keeps more than the slot's own state and every cache entry; if the engine refuses it, the slot resets and the request prefills as before.Release notes: Changed: with
--parallel, a Qwen3.8 request that repeats a running request's prompt prefix reuses that prefix's KV pages instead of prefilling it again.Code shape
The review reads these first. A box left unticked needs one line of why.
copying it (
AGENTS.md"Common code first",docs/rust-quality.mdR14). Where I found an existing copy, Inamed it below.
(tensor shapes, the attention kind, the quant). A common owner gained no per-model branch, flag or trait method.
tools/check-comments.sh).PIN(YYYY-MM-DD):and its reason.
cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up.Duplication found or removed (
path:line), or "none": none. The duplicate scan reports only per-command wrappers incrates/gpu-gates/src/bind.rsand per-room accessors inscratch38.rs, each with its own command or figure.How it is built:
crates/gpu/src/room.rs:Room::share(from, n)maps the source room's memory for every page that holds only whole rows belown. The page where the prefix ends gets its own memory with the bytes copied (one newunsafeblock, so the gpu pin intools/unsafe-ratchet.txtmoves from 2838 to 2839 with aPINline).Room::own_from(pos)gives every shared page that a write fromposreaches its own memory with the same bytes. The new pages are made first and filled through a scratch virtual range, then remapped, so a failure moves no page and the copy takes no device memory beyond the new pages. Alentflag skips the page scan on rooms that never shared.scratch38.rs,mtp38.rs,body38.rs: the K/V planes, the pooled keys and the MTP draft store share pages. Every writer callsown_fromafterfit.Slot38::share_pointgrants nothing when the source sequence holds an image, because a share does not carry the M-RoPE table.crates/serve:Engine::share_keepableandEngine::share_prefix(defaults 0 and Unsupported), acache sharenote, and a choice ingenloopthat takes the share only when it keeps more than the slot's own state and every cache entry.crates/gpu-gates: the qwen38 seat implements both calls, thekv roomrecord gainsshared_bytes, andgate_qwen4exp_e2egains aslots shareclause.What I ran
Card for every run below: GB10, driver 595.84, CUDA 13.3 (nvcc V13.3.73),
sm_121a.Gates on head
a0429839d, basefb43427d1, with the Qwen3.8 fixtureqwen38-fixture-00001-of-00001.ggufand its draftmtp-Qwen3.8-Flash-Next-shared-Q8_0.gguf:The new
slots shareclause fails without the change. WithBody38::stagenot callingown_from, the same run gives:With
Room::own_frommade a no-op, the room test fails on the pages the write reached:MTP draft store gate on head
ef6391584, baseb9584f6a6, the Qwen3.8 fixture and its draft above, GB10, driver 595.84, CUDA 13.3 (nvcc V13.3.73):The gate fails when a copy-on-write call is left out. Without it in
Mtp38::run_walk, instage_store, or withoutresetreturning the shared pages before a put-back, the same run stops with:The real
bloomery-servewith the MTP draft (--ctx-size 12288 --parallel 1, modelnvidia__Qwen3.8-Flash-Next-FP4-Localb9ce18a6) restores a cached prefix and continues bit-identically over three requests of 8 tokens:Real
bloomery-serve(qwen38 seat, release feature set fromtools/release/build.sh) on headb26420251, modelnvidia__Qwen3.8-Flash-Next-FP4-Local(b9ce18a6). Request A is a 10,000-id prompt with 768 greedy ids, streamed. Request B is A's first 9,000 ids plus 600 other ids with 128 greedy ids, sent when A's first chunk arrives. The server runs with--ctx-size 32768 --parallel 2; the reference runs A then B with--ctx-size 16384 --parallel 1. Both run with the MTP draft and withBLOOMERY_DRAFT=off. The ids of A and B from the two runs are compared:Request B with the MTP draft, on base
2a20a6e47and on headb26420251, same requests, one run each:prompt_msThe head also spends 14.7 ms on the share itself, shown in the
cache shareline above.AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.