[inductor] fix CompiledArtifact.load path on Windows. (#160268)

fix CompiledArtifact.load path on Windows.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/160268
Approved by: https://github.com/ezyang
This commit is contained in:
Xu Han
2025-08-10 14:22:49 +00:00
committed by PyTorch MergeBot
parent a84b60c0c4
commit 0e3e377bd5
2 changed files with 6 additions and 1 deletions

View File

@ -29,6 +29,7 @@ from torch._inductor.codecache import (
TensorMetadata, TensorMetadata,
TensorMetadataAndValues, TensorMetadataAndValues,
) )
from torch._inductor.cpp_builder import normalize_path_separator
from torch._inductor.custom_graph_pass import ( from torch._inductor.custom_graph_pass import (
CustomGraphModulePass, CustomGraphModulePass,
CustomGraphPass, CustomGraphPass,
@ -1806,7 +1807,9 @@ class TestStandaloneCompile(TestCase):
assert not kwargs assert not kwargs
with tempfile.TemporaryDirectory() as temp_dir: with tempfile.TemporaryDirectory() as temp_dir:
path = os.path.join(temp_dir, "compiled_artifact.bin") path = normalize_path_separator(
os.path.join(temp_dir, "compiled_artifact.bin")
)
with fresh_cache(): with fresh_cache():
compiled_artifact = torch._inductor.standalone_compile(gm, args) compiled_artifact = torch._inductor.standalone_compile(gm, args)

View File

@ -10,6 +10,7 @@ from typing import Any, Callable, Literal, Optional, TYPE_CHECKING
import torch.fx import torch.fx
from torch._dynamo.utils import dynamo_timed from torch._dynamo.utils import dynamo_timed
from torch._inductor.cpp_builder import normalize_path_separator
from torch._inductor.cudagraph_utils import BoxedDeviceIndex from torch._inductor.cudagraph_utils import BoxedDeviceIndex
from torch._inductor.runtime.cache_dir_utils import temporary_cache_dir from torch._inductor.runtime.cache_dir_utils import temporary_cache_dir
from torch._inductor.utils import BoxedBool, InputType from torch._inductor.utils import BoxedBool, InputType
@ -116,6 +117,7 @@ class CompiledArtifact:
def load( def load(
*, path: str, format: Literal["binary", "unpacked"] = "binary" *, path: str, format: Literal["binary", "unpacked"] = "binary"
) -> CompiledArtifact: ) -> CompiledArtifact:
path = normalize_path_separator(path)
with dynamo_timed("CompiledArtifact.load"): with dynamo_timed("CompiledArtifact.load"):
if format == "binary": if format == "binary":
# can't assert that it is a file since it might not exist yet # can't assert that it is a file since it might not exist yet