Disable the constant folding output-size limit by default - #32151
Disable the constant folding output-size limit by default#32151pragyam32 wants to merge 1 commit into
Conversation
The output-size guard added in microsoft#28055 skips any node whose output size cannot be estimated before execution. Ops that have no ONNX shape inference function, such as the GreaterOrEqual and LessOrEqual functions below opset 16, reach the guard with no inferred output shape, so since 1.27 they are never constant folded and the entire downstream constant chain stops folding with them. No positive cap value avoids this because the bail is inside the guard. Default the cap to 0 so folding behaves as it did in 1.26, and make the mitigation opt-in through optimization.constant_folding_max_output_size_in_bytes. Fixes microsoft#32130 Co-authored-by: Cursor <cursoragent@cursor.com>
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
pragyam32 please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
|
reproduced #32130 on 1.27.0 — a but the post-execution actual-size check right below it already covers that — its own comment says it is there "to catch cases where pre-execution shape inference couldnt determine the output size." so just dropping the |
Cherry-pick of the fix for #32130 onto
rel-1.27.0. Supersedes #32150, which targetedmain.Description
The output-size guard added in #28055 skips any node whose output size cannot be estimated before execution.
EstimateTensorSizeInBytes()returns -1 when the outputNodeArghas no shape, andApplyImpl()treats -1 as "skip this node".GreaterOrEqualandLessOrEqualare ONNX function ops with no type-and-shape inference function until opset 16, so at ai.onnx opset 12-15 their outputs reach the guard with no inferred shape and are never constant folded. No positive cap value avoids this, because theestimated_size < 0bail sits inside themax_output_size > 0guard; only the literal"0"works, which turns the mitigation off entirely. An unfolded comparison node also makes its consumers non-constant, so an entire downstream constant chain stops folding and shapes that used to become static stay symbolic.Motivation and Context
This is a silent de-optimization of any opset <= 15 model containing these ops, introduced in 1.27 and not present in 1.26. Reported in #32130 with a real-world impact: a quantized segmentation model at opset 15 went from 1146 to 1186 nodes and lost its static output shapes, which caused a downstream plugin EP to reject 28 Slice nodes and fall the whole model back to CPU.
This change defaults
kDefaultConstantFoldingMaxOutputSizeInBytesto 0 so constant folding behaves as it did in 1.26, and makes the size cap opt-in throughoptimization.constant_folding_max_output_size_in_bytes. Users who want the hardening from #28055 can still set a positive value.All five existing size-limit tests in
onnxruntime/test/optimizer/graph_transform_test.ccset the config entry explicitly, so none of them depend on the previous 1 GB default.Fixes #32130