From c20b9a2c32e19777f48d2131563abbc0504e0aaa Mon Sep 17 00:00:00 2001 From: hualxie Date: Mon, 13 Apr 2026 14:48:44 +0800 Subject: [PATCH] fix(quant): delete stale external data sidecar before save_onnx overwrites it ORT quantize() writes the .data sidecar, then save_onnx tries to write the same file again and hits onnx's FileExistsError. Delete the sidecar before saving so the overwrite succeeds cleanly. --- src/winml/modelkit/onnx/persistence.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/winml/modelkit/onnx/persistence.py b/src/winml/modelkit/onnx/persistence.py index 8c4a97bf1..b6b12ab7a 100644 --- a/src/winml/modelkit/onnx/persistence.py +++ b/src/winml/modelkit/onnx/persistence.py @@ -106,6 +106,12 @@ def save_onnx( if save_external: ext_location = location or f"{path.name}.data" + # Delete any pre-existing sidecar so onnx.save_model doesn't raise + # FileExistsError (e.g. when ORT quantize() already wrote the file). + ext_path = path.parent / ext_location + if ext_path.exists(): + ext_path.unlink() + logger.debug("Removed existing external data sidecar: %s", ext_path) logger.debug( "Saving ONNX model with external data to %s (location=%s)", path,