|
12 | 12 |
|
13 | 13 | import re |
14 | 14 | import tempfile |
| 15 | +from pathlib import Path |
15 | 16 |
|
16 | 17 | import numpy as np |
17 | 18 | import pytest |
@@ -63,9 +64,11 @@ def test_cross_attention_block_matches_diffusers(): |
63 | 64 | model = _make_model(graph) |
64 | 65 | apply_weights(model, _remap_transformer(hf.state_dict())) |
65 | 66 |
|
66 | | - with tempfile.NamedTemporaryFile(suffix=".onnx") as handle: |
67 | | - onnx_ir.save(model, handle.name) |
68 | | - session = ort.InferenceSession(handle.name) |
| 67 | + # Windows keeps the ORT model file mapped; ignore cleanup errors so the dir can be removed. |
| 68 | + with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as temp_dir: |
| 69 | + model_path = Path(temp_dir) / "model.onnx" |
| 70 | + onnx_ir.save(model, model_path) |
| 71 | + session = ort.InferenceSession(model_path) |
69 | 72 | actual = session.run(None, {"hidden": hidden.numpy(), "context": context.numpy()})[0] |
70 | 73 | assert np.abs(actual - expected).max() < 1e-4 |
71 | 74 |
|
@@ -115,9 +118,11 @@ def test_unet_matches_diffusers(): |
115 | 118 | model = DenoisingTask().build(module, config)["model"] |
116 | 119 | apply_weights(model, module.preprocess_weights(dict(hf.state_dict()))) |
117 | 120 |
|
118 | | - with tempfile.NamedTemporaryFile(suffix=".onnx") as handle: |
119 | | - onnx_ir.save(model, handle.name) |
120 | | - session = ort.InferenceSession(handle.name) |
| 121 | + # Windows keeps the ORT model file mapped; ignore cleanup errors so the dir can be removed. |
| 122 | + with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as temp_dir: |
| 123 | + model_path = Path(temp_dir) / "model.onnx" |
| 124 | + onnx_ir.save(model, model_path) |
| 125 | + session = ort.InferenceSession(model_path) |
121 | 126 | actual = session.run( |
122 | 127 | None, |
123 | 128 | { |
@@ -185,9 +190,11 @@ def test_unet_sd1x_mixed_block_types_matches_diffusers(): |
185 | 190 | model = DenoisingTask().build(module, config)["model"] |
186 | 191 | apply_weights(model, module.preprocess_weights(dict(hf.state_dict()))) |
187 | 192 |
|
188 | | - with tempfile.NamedTemporaryFile(suffix=".onnx") as handle: |
189 | | - onnx_ir.save(model, handle.name) |
190 | | - session = ort.InferenceSession(handle.name) |
| 193 | + # Windows keeps the ORT model file mapped; ignore cleanup errors so the dir can be removed. |
| 194 | + with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as temp_dir: |
| 195 | + model_path = Path(temp_dir) / "model.onnx" |
| 196 | + onnx_ir.save(model, model_path) |
| 197 | + session = ort.InferenceSession(model_path) |
191 | 198 | actual = session.run( |
192 | 199 | None, |
193 | 200 | { |
@@ -271,9 +278,11 @@ def test_unet_lora_gate_parity(): |
271 | 278 | weights.update(remap_diffusers_unet_lora(lora_state, "test")) |
272 | 279 | apply_weights(model, weights) |
273 | 280 |
|
274 | | - with tempfile.NamedTemporaryFile(suffix=".onnx") as handle: |
275 | | - onnx_ir.save(model, handle.name) |
276 | | - session = ort.InferenceSession(handle.name) |
| 281 | + # Windows keeps the ORT model file mapped; ignore cleanup errors so the dir can be removed. |
| 282 | + with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as temp_dir: |
| 283 | + model_path = Path(temp_dir) / "model.onnx" |
| 284 | + onnx_ir.save(model, model_path) |
| 285 | + session = ort.InferenceSession(model_path) |
277 | 286 | feed = { |
278 | 287 | "sample": sample.numpy(), |
279 | 288 | "timestep": timestep.numpy().astype(np.int64), |
|
0 commit comments