[PR #1281] [CLOSED] sampler: coupled drafts with Gumbel-max picks (STRATA_SPEC_GUMBEL=1, opt-in): +7 points draft acceptance, +9% output at temperature 1.0 on Strix Halo #3356

Closed
opened 2026-11-07 14:40:54 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/1281
Author: @routhjim
Created: 10/6/2026
Status: ❌ Closed

Base: main ← Head: gumbel-coupled


📝 Commits (3)

  • 0b597a7 sampler: Gumbel-max coupled drafts (STRATA_SPEC_GUMBEL=1, opt-in)
  • 3787d0c docs: coupled drafts with Gumbel-max picks (STRATA_SPEC_GUMBEL), measured on Strix Halo
  • 6c5715d docs: the coupled-draft measurement is the single-request path; --batch slot drafters do not couple (#1281 review)

📊 Changes

5 files changed (+183 additions, -17 deletions)

View changed files

📝 docs/DETAILS.md (+16 -0)
📝 include/strata/core/coupled_draft.hpp (+5 -0)
📝 include/strata/kernels/sampler.hpp (+1 -0)
📝 src/kernels/cuda/sampler.cu (+60 -15)
📝 src/kernels/sampler_parity.cpp (+101 -2)

📄 Description

Under sampling, STRATA_SPEC_COUPLED=1 makes the draft layer sample its guess with the target's chain and the target's Philox draw. Both sides then pick by walking one uniform over their own candidates sorted by probability. When the draft's top_k / top_p list differs from the target's by even one token, every later interval shifts, and the two picks land on different tokens even where the distributions mostly agree.

This PR adds an opt-in Gumbel-max pick that does not have that problem. With STRATA_SPEC_GUMBEL=1 both the target and the coupled draft pick argmax_i p_i / E_i, where E_i ~ Exp(1) comes from a hash of (seed, counter, token id). That is exactly argmax(log p_i + Gumbel_i), so it is still an exact sample of p. A token gets the same noise in the draft's draw and in the target's, whichever other tokens survived either cut, so the two agree on the tokens they share. Verification is still exact-match against the target's pick: the text is a sample from the same distribution as before, and only the number of accepted drafts changes.

What changes

  • src/kernels/cuda/sampler.cu:
    • gumbel_exp(seed, counter, token) (splitmix64 to Exp(1)).
    • The Gumbel pick in both tails: sampler_kernel and sampled_tail_warp, which serves the split, one-block and coupled-draft paths.
    • The coupled draft keys its noise by the real token id through sub_to_id, so the draft-vocab subset does not break the coupling.
  • include/strata/kernels/sampler.hpp: SamplerParams::gumbel. It sits in the struct's existing padding, so sizeof is unchanged (64 bytes).
  • STRATA_SPEC_GUMBEL=1 is read once on the host. sample_tokens applies it to the target's pick, and coupled_stage_kernel writes it into the drafter's device copy of the params, so the captured round graphs see it.
  • Off by default: without the variable nothing changes, and greedy requests never read it.
  • sampler_parity: three new checks, run on all three sampled paths by the existing ctest entries:
    • the kernel's Gumbel pick equals a host reference draw for draw, under three chains (top_k/top_p, temperature only, and with min_p): 0 of 48 differ;
    • pick frequencies match the softmax over 10,240 draws (total variation 0.0098);
    • the flag is really read (2 of 16 sampled picks coincide with the inverse-CDF ones), and greedy output is unchanged.
  • Docs: a paragraph in docs/DETAILS.md next to the other opt-in switches, and a note in include/strata/core/coupled_draft.hpp.

Measured on a Ryzen AI Max+ 395 (Radeon 8060S, gfx1151, 128 GB, Linux 7.2, ROCm 7.14.1, the iGPU alone).

  • Setup: 82f46a8 plus this PR, built per docs/STRIX_HALO.md with the section-4 defaults and STRATA_PF_FUSED_KQ=1, Unsloth UD-Q4_K_XL, --mmap-experts --expert-cache auto --spec 4 --mtp mtp/rt --lookup-chain 3 --kv int8 (the base model's draft layer, Q2_0 experts).
  • Requests: temperature 1.0, top_p 0.95, top_k 20, thinking off, a 1.3K-token prompt with a fresh prefix each time, 512 output tokens.
  • Counts come from the /metrics totals around each request; timings from STRATA_DECODE_TIMING=1.
arm requests drafts accepted accepted tokens / request tokens per window ms per window (draft) output tok/s
STRATA_SPEC_COUPLED off (default) 12 52.8% 318 2.65 63.6 (8.8) 41.1 ± 0.8
STRATA_SPEC_COUPLED=1 STRATA_SPEC_GUMBEL=1 13 59.9% 336 2.88 64.3 (9.1) 44.9 ± 0.6

A window costs the same: drafting by sampling adds about 0.3 ms of 64. The gain is entirely more tokens per verify window. ± is the standard error over the requests.

Output stays an exact sample: with the switches on, three seeds give three different texts, and the same seed twice gives the same text.

Not tested:

  • the CUDA build (I have no NVIDIA card), Windows, and other AMD cards;
  • --batch-mtp slot drafters;
  • STRATA_SPEC_COUPLED=1 on its own with this draft layer: on this box with a different draft head it measured slightly below the default (one arm, within noise), so it is not claimed either way.

Measured with the help of Claude (Anthropic).

🤖 Generated with Claude Code


🔄 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/1281 **Author:** [@routhjim](https://github.com/routhjim) **Created:** 10/6/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `gumbel-coupled` --- ### 📝 Commits (3) - [`0b597a7`](https://github.com/Niko1221/Strata/commit/0b597a7448e8cb885361503d1ce2be8706546050) sampler: Gumbel-max coupled drafts (STRATA_SPEC_GUMBEL=1, opt-in) - [`3787d0c`](https://github.com/Niko1221/Strata/commit/3787d0ce7ffe900909f672944b7ea1eae35713bd) docs: coupled drafts with Gumbel-max picks (STRATA_SPEC_GUMBEL), measured on Strix Halo - [`6c5715d`](https://github.com/Niko1221/Strata/commit/6c5715df488df36bac23a73da99398ef4f15558d) docs: the coupled-draft measurement is the single-request path; --batch slot drafters do not couple (#1281 review) ### 📊 Changes **5 files changed** (+183 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+16 -0) 📝 `include/strata/core/coupled_draft.hpp` (+5 -0) 📝 `include/strata/kernels/sampler.hpp` (+1 -0) 📝 `src/kernels/cuda/sampler.cu` (+60 -15) 📝 `src/kernels/sampler_parity.cpp` (+101 -2) </details> ### 📄 Description Under sampling, `STRATA_SPEC_COUPLED=1` makes the draft layer sample its guess with the target's chain and the target's Philox draw. Both sides then pick by walking one uniform over their own candidates sorted by probability. When the draft's top_k / top_p list differs from the target's by even one token, every later interval shifts, and the two picks land on different tokens even where the distributions mostly agree. This PR adds an opt-in Gumbel-max pick that does not have that problem. With `STRATA_SPEC_GUMBEL=1` both the target and the coupled draft pick argmax_i p_i / E_i, where E_i ~ Exp(1) comes from a hash of (seed, counter, **token id**). That is exactly argmax(log p_i + Gumbel_i), so it is still an exact sample of p. A token gets the same noise in the draft's draw and in the target's, whichever other tokens survived either cut, so the two agree on the tokens they share. Verification is still exact-match against the target's pick: the text is a sample from the same distribution as before, and only the number of accepted drafts changes. **What changes** - `src/kernels/cuda/sampler.cu`: - `gumbel_exp(seed, counter, token)` (splitmix64 to Exp(1)). - The Gumbel pick in both tails: `sampler_kernel` and `sampled_tail_warp`, which serves the split, one-block and coupled-draft paths. - The coupled draft keys its noise by the real token id through `sub_to_id`, so the draft-vocab subset does not break the coupling. - `include/strata/kernels/sampler.hpp`: `SamplerParams::gumbel`. It sits in the struct's existing padding, so `sizeof` is unchanged (64 bytes). - `STRATA_SPEC_GUMBEL=1` is read once on the host. `sample_tokens` applies it to the target's pick, and `coupled_stage_kernel` writes it into the drafter's device copy of the params, so the captured round graphs see it. - **Off by default:** without the variable nothing changes, and greedy requests never read it. - `sampler_parity`: three new checks, run on all three sampled paths by the existing ctest entries: - the kernel's Gumbel pick equals a host reference draw for draw, under three chains (top_k/top_p, temperature only, and with min_p): 0 of 48 differ; - pick frequencies match the softmax over 10,240 draws (total variation 0.0098); - the flag is really read (2 of 16 sampled picks coincide with the inverse-CDF ones), and greedy output is unchanged. - Docs: a paragraph in `docs/DETAILS.md` next to the other opt-in switches, and a note in `include/strata/core/coupled_draft.hpp`. **Measured** on a Ryzen AI Max+ 395 (Radeon 8060S, gfx1151, 128 GB, Linux 7.2, ROCm 7.14.1, the iGPU alone). - Setup: 82f46a8 plus this PR, built per `docs/STRIX_HALO.md` with the section-4 defaults and `STRATA_PF_FUSED_KQ=1`, Unsloth UD-Q4_K_XL, `--mmap-experts --expert-cache auto --spec 4 --mtp mtp/rt --lookup-chain 3 --kv int8` (the base model's draft layer, Q2_0 experts). - Requests: temperature 1.0, top_p 0.95, top_k 20, thinking off, a 1.3K-token prompt with a fresh prefix each time, 512 output tokens. - Counts come from the `/metrics` totals around each request; timings from `STRATA_DECODE_TIMING=1`. | arm | requests | drafts accepted | accepted tokens / request | tokens per window | ms per window (draft) | output tok/s | |---|---:|---:|---:|---:|---:|---:| | `STRATA_SPEC_COUPLED` off (default) | 12 | 52.8% | 318 | 2.65 | 63.6 (8.8) | 41.1 ± 0.8 | | `STRATA_SPEC_COUPLED=1 STRATA_SPEC_GUMBEL=1` | 13 | **59.9%** | **336** | **2.88** | 64.3 (9.1) | **44.9 ± 0.6** | A window costs the same: drafting by sampling adds about 0.3 ms of 64. The gain is entirely more tokens per verify window. ± is the standard error over the requests. Output stays an exact sample: with the switches on, three seeds give three different texts, and the same seed twice gives the same text. **Not tested:** - the CUDA build (I have no NVIDIA card), Windows, and other AMD cards; - `--batch-mtp` slot drafters; - `STRATA_SPEC_COUPLED=1` on its own with this draft layer: on this box with a different draft head it measured slightly below the default (one arm, within noise), so it is not claimed either way. Measured with the help of Claude (Anthropic). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 14:40:54 +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#3356
No description provided.