Skip to content

Commit dd95900

Browse files
xuhancnpytorchmergebot
authored andcommitted
[AOTI] normalize_path_separator file path for Windows. (pytorch#159726)
`normalize_path_separator` file path for Windows. Pull Request resolved: pytorch#159726 Approved by: https://github.com/angelayi, https://github.com/jansel
1 parent 1cdd665 commit dd95900

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

torch/export/pt2_archive/_package.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import torch
1313
import torch.utils._pytree as pytree
1414
from torch._export.serde.serialize import deserialize, serialize, SerializedArtifact
15+
from torch._inductor.cpp_builder import normalize_path_separator
1516
from torch.export import ExportedProgram
1617
from torch.export._tree_utils import reorder_kwargs
1718
from torch.export.pt2_archive._package_weights import (
@@ -75,6 +76,8 @@ class PT2ArchiveWriter:
7576
"""
7677

7778
def __init__(self, archive_path_or_buffer: FileLike):
79+
if isinstance(archive_path_or_buffer, str):
80+
archive_path_or_buffer = normalize_path_separator(archive_path_or_buffer)
7881
self.archive_file = torch._C.PyTorchFileWriter(archive_path_or_buffer) # type: ignore[arg-type]
7982
# NOTICE: version here is different from the archive_version
8083
# this is the version of zip file format, which is used by PyTorchFileWriter, which write to /.data/version
@@ -169,6 +172,8 @@ class PT2ArchiveReader:
169172
"""
170173

171174
def __init__(self, archive_path_or_buffer: FileLike):
175+
if isinstance(archive_path_or_buffer, str):
176+
archive_path_or_buffer = normalize_path_separator(archive_path_or_buffer)
172177
self.archive_file = torch._C.PyTorchFileReader(archive_path_or_buffer) # type: ignore[arg-type]
173178
assert self.read_string(ARCHIVE_FORMAT_PATH) == ARCHIVE_FORMAT_VALUE, (
174179
"Invalid archive format"

0 commit comments

Comments
 (0)