Skip to content

Clamp Shape slice bounds during elimination - #352

Closed
Yuhx141 wants to merge 1 commit into
onnx:mainfrom
Yuhx141:codex/fix-shape-slice-bounds
Closed

Yuhx141 wants to merge 1 commit into
onnx:mainfrom
Yuhx141:codex/fix-shape-slice-bounds

Conversation

@Yuhx141

@Yuhx141 Yuhx141 commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Description

ONNX Shape slices use clamped Python-style bounds. The shared optimizer helper only normalized negative indices, so out-of-range or reversed bounds could create invalid iterator ranges during elimination.

Clamp both bounds to the input rank and normalize end-before-start to an empty slice in FetchStartAndEndAttrOfShape. The shared fix also covers eliminate_shape_gather and eliminate_slice_after_shape.

This is the upstream counterpart requested in onnxsim/onnxsim#2015.

Test

  • PYTHONPATH=/tmp/onnxopt-py312:. python3 -m pytest -q -o addopts= onnxoptimizer/test/optimizer_test.py -k eliminate_shape_op (3 passed)

Signed-off-by: Yuhx141 <155034285+Yuhx141@users.noreply.github.com>
@take-cheeze

Copy link
Copy Markdown
Member

Is this duplicate of #351 ?

@Yuhx141

Yuhx141 commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

Yes, this duplicates #351. I’ll close it. Sorry for the duplicate.

@Yuhx141 Yuhx141 closed this Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants