mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #1685] [RFC/PoC] Native Chunked Online Softmax Prefill for Dense Models (Qwen3.6) on HIP (Tested on gfx1031) #674
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#674
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?
Originally created by @leafgaga52keke on GitHub (Oct 9, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/1685
Summary & Context
Building on top of @aflin's excellent
qwen36-35b-supportbranch (commit20f4d4b), which brought foundational Qwen3.6-35B-A3B (qwen35moe) capabilities to Strata, I tested the implementation on a physical AMD GPU environment: AMD Radeon RX 6750 GRE 10GB (gfx1031, RDNA2, Wave32, Windows 10, ROCm 7.x via TheRock wheels).In commit
20f4d4b, Aaron noted:On my physical
gfx1031card, I verified this fallback behavior as well as anIQ2_Sstartup issue. As an amateur enthusiast, I put together a working, lightweight proof-of-concept (PoC) that unlocks the native batched prefill path for dense models on HIP without relying on Tensor Cores or WMMA.For an 8,726-token prompt, cold prefill time dropped from 78.51s down to 27.98s ~ 29.40s (a 2.8x speedup, saving over 64% wall-clock time), while maintaining full generation speed (~91–100 tok/s with 85.7% MTP draft acceptance).
I would like to share the root cause analysis, kernel design, and empirical benchmarks in case they provide helpful reference for maintainers adapting native prompt prefill across AMD architectures.
1. Bottleneck Analysis
Issue A: Missing
IQ2_Sin Down-Expert FormatsIQ2_SMoE layers failed at startup with:layer 10's experts are IQ2_S/IQ2_S (ggml types 22/22), which this engine has no GPU kernels forSTRATA_MMVQ_FMTSinsrc/kernels/cuda/iq_kernels.cualready hadX(22)(GGML_TYPE_IQ2_S), butSTRATA_D_FMTS(the down-projection expert macro) was missing it.X(22)intoSTRATA_D_FMTSinstantiates the down kernel and resolves startup cleanly.Issue B: No Batched Dense Prompt Attention on AMD HIP
this GPU has no batched prompt path for a qwen35moe model (NVIDIA sm_75+): prompts are read through the decode windows (slower)An 8,726-token prompt took 78.51 seconds because prompts were digested 1–6 tokens at a time via decode windows.
!g.has_indexer, such as Qwen3.6) rely on dense attention. Insrc/prefill/prefill.cpp,Prefill::supportsexplicitly returnedfalseon HIP when!g.has_indexerbecause upstream prompt attention was implemented using NVIDIA Tensor Core PTX (mma.sync).2. Kernel Design: Non-Fused Chunked Online Softmax
Why Avoid Fused WMMA on RDNA2 (
gfx1030/gfx1031)?Consumer RDNA2 cards have no native matrix cores (
v_wmma). Emulating synthetic matrix fragments via Clang often leads to high register pressure, spilling, or driver instability.The 128-Thread Online Softmax Design
Instead of matrix cores, I implemented a 128-thread chunked Online Softmax kernel with warp shuffles (
hip_dense_prompt_attn_kernel) insrc/kernels/cuda/qsa_prompt_attn.cu:blockDim.x = 128threads (4 warps under Wave32).const int d = threadIdx.x;exactly maps to the 128 dimensions of Head Dim (HD = 128).Q, K, Vand writes 1 element to outputO. This avoids out-of-bounds access and minimizes register pressure.mand normalization sumlentirely in registers across the prompt widthW.O(W \times W)attention matrix in global memory or scratch buffers.__shfl_xor_sync(0xffffffffu, pdot[h], offset, 32)across offsets 16, 8, 4, 2, 1.12 \times 4float__shared__buffer.KV_MODE 0(FP16),1(INT8q8_0),3(Hybrid), and4(q4_0) from Strata's paged memory pools (k_pool,k_q,k_q4).3. Benchmark Telemetry (Verified on
gfx1031)gfx1031, Wave32)Qwen3.6-35B-A3B(APEX-MINI, INT8 KV cache, MTP Speculative Draft = 5)20f4d4b)4. Generalization Considerations for Maintainers
If upstream intends to adapt this to all AMD architectures, here are a few key points to consider:
gfx103x,gfx110x) default to Wave32, where 128 threads = 4 warps.gfx906, MI200) use Wave64, where 128 threads = 2 warps.warpSizeor#if defined(__AMDGCN_WAVEFRONT_SIZE__):HD != 128, threads can loop over dimensions:for (int d = tid; d < HD; d += blockDim.x).5. Reference Implementation
The working patch tested on
gfx1031includes:src/kernels/cuda/iq_kernels.cu: addingX(22)toSTRATA_D_FMTSsrc/prefill/prefill.cpp: unlockingPrefill::supportsfor HIP dense attentionsrc/kernels/cuda/qsa_prompt_attn.cu:hip_dense_prompt_attn_kernel<KV_MODE>and dispatchHuge thanks to @Niko1221 for creating Strata and to @aflin for the initial Qwen3.6 integration! Hope these empirical measurements and PoC implementation provide helpful insights for official HIP prefill support across AMD GPUs!
(Note: The benchmark measurements and kernel were physically tested on my local GPU; this summary writeup was drafted with AI assistance and is provided for reference only.)
(注:基准测试与内核已在我的本地显卡上通过真机实测;本文由 AI 辅助整理起草,仅供参考交流。)