onnx / onnx/optimizer

[BUG] The Pass “eliminate_consecutive_idempotent_ops“ causes output mismatch

Open
#259 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

Pass “eliminate_consecutive_idempotent_ops“ causes output mismatch

Issue
Running the single pass eliminate_consecutive_idempotent_ops with onnxoptimizer 0.4.2 changes numerical outputs. One real model regresses after this pass only, while the original model runs correctly with the same oracle inputs.

Environment

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

Repro steps (run from this folder)

  1. Download and unzip the attached archive, then cd into the extracted directory

eliminate_consecutive_idempotent_ops_repro.tar.gz

tar -xzvf eliminate_consecutive_idempotent_ops_repro.tar.gz
cd eliminate_consecutive_idempotent_ops_repro
  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_consecutive_idempotent_ops:
  • python optimize_model.py --case ./case_06833_seed74361546
    (Writes model.opt.onnx next to model.onnx in the case directory.)
  1. Differential test original vs optimized outputs using stored oracle inputs:
  • python diff_test.py --case ./case_06833_seed74361546

Observed results

  • case_06833_seed74361546: mismatch with orginal model after optimization

Expected
eliminate_consecutive_idempotent_ops should be semantics-preserving. Applying this pass alone should not change any output values. Please investigate why the optimized graph for the above case produces different outputs.

Differential Test Output Details

Case: case_06833_seed74361546
  output[0]: max_abs=0.000e+00, max_rel=0.000e+00, shape=(5, 1, 1, 1)
  output[1]: max_abs=0.000e+00, max_rel=0.000e+00, shape=(5, 1, 4)
  output[2]: max_abs=0.000e+00, max_rel=0.000e+00, shape=(5, 1, 1)
  output[3]: max_abs=6.079e+00, max_rel=7.709e+01, shape=(5, 1, 57)
  output[4]: max_abs=0.000e+00, max_rel=0.000e+00, shape=(1, 5, 1)
  output[5]: max_abs=0.000e+00, max_rel=0.000e+00, shape=(1, 5, 1, 1)
  output[6]: max_abs=0.000e+00, max_rel=0.000e+00, shape=(1, 5, 1, 1)
  output[7]: max_abs=7.297e-01, max_rel=7.129e+00, shape=(5, 1, 1)
  output[8]: max_abs=0.000e+00, max_rel=0.000e+00, shape=(5, 1, 63)
  output[9]: max_abs=0.000e+00, max_rel=0.000e+00, shape=(15, 1, 63)
  output[10]: max_abs=0.000e+00, max_rel=0.000e+00, shape=(5,)
  output[11]: max_abs=0.000e+00, max_rel=0.000e+00, shape=(5, 63)
  output[12]: max_abs=0.000e+00, max_rel=0.000e+00, shape=(5, 63)
  output[13]: max_abs=0.000e+00, max_rel=0.000e+00, shape=(5, 63)
Overall: max_abs=6.079e+00, max_rel=7.709e+01

Attachments

  • README.md (this document)
  • requirements.txt (dependency versions)
  • optimize_model.py (runs only eliminate_consecutive_idempotent_ops and saves model.opt.onnx)
  • diff_test.py (runs original vs optimized with oracle inputs and reports max_abs/max_rel)
  • case_06833_seed74361546/ (contains model.onnx which is original model, oracle.pkl which is the input data for both original and optimized model)

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 running optimize_model.py and diff_test.py from the attached reproduction directory against case_06833_seed74361546, then inspect the implementation entry point for eliminate_consecutive_idempotent_ops using case_06833_seed74361546/model.onnx. Done means the pass no longer changes the reported outputs, with diff_test.py showing zero mismatches while the pass remains enabled alone.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
devtools, testing-qa
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.