Export aten::relu6 as a single Clip op - #2987
Merged
Merged
Conversation
Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Improve ONNX export for relu6 layer to use Clip
Export aten::relu6 as a single Clip op
Aug 3, 2026
justinchuby
marked this pull request as ready for review
August 4, 2026 17:17
justinchuby
enabled auto-merge (squash)
August 4, 2026 17:17
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves the ONNX export of aten::relu6 by emitting a single Clip op (with min=0, max=6) instead of the previous Relu + Min pair, aligning the export with ONNX’s native clamp representation and avoiding reliance on downstream fusion.
Changes:
- Update
aten_relu6to returnop.Clip(self, zero, six)rather thanop.Min(op.Relu(self), six). - Ensure
Clipbounds are cast to the input dtype viaCastLike.
titaiwangms
approved these changes
Aug 4, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2987 +/- ##
=======================================
Coverage 72.63% 72.63%
=======================================
Files 265 265
Lines 32204 32205 +1
Branches 3041 3041
=======================================
+ Hits 23391 23392 +1
Misses 7779 7779
Partials 1034 1034 ☔ View full report in Codecov by Harness. |
justinchuby
approved these changes
Aug 4, 2026
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
aten::relu6was exported as aRelu+Minpair, which relies on downstream fusion to become a single clamp. ONNX hasClip, which expresses this directly.Changes
onnxscript/function_libs/torch_lib/ops/nn.py:aten_relu6now emitsClip(self, 0, 6)with bounds cast to the input dtype.Benchmark
Measured on onnxruntime CPU EP (float32, 500 iterations, mean per-run latency) per the issue's request to confirm which form is faster:
ClipRelu+MinClipis ~2–4x faster unfused, so the single-op form is preferable even before any graph optimization.