mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #197] [CLOSED] sampler: top_k by lexicographic threshold, split over the whole GPU #2503
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#2503
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/197
Author: @gputier
Created: 9/30/2026
Status: ❌ Closed
Base:
main← Head:pr/sampler-topk📝 Commits (1)
fd2c6easampler: top_k by lexicographic threshold, split over the whole GPU📊 Changes
4 files changed (+908 additions, -6 deletions)
View changed files
📝
CMakeLists.txt(+6 -0)📝
include/strata/hip_compat/cuda_runtime.h(+3 -0)📝
src/kernels/cuda/sampler.cu(+466 -4)📝
src/kernels/sampler_parity.cpp(+433 -2)📄 Description
First of the three packages from #149, rebased on 0.1.26 as asked. The grouped Q2_0 kernel and the IQ grid decode follow once #154 is through.
The sampled path (penalties, top_k, top_p, min_p, temperature, draw) kept one row on one SM.
sampler_kernelexcluded the logits already kept by sweeping the kept list for every logit of every round, which is O(k^2 x n_vocab) shared-memory compares per row, and it ran the double-precision tail on all 1,024 threads.What changes:
sampler_one_block_kernel: one block per row, each round takes the logits strictly after the previous pick in the selection order (value descending, id ascending). It is the fallback when the split cannot run (stream under graph capture, vocabulary above 262,144, more than 64 rows, no scratch).STRATA_SAMPLER_ONE_BLOCK=1forces it.sampler_kernelis unchanged and stays as the reference;STRATA_OLD_SAMPLER=1selects it.hip_compat/cuda_runtime.hmapscudaStreamIsCapturing,cudaStreamCaptureStatusandcudaStreamCaptureStatusNone, which the new capture check needs, sincesampler.cuis in the shared CUDA/HIPstrata_kernelslist.Default behaviour: the split path is new code, but the list, its order and the pick are the same by construction (the first k of a union lie within the first k of each part, and a merge of ordered lists is ordered). The tail keeps the same arithmetic, with exps and quotients shared across a warp and lane 0 running the ordered sums and scans.
Parity test:
sampler_parity(fixtures 16 to 18) pins the whole top_k list position by position under ties, with rows holding +inf, -inf, NaN, +0/-0, the id-0 sentinel and penalised tokens landing on other tokens' values, over vocabularies of 248,320, 100,003, 262,144, 262,145 and 1,000. It also checks tied draws through the whole chain and the automatic fallbacks (graph capture, row cap). Picks are token ids compared for equality with a host reference. ctest runs it once per path,sampler_parity,sampler_parity_one_blockandsampler_parity_old, so all three are held to the same expected ids.What I could and could not check: the commit applies on 0.1.26 without conflicts. I could not compile CUDA or HIP, or run
sampler_parityon a GPU, from where I am now; your gate is the check there, and I will add results from my RTX 5090 when I have them. On HIP,__syncwarpis used unmapped, as innative_flash_attn.cu; I have not built it with ROCm.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.