Skip to content

GLM CUDA: gather and sample shared verification windows together - #4698

Draft
MaverickKB wants to merge 1 commit into
ashhart:mainfrom
MaverickKB:codex/glm-sampled-verification-windows
Draft

MaverickKB wants to merge 1 commit into
ashhart:mainfrom
MaverickKB:codex/glm-sampled-verification-windows

Conversation

@MaverickKB

Copy link
Copy Markdown
Contributor

What this changes

GLM CUDA already runs the target forward for several verification windows together. It then gathers the vocabulary shards, samples, synchronizes and reads tokens back separately for each window. This change gathers all rows once when every window in the step is sampled and the step has no grammar masks. Each row carries its own sequence's sampling rule and absolute position. The existing CUDA row sampler can split the vocabulary into 8,192-entry slices. Its scratch reuses the gather staging buffer after the strided copies on the same stream.

Ordinary single-stream top-k sampling also uses the row sampler. Grammar draws and single-stream unrestricted-vocabulary draws retain the previous call. Mixed greedy/sampled windows continue selecting each window separately. The patch changes no CUDA kernel or draft-acceptance rule.

  • Issue: n/a. This ports shipped sampling kernels to an existing target-verification path.
  • Stacked on: main at 95ae4081770ff36fc83d16a5be7d166bdee005fa.
  • Head: 92073e9f1ff614d4853e6e6201a8f6c3c645faef.

Device receipt

A checkpoint-free, single-GPU driver fixture used the actual GLM vocabulary width of 154,880, BF16 logits, temperature 0.7, top-p 1 and top-k 20. Each sample included metadata upload, draw, stream synchronization and token download. The interval started with full logits already on the GPU. The legacy column runs one draw and one readback per stream. The other columns use the same input rows, with each stream's seed and absolute position keyed separately. The table gives the median of 16 timed repetitions after two warmups, rotating variant order each repetition.

Verification rows per stream Legacy per-stream draw Packed row draw Packed sliced draw
8 185.8 µs 188.4 µs 72.7 µs
4 + 5 369.9 µs 188.3 µs 72.6 µs
8 + 8 369.6 µs 188.5 µs 98.9 µs
4 each across 4 streams 735.3 µs 188.4 µs 99.8 µs
4 each across 8 streams 1,471.7 µs 189.7 µs 153.9 µs

Both kernel variants matched the legacy token ID on all 2,580 checked rows. The checks included broad, peaked, tied and partially masked logits, independent seeds and positions, mixed top-k rules, top-p/min-p, and fallback outside the sliced kernels' supported top-k range. Device: NVIDIA GB10, SM121, Linux aarch64, driver 580.178.04. The same sample.fatbin was used for all three variants (SHA-256 58b81ee0c449be7a1aa6976f1a31f37b3e2e5a1678bbc53cd29931c969556b19).

The new regression is part of the existing tf-cuda-test sample entrypoint. I ran its GLM case independently on the GB10. It invokes the actual GLM Zig adapter, splits each vocabulary across two locally emulated shards, gathers three rows from one window and five from a second, and compares all 32 picks over four distributions against the two serial draws. It passed with both per-window temperatures and top-k rules active.

Checks and remaining gates

  • Zig 0.17.0, zig build test-glm-logprobs-host test-glm-structured-host compile-glm-native-open --summary all: 15 tests passed. The host coverage includes per-sequence row keys and the existing NCCL recording interposer for two ranks and uneven three-rank vocabulary splits.
  • zig fmt --check on all touched Zig files and git diff --check passed. The repository lean checker found 165 inherited findings on both main and head, zero new.
  • NCCL traffic, target-forward time, end-to-end decode, full model output hashes, cold prefill, and resumed versus fresh conversations were outside the microbenchmark. The outstanding acceptance run is same-checkpoint main/head with one and the widest admitted streams, comparing draft/plain, solo/concurrent hashes, output throughput and cold TTFT.
  • New flags, weights, and precision changes: none. Upstream CI and full host/device matrices remain pending on this draft.

Coordination

atc overlap --json reported capped coverage and seven file overlaps. A paginated GitHub check covered 401 open PRs and 46 that shared paths, with 57 per-file three-way comparisons on each PR's merge base. The separate source comparisons found these integration points:

@joshuaswarren

Copy link
Copy Markdown
Contributor

sm_120 cross-check (RTX 5060 Ti, live), head 92073e9f, nvcc 13.5:

  • tf-cuda-test sample: PASS - 2880 draws equal host references, pitched proposal 54 cases equal, and 'GLM shared sampled windows match serial draws' - your new regression is green on sm_120 too, not just SM121
  • tf-cuda-test kernel-contract sample: 2/2 kernels pass gates 1-4, 2 limit problems - both the known nvcc-13.5-vs-13.3 record drift (d3_sample_code 37r vs 39, tf_logprob_rows 43r/520B vs 40/520); all launches within driver limits

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.

2 participants