From 9f20e228a0a143b0cd899c98a176112db1c6e741 Mon Sep 17 00:00:00 2001 From: lowinli <33021512+LowinLi@users.noreply.github.com> Date: Mon, 26 Sep 2022 09:50:42 +0800 Subject: [PATCH 1/2] debug an exception if dst_path is not a file, it will raise Exception in the function src_path.samefile: FileNotFoundError: [Errno 2] No such file or directory: '/home/lilongwei/notebook/onnx_diffusion/vae_decoder/model.onnx' --- src/diffusers/onnx_utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/diffusers/onnx_utils.py b/src/diffusers/onnx_utils.py index 2282f411aed8..47119f0f7a69 100644 --- a/src/diffusers/onnx_utils.py +++ b/src/diffusers/onnx_utils.py @@ -79,7 +79,9 @@ def _save_pretrained(self, save_directory: Union[str, Path], file_name: Optional src_path = self.model_save_dir.joinpath(self.latest_model_name) dst_path = Path(save_directory).joinpath(model_file_name) - if not src_path.samefile(dst_path): + if dst_path.is_file() and not src_path.samefile(dst_path): + shutil.copyfile(src_path, dst_path) + elif not dst_path.is_file(): shutil.copyfile(src_path, dst_path) def save_pretrained( From 277602b9dc35e7c5595ed3cf216a77901a5acce4 Mon Sep 17 00:00:00 2001 From: Anton Lozhkov Date: Mon, 10 Oct 2022 12:58:32 +0200 Subject: [PATCH 2/2] Update src/diffusers/onnx_utils.py --- src/diffusers/onnx_utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/diffusers/onnx_utils.py b/src/diffusers/onnx_utils.py index 47119f0f7a69..142174f6e101 100644 --- a/src/diffusers/onnx_utils.py +++ b/src/diffusers/onnx_utils.py @@ -79,10 +79,10 @@ def _save_pretrained(self, save_directory: Union[str, Path], file_name: Optional src_path = self.model_save_dir.joinpath(self.latest_model_name) dst_path = Path(save_directory).joinpath(model_file_name) - if dst_path.is_file() and not src_path.samefile(dst_path): - shutil.copyfile(src_path, dst_path) - elif not dst_path.is_file(): + try: shutil.copyfile(src_path, dst_path) + except shutil.SameFileError: + pass def save_pretrained( self,