[PR #185] [CLOSED] sampler: the sampled path over 64 vocabulary chunks per token (identical picks, ~12% faster sampled decode) #2496

Closed
opened 2026-11-04 02:00:43 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/185
Author: @q8atnight
Created: 9/30/2026
Status: ❌ Closed

Base: main ← Head: pr/sampler-chunks


📝 Commits (1)

  • 6e2e315 sampler: the sampled path over 64 vocabulary chunks per token + a merge block (identical picks, ~3 ms less per sampled verify window)

📊 Changes

1 file changed (+203 additions, -2 deletions)

View changed files

📝 src/kernels/cuda/sampler.cu (+203 -2)

📄 Description

Summary

The sampled path in sampler.cu put ONE block per token over the 248,320-logit vocabulary and ran top_k (20) argmax
rounds, each a full scan with an inner "already taken?" loop: ~3 ms per sampled verify window on 3 of 82 SMs.
This splits the same selection into two kernels:

  • kernel 1: the vocabulary in 64 chunks per token, each chunk block keeps its own top-k (k rounds over its ~3,900
    values in shared memory, a taken value set to -inf)
  • kernel 2: one block per token merges the chunks' candidates with k more rounds, then runs the unchanged
    top_p / min_p / temperature / Philox chain, line for line

The global top-k in (value desc, index asc) order is the union of the chunks' top-k's, so the kept list - set AND
order - is exactly the serial one.

One commit on top of 0.1.27 (a790805); all four of my current branches were compile-tested together on 0.1.27.

Measured

Measured on 2x RTX 3090, IQ3_S, with the engine this was developed in (0.1.24 + the dual-GPU work): sampled decode
(temperature 0.7, top_p 0.95, top_k 20) at 1K context 102 -> 114 tok/s; about 3 ms less per sampled verify window.
Greedy is unaffected (it does not go through this path).

Correctness

STRATA_SAMPLER_CHECK=1 runs the old one-block kernel beside the new one and compares every pick:
1,001 of 1,001 identical.

Switch

STRATA_SAMPLER_FAST=0 = the old one-block kernel.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/185 **Author:** [@q8atnight](https://github.com/q8atnight) **Created:** 9/30/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/sampler-chunks` --- ### 📝 Commits (1) - [`6e2e315`](https://github.com/Niko1221/Strata/commit/6e2e3158a661a67eb4ee9b3b268ad24f28fa95c7) sampler: the sampled path over 64 vocabulary chunks per token + a merge block (identical picks, ~3 ms less per sampled verify window) ### 📊 Changes **1 file changed** (+203 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `src/kernels/cuda/sampler.cu` (+203 -2) </details> ### 📄 Description ## Summary The sampled path in `sampler.cu` put ONE block per token over the 248,320-logit vocabulary and ran top_k (20) argmax rounds, each a full scan with an inner "already taken?" loop: ~3 ms per sampled verify window on 3 of 82 SMs. This splits the same selection into two kernels: - kernel 1: the vocabulary in 64 chunks per token, each chunk block keeps its own top-k (k rounds over its ~3,900 values in shared memory, a taken value set to -inf) - kernel 2: one block per token merges the chunks' candidates with k more rounds, then runs the unchanged top_p / min_p / temperature / Philox chain, line for line The global top-k in (value desc, index asc) order is the union of the chunks' top-k's, so the kept list - set AND order - is exactly the serial one. One commit on top of 0.1.27 (a790805); all four of my current branches were compile-tested together on 0.1.27. ## Measured Measured on 2x RTX 3090, IQ3_S, with the engine this was developed in (0.1.24 + the dual-GPU work): sampled decode (temperature 0.7, top_p 0.95, top_k 20) at 1K context 102 -> 114 tok/s; about 3 ms less per sampled verify window. Greedy is unaffected (it does not go through this path). ## Correctness `STRATA_SAMPLER_CHECK=1` runs the old one-block kernel beside the new one and compares every pick: 1,001 of 1,001 identical. ## Switch `STRATA_SAMPLER_FAST=0` = the old one-block kernel. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-04 02:00:43 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#2496
No description provided.