Repository navigation
Conversation
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
The shared diffusion FFN MLP (runtime/layers/mlp.py, used by Wan2.2, HunyuanVideo, Hunyuan3D, Helios, JoyImage, MOVA, ...) computed gelu_pytorch_tanh(fc_in(x)) as a standalone GEMM followed by a separate, bandwidth-bound GELU kernel over the [tokens, mlp_hidden] intermediate. Route it through the existing cublasLt GELU-epilogue helper linear_gelu_tanh (already used by flux.py) so the bias-add + tanh-GELU fold into the fc_in GEMM epilogue, removing the extra kernel launch and the intermediate HBM round-trip. Only the tanh-approx GELU path is fused; other activations keep the exact reference path, and the helper guards fall back when not applicable. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
(This PR wires the shared CI consistency failure: root-cause analysis (it's a stale-GT / rounding issue, not a correctness bug)The 1. The cublasLt epilogue is the tanh-approx GELU (not erf): 2. The fused path is closer to the fp32 ground truth than the unfused reference (Qwen FFN shape, bf16):
The unfused path rounds the GEMM result to bf16 before GELU (double rounding); the fused path keeps fp32 through bias+GELU and rounds once. So the fused output is the more precise one — but it differs from the stored GT, which was generated with the lower-precision unfused path. 3. Same-seed end-to-end is essentially identical on a normal prompt ( The large CI delta (e.g. Conclusion / proposed resolution: the fusion is correct and faster; the failure is that the consistency GT was baked with the lower-precision double-rounded path. The clean fix is to refresh the ground-truth for the affected cases against the fused output (the same path #28166 effectively took), or to gate the fusion off for cases where the GT cannot be refreshed. Happy to regenerate the GT ( |
|
Closing this PR because the fused GELU path changes diffusion outputs too much; we want to stay closer to the original model behavior. |
Summary
The shared diffusion FFN
MLP(python/sglang/multimodal_gen/runtime/layers/mlp.py) — used by Wan2.2 (T2V / TI2V / causal), HunyuanVideo, Hunyuan3D, Helios, JoyImage and MOVA — computedgelu_pytorch_tanh(fc_in(x))as a standalone GEMM followed by a separate, bandwidth-bound GELU kernel over the[tokens, mlp_hidden]intermediate.This routes the tanh-GELU FFN through the existing cublasLt GELU-epilogue helper
linear_gelu_tanh(runtime/layers/fused_linear_act/gelu.py, already used byflux.py), folding the bias-add + tanh-GELU into thefc_inGEMM epilogue (torch._addmm_activation(..., use_gelu=True)). This removes the extra kernel launch and the HBM round-trip of the MLP intermediate.act_type == "gelu_pytorch_tanh") is fused; every other activation keeps the exact reference path.fc_in(x)+F.gelu(approximate="tanh").This is the same mechanism already shipped for FLUX; this PR extends it to the shared
MLPFFN so every model that uses it benefits.Benchmark
Wan2.2-TI2V-5B, 1280×720, 81 frames, 50 steps, B200,
--enable-torch-compile --warmup, isolated HF cache. Denoise latency reported as steady-state per-step (steps 5–49; step 0 excluded as the one-time compile spike).Command shape:
Per-run steady-state median (ms/step):
(steady-state per-step variance is < 0.3 ms within each side; the speedup is consistent run-to-run.)
Mechanism: the fused path removes the standalone
triton_poi_fused_gelukernel, which is 3.9% of denoise GPU time in the baseline torch.profiler trace; at Wan's FFN shape the MLP forward itself is 1.10–1.13× faster in isolation (compiled microbench).Generated Video Check
Same prompt / input image / seed (42), main vs PR.
Columns: main | PR | 10× absolute diff. Side-by-side video: https://github.com/BBuf/sglang/raw/kda/diffusion-gelu-artifacts/mlp-fused-gelu/wan_ti2v_side_by_side.mp4
Per-frame difference over all 81 frames:
publish_diffusion_gt.py)The output is a perceptually-equivalent sample, not bit-identical: the bf16-level epilogue difference propagates through the 50-step denoise trajectory, so the residual differences concentrate on high-frequency edges (only visible at 10× amplification). Both diffusion-CI quality thresholds (SSIM ≥ 0.20, mean_abs_diff ≤ 45) pass by a wide margin.
Validation
Checklist
fused_linear_acthelper.CI States
Latest PR Test (Base): ❌ Run #27602521664
Latest PR Test (Extra): ❌ Run #27602534758