Repository navigation
Conversation
…ts for the copy kvg_trim refilled the slots the K/V gave back and then uploaded host_res with a plain cudaMemcpy from pageable memory. That returns once the table is staged, before its DMA lands, and nothing after it waited for stream 0: the next request's session_zero syncs main_stream only, and a prompt part of --short-read tokens or fewer goes straight to ver.run, whose graph reads hits_.d_res on the verifier's cudaStreamNonBlocking stream. res_put (Niko1221#550) is the upload every other residency change uses: the same copy, then cudaStreamSynchronize(nullptr). kvg_ensure's upload needs nothing: qsa_kv_elastic_grow ends in cudaDeviceSynchronize before anything reads the table. Only --kv-grow (opt-in) runs kvg_trim, so the default path is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VZy1yKaDDiA8a7svdwaHio
Owner
|
Ported with your authorship; the reasoning matches res_put's own comment and the change is tiny. |
DarthCY-K
pushed a commit
to DarthCY-K/Strata
that referenced
this pull request
Oct 20, 2026
…ured PCIe share, Niko1221#1690 Niko1221#1693 Niko1221#1696 Niko1221#1283 as upstream's code) - README, docs/NVFP4.md and the bundle version Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VZy1yKaDDiA8a7svdwaHio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
--kv-grow(opt-in),kvg_trimgives the K/V's surplus back to the expert cache. It refills those slots and then uploads the residency table with a plaincudaMemcpyfrom pageable memory, with no sync after it (generate.cpp:6049 on fb58e0d):CUDA's API synchronization notes say that for a pageable host-to-device
cudaMemcpy, "The function will return once the pageable buffer has been copied to the staging memory for DMA transfer to device memory, but the DMA to final destination may not have completed."res_put's comment says the same (generate.cpp:5558, from generate: residency-table uploads wait for their own copy before the non-blocking streams read the table #550), and every other residency upload goes throughres_put. These twokvg_*uploads are the exceptions.kvg_ensure's upload (5963) is covered:qsa_kv_elastic_growends incudaDeviceSynchronize(layer.cpp:601) before anything reads the table.kvg_trim's upload is not covered.What reads
d_resafter a trim, in serve on fb58e0d:kv_quiesce()(cudaDeviceSynchronize+apply_pending), thenkvg_trim. The sync comes before the upload, not after it.resume == 0, 9325):session_zeroonmain_cs, thencudaStreamSynchronize(main_stream).main_streamiscudaStreamNonBlocking(2796), so this waits for nothing on stream 0.apply_pending(true)returns at once, becausekv_quiesceemptiedpending(7415).adapt_tick(true)also returns at once:--adapt-asyncneeds the resident mode, and that turns--kv-growoff.--short-read(64) tokens or fewer goes through the verify windows (9396).refill()(9883) has nothing to give back, because the last request refilled its loan at its end (9927). So it makes nores_upload.ver.run(9539) launches the window graph on the verifier'scs_, which iscudaStreamNonBlocking(verify.cpp:605).hits_.d_resinresident_plananddoorbell_publish_res(verify.cpp:1320-1352).lend()instead, whoseres_uploadsyncs stream 0 first. That path is ordered.So nothing orders that first window after the copy. If the window reads the old table, the refilled experts look not resident to the GPU's plan, while the CPU pool, which plans from
host_res, already counts them as resident.The pattern alone (a scratch program, not part of the PR):
cudaMemcpyfrom a pageable buffer;cudaMemcpy, reader on acudaStreamNonBlockingstream (kvg_trimnow)cudaMemcpy+cudaStreamSynchronize(nullptr)(res_put, this PR)cudaMemcpy, reader on a blocking streamWith the host waiting before the launch (1,000 launches each, two runs):
In the engine, more host work than that sits between the two:
session_zero's memsets, which the host waits for, and theRESUMEline. So the window is tens of µs wide here. This is a latent ordering bug: I have not seen it change tokens. A copy queued behind other DMA, or a faster path to the first window, would widen or reach it.Change:
kvg_trimuploads withres_put: the same copy, thencudaStreamSynchronize(nullptr). One line.Default identity:
kvg_trimreturns at its first line unless--kv-growis on (kvg.on), so without the flag the build runs fb58e0d's code. The extra sync costs one wait for a 96 KiB copy per trim, and a trim happens at most once per request.Run with the change. Settings:
--kv-grow --expert-cache 12000 --spec 4 --kv int8 --max-context 262144 --vram-reserve-mib 1500;STRATA_KV_GROW_INIT=4096 STRATA_KV_GROW_STEP=2048, so a short session grows and trims.Requests, all greedy:
The same four requests on a fb58e0d build with the same settings gave the same replies (content and token counts), and the same grow, trim and per-request
decode expert cache hit ratelines, to the hit. No errors.Not measured: the engine's actual gap between the trim and the first window; HIP (
res_putis already used there).🤖 Generated with Claude Code
https://claude.ai/code/session_01VZy1yKaDDiA8a7svdwaHio