[PR #109] [MERGED] decode: batch the verify window's per-token kernels (bit-identical, +~10% decode) #2459

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/109
Author: @q8atnight
Created: 9/29/2026
Status: ✅ Merged
Merged: 9/29/2026
Merged by: @Niko1221

Base: main ← Head: pr/decode-batch


📝 Commits (1)

  • 1e4515c decode: batch the verify window's per-token kernels (bit-identical); skip the PCIe path with --pcie-frac 0; decode timing/profile switches

📊 Changes

16 files changed (+387 additions, -10 deletions)

View changed files

📝 include/strata/core/verify.hpp (+13 -0)
📝 include/strata/kernels/bf16_gemv.hpp (+4 -0)
📝 include/strata/kernels/elementwise.hpp (+4 -0)
📝 include/strata/kernels/fused_gr.hpp (+2 -1)
📝 include/strata/kernels/native_moe.hpp (+3 -0)
📝 include/strata/kernels/native_router.hpp (+2 -0)
📝 include/strata/kernels/verify_kernels.hpp (+2 -0)
📝 src/core/verify.cpp (+173 -8)
📝 src/kernels/cuda/elementwise.cu (+31 -0)
📝 src/kernels/cuda/fused_gr.cu (+5 -1)
📝 src/kernels/cuda/native_bf16.cu (+68 -0)
📝 src/kernels/cuda/native_moe.cu (+12 -0)
📝 src/kernels/cuda/native_router.cu (+10 -0)
📝 src/kernels/cuda/shared_expert.cu (+8 -0)
📝 src/kernels/cuda/verify_kernels.cu (+10 -0)
📝 src/program/generate.cpp (+40 -0)

📄 Description

What

The verify window's graph launched a few hundred tiny kernels per window token (≈450 extra graph nodes per token;
the window is launch-latency bound: ~3-5 µs per small kernel). This batches them over the window's rows, keeping every
row's arithmetic identical to the single-token call (outputs bit-identical):

  • router: one bf16_gemv_fp32_mmvf_multi (reads the 2.6 MB weight once, per-token accumulators in exactly the
    single-row order) + one multi-row top-10 launch (the kernel takes blockIdx.x = token)
  • shared expert's scalar gate: one multi-row GEMV + one sigmoid launch
  • bf16 cast of the window's rows: one call (the rows are contiguous)
  • MoE combine: one launch (blockIdx.y = token)
  • QSA layers: the indexer-key / indexer-query GEMVs, K / Q / indexer-query norm + RoPE (per-row positions added to the
    mapped position array), the q/gate split (one 2-D copy) and the output gate - one launch each instead of one per token
  • the CPU expert rows: only rows the CPU (not the GPU plan) computed are read from mapped memory
    (copy_rows_from_mapped; the GPU-planned rows are +0.0 there anyway)
  • with --pcie-frac 0 the window skips the PCIe path completely (no flag-B wait, no empty grouped launch)

STRATA_DEC_BATCH=0 restores the per-token launches.

Diagnostics (off by default): STRATA_DECODE_TIMING=1 prints per request where the window time goes (GPU wait, host
per layer, commit, draft); STRATA_VERIFY_PROFILE=1 stamps %globaltimer inside the captured window and prints the GPU
time per stage (GDN vs QSA layers); STRATA_VERIFY_NODES=1 prints each window graph's kernel histogram.

Measured

IQ3_S on an RTX 3090 (+ a second card holding experts, see the multi-GPU PR), window-weighted over flashbench 1K/8K
greedy + sampled: 80.1 → 88.6 tok/s from the batching. Exactness: greedy output identical to the per-token path on the
flashbench gate prompts (with STRATA_MMQ_NO_STREAMK).

One observation, not changed here: once most experts are on GPUs, the PCIe share made the GPU wait 2.5-5 ms per
window on flag B for the few missed experts; --pcie-frac 0 (the CPU computes them) was +13 % decode in that
setup. On a single card with many misses the trade-off is likely different.

Developed with an AI coding assistant; all numbers measured on 2x RTX 3090 / Ryzen 9 3950X.


🔄 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/109 **Author:** [@q8atnight](https://github.com/q8atnight) **Created:** 9/29/2026 **Status:** ✅ Merged **Merged:** 9/29/2026 **Merged by:** [@Niko1221](https://github.com/Niko1221) **Base:** `main` ← **Head:** `pr/decode-batch` --- ### 📝 Commits (1) - [`1e4515c`](https://github.com/Niko1221/Strata/commit/1e4515c87ba3c5ab0a633ac2a79643096242cf15) decode: batch the verify window's per-token kernels (bit-identical); skip the PCIe path with --pcie-frac 0; decode timing/profile switches ### 📊 Changes **16 files changed** (+387 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `include/strata/core/verify.hpp` (+13 -0) 📝 `include/strata/kernels/bf16_gemv.hpp` (+4 -0) 📝 `include/strata/kernels/elementwise.hpp` (+4 -0) 📝 `include/strata/kernels/fused_gr.hpp` (+2 -1) 📝 `include/strata/kernels/native_moe.hpp` (+3 -0) 📝 `include/strata/kernels/native_router.hpp` (+2 -0) 📝 `include/strata/kernels/verify_kernels.hpp` (+2 -0) 📝 `src/core/verify.cpp` (+173 -8) 📝 `src/kernels/cuda/elementwise.cu` (+31 -0) 📝 `src/kernels/cuda/fused_gr.cu` (+5 -1) 📝 `src/kernels/cuda/native_bf16.cu` (+68 -0) 📝 `src/kernels/cuda/native_moe.cu` (+12 -0) 📝 `src/kernels/cuda/native_router.cu` (+10 -0) 📝 `src/kernels/cuda/shared_expert.cu` (+8 -0) 📝 `src/kernels/cuda/verify_kernels.cu` (+10 -0) 📝 `src/program/generate.cpp` (+40 -0) </details> ### 📄 Description ## What The verify window's graph launched a few hundred tiny kernels **per window token** (≈450 extra graph nodes per token; the window is launch-latency bound: ~3-5 µs per small kernel). This batches them over the window's rows, keeping every row's arithmetic identical to the single-token call (outputs bit-identical): - router: one `bf16_gemv_fp32_mmvf_multi` (reads the 2.6 MB weight once, per-token accumulators in exactly the single-row order) + one multi-row top-10 launch (the kernel takes `blockIdx.x` = token) - shared expert's scalar gate: one multi-row GEMV + one sigmoid launch - bf16 cast of the window's rows: one call (the rows are contiguous) - MoE combine: one launch (`blockIdx.y` = token) - QSA layers: the indexer-key / indexer-query GEMVs, K / Q / indexer-query norm + RoPE (per-row positions added to the mapped position array), the q/gate split (one 2-D copy) and the output gate - one launch each instead of one per token - the CPU expert rows: only rows the CPU (not the GPU plan) computed are read from mapped memory (`copy_rows_from_mapped`; the GPU-planned rows are +0.0 there anyway) - with `--pcie-frac 0` the window skips the PCIe path completely (no flag-B wait, no empty grouped launch) `STRATA_DEC_BATCH=0` restores the per-token launches. Diagnostics (off by default): `STRATA_DECODE_TIMING=1` prints per request where the window time goes (GPU wait, host per layer, commit, draft); `STRATA_VERIFY_PROFILE=1` stamps `%globaltimer` inside the captured window and prints the GPU time per stage (GDN vs QSA layers); `STRATA_VERIFY_NODES=1` prints each window graph's kernel histogram. ## Measured IQ3_S on an RTX 3090 (+ a second card holding experts, see the multi-GPU PR), window-weighted over flashbench 1K/8K greedy + sampled: 80.1 → 88.6 tok/s from the batching. Exactness: greedy output identical to the per-token path on the flashbench `gate` prompts (with `STRATA_MMQ_NO_STREAMK`). One observation, not changed here: once most experts are on GPUs, the PCIe share made the GPU wait 2.5-5 ms per window on flag B for the few missed experts; `--pcie-frac 0` (the CPU computes them) was +13 % decode in that setup. On a single card with many misses the trade-off is likely different. Developed with an AI coding assistant; all numbers measured on 2x RTX 3090 / Ryzen 9 3950X. --- <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:21 +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#2459
No description provided.