Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions onnxscript/rewriter/ort_fusions/_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# Licensed under the MIT License.
from __future__ import annotations

import os
import tempfile

import numpy as np
import onnx_ir as ir
import onnxruntime
Expand All @@ -12,13 +15,17 @@

def ort_run(model_name: str, model, inputs):
providers = ["CPUExecutionProvider"]
model_proto = ir.serde.serialize_model(model)
options = onnxruntime.SessionOptions()
options.graph_optimization_level = onnxruntime.GraphOptimizationLevel.ORT_DISABLE_ALL
session = onnxruntime.InferenceSession(
model_proto.SerializeToString(), options, providers=providers
)
return session.run(None, inputs)
# Save the model to a temporary file and load it from disk. This uses external data
# to store tensors so that large models are not limited by the 2GB protobuf
# serialization limit, which can otherwise raise
# ``google.protobuf.message.EncodeError: Failed to serialize proto``.
with tempfile.TemporaryDirectory() as temp_dir:
model_path = os.path.join(temp_dir, f"{model_name}.onnx")
ir.save(model, model_path, external_data=f"{model_name}.onnx.data")
session = onnxruntime.InferenceSession(model_path, options, providers=providers)
return session.run(None, inputs)


def assert_allclose(outputs, expected_outputs, rtol=1e-3, atol=1e-3):
Expand Down
Loading