Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsupported model IR version: 10, max supported IR version: 9 #1118

Open
coogle opened this issue Jul 12, 2024 · 3 comments
Open

Unsupported model IR version: 10, max supported IR version: 9 #1118

coogle opened this issue Jul 12, 2024 · 3 comments

Comments

@coogle
Copy link

coogle commented Jul 12, 2024

I'm trying to use convert_sklearn to convert my model to ONNX for use. My notebook runs and I can use the converted model within the notebook to make predictions... but when I try to take my ONNX model and use it in its production environment I am getting a version error:

Unsupported model IR version: 10, max supported IR version: 9

I don't think I can do much about the max supported IR version 9 (I'll be 100% honest I'm also kind of unclear what's going on here as this is my very first attempt at making a model from scratch ever).. Is there something I need to do in my call to convert_sklearn?

Here's the relevant code:

clr = MultiOutputClassifier(
    LogisticRegression(max_iter=500),
)

model = clr.fit(
    cv_clean.transform(X_train_clean), # Uncomment to try and comment out below
    #tfidf_clean.transform(X_train_raw), 
    y_train
)

y_pred = model.predict(
    cv_clean.transform(X_test_clean), # Uncomment to try and comment out below
    #tfidf_clean.transform(X_test_raw)
)

smaller_classification_report(y_test.values.astype(int), y_pred)

initial_type = [('float_input', FloatTensorType([None, cv_clean.transform(X_train_clean).shape[1]]))]

onnx_model = convert_sklearn(model, initial_types=initial_type, options={type(clr.estimator): {'zipmap': False}})

onnx_model_path = "build/Arvee/tags-classifier/onnx/model_quantized.onnx"
with open(onnx_model_path, "wb") as f:
    f.write(onnx_model.SerializeToString())

print(f"ONNX model saved to {onnx_model_path}")

session = rt.InferenceSession(onnx_model_path)

# Prepare the test data for ONNX Runtime
X_test_onnx = cv_clean.transform(X_test_clean).toarray().astype(np.float32)

# Execute the model against the test data
input_name = session.get_inputs()[0].name
label_name = session.get_outputs()[0].name

y_pred_onnx = session.run([label_name], {input_name: X_test_onnx})[0]

# Print the classification report
smaller_classification_report(y_test.values.astype(int), y_pred_onnx)
@coogle
Copy link
Author

coogle commented Jul 12, 2024

Package versions

scikit-learn 1.4.2
onnxruntime 1.17.0 (prod)
onnxruntime 1.18.0 (notebook)
skl2onnx 1.17.0

@xadupre
Copy link
Collaborator

xadupre commented Aug 1, 2024

onnx version is missing in your message. You should add convert_sklearn(..., target_opset=18). onnxruntime is usually one or two releases behind onnx.

@berkanttubi
Copy link

Downgrading onnx version to 1.15.0 will solve your problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants