Repository navigation
Conversation
fd7cf70 to
8de6cba
Compare
|
@jschmied, thanks. This is a clean first step for P3: every entry is the address the kernels computed before, so the arithmetic and its order are unchanged, and the host tests pin that. A few things before it lands:
|
8de6cba to
6ea5ca8
Compare
|
@jschmied, thanks for the follow-up and the full table. Finding each segment's table without waiting for the
|
|
@ashhart thanks. The head is
Checks on
|
|
Thanks @jschmied, this is a careful answer.
One small thing for the next push: the comment at |
|
@ashhart, converted to draft; Q3 is being built on it. Two questions before the table, each with what I'll do unless you say otherwise:
Streams without pages will keep main's kernels exactly: the table-reading kernels become a second instantiation used only by paged streams, so the pages-off cells run main's SASS and should be level by construction. |
|
Thanks @jschmied. On your two questions:
For the pages-off cells, please include the SASS (or fatbin) comparison against main that shows they run main's kernels, alongside the table. And on your next push, the comment at
|
3f044af to
ce657e4
Compare
|
@ashhart thanks.
Gates on ce657e4: test/golden, cuda-host, ci set, x86 cross, pr_check (0 errors), fmt, lean 0 new; tf-cuda-test qwen-pending, qwen-pages and kernel-contract equal main plus all |
|
@jschmied, thanks; this answers everything we asked:
Since
Otherwise the plan stands: keep this as a draft, build Q3 on it, and post the main-against-pair table with the SASS comparison for the pages-off cells beside it.
|
|
@ashhart thanks.
Still a draft. The body has both. |
|
@jschmied thanks, both are answered. Zero of 114 keys differing in all 12 page-on/page-off pairs, with the seeded replies in the set and drafting, resume and concurrency covered, is the comparison we were after.
|
c4ba435 to
0a49c0a
Compare
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).
|
@ashhart this PR is rebased onto main f0d8c8d, because #2939 asked for a rebase and is stacked on it. The new head is 0a49c0a; the commits and messages are unchanged. Gates rerun on 0a49c0a:
The body names the new head. Main has moved again since the rebase: on 000b534 the pipeline-stage commits (4dd870b to 799ae94) touch |
|
Thanks @jschmied for rebasing the pair and rerunning every gate on 0a49c0a, including the SASS comparison and the conformance kit. We compared it with c4ba435, and all twelve commits carry the same changes, so our earlier review stands and the code needs nothing new. On another rebase: yes, one more is needed before the pair can land, because both heads now conflict with main's pipeline-stage commits in
GitHub ran no CI on 0a49c0a, because it doesn't start pull request jobs while a branch conflicts with main. The rebased head will get its first run. This stays a draft and lands with #2939 in one train.
|
0a49c0a to
74140af
Compare
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).
|
Thanks @jschmied for rebasing the pair onto
CI is green on Next is a run 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)
74140af to
6587e14
Compare
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).
|
@ashhart this PR and #2939 are rebased onto main 328a566; both were conflicting with main. The new head is 6587e14. Each conflict is fitted into the commit that brought the line, taking main's code where main moved:
Gates on 6587e14:
The body names the new head. |
What this changes
The first kernel step of #2444 P3 for Qwen 3.5/3.6 on CUDA (Q1 in the P3 plan). Main's GDN kernels assume one
contiguous block a stream and compute their addresses from it: a layer's recurrence at
sg.rec + layer * rec(), itsconv tail at
sg.conv + layer * conv_rows(), the one-row rollback copy's tail pastnlrecurrences, and a windowrow's record at
(row * nl + layer) * log_bytes. This branch adds a per-stream table of those addresses(
cuda_states.zigStates: nl recurrences, nl tails, nl + nl copies, 64 log rows; 2 KiB on the 27B, 1.4 KiB on the35B-A3B) and a second build of each of those kernels,
name_table, that takes every address from the table. That iswhat lets P3 put the state on separate pool pages (Q3) without touching a kernel again.
gdn_pre,conv_commit,gdn_chain,gdn_slots_{1,2,4,8,16},k_apply,k_apply_pendandk_convare main's code, compiled to main's SASS on all five SMs (table below). Only aforward with a pool lane among its parts (
TF_QWEN_KV_PAGES,Cache.on_table) runs the_tablekernels(
Shape.table, its own captured graphs); every other forward builds main'sSegand launches main's kernels, and itskeep, pending rows and prompt delta read the stream's blocks as on main.
qwen35_gdn.cuh,qwen35_slots.cuh,qwen35_keep_state.cuh), withTF_Q35_TABLE0 and 1;#if TF_Q35_TABLEpicks the table reads (1 to 4 lines akernel) and
TF_Q35_K(name)names the kernel. TheTF_Q35_TABLE 0pass is main's text token for token, so the mainnames compile to main's SASS. A
template <bool TABLE>body was tried first and is not used: on sm_80, 86 and 89nvcc reordered the address math of main's instantiation (same instruction count and registers, different order) in
gdn_chain, the slot scans,k_applyandk_apply_pend.lane's
mapRun, the dense 27B's adaptive scratch leases). The forward kernels find segment s's table in theengine's tables buffer after its staged planes (
cuda_round.zigstates_at,qwen35.cuhforward_states), copieddevice to device only when the stream at that position or its blocks change, so a captured forward needs no
recapture and the entry load issues beside the
Segload. Keep launches, which take theirSegby value, read thestream's own table.
TF_QWEN_KEEP_LATEpending buffer (Seg.plog) stays a direct pointer (P3 Q5).Cost: pages off (the default) is main's SASS, see the table. Under
TF_QWEN_KV_PAGESthe_tablekernels run;the 256 rows on this head are in the receipt, with the cells that came out slower than main named there.
pr_checkwarns that no Unreleased bullet names this PR.Proposed CHANGELOG line (for you to place):
Rebase onto main 328a566 (head 6587e14)
Main moved about 1,700 commits since 6c5cef8. Each conflict is fitted into the commit that brought the line, taking
main's newer code where main moved:
tf_q35_conv_commitand the slot scans copy the one-rowbeforeonlywhen
sg.before != 0. The shared source inqwen35_gdn.cuhandqwen35_slots.cuhcarries that guard, so theTF_Q35_TABLE 0pass is still main's text, and the_tablecopies skip the copy the same way.stagedSegtakes theforward's table (null: main's
Seg) and still clearsbeforefor an unkept one-row step.Shape.key: main widened the key tou64and putjoinon bit 32.tablenow takes bit 33, andslotskeepsmain's 8 bits (the 5-bit narrowing and its assert are gone). The Rollback conformance tests #2138 test varies
join,tableandparttogether.Planted control:
tableonjoin's bit 32 turns that test red.max_rows8192 (TF_QWEN35_CHUNK_SOLO): the per-forward state tables sit after the larger planes, soSEG_STATES(qwen35.cuh, asserted incuda_round.zig, and the two GPU tests'seg_states) is 445,472, not232,480.
anySharesbesideStates,e.tapRows()in theSeg);finishtakes main's form without the scratch line.dense_serving_test.zigpinsqwen35.cu,qwen35.cuh,qwen35_keep.cuand the launch sequence;they name this PR's bytes now (the sequence differs only because
gdn_preandconv_commitpick their_tablecopy under
shape.table, with the same arguments).contract_q35_launch_args_host.zigreadsgdn_pre'spast_rowscheck fromqwen35_gdn.cuh.qwen35_live_host.zigpassesshape.tabletodeltaScan.cuda_engine.zigis at 600 lines and already moved the "dense read cost" key test tocuda_engine_test.zig, so the last commit is replaced:deltaScanmoves besidebodyincuda_forward.zigandstateEntriesintocuda_round.zig(engine 600 lines). The usage line forqwen-tableis inmain_usage.zig.tf_q35_gdn_slots_{1,2,4,8,16}_table(for examplesm_121 80/80/88/78/94 under nvcc 13.0). Their 13.0 rows (
cuda_lane_pending.zig) and 13.2 rows(
measurements/qwen_lanes_132.zig) carry the new numbers; every other_tablerow is unchanged.qwen-table: its_tableSegsetsbeforeassegIndoes (the copy's table entry), so a one-row step keepsits copy under main's
sg.before != 0guard, as in the engine.SASS against main (pages off runs main's kernels)
tools/zig/cuda_sass_compare.py 328a566e2 d819e71aa(nvcc 13.0.88, every emitted function, sm_80/86/89/120/121);d819e71aa's kernel sources and build files equal 6587e14's (the later fixups touch only tests and limit rows). The
change reaches three images: qwen35, qwen35_keep and qwen35_kv8.
_tablekernels a SM_tablekernels a SMbeforeguard, is equal (SASS and encodingsha256); nothing changed, removed or unstable. The tool counts an added function as a difference, so qwen35 and
qwen35_keep were compared in runs of their own and the verdict is "main's functions equal, only the expected
_tablekernels added"; qwen35_kv8 runs alone to the tool's own SUMMARY PASS, its planted control red as expected.compared-functions.tsvand the per-run logs, kept with the run.Checks on this head
On 6587e14 (main 328a566), nvcc 13.0.88 (13.2.86 for the 13.2 records), one GB10 (sm_121):
qwen-tabletest):zig build -Dfixed-cpu test test-golden(781/781 steps),test-cuda-host(438/438steps), the CI set
test-kernel-contract test-server-security test-pull-security fuzz-cortheon(54/54 steps,340/340),
test-kv-pool(100/100),test-qwen35-stage-host(24/24), every qwen/recurrent-hoststep (331/331steps),
tools/zig/cuda_common_check.py,pr_check(0 errors),zig fmt --check,git diff --check, no changed fileover 600 lines, lean 0 new (168 against 168 on main).
check-native-cuda-host compile-cuda-tests(17/17), the full host set withcheck-release-paths(2287/2287 steps, 22441/22597 tests, 156 skipped),
pr_check(0 errors, the CHANGELOG warning),zig fmt --check.Run with umask 022: under the box's umask 0002 main 328a566 fails its own
cli_config_testmode check(
serve --config: expand reads the file...) the same way.Shape.key:tableput onjoin's bit 32 turns the Rollback conformance tests #2138 key test red by name.tf-cuda-testand the head's, outcome lines compared:qwen-pending49 lines equal main's, andthe same 49 cases on the
_tableinstantiation all PASS;qwen-pages26 equal;kernel-contract qwen35 q35125equal plus 11
_tablelimit lines PASS.kernel-contract-limitson 5-SM fatbins: nvcc 13.0.88 0 failing and no_tablerow stale; nvcc 13.2.86 0failing and no
_tablerow stale. The stale lines left (86 under 13.0, 1349 under 13.2) are the same lines main328a566 gives on the same fatbins, for launches this PR does not touch.
tf-cuda-test qwen-table(test only,zig/tests/cuda/contract_qwen_table.zig):gdn_pre_table,conv_commit_table,gdn_chain_tableandtf_q35k_conv_tableon a state split into one allocation a layer's regionand a log row (two segments, layer 1) give main's kernels' bytes on the blocks: outputs and both streams' whole
state, a decode row, a 4-row chain and an 8-row drafted tree, recorded and not, 3 repeats, guards. Planted controls
in segment 1's table go red in every case that reads the entry. 25 PASS lines.
Receipt
tools/conformance.py, profileqwen35-cuda: drafted == plain, repeat ==first, concurrent == solo at 1/2/4/8, resumed == fresh, refusals, cancel, evict) on main 328a566
(
tensorfold-nativemd5 7f498d79) and this head (md5 6801b1a7; 6587e14 builds the same binary as d819e71aa),both
zig build native -Dsm=121,--parallel 8 --context 16384: Qwen3.8-27B NVFP4 + DFlash2, the 27B without adrafter, Qwen3.6-35B-A3B + MTP, each with
TF_QWEN_KV_PAGESunset, at 256, and at 256 withTF_QWEN_KV_SHARE=16.sampling, 4 refusals, 14 evict and overlap; 116 for the 27B without one), and each gate's verdict is the same.
evictfails on main too: its 10 fill prompts evictnothing (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 (no cancel or evict block, and concurrent == solo, 76/76 equal, flags that no draft was
accepted).
--parallel 8 --context 16384, clock capped, page cache dropped before each server;c=1 is 3 x 256 tokens, tok/s from the done lines, one decimal; c=4 is 3 rounds of 4 x 256; greedy shas of solo,
c=4, c=8, decode and the c=4 rounds equal to main's in every arm):
TF_QWEN_KV_PAGES=256, main, this PR and this PR + qwen3_5 cuda: a pool lane's state as pieces on any whole pages of its lease, no run (#2444 P3, Q3) #2939, 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.
Pages unset runs main's SASS (above). Measured anyway on the 35B-A3B + MTP, the same A-B-C-C-B-A: c=1
-0.17 / +0.35 %, c=4 -0.37 / -0.17 % against main (medians 114.40 / 114.35 and 186.02 / 185.29). The 27B cells
unset are in qwen3_5 cuda: a pool lane's state as pieces on any whole pages of its lease, no run (#2444 P3, Q3) #2939's table (this PR + qwen3_5 cuda: a pool lane's state as pieces on any whole pages of its lease, no run (#2444 P3, Q3) #2939 against main).
Paired losses, stated plainly: at 256 this PR is slower than main in 3 of 6 c=4 blocks (27B + DFlash2 block 1
-1.03 %, the 27B without a drafter -0.06 and -0.11 %), and unset, where the kernels are main's, the 35B's c=4 is
slower in both blocks (-0.37 / -0.17 %). Under the no-slower-cell rule: don't land yet. The unset cells run
main's kernels with only host-side changes, and a second A-B-B-A for the same cell can come out the other way
(see qwen3_5 cuda: a pool lane's state as pieces on any whole pages of its lease, no run (#2444 P3, Q3) #2939: the pair's 35B c=1 unset was 4 of 4 slower in one run and +0.57 % in the next), so these are within
the run-to-run spread; I'm saying it rather than calling them level.
rows), sm_121; one NVIDIA GB10 (128 GB unified), GPU clock capped, page cache dropped before each server;
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.
Metal, HIP and XPU are not reached.
Checklist