[PR #4871] [CLOSED] [Engine] prompt path: opt-in int8 kernel for the IQ4_XS / IQ4_NL expert products (STRATA_IQ4_W4A8), MMQ's bits #5222

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4871
Author: @orochifj
Created: 11/1/2026
Status: ❌ Closed

Base: main ← Head: pr/iq4-w4a8


📝 Commits (1)

  • 4788c4e [Engine] prompt path: opt-in int8 kernel for the IQ4_XS / IQ4_NL expert products (STRATA_IQ4_W4A8), MMQ's bits

📊 Changes

6 files changed (+780 additions, -1 deletions)

View changed files

📝 CMakeLists.txt (+9 -1)
📝 docs/DETAILS.md (+1 -0)
➕ include/strata/prefill/moe_iq4_w4a8.hpp (+20 -0)
➕ src/prefill/moe_iq4_w4a8.cu (+460 -0)
📝 src/prefill/moe_mmq.cu (+12 -0)
➕ tests/cuda/prefill_iq4_w4a8_test.cu (+278 -0)

📄 Description

Problem and result

The prompt path's IQ4 expert products (IQ4_XS gate/up and IQ4_NL down in an IQ4 pack) run through llama.cpp's MMQ, which on an RTX 3090 reaches roughly 28 % (gate/up) and 19 % (down) of the int8 peak: every tile load is synchronous and is converted to int8 in shared memory before the MMA. With STRATA_IQ4_W4A8=1 these products run on a pipelined int8 kernel that computes the same sums, bit for bit. Measured on 2x RTX 3090: prompts of 8K-123K tokens read +3.0 to +4.8 % faster (engine timing, medians of three alternating rounds); 1.5K-4K are unchanged. Unset, nothing changes.

None. The switch is opt-in and the default path is unchanged: Context::run calls the kernel only when STRATA_IQ4_W4A8 is 1 or 2 (iq4_w4a8_mode() returns 0 otherwise), checked by reading the diff; the A arm below is the stock path. Happy to move this to an issue first if you prefer.

Approach

src/prefill/moe_iq4_w4a8.cu, tried first by mmq::Context::run:

  • CTA = 128 weight rows x up to 128 tokens of one expert; warp w owns rows 16w..16w+15 and all of the tile's tokens, so the 4-bit weights are converted to int8 once per K step, in registers, and used for every token tile.
  • 128-value K steps through a 2-stage cp.async pipeline (the raw IQ4 rows where they lie - group buffer or STRATA_MMQ_DIRECT's pointer table - and the q8_1 activation rows), one barrier per step; the partial last token tile is skipped (one instantiation per count of 8-token tiles).
  • The arithmetic is MMQ's tiling-mode arithmetic: per 32-value block the exact int32 dot (mma.m16n8k32), then sum += (float) dot * d_w * d_y in K order. The int8 lookup is llama.cpp's get_int_from_table_16 (MIT, noted in the file).
  • It declines (MMQ runs) a product of another type, rows not a multiple of 128, a GPU outside sm_80..sm_88 (the split rule mirrors MMQ's Ampere configs), or a launch MMQ would split along K with its stream-k fixup (those sums are added in another order).
  • =2 sends only the IQ4_NL down products through it; measured below, it gains less than =1.
  • In the gfx906 HIP build, which compiles every CUDA source of the tree as HIP, the file is a stub that declines every product.

tests/cuda/prefill_iq4_w4a8_test.cu builds one prompt layer-chunk of a Flash-Next IQ4 pack's products (T tokens x 10 experts over 512, 16 experts a launch, gate/up on the chunk's q8_1 rows with absolute bounds, down on each group's own rows), on three routings (uniform, log-normal sigma 1 and 2) and both weight layouts, and compares every output word of Context::run and of the kernel. Exit 77 without a card or off sm_80..sm_88.

Validation

Passed

  • Builds at this branch's commit with CUDA 13.0 for 86-real;86-virtual: the Dockerfile's CMake options plus -DSTRATA_BUILD_TESTS=ON, and the same plus -DSTRATA_MMQ_TAB=ON (engine, prefill_iq4_w4a8_test, prefill_mmq_tab_test). No compiler warnings from the changed files.
  • prefill_iq4_w4a8_test on an RTX 3090 (sm_86), both builds, default (4,096 tokens) and --full (15,360): every case 0 differing words of 157,286,400 (default) / 589,824,000 (--full); the kernel ran 30-32 gate/up and 30-32 down products per case, MMQ the rest (in the log-normal sigma 2 routing one gate/up and at most one down product, which exercises the fallback).
  • prefill_mmq_tab_test (TAB build): 890 comparisons, 0 failed.
  • A/B on the Dockerfile-options build, run in the v0.2.9 image with its own serve/server.py, 2026-11-01. 2x RTX 3090 24 GB at 250 W, EPYC 7452, 256 GB DDR4, Linux 6.8, NVIDIA 610.57.04. Swift-1.5 Qwen3.8-Flash-Next IQ4_XS (IQ4_XS gate/up, IQ4_NL down), layer split auto (24 / 24), --max-context 524288 --rope-scaling yarn --rope-scale 2 --kv int8 --kv-resident 32768 --spec 4 --spec-min-p 0.5 --pipeline-windows 2 --pcie-frac 0, env STRATA_KV_HOST_DMA=1 STRATA_PREFILL_AUTO_MAX=16384 STRATA_HC_Q8=1 STRATA_ROUTE_TAIL_SKIP=0 STRATA_DECODE_TIMING=1 in both arms; the rest of the config (vision, conversation cache, an expert profile recorded for this pack) is the same in both. The only change between arms is STRATA_IQ4_W4A8. Each arm: a fresh engine start, a 64-token warm-up, then fresh salted filler prompts (nothing reused; max_tokens 1), two reads per size up to 12K and one per size from 19K, three rounds ordered A B / B A / A B. Numbers are the engine's strata serve: prompt N tokens = 0 reused + N read in X ms line, tokens/s, median (min-max):
prompt tokens A: unset B: =1 B vs A
1,471 863 (862-864) 864 (863-865) +0.1 %
3,844 1,945 (1,941-1,949) 1,960 (1,959-1,962) +0.8 %
7,901 2,237 (2,233-2,257) 2,344 (2,332-2,354) +4.8 %
11,996 2,301 (2,238-2,364) 2,395 (2,336-2,460) +4.1 %
19,206 2,314 (2,302-2,318) 2,384 (2,380-2,387) +3.0 %
43,036 3,401 (3,401-3,432) 3,540 (3,532-3,549) +4.1 %
88,907 3,989 (3,984-4,009) 4,146 (4,132-4,148) +3.9 %
122,507 4,061 (4,059-4,084) 4,218 (4,212-4,219) +3.9 %

The two 12K reads of a round differ (the first ~2,360, the second ~2,240 in A; ~2,455 / ~2,337 in B) in every round of both arms; the ranges show both.

  • =2 (down only), same build and harness right after: three rounds plus one A round as a drift check (A4 within 0.2 % of A's medians): 7,901 tokens 2,292, 43,036 tokens 3,482, 122,507 tokens 4,149 tok/s, i.e. +1.8 to +2.6 % from 8K, below =1.

Failed: none observed.

Not run

  • HIP (STRATA_ENABLE_HIP): not built. The new file is only in the CUDA strata_mmq source list, and the hook in moe_mmq.cu is under #if !defined(GGML_USE_HIP).
  • HIP gfx906 (STRATA_HIP_GFX906): not built, no toolchain here. That build compiles every src/*.cu as HIP, so it compiles this file; under GGML_USE_HIP it is the stub - by reading only, unconfirmed by a compile. The test is not registered there. A gfx906 build check would be welcome.
  • SYCL and Metal: not touched.
  • Other GPUs: only sm_86 ran. The kernel enables itself on sm_80..sm_88; A100 (sm_80) and Orin (sm_87) are untested. Ada and newer decline, so MMQ runs as before.
  • Other IQ4 packs (Unsloth UD-IQ4_XS, ISTA): not run. Decode was not measured: the switch changes only mmq::Context::run, which the prompt path calls.

Limits

  • IQ4_XS and IQ4_NL with q8_1 activations only; anything else stays on MMQ.
  • STRATA_W4A8_CFG=0..3 picks the tokens per CTA (128 / 104 / 112 / 96). 0 is the default and the only one measured end to end here.
  • One rig, one pack. The gain should depend on how much of a prompt's time the IQ4 expert products take.

Prepared with AI assistance (Claude); every measurement above comes from the runs described, and the logs are available.

🤖 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/4871 **Author:** [@orochifj](https://github.com/orochifj) **Created:** 11/1/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/iq4-w4a8` --- ### 📝 Commits (1) - [`4788c4e`](https://github.com/Niko1221/Strata/commit/4788c4e24c13b2b8ba36b738621b8bab0f298803) [Engine] prompt path: opt-in int8 kernel for the IQ4_XS / IQ4_NL expert products (STRATA_IQ4_W4A8), MMQ's bits ### 📊 Changes **6 files changed** (+780 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+9 -1) 📝 `docs/DETAILS.md` (+1 -0) ➕ `include/strata/prefill/moe_iq4_w4a8.hpp` (+20 -0) ➕ `src/prefill/moe_iq4_w4a8.cu` (+460 -0) 📝 `src/prefill/moe_mmq.cu` (+12 -0) ➕ `tests/cuda/prefill_iq4_w4a8_test.cu` (+278 -0) </details> ### 📄 Description ### Problem and result The prompt path's IQ4 expert products (IQ4_XS gate/up and IQ4_NL down in an IQ4 pack) run through llama.cpp's MMQ, which on an RTX 3090 reaches roughly 28 % (gate/up) and 19 % (down) of the int8 peak: every tile load is synchronous and is converted to int8 in shared memory before the MMA. With `STRATA_IQ4_W4A8=1` these products run on a pipelined int8 kernel that computes **the same sums, bit for bit**. Measured on 2x RTX 3090: prompts of 8K-123K tokens read **+3.0 to +4.8 %** faster (engine timing, medians of three alternating rounds); 1.5K-4K are unchanged. Unset, nothing changes. ### Related discussion None. The switch is opt-in and the default path is unchanged: `Context::run` calls the kernel only when `STRATA_IQ4_W4A8` is 1 or 2 (`iq4_w4a8_mode()` returns 0 otherwise), checked by reading the diff; the A arm below is the stock path. Happy to move this to an issue first if you prefer. ### Approach `src/prefill/moe_iq4_w4a8.cu`, tried first by `mmq::Context::run`: - CTA = 128 weight rows x up to 128 tokens of one expert; warp w owns rows 16w..16w+15 and all of the tile's tokens, so the 4-bit weights are converted to int8 once per K step, in registers, and used for every token tile. - 128-value K steps through a 2-stage `cp.async` pipeline (the raw IQ4 rows where they lie - group buffer or `STRATA_MMQ_DIRECT`'s pointer table - and the q8_1 activation rows), one barrier per step; the partial last token tile is skipped (one instantiation per count of 8-token tiles). - The arithmetic is MMQ's tiling-mode arithmetic: per 32-value block the exact int32 dot (`mma.m16n8k32`), then `sum += (float) dot * d_w * d_y` in K order. The int8 lookup is llama.cpp's `get_int_from_table_16` (MIT, noted in the file). - It declines (MMQ runs) a product of another type, rows not a multiple of 128, a GPU outside sm_80..sm_88 (the split rule mirrors MMQ's Ampere configs), or a launch MMQ would split along K with its stream-k fixup (those sums are added in another order). - `=2` sends only the IQ4_NL down products through it; measured below, it gains less than `=1`. - In the gfx906 HIP build, which compiles every CUDA source of the tree as HIP, the file is a stub that declines every product. `tests/cuda/prefill_iq4_w4a8_test.cu` builds one prompt layer-chunk of a Flash-Next IQ4 pack's products (T tokens x 10 experts over 512, 16 experts a launch, gate/up on the chunk's q8_1 rows with absolute bounds, down on each group's own rows), on three routings (uniform, log-normal sigma 1 and 2) and both weight layouts, and compares every output word of `Context::run` and of the kernel. Exit 77 without a card or off sm_80..sm_88. ### Validation **Passed** - Builds at this branch's commit with CUDA 13.0 for `86-real;86-virtual`: the Dockerfile's CMake options plus `-DSTRATA_BUILD_TESTS=ON`, and the same plus `-DSTRATA_MMQ_TAB=ON` (engine, `prefill_iq4_w4a8_test`, `prefill_mmq_tab_test`). No compiler warnings from the changed files. - `prefill_iq4_w4a8_test` on an RTX 3090 (sm_86), both builds, default (4,096 tokens) and `--full` (15,360): every case 0 differing words of 157,286,400 (default) / 589,824,000 (`--full`); the kernel ran 30-32 gate/up and 30-32 down products per case, MMQ the rest (in the log-normal sigma 2 routing one gate/up and at most one down product, which exercises the fallback). - `prefill_mmq_tab_test` (TAB build): 890 comparisons, 0 failed. - A/B on the Dockerfile-options build, run in the v0.2.9 image with its own `serve/server.py`, 2026-11-01. 2x RTX 3090 24 GB at 250 W, EPYC 7452, 256 GB DDR4, Linux 6.8, NVIDIA 610.57.04. Swift-1.5 Qwen3.8-Flash-Next IQ4_XS (IQ4_XS gate/up, IQ4_NL down), layer split auto (24 / 24), `--max-context 524288 --rope-scaling yarn --rope-scale 2 --kv int8 --kv-resident 32768 --spec 4 --spec-min-p 0.5 --pipeline-windows 2 --pcie-frac 0`, env `STRATA_KV_HOST_DMA=1 STRATA_PREFILL_AUTO_MAX=16384 STRATA_HC_Q8=1 STRATA_ROUTE_TAIL_SKIP=0 STRATA_DECODE_TIMING=1` in both arms; the rest of the config (vision, conversation cache, an expert profile recorded for this pack) is the same in both. The only change between arms is `STRATA_IQ4_W4A8`. Each arm: a fresh engine start, a 64-token warm-up, then fresh salted filler prompts (nothing reused; `max_tokens` 1), two reads per size up to 12K and one per size from 19K, three rounds ordered A B / B A / A B. Numbers are the engine's `strata serve: prompt N tokens = 0 reused + N read in X ms` line, tokens/s, median (min-max): | prompt tokens | A: unset | B: `=1` | B vs A | |---|---|---|---| | 1,471 | 863 (862-864) | 864 (863-865) | +0.1 % | | 3,844 | 1,945 (1,941-1,949) | 1,960 (1,959-1,962) | +0.8 % | | 7,901 | 2,237 (2,233-2,257) | 2,344 (2,332-2,354) | +4.8 % | | 11,996 | 2,301 (2,238-2,364) | 2,395 (2,336-2,460) | +4.1 % | | 19,206 | 2,314 (2,302-2,318) | 2,384 (2,380-2,387) | +3.0 % | | 43,036 | 3,401 (3,401-3,432) | 3,540 (3,532-3,549) | +4.1 % | | 88,907 | 3,989 (3,984-4,009) | 4,146 (4,132-4,148) | +3.9 % | | 122,507 | 4,061 (4,059-4,084) | 4,218 (4,212-4,219) | +3.9 % | The two 12K reads of a round differ (the first ~2,360, the second ~2,240 in A; ~2,455 / ~2,337 in B) in every round of both arms; the ranges show both. - `=2` (down only), same build and harness right after: three rounds plus one A round as a drift check (A4 within 0.2 % of A's medians): 7,901 tokens 2,292, 43,036 tokens 3,482, 122,507 tokens 4,149 tok/s, i.e. +1.8 to +2.6 % from 8K, below `=1`. **Failed:** none observed. **Not run** - HIP (`STRATA_ENABLE_HIP`): not built. The new file is only in the CUDA `strata_mmq` source list, and the hook in `moe_mmq.cu` is under `#if !defined(GGML_USE_HIP)`. - HIP gfx906 (`STRATA_HIP_GFX906`): not built, no toolchain here. That build compiles every `src/*.cu` as HIP, so it compiles this file; under `GGML_USE_HIP` it is the stub - by reading only, **unconfirmed by a compile**. The test is not registered there. A gfx906 build check would be welcome. - SYCL and Metal: not touched. - Other GPUs: only sm_86 ran. The kernel enables itself on sm_80..sm_88; A100 (sm_80) and Orin (sm_87) are untested. Ada and newer decline, so MMQ runs as before. - Other IQ4 packs (Unsloth UD-IQ4_XS, ISTA): not run. Decode was not measured: the switch changes only `mmq::Context::run`, which the prompt path calls. ### Limits - IQ4_XS and IQ4_NL with q8_1 activations only; anything else stays on MMQ. - `STRATA_W4A8_CFG=0..3` picks the tokens per CTA (128 / 104 / 112 / 96). 0 is the default and the only one measured end to end here. - One rig, one pack. The gain should depend on how much of a prompt's time the IQ4 expert products take. Prepared with AI assistance (Claude); every measurement above comes from the runs described, and the logs are available. 🤖 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 16:33:35 +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#5222
No description provided.