We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[Tracker] change to posix for better Windows support
In https://github.com/huggingface/diffusers/pull/6564, @fabiorigano introduced the use of Posix to better support Windows compatibility. 

It'd be nice to change the instances of `os.path.join()` to `Path(...).as_posix()`. 

Feel free to open PRs for this and tag me. 

While opening PRs, please target only ONE script at a time. 

Let's go 🚀 


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/diffusers/pipelines/onnx_utils.py`
Content:
```
1 # coding=utf-8
2 # Copyright 2023 The HuggingFace Inc. team.
3 # Copyright (c) 2022, NVIDIA CORPORATION.  All rights reserved.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 
18 import os
19 import shutil
20 from pathlib import Path
21 from typing import Optional, Union
22 
23 import numpy as np
24 from huggingface_hub import hf_hub_download
25 from huggingface_hub.utils import validate_hf_hub_args
26 
27 from ..utils import ONNX_EXTERNAL_WEIGHTS_NAME, ONNX_WEIGHTS_NAME, is_onnx_available, logging
28 
29 
30 if is_onnx_available():
31     import onnxruntime as ort
32 
33 
34 logger = logging.get_logger(__name__)
35 
36 ORT_TO_NP_TYPE = {
37     "tensor(bool)": np.bool_,
38     "tensor(int8)": np.int8,
39     "tensor(uint8)": np.uint8,
40     "tensor(int16)": np.int16,
41     "tensor(uint16)": np.uint16,
42     "tensor(int32)": np.int32,
43     "tensor(uint32)": np.uint32,
44     "tensor(int64)": np.int64,
45     "tensor(uint64)": np.uint64,
46     "tensor(float16)": np.float16,
47     "tensor(float)": np.float32,
48     "tensor(double)": np.float64,
49 }
50 
51 
52 class OnnxRuntimeModel:
53     def __init__(self, model=None, **kwargs):
54         logger.info("`diffusers.OnnxRuntimeModel` is experimental and might change in the future.")
55         self.model = model
56         self.model_save_dir = kwargs.get("model_save_dir", None)
57         self.latest_model_name = kwargs.get("latest_model_name", ONNX_WEIGHTS_NAME)
58 
59     def __call__(self, **kwargs):
60         inputs = {k: np.array(v) for k, v in kwargs.items()}
61         return self.model.run(None, inputs)
62 
63     @staticmethod
64     def load_model(path: Union[str, Path], provider=None, sess_options=None):
65         """
66         Loads an ONNX Inference session with an ExecutionProvider. Default provider is `CPUExecutionProvider`
67 
68         Arguments:
69             path (`str` or `Path`):
70                 Directory from which to load
71             provider(`str`, *optional*):
72                 Onnxruntime execution provider to use for loading the model, defaults to `CPUExecutionProvider`
73         """
74         if provider is None:
75             logger.info("No onnxruntime provider specified, using CPUExecutionProvider")
76             provider = "CPUExecutionProvider"
77 
78         return ort.InferenceSession(path, providers=[provider], sess_options=sess_options)
79 
80     def _save_pretrained(self, save_directory: Union[str, Path], file_name: Optional[str] = None, **kwargs):
81         """
82         Save a model and its configuration file to a directory, so that it can be re-loaded using the
83         [`~optimum.onnxruntime.modeling_ort.ORTModel.from_pretrained`] class method. It will always save the
84         latest_model_name.
85 
86         Arguments:
87             save_directory (`str` or `Path`):
88                 Directory where to save the model file.
89             file_name(`str`, *optional*):
90                 Overwrites the default model file name from `"model.onnx"` to `file_name`. This allows you to save the
91                 model with a different name.
92         """
93         model_file_name = file_name if file_name is not None else ONNX_WEIGHTS_NAME
94 
95         src_path = self.model_save_dir.joinpath(self.latest_model_name)
96         dst_path = Path(save_directory).joinpath(model_file_name)
97         try:
98             shutil.copyfile(src_path, dst_path)
99         except shutil.SameFileError:
100             pass
101 
102         # copy external weights (for models >2GB)
103         src_path = self.model_save_dir.joinpath(ONNX_EXTERNAL_WEIGHTS_NAME)
104         if src_path.exists():
105             dst_path = Path(save_directory).joinpath(ONNX_EXTERNAL_WEIGHTS_NAME)
106             try:
107                 shutil.copyfile(src_path, dst_path)
108             except shutil.SameFileError:
109                 pass
110 
111     def save_pretrained(
112         self,
113         save_directory: Union[str, os.PathLike],
114         **kwargs,
115     ):
116         """
117         Save a model to a directory, so that it can be re-loaded using the [`~OnnxModel.from_pretrained`] class
118         method.:
119 
120         Arguments:
121             save_directory (`str` or `os.PathLike`):
122                 Directory to which to save. Will be created if it doesn't exist.
123         """
124         if os.path.isfile(save_directory):
125             logger.error(f"Provided path ({save_directory}) should be a directory, not a file")
126             return
127 
128         os.makedirs(save_directory, exist_ok=True)
129 
130         # saving model weights/files
131         self._save_pretrained(save_directory, **kwargs)
132 
133     @classmethod
134     @validate_hf_hub_args
135     def _from_pretrained(
136         cls,
137         model_id: Union[str, Path],
138         token: Optional[Union[bool, str, None]] = None,
139         revision: Optional[Union[str, None]] = None,
140         force_download: bool = False,
141         cache_dir: Optional[str] = None,
142         file_name: Optional[str] = None,
143         provider: Optional[str] = None,
144         sess_options: Optional["ort.SessionOptions"] = None,
145         **kwargs,
146     ):
147         """
148         Load a model from a directory or the HF Hub.
149 
150         Arguments:
151             model_id (`str` or `Path`):
152                 Directory from which to load
153             token (`str` or `bool`):
154                 Is needed to load models from a private or gated repository
155             revision (`str`):
156                 Revision is the specific model version to use. It can be a branch name, a tag name, or a commit id
157             cache_dir (`Union[str, Path]`, *optional*):
158                 Path to a directory in which a downloaded pretrained model configuration should be cached if the
159                 standard cache should not be used.
160             force_download (`bool`, *optional*, defaults to `False`):
161                 Whether or not to force the (re-)download of the model weights and configuration files, overriding the
162                 cached versions if they exist.
163             file_name(`str`):
164                 Overwrites the default model file name from `"model.onnx"` to `file_name`. This allows you to load
165                 different model files from the same repository or directory.
166             provider(`str`):
167                 The ONNX runtime provider, e.g. `CPUExecutionProvider` or `CUDAExecutionProvider`.
168             kwargs (`Dict`, *optional*):
169                 kwargs will be passed to the model during initialization
170         """
171         model_file_name = file_name if file_name is not None else ONNX_WEIGHTS_NAME
172         # load model from local directory
173         if os.path.isdir(model_id):
174             model = OnnxRuntimeModel.load_model(
175                 os.path.join(model_id, model_file_name), provider=provider, sess_options=sess_options
176             )
177             kwargs["model_save_dir"] = Path(model_id)
178         # load model from hub
179         else:
180             # download model
181             model_cache_path = hf_hub_download(
182                 repo_id=model_id,
183                 filename=model_file_name,
184                 token=token,
185                 revision=revision,
186                 cache_dir=cache_dir,
187                 force_download=force_download,
188             )
189             kwargs["model_save_dir"] = Path(model_cache_path).parent
190             kwargs["latest_model_name"] = Path(model_cache_path).name
191             model = OnnxRuntimeModel.load_model(model_cache_path, provider=provider, sess_options=sess_options)
192         return cls(model=model, **kwargs)
193 
194     @classmethod
195     @validate_hf_hub_args
196     def from_pretrained(
197         cls,
198         model_id: Union[str, Path],
199         force_download: bool = True,
200         token: Optional[str] = None,
201         cache_dir: Optional[str] = None,
202         **model_kwargs,
203     ):
204         revision = None
205         if len(str(model_id).split("@")) == 2:
206             model_id, revision = model_id.split("@")
207 
208         return cls._from_pretrained(
209             model_id=model_id,
210             revision=revision,
211             cache_dir=cache_dir,
212             force_download=force_download,
213             token=token,
214             **model_kwargs,
215         )
216
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/diffusers/pipelines/onnx_utils.py b/src/diffusers/pipelines/onnx_utils.py
--- a/src/diffusers/pipelines/onnx_utils.py
+++ b/src/diffusers/pipelines/onnx_utils.py
@@ -172,7 +172,7 @@
         # load model from local directory
         if os.path.isdir(model_id):
             model = OnnxRuntimeModel.load_model(
-                os.path.join(model_id, model_file_name), provider=provider, sess_options=sess_options
+                Path(model_id, model_file_name).as_posix(), provider=provider, sess_options=sess_options
             )
             kwargs["model_save_dir"] = Path(model_id)
         # load model from hub

{"golden_diff": "diff --git a/src/diffusers/pipelines/onnx_utils.py b/src/diffusers/pipelines/onnx_utils.py\n--- a/src/diffusers/pipelines/onnx_utils.py\n+++ b/src/diffusers/pipelines/onnx_utils.py\n@@ -172,7 +172,7 @@\n         # load model from local directory\n         if os.path.isdir(model_id):\n             model = OnnxRuntimeModel.load_model(\n-                os.path.join(model_id, model_file_name), provider=provider, sess_options=sess_options\n+                Path(model_id, model_file_name).as_posix(), provider=provider, sess_options=sess_options\n             )\n             kwargs[\"model_save_dir\"] = Path(model_id)\n         # load model from hub\n", "issue": "[Tracker] change to posix for better Windows support\nIn https://github.com/huggingface/diffusers/pull/6564, @fabiorigano introduced the use of Posix to better support Windows compatibility. \r\n\r\nIt'd be nice to change the instances of `os.path.join()` to `Path(...).as_posix()`. \r\n\r\nFeel free to open PRs for this and tag me. \r\n\r\nWhile opening PRs, please target only ONE script at a time. \r\n\r\nLet's go \ud83d\ude80 \r\n\n", "before_files": [{"content": "# coding=utf-8\n# Copyright 2023 The HuggingFace Inc. team.\n# Copyright (c) 2022, NVIDIA CORPORATION.  All rights reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\nimport os\nimport shutil\nfrom pathlib import Path\nfrom typing import Optional, Union\n\nimport numpy as np\nfrom huggingface_hub import hf_hub_download\nfrom huggingface_hub.utils import validate_hf_hub_args\n\nfrom ..utils import ONNX_EXTERNAL_WEIGHTS_NAME, ONNX_WEIGHTS_NAME, is_onnx_available, logging\n\n\nif is_onnx_available():\n    import onnxruntime as ort\n\n\nlogger = logging.get_logger(__name__)\n\nORT_TO_NP_TYPE = {\n    \"tensor(bool)\": np.bool_,\n    \"tensor(int8)\": np.int8,\n    \"tensor(uint8)\": np.uint8,\n    \"tensor(int16)\": np.int16,\n    \"tensor(uint16)\": np.uint16,\n    \"tensor(int32)\": np.int32,\n    \"tensor(uint32)\": np.uint32,\n    \"tensor(int64)\": np.int64,\n    \"tensor(uint64)\": np.uint64,\n    \"tensor(float16)\": np.float16,\n    \"tensor(float)\": np.float32,\n    \"tensor(double)\": np.float64,\n}\n\n\nclass OnnxRuntimeModel:\n    def __init__(self, model=None, **kwargs):\n        logger.info(\"`diffusers.OnnxRuntimeModel` is experimental and might change in the future.\")\n        self.model = model\n        self.model_save_dir = kwargs.get(\"model_save_dir\", None)\n        self.latest_model_name = kwargs.get(\"latest_model_name\", ONNX_WEIGHTS_NAME)\n\n    def __call__(self, **kwargs):\n        inputs = {k: np.array(v) for k, v in kwargs.items()}\n        return self.model.run(None, inputs)\n\n    @staticmethod\n    def load_model(path: Union[str, Path], provider=None, sess_options=None):\n        \"\"\"\n        Loads an ONNX Inference session with an ExecutionProvider. Default provider is `CPUExecutionProvider`\n\n        Arguments:\n            path (`str` or `Path`):\n                Directory from which to load\n            provider(`str`, *optional*):\n                Onnxruntime execution provider to use for loading the model, defaults to `CPUExecutionProvider`\n        \"\"\"\n        if provider is None:\n            logger.info(\"No onnxruntime provider specified, using CPUExecutionProvider\")\n            provider = \"CPUExecutionProvider\"\n\n        return ort.InferenceSession(path, providers=[provider], sess_options=sess_options)\n\n    def _save_pretrained(self, save_directory: Union[str, Path], file_name: Optional[str] = None, **kwargs):\n        \"\"\"\n        Save a model and its configuration file to a directory, so that it can be re-loaded using the\n        [`~optimum.onnxruntime.modeling_ort.ORTModel.from_pretrained`] class method. It will always save the\n        latest_model_name.\n\n        Arguments:\n            save_directory (`str` or `Path`):\n                Directory where to save the model file.\n            file_name(`str`, *optional*):\n                Overwrites the default model file name from `\"model.onnx\"` to `file_name`. This allows you to save the\n                model with a different name.\n        \"\"\"\n        model_file_name = file_name if file_name is not None else ONNX_WEIGHTS_NAME\n\n        src_path = self.model_save_dir.joinpath(self.latest_model_name)\n        dst_path = Path(save_directory).joinpath(model_file_name)\n        try:\n            shutil.copyfile(src_path, dst_path)\n        except shutil.SameFileError:\n            pass\n\n        # copy external weights (for models >2GB)\n        src_path = self.model_save_dir.joinpath(ONNX_EXTERNAL_WEIGHTS_NAME)\n        if src_path.exists():\n            dst_path = Path(save_directory).joinpath(ONNX_EXTERNAL_WEIGHTS_NAME)\n            try:\n                shutil.copyfile(src_path, dst_path)\n            except shutil.SameFileError:\n                pass\n\n    def save_pretrained(\n        self,\n        save_directory: Union[str, os.PathLike],\n        **kwargs,\n    ):\n        \"\"\"\n        Save a model to a directory, so that it can be re-loaded using the [`~OnnxModel.from_pretrained`] class\n        method.:\n\n        Arguments:\n            save_directory (`str` or `os.PathLike`):\n                Directory to which to save. Will be created if it doesn't exist.\n        \"\"\"\n        if os.path.isfile(save_directory):\n            logger.error(f\"Provided path ({save_directory}) should be a directory, not a file\")\n            return\n\n        os.makedirs(save_directory, exist_ok=True)\n\n        # saving model weights/files\n        self._save_pretrained(save_directory, **kwargs)\n\n    @classmethod\n    @validate_hf_hub_args\n    def _from_pretrained(\n        cls,\n        model_id: Union[str, Path],\n        token: Optional[Union[bool, str, None]] = None,\n        revision: Optional[Union[str, None]] = None,\n        force_download: bool = False,\n        cache_dir: Optional[str] = None,\n        file_name: Optional[str] = None,\n        provider: Optional[str] = None,\n        sess_options: Optional[\"ort.SessionOptions\"] = None,\n        **kwargs,\n    ):\n        \"\"\"\n        Load a model from a directory or the HF Hub.\n\n        Arguments:\n            model_id (`str` or `Path`):\n                Directory from which to load\n            token (`str` or `bool`):\n                Is needed to load models from a private or gated repository\n            revision (`str`):\n                Revision is the specific model version to use. It can be a branch name, a tag name, or a commit id\n            cache_dir (`Union[str, Path]`, *optional*):\n                Path to a directory in which a downloaded pretrained model configuration should be cached if the\n                standard cache should not be used.\n            force_download (`bool`, *optional*, defaults to `False`):\n                Whether or not to force the (re-)download of the model weights and configuration files, overriding the\n                cached versions if they exist.\n            file_name(`str`):\n                Overwrites the default model file name from `\"model.onnx\"` to `file_name`. This allows you to load\n                different model files from the same repository or directory.\n            provider(`str`):\n                The ONNX runtime provider, e.g. `CPUExecutionProvider` or `CUDAExecutionProvider`.\n            kwargs (`Dict`, *optional*):\n                kwargs will be passed to the model during initialization\n        \"\"\"\n        model_file_name = file_name if file_name is not None else ONNX_WEIGHTS_NAME\n        # load model from local directory\n        if os.path.isdir(model_id):\n            model = OnnxRuntimeModel.load_model(\n                os.path.join(model_id, model_file_name), provider=provider, sess_options=sess_options\n            )\n            kwargs[\"model_save_dir\"] = Path(model_id)\n        # load model from hub\n        else:\n            # download model\n            model_cache_path = hf_hub_download(\n                repo_id=model_id,\n                filename=model_file_name,\n                token=token,\n                revision=revision,\n                cache_dir=cache_dir,\n                force_download=force_download,\n            )\n            kwargs[\"model_save_dir\"] = Path(model_cache_path).parent\n            kwargs[\"latest_model_name\"] = Path(model_cache_path).name\n            model = OnnxRuntimeModel.load_model(model_cache_path, provider=provider, sess_options=sess_options)\n        return cls(model=model, **kwargs)\n\n    @classmethod\n    @validate_hf_hub_args\n    def from_pretrained(\n        cls,\n        model_id: Union[str, Path],\n        force_download: bool = True,\n        token: Optional[str] = None,\n        cache_dir: Optional[str] = None,\n        **model_kwargs,\n    ):\n        revision = None\n        if len(str(model_id).split(\"@\")) == 2:\n            model_id, revision = model_id.split(\"@\")\n\n        return cls._from_pretrained(\n            model_id=model_id,\n            revision=revision,\n            cache_dir=cache_dir,\n            force_download=force_download,\n            token=token,\n            **model_kwargs,\n        )\n", "path": "src/diffusers/pipelines/onnx_utils.py"}], "after_files": [{"content": "# coding=utf-8\n# Copyright 2023 The HuggingFace Inc. team.\n# Copyright (c) 2022, NVIDIA CORPORATION.  All rights reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\nimport os\nimport shutil\nfrom pathlib import Path\nfrom typing import Optional, Union\n\nimport numpy as np\nfrom huggingface_hub import hf_hub_download\nfrom huggingface_hub.utils import validate_hf_hub_args\n\nfrom ..utils import ONNX_EXTERNAL_WEIGHTS_NAME, ONNX_WEIGHTS_NAME, is_onnx_available, logging\n\n\nif is_onnx_available():\n    import onnxruntime as ort\n\n\nlogger = logging.get_logger(__name__)\n\nORT_TO_NP_TYPE = {\n    \"tensor(bool)\": np.bool_,\n    \"tensor(int8)\": np.int8,\n    \"tensor(uint8)\": np.uint8,\n    \"tensor(int16)\": np.int16,\n    \"tensor(uint16)\": np.uint16,\n    \"tensor(int32)\": np.int32,\n    \"tensor(uint32)\": np.uint32,\n    \"tensor(int64)\": np.int64,\n    \"tensor(uint64)\": np.uint64,\n    \"tensor(float16)\": np.float16,\n    \"tensor(float)\": np.float32,\n    \"tensor(double)\": np.float64,\n}\n\n\nclass OnnxRuntimeModel:\n    def __init__(self, model=None, **kwargs):\n        logger.info(\"`diffusers.OnnxRuntimeModel` is experimental and might change in the future.\")\n        self.model = model\n        self.model_save_dir = kwargs.get(\"model_save_dir\", None)\n        self.latest_model_name = kwargs.get(\"latest_model_name\", ONNX_WEIGHTS_NAME)\n\n    def __call__(self, **kwargs):\n        inputs = {k: np.array(v) for k, v in kwargs.items()}\n        return self.model.run(None, inputs)\n\n    @staticmethod\n    def load_model(path: Union[str, Path], provider=None, sess_options=None):\n        \"\"\"\n        Loads an ONNX Inference session with an ExecutionProvider. Default provider is `CPUExecutionProvider`\n\n        Arguments:\n            path (`str` or `Path`):\n                Directory from which to load\n            provider(`str`, *optional*):\n                Onnxruntime execution provider to use for loading the model, defaults to `CPUExecutionProvider`\n        \"\"\"\n        if provider is None:\n            logger.info(\"No onnxruntime provider specified, using CPUExecutionProvider\")\n            provider = \"CPUExecutionProvider\"\n\n        return ort.InferenceSession(path, providers=[provider], sess_options=sess_options)\n\n    def _save_pretrained(self, save_directory: Union[str, Path], file_name: Optional[str] = None, **kwargs):\n        \"\"\"\n        Save a model and its configuration file to a directory, so that it can be re-loaded using the\n        [`~optimum.onnxruntime.modeling_ort.ORTModel.from_pretrained`] class method. It will always save the\n        latest_model_name.\n\n        Arguments:\n            save_directory (`str` or `Path`):\n                Directory where to save the model file.\n            file_name(`str`, *optional*):\n                Overwrites the default model file name from `\"model.onnx\"` to `file_name`. This allows you to save the\n                model with a different name.\n        \"\"\"\n        model_file_name = file_name if file_name is not None else ONNX_WEIGHTS_NAME\n\n        src_path = self.model_save_dir.joinpath(self.latest_model_name)\n        dst_path = Path(save_directory).joinpath(model_file_name)\n        try:\n            shutil.copyfile(src_path, dst_path)\n        except shutil.SameFileError:\n            pass\n\n        # copy external weights (for models >2GB)\n        src_path = self.model_save_dir.joinpath(ONNX_EXTERNAL_WEIGHTS_NAME)\n        if src_path.exists():\n            dst_path = Path(save_directory).joinpath(ONNX_EXTERNAL_WEIGHTS_NAME)\n            try:\n                shutil.copyfile(src_path, dst_path)\n            except shutil.SameFileError:\n                pass\n\n    def save_pretrained(\n        self,\n        save_directory: Union[str, os.PathLike],\n        **kwargs,\n    ):\n        \"\"\"\n        Save a model to a directory, so that it can be re-loaded using the [`~OnnxModel.from_pretrained`] class\n        method.:\n\n        Arguments:\n            save_directory (`str` or `os.PathLike`):\n                Directory to which to save. Will be created if it doesn't exist.\n        \"\"\"\n        if os.path.isfile(save_directory):\n            logger.error(f\"Provided path ({save_directory}) should be a directory, not a file\")\n            return\n\n        os.makedirs(save_directory, exist_ok=True)\n\n        # saving model weights/files\n        self._save_pretrained(save_directory, **kwargs)\n\n    @classmethod\n    @validate_hf_hub_args\n    def _from_pretrained(\n        cls,\n        model_id: Union[str, Path],\n        token: Optional[Union[bool, str, None]] = None,\n        revision: Optional[Union[str, None]] = None,\n        force_download: bool = False,\n        cache_dir: Optional[str] = None,\n        file_name: Optional[str] = None,\n        provider: Optional[str] = None,\n        sess_options: Optional[\"ort.SessionOptions\"] = None,\n        **kwargs,\n    ):\n        \"\"\"\n        Load a model from a directory or the HF Hub.\n\n        Arguments:\n            model_id (`str` or `Path`):\n                Directory from which to load\n            token (`str` or `bool`):\n                Is needed to load models from a private or gated repository\n            revision (`str`):\n                Revision is the specific model version to use. It can be a branch name, a tag name, or a commit id\n            cache_dir (`Union[str, Path]`, *optional*):\n                Path to a directory in which a downloaded pretrained model configuration should be cached if the\n                standard cache should not be used.\n            force_download (`bool`, *optional*, defaults to `False`):\n                Whether or not to force the (re-)download of the model weights and configuration files, overriding the\n                cached versions if they exist.\n            file_name(`str`):\n                Overwrites the default model file name from `\"model.onnx\"` to `file_name`. This allows you to load\n                different model files from the same repository or directory.\n            provider(`str`):\n                The ONNX runtime provider, e.g. `CPUExecutionProvider` or `CUDAExecutionProvider`.\n            kwargs (`Dict`, *optional*):\n                kwargs will be passed to the model during initialization\n        \"\"\"\n        model_file_name = file_name if file_name is not None else ONNX_WEIGHTS_NAME\n        # load model from local directory\n        if os.path.isdir(model_id):\n            model = OnnxRuntimeModel.load_model(\n                Path(model_id, model_file_name).as_posix(), provider=provider, sess_options=sess_options\n            )\n            kwargs[\"model_save_dir\"] = Path(model_id)\n        # load model from hub\n        else:\n            # download model\n            model_cache_path = hf_hub_download(\n                repo_id=model_id,\n                filename=model_file_name,\n                token=token,\n                revision=revision,\n                cache_dir=cache_dir,\n                force_download=force_download,\n            )\n            kwargs[\"model_save_dir\"] = Path(model_cache_path).parent\n            kwargs[\"latest_model_name\"] = Path(model_cache_path).name\n            model = OnnxRuntimeModel.load_model(model_cache_path, provider=provider, sess_options=sess_options)\n        return cls(model=model, **kwargs)\n\n    @classmethod\n    @validate_hf_hub_args\n    def from_pretrained(\n        cls,\n        model_id: Union[str, Path],\n        force_download: bool = True,\n        token: Optional[str] = None,\n        cache_dir: Optional[str] = None,\n        **model_kwargs,\n    ):\n        revision = None\n        if len(str(model_id).split(\"@\")) == 2:\n            model_id, revision = model_id.split(\"@\")\n\n        return cls._from_pretrained(\n            model_id=model_id,\n            revision=revision,\n            cache_dir=cache_dir,\n            force_download=force_download,\n            token=token,\n            **model_kwargs,\n        )\n", "path": "src/diffusers/pipelines/onnx_utils.py"}]}