Skip to content

cuda: radix-search nucleus extension (#3713) - #4691

Open
tacosta wants to merge 1 commit into
ashhart:mainfrom
tacosta:feat/3713-cuda-nucleus-extension
Open

tacosta wants to merge 1 commit into
ashhart:mainfrom
tacosta:feat/3713-cuda-nucleus-extension

Conversation

@tacosta

@tacosta tacosta commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

The CUDA full-row nucleus sampler finds its top-p boundary with four-bit radix probes instead of one-bit key and token-ID probes. For the 131,072-element flat-BF16 fixture at top-p 0.95, the search uses 13 full-row probes (8 key digits and 5 ID digits), down from 50.

Checks on this head

  • Head: d978250ff26c49a0b43c27e206b88ceeb0a38f4f, one commit on qualification base a3c3e5cef303646c7b73587262d834dbd155c6d5. Review patch SHA-256: 2d072eadb2e8398983edd2e8865e317e1d6836566d69c5ef4e924eeff06ea4e8.
  • The local branch was rebased onto main before qualification. At the post-push reread, GitHub reported main at 0a5c699c891201df4162ba23f938ef4027aaa939; the evidence below remains measured on base a3c3e5ce.
  • Lean checker via tools/pr_check.py: 164 base / 164 head, 0 new findings. PR preflight: 0 errors, 1 advisory warning (no Unreleased bullet naming this PR).
  • On this head, zig fmt --check build.zig zig, git diff --check, zig build -j1 -Dfixed-cpu test-gradient-serving test-kernel-contract compile-cuda-tests passed. The CUDA runner was compile-only; no GPU test ran. Host output included UNSUPPORTED/N/A architecture coverage and internal failed command diagnostics, while the focused command exited 0.
  • A broader zig build -j2 -Dfixed-cpu test test-golden test-cuda-host compile-cuda-tests attempt did not finish: the test-cuda-host compilation hit NoSpaceLeft and the Zig compiler aborted. The test-golden step reported 327/340 equal, 0 unexpected differences and 13 known differences. This is not a full-suite pass; see the attached failed-run log.
  • Independent trial merge of d978250f into 9961ca49 reported 325 host checks passing on M5 Max and the ARM64 Linux CUDA test runner cross-compiling in 12/12 steps. No CUDA device test ran in that report.
  • Hosted CI on this head: Zig format passed; No GPU remained queued at the latest reread. No result is claimed for the queued workflow.

Receipt

  • Main against branch: the local A-B-B-A sample-kernel benchmark below compares main at ef4d6429 with the PR kernel on the same RTX 5090 Laptop GPU. The baseline sampler source is unchanged between ef4d6429 and current main a3c3e5ce. No model checkpoint or end-to-end decode receipt was used.

  • Boxes it reaches: CUDA full-row draws when top_k is 0 or above 1024 and 0 < top_p < 1; the extension runs when the initial candidate block's sequential mass does not reach top_p. The small-top_k route remains a control.

  • New switch: none. Common defaults in family_sampling.zig bypass the extension: DeepSeek V4.x uses top_p=1.0 with no top_k; Qwen instruct uses top_k=20, top_p=0.8. Both have a 0% extension rate at those defaults. The repository has no production request trace, so actual rates for user overrides are unknown.

  • Environment: timing base ef4d6429, timing head caf10040; final rebase base a3c3e5ce, final head d978250f; Zig 0.17.0; CUDA/NVCC 13.3.73; Linux x86_64; RTX 5090 Laptop GPU (SM120), driver 595.99.02. No checkpoint.

  • Paths and platforms: local host build and runner compile on Linux x86_64; CUDA timing on SM120. Maintainer live correctness is separately reported on RTX 5060 Ti (SM120). No local GB10/SM121 run; Metal and HIP are unchanged and untested.

  • Exactness: maintainer report on earlier head a2b8ca6c says tf-cuda-test sample passed 2,880 draws against Metal-rule host references (hash 0xc0672952ba6888cd), the pitched proposal passed 54 keyed/full cases with matching IDs and probability bits, and sample-adversarial passed 7/7 cases. These checks were not repeated on this rebased head. The current adversarial test prints per-case probability bits but checks them against the f64 host reference with a tolerance; an exact old/new bit comparison remains pending.

  • Main against this branch, same machine and checkpoint: no checkpoint decode run; the local kernel benchmark uses identical synthetic rows and hardware for both kernels.

  • Decode speed: A-B-B-A order was main, PR, PR, main. Each sample-bench result is the median of 11 timed repetitions; values below average the two A passes and two B passes and average regular/pitched paths:

    Synthetic row Main k=0, p=.95 PR k=0, p=.95 Change
    Flat 408.0 us/row 275.1 us/row 32.6% lower
    Spread 464.7 us/row 273.2 us/row 41.2% lower
    Peaked 463.8 us/row 273.0 us/row 41.1% lower

    The timing runner used head caf10040 before the dispatch-only relocation. A post-rebase comparison of sampler/test paths shows identical kernel, benchmark and test implementation sources; only the two dispatch lines moved in zig/tests/cuda/main.zig. Main's sampler source is unchanged between timing base ef4d6429 and rebased main a3c3e5ce. Timings were not rerun on the rebased head. The top_k=0, top_p=1.0 control stayed around 15 us/row. The small-top_k=20, top_p=.95 control remained near baseline (about 30, 20 and 8 us/row for flat, spread and peaked rows). These are synthetic sampler timings, not served-decode speedups.

  • Prompt speed: n/a; this decode sampler change does not touch prompt processing.

  • Licence of any new weights or drafter: n/a; none are added.

Kernel contract
  • No new launch symbol; existing CUDA sample entry points use the changed full-row search. The local sample-bench run measured timing only, not a live kernel-contract summary.
  • Maintainer SM120 kernel-contract run reported 2/2 kernels passing gates 1–4 and 0 missed controls, plus five recorded-limit discrepancies while compiling with NVCC 13.5 against NVCC 13.3 records: tf_draw and tf_draw_pitched were 64 registers/9,752 bytes vs recorded 64/10,776; tf_logprob_rows was 43/520 vs 40/520; d3_sample_code used 37 registers vs recorded 39. All tested launches were within driver limits; contract exit 1 reflected the mismatch count. Awaiting maintainer instructions before changing records.
  • GB10/SM121 contract, parity and occupancy evidence remain pending from the maintainer. Preserve the full resource-contract output, including every RECORD, mismatch and SUMMARY line; the previous SM120 receipt is not a substitute.

Maintainer GPU checks

Maintainer-reported RTX 5060 Ti (SM120) sampler and adversarial checks passed on earlier head a2b8ca6c as described above. The NVCC 13.5 vs 13.3 resource-record discrepancies remain unchanged while we await maintainer guidance. GB10/SM121 parity, exact old/new probability-bit comparison, contract and occupancy checks remain pending.

Requested hardware validation

Please qualify the integrated PR head on GB10 (SM121), using the same NVCC version, driver and test fixtures for the pre-change main baseline and candidate:

  1. Run tf-cuda-test sample and tf-cuda-test sample-adversarial on both versions. Apply only the PR's test-harness changes to the baseline so both runs emit the same records. Keep the full logs and compare RESULT sample identity-hash plus all seven RESULT sample-adversarial ... probability_bits lines exactly. The f64 host-reference tolerance is a separate check and does not establish old/new bit identity.
  2. Record nvcc --version and the full output and exit status from zig build kernel-contract -Dnvcc=PATH, zig build fatbins kernel-contract-fatbins -Dnvcc=PATH -Dsm=121, zig-out/bin/tf-cuda-test kernel-contract-limits zig-out/fatbin and zig-out/bin/tf-cuda-test kernel-contract sample. Preserve every RECORD, mismatch and SUMMARY line. The existing SM120 run has five NVCC 13.5 versus 13.3 resource-record discrepancies; leave records unchanged pending maintainer guidance.
  3. Keep synthetic sampler timings separate from served-decode performance claims.

The previous RTX 5060 Ti results are useful SM120 evidence but were collected on earlier head a2b8ca6c. Current main's sampler kernel and test-harness files are unchanged since the qualification base. A local test-only backport patch and command recipe are available for the baseline comparison; no GB10 result is claimed here.

Checklist

  • Title and description match the single behavior and link issue CUDA nucleus extension can traverse the whole vocabulary 50 times for one broad row #3713.
  • New CUDA tests fail before the change and pass on a maintainer GPU; maintainer results are reported above, detailed red/green receipt pending.
  • Comments/docstrings remain one line; no measurements or history were added to source.
  • No personal data, local paths, internal hosts or AI attribution in the source diff or commit.
  • Local compile and synthetic SM120 timing evidence recorded; maintainer parity and resource-record guidance remain pending.

@tacosta
tacosta force-pushed the feat/3713-cuda-nucleus-extension branch from efd3f4b to a2b8ca6 Compare November 23, 2026 20:22
@tacosta

tacosta commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @ashhart, CI follow-up: I updated the serving identity fixture for the changed sample.cu and new sample_nucleus.cuh, with GB10 runtime qualification still pending. The focused test-gradient-serving host check passes locally (LocalATC job job_20261123_201450_c303aa). This is included in single commit a2b8ca6; hosted checks are rerunning. CUDA parity and performance remain for maintainer GB10.

@joshuaswarren

Copy link
Copy Markdown
Contributor

Live-GPU run on RTX 5060 Ti (sm_120), head a2b8ca6c, nvcc 13.5 - the runs the PR asks for:

  • tf-cuda-test sample: PASS - 2880 draws equal the Metal rule's host references (identity-hash 0xc0672952ba6888cd); pitched proposal: 54 keyed+full cases equal contiguous IDs and probability bits
  • tf-cuda-test sample-adversarial: PASS - 7/7 boundary cases equal the host reference (flat/spread v248320, mapped v32768, k0/k1500, pitched+unpitched)
  • tf-cuda-test kernel-contract sample: 2/2 kernels pass gates 1-4, 0 controls missed - 5 limit problems: small record drift, not the 0,0 gap. Live values vs sm_120 records: tf_draw 64r/9752B vs 64/10776, tf_draw_pitched same, tf_logprob_rows 43r/520B vs 40/520, d3_sample_code 37 regs vs recorded 39. Kernel launches within driver limits in every case; the records look stale against nvcc 13.5 codegen (built by 13.5, checked vs 13.3's records)

All three runs real on the card; rc=1 on the contract is the limits count.

@tacosta
tacosta force-pushed the feat/3713-cuda-nucleus-extension branch 2 times, most recently from 864865e to 5a5f883 Compare November 24, 2026 20:04
@tacosta

tacosta commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto upstream main at 3942d68 as 5a5f883. The focused CPU-only host checks passed; CI for the new head is pending. GPU/resource-record follow-up is awaiting maintainer guidance.

@tacosta
tacosta force-pushed the feat/3713-cuda-nucleus-extension branch from 5a5f883 to d978250 Compare November 25, 2026 12:00
@tacosta
tacosta marked this pull request as ready for review November 25, 2026 12:12
@AIFlowML

Copy link
Copy Markdown
Contributor

I trial-merged d978250ff2 cleanly into 9961ca492. All 325 host checks passed on M5 Max, and the ARM64 Linux CUDA test runner cross-compiled in 12/12 steps.

zig build test-gradient-serving test-kernel-contract -Dfixed-cpu -j2 --summary all
zig build compile-cuda-tests -Dtarget=aarch64-linux-gnu -Dfixed-cpu -j2 --summary all

The sampler kernel, nucleus helper, two local headers and both sampler fixture files match a2b8ca6c20, the revision in the earlier RTX 5060 Ti report. The remaining device check is on GB10/SM121 at the integrated head: run tf-cuda-test sample, tf-cuda-test sample-adversarial and tf-cuda-test kernel-contract sample, and record the NVCC version beside the resource counts. That will let reviewers compare like-for-like with the 13.3 resource records. I did not run a CUDA device test here.

Igor Lessio - AIFLOW LABS

@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thanks @tacosta. Each candidate cut keeps the previous addition and reduction order, and the keyed draw and tie handling remain unchanged in source. This is ready for a controlled comparison, with final numerical and resource qualification still open.

The new adversarial test checks token IDs exactly but allows a probability tolerance. Please retain exact old/new probability-bit comparisons in the qualification results, and include the full compiler resource-contract output: the supplied older run still has five limit failures. The synthetic timing results should stay separate from serving performance claims.

  • Synthena

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants