Skip to content

Commit 3de4283

Browse files
titaiwangmsCopilot
andcommitted
Fix Windows PermissionError in test_patch_merger
Replace tempfile-based ONNX save/load with in-memory protobuf serialization to avoid Windows concurrent file access errors. Use ir.serde.serialize_model() + SerializeToString() to load the model directly into ORT InferenceSession without disk I/O. Closes #159 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Ti-Tai Wang <titaiwang@microsoft.com>
1 parent ec3455b commit 3de4283

1 file changed

Lines changed: 15 additions & 13 deletions

File tree

src/mobius/components/_pixtral_vision_test.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ def test_patch_merger_matches_hf_unfold_ordering():
115115
the outermost loop). The ONNX implementation must reproduce this
116116
ordering so the learned ``merging_layer`` projection is correct.
117117
"""
118-
import tempfile
119-
120118
import torch
121119
from onnxscript._internal.builder import GraphBuilder
122120

@@ -181,17 +179,21 @@ def test_patch_merger_matches_hf_unfold_ordering():
181179

182180
model = ir.Model(graph, ir_version=11)
183181

184-
with tempfile.NamedTemporaryFile(suffix=".onnx", delete=True) as f:
185-
ir.save(model, f.name)
186-
sess = ort.InferenceSession(f.name, providers=["CPUExecutionProvider"])
187-
onnx_out = sess.run(
188-
None,
189-
{
190-
"x": x,
191-
"grid_h": np.array(grid_h, dtype=np.int64),
192-
"grid_w": np.array(grid_w, dtype=np.int64),
193-
},
194-
)[0]
182+
# Serialize to protobuf in-memory (avoids Windows PermissionError
183+
# from concurrent file access with tempfile + ir.save).
184+
proto = ir.serde.serialize_model(model)
185+
sess = ort.InferenceSession(
186+
proto.SerializeToString(),
187+
providers=["CPUExecutionProvider"],
188+
)
189+
onnx_out = sess.run(
190+
None,
191+
{
192+
"x": x,
193+
"grid_h": np.array(grid_h, dtype=np.int64),
194+
"grid_w": np.array(grid_w, dtype=np.int64),
195+
},
196+
)[0]
195197

196198
np.testing.assert_allclose(
197199
onnx_out.squeeze(0),

0 commit comments

Comments
 (0)