feat: NVFP4 standard format quantized inference with optimized bitwise decode kernels - #11
Open
AUXStar wants to merge 18 commits into
Open
feat: NVFP4 standard format quantized inference with optimized bitwise decode kernels#11AUXStar wants to merge 18 commits into
AUXStar wants to merge 18 commits into
Conversation
Add INT8 weight quantization support for RWKV-7 v3a inference engine: - New CUDA kernels: int8 GEMV (M=1/2), 4-wide K-loop GEMM (M>=3), vectorized dequant (8-wide int32 load + half2 write) - Offline quantization tool (per-channel symmetric INT8) - Dispatch optimization: group-aware INT8 threshold (att/head <=16, ffn_key <=12), RowTile/OutTile tuning (M<=4 -> (4,4), M>4 -> (8,2)) - 4-wide K loop reduces loop count by 50% for K%4==0 - Head dequant 13x faster, total dequant 30% faster B=128 throughput: 553 -> 979 tok/s (+77%) B=64 throughput: 852 -> 1013 tok/s (+19%) 1x4 prefill: 36% faster than 2-wide baseline
- Migrate from bitsandbytes NF4 to standard NVFP4 (E2M1 + E4M3 block scale + FP32 tensor scale) - Add e2m1_decode_f() and e2m1_decode_h() bitwise IEEE 754 decode (FP32/FP16) - Replace all constant-memory LUT lookups with bitwise decode to eliminate warp-level address divergence serialization bottleneck - Add optimized blk16 GEMV kernels (uint2 vectorized, 1-warp, K%16 aligned) for M=1 and M=2 decode paths - Update quantize_nf4.py to generate standard NVFP4 format - Update dispatch in rwkv7_fast_v3a.py to use optimized blk16 kernels Performance (2.9B model, RTX 5070 Ti Laptop): - T=1 decode: 71.69 -> 207 tok/s (2.9x) - T=16: 574 -> 983 tok/s (1.7x) - Kernel bandwidth: 80 -> 350 GB/s (4.4x) - VRAM: 3.40 GiB (unchanged) Performance (7.2B model): - T=1 decode: 106 tok/s - T=128: 797 tok/s - VRAM: 6.02 GiB (from 14GB original) - CosSim: ~0.9952 across all 192 quantized weights
This reverts commit 4adf2ea.
This reverts commit 4bbe65d.
This reverts commit c6a859e.
… count > SM limit, data dependencies block fusion)
- Replace 16x e2m1_decode_f (bitwise) + fmaf with shared mem byte→__half2 LUT - Use __hfma2 for FP16 block accumulation (8 instr instead of 16 fmaf) - Apply block scale once per block instead of per element - FP32 cross-block accumulation preserves precision - Both row1 and rkv fused kernels optimized 13.3B decode B=1: 19.35ms → 17.50ms (-9.6%, +10.6% tok/s) 51.7 → 57.1 tok/s
- Increase OutTile from 2 to 4: each block produces 4 outputs instead of 2 - x vector loaded once per block, reused 4x instead of 2x - Block count halved: 2048→1024 for N=4096 (row1), 6144→3072 (rkv) - OutTile=8 tested but causes register spilling (24ms vs 16ms) - OutTile=4 is sweet spot: 4 FP32 acc + 4×8 weight temps fit in registers 13.3B decode B=1: 17.50ms → 16.25ms (-7.1%, +7.7% tok/s) Combined v1→v2+OutTile4: 19.35ms → 16.25ms (-16.0%, +19.0% tok/s) 51.7 → 61.5 tok/s
- 2.9B: 174.8 tok/s (B=1), 130.0 tok/s (B=2) - 7.2B: 98.4 tok/s (B=1), 72.0 tok/s (B=2) - 13.3B: 63.4 tok/s (B=1), 39.2 tok/s (B=2) - All models pass correctness (no NaN/Inf) - 13.3B B=1: 51.7→63.4 tok/s (+22.6% vs v1)
Root cause: NVFP4 cmix kernel expects [F, C/2] layout but weights stay [C, F/2]. Fix: dequant -> transpose -> requant to NVFP4 [F, C/2]. Preserves NVFP4 format. Also fix dense path (T>19): dequant with transpose=False since weight is already [F, C/2]. Tested: 2.9B loss=1.79 VRAM=2.91GB, 7.2B loss=1.63 VRAM=7.09GB, 13.3B loss=1.54 VRAM=11.03GB
Author
Fix: NVFP4 cmix kernel weight layout mismatch (transpose-requant)Root CauseNVFP4 cmix kernel ( FixDuring weight preprocessing, for each NVFP4
Preserves NVFP4 format, zero VRAM increase. Test Results (all 3 model sizes, RTX 5070 Ti Laptop 12GB)
Generation sample (7.2B): "The meaning of life is to find your gift. The purpose of life is to give it away." – Pablo Picasso Commit: |
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.
NVFP4 量化推理 + GEMV kernel 优化
变更概述
在 RWKV-7 v3a 推理引擎上实现 NVFP4 (E2M1 + E4M3 block scale + FP32 tensor scale) 4-bit 量化推理,并逐步优化 decode 性能。
优化历程
Phase 1-4: 推理路径融合
Phase 6: NVFP4 GEMV kernel 优化
性能测试结果
硬件: RTX 5070 Ti Laptop (12GB GDDR7, 448 GB/s, sm_120)
13.3B kernel 优化前后对比 (B=1):
带宽利用率: 96.1% (HBM 8.35GB/tok, 理论 18.6ms)
正确性
新增文件
quantize_stream.py: mmap 流式量化工具 (13.3B 量化 171 秒,峰值 12.9GB RAM)约束
head.weight保持 FP16 (防止 RL 训练崩坏)ffn.value.weight走 NVFP4 cmix_sparse kernel详细报告
完整性能报告见
docs/features/nvfp4/performance_report.md