Skip to content

Fix ConcatFromSequence lowering for opsets 11 and 12 - #3161

Open
DiadkoShmek wants to merge 1 commit into
microsoft:mainfrom
DiadkoShmek:lezo50-sequence-opset-20261105
Open

DiadkoShmek wants to merge 1 commit into
microsoft:mainfrom
DiadkoShmek:lezo50-sequence-opset-20261105

Conversation

@DiadkoShmek

Copy link
Copy Markdown

optimizer.optimize can turn a valid opset-11/12 SequenceConstruct → ConcatFromSequence(new_axis=1) model into an invalid graph. The replacement currently uses the two-input form of Unsqueeze, while these opsets require an axes attribute. Both ONNX full checking and ONNX Runtime reject the optimized graph.

Use the attribute form before opset 13 and retain the existing axes-input form for newer models. Pass the optimizer's effective model-opset map through its existing state so nested If graphs inherit the correct version without requiring their own imports.

This covers the model target version, nested graphs, and the tested same-version local functions. Mixed model/function imports (11/18 and 18/11) retain a pre-existing compatibility failure in both baseline and candidate and are outside this repair.

A minimal reproduction is:

import onnx
from onnxscript import optimizer

model = onnx.parser.parse_model(
    '''
    <ir_version: 10, opset_import: ["" : 11]>
    main (float[2,3] A, float[2,3] B) => (float[2,2,3] Y) {
        S = SequenceConstruct (A, B)
        Y = ConcatFromSequence <axis=1, new_axis=1> (S)
    }
    '''
)
onnx.checker.check_model(model, full_check=True)
optimized = optimizer.optimize(model)
onnx.checker.check_model(optimized, full_check=True)
print("Original and optimized opset-11 models pass full ONNX checking.")

Validation:

  • The constant-folding test module passes all 80 methods. The baseline has six failing subcases in the two added regression methods.
  • 192 CPU cases compare the original, optimized and optimized-again models against NumPy stack/concatenate through full ONNX checking and ONNX Runtime. They cover opsets 11/12/13/18, positive/negative axes, new_axis 0/1, two/three sequence members, multiple shapes and float32/float64/int64.
  • Nested If branches and reuse of the same pass across different target versions retain the expected lowering and values.
  • Full configured lintrunner all-files checks and Python wheel/sdist builds pass for baseline and candidate. Mypy excludes Python files in the current upstream configuration; this is not a full type-check claim. Existing packaging warnings are identical in both builds.

The local runtime checks use ONNX 1.18.0 and ONNX Runtime 1.20.1 CPU. The full Nox/framework/nightly/docs matrix was not run.

This is author-directed, AI-assisted work. The author sets direction, owns the submission and takes responsibility for follow-up.

This branch has not been deployed

No deployments
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.

1 participant