Skip to content

onnxruntime errors out due to ORT_ENABLE_BASIC optimization: [ONNXRuntimeError] : 1 : FAIL : Type Error: Shape of initializer v7_0 does not match. {1} != {} #24160

@coffezhou

Description

@coffezhou

Expected behavior

onnxruntime should run the model when using the optimization ORT_ENABLE_BASIC.

Actual behavior

When using the optimization ORT_ENABLE_BASIC, onnxruntime crashes.

Traceback (most recent call last):
  File "/home/carla/Documents/test_onnxruntime/0325/test.py", line 18, in <module>
    ort_session = onnxruntime.InferenceSession(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/carla/anaconda3/envs/nnsmith-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/nnsmith-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.Fail: [ONNXRuntimeError] : 1 : FAIL : Type Error: Shape of initializer v7_0 does not match. {1} != {}

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_BASIC with ORT_DISABLE_ALL, every thing is ok.

from typing import Dict, List, Literal, Optional
import sys

import numpy as np
import onnx
import onnxruntime

model_path = "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_BASIC


ort_session = onnxruntime.InferenceSession(
                     onnx_model.SerializeToString(), sess_options, providers=["CPUExecutionProvider"]
                  )

model.zip

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleissues that have not been addressed in a while; categorized by a bot

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions