[PR #5475] [Engine] opt-in int8 copies for the persistent hc read (STRATA_HC_PERSIST_Q8) #5451

Open
opened 2026-11-07 19:36:07 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/5475
Author: @Vop3p
Created: 11/7/2026
Status: 🔄 Open

Base: main ← Head: pr/hc-persist-q8


📝 Commits (2)

  • 1a5274e Opt-in int8 copies for the persistent hc read (STRATA_HC_PERSIST_Q8)
  • 158413f fused_gr.hpp: include for size_t

📊 Changes

3 files changed (+204 additions, -16 deletions)

View changed files

📝 include/strata/kernels/fused_gr.hpp (+7 -0)
📝 src/core/verify.cpp (+19 -0)
📝 src/kernels/cuda/fused_gr.cu (+178 -16)

📄 Description

Problem and result

With STRATA_HC_PERSIST=1 the verifier's hyper-connection read (down + inject, then up) runs as one persistent kernel per read. On gfx1030 it is bound by memory bandwidth: it streams the bf16 hc weights once per read, and synchronization is only ~4 us of each read. Halving the bytes is the lever. STRATA_HC_Q8 already makes Q8_0 copies of these weights, but it does not apply to the persistent read: it runs a separate path, which on this card is slower than HC_PERSIST.

STRATA_HC_PERSIST_Q8=1 (with STRATA_HC_PERSIST=1) makes int8 copies of each hc read's weights at start-up, on Q8_0's grid: one fp16 scale per 32 values, the same rounding as STRATA_HC_Q8. The persistent kernel then reads those copies. The output changes, by about as much as STRATA_HC_Q8 changes it.

Decode, 2x RX 6900 XT, 10 cold-start interleaved pairs, off vs on, same binary. The output text differs between off and on (int8 weights), so the draft acceptance on a given prompt differs too. Time per verify window is therefore the fair number:

off (median) on (median) paired difference (median) pairs faster range
4K context, ms per window 28.33 27.15 -4.2% 10/10 -4.6 .. -4.0%
32K context, ms per window 27.11 26.54 -2.1% 10/10 -2.3 .. -1.6%
prompt 32K, tok/s 1,771 1,768 -0.2% -0.4 .. +0.1%

Plain decode tok/s on the same runs was +7.2% at 32K and -0.5% at 4K. Both differences mostly reflect acceptance: the windows went 126 -> 120 at 32K and 122 -> 128 at 4K, the same in every pair. I do not claim tok/s from two prompts. The prompt read does not use this path.

Quality (our production tree with the same kernel, teacher-forced KL against a double-precision reference, 8 conversation segments). Top-10 overlap with the reference:

top-10 overlap vs. no int8
neither 91.36
STRATA_HC_Q8=1 (upstream) 90.96 -0.4 pt
STRATA_HC_PERSIST_Q8=1 (this PR) 90.64 -0.7 pt

Mean KL was within the segment-to-segment noise for all arms (a single segment varies by up to 5x), so I do not read it either way. The start-up check reports a max relative difference of 0.00497 against the bf16 read. An earlier version of this patch used one fp32 scale per 128 columns, and one per row for up; it reported 0.00705 and lost 1.3 pt, which is why the grid is now Q8_0's.

none (opt-in, decode verifier only; it follows the existing STRATA_HC_Q8 / STRATA_HC_PERSIST pair)

Approach

  • fused_gr_persist_q8_prepare builds one read's copies at start-up, outside graph capture: qd [NR][D] (down rows, then inject rows) with sdh [NR][D/32] fp16 scale bits, and qu [D][LR] with suh [D][LR/32]. The copies are keyed by the read's bf16 w_down, so a read without copies keeps the bf16 kernel. Verifier::init calls it for each of this stage's layers and prints the count and MiB. Layers whose weights already carry q8_scale (STRATA_HC_Q8) are skipped.
  • q8g32_rows_kernel: d = amax / 127 per 32 contiguous values, then q = round(x / d) with d already rounded to fp16, which is ggml's reference rounding.
  • The persistent kernel gets a Q8 template argument. In the down/inject phase each lane pair shares one 32-value group and its scale; in the up phase each thread applies five group scales.
  • fused_gr_persist_q8_on() is true only after the int8 kernel passes a start-up check on the current card against the bf16 read (bar 2e-2; ~5e-3 measured).
  • Cost: VRAM for the copies, 360 MiB on card 0 (54 reads) and 280 MiB on card 1 (42 reads) in a 27/21 layer split. On our two-card setup that took 196 expert slots off card 1 (-3.8%). On a single 16 GB card the copies (641 MiB) left the draft head without room in 1 of 2 cold starts, so a single 16 GB card needs a smaller --vram-reserve or context.

Validation

Environment: 2x RX 6900 XT (gfx1030, 16 GB, PCIe 4.0 x8 each), Ryzen 5 5600X, 128 GB DDR4-3200, Ubuntu 26.04, kernel 7.0.0-42, ROCm 10.0 runtime (/opt/rocm/lib).

Passed:

  • Build: main 54828c7e + this change, -DSTRATA_ENABLE_HIP=ON -DCMAKE_HIP_ARCHITECTURES=gfx1030 -DSTRATA_NATIVE_EXPERTS=ON -DSTRATA_PREFILL_MMQ=ON -DSTRATA_Q6K_EXPERTS=ON -DGGML_HIP_GRAPHS=ON -DGGML_HIP_NO_VMM=ON -DSTRATA_BUILD_TESTS=ON.
  • ctest -j 1: 221/224 (hc_persist_parity and hc_persist_default_off pass; they cover the bf16 read, not the int8 one). The three failures are the same on main 54828c7e without this change: ple_parity (Q2_0 gguf relative path), conversation_copy_streams_test (148 MiB first copy stream) and isa_guard_check (CPU iq512 function).
  • Speed: the table above. IQ3_S pack, two-card layer split at 27, --spec 3 --spec-min-p 0.6 --pipeline-windows 1 --kv int8, parallel 1, STRATA_HC_PERSIST=1 plus our usual HIP env. benchmark.py 4K + 32K, 256 tokens each, arms alternating. Each arm produced the same text in all 10 runs. 0 stalls.
  • On our production tree (same kernel), the standard protocol's 12 sanity checks: 12/12, 0 stalls, with parallel 2 + --batch-mtp.

Failed:

  • none observed

Not run:

  • CUDA / SYCL / Metal. The kernel is in fused_gr.cu next to the existing persistent kernel. I built and ran only HIP gfx1030.
  • A ctest for the int8 kernel. It is covered by the start-up check (int8 kernel on int8 copies of random weights against the bf16 read, bar 2e-2, 4.97e-3 measured), which turns the mode off on failure, but not by a standalone test. I can add one if you want it in ctest.
  • Long-context headroom at 128K-256K with the copies' extra VRAM, on this PR's tree.
  • Other gfx103x chips.

Limits

  • The gain is ~2-4% per window, smaller than halving the hc bytes would suggest. The hc read is one part of the window; experts and attention are the rest.
  • The copies cost VRAM (see Approach). On 16 GB cards that is real. That is the main reason this stays opt-in.

Developed with an AI coding assistant; every number above was measured on the machine described in Validation.

🤖 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/5475 **Author:** [@Vop3p](https://github.com/Vop3p) **Created:** 11/7/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr/hc-persist-q8` --- ### 📝 Commits (2) - [`1a5274e`](https://github.com/Niko1221/Strata/commit/1a5274ee04ec5194464242dd849cebb99fb6dc57) Opt-in int8 copies for the persistent hc read (STRATA_HC_PERSIST_Q8) - [`158413f`](https://github.com/Niko1221/Strata/commit/158413fd9307db00afc056b093976e13f7d9a317) fused_gr.hpp: include <cstddef> for size_t ### 📊 Changes **3 files changed** (+204 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `include/strata/kernels/fused_gr.hpp` (+7 -0) 📝 `src/core/verify.cpp` (+19 -0) 📝 `src/kernels/cuda/fused_gr.cu` (+178 -16) </details> ### 📄 Description ## Problem and result With `STRATA_HC_PERSIST=1` the verifier's hyper-connection read (down + inject, then up) runs as one persistent kernel per read. On gfx1030 it is bound by memory bandwidth: it streams the bf16 hc weights once per read, and synchronization is only ~4 us of each read. Halving the bytes is the lever. `STRATA_HC_Q8` already makes Q8_0 copies of these weights, but it does not apply to the persistent read: it runs a separate path, which on this card is slower than `HC_PERSIST`. `STRATA_HC_PERSIST_Q8=1` (with `STRATA_HC_PERSIST=1`) makes int8 copies of each hc read's weights at start-up, on Q8_0's grid: one fp16 scale per 32 values, the same rounding as `STRATA_HC_Q8`. The persistent kernel then reads those copies. The output changes, by about as much as `STRATA_HC_Q8` changes it. Decode, 2x RX 6900 XT, 10 cold-start interleaved pairs, off vs on, same binary. The output text differs between off and on (int8 weights), so the draft acceptance on a given prompt differs too. **Time per verify window** is therefore the fair number: | | off (median) | on (median) | paired difference (median) | pairs faster | range | |---|---|---|---|---|---| | 4K context, ms per window | 28.33 | 27.15 | **-4.2%** | 10/10 | -4.6 .. -4.0% | | 32K context, ms per window | 27.11 | 26.54 | **-2.1%** | 10/10 | -2.3 .. -1.6% | | prompt 32K, tok/s | 1,771 | 1,768 | -0.2% | | -0.4 .. +0.1% | Plain decode tok/s on the same runs was +7.2% at 32K and -0.5% at 4K. Both differences mostly reflect acceptance: the windows went 126 -> 120 at 32K and 122 -> 128 at 4K, the same in every pair. I do not claim tok/s from two prompts. The prompt read does not use this path. Quality (our production tree with the same kernel, teacher-forced KL against a double-precision reference, 8 conversation segments). Top-10 overlap with the reference: | | top-10 overlap | vs. no int8 | |---|---|---| | neither | 91.36 | | | `STRATA_HC_Q8=1` (upstream) | 90.96 | -0.4 pt | | `STRATA_HC_PERSIST_Q8=1` (this PR) | 90.64 | -0.7 pt | Mean KL was within the segment-to-segment noise for all arms (a single segment varies by up to 5x), so I do not read it either way. The start-up check reports a max relative difference of 0.00497 against the bf16 read. An earlier version of this patch used one fp32 scale per 128 columns, and one per row for `up`; it reported 0.00705 and lost 1.3 pt, which is why the grid is now Q8_0's. ## Related discussion none (opt-in, decode verifier only; it follows the existing `STRATA_HC_Q8` / `STRATA_HC_PERSIST` pair) ## Approach - `fused_gr_persist_q8_prepare` builds one read's copies at start-up, outside graph capture: `qd [NR][D]` (down rows, then inject rows) with `sdh [NR][D/32]` fp16 scale bits, and `qu [D][LR]` with `suh [D][LR/32]`. The copies are keyed by the read's bf16 `w_down`, so a read without copies keeps the bf16 kernel. `Verifier::init` calls it for each of this stage's layers and prints the count and MiB. Layers whose weights already carry `q8_scale` (`STRATA_HC_Q8`) are skipped. - `q8g32_rows_kernel`: d = amax / 127 per 32 contiguous values, then q = round(x / d) with d already rounded to fp16, which is ggml's reference rounding. - The persistent kernel gets a `Q8` template argument. In the down/inject phase each lane pair shares one 32-value group and its scale; in the up phase each thread applies five group scales. - `fused_gr_persist_q8_on()` is true only after the int8 kernel passes a start-up check on the current card against the bf16 read (bar 2e-2; ~5e-3 measured). - Cost: VRAM for the copies, 360 MiB on card 0 (54 reads) and 280 MiB on card 1 (42 reads) in a 27/21 layer split. On our two-card setup that took 196 expert slots off card 1 (-3.8%). On a single 16 GB card the copies (641 MiB) left the draft head without room in 1 of 2 cold starts, so a single 16 GB card needs a smaller `--vram-reserve` or context. ## Validation Environment: 2x RX 6900 XT (gfx1030, 16 GB, PCIe 4.0 x8 each), Ryzen 5 5600X, 128 GB DDR4-3200, Ubuntu 26.04, kernel 7.0.0-42, ROCm 10.0 runtime (`/opt/rocm/lib`). **Passed:** - Build: main 54828c7e + this change, `-DSTRATA_ENABLE_HIP=ON -DCMAKE_HIP_ARCHITECTURES=gfx1030 -DSTRATA_NATIVE_EXPERTS=ON -DSTRATA_PREFILL_MMQ=ON -DSTRATA_Q6K_EXPERTS=ON -DGGML_HIP_GRAPHS=ON -DGGML_HIP_NO_VMM=ON -DSTRATA_BUILD_TESTS=ON`. - `ctest -j 1`: 221/224 (`hc_persist_parity` and `hc_persist_default_off` pass; they cover the bf16 read, not the int8 one). The three failures are the same on main 54828c7e without this change: `ple_parity` (Q2_0 gguf relative path), `conversation_copy_streams_test` (148 MiB first copy stream) and `isa_guard_check` (CPU iq512 function). - Speed: the table above. IQ3_S pack, two-card layer split at 27, `--spec 3 --spec-min-p 0.6 --pipeline-windows 1 --kv int8`, parallel 1, `STRATA_HC_PERSIST=1` plus our usual HIP env. `benchmark.py` 4K + 32K, 256 tokens each, arms alternating. Each arm produced the same text in all 10 runs. 0 stalls. - On our production tree (same kernel), the standard protocol's 12 sanity checks: 12/12, 0 stalls, with parallel 2 + `--batch-mtp`. **Failed:** - none observed **Not run:** - CUDA / SYCL / Metal. The kernel is in `fused_gr.cu` next to the existing persistent kernel. I built and ran only HIP gfx1030. - A ctest for the int8 kernel. It is covered by the start-up check (int8 kernel on int8 copies of random weights against the bf16 read, bar 2e-2, 4.97e-3 measured), which turns the mode off on failure, but not by a standalone test. I can add one if you want it in ctest. - Long-context headroom at 128K-256K with the copies' extra VRAM, on this PR's tree. - Other gfx103x chips. ## Limits - The gain is ~2-4% per window, smaller than halving the hc bytes would suggest. The hc read is one part of the window; experts and attention are the rest. - The copies cost VRAM (see Approach). On 16 GB cards that is real. That is the main reason this stays opt-in. --- Developed with an AI coding assistant; every number above was measured on the machine described in Validation. 🤖 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>
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#5451
No description provided.