feat(fp8): E4M3 fused dequant-linear kernel + FP8 quantized-linear slice (RFC 0001) - #526
Open
CAICAIIs wants to merge 1 commit into
Open
feat(fp8): E4M3 fused dequant-linear kernel + FP8 quantized-linear slice (RFC 0001)#526CAICAIIs wants to merge 1 commit into
CAICAIIs wants to merge 1 commit into
Conversation
CAICAIIs
force-pushed
the
perf/e4m3-cuda-kernel
branch
3 times, most recently
from
August 26, 2026 17:53
1cebd8f to
5d8b944
Compare
Add a forward-only WMMA (16x16x16 fp16 tensor-core) kernel that reads a 1-byte uint8 E4M3 weight payload, decodes each byte to fp16 in shared memory (fast bit-decode), and applies a per-tensor scalar scale after the dot -- the memory-bandwidth benefit from RFC 0001 for decode/inference. - csrc/e4m3_linear.cu: fused dequant-GEMM + registration. - kernels/e4m3_cuda.py: CUDA shim (quantized_e4m3_linear_cuda) + quantize/dequant helpers. - tests/test_e4m3_decode_cpu.py: CPU decode reference vs torch.float8_e4m3fn. - setup.py: compile the new .cu. Forward-only (no backward): E4M3 must not be wired into a training graph. Opt-in and backward-compatible; the model hook is not yet switched to this path.
CAICAIIs
force-pushed
the
perf/e4m3-cuda-kernel
branch
from
August 27, 2026 01:45
5d8b944 to
837437c
Compare
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
Adds the FP8 weight-quantization vertical slice (RFC 0001, M1) and an E4M3 fused dequant-linear CUDA kernel for the memory-bound decode path.
Decode re-reads the full weight tensor from HBM for every generated token, so it is memory-bandwidth-bound. Storing the weight as 1-byte E4M3 FP8 halves the weight bytes read, which is the memory-bound benefit from RFC 0001. On Hopper / H20 the built-in
torch._scaled_mmFP8 path delivers 1.53–1.72× decode speedup vs bf16; on Ampere / A100 (which has no built-in FP8 matmul) a custom E4M3 dequant-linear kernel is provided.quant_methodis opt-in and unchanged by default ("none"); unmarked weights keep the existing bf16 path.Motivation
On the 8×A100 node, decode is weight-read-bound and compute sits idle. Quantizing weights to FP8 (1 byte) vs bf16 (2 bytes) halves the weight-read bytes. This PR lands the M1 vertical slice: an opt-in FP8 decode path + an Ampere E4M3 kernel, both forward-only.
Changes
areno/accel/csrc/e4m3_linear.cu— E4M3 fused dequant-linear. A branchless bit-trick decode (validated byte-for-byte vstorch.float8_e4m3fn) plus:M <= 4) memory-streaming GEMV: one warp streams one weight row with coalesced 8-byte loads, reuses the staged activation, and reduces with warp shuffles;M > 4.Per-tensor scalar scale applied once post-dot.
areno/accel/kernels/e4m3_cuda.py—quantized_e4m3_linear_cudashim + quantize/dequant helpers, with anout-buffer reuse for the hot decode path.areno/engine/quantization.py— FP8 (E4M3) scale/quantize/dequant reference, CPU-portable.areno/engine/layers/linear.py—QuantizedLinear(W8A16 dequant-forward reference) +_areno_linear_forwardroutes FP8-marked weights; unmarked weights unchanged.areno/engine/{config,modeling,worker}.py—quant_method/quant_group_size(opt-in),quantize_model_weights_fp8, and a guard that rejectsquant_method='fp8'in a train worker (forward-only, no backward).areno/accel/kernels/fp8_linear.py— the model's E5M2 W8A16 Triton dequant-linear (the grid Triton accepts on Ampere).setup.py/areno/accel/csrc/extension.cpp— register the new kernel (optionaloutarg).tests/test_e4m3_decode_cpu.py,tests/test_fp8_quant_cpu.py(decode formula vs torch, quant/dequant round-trip,QuantizedLinearreference, opt-in default).scripts/bench/{e4m3_cuda_bench,h20_fp8_scaled_mm,fp8_end_to_end_bench,triton_fp8_matmul_bench}.py.docs/rfcs/0001-weight-quantization-fp8-int4.md— design, gates, measured results.Testing
pytest tests/test_e4m3_decode_cpu.py tests/test_fp8_quant_cpu.py→ 11 passed.torch._scaled_mmFP8 E4M3 → 1.53–1.72× vs bf16 (RFC §4.8).Known limitations
worker.py)._scaled_mmpath._scaled_mmresult.Related
docs/rfcs/0001-weight-quantization-fp8-int4.md