Repository navigation
Add SM89 Qwen3-VL FP8 path (8B + 2B) - #116
Merged
LiangSu8899 merged 9 commits intoJun 26, 2026
Merged
Conversation
Hand-written Ada (sm_89) FP8 e4m3 -> BF16 block-128 scaled GEMM for official Qwen3-VL FP8 prefill. Reads FP8 weight directly (no dequant scratch), keeps per-token act scale [M,K/128] and DeepSeek-style weight block scale [N/128,K/128]. cp.async pipeline + m16n8k32 e4m3 MMA + ldmatrix.x4 over a 128B-swizzled smem layout + coalesced scale staging + bfloat162 paired stores. The device kernel body lives in fp8_bs_gemm_device.cuh so the production launcher and the micro-bench share one source (zero drift). Gated by ENABLE_SM89_BLOCK_FP8_GEMM for GPU_ARCH=89.
Decode-shape (M=1) sibling of the SM89 block-128 GEMM: per-token activation block scale [K/128] x per-weight block scale [N/128,K/128], warp-per-row with A staged in smem and 16-byte coalesced B loads. Lives in its own file/namespace (gemv_m1_sm89) rather than the SM120 per-tensor GEMV, so the two architectures' GEMVs do not share a source. Wired into the build with the dedicated Qwen3-VL module in a later commit.
…orm)
Union-merge of the existing main kernels with the SM89-needed additions, so no
existing variant is lost:
- qwen3_qkv_post_proc: add qwen3_qk_norm_rope_kvwrite_bf16 and _batched_bf16
(fused Q+K norm+rope+kv-write used by the SM89 prefill path), keeping main's
_prefill_bf16 / _devpos_bf16 variants.
- fp8_per_token_block_quant: add rms_norm / residual_add_rms_norm / silu_mul /
silu_mul_merged to-fp8-block128 fused activation-quant kernels.
Both TUs compile clean for sm_89.
Extend the dedicated Qwen3-VL pybind module (previously SM120-only) to also build for GPU_ARCH=89, compiling the SM89 block-128 GEMM/GEMV + fused act/norm-quant + QK norm-rope sources and binding their 8 new symbols (fp8_block128_gemm_blockscaled_sm89_bf16out, ht_gemv_fp8_block128_m1_*, rms_norm/residual_add_rms_norm/silu_mul[_merged]_to_fp8_block128_bf16, qwen3_qk_norm_rope_kvwrite[_batched]_bf16). The 7 generic symbols the SM89 frontend also needs stay in central flash_rt_kernels. Keeping the SM89 GEMM out of flash_rt_kernels keeps that .so small (mirrors the SM120 split). The SM89 frontend imports both modules, like the SM120 ViT path.
Qwen3-VL 2B ViT runs full (non-causal) attention at head_dim=64; the previous FA2 build only shipped hdim 96/128/256, forcing a 64->96 pad (33% waste). Add the auto-generated hdim64 sm80 fp16/bf16 instantiations, the launch-template hdim64 tile selection (no-split, 128x64 for the non-causal Ada path), and the fa2_wrapper <=64 dispatch bucket. CMake FA2_HDIMS gains 64 (default) and skips the unused split-KV hdim64 object to keep ptxas time down. Vendored FA2 kernel body unchanged (Tri Dao); this is instantiation only.
Add the SM89 text + multimodal frontends and the FP8 block-128 weight loader: - qwen3_vl_fp8_sm89.py: batch-1 text decode + FP8 block-scaled prefill GEMM. - qwen3_vl_fp8_sm89_multimodal.py: ViT tower + image scatter + FP8 language. - _qwen3_vl_fp8_weights.py: official .weight/.weight_scale_inv loader. Kernel symbols resolve via _MergedKernels: the SM89-specific kernels come from flash_rt_qwen3_vl_kernels, generic ones from flash_rt_kernels (same dual-module split the SM120 ViT path already uses). Shared SM120 infra is union-merged with main: _qwen3_vl_geometry (dim contract for 2B/8B), _qwen3_vl_vision_rtx (SM89 FP8 linear dispatch via the dedicated module), qwen3_vl_rtx + attn_backend_qwen3 (generalized head/layer config for both archs).
- quantize_qwen3_vl_to_fp8_block128.py: offline BF16 -> FP8 block-128
quantizer for the language linears (single-file or sharded output).
- smoke_qwen3_vl_fp8_sm89.py: end-to-end text/multimodal smoke + logit-cosine
vs eager + tps harness.
- test_qwen3_vl_fp8_sm89{,_2b}.py: CPU/CI-friendly checks (config guard,
block-128 quant round-trip, expected quant-linear count) without the
multi-GB checkpoint or CUDA.
Bench/NCU iteration harnesses are intentionally not shipped.
Document the SM89 official-FP8 path for the 8B and 2B variants (build flags, quantizer usage, smoke command, measured prefill/decode). Add a 'Why this path is hand-written' section explaining that Ada has no TMA and no warp-specialized CUTLASS collective, so the SM120 TMA warp-specialized blockwise GEMM and its deep multi-stage cp.async pipeline do not port -- hence the single-stage hand-written cp.async + ldmatrix kernel and the use of vendored FA2 for attention.
Member
|
Very cool! |
LiangSu8899
approved these changes
Jun 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Brings up Qwen3-VL on Ada RTX 4090 (sm_89) with the checkpoint's native
block-scaled FP8 language weights, for both the 8B and 2B variants.
This is the SM89 counterpart to the SM120/NVFP4 Qwen3-VL path: the vision tower,
geometry, image scatter and MRoPE are reused from that work; this branch adds
the Ada FP8 language stack, a hand-written sm_89 block-128 GEMM/GEMV, and the
offline quantizer + config-driven generalization that bring up the 2B.
This is a clean re-cut of the earlier prototype branch onto current
main,reorganized into reviewable commits with the file scope aligned to the SM120
Qwen3-VL pattern (dedicated
flash_rt_qwen3_vl_kernelsmodule; no centralbindings.cppchurn; iteration/benchmark harnesses kept out of the PR).Why hand-written (no TMA on Ada)
The SM120 Qwen3-VL GEMM runs through the CUTLASS
KernelTmaWarpSpecializedBlockwisecollective — TMA bulk-copy + awarp-specialized producer/consumer pipeline with an auto-selected deep
(3-4 stage) software pipeline that hides load latency without spending
registers or occupancy on staging.
Ada (sm_89) has no TMA and no warp-specialized CUTLASS collective (those
builders are Sm90+/Sm120 only), so that design does not port:
cp.async+ldmatrix.x4+ block-128-scaling MMAkernel (
mma.sync...m16n8k32...e4m3.e4m3.f32, no.kind::f8f6f4). Withcp.asyncinstead of TMA, each extra pipeline stage costs a full smem buffer;at the tuned 64x64 tile the kernel is already register-limited to 4 CTA/SM, so
a 2-stage pipeline halves occupancy and regresses. It runs single-stage and is
latency-bound. The obvious memory-pattern wins (load/store coalescing,
ldmatrix) are applied; CUTLASS's own Ada blockwise example is slower thanthis kernel at these shapes, so it is not used.
an
hdim64instantiation for the 2B ViT (avoids a 64->96 pad); the FA2 kernelbody is upstream and unmodified.
So the SM89 path matches the SM120 design intent (block-128 FP8, fused
act/norm-quant, ldmatrix MMA) but cannot reuse the TMA/warp-specialized
machinery — the main reason its prefill is slower than the Blackwell NVFP4 path.
Commits
csrc: add SM89 native FP8 block-128 GEMM kernelcsrc: add SM89 block-128 M=1 GEMV for Qwen3-VL decodecsrc: add SM89 Qwen3-VL helper kernels (qk-norm-rope, fp8 block act/norm)build: bind SM89 Qwen3-VL kernels into flash_rt_qwen3_vl_kernelsfa2: add hdim64 instantiation for Qwen3-VL 2B vision attentionfrontend: SM89 Qwen3-VL official-FP8 path (8B + 2B)tools: SM89 FP8 block-128 quantizer + smoke/CPU testsdocs: SM89 Qwen3-VL FP8 (8B + 2B); note no-TMA optimization limitsModule layout
SM89-specific kernels (block-128 GEMM/GEMV, fused act/norm-quant, QK
norm-rope-kvwrite, the ViT bf16 cuBLASLt matmul) build into the dedicated
flash_rt_qwen3_vl_kernelsmodule (FLASHRT_BUILD_QWEN3_VL=ON, nowGPU_ARCH89 or 120), keeping
flash_rt_kernels.sosmall. The frontend resolves namesfrom the dedicated module first, then the generic one — the same dual-module
split the SM120 ViT path already uses.
Build
cmake -S . -B build -DGPU_ARCH=89 -DFLASHRT_BUILD_QWEN3_VL=ON cmake --build build --target flash_rt_kernels flash_rt_fa2 flash_rt_qwen3_vl_kernels -jVerification
Built clean for sm_89 (both modules). End-to-end 2B multimodal smoke
(
scripts/smoke_qwen3_vl_fp8_sm89.py --multimodal --fp8-lm-head, FlashRT.png):cos_vs_eager=1.000000, top token matches eager, prefill ~80 ms, decodecos_vs_eager=1.000000, coherent generation. CPU/CI tests cover the configguard, the block-128 quant round-trip, and the expected quant-linear count
without the multi-GB checkpoint or CUDA.