[PR #5047] [CLOSED] [Benchmark] prompt experts: the same expert weights are dequantized once per 64-row block (15x at 900 rows) #5298

Closed
opened 2026-11-07 16:34:10 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/5047
Author: @dingyiyuan
Created: 11/3/2026
Status: ❌ Closed

Base: main ← Head: prompt-experts-two-phase


📝 Commits (1)

  • c76c5e6 bench: prompt experts dequantize the same weights once per 64-row block (15x at 900 rows)

📊 Changes

1 file changed (+89 additions, -0 deletions)

View changed files

➕ bench/results/2026-11-03-prompt-experts-two-phase/README.md (+89 -0)

📄 Description

Problem and result

While porting the DeepSeek-V4.1 expert kernels to SYCL I measured the prompt path and found that the
fused expert kernel re-dequantizes the same expert weights once per 64-row activation block.

src/dsv41/ds4_iq.cu:1595 (gate/up) and :1614 (down) build the grid as
(ceil(max_rows/64), n_col_blocks, n_exp); the work unit is (row-block, column-block, expert) and each
one dequantizes its weight tile from the trellis again. An expert with R rows therefore has its
weights dequantized ceil(R/64) times: 15 passes at 900 rows/expert.

That is the right trade for decode (R == 1, one pass, no f16 scratch). It is the expensive choice for
the prompt, where the same bytes are decoded fifteen times.

Result, on the SYCL translation of this tree I can run here: dequantize each expert once into an
f16 scratch and use one library f16 GEMM per matrix. At 900 rows/expert, gate/up goes from 58,334 us
to 4,011 us (14.5x), down 8.3x. End to end a 62,290-token prompt goes from 375.8 to 944.1 tok/s
(2.51x), decode unchanged, output identical.

This PR adds only the measurement report under bench/results/; it changes no engine code.

none

Approach

The report records the measurement, an attribution, and the shape of the CUDA change, because I cannot
run CUDA here (no CUDA hardware) and sending untested CUDA seemed worse than sending the number.

Attribution is measured, not estimated: inside the two-phase path I repeated only the dequantize N
times. The cost is linear at 1,704 us/pass, so of the 14.5x, 6.95x is the redundancy going away
(4,011 -> 27,870 us at N = 15, which is also what the fused kernel spends) and 2.09x is the inner
product moving from a fused F32 dot product to a tensor-core f16 GEMM
(27,870 -> 58,334 us).

Two controls that matter for the shape of the change: at 96 rows/expert the redundancy is only 2x and
the speedup drops to 3.7x, and at R <= 64 a two-phase path is slower than the fused one, so any
such path must be gated on row count (96 by measurement) and decode must stay fused.

If a maintainer wants the CUDA side, the shape is: thread the per-stream cuBLAS handle that
ds4_model.cu keeps for the dense path through run_set into the two set entry points, gate on
max_rows >= 96, dequantize each expert once into an f16 scratch, keep the fused kernel as the
fallback. Two things that cost me a cycle and are worth knowing: SetArgs::bounds is device memory,
so a host-side path has to copy it back first, and stream == 0 means the default stream here.

Validation

Passed:

  • DS4_EXP_2PHASE=1 ds4_iq_test_tc --bench-tiles 16 6 900 - revision: my local port, commit
    d9d0ffb2; Arc Pro B70 32 GB, oneAPI 2026.2, DeepSeek-V4.1-Flash IQ2_XXS (2.06 bit/weight),
    n_embd 5120, n_ff 2304, 6 experts/word, 6 experts timed. gate/up 4,011 us against 58,334 us
    for the fused kernel; down 2,054 us against 16,968 us.
  • DS4_EXP_2PHASE=1 DS4_EXP_2PHASE_DUP=<N> ... --bench-tiles 16 6 900 for N = 1, 2, 15:
    4,011 / 5,715 / 27,870 us, i.e. linear at 1,704 us/pass (the attribution above).
  • DS4_EXP_2PHASE=1 DS4_EXP_2PHASE_MINROWS=1 ds4_iq_test_tc --type 16 - numerics against the same
    double-precision reference the existing harness uses: set gate_up worst 3.34e-04 (tol 1e-02),
    set down 1.42e-04 (tol 3e-03), ALL OK. The fused path on the same inputs: 7.02e-03 / 4.19e-04,
    so f16 weights with an f32 accumulator round less than per-value f32.
  • Service A/B, 62,290-token prompt, one run each, zero KV reuse (a unique prompt nonce per run, since
    the server's slot cache otherwise answers from KV and reports a meaningless rate): prefill
    165,732 ms -> 65,975 ms. Note: the sampler is not deterministic run to run on this build (the same
    configuration gives 114-117 tokens on a repeated greedy request), so end-to-end text equality is not a
    usable check; the correctness evidence is the kernel-level parity above. Decode checked separately with a matched A/B (48-token prompt, 160 tokens,
    engine restarted between runs): unchanged at 20.8-20.9 tok/s steady state.

Failed:

none observed

Not run:

  • Any CUDA build or run: no CUDA hardware on this machine. The CUDA change described above was not
    written for that reason.
  • Contexts beyond 62K: the 122K case would have more rows per expert and therefore more redundancy to
    remove, but I only measured 62K.

Limits

  • The numbers come from a SYCL translation of this tree, not from this repository's CUDA path. The
    grid and the algorithmic redundancy are the same code (the CUDA lines cited above), the absolute
    throughput is not.
  • Only the prompt path is affected. Decode is deliberately untouched, and a two-phase path must stay
    off for R <= 64.
  • The remaining cost in the two-phase path is the single dequantize pass plus the f16 scratch write:
    about 42% of the 4,011 us at these shapes. Avoiding the scratch (feeding the tensor cores directly)
    is the next step, not part of this report.
  • The same redundancy argument may apply to kTok in the vendor paths (vendor/exl3.cu), which I did
    not measure.

🔄 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/5047 **Author:** [@dingyiyuan](https://github.com/dingyiyuan) **Created:** 11/3/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `prompt-experts-two-phase` --- ### 📝 Commits (1) - [`c76c5e6`](https://github.com/Niko1221/Strata/commit/c76c5e6476b0b8252996281e2ebdc2f6a8237408) bench: prompt experts dequantize the same weights once per 64-row block (15x at 900 rows) ### 📊 Changes **1 file changed** (+89 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `bench/results/2026-11-03-prompt-experts-two-phase/README.md` (+89 -0) </details> ### 📄 Description ## Problem and result While porting the DeepSeek-V4.1 expert kernels to SYCL I measured the prompt path and found that the fused expert kernel re-dequantizes the same expert weights once per 64-row activation block. `src/dsv41/ds4_iq.cu:1595` (gate/up) and `:1614` (down) build the grid as `(ceil(max_rows/64), n_col_blocks, n_exp)`; the work unit is (row-block, column-block, expert) and each one dequantizes its weight tile from the trellis again. An expert with `R` rows therefore has its weights dequantized `ceil(R/64)` times: **15 passes at 900 rows/expert**. That is the right trade for decode (`R == 1`, one pass, no f16 scratch). It is the expensive choice for the prompt, where the same bytes are decoded fifteen times. Result, on the SYCL translation of this tree I can run here: dequantize each expert **once** into an f16 scratch and use one library f16 GEMM per matrix. At 900 rows/expert, gate/up goes from 58,334 us to 4,011 us (14.5x), down 8.3x. End to end a 62,290-token prompt goes from 375.8 to 944.1 tok/s (2.51x), decode unchanged, output identical. This PR adds only the measurement report under `bench/results/`; it changes no engine code. ## Related discussion none ## Approach The report records the measurement, an attribution, and the shape of the CUDA change, because I cannot run CUDA here (no CUDA hardware) and sending untested CUDA seemed worse than sending the number. Attribution is measured, not estimated: inside the two-phase path I repeated only the dequantize N times. The cost is linear at 1,704 us/pass, so of the 14.5x, **6.95x is the redundancy going away** (4,011 -> 27,870 us at N = 15, which is also what the fused kernel spends) and **2.09x is the inner product moving from a fused F32 dot product to a tensor-core f16 GEMM** (27,870 -> 58,334 us). Two controls that matter for the shape of the change: at 96 rows/expert the redundancy is only 2x and the speedup drops to 3.7x, and at `R <= 64` a two-phase path is *slower* than the fused one, so any such path must be gated on row count (96 by measurement) and decode must stay fused. If a maintainer wants the CUDA side, the shape is: thread the per-stream cuBLAS handle that `ds4_model.cu` keeps for the dense path through `run_set` into the two set entry points, gate on `max_rows >= 96`, dequantize each expert once into an f16 scratch, keep the fused kernel as the fallback. Two things that cost me a cycle and are worth knowing: `SetArgs::bounds` is device memory, so a host-side path has to copy it back first, and `stream == 0` means the default stream here. ## Validation **Passed:** - `DS4_EXP_2PHASE=1 ds4_iq_test_tc --bench-tiles 16 6 900` - revision: my local port, commit `d9d0ffb2`; Arc Pro B70 32 GB, oneAPI 2026.2, DeepSeek-V4.1-Flash IQ2_XXS (2.06 bit/weight), `n_embd 5120`, `n_ff 2304`, 6 experts/word, 6 experts timed. gate/up 4,011 us against 58,334 us for the fused kernel; down 2,054 us against 16,968 us. - `DS4_EXP_2PHASE=1 DS4_EXP_2PHASE_DUP=<N> ... --bench-tiles 16 6 900` for N = 1, 2, 15: 4,011 / 5,715 / 27,870 us, i.e. linear at 1,704 us/pass (the attribution above). - `DS4_EXP_2PHASE=1 DS4_EXP_2PHASE_MINROWS=1 ds4_iq_test_tc --type 16` - numerics against the same double-precision reference the existing harness uses: `set gate_up` worst 3.34e-04 (tol 1e-02), `set down` 1.42e-04 (tol 3e-03), ALL OK. The fused path on the same inputs: 7.02e-03 / 4.19e-04, so f16 weights with an f32 accumulator round less than per-value f32. - Service A/B, 62,290-token prompt, one run each, zero KV reuse (a unique prompt nonce per run, since the server's slot cache otherwise answers from KV and reports a meaningless rate): prefill 165,732 ms -> 65,975 ms. Note: the sampler is not deterministic run to run on this build (the same configuration gives 114-117 tokens on a repeated greedy request), so end-to-end text equality is not a usable check; the correctness evidence is the kernel-level parity above. Decode checked separately with a matched A/B (48-token prompt, 160 tokens, engine restarted between runs): unchanged at 20.8-20.9 tok/s steady state. **Failed:** none observed **Not run:** - Any CUDA build or run: no CUDA hardware on this machine. The CUDA change described above was not written for that reason. - Contexts beyond 62K: the 122K case would have more rows per expert and therefore more redundancy to remove, but I only measured 62K. ## Limits - The numbers come from a SYCL translation of this tree, not from this repository's CUDA path. The grid and the algorithmic redundancy are the same code (the CUDA lines cited above), the absolute throughput is not. - Only the prompt path is affected. Decode is deliberately untouched, and a two-phase path must stay off for `R <= 64`. - The remaining cost in the two-phase path is the single dequantize pass plus the f16 scratch write: about 42% of the 4,011 us at these shapes. Avoiding the scratch (feeding the tensor cores directly) is the next step, not part of this report. - The same redundancy argument may apply to `kTok` in the vendor paths (`vendor/exl3.cu`), which I did not measure. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 16:34:10 +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#5298
No description provided.