mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 21:05:40 +07:00
[PR #5474] [Engine] HIP prompt path: opt-in FP16 reads of the hc up projection and attn_qkv (STRATA_F16_NOWIDEN) and the fused SwiGLU + Q8 pass on HIP (STRATA_SWIGLU_Q8) #5452
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#5452
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/5474
Author: @Vop3p
Created: 11/7/2026
Status: 🔄 Open
Base:
main← Head:pr/f16-nowiden-swiglu-q8📝 Commits (1)
cf7deccHIP prompt path: opt-in FP16 reads of the hc up projection and attn_qkv (STRATA_F16_NOWIDEN), fused SwiGLU + Q8 on HIP (STRATA_SWIGLU_Q8)📊 Changes
6 files changed (+211 additions, -26 deletions)
View changed files
📝
include/strata/prefill/gemm.hpp(+14 -0)📝
include/strata/prefill/kernels.hpp(+6 -2)📝
src/prefill/gemm.cu(+16 -0)📝
src/prefill/kernels.cu(+52 -12)📝
src/prefill/moe_mmq.cu(+17 -3)📝
src/prefill/prefill.cpp(+106 -9)📄 Description
Problem and result
With
STRATA_HIP_PROMPT_F16=1the prompt GEMMs run FP16 in and out, andf16_inplacethen widens every FP16 product back to FP32 in place. On gfx1030 that widen pass is already at memory bandwidth (636-900 GB/s at N 1024-6144, 528 GB/s at N 10240 in a standalone kernel), so it cannot be made faster. It can only be skipped. In a 32K prompt trace it is ~4% of GPU time. About two thirds of it is two products whose only consumers can read FP16 directly: the hyper-connection up projection (hc_attn_up/hc_ffn_up, N 10240, read bygr_mix_r) andattn_qkvon the GDN layers (N 10240, read by the GDN conv kernels).This PR has two opt-in parts, both bitwise identical to the default path:
STRATA_F16_NOWIDEN=1(new code): those two products stay FP16 and their consumers read halves. FP16 to FP32 is exact, so the values do not change; the conversion only moves into the consumer.gr_mix_r_kernel<G16>reads the up projection's FP16 rows.gdn_conv_kernel/gdn_conv_l2_kernel/gdn_conv_hist_kernel<H16>readattn_qkvin its row-slice layout (the native path computes it in slices of R columns). The request is made only where the conv kernel that reads FP16 runs (gdn_conv_f16_ok(): CONVL2=1, not serial, not CHUNKED). A product that goes through MMQ, PF_PAD or has no FP16 I/O reports R = 0 and keeps the widen.STRATA_SWIGLU_Q8=1(enables an existing kernel on HIP):swiglu_quant_kernelinmoe_mmq.cualready fuses SwiGLU withquantize_mmq_q8_1for CUDA SM60 resident weights. HIP had it behind an#if("not checked against the HIP quantizer"). This PR builds it for HIP (__shfl_xorat width 32) and uses it in the plain grouped expert path (both the whole-group and sliced call sites) when there is no tail scale and no Hadamard. The intermediate H no longer goes through memory.Measured on 2x RX 6900 XT, 10 cold-start interleaved pairs, off vs on, same binary:
Output text is identical in all 10 pairs (8K and 32K). Decode does not use these paths. 8K prompt reads on this machine have a wide spread from run to run; 32K is the clean number.
Related discussion
none (opt-in, HIP prompt path only, bitwise identical to the default)
Approach
STRATA_HIP_PROMPT_F16=1is on would be a one-line change if you prefer that.Gemmgetskeep_f16_once(n_full)/take_kept_f16()(up projection: one whole product) andkeep_f16_slices_once(n_full)/take_kept_rows()(attn_qkv: every slice stays FP16, and the slice width is returned).f16_inplaceskips the widen only for the product that was asked for, so every other GEMM is unchanged. The inject product shares the sameGemm, so the flag is taken back right after the up projection.STRATA_F16_NOWIDEN_CHECK=N(mixed output of the hc read),STRATA_F16_NOWIDEN_QKV_CHECK=N(conv output; the conv history is saved and restored around the recomputation) andSTRATA_SWIGLU_Q8_CHECK=N(the quantized H, 1152 bytes per row).STRATA_F16_RANGE/STRATA_DBG_NANrange checks live in the widen pass, so they do not see the two products that skip it. Leave NOWIDEN off when you use them.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:
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.gr_mix_r_kernel<true>/<false>use 32 VGPRs with 0 spills, the same as before;swiglu_quant_kerneluses 34-35 VGPRs.54828c7e.ctest -j 1: 221/224. The three failures are the same on main54828c7ewithout this change:ple_parity(cannot find the Q2_0 gguf through its relative path),conversation_copy_streams_test(the first copy stream takes 148 MiB here) andisa_guard_check(reports a CPU iq512 function).hip_prefill_gemmpasses.strataserve, IQ3_S pack, two-card layer split at 27,--prefill 16384 --prefill-pipe 1600 --spec 3 --spec-min-p 0.6 --pipeline-windows 1 --kv int8, parallel 1,STRATA_HIP_PROMPT_F16=1plus our usual HIP env.benchmark.py8K + 32K, one run each per arm, a new nonce each request, arms alternating off/on and on/off. 0 stalls.Failed:
Not run:
STRATA_F16_NOWIDENonly does something when FP16 prompt I/O is on (HIP). Theswiglu_quantchange widens an existing#ifto__HIPCC__. I did not build the other backends.Limits
attn_qon the QSA layers (~6% of the widen time) still widens. It has five consumers, so I left it out.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.