Skip to content

Fix test_patch_merger_matches_hf_unfold_ordering: Windows temp file PermissionError #159

Description

@titaiwangms

Summary

test_patch_merger_matches_hf_unfold_ordering in _pixtral_vision_test.py fails on Windows CI with:

PermissionError: [Errno 13] Permission denied: 'C:\Users\RUNNER~1\AppData\Local\Temp\tmpXXXX.onnx'

CI run: https://github.com/onnxruntime/mobius/actions/runs/24267296245/job/70864946872

Root Cause

The test uses tempfile.NamedTemporaryFile() to create a temp file, then calls ir.save(model, f.name) which internally calls onnx.save(). On Windows, the temp file handle is still open when onnx.save tries to open the same path for writing — Windows does not allow concurrent file access.

Proposed Fix

Option A (preferred by justinchuby): Run the ORT inference session directly from the in-memory IR model without saving to disk. Use onnxruntime.InferenceSession with the serialized protobuf bytes:

proto = ir.serde.serialize_model(model)
session = ort.InferenceSession(proto.SerializeToString())

Option B: Use tempfile.mkdtemp() for a directory-based approach:

with tempfile.TemporaryDirectory() as tmpdir:
    path = os.path.join(tmpdir, "model.onnx")
    ir.save(model, path)
    session = ort.InferenceSession(path)

Option C: Use NamedTemporaryFile(delete=False), close it before saving:

f = tempfile.NamedTemporaryFile(suffix=".onnx", delete=False)
f.close()
ir.save(model, f.name)

References

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions