Closed
Description
Expected behavior
onnxruntime can run the model when using the optimization ORT_ENABLE_EXTENDED.
Actual behavior
When using the optimization ORT_ENABLE_EXTENDED, onnxruntime crashes.
Traceback (most recent call last):
File "/home/carla/Documents/test_onnxruntime/0322/test.py", line 15, in <module>
ort_session = onnxruntime.InferenceSession(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/carla/anaconda3/envs/onnxruntime/lib/python3.11/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 472, in __init__
self._create_inference_session(providers, provider_options, disabled_optimizers)
File "/home/carla/anaconda3/envs/onnxruntime/lib/python3.11/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 544, in _create_inference_session
sess.initialize_session(providers, provider_options, disabled_optimizers)
onnxruntime.capi.onnxruntime_pybind11_state.RuntimeException: [ONNXRuntimeError] : 6 : RUNTIME_EXCEPTION : Exception during initialization: /onnxruntime_src/onnxruntime/core/graph/graph.cc:4037 bool onnxruntime::Graph::RemoveNode(onnxruntime::NodeIndex) node->GetOutputEdgesCount() == 0 was false. Can't remove node Transpose as it still has output edges.
To reproduce
Environment
OS: Ubuntu 20.04
onnxruntime: 1.22.0.dev20250320003
Steps to reproduce
This bug can be reproduced by the following code with the model in the attachment. For the model, it can be correctly checked by onnx.checker.check_model. However, if we replace ORT_ENABLE_EXTENDED with ORT_ENABLE_BASIC, every thing is ok.
from typing import Dict, List, Literal, Optional
import sys
import numpy as np
import onnx
import onnxruntime
model_path = "bugs/onnx_output5932/model.onnx"
onnx_model = onnx.load(model_path)
onnx.checker.check_model(onnx_model)
sess_options = onnxruntime.SessionOptions()
sess_options.graph_optimization_level = onnxruntime.GraphOptimizationLevel.ORT_ENABLE_EXTENDED
ort_session = onnxruntime.InferenceSession(
onnx_model.SerializeToString(), sess_options, providers=["CPUExecutionProvider"]
)
Urgency
No response
Platform
Linux
OS Version
Ubuntu 20.04
ONNX Runtime Installation
Built from Source
ONNX Runtime Version or Commit ID
1.22.0.dev20250320003
ONNX Runtime API
Python
Architecture
X64
Execution Provider
Default CPU
Execution Provider Library Version
No response