Repository navigation
qwen3_5 cuda: a pool lane's state as pieces on any whole pages of its lease, no run (#2444 P3, Q3) - #2939
qwen3_5 cuda: a pool lane's state as pieces on any whole pages of its lease, no run (#2444 P3, Q3)#2939jschmied wants to merge 15 commits into
Conversation
|
Thanks @jschmied. The piece packing, the page accounting through
On the behaviour change you asked us to rule on: refusing a page smaller than the largest piece at load, by name and with the smallest size that works, is fine. It applies only under the opt-in, and 256 clears it on the 27B, the 35B-A3B and the 2B, with fp8 caches too (their minimums are higher there, 131 and 202 rows on the 27B and 35B-A3B, which your log line already computes). #2898 carries the same core commit, so whichever of the two lands second takes the other's
|
9a671bd to
f4a0bdf
Compare
|
@ashhart thanks.
Thanks for ruling on the page-size refusal. On #2898: agreed, whichever lands second takes the other's The decode hot path did not change (load, init and the load-time plan only), so the speed table stands. Main has moved again since the rebase: on 000b534 the pipeline-stage commits (4dd870b to 799ae94) touch |
|
Thanks @jschmied. All four points are answered on
Yes, please rebase #2620 and this onto main. We tried the merge here, and it needs more than the two textual conflicts:
With those three changes and nothing else (we tried For gates on the rebased pair, the full 8 h set isn't needed again, because the rebase changes only these lines and no kernel. Please run the host set and the x86 checks,
|
f4a0bdf to
250994a
Compare
|
@ashhart both PRs are rebased onto main 6c5cef8. #2620 is now at 74140af and this PR at 250994a, still stacked on #2620. The four points are folded into the commits that introduced each line:
Gates, the reduced set you named, on both heads against main 6c5cef8:
No SASS run this time: no kernel changed. The speed table stands.
|
|
Thanks @jschmied for the rebase onto
CI is green on this head and on #2620's Next we'll run the pair on our GB10, main
|
…og through a stream's state table The GDN kernels assumed one contiguous block a stream: a layer's recurrence at `sg.rec + layer * rec()`, its tail at `sg.conv + layer * conv_rows()`, the rollback copy's tail past `nl` recurrences, a window row's record at `(row * nl + layer) * log_bytes`. Seg.rec, .conv, .before and .log now point into a per-stream table of addresses (cuda_cache.zig States: nl recurrences, nl tails, 2 nl copies, 64 log rows; 2 KiB on the 27B), so the pieces can later live on separate pages without another kernel change. Seg keeps its layout, so kernels that do not touch the state compile as before. The table is filled from today's blocks, so every entry is the address the kernels computed before and the placement is unchanged. Cache.seg rewrites it on the engine's stream only when the state, before or log block moved (a pool lane's mapRun, the 27B's adaptive scratch leases); a captured forward reads it from device memory, so no graph is recaptured. The prompt chunk's delta rule and the pending keep copy take their addresses from the host copy. Its bytes count in streamBytes and a pool lane's fixed bytes.
kernel-contract-limits on 5-SM fatbins (sm_80, 86, 89, 120, 121) built with nvcc 13.0.88 printed these for the ten launches that now read a stream's state table; every other launch's record is current. nvcc 13.2's and 13.3's receipts for them are not measured here and stay as they are.
…compute Each GDN launch read its Seg, then the table entry, then the state: one more dependent load than before the table. The engine's tables buffer now holds a state table for each forward segment after its staged planes (cuda_round.zig states_at), copied from the stream's own when the stream or its blocks change, and the forward kernels find segment s's table at segs + SEG_STATES + s tables, so the entry load does not wait for the Seg. Keep launches, which take their Seg by value, read the stream's own table as before.
…a_states.zig A pure move: cuda_cache.zig keeps States as a name for it, so no caller changes.
…g receipts, not records The seven rows predate the state table and nvcc 13.3 is not on the machine that changed the kernels, so they move from nvcc_133_records.zig to measurements/pending_133.zig until 13.3 measures them.
…ve SMs Measured with nvcc 13.2.86 on five-SM fatbins (kernel-contract-limits); the ten launches' rows in qwen_lanes_132.zig take its numbers, and the slot scan's selection test follows them.
…te table's readers are _table copies
Main's gdn_pre, conv_commit, gdn_chain, gdn_slots_{1,2,4,8,16}, k_apply, k_apply_pend and k_conv keep main's
code and read Seg's blocks again. Each is built a second time as name_table, reading the stream's state table:
the kernel's source is included twice (qwen35_gdn.cuh, qwen35_slots.cuh, qwen35_keep_state.cuh) with
TF_Q35_TABLE 0 and 1, and #if TF_Q35_TABLE picks the table reads, so the TF_Q35_TABLE 0 pass is main's text
token for token and main's names compile to main's SASS on sm_80, 86, 89, 120 and 121 (a template parameter
did not: nvcc reordered the address math on sm_80-89).
Only a forward with a pool lane among its parts (TF_QWEN_KV_PAGES, Cache.on_table) runs the _table kernels
(Shape.table, its own captured graphs); every other forward builds main's Seg and launches main's kernels, and
its keep, pending rows and prompt delta read the stream's blocks as on main. The _table kernels' contract rows
carry the numbers the table readers had under main's names; main's rows are main's again.
…tate table A cache holds its state table beside its blocks since the first commit (one more device allocation and its bytes in streamBytes), and Cache.seg can fail; the nightly host steps test-qwen35-shared-host and test-qwen35-recurrent's 27B checks now expect both.
…ive SMs The other ten _table launches carry a 13.2 row in measurements/qwen_lanes_132.zig; apply_pend_table had none, so kernel-contract-limits found no 13.2 record for it. Measured with nvcc 13.2.86 on this head's fatbins.
…_table on pieces against main's on blocks qwen-table runs each _table kernel on a state split into one allocation a layer's region and a log row, two segments, and compares its outputs and both streams' state with main's kernel on the blocks; a planted table entry (layer 1's tail or recurrence naming layer 0's, or the kept log row naming another row) in segment 1 must change them.
… in cuda_round.zig (cuda_engine.zig 600 lines)
kv_pieces packs a family's state pieces first-fit decreasing on whole pages (each piece inside one page, 256-byte aligned) and checks a map for overlap. Lease.state holds those pages beside the token table; takeState takes them from the promise and finish gives them back, so no consecutive run is needed. Layout.pieces counts them wherever a run counted (need, plan, holds), and Layout.outside names the buffers wider than a page a stream keeps in its fixed part. The load report shows the pieces, their pages and pad, and that fixed part.
Under TF_QWEN_KV_PAGES a lane's recurrences and tails, its verify log rows and the rollback copy are pieces on whole pages taken from its lease (cuda_state_pieces.zig over core kv_pieces): no consecutive run, so a pool with no two free pages side by side still admits a lane. The copy lies in the bytes of log rows 1.., as the Overlay does: a one-row window uses row 0 and the copy, a wider window the rows and no copy. The taps and a drafter's ring, wider than a page, are a lane's own block outside the pool, counted in its fixed part. The lane's state table is written once at open from the piece map; a closed lane's table is refused (version 0, and a lane without blocks or pieces has no entries to read), so no forward copies entries that point at the pages it gave back. Kernels are ashhart#2620's: a forward with a lane on pieces runs the _table kernels. A page must hold the largest piece (a log row or a layer's recurrence): a smaller TF_QWEN_KV_PAGES is refused at load with the smallest size that works (27B: 67 rows; 35B-A3B: 103).
250994a to
1350872
Compare
|
@ashhart this PR is rebased onto main 328a566, on #2620's new head 6587e14. The new head is 1350872: the core commit is 5451b4a and the Qwen commit is 1350872.
Gates:
The body names the new head. |
What this changes
The pages step of #2444 P3 for Qwen 3.5/3.6 on CUDA (Q3 in the P3 plan). Under
TF_QWEN_KV_PAGES, a pool lane usedto take its state, log, rollback copy, taps and drafter ring as one run of consecutive pool pages, so a fragmented
pool refused a lane with
LaneMemory. Here a lane's state lies as pieces on whole pages it takes from its lease,any ids. #2620's state table already addresses the pieces, so no kernel changes.
Stacked on #2620 (6587e14, on main 328a566). The base is main because #2620's head is on the fork. Please
review only the two commits after it: 5451b4a (core) and 1350872 (Qwen). Head: 1350872.
kv_pieces.zigpacks a family's pieces first-fit decreasing on whole pages,each piece inside one page and 256-byte aligned, and checks a map for overlap.
Lease.stateholds the state's pagesbeside the token table.
Pool.takeStatetakes them from the promise, andfinishgives them back.Layout.piecescounts them wherever the run counted (
need,plan,holds,held). NoclaimRunand no consecutive run.takeStatetakes the highest free ids and keeps the free stack's order, so KV pages still fill from the bottom(see the c=4 cause below). flashnext: pool lanes keep their states and draft as pieces on whole pages, no run (#2444 P3, F2) #2898 carries the same core commit with the older
takeStateand will take this one.cuda_state_pieces.zigplans a lane's pieces: a recurrence and a conv tail per linear layer, theirpre-round copies, and the 64 log rows.
cuda_cache_lane.zigmaps them at open (the state table written once anduploaded), zeroes them, rolls back and copies them piece by piece, and unmaps at close. A closed lane's table is
refused (version 0,
MissingQwenStates). The save/restore and reuse paths walk the pieces.stay outside the pool as part of a lane's fixed part, are counted at admission (the extra lane the pool makes when
every stream is on pages too:
cuda_kv_pool.zigserved), and the load line names them,as Roadmap: one paged KV pool and a radix prompt cache for every family #2444 option (a) settles.
state, in the pool as pieces: 118 pieces, 411.38 MiB on 27 pages a lane, 20.63 MiB padding (4.8 %). qwen3_5 cuda: the GDN kernels read the state, its rollback copy and the log through a stream's state table (#2444 P3) #2620's run took 26 pages with 4.63 MiB padding.log row. A smaller
TF_QWEN_KV_PAGESis now refused at load by name (QwenPageBelowState), and the log names thesmallest size that works: 67 rows on the 27B, 103 on the 35B-A3B. The run accepted any page size.
Rebase onto main 328a566 (head 1350872)
Rebased with #2620 (see its body for the GDN side: main's rollback-copy guard,
Shape.keyonu64withtableonbit 33,
SEG_STATES445,472). On this PR's two commits:kv_pool.zig.finishkeeps main's skip of retiredids (
retirement.none) for the token table and gives the state pages back as before; state pages are never inids, so retirement does not see them.cuda_kv_pool.zigis flashnext: pool lanes keep their states and draft as pieces on whole pages, no run (#2444 P3, F2) #2898's current file as is (7ca3798, three blanklines out, 600 lines).
kv_pool.zigtakes main'skv_pool_trim_cost_test.zigline too, so to stay at 600 lineskv_pool_state_test.zigis referenced fromkv_pieces.zig's test block instead ofkv_pool.zig's; that is theone difference from flashnext: pool lanes keep their states and draft as pieces on whole pages, no run (#2444 P3, F2) #2898's core files, besides main's test line.
cuda_reuse.ziggrew on main (spares, 595 lines), so its image-rule test ("a state resumes only arequest with the same images") moves unchanged to
cuda_reuse_test.zig(596 lines). Thecuda_pages.zigandcuda_reuse.zigimports keep both sides.cuda_spares_test.zig): its fixture starts from anundefinedcache and sets main'sfields; it now also sets
pieces = null, so the save path walks the one block as on main. Without it the x86 hostrun crashed in 8 of those tests (
cuda_cache_lane.zigparton garbage pieces).Main against the pair (#2620 + this), on these heads
Main 328a566 (
tensorfold-nativemd5 7f498d79), #2620 6587e14 (md5 6801b1a7) and the pair (md5 c34e9cf1;1350872 and f4f591e74 differ only in a host test), each
zig build native -Dsm=121, the md5 of each served binarychecked, one GB10 with the clock capped and the page cache dropped before each server,
--parallel 8 --context 16384.c=1 is 3 x 256 tokens (tok/s from the done lines, one decimal). c=4 is 3 rounds of 4 x 256. In every arm the greedy
shas (solo, c=4, c=8, decode and the c=4 rounds) are equal to main's.
Pages unset, main against the pair, A-B-B-A twice. The paired median is over 4 neighbouring pairs.
The 35B c=1 loss was run again (main, #2620, pair, A-B-C-C-B-A twice): the pair against main was -0.22 / +0.57 % at
c=1 and +0.07 / +0.06 % at c=4, #2620 alone -0.17 / +0.35 % and -0.37 / -0.17 %. With pages unset the pair runs main's
kernels (SASS above, through #2620).
TF_QWEN_KV_PAGES=256: main, #2620 alone and the pair, A-B-C-C-B-A twice. Each block's difference to maincancels linear drift: (x_i + x_j) / 2 against (main_i + main_j) / 2.
Paired losses, stated plainly: pages unset, the pair's 35B c=1 was slower in 4 of 4 pairs (-0.44 %) and its c=4
in 3 of 4 (-0.26 %); the rerun did not repeat the c=1 loss. At 256 the pair is slower than main in 5 of 12 blocks
(-0.04 to -0.68 %), and #2620 alone in 3 of 6 c=4 blocks. Under the no-slower-cell rule: don't land yet. These sit
inside the ±0.6 % run-to-run spread of one cell, and the unset path runs main's kernels, but I'm reporting them as
measured rather than calling them level.
The c=4 cause, found and fixed on this branch. An earlier head (4881be351) was slower than main at 256 and c=4
in 4 of 4 pairs on every configuration: -0.05 % (27B + DFlash2), -0.16 % (27B, no drafter) and -0.21 % (35B-A3B +
MTP). nsys over one c=4 window (27B, 256; never ncu) showed:
tf_q35_attn_partial14-16 % slower by median (103 -> 118-120 us), only on this branch.takeStatehad taken a lane's state pages from the low free ids, so the four streams' KV pages lay about 27 pagesapart instead of side by side. With the state on the highest ids (9a671bd), attention runs at 98.8-100.5 us
against main's 107.7 and #2620's 101.6.
kv_pool_state_test.zigpins the order.Checks on this head
On 1350872 (stacked on #2620 6587e14, merge base 328a566), nvcc 13.0.88, one GB10 (sm_121):
qwen-tableline and the spares fixture line):zig build -Dfixed-cpu test test-golden(781/781 steps),test-cuda-host(438/438 steps), the CI set (54/54 steps, 343/343),test-kv-pool(113/113),
test-qwen35-stage-host(25/25), every qwen/recurrent-hoststep (331/331 steps),tools/zig/cuda_common_check.py,pr_check(0 errors),zig fmt --check,git diff --check, no changed file over600 lines, lean 0 new (168 against 168). On 1350872:
test-qwen35-kept-spares-hostandtest-qwen35-modelopt-admission-host(220/222, 2 skipped).check-native-cuda-host compile-cuda-tests(17/17), the full host set withcheck-release-paths(2287/2287 steps, 22513/22669 tests, 156 skipped),pr_check(0 errors, the CHANGELOGwarning),
zig fmt --check. Run with umask 022: under the box's umask 0002 main fails its owncli_config_testmode check the same way.
tf-cuda-testoutcome lines equal to main's:qwen-pending49 lines plus the 49_tablecases, all PASS;qwen-pages26 lines;kernel-contract qwen35 q35125 lines plus 11_tablelimit lines, all PASS; qwen3_5 cuda: the GDN kernels read the state, its rollback copy and the log through a stream's state table (#2444 P3) #2620'sqwen-tableon this head: 25 PASS lines, every planted control red.git diff 6587e1435 1350872c2 -- zig/kernelsis empty);cuda_sass_compare.py 6587e1435 f4f591e74 --images qwen35,qwen35_keep,qwen35_kv8refuses with"image scope is not reached by this change". The SASS against main is qwen3_5 cuda: the GDN kernels read the state, its rollback copy and the log through a stream's state table (#2444 P3) #2620's (qwen35 33/33, qwen35_keep 4/4,
qwen35_kv8 PASS on all five SMs).
tools/conformance.py, profileqwen35-cuda), main 328a566 and this head, threeconfigurations (27B + DFlash2, 27B without a drafter, 35B-A3B + MTP), each with
TF_QWEN_KV_PAGESunset, at 256 andat 256 with
TF_QWEN_KV_SHARE=16:sampling, 4 refusals, 14 evict and overlap; 116 without one) and each gate's verdict is the same;
concurrency 1/2/4/8, drafting);
evictfails on main too (its fill evicts nothing:cached 4096 -> 4096, 3/3 equal against cache-off); the 27B without a drafter uses the earlier copies profile, 4/7
on main and here.
pieces (kv-pool and cuda-host tests); the rollback copy's pieces on log row 0's piece (cuda-host); a reopened lane
keeping its last lease's table entries (18 of 76 concurrent == solo unequal, 0 illegal-address lines); the old init
order (
cuda_pages_init_test.zig). LEAK: a failed state allocation, a cancel after open and a failed table writeleave the pool as at load.
Receipt
13.2 limit rows); one NVIDIA GB10 (sm_121, 128 GB unified); checkpoints Qwen3.8-27B NVFP4 (Unsloth FP8 head) with
the Qwen3.8-27B DFlash2 drafter, and Qwen3.6-35B-A3B MLX 4-bit with its MTP head.
HIP and XPU are not reached.
pr_checkwarns that no Unreleased bullet names this PR.Proposed CHANGELOG line (for you to place):
Checklist