Context
Spun out of RFC #749 (a contribution path for FlyDSL kernels into downstream OSS libraries). While analyzing the quack rmsnorm interface gap, we confirmed FlyDSL's norm family is forward-only:
kernels/rmsnorm_kernel.py and kernels/layernorm_kernel.py expose only build_* / launch_* forward paths.
- There are no
*bwd* / *backward* / *grad* files under kernels/, and a repo-wide autograd search returns 0.
- FlyDSL's own
tests/kernels/test_rmsnorm.py exercises forward only (no gradient checks).
This is expected for an inference kernel library, but it is the blocker for training use cases and for backing a training-capable library (quack).
Goal
Add a correct, performant rmsnorm backward so FlyDSL can serve training, and so the downstream-backend PoC in #749 can target fwd+bwd rather than forward-only.
Scope / tasks
- Backward kernel — compute
dx, dweight (and dbias if bias is added). Accumulate weight/bias partials in fp32 for numerical accuracy (cf. quack's rmsnorm_bwd: per-SM fp32 partials, then reduce).
- Forward must save backward state — the current forward does not emit
rstd (the per-row 1/RMS). Backward needs it, so add an optional store_rstd / rstd output to the forward path instead of recomputing.
- Autograd wrapper — a
torch.autograd.Function (forward saves x, weight, rstd; backward calls the new kernel) so quack-style call sites get gradients transparently.
- Fused-add (residual / prenorm) backward —
kernels/rmsnorm_kernel.py already has a separate fused-add forward module; backward should handle the residual path too (grad w.r.t. residual_out).
- Tests — extend
tests/kernels/test_rmsnorm.py with gradient checks against a torch reference (bf16 / fp16 / fp32; several M/N including the N<=2048 small-N path). Reuse quack's tolerance style.
- (stretch) layernorm backward — same pattern; can be a follow-up.
Why now
Direct enabler for #749 (training-capable downstream integration). Without this, any "fwd+bwd parity" with quack is net-new kernel work rather than interface adaptation.
Refs
Context
Spun out of RFC #749 (a contribution path for FlyDSL kernels into downstream OSS libraries). While analyzing the quack
rmsnorminterface gap, we confirmed FlyDSL's norm family is forward-only:kernels/rmsnorm_kernel.pyandkernels/layernorm_kernel.pyexpose onlybuild_*/launch_*forward paths.*bwd*/*backward*/*grad*files underkernels/, and a repo-wideautogradsearch returns 0.tests/kernels/test_rmsnorm.pyexercises forward only (no gradient checks).This is expected for an inference kernel library, but it is the blocker for training use cases and for backing a training-capable library (quack).
Goal
Add a correct, performant rmsnorm backward so FlyDSL can serve training, and so the downstream-backend PoC in #749 can target fwd+bwd rather than forward-only.
Scope / tasks
dx,dweight(anddbiasif bias is added). Accumulate weight/bias partials in fp32 for numerical accuracy (cf. quack'srmsnorm_bwd: per-SM fp32 partials, then reduce).rstd(the per-row 1/RMS). Backward needs it, so add an optionalstore_rstd/rstdoutput to the forward path instead of recomputing.torch.autograd.Function(forward savesx,weight,rstd; backward calls the new kernel) so quack-style call sites get gradients transparently.kernels/rmsnorm_kernel.pyalready has a separate fused-add forward module; backward should handle the residual path too (grad w.r.t.residual_out).tests/kernels/test_rmsnorm.pywith gradient checks against a torch reference (bf16 / fp16 / fp32; several M/N including the N<=2048 small-N path). Reuse quack's tolerance style.Why now
Direct enabler for #749 (training-capable downstream integration). Without this, any "fwd+bwd parity" with quack is net-new kernel work rather than interface adaptation.
Refs
rmsnorm_bwd(quack/rmsnorm.py:1252),RMSNormFunction(:1368).build_rmsnorm_module(kernels/rmsnorm_kernel.py:113), forward has norstdoutput;launch_fused_add_rmsnorm(:604).