This repository was archived by the owner on Apr 6, 2026. It is now read-only.
Add a full ReLU example with backprop and torch.compile support#206
Merged
Conversation
The existing `examples/relu` is made to be as simple as possible, using the absolute minimum to get a CUDA/ROCm/XPU kernel working. However, real-world kernels often also have to provide backprop and `torch.compile` support. This change adds an example of an extended ReLU kernel that can backpropagate and can be compiled with `torch.compile`.
sayakpaul
approved these changes
Sep 4, 2025
sayakpaul
left a comment
Member
There was a problem hiding this comment.
Thanks! Just very minor comments.
Could be also worthwhile adding a note about the test suite (particularly mentioning the torch.compile test).
|
|
||
| TORCH_CHECK(input.device() == grad_output.device(), | ||
| "input and grad_output must be on the same device"); | ||
|
|
Member
There was a problem hiding this comment.
Should there be a NaN check? 👀 Probably not necessary in this case.
Member
Author
There was a problem hiding this comment.
I think it's nicer to do NaN checks outside kernels, so that users can decide when they want to pay the cost for doing another iteration over the data.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The existing
examples/reluis made to be as simple as possible, using the absolute minimum to get a CUDA/ROCm/XPU kernel working. However, real-world kernels often also have to provide backprop andtorch.compilesupport.This change adds an example of an extended ReLU kernel that can backpropagate and can be compiled with
torch.compile.