-
Notifications
You must be signed in to change notification settings - Fork 37
Add backward pass for softmax kernel #744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
stack-info: PR: #744, branch: karthickai/stack/4
656fba4
to
3e31a31
Compare
examples/softmax.py
Outdated
m, n = grad_output.size() | ||
grad_input = torch.empty_like(grad_output) | ||
|
||
block_size_m = hl.register_block_size(m) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it is not need, I followed the implementation from softmax two pass, now I've updated the code.
stack-info: PR: #744, branch: karthickai/stack/4
3e31a31
to
d5f0d11
Compare
x: torch.Tensor, | ||
) -> torch.Tensor: | ||
"""Softmax with forward + backward support.""" | ||
return SoftmaxFunction.apply(x) # type: ignore[no-any-return] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you like to also add integration in benchmarks/run.py
(similar to rms_norm-bwd
), and test accuracy via tritonbench --metrics accuracy
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
backward pass for softmax
is disabled in tritonbench. I enabled it in this PR meta-pytorch/tritonbench#528 and added softmax-bwd
in benchmarks/run.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HELION_USE_DEFAULT_CONFIG=1 python benchmarks/run.py --op softmax-bwd --num-inputs 3 --metrics accuracy
(M, N) triton_softmax-accuracy quack-accuracy torch_compile_softmax-accuracy helion_softmax_tritonbench-accuracy
----------- ------------------------- ---------------- -------------------------------- -------------------------------------
(4096, 256) 1 1 1 1
(4096, 384) 1 1 1 1
(4096, 512) 1 1 1 1
average 1 1 1 1
HELION_USE_DEFAULT_CONFIG=1 python benchmarks/run.py --op softmax --num-inputs 3 --metrics accuracy
(M, N) triton_softmax-accuracy quack-accuracy torch_compile_softmax-accuracy helion_softmax_tritonbench-accuracy
----------- ------------------------- ---------------- -------------------------------- -------------------------------------
(4096, 256) 1 1 1 1
(4096, 384) 1 1 1 1
(4096, 512) 1 1 1 1
average 1 1 1 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update: tirtonbench softmax-bwd is landed meta-pytorch/tritonbench#528
stack-info: PR: #744, branch: karthickai/stack/4
d5f0d11
to
2c155fd
Compare
stack-info: PR: #744, branch: karthickai/stack/4
2c155fd
to
62bbc0e
Compare
Stacked PRs:
Add backward pass for softmax kernel