Fp8 support#65
Open
bdepyzy wants to merge 15 commits into
Open
Conversation
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.
Add plumbing for per-tensor fp8 expert GEMM
Adds per-tensor
float8_e4m3fnsupport for the MoE expert GEMMs, forward and backward, behinduse_fp8=True.What it does
data_ptr+_version, auto-invalidated after optimizer steps). Runs fp8 grouped GEMMs viagemm/gemm_gated, then descales with.mul_().dx,dw1,dw2,dh,dsviagemm/gemm_dgated, descaled with.mul_().torch2cute_dtype_mapto cover fp8 (the CuTe kernels already support fp8 element types, but the Python dispatch layer doesn't map it by default).fp8 is currently slower than bf16. The fp8 GEMMs themselves are ~2x faster, but per-tensor fp8 requires descaling each GEMM output by its activation×weight scale before the nonlinear GLU, and since those separate
.mul_()passes are memory-bound and dominate at these shapes. This descale is fundamental to per-tensor fp8 (it cannot be folded throughswiglu).I have a working speedup of ~1.35x, but it requires folding the descale into the GEMM epilogue, something that quack doesn't currently expose. With that, the descale passes disappear and fp8's 2x compute advantage wins. This PR is the sonicmome-side plumbing; switching from
.mul_()toalpha=is a one-line-per-call change once quack supports it. If this PR into sonicmoe is good, then I will open a PR into quack to make this faster.Correctness: fp8 fwd+bwd matches bf16 within per-tensor fp8 tolerance ~2–3% mean rel error across output and gradients (test asserts
rtol=0.2).