Skip to content

Fix SplitToSequence with scalar uneven split producing incorrect equal-split output#2858

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-unequal-split-onnx-model
Draft

Fix SplitToSequence with scalar uneven split producing incorrect equal-split output#2858
Copilot wants to merge 2 commits intomainfrom
copilot/fix-unequal-split-onnx-model

Conversation

Copy link
Contributor

Copilot AI commented Mar 18, 2026

When optimizing SplitToSequence with a scalar split that doesn't evenly divide the axis dimension, the optimizer was emitting a Split node with only num_outputs, which produces an equal split — silently corrupting the model semantics.

Example: Input [1, 8400, 80] with split=5000 on axis=-2 should produce [1, 5000, 80] + [1, 3400, 80], but was producing [1, 4200, 80] + [1, 4200, 80].

Changes

  • optimizer/_constant_folding.py — In split_to_sequence, when the scalar split doesn't evenly divide the axis dimension (split_dimension_size % split_size != 0), construct an explicit 1-D constant tensor [split_size, ..., remainder] and pass it as the split input to Split. Even splits retain the existing num_outputs-only path.
# Before (always equal split via num_outputs)
split_values = op.Split(input, axis=axis, num_outputs=num_outputs, ...)

# After (explicit sizes for uneven case)
remainder = split_dimension_size - (num_outputs - 1) * split_size
explicit_split = op.Constant(value_ints=[split_size, ..., remainder], ...)
split_values = op.Split(input, explicit_split, axis=axis, num_outputs=num_outputs, ...)
  • optimizer/_constant_folding_test.py — Adds a regression test asserting the generated Split node carries explicit split sizes [5000, 3400] rather than performing an equal split.
Original prompt

This section details on the original issue you should resolve

<issue_title>SplitToSequence layer with unequal split generates incorrect onnx model</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 the following output model:

Image

The uneven split in the SplitToSequence layer has been converted to an even split Split 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>

<agent_instructions>Try fix this</agent_instructions>

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

<comments>
</comments>


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

…lit node

When split is a scalar that doesn't evenly divide the axis dimension, create
an explicit split sizes tensor and pass it to Split, instead of using num_outputs
alone (which would produce an equal split).

Example: input [1,8400,80] with scalar split=5000 on axis=1 now correctly
produces [1,5000,80] and [1,3400,80] instead of [1,4200,80] and [1,4200,80].

Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
Copilot AI changed the title [WIP] [ISSUE-123] Fix SplitToSequence layer with unequal split in ONNX model Fix SplitToSequence with scalar uneven split producing incorrect equal-split output Mar 18, 2026
Copilot AI requested a review from justinchuby March 18, 2026 18:13
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.

SplitToSequence layer with unequal split generates incorrect onnx model

2 participants