onnx / onnx/optimizer

[BUG] The pass "eliminate_shape_op" causes output mismatch

Open
#279 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
834
Forks
109
Avg merge
6h 55m
Merged PRs (30d)
2

Description

[BUG] The pass "eliminate_shape_op" causes output mismatch

Issue
Running the single pass eliminate_shape_op with onnxoptimizer 0.4.2 changes numerical outputs.

Environment

  • Ubuntu 20.04
  • Python 3.10
  • onnx==1.19.0
  • onnxruntime==1.23.2
  • onnxoptimizer==0.4.2(latest)

Repro steps (run from this folder)
eliminate_shape_op_repro.tar.gz

  1. Create a Python environment (Python 3.10) and install dependencies:
python3 -m venv .venv
source .venv/bin/activate
pip install -U pip
pip install -r requirements.txt
  1. Optimize a case with only eliminate_shape_op (writes model.opt.onnx next to model.onnx):
  • python optimize_model.py --case ./case_03140_seed45116679
  1. Differential test original and optimized models with the same oracle inputs (ORT graph optimization disabled; NaN pairs treated as equal):
  • python diff_test.py --case ./case_03140_seed45116679

Expected
eliminate_shape_op should be semantics-preserving. Applying this pass alone should not change any output values.

Differential Test Output Details

  1. case_03140_seed45116679 — mismatch; output[14] max_abs=4.022e+04 max_rel=4.022e+12, output[15] max_abs=5.190e+02 max_rel=5.120e+10; overall mismatch.
  2. case_00324_seed22816775 — mismatch; output[3] max_abs=5.022e+18 max_rel=1.000e+00; overall mismatch.
  3. case_03181_seed45441358 — mismatch; output[11] max_abs=3.352e+00 max_rel=6.005e-01, output[12] max_abs=5.664e+00 max_rel=4.489e+00; overall mismatch.
Case: case_03140_seed45116679 (ORT graph optimizations disabled)
	output[14]: max_abs=4.022e+04, max_rel=4.022e+12, shape=(1, 21, 24)
	output[15]: max_abs=5.190e+02, max_rel=5.120e+10, shape=(32, 21, 24)
Overall: max_abs=4.022e+04, max_rel=4.022e+12


Case: case_00324_seed22816775 (ORT graph optimizations disabled)
	output[3]: max_abs=5.022e+18, max_rel=1.000e+00, shape=(51, 1, 1, 1)
Overall: max_abs=5.022e+18, max_rel=1.000e+00


Case: case_03181_seed45441358 (ORT graph optimizations disabled)
	output[11]: max_abs=3.352e+00, max_rel=6.005e-01, shape=(1, 135, 17)
	output[12]: max_abs=5.664e+00, max_rel=4.489e+00, shape=(57, 45, 17)
Overall: max_abs=5.664e+00, max_rel=4.489e+00

Attachments

  • requirements.txt
  • optimize_model.py
  • diff_test.py (runs original and optimized with same oracle inputs; ORT graph optimizations disabled; NaN pairs treated equal)
  • run_optimized_model.py (executes optimized model with oracle inputs)
  • case_03140_seed45116679/, case_00324_seed22816775/, case_03181_seed45441358/ (original models, optimized models, and oracle inputs)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by following the attached requirements.txt setup and run optimize_model.py followed by diff_test.py for the three listed cases, with ORT graph optimizations disabled. Then trace the eliminate_shape_op pass implementation against the original and optimized models. Done means applying only this pass produces matching outputs for the provided differential tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.