Skip to content

Fold SplitToSequence when split input is omitted - #3061

Merged
G. Ramalingam (gramalingam) merged 1 commit into
microsoft:mainfrom
rioyu123:fix-omitted-split-to-sequence
Oct 7, 2026
Merged

G. Ramalingam (gramalingam) merged 1 commit into
microsoft:mainfrom
rioyu123:fix-omitted-split-to-sequence

Conversation

@rioyu123

Copy link
Copy Markdown
Contributor

Fixes #3057.

The constant folder returns early when SplitToSequence has no split input, even when the split-axis size is known. This prevents lowering it to Split and resolving downstream SequenceAt nodes.

Following the approach described in the issue, this treats an omitted split as chunks of size one and reuses the existing scalar lowering, including Squeeze for keepdims=0. An explicit empty optional-input slot is handled the same way.

The new path requires an opset 18+ import on the node's graph or function, since it uses Split.num_outputs. Older opsets, control-flow subgraphs without their own imports, and dynamic axis sizes remain unchanged. A zero-length axis is also left alone rather than creating an invalid zero-output Split; that guard applies to explicit scalar splits too.

Tests

  • Added 12 rewrite cases covering axes 0, 1 and -1, both keepdims values, and omitted versus empty-name inputs. Each compares original and optimized ONNX reference execution with NumPy and checks the optimized graph's validity.
  • Added six controls for dynamic shapes, empty axes and opset 13.
  • The 12 rewrite cases fail on the base commit; the optimizer tests pass with the fix (74 passed).
  • Required lintrunner -a on both changed files passes.

No full-repository test run or runtime speedup is claimed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The focused implementation handles the required edge cases and is supported by comprehensive regression coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Enables constant folding of SplitToSequence when its optional split input is omitted.

Changes:

  • Treats omitted splits as scalar-one chunks for opset 18+.
  • Guards zero-length axes and adds rewrite/control tests.
File Description
onnxscript/​optimizer/​_constant_folding.py Implements omitted-split lowering and safety guards.
onnxscript/​optimizer/​_constant_folding_test.py Tests semantics and non-rewrite conditions.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@codecov

codecov Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.79%. Comparing base (08898ad) to head (c1e9cdd).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3061      +/-   ##
==========================================
+ Coverage   72.73%   72.79%   +0.05%     
==========================================
  Files         265      265              
  Lines       32358    32392      +34     
  Branches     3069     3074       +5     
==========================================
+ Hits        23536    23580      +44     
+ Misses       7779     7774       -5     
+ Partials     1043     1038       -5     

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

@gramalingam
G. Ramalingam (gramalingam) merged commit daf4fbb into microsoft:main Oct 7, 2026
26 of 32 checks passed
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.

constant folding does not fold SplitToSequence layer w/o a split input

3 participants