.. warning:: Under active development, saved files may not be usable in newer versions of PyTorch. Loads an :class:`ExportedProgram` previously saved with :func:`torch.export.save `. Args: ep (ExportedProgram): The exported program to sa
(
f: Union[str, pathlib.Path, io.BytesIO],
*,
extra_files: Optional[Dict[str, Any]] = None,
expected_opset_version: Optional[Dict[str, int]] = None,
)
| 251 | |
| 252 | |
| 253 | def load( |
| 254 | f: Union[str, pathlib.Path, io.BytesIO], |
| 255 | *, |
| 256 | extra_files: Optional[Dict[str, Any]] = None, |
| 257 | expected_opset_version: Optional[Dict[str, int]] = None, |
| 258 | ) -> ExportedProgram: |
| 259 | """ |
| 260 | |
| 261 | .. warning:: |
| 262 | Under active development, saved files may not be usable in newer versions |
| 263 | of PyTorch. |
| 264 | |
| 265 | Loads an :class:`ExportedProgram` previously saved with |
| 266 | :func:`torch.export.save <torch.export.save>`. |
| 267 | |
| 268 | Args: |
| 269 | ep (ExportedProgram): The exported program to save. |
| 270 | |
| 271 | f (Union[str, pathlib.Path, io.BytesIO): A file-like object (has to |
| 272 | implement write and flush) or a string containing a file name. |
| 273 | |
| 274 | extra_files (Optional[Dict[str, Any]]): The extra filenames given in |
| 275 | this map would be loaded and their content would be stored in the |
| 276 | provided map. |
| 277 | |
| 278 | expected_opset_version (Optional[Dict[str, int]]): A map of opset names |
| 279 | to expected opset versions |
| 280 | |
| 281 | Returns: |
| 282 | An :class:`ExportedProgram` object |
| 283 | |
| 284 | Example:: |
| 285 | |
| 286 | import torch |
| 287 | import io |
| 288 | |
| 289 | # Load ExportedProgram from file |
| 290 | ep = torch.export.load('exported_program.pt2') |
| 291 | |
| 292 | # Load ExportedProgram from io.BytesIO object |
| 293 | with open('exported_program.pt2', 'rb') as f: |
| 294 | buffer = io.BytesIO(f.read()) |
| 295 | buffer.seek(0) |
| 296 | ep = torch.export.load(buffer) |
| 297 | |
| 298 | # Load with extra files. |
| 299 | extra_files = {'foo.txt': ''} # values will be replaced with data |
| 300 | ep = torch.export.load('exported_program.pt2', extra_files=extra_files) |
| 301 | print(extra_files['foo.txt']) |
| 302 | print(ep(torch.randn(5))) |
| 303 | """ |
| 304 | from torch._export import load |
| 305 | |
| 306 | return load( |
| 307 | f, extra_files=extra_files, expected_opset_version=expected_opset_version |
| 308 | ) |
| 309 | |
| 310 |
searching dependent graphs…