Repository navigation
Qwen 3.5 CUDA: kept prompt states reuse a freed pinned buffer of their size - #2841
Conversation
0ee0c87 to
c5dcbe0
Compare
|
I’m preparing the dense MTP work for #2485 as an unpublished local branch. ATC reports a merge conflict in |
|
Update after rebasing the #2485 MTP stack onto upstream main 6bc82ac. ATC still reports a conflict with #2841 in zig/src/families/qwen3_5/cuda_native.zig. I’m opening a draft PR from my fork so the MTP/TTFT work can be reviewed; it is not merge-ready. Would you prefer the MTP branch to be restacked after #2841 lands, or should we coordinate a combined resolution? |
bb325b7 to
0977ee9
Compare
|
/atc exchange 61feb30bb52e3b340c3fca87c75804e681614b0ae97909602022e9ab18cfb067 |
…2833) Every host save and disk-recall blank pinned new memory (cuMemHostAlloc) and every drop unpinned it. A dropped copy's buffer now goes to a list of at most two spares on the target, once no copy into or out of it can be queued: the save synchronized, and no restore still reads it (a stuck one still goes to the copy-source quarantine). The next save or blank of exactly that size takes it instead of pinning. The prompt cache counts the spares inside its budget (snap_spare), frees them when it needs the room (snap_trim, now wired through cuda_snaps.zig) and keeps a state in a spare without evicting more (snap_reuses); the dense and MoE entries both declare the hooks. The spares are freed with the engine, after the host closes the prompt cache. The bytes copied are the same; only their buffer changes. Host tests on a mock driver that moves real bytes: reuse after a drain, none before, another size pins, the cap, trim and teardown, byte-equal saves and restores in every layout, a recall blank, and the store reusing an evicted state's buffer.
…erywhere, so a skipped byte shows
… stage Main's stage geometry reads first and whole; a geometry built field by field from undefined left them unset, so deltas() read past the layer table and every kept-spares test crashed on today's main.
…o spares saveCache takes the spare list now; the checker's three saves passed five arguments, so the Linux checker (compile-qwen35-rounds-host, and tf-qwen35-cuda on a device) no longer compiled.
…imported inline, so cuda_native.zig stays under 600 lines
0977ee9 to
573f97c
Compare
Qwen 3.5 on CUDA pins a new host buffer (
cuMemHostAlloc) for every kept prompt state it saves and every disk-recall blank, and unpins it when the state is dropped. Pinning is slow, and a cold 8K-32K prompt that saves states pays it on every save.What changes:
Exactness: the copies are byte-for-byte the same; only the buffer they land in differs, and every byte is written before it is read. Two cache edge cases can differ from main (never replies, only which states stay cached):
core/lane_cache_queue.zig), without trimming spares or checking whether it could reuse one first. Right after a keep, spares sit in exactly that room, so a fallback checkpoint main kept can now be skipped. The disk probe's spare (sized atmax_rows, held until the first keep or recall trims) can trigger this on the first requests, as can a debug-onlyTF_IMPRINT_VERIFYread-back.Checks: nine spare tests and one hook-wiring test on a fake driver that moves real bytes and hands out pinned memory from the testing allocator (a leak fails the test): reuse after drain, none before, a size mismatch pinning new memory, the cap, teardown, a recall blank, a real prompt cache reusing an evicted state's buffer, and a save/restore round trip matching a save into new memory in bf16 and fp8, contiguous and paged, with the reused buffer pre-filled with other bytes. Fifteen planted breaks each turned a test red.
test-cuda-host,compile-cuda-tests -Dtarget=aarch64-linux-gnu,check-native-cuda-host,zig fmt --checkand the lean count pass.Still to run before landing: one GB10, Qwen3.8-27B, main against this branch with a small
--prompt-cache-gib(2 GiB for 8K prompts, 5 GiB for 32K) so saves start reusing early, with--learn-conversationsand then--spill-gib:token_sha256equal and first-token time after the budget fills. #2113 measured a 1.6-2.1% ceiling for this kind of save cost.For #2833.