From 22845c4d1a4ea21fe2af4a7d9a8075edb3190b4f Mon Sep 17 00:00:00 2001 From: Hardik Kaurani Date: Sun, 1 Nov 2026 13:52:43 +0530 Subject: [PATCH 1/7] test(rewriter): add regression tests for cast string in cast_constant_of_shape --- .../common/_cast_constant_of_shape_test.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/onnxscript/rewriter/rules/common/_cast_constant_of_shape_test.py b/onnxscript/rewriter/rules/common/_cast_constant_of_shape_test.py index 9001f95806..2c6f11f59a 100644 --- a/onnxscript/rewriter/rules/common/_cast_constant_of_shape_test.py +++ b/onnxscript/rewriter/rules/common/_cast_constant_of_shape_test.py @@ -49,6 +49,40 @@ def test_cast_after_constant_of_shape_without_value_is_fused(self): output_model_proto = ir.serde.serialize_model(model) onnx.checker.check_model(output_model_proto, True) + def test_cast_to_string_after_constant_of_shape_is_not_fused(self): + """Cast to string should not be fused into ConstantOfShape as string serialization fails.""" + model_text = """ + + agraph (int64[2] input_x) => (string[1, 4] output) + { + constant = ConstantOfShape (input_x) + output = Cast (constant) + } + """ + model = ir.from_onnx_text(model_text) + count = _cast_constant_of_shape.rules.apply_to_model(model) + self.assertEqual(count, 0) + # Verify the model serializes cleanly without SerdeError + output_proto = ir.serde.serialize_model(model) + self.assertIsNotNone(output_proto) + + def test_cast_to_string_after_constant_of_shape_without_value_is_not_fused(self): + """Cast to string without value should not be fused into ConstantOfShape.""" + model_text = """ + + agraph (int64[2] input_x) => (string[1, 4] output) + { + constant = ConstantOfShape (input_x) + output = Cast (constant) + } + """ + model = ir.from_onnx_text(model_text) + count = _cast_constant_of_shape.rules.apply_to_model(model) + self.assertEqual(count, 0) + # Verify the model serializes cleanly without SerdeError + output_proto = ir.serde.serialize_model(model) + self.assertIsNotNone(output_proto) + if __name__ == "__main__": unittest.main() From 953d3767f2aba2f43a43f5647413ef4570d1aa7e Mon Sep 17 00:00:00 2001 From: Hardik Kaurani Date: Sun, 1 Nov 2026 13:53:36 +0530 Subject: [PATCH 2/7] fix(rewriter): prevent fusing Cast to string or ref attr in cast_constant_of_shape --- .../rules/common/_cast_constant_of_shape.py | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/onnxscript/rewriter/rules/common/_cast_constant_of_shape.py b/onnxscript/rewriter/rules/common/_cast_constant_of_shape.py index 8c63d3e777..7e22278d23 100644 --- a/onnxscript/rewriter/rules/common/_cast_constant_of_shape.py +++ b/onnxscript/rewriter/rules/common/_cast_constant_of_shape.py @@ -23,6 +23,22 @@ def fused_cast_constant_of_shape(op, shape: ir.Value, scalar: ir.Attr, dtype: ir return op.ConstantOfShape(shape, value=cast_value) +def check_cast_constant_of_shape(context, shape, scalar, dtype, **_) -> bool: + del context, shape + if dtype.is_ref() or scalar.is_ref(): + return False + if dtype.type != ir.AttributeType.INT: + return False + to_dtype = dtype.as_int() + if to_dtype in (ir.DataType.UNDEFINED, ir.DataType.STRING): + return False + if scalar.type != ir.AttributeType.TENSOR or scalar.value is None: + return False + if scalar.value.size != 1 or scalar.value.dtype == ir.DataType.STRING: + return False + return True + + def cast_constant_of_shape_without_value(op, shape, dtype): constant = op.ConstantOfShape(shape) return op.Cast(constant, to=dtype) @@ -33,10 +49,28 @@ def fused_cast_constant_of_shape_without_value(op, shape, dtype, **_): return op.ConstantOfShape(shape, value=zero) -cast_constant_of_shape_rule = RewriteRule(cast_constant_of_shape, fused_cast_constant_of_shape) +def check_cast_constant_of_shape_without_value(context, shape, dtype, **_) -> bool: + del context, shape + if dtype.is_ref(): + return False + if dtype.type != ir.AttributeType.INT: + return False + to_dtype = dtype.as_int() + if to_dtype in (ir.DataType.UNDEFINED, ir.DataType.STRING): + return False + return True + + +cast_constant_of_shape_rule = RewriteRule( + cast_constant_of_shape, + fused_cast_constant_of_shape, + check_cast_constant_of_shape, +) cast_constant_of_shape_without_value_rule = RewriteRule( - cast_constant_of_shape_without_value, fused_cast_constant_of_shape_without_value + cast_constant_of_shape_without_value, + fused_cast_constant_of_shape_without_value, + check_cast_constant_of_shape_without_value, ) rules = RewriteRuleSet( From dccf069fa4aca7f472715787c08ab8edc2190d26 Mon Sep 17 00:00:00 2001 From: Hardik Kaurani Date: Thu, 5 Nov 2026 09:59:54 +0530 Subject: [PATCH 3/7] fix(rewriter): prevent no-value cast_constant_of_shape fallback from matching explicit values Set _allow_other_attributes=False on ConstantOfShape in the no-value pattern so that ConstantOfShape nodes with explicit value attributes (such as reference attributes or non-scalar tensors rejected by the first rule) do not match the no-value fallback and get erroneously replaced with zero. Also use scalar.as_tensor() for explicit tensor access. Signed-off-by: Hardik Kaurani --- .../rewriter/rules/common/_cast_constant_of_shape.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/onnxscript/rewriter/rules/common/_cast_constant_of_shape.py b/onnxscript/rewriter/rules/common/_cast_constant_of_shape.py index 7e22278d23..51c8231143 100644 --- a/onnxscript/rewriter/rules/common/_cast_constant_of_shape.py +++ b/onnxscript/rewriter/rules/common/_cast_constant_of_shape.py @@ -18,7 +18,7 @@ def cast_constant_of_shape(op, shape, scalar, dtype): def fused_cast_constant_of_shape(op, shape: ir.Value, scalar: ir.Attr, dtype: ir.Attr, **_): # Cast scalar (a TensorProto attribute) to the specified dtype - scalar_value = scalar.value.numpy().item() + scalar_value = scalar.as_tensor().numpy().item() cast_value = ir.tensor([scalar_value], dtype=ir.DataType(dtype.as_int())) return op.ConstantOfShape(shape, value=cast_value) @@ -34,13 +34,14 @@ def check_cast_constant_of_shape(context, shape, scalar, dtype, **_) -> bool: return False if scalar.type != ir.AttributeType.TENSOR or scalar.value is None: return False - if scalar.value.size != 1 or scalar.value.dtype == ir.DataType.STRING: + scalar_tensor = scalar.as_tensor() + if scalar_tensor.size != 1 or scalar_tensor.dtype == ir.DataType.STRING: return False return True def cast_constant_of_shape_without_value(op, shape, dtype): - constant = op.ConstantOfShape(shape) + constant = op.ConstantOfShape(shape, _allow_other_attributes=False) return op.Cast(constant, to=dtype) From 7c8fd73828b9271d368ee499a2012d12508c37e8 Mon Sep 17 00:00:00 2001 From: Hardik Kaurani Date: Thu, 5 Nov 2026 10:00:46 +0530 Subject: [PATCH 4/7] test(rewriter): add regression test for reference attribute preservation in cast_constant_of_shape Add a regression test using the full rewrite rule set verifying that a function containing ConstantOfShape with a reference attribute @fill and a concrete numeric Cast target is not fused and does not fall through to the no-value rule to be replaced with a zero-filled tensor. Signed-off-by: Hardik Kaurani --- .../common/_cast_constant_of_shape_test.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/onnxscript/rewriter/rules/common/_cast_constant_of_shape_test.py b/onnxscript/rewriter/rules/common/_cast_constant_of_shape_test.py index 2c6f11f59a..7a329b93d6 100644 --- a/onnxscript/rewriter/rules/common/_cast_constant_of_shape_test.py +++ b/onnxscript/rewriter/rules/common/_cast_constant_of_shape_test.py @@ -83,6 +83,29 @@ def test_cast_to_string_after_constant_of_shape_without_value_is_not_fused(self) output_proto = ir.serde.serialize_model(model) self.assertIsNotNone(output_proto) + def test_cast_after_constant_of_shape_with_ref_attr_is_not_fused(self): + """Cast after ConstantOfShape with a reference value attribute should not be fused or replaced with zero.""" + model_text = """ + + main_graph (int64[2] shape) => (float[1, 4] output) { + output = pkg.my_func (shape) + } + + my_func (shape) => (output) { + constant = ConstantOfShape (shape) + output = Cast (constant) + } + """ + model = ir.from_onnx_text(model_text) + count = _cast_constant_of_shape.rules.apply_to_model(model) + self.assertEqual(count, 0) + function = next(iter(model.functions.values())) + self.assertEqual([node.op_type for node in function], ["ConstantOfShape", "Cast"]) + constant_node = function[0] + self.assertIn("value", constant_node.attributes) + self.assertTrue(constant_node.attributes["value"].is_ref()) + self.assertEqual(constant_node.attributes["value"].ref_attr_name, "fill") + if __name__ == "__main__": unittest.main() From 6c5329a3db4b5ef7583107eb427c0e5057d56611 Mon Sep 17 00:00:00 2001 From: Hardik Kaurani Date: Thu, 5 Nov 2026 10:01:54 +0530 Subject: [PATCH 5/7] test(rewriter): add regression tests for non-scalar fill value rejection and no-value fusion verification Add regression tests verifying that ConstantOfShape with a non-scalar value attribute (e.g. float[2]) followed by Cast is rejected and not matched by the no-value fallback, and verify numerical equivalence for legitimate no-value ConstantOfShape cast fusion. Signed-off-by: Hardik Kaurani --- .../common/_cast_constant_of_shape_test.py | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/onnxscript/rewriter/rules/common/_cast_constant_of_shape_test.py b/onnxscript/rewriter/rules/common/_cast_constant_of_shape_test.py index 7a329b93d6..76210ae659 100644 --- a/onnxscript/rewriter/rules/common/_cast_constant_of_shape_test.py +++ b/onnxscript/rewriter/rules/common/_cast_constant_of_shape_test.py @@ -1,11 +1,15 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. +from __future__ import annotations + import unittest +import numpy as np import onnx.checker import onnx.parser import onnx_ir as ir +from onnxscript.rewriter import testing from onnxscript.rewriter.rules.common import _cast_constant_of_shape @@ -106,6 +110,41 @@ def test_cast_after_constant_of_shape_with_ref_attr_is_not_fused(self): self.assertTrue(constant_node.attributes["value"].is_ref()) self.assertEqual(constant_node.attributes["value"].ref_attr_name, "fill") + def test_cast_after_constant_of_shape_with_non_scalar_value_is_not_fused(self): + """Cast after ConstantOfShape with a non-scalar value attribute should not be fused.""" + model_text = """ + + agraph (int64[2] input_x) => (float[1, 4] output) + { + constant = ConstantOfShape (input_x) + output = Cast (constant) + } + """ + model = ir.from_onnx_text(model_text) + count = _cast_constant_of_shape.rules.apply_to_model(model) + self.assertEqual(count, 0) + self.assertEqual([node.op_type for node in model.graph], ["ConstantOfShape", "Cast"]) + + def test_cast_after_constant_of_shape_without_value_numerical_correctness(self): + """Verify numerical correctness of legitimate ConstantOfShape without value cast fusion.""" + model_text = """ + + agraph (int64[2] input_x) => (float[1, 4] output) + { + constant = ConstantOfShape (input_x) + output = Cast (constant) + } + """ + original = ir.from_onnx_text(model_text) + model = ir.from_onnx_text(model_text) + count = _cast_constant_of_shape.rules.apply_to_model(model) + self.assertEqual(count, 1) + testing.assert_numerically_equal( + original, + model, + (np.array([1, 4], dtype=np.int64),), + ) + if __name__ == "__main__": unittest.main() From ea0613255bde63128b85bb662a87ba69cd6eaf61 Mon Sep 17 00:00:00 2001 From: Hardik Kaurani Date: Fri, 6 Nov 2026 02:18:00 +0530 Subject: [PATCH 6/7] fix(rewriter): address confirmed nightly CI regression --- .../common/_cast_constant_of_shape_test.py | 83 +++++++++++++++++++ .../function_libs/torch_lib/ops_test_data.py | 45 +++++++++- 2 files changed, 126 insertions(+), 2 deletions(-) diff --git a/onnxscript/rewriter/rules/common/_cast_constant_of_shape_test.py b/onnxscript/rewriter/rules/common/_cast_constant_of_shape_test.py index 76210ae659..7dd11d256f 100644 --- a/onnxscript/rewriter/rules/common/_cast_constant_of_shape_test.py +++ b/onnxscript/rewriter/rules/common/_cast_constant_of_shape_test.py @@ -145,6 +145,89 @@ def test_cast_after_constant_of_shape_without_value_numerical_correctness(self): (np.array([1, 4], dtype=np.int64),), ) + def test_cast_with_ref_attr_to_after_constant_of_shape_is_not_fused(self): + """Cast with reference target dtype attribute should not be fused.""" + model_text = """ + + main_graph (int64[2] shape) => (float[1, 4] output) { + output = pkg.my_func (shape) + } + + my_func (shape) => (output) { + constant = ConstantOfShape (shape) + output = Cast (constant) + } + """ + model = ir.from_onnx_text(model_text) + count = _cast_constant_of_shape.rules.apply_to_model(model) + self.assertEqual(count, 0) + function = next(iter(model.functions.values())) + self.assertEqual([node.op_type for node in function], ["ConstantOfShape", "Cast"]) + + def test_cast_with_ref_attr_to_after_constant_of_shape_without_value_is_not_fused(self): + """Cast with reference target dtype without value should not be fused.""" + model_text = """ + + main_graph (int64[2] shape) => (float[1, 4] output) { + output = pkg.my_func (shape) + } + + my_func (shape) => (output) { + constant = ConstantOfShape (shape) + output = Cast (constant) + } + """ + model = ir.from_onnx_text(model_text) + count = _cast_constant_of_shape.rules.apply_to_model(model) + self.assertEqual(count, 0) + function = next(iter(model.functions.values())) + self.assertEqual([node.op_type for node in function], ["ConstantOfShape", "Cast"]) + + def test_cast_to_undefined_after_constant_of_shape_is_not_fused(self): + """Cast to undefined data type should not be fused into ConstantOfShape.""" + model_text = """ + + agraph (int64[2] input_x) => (float[1, 4] output) + { + constant = ConstantOfShape (input_x) + output = Cast (constant) + } + """ + model = ir.from_onnx_text(model_text) + count = _cast_constant_of_shape.rules.apply_to_model(model) + self.assertEqual(count, 0) + self.assertEqual([node.op_type for node in model.graph], ["ConstantOfShape", "Cast"]) + + def test_cast_to_undefined_after_constant_of_shape_without_value_is_not_fused(self): + """Cast to undefined data type without value should not be fused into ConstantOfShape.""" + model_text = """ + + agraph (int64[2] input_x) => (float[1, 4] output) + { + constant = ConstantOfShape (input_x) + output = Cast (constant) + } + """ + model = ir.from_onnx_text(model_text) + count = _cast_constant_of_shape.rules.apply_to_model(model) + self.assertEqual(count, 0) + self.assertEqual([node.op_type for node in model.graph], ["ConstantOfShape", "Cast"]) + + def test_cast_after_constant_of_shape_with_string_value_is_not_fused(self): + """Cast after ConstantOfShape with a string value tensor should not be fused.""" + model_text = """ + + agraph (int64[2] input_x) => (float[1, 4] output) + { + constant = ConstantOfShape (input_x) + output = Cast (constant) + } + """ + model = ir.from_onnx_text(model_text) + count = _cast_constant_of_shape.rules.apply_to_model(model) + self.assertEqual(count, 0) + self.assertEqual([node.op_type for node in model.graph], ["ConstantOfShape", "Cast"]) + if __name__ == "__main__": unittest.main() diff --git a/tests/function_libs/torch_lib/ops_test_data.py b/tests/function_libs/torch_lib/ops_test_data.py index 15a0cec84c..b91682dcf8 100644 --- a/tests/function_libs/torch_lib/ops_test_data.py +++ b/tests/function_libs/torch_lib/ops_test_data.py @@ -43,6 +43,7 @@ from typing import Any, Callable, Collection, Optional import numpy as np +import packaging.version import torch from torch.testing._internal import common_methods_invocations from torch.testing._internal.opinfo import definitions as opinfo_definitions @@ -58,6 +59,8 @@ from onnxscript.function_libs.torch_lib.ops import vision as vision_ops from tests.function_libs.torch_lib import extra_opinfo, ops_test_common +_IS_TORCH_NIGHTLY = packaging.version.parse(torch.__version__).is_devrelease + # Create a copy of the op_db to modify OPS_DB = copy.deepcopy(common_methods_invocations.op_db) @@ -504,6 +507,16 @@ def _where_input_wrangler( "addbmm", core_ops.aten_addbmm, tolerance={torch.float32: (2e-5, 2e-5), torch.float16: (2e-1, 2e-2)}, + ).xfail( + matcher=lambda sample: ( + len(sample.args) >= 2 + and isinstance(sample.args[0], torch.Tensor) + and isinstance(sample.args[1], torch.Tensor) + and (sample.args[0].numel() == 0 or sample.args[1].numel() == 0) + and sample.kwargs.get("beta") == 0 + ), + reason="fixme: In PyTorch nightly, beta=0 with zero-size reduction dimension does not propagate inf to NaN.", + enabled_if=_IS_TORCH_NIGHTLY, ), TorchLibOpInfo("addcdiv", core_ops.aten_addcdiv, tolerance={torch.float16: (3e-2, 1e-3)}), TorchLibOpInfo("addcmul", core_ops.aten_addcmul, tolerance={torch.float16: (4e-3, 3e-3)}), @@ -596,7 +609,19 @@ def _where_input_wrangler( "https://github.com/microsoft/onnxscript/issues/1007" ) ), - TorchLibOpInfo("baddbmm", core_ops.aten_baddbmm, tolerance={torch.float16: (1e-3, 1e-2)}), + TorchLibOpInfo( + "baddbmm", core_ops.aten_baddbmm, tolerance={torch.float16: (1e-3, 1e-2)} + ).xfail( + matcher=lambda sample: ( + len(sample.args) >= 2 + and isinstance(sample.args[0], torch.Tensor) + and isinstance(sample.args[1], torch.Tensor) + and (sample.args[0].numel() == 0 or sample.args[1].numel() == 0) + and sample.kwargs.get("beta") == 0 + ), + reason="fixme: In PyTorch nightly, beta=0 with zero-size reduction dimension does not propagate inf to NaN.", + enabled_if=_IS_TORCH_NIGHTLY, + ), TorchLibOpInfo("bernoulli", core_ops.aten_bernoulli, nondeterministic=True), TorchLibOpInfo( "bilinear", core_ops.aten_bilinear, tolerance={torch.float32: (2e-5, 2e-5)} @@ -1438,7 +1463,23 @@ def _where_input_wrangler( TorchLibOpInfo("logical_not", core_ops.aten_logical_not), TorchLibOpInfo("logical_or", core_ops.aten_logical_or), TorchLibOpInfo("logical_xor", core_ops.aten_logical_xor), - TorchLibOpInfo("logit", core_ops.aten_logit, tolerance={torch.float16: (1e-1, 7e-4)}), + TorchLibOpInfo( + "logit", core_ops.aten_logit, tolerance={torch.float16: (1e-1, 7e-4)} + ).xfail( + matcher=lambda sample: ( + ( + len(sample.args) > 0 + and isinstance(sample.args[0], (int, float)) + and sample.args[0] > 0.5 + ) + or ( + isinstance(sample.kwargs.get("eps"), (int, float)) + and sample.kwargs["eps"] > 0.5 + ) + ), + reason="fixme: In PyTorch nightly, eps > 0.5 uses ternary clamp min/max evaluation.", + enabled_if=_IS_TORCH_NIGHTLY, + ), TorchLibOpInfo("max_dim", core_ops.aten_max_dim) .xfail( variant_name="reduction_with_dim", From 754c4f86888e0e2c492fdda317b2a46605901e32 Mon Sep 17 00:00:00 2001 From: Hardik Kaurani Date: Fri, 6 Nov 2026 10:35:12 +0530 Subject: [PATCH 7/7] fix(rewriter): remove unrelated nightly xfails and clarify ConstantOfShape STRING output docstrings Signed-off-by: Hardik Kaurani --- .../common/_cast_constant_of_shape_test.py | 4 +- .../function_libs/torch_lib/ops_test_data.py | 45 +------------------ 2 files changed, 4 insertions(+), 45 deletions(-) diff --git a/onnxscript/rewriter/rules/common/_cast_constant_of_shape_test.py b/onnxscript/rewriter/rules/common/_cast_constant_of_shape_test.py index 7dd11d256f..a6e4b82a21 100644 --- a/onnxscript/rewriter/rules/common/_cast_constant_of_shape_test.py +++ b/onnxscript/rewriter/rules/common/_cast_constant_of_shape_test.py @@ -54,7 +54,7 @@ def test_cast_after_constant_of_shape_without_value_is_fused(self): onnx.checker.check_model(output_model_proto, True) def test_cast_to_string_after_constant_of_shape_is_not_fused(self): - """Cast to string should not be fused into ConstantOfShape as string serialization fails.""" + """Cast to string should not be fused into ConstantOfShape as ConstantOfShape does not support STRING output.""" model_text = """ agraph (int64[2] input_x) => (string[1, 4] output) @@ -71,7 +71,7 @@ def test_cast_to_string_after_constant_of_shape_is_not_fused(self): self.assertIsNotNone(output_proto) def test_cast_to_string_after_constant_of_shape_without_value_is_not_fused(self): - """Cast to string without value should not be fused into ConstantOfShape.""" + """Cast to string without value should not be fused into ConstantOfShape as ConstantOfShape does not support STRING output.""" model_text = """ agraph (int64[2] input_x) => (string[1, 4] output) diff --git a/tests/function_libs/torch_lib/ops_test_data.py b/tests/function_libs/torch_lib/ops_test_data.py index b91682dcf8..15a0cec84c 100644 --- a/tests/function_libs/torch_lib/ops_test_data.py +++ b/tests/function_libs/torch_lib/ops_test_data.py @@ -43,7 +43,6 @@ from typing import Any, Callable, Collection, Optional import numpy as np -import packaging.version import torch from torch.testing._internal import common_methods_invocations from torch.testing._internal.opinfo import definitions as opinfo_definitions @@ -59,8 +58,6 @@ from onnxscript.function_libs.torch_lib.ops import vision as vision_ops from tests.function_libs.torch_lib import extra_opinfo, ops_test_common -_IS_TORCH_NIGHTLY = packaging.version.parse(torch.__version__).is_devrelease - # Create a copy of the op_db to modify OPS_DB = copy.deepcopy(common_methods_invocations.op_db) @@ -507,16 +504,6 @@ def _where_input_wrangler( "addbmm", core_ops.aten_addbmm, tolerance={torch.float32: (2e-5, 2e-5), torch.float16: (2e-1, 2e-2)}, - ).xfail( - matcher=lambda sample: ( - len(sample.args) >= 2 - and isinstance(sample.args[0], torch.Tensor) - and isinstance(sample.args[1], torch.Tensor) - and (sample.args[0].numel() == 0 or sample.args[1].numel() == 0) - and sample.kwargs.get("beta") == 0 - ), - reason="fixme: In PyTorch nightly, beta=0 with zero-size reduction dimension does not propagate inf to NaN.", - enabled_if=_IS_TORCH_NIGHTLY, ), TorchLibOpInfo("addcdiv", core_ops.aten_addcdiv, tolerance={torch.float16: (3e-2, 1e-3)}), TorchLibOpInfo("addcmul", core_ops.aten_addcmul, tolerance={torch.float16: (4e-3, 3e-3)}), @@ -609,19 +596,7 @@ def _where_input_wrangler( "https://github.com/microsoft/onnxscript/issues/1007" ) ), - TorchLibOpInfo( - "baddbmm", core_ops.aten_baddbmm, tolerance={torch.float16: (1e-3, 1e-2)} - ).xfail( - matcher=lambda sample: ( - len(sample.args) >= 2 - and isinstance(sample.args[0], torch.Tensor) - and isinstance(sample.args[1], torch.Tensor) - and (sample.args[0].numel() == 0 or sample.args[1].numel() == 0) - and sample.kwargs.get("beta") == 0 - ), - reason="fixme: In PyTorch nightly, beta=0 with zero-size reduction dimension does not propagate inf to NaN.", - enabled_if=_IS_TORCH_NIGHTLY, - ), + TorchLibOpInfo("baddbmm", core_ops.aten_baddbmm, tolerance={torch.float16: (1e-3, 1e-2)}), TorchLibOpInfo("bernoulli", core_ops.aten_bernoulli, nondeterministic=True), TorchLibOpInfo( "bilinear", core_ops.aten_bilinear, tolerance={torch.float32: (2e-5, 2e-5)} @@ -1463,23 +1438,7 @@ def _where_input_wrangler( TorchLibOpInfo("logical_not", core_ops.aten_logical_not), TorchLibOpInfo("logical_or", core_ops.aten_logical_or), TorchLibOpInfo("logical_xor", core_ops.aten_logical_xor), - TorchLibOpInfo( - "logit", core_ops.aten_logit, tolerance={torch.float16: (1e-1, 7e-4)} - ).xfail( - matcher=lambda sample: ( - ( - len(sample.args) > 0 - and isinstance(sample.args[0], (int, float)) - and sample.args[0] > 0.5 - ) - or ( - isinstance(sample.kwargs.get("eps"), (int, float)) - and sample.kwargs["eps"] > 0.5 - ) - ), - reason="fixme: In PyTorch nightly, eps > 0.5 uses ternary clamp min/max evaluation.", - enabled_if=_IS_TORCH_NIGHTLY, - ), + TorchLibOpInfo("logit", core_ops.aten_logit, tolerance={torch.float16: (1e-1, 7e-4)}), TorchLibOpInfo("max_dim", core_ops.aten_max_dim) .xfail( variant_name="reduction_with_dim",