@@ -741,6 +741,38 @@ def test_constant_folding_creates_constant_nodes_in_function(self):
741741 constant_nodes = [n for n in func .graph if n .op_type == "Constant" ]
742742 self .assertEqual (len (constant_nodes ), 1 )
743743
744+ def test_output_size_limit_prevents_evaluation_before_running (self ):
745+ """Test that output_size_limit is checked before calling the (expensive) reference
746+ evaluator. This is a regression test for https://github.com/microsoft/onnxscript/issues/2709
747+ where Resize with cubic mode on a large output tensor caused an infinite loop/hang
748+ because the reference evaluator was called before checking output size.
749+ """
750+ # Create a model with Resize that has a small constant input but large output
751+ # sizes: [1, 2, 64, 64] -> output has 8192 elements, exceeding a small output_size_limit
752+ model_text = """
753+ <ir_version: 8, opset_import: [ "" : 18]>
754+ agraph () => (float[1, 2, 64, 64] output)
755+ <float[1, 2, 4, 4] x_const = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0,
756+ 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0,
757+ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0,
758+ 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0}>
759+ {
760+ sizes = Constant <value_ints=[1, 2, 64, 64]> ()
761+ output = Resize <mode="nearest"> (x_const, , , sizes)
762+ }
763+ """
764+ model = ir .from_onnx_text (model_text )
765+ # With a small output_size_limit, the Resize node should NOT be folded
766+ # (and more importantly, should NOT hang)
767+ optimized = self ._fold (
768+ model ,
769+ onnx_shape_inference = True ,
770+ output_size_limit = 100 , # very small limit to prevent evaluation
771+ )
772+ # The Resize node should remain (not folded)
773+ ops = [node .op_type for node in optimized .graph ]
774+ self .assertIn ("Resize" , ops )
775+
744776 def test_initializer_as_graph_output_is_not_removed (self ):
745777 """Test that an initializer that is a graph output is not removed during constant folding."""
746778 model = """
0 commit comments