From 2f27cc786a47eaba43f73d085469b4a4488f5516 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Jul 2026 17:04:15 +0000 Subject: [PATCH 1/2] Initial plan From f4c1f3ace8cc109cc0d26ae27314f50a08973939 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Jul 2026 17:10:56 +0000 Subject: [PATCH 2/2] Fix ort_run serialization failure by saving model with external data --- onnxscript/rewriter/ort_fusions/_test_utils.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/onnxscript/rewriter/ort_fusions/_test_utils.py b/onnxscript/rewriter/ort_fusions/_test_utils.py index 24e9bcce61..35092ddf45 100644 --- a/onnxscript/rewriter/ort_fusions/_test_utils.py +++ b/onnxscript/rewriter/ort_fusions/_test_utils.py @@ -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 @@ -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):