mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[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
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#5222
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 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=1these 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::runcalls the kernel only whenSTRATA_IQ4_W4A8is 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 bymmq::Context::run:cp.asyncpipeline (the raw IQ4 rows where they lie - group buffer orSTRATA_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).mma.m16n8k32), thensum += (float) dot * d_w * d_yin K order. The int8 lookup is llama.cpp'sget_int_from_table_16(MIT, noted in the file).=2sends only the IQ4_NL down products through it; measured below, it gains less than=1.tests/cuda/prefill_iq4_w4a8_test.cubuilds 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 ofContext::runand of the kernel. Exit 77 without a card or off sm_80..sm_88.Validation
Passed
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_teston 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.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, envSTRATA_KV_HOST_DMA=1 STRATA_PREFILL_AUTO_MAX=16384 STRATA_HC_Q8=1 STRATA_ROUTE_TAIL_SKIP=0 STRATA_DECODE_TIMING=1in 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 isSTRATA_IQ4_W4A8. Each arm: a fresh engine start, a 64-token warm-up, then fresh salted filler prompts (nothing reused;max_tokens1), 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'sstrata serve: prompt N tokens = 0 reused + N read in X msline, tokens/s, median (min-max):=1The 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
STRATA_ENABLE_HIP): not built. The new file is only in the CUDAstrata_mmqsource list, and the hook inmoe_mmq.cuis under#if !defined(GGML_USE_HIP).STRATA_HIP_GFX906): not built, no toolchain here. That build compiles everysrc/*.cuas HIP, so it compiles this file; underGGML_USE_HIPit is the stub - by reading only, unconfirmed by a compile. The test is not registered there. A gfx906 build check would be welcome.mmq::Context::run, which the prompt path calls.Limits
STRATA_W4A8_CFG=0..3picks the tokens per CTA (128 / 104 / 112 / 96). 0 is the default and the only one measured end to end here.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.