Fix hang in constant folding when Resize output exceeds size limit#2860
Draft
Fix hang in constant folding when Resize output exceeds size limit#2860
Conversation
…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
Codecov Report❌ Patch coverage is
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. |
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.
Constant folding hangs on
Resizenodes (and potentially other ops) where all inputs are constants but the output is very large — e.g.,Resizewithmode=cubicupscaling 1×96×7×7 → 1×96×256×256. The ONNX reference implementation for cubic interpolation is extremely slow at this scale, and theoutput_size_limitguard only fired after evaluation completed (in_prepare_folded_tensor), so the evaluator was never interrupted.Changes
_constant_folding.py: InFoldConstantsPass.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 exceedsoutput_size_limit, the node is skipped immediately — no evaluation is attempted._constant_folding_test.py: Added regression testtest_output_size_limit_prevents_evaluation_before_running— creates aResizenode with all-constant inputs and an output that exceeds a smalloutput_size_limit, verifying the node is not folded (and does not hang).Original prompt
🔒 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.