[RFC] 具有前向/后向共同优化的全流水线 SwiGLU MLP
Summary
I have implemented Flash SwiGLU MLP, a Triton-based SwiGLU MLP that co-optimizes the complete forward and backward dataflow rather than only the element-wise SiLU-and-gating stage. The current LigerSwiGLUMLP keeps gate_proj, up_proj, and down_proj as nn.Linear modules and applies LigerSiLUMulFunction to the outputs of the first two projections. This implementation explores a broader fusion boundary:
- fuse the gate and up projections with SiLU and element-wise gating;
- store
A,G, andUin one contiguous buffer; - avoid materializing the full
dAtensor during backward; - overwrite expired
G/Ustorage withdG/dU; - aggregate the
dWganddWucomputations into one GEMM; - compute
dIin one fused kernel with a single accumulator; - use a dedicated no-grad path that does not save
G/U. Across the complete benchmark set, most measured end-to-end training speedups are in the 5%–15% range compared withLigerSwiGLUMLP. The no-grad inference path also uses substantially less intermediate memory, although training-memory behavior is shape-dependent. - Repository: https://GitHub.com/Pearblossom-M/flash-swiglu-mlp
- Technical report: https://GitHub.com/Pearblossom-M/flash-swiglu-mlp/blob/main/flash-swiglu-mlp-technical-report.en.pdf
Question for maintainers
Would an implementation with this fusion scope be appropriate for Liger Kernel? I would mainly appreciate feedback on whether this broader fusion scope is interesting and fits the project's goals.
Validation environment
- GPU: RTX 5060 Ti 16 GB (SM120)
- Driver: 580.159.03
- CUDA: 13.1
- PyTorch: 2.13.0
- Triton: 3.7.1
- Liger Kernel: 0.8.1
- Dtypes: BF16 and FP16; the tables below show BF16
- Training shapes:
(D, H) ∈ {(1024, 2816), (2048, 5632), (4096, 11008)}B = 8S ∈ {256, 512, 1024, 2048, 4096, 8192}
- Inference shapes:
B = 1- effective request count
S ∈ {1, 2, 4, 8, 16, 32, 64, 128, 256}The main GEMM kernels use Triton's host-sideTensorDescriptorAPI. I have only benchmarked the implementation on SM120, so I am not yet making portability or performance claims for other GPU architectures.
Training results: forward + backward, BF16, B=8
| D → H | S | Flash SwiGLU | Liger | torch.compile |
Speedup vs. Liger |
|---|---|---|---|---|---|
| 1024 → 2816 | 2048 | 17.25 ms (49.3 TFLOPS) | 19.59 ms | 19.68 ms | 1.14× |
| 1024 → 2816 | 8192 | 70.00 ms (48.6 TFLOPS) | 78.93 ms | 79.16 ms | 1.13× |
| 2048 → 5632 | 4096 | 137.96 ms (49.3 TFLOPS) | 149.80 ms | 149.99 ms | 1.09× |
| 4096 → 11008 | 8192 | 1049.66 ms (50.7 TFLOPS) | 1136.68 ms | 1136.79 ms | 1.08× |
These are representative rows; the linked report contains the complete plots and methodology. Each benchmark uses 10 warm-up iterations and reports the mean of 50 measured …
内容来源: linkedin/Liger-Kernel