Repository navigation
Conversation
There was a problem hiding this comment.
Thanks for the careful PR. The writeup is unusually honest about its limits, and the opt-in design keeps the default path safe. I tested it on a GB300 (sm_103, CUDA 13.1). The base tree needs conan 1.x and x86 NCCL, so I couldn't build the full engine there. Instead I built the R2S-K selector and the in-tree RadiK on their own with nvcc and compared them directly.
Correctness: looks solid
cpp_r2sk_sampling_testpasses. compute-sanitizer memcheck, racecheck, synccheck and initcheck all report 0 errors.- I compared it against a CPU reference with randomized inputs: 544 cases and 2.1M outputs. Vocab sizes ran from 3 to 248,320, batch from 1 to 255 and k from 2 to 256. Inputs included tie-heavy rows, all-equal rows, mixed ±0, outliers and values near the largest finite negative. There were 0 mismatches and 0 unexpected fallbacks, and the input was never modified.
Performance (GB300, median host µs per call, including the stream sync)
| vocab | batch | k=20 | k=50 | k=256 |
|---|---|---|---|---|
| 151,936 | 1 | +18 to +22% | +5 to +19% | −16% to +10% |
| 151,936 | 16 | +11 to +12% | +11% | −13% to +1% |
| 151,936 | 64 | +17% | +16 to +17% | −16% to +4% |
| 151,936 | 256 | +18 to +21% | +19 to +21% | +5 to +13% |
| 248,320 | 1 to 256 | +7 to +28% | +5 to +24% | +3 to +23% |
Positive numbers mean R2S-K is faster. The negative cells are Gaussian logits at k=256. Scratch is about 1.5× RadiK's at every shape, for example 776 MB against 513 MB at batch 256 and vocab 248,320.
Concerns before merging
- CUDA graphs.
Try()declines whenever the stream is capturing. The batch driver also synchronizes the stream several times per call to read decisions and counters back to the host (r2sk.cu:671,:702), and it creates its own stream. Decode sampling is moving toward graph capture, where this backend would never dispatch. Could the per-pass decisions stay on the device, for example with a fixed number of passes or device-side scheduling, so that it can be captured? - End-to-end benefit. The reported gain is 0.88% at batch 16 and flat at batch 1, on one model and one GPU. Answer-quality equivalence is unverified. Numbers on a larger model or on Hopper/Blackwell would help, ideally with a quality check under top-k/top-p sampling.
- Slower at large k. k=256 is 13–16% slower in the cases above. Please consider a dispatch threshold on k, or explain the cause.
- No CI coverage. The CMake option defaults to OFF, and the test is only built when it is ON, so CI never compiles or runs this code. Please add at least one CI configuration that builds with
ENABLE_R2SK_SAMPLING=ONand runscpp_r2sk_sampling_test. - Code style.
r2sk.cu(844 lines) and the headers are written as dense one-statement-per-line code. Please reformat to the project's clang-format style. That would make long-term maintenance and review practical.
Minor
RunSamplenow wraps the launcher inAS_CHECK_STATUS, which changes default-build behavior. For example,max_k > lengthused to log and continue, and now it returns an error. That seems like a good fix, but please call it out in the description.- Licensing: only
sampling.cu/.hcarry an SPDX header.r2sk.cuand the sixr2sk/*.hppheaders have no license or copyright notice. Please add SPDX headers to every new file (the RadiK-derived parts are already credited viaLICENSE.RadiK). - Provenance: is R2S-K derived from a separate project or publication? If so, please link it and state its license.
Happy to re-test on GB300 once these are addressed.
|
Hi @kzjeef, thanks for the careful review and the GB300 measurements. Here’s where the updates stand.
The PR description calls out the R2S-K comes from my private If you have time to retest on GB300, a check that |
|
Hi @kzjeef, I explored few other ideas and have an update on the large-k regression. The opt-in eager backend now uses the BF16 device controller through k=256, replacing the earlier host-controlled path and its k=50 cutoff. It launches on the regular CUDA stream and reads the fused finite-input flag during DashInfer's existing synchronization. The sampler graph remains a separate opt-in. Implementation (SiraajR@b65f08d) |
Summary
Add an opt-in BF16 R2S-K backend for token sampling. It preserves confirmed winners during radix refinement and can finish by sorting a small candidate superset. It uses DashInfer's shared top-k/top-p arena and returns descending BF16 scores with row-relative token IDs.
Both opt-ins default to off. Enable the build with
ENABLE_R2SK_SAMPLING=ONand the runtime withAS_ENABLE_R2SK_SAMPLING=1. The backend supports Ampere and newer GPUs, finite BF16 logits, and2 <= k <= 256withk < vocabulary. Unsupported inputs use the existing sampling paths. Equal BF16 scores can select different valid token IDs at the cutoff.Sampling error handling.
RunSamplenow propagates errors returned by the sampling launcher throughAS_CHECK_STATUS, including when R2S-K is disabled. For example, whenmax_kexceeds the vocabulary size,RunSamplenow returns the launcher error. Previously the launcher logged the error andRunSamplecontinued.Results on NVIDIA L40S
Both selectors used the same DashInfer checkout, CUDA 12.4.131, and BF16 logits captured from Qwen2.5-1.5B-Instruct. Vocabulary was 151,936 and k was 20. Each shape used one real capture, with 101 measured calls per backend after 10 warmups. Both outputs passed an exact CPU reference for sorted values and input occurrence indices.
The selector requires about 52% more scratch on these shapes. The shared engine arena was 63,205,712 bytes in both arms at configured maximum batch 16 because the top-p scratch reservation already covered the larger requirement.
A separate source-built Qwen benchmark measured request submission through completion, including prefill, decode and sampling. It used 20 timed cohorts per arm and batch size across four paired process blocks, with 96 output tokens per request. Prefix caching and early stopping were disabled to match work, and dispatch tracing was off during timing.
Batch 1 was effectively even. Batch 16 median latency was 0.88% lower, with all four paired block medians favoring R2S-K. These are results for one checkpoint and GPU. Answer-quality equivalence remains unverified.
Validation
ALLSPARK_DISABLE_WARMUP=1in both arms after default warm-up left insufficient allocator memory for the RadiK arm's log-probability buffer.Reproduction
See the build, correctness, and replay guide. The build was tested against upstream
06669fa30816f828c53ea144a7a9ac01507df5b5.AS_BUILD_R2SK_SAMPLING=ON AS_CUDA_VERSION=12.4 AS_CUDA_SM=89 bash build.sh ctest --test-dir build -R '^cpp_r2sk_sampling_test$' --output-on-failure