Conversation
Signed-off-by: nayanp38 <nayanp@seas.upenn.edu>
Signed-off-by: nayanp38 <nayanp@seas.upenn.edu>
10a8af8 to
7f944c3
Compare
|
Rebased onto current Something I noticed after the rebase: cuTile geglu imports |
|
Hi @nayanp38, thanks for digging into this! |
|
Of course! Thank you for letting me know and I'll make those changes when the backward lands. |
|
Hey @hannahli-nv, I've been looking over the GELU forward/backward pipeline with the new commits landing. Doesn't seem like any of them are relevant to this pr, but I had two quick questions on things I found:
Just wanted to ask if the above two are intended? I'm happy to apply fixes when I rebase, just let me know. Thank you! |
|
Hi @nayanp38, sorry for the late reply, and thank you for digging into this. Both of the things you spotted are real bugs, not intentional.
Thanks again for flagging both. |
Description
Problem:
When using
approximate="none", the tanh approximation of GELU is calculated rather than the exact GELU in both cuTile (standard_normal_cdf_ct) and tilecpp (normal_cdf_f32).Further, the cuTile kernel calculates intermediate values in the storage dtype while tilecpp casts to fp32. This causes noticeable cancellations on negative inputs on bf16/fp16:
x = [-2.0, -2.5, -3.0, -3.5, -4.0] (bf16)
exact (fp64): [-0.04550, -0.01552, -0.00405, -0.00081, -0.00013]
cutile: [-0.04688, -0.01465, -0.00586, 0.00000, 0.00000] <-
tilecpp: [-0.04541, -0.01508, -0.00363, -0.00062, -0.00007]
The defect seems to be invisible to
test_gelu.py, whose atol is too loose under the inputs spanning [-2.3, -1.8].Changes:
test_gelu.pyand tighten tolerancesbench_gelu.py, structured nearly identically tobench_silu_and_mul.pyTanh mode is unchanged (but now recieves fp32 input in cuTile, resolving some fails on the tightened
test_gelu.pyfound below).Results:
Max error vs fp64 reference on inputs from [-6, 6]:
Now, we have backend agreement within <= 1 ULP on all inputs. I also tightened the tolerances and widened input ranges under
test_gelu.pyto reflect these changes, giving 2 output ULPs per dtype. The tests pass here but fail on the previous (currentmain) branch in 8 cases:No performance losses were measured on my RTX 3060ti (all measurements within +/- 1% before vs. after). Ran on the following env:
WSL2 Ubuntu 24.04
CUDA Toolkit 13.3
cuda-tile 1.5.0,
torch 2.9.1+cu130
triton 3.5.1
Not addressed here: running tanh on fp16 with M=1024 resulted in ~15-35 GB/s for both backends, both before and after these changes. All other tests were in the 380-400 GB/s range on my hardware However, in isolation (with a warmup), it runs at 385 GB/s (same as pyTorch). I'm unsure about why this specifically happens in this case, but possibly a point for future investigation or changes to
bench_gelu.pyto add a warmupCI Configuration
Checklist
./format.sh)