Skip to content
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
danieldk merged 6 commits into
mainfrom
torch-compile-example
Sep 4, 2025
Merged

Add a full ReLU example with backprop and torch.compile support#206
danieldk merged 6 commits into
mainfrom
torch-compile-example

Conversation

@danieldk

@danieldk danieldk commented Sep 3, 2025

Copy link
Copy Markdown
Member

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.

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 sayakpaul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be a NaN check? 👀 Probably not necessary in this case.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread examples/relu-backprop-compile/tests/test_relu.py
@danieldk danieldk merged commit 207827d into main Sep 4, 2025
9 checks passed
@danieldk danieldk deleted the torch-compile-example branch September 4, 2025 13:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants