onnx.onnx_cpp2py_export.checker.ValidationError: The model does not have an ir_version set properly.

#18
by KamalnathManezhi - opened

Hi,
I downloaded the model "phi3-mini-4k-instruct-cpu-int4-rtn-block-32-acc-level-4.onnx" from https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx/tree/main/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4.

When I run below model validity check code,

model_path = 'phi3-mini-4k-instruct-cpu-int4-rtn-block-32-acc-level-4.onnx'

Check the model validity

onnx.checker.check_model(model_path)
print(f"The model at {model_path} is valid.")

I get below error

Traceback (most recent call last):
File "\Microsoft_Phi3\model_validity.py", line 16, in
onnx.checker.check_model(model_path)
File "C:\Users\XXXXXX\AppData\Local\Programs\Python\Python312\Lib\site-packages\onnx\checker.py", line 163, in check_model
C.check_model_path(
onnx.onnx_cpp2py_export.checker.ValidationError: The model does not have an ir_version set properly.

I tried setting the model.ir_version as below, but didnt help

# Load the model
model = onnx.load(model_path)

# Set a valid IR version (usually 7 or higher is safe)
model.ir_version = 7  # Replace with a valid version if necessary
opset = model.opset_import.add() 
opset.version = 13 

# Save the model with the fixed IR version
onnx.save_model(model, output_path)

Let me know if you've any suggestions.

Thanks,
Kamalnath

Microsoft org

The ONNX model is created using ONNX Runtime GenAI's model builder, and the IR version is set to 7 here. If you open the model using Netron, you can see the format section set to ONNX v7.

I tested with both ONNX v1.13.0 and ONNX v1.16.2 and both versions did not raise the above error. However, the "bad node spec" error was raised as expected. The uploaded ONNX models contain operators that are in the ai.onnx domain and com.microsoft domain for optimized performance with ONNX Runtime. The ONNX checker works for models that contain operators only in the ai.onnx domain.

kvaishnavi changed discussion status to closed

Sign up or log in to comment