Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"typing_extensions>=4.10",
"ml-dtypes",
)
ONNX = "onnx==1.17"
ONNX = "onnx==1.18"
ONNX_RUNTIME = "onnxruntime==1.23.0"
PYTORCH = "torch==2.7.1"
TORCHVISON = "torchvision==0.22.1"
Expand Down
4 changes: 3 additions & 1 deletion onnxscript/rewriter/rules/common/_fuse_relus_clips.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ def extract_min_max(self, node: ir.Node):
min_clip = min_input.const_value.numpy()

if len(node.inputs) > 2:
max_clip = node.inputs[2].const_value.numpy()
max_clip = node.inputs[2]
if max_clip is not None:
max_clip = max_clip.const_value.numpy()
Comment thread
justinchuby marked this conversation as resolved.

return min_clip, max_clip, dtype

Expand Down
36 changes: 30 additions & 6 deletions onnxscript/rewriter/rules/common/_fuse_relus_clips_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@
import parameterized
from onnx_ir.passes.common import onnx_checker, shape_inference

from onnxscript.rewriter import (
MatchingTracer,
MatchStatus,
RewriteRule,
testing,
)
from onnxscript.rewriter import MatchingTracer, MatchStatus, RewriteRule, testing
from onnxscript.rewriter.rules.common import _fuse_relus_clips
from onnxscript.rewriter.rules.common._fuse_relus_clips import (
successive_clip_relu_rule,
Expand Down Expand Up @@ -206,6 +201,35 @@ def test_successful_fuse_successive_relu_clip_no_min(self, _, nodes):
""")
self.run_test(model, expected_op_types=["Clip"])

@parameterized.parameterized.expand(
[
(
"relu_then_clip",
"""
x1 = Relu(X)
Y = Clip(x1,min,"")
""",
),
(
"clip_then_relu",
"""
x1 = Clip(X,min,"")
Y = Relu(x1)
""",
),
]
)
def test_successful_fuse_successive_relu_clip_no_max(self, _, nodes):
model = ir.from_onnx_text(f"""
< ir_version: 10, opset_import: ["" : 20] >
test_model (float[N, 32, 14] X) => (float [N, ?, ?] Y)
<float min = {{1.0}}>
{{
{nodes}
}}
""")
self.run_test(model, expected_op_types=["Clip"])

@parameterized.parameterized.expand(
[
(
Expand Down
Loading