Skip to content

Fix hang in constant folding when Resize output exceeds size limit#2860

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-infinite-loop-resize-layer
Draft

Fix hang in constant folding when Resize output exceeds size limit#2860
Copilot wants to merge 2 commits intomainfrom
copilot/fix-infinite-loop-resize-layer

Conversation

Copy link
Contributor

Copilot AI commented Mar 19, 2026

Constant folding hangs on Resize nodes (and potentially other ops) where all inputs are constants but the output is very large — e.g., Resize with mode=cubic upscaling 1×96×7×7 → 1×96×256×256. The ONNX reference implementation for cubic interpolation is extremely slow at this scale, and the output_size_limit guard only fired after evaluation completed (in _prepare_folded_tensor), so the evaluator was never interrupted.

Changes

  • _constant_folding.py: In FoldConstantsPass.process_node, added a pre-evaluation output size check. Before invoking _reference_evaluator.evaluate, the code now estimates the output tensor size from statically-known output shapes. If any output exceeds output_size_limit, the node is skipped immediately — no evaluation is attempted.

  • _constant_folding_test.py: Added regression test test_output_size_limit_prevents_evaluation_before_running — creates a Resize node with all-constant inputs and an output that exceeds a small output_size_limit, verifying the node is not folded (and does not hang).

Original prompt

This section details on the original issue you should resolve

<issue_title>Infinite loop in constant folding of Resize layer</issue_title>
<issue_description>converting the attached ONNX model

Image

with the following script:

from onnxscript import ir
from onnxscript.optimizer import optimize

ir_model = ir.load("input.onnx")
optimized_model = optimize(ir_model)
ir.save(optimized_model, "output.onnx")

results in a hang when constant folding the Resize layer

input.onnx.zip

versions of relevant packages:

ml_dtypes         0.5.4
onnx              1.20.1
onnx-ir           0.2.0
onnxscript        0.6.2
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…size check

Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix infinite loop in constant folding of Resize layer Fix hang in constant folding when Resize output exceeds size limit Mar 19, 2026
Copilot AI requested a review from justinchuby March 19, 2026 21:25
@codecov
Copy link

codecov bot commented Mar 19, 2026

Codecov Report

❌ Patch coverage is 87.50000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.85%. Comparing base (4c4f7a0) to head (fdaa406).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
onnxscript/optimizer/_constant_folding.py 80.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2860      +/-   ##
==========================================
- Coverage   71.86%   71.85%   -0.02%     
==========================================
  Files         239      239              
  Lines       29139    29154      +15     
  Branches     2875     2878       +3     
==========================================
+ Hits        20942    20949       +7     
- Misses       7219     7229      +10     
+ Partials      978      976       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

Infinite loop in constant folding of Resize layer

2 participants