Revert "Use absolute path path.resolve() -> path.absolute() (#129409)"

This reverts commit 45411d1fc9a2b6d2f891b6ab0ae16409719e09fc.

Reverted https://github.com/pytorch/pytorch/pull/129409 on behalf of https://github.com/jeanschmidt due to Breaking internal CI, @albanD please help get this PR merged ([comment](https://github.com/pytorch/pytorch/pull/129409#issuecomment-2571316444))
This commit is contained in:
PyTorch MergeBot
2025-01-04 14:17:20 +00:00
parent df458be4e5
commit 99f2491af9
83 changed files with 123 additions and 127 deletions

View File

@ -9,7 +9,7 @@ from tempfile import TemporaryDirectory
from typing import Optional from typing import Optional
SCRIPT_DIR = Path(__file__).absolute().parent SCRIPT_DIR = Path(__file__).parent
REPO_DIR = SCRIPT_DIR.parent.parent REPO_DIR = SCRIPT_DIR.parent.parent

View File

@ -12,9 +12,8 @@ import requests
from gitutils import retries_decorator from gitutils import retries_decorator
REPO_ROOT = Path(__file__).absolute().parents[2] REPO_ROOT = Path(__file__).resolve().parent.parent.parent
sys.path.insert(0, str(REPO_ROOT)) sys.path.insert(0, str(REPO_ROOT))
from tools.testing.clickhouse import query_clickhouse from tools.testing.clickhouse import query_clickhouse

View File

@ -7,7 +7,7 @@ from typing import Any, cast, Dict, List, Set
import yaml import yaml
GITHUB_DIR = Path(__file__).absolute().parent.parent GITHUB_DIR = Path(__file__).parent.parent
def get_workflows_push_tags() -> Set[str]: def get_workflows_push_tags() -> Set[str]:

View File

@ -22,7 +22,7 @@ TOKEN = os.environ["GITHUB_TOKEN"]
if not TOKEN: if not TOKEN:
raise Exception("GITHUB_TOKEN is not set") # noqa: TRY002 raise Exception("GITHUB_TOKEN is not set") # noqa: TRY002
REPO_ROOT = Path(__file__).absolute().parents[2] REPO_ROOT = Path(__file__).parents[2]
# Query for all PRs instead of just closed/merged because it's faster # Query for all PRs instead of just closed/merged because it's faster
GRAPHQL_ALL_PRS_BY_UPDATED_AT = """ GRAPHQL_ALL_PRS_BY_UPDATED_AT = """

View File

@ -6,7 +6,7 @@ from pathlib import Path
import yaml import yaml
REPO_ROOT = Path(__file__).absolute().parents[2] REPO_ROOT = Path(__file__).resolve().parents[2]
WORKFLOWS = REPO_ROOT / ".github" / "workflows" WORKFLOWS = REPO_ROOT / ".github" / "workflows"
EXPECTED_GROUP_PREFIX = ( EXPECTED_GROUP_PREFIX = (
"${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}" "${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}"

View File

@ -13,7 +13,7 @@ import jinja2
Arch = Literal["windows", "linux", "macos"] Arch = Literal["windows", "linux", "macos"]
GITHUB_DIR = Path(__file__).absolute().parent.parent GITHUB_DIR = Path(__file__).resolve().parent.parent
LABEL_CIFLOW_TRUNK = "ciflow/trunk" LABEL_CIFLOW_TRUNK = "ciflow/trunk"
LABEL_CIFLOW_UNSTABLE = "ciflow/unstable" LABEL_CIFLOW_UNSTABLE = "ciflow/unstable"

View File

@ -32,7 +32,7 @@ def get_git_remote_name() -> str:
def get_git_repo_dir() -> str: def get_git_repo_dir() -> str:
from pathlib import Path from pathlib import Path
return os.getenv("GIT_REPO_DIR", str(Path(__file__).absolute().parents[2])) return os.getenv("GIT_REPO_DIR", str(Path(__file__).resolve().parents[2]))
def fuzzy_list_to_dict(items: List[Tuple[str, str]]) -> Dict[str, List[str]]: def fuzzy_list_to_dict(items: List[Tuple[str, str]]) -> Dict[str, List[str]]:

View File

@ -26,7 +26,7 @@ def fn(base: str) -> str:
return str(base / Path("aten/src/ATen/native/native_functions.yaml")) return str(base / Path("aten/src/ATen/native/native_functions.yaml"))
with open(Path(__file__).absolute().parents[2] / fn(".")) as f: with open(Path(__file__).parents[2] / fn(".")) as f:
contents = f.read() contents = f.read()
yaml = ruamel.yaml.YAML() # type: ignore[attr-defined] yaml = ruamel.yaml.YAML() # type: ignore[attr-defined]

View File

@ -12,7 +12,7 @@ from gitutils import (
) )
BASE_DIR = Path(__file__).absolute().parent BASE_DIR = Path(__file__).parent
class TestPeekableIterator(TestCase): class TestPeekableIterator(TestCase):

View File

@ -669,7 +669,7 @@ def get_ghstack_prs(
if not open_only or not candidate.is_closed(): if not open_only or not candidate.is_closed():
return False return False
print( print(
f"Skipping {idx + 1} of {len(rev_list)} PR (#{candidate.pr_num}) as its already been merged" f"Skipping {idx+1} of {len(rev_list)} PR (#{candidate.pr_num}) as its already been merged"
) )
return True return True
@ -1596,7 +1596,7 @@ def save_merge_record(
"_id": f"{project}-{pr_num}-{comment_id}-{os.environ.get('GITHUB_RUN_ID')}", "_id": f"{project}-{pr_num}-{comment_id}-{os.environ.get('GITHUB_RUN_ID')}",
} }
] ]
repo_root = Path(__file__).absolute().parents[2] repo_root = Path(__file__).resolve().parent.parent.parent
with open(repo_root / "merge_record.json", "w") as f: with open(repo_root / "merge_record.json", "w") as f:
json.dump(data, f) json.dump(data, f)

View File

@ -85,7 +85,7 @@ def write_kernel(kernel: Kernel, autogen_dir: Path) -> None:
def main(output_dir: Optional[str]) -> None: def main(output_dir: Optional[str]) -> None:
if output_dir is None: if output_dir is None:
output_dir = Path(__file__).absolute().parent output_dir = Path(__file__).parent
else: else:
output_dir = Path(output_dir) output_dir = Path(output_dir)

View File

@ -380,7 +380,7 @@ void dispatch_{family_name}(T cb, int cc = 0) {{
def main(output_dir: Optional[str]) -> None: def main(output_dir: Optional[str]) -> None:
if output_dir is None: if output_dir is None:
output_dir = Path(__file__).absolute().parent output_dir = Path(__file__).parent
else: else:
output_dir = Path(output_dir) output_dir = Path(output_dir)
write_decl_impl( write_decl_impl(

View File

@ -232,7 +232,7 @@ def main(argv):
) )
) )
out_dir = Path(__file__).absolute().parent out_dir = Path(__file__).parent
(out_dir / "nnapi_wrapper.h").write_text( (out_dir / "nnapi_wrapper.h").write_text(
PREFIX PREFIX

View File

@ -330,7 +330,7 @@ def get_json_config(file_name: str, id: str):
file_name (str): name of configuration file to load file_name (str): name of configuration file to load
id (str): configuration that will be loaded id (str): configuration that will be loaded
""" """
with open(Path(__file__).absolute().parent / file_name) as f: with open(Path(__file__).parent / file_name) as f:
json_config = json.load(f)[id] json_config = json.load(f)[id]
return json_config return json_config

View File

@ -16,7 +16,7 @@ matplotlib.use("Agg")
# Create a directory for the images, if it doesn't exist # Create a directory for the images, if it doesn't exist
ACTIVATION_IMAGE_PATH = Path(__file__).absolute().parent / "activation_images" ACTIVATION_IMAGE_PATH = Path(__file__).parent / "activation_images"
if not ACTIVATION_IMAGE_PATH.exists(): if not ACTIVATION_IMAGE_PATH.exists():
ACTIVATION_IMAGE_PATH.mkdir() ACTIVATION_IMAGE_PATH.mkdir()

View File

@ -10,10 +10,7 @@ def get_correct_mypy_version():
(match,) = re.finditer( (match,) = re.finditer(
r"mypy==(\d+(?:\.\d+)*)", r"mypy==(\d+(?:\.\d+)*)",
( (
Path(__file__).absolute().parent.parent Path(__file__).parent.parent / ".ci" / "docker" / "requirements-ci.txt"
/ ".ci"
/ "docker"
/ "requirements-ci.txt"
).read_text(), ).read_text(),
) )
(version,) = match.groups() (version,) = match.groups()

View File

@ -2391,8 +2391,7 @@
"Set", "Set",
"Tuple", "Tuple",
"Union", "Union",
"defaultdict", "defaultdict"
"Path"
], ],
"torch.utils.data.datapipes.utils.snapshot": [ "torch.utils.data.datapipes.utils.snapshot": [
"IterDataPipe", "IterDataPipe",

View File

@ -2,9 +2,9 @@
# Owner(s): ["oncall: distributed"] # Owner(s): ["oncall: distributed"]
import os import os
import pathlib
import tempfile import tempfile
import unittest import unittest
from pathlib import Path
from numpy.testing import assert_array_equal from numpy.testing import assert_array_equal
@ -559,7 +559,7 @@ class DTensorTest(DTensorTestBase):
import_string = ( import_string = (
"import torch.distributed.tensor;" if should_import else "" "import torch.distributed.tensor;" if should_import else ""
) )
filename = Path(f.name) filename = pathlib.Path(f.name)
err_msg = ( err_msg = (
( (
"_pickle.UnpicklingError: Weights only load failed. " "_pickle.UnpicklingError: Weights only load failed. "

View File

@ -5,10 +5,9 @@
# #
# This source code is licensed under the BSD-style license found in the # This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. # LICENSE file in the root directory of this source tree.
import pathlib
import sys import sys
import unittest import unittest
from pathlib import Path
import torch.distributed.elastic.rendezvous as rdvz import torch.distributed.elastic.rendezvous as rdvz
@ -19,7 +18,7 @@ TEST_PACKAGE_PATH = "/out_of_tree_test_package/src"
class OutOfTreeRendezvousTest(unittest.TestCase): class OutOfTreeRendezvousTest(unittest.TestCase):
def test_out_of_tree_handler_loading(self): def test_out_of_tree_handler_loading(self):
current_path = str(Path(__file__).absolute().parent) current_path = str(pathlib.Path(__file__).parent.resolve())
rdvz._register_out_of_tree_handlers() rdvz._register_out_of_tree_handlers()
registry_dict = rdvz.rendezvous_handler_registry._registry registry_dict = rdvz.rendezvous_handler_registry._registry

View File

@ -1,11 +1,11 @@
# Owner(s): ["oncall: distributed"] # Owner(s): ["oncall: distributed"]
import math import math
import pathlib
import sys import sys
from pathlib import Path
REPO_ROOT = Path(__file__).absolute().parents[3] REPO_ROOT = pathlib.Path(__file__).resolve().parent.parent.parent.parent
sys.path.insert(0, str(REPO_ROOT)) sys.path.insert(0, str(REPO_ROOT))
from tools.flight_recorder.components.types import COLLECTIVES, MatchState from tools.flight_recorder.components.types import COLLECTIVES, MatchState

View File

@ -2,8 +2,8 @@
# run time cuda tests, but with the allocator using expandable segments # run time cuda tests, but with the allocator using expandable segments
import os import os
import pathlib
import sys import sys
from pathlib import Path
import torch import torch
from torch.testing._internal.common_cuda import IS_JETSON, IS_WINDOWS from torch.testing._internal.common_cuda import IS_JETSON, IS_WINDOWS
@ -16,10 +16,9 @@ sys.path.append(pytorch_test_dir)
from dynamo.test_cudagraphs import TestAotCudagraphs # noqa: F401 from dynamo.test_cudagraphs import TestAotCudagraphs # noqa: F401
REPO_ROOT = Path(__file__).absolute().parents[2] REPO_ROOT = pathlib.Path(__file__).resolve().parent.parent.parent
sys.path.insert(0, str(REPO_ROOT)) sys.path.insert(0, str(REPO_ROOT))
from tools.stats.import_test_stats import get_disabled_tests from tools.stats.import_test_stats import get_disabled_tests

View File

@ -2,8 +2,8 @@
# run time cuda tests, but with the allocator using expandable segments # run time cuda tests, but with the allocator using expandable segments
import os import os
import pathlib
import sys import sys
from pathlib import Path
import torch import torch
from torch.testing._internal.common_cuda import IS_JETSON, IS_WINDOWS from torch.testing._internal.common_cuda import IS_JETSON, IS_WINDOWS
@ -22,7 +22,7 @@ if HAS_CUDA and not TEST_WITH_ASAN:
CudaGraphTreeTests, CudaGraphTreeTests,
) )
REPO_ROOT = Path(__file__).absolute().parents[2] REPO_ROOT = pathlib.Path(__file__).resolve().parent.parent.parent
sys.path.insert(0, str(REPO_ROOT)) sys.path.insert(0, str(REPO_ROOT))
from tools.stats.import_test_stats import get_disabled_tests # @manual from tools.stats.import_test_stats import get_disabled_tests # @manual

View File

@ -111,7 +111,7 @@ Get the path to `test/jit/fixtures`, where all test models for operator changes
def get_fixtures_path() -> Path: def get_fixtures_path() -> Path:
pytorch_dir = Path(__file__).absolute().parents[3] pytorch_dir = Path(__file__).resolve().parents[3]
fixtures_path = pytorch_dir / "test" / "jit" / "fixtures" fixtures_path = pytorch_dir / "test" / "jit" / "fixtures"
return fixtures_path return fixtures_path

View File

@ -41,7 +41,7 @@ Inherits most tests from TestNNAPI, which loads Android NNAPI models
without the delegate API. without the delegate API.
""" """
# First skip is needed for IS_WINDOWS or IS_MACOS to skip the tests. # First skip is needed for IS_WINDOWS or IS_MACOS to skip the tests.
torch_root = Path(__file__).absolute().parents[2] torch_root = Path(__file__).resolve().parents[2]
lib_path = torch_root / "build" / "lib" / "libnnapi_backend.so" lib_path = torch_root / "build" / "lib" / "libnnapi_backend.so"

View File

@ -21,7 +21,7 @@ from torch.jit.mobile import (
from torch.testing._internal.common_utils import run_tests, TestCase from torch.testing._internal.common_utils import run_tests, TestCase
pytorch_test_dir = Path(__file__).absolute().parents[1] pytorch_test_dir = Path(__file__).resolve().parents[1]
# script_module_v4.ptl and script_module_v5.ptl source code # script_module_v4.ptl and script_module_v5.ptl source code
# class TestModule(torch.nn.Module): # class TestModule(torch.nn.Module):

View File

@ -9,7 +9,7 @@ from torch.testing._internal.common_utils import run_tests, TestCase
from torchgen.operator_versions.gen_mobile_upgraders import sort_upgrader, write_cpp from torchgen.operator_versions.gen_mobile_upgraders import sort_upgrader, write_cpp
pytorch_caffe2_dir = Path(__file__).absolute().parents[2] pytorch_caffe2_dir = Path(__file__).resolve().parents[2]
class TestLiteScriptModule(TestCase): class TestLiteScriptModule(TestCase):

View File

@ -10,7 +10,7 @@ from torch.jit.mobile import _load_for_lite_interpreter
from torch.testing._internal.common_utils import run_tests, TestCase from torch.testing._internal.common_utils import run_tests, TestCase
pytorch_test_dir = Path(__file__).absolute().parents[1] pytorch_test_dir = Path(__file__).resolve().parents[1]
class TestLiteScriptModule(TestCase): class TestLiteScriptModule(TestCase):

View File

@ -3,11 +3,11 @@
from __future__ import annotations from __future__ import annotations
import difflib import difflib
import pathlib
import platform import platform
import sys import sys
import time import time
import traceback import traceback
from pathlib import Path
import numpy as np import numpy as np
@ -169,7 +169,7 @@ torch=={torch.__version__}"""
def save_error_report(file_name: str, text: str): def save_error_report(file_name: str, text: str):
reports_dir = Path("error_reports") reports_dir = pathlib.Path("error_reports")
reports_dir.mkdir(parents=True, exist_ok=True) reports_dir.mkdir(parents=True, exist_ok=True)
file_path = reports_dir / file_name file_path = reports_dir / file_name
with open(file_path, "w", encoding="utf-8") as f: with open(file_path, "w", encoding="utf-8") as f:

View File

@ -6,7 +6,7 @@ from torch.package import PackageExporter
from torch.testing._internal.common_utils import IS_FBCODE, IS_SANDCASTLE from torch.testing._internal.common_utils import IS_FBCODE, IS_SANDCASTLE
packaging_directory = str(Path(__file__).absolute().parent / "package_bc") packaging_directory = f"{Path(__file__).parent}/package_bc"
torch.package.package_exporter._gate_torchscript_serialization = False torch.package.package_exporter._gate_torchscript_serialization = False

View File

@ -2,7 +2,6 @@
import os import os
import zipfile import zipfile
from pathlib import Path
from sys import version_info from sys import version_info
from tempfile import TemporaryDirectory from tempfile import TemporaryDirectory
from textwrap import dedent from textwrap import dedent
@ -33,8 +32,10 @@ except ImportError:
# Support the case where we run this file directly. # Support the case where we run this file directly.
from common import PackageTestCase from common import PackageTestCase
from pathlib import Path
packaging_directory = Path(__file__).absolute().parent
packaging_directory = Path(__file__).parent
@skipIf( @skipIf(

View File

@ -13,7 +13,7 @@ except ImportError:
# Support the case where we run this file directly. # Support the case where we run this file directly.
from common import PackageTestCase from common import PackageTestCase
packaging_directory = str(Path(__file__).absolute().parent / "package_bc") packaging_directory = f"{Path(__file__).parent}/package_bc"
class TestLoadBCPackages(PackageTestCase): class TestLoadBCPackages(PackageTestCase):

View File

@ -198,7 +198,7 @@ class TestMisc(PackageTestCase):
def test_load_python_version_from_package(self): def test_load_python_version_from_package(self):
"""Tests loading a package with a python version embdded""" """Tests loading a package with a python version embdded"""
importer1 = PackageImporter( importer1 = PackageImporter(
str(Path(__file__).absolute().parent / "package_e" / "test_nn_module.pt") f"{Path(__file__).parent}/package_e/test_nn_module.pt"
) )
self.assertEqual(importer1.python_version(), "3.9.7") self.assertEqual(importer1.python_version(), "3.9.7")

View File

@ -2,7 +2,6 @@
import pickle import pickle
from io import BytesIO from io import BytesIO
from pathlib import Path
from sys import version_info from sys import version_info
from textwrap import dedent from textwrap import dedent
from unittest import skipIf from unittest import skipIf
@ -18,8 +17,10 @@ except ImportError:
# Support the case where we run this file directly. # Support the case where we run this file directly.
from common import PackageTestCase from common import PackageTestCase
from pathlib import Path
packaging_directory = Path(__file__).absolute().parent
packaging_directory = Path(__file__).parent
class TestSaveLoad(PackageTestCase): class TestSaveLoad(PackageTestCase):

View File

@ -44,7 +44,7 @@ class TestQuantizationDocs(QuantizationTestCase):
Current working directory when CI is running test seems to vary, this function Current working directory when CI is running test seems to vary, this function
looks for docs relative to this test file. looks for docs relative to this test file.
""" """
core_dir = Path(__file__).absolute().parent core_dir = Path(__file__).parent
assert core_dir.match("test/quantization/core/"), ( assert core_dir.match("test/quantization/core/"), (
"test_docs.py is in an unexpected location. If you've been " "test_docs.py is in an unexpected location. If you've been "
"moving files around, ensure that the test and build files have " "moving files around, ensure that the test and build files have "

View File

@ -41,7 +41,7 @@ from torch.testing._internal.common_utils import (
# using tools/ to optimize test run. # using tools/ to optimize test run.
REPO_ROOT = Path(__file__).absolute().parent.parent REPO_ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO_ROOT)) sys.path.insert(0, str(REPO_ROOT))
from tools.stats.import_test_stats import ( from tools.stats.import_test_stats import (

View File

@ -1,8 +1,8 @@
# Owner(s): ["module: cuda"] # Owner(s): ["module: cuda"]
# run time cuda tests, but with the allocator using expandable segments # run time cuda tests, but with the allocator using expandable segments
import pathlib
import sys import sys
from pathlib import Path
from test_cuda import ( # noqa: F401 from test_cuda import ( # noqa: F401
TestBlockStateAbsorption, TestBlockStateAbsorption,
@ -15,7 +15,7 @@ from torch.testing._internal.common_cuda import IS_JETSON, IS_WINDOWS
from torch.testing._internal.common_utils import run_tests, TEST_WITH_ROCM from torch.testing._internal.common_utils import run_tests, TEST_WITH_ROCM
REPO_ROOT = Path(__file__).absolute().parents[1] REPO_ROOT = pathlib.Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO_ROOT)) sys.path.insert(0, str(REPO_ROOT))
from tools.stats.import_test_stats import get_disabled_tests from tools.stats.import_test_stats import get_disabled_tests

View File

@ -7,6 +7,7 @@ import gc
import gzip import gzip
import io import io
import os import os
import pathlib
import pickle import pickle
import platform import platform
import re import re
@ -4444,7 +4445,7 @@ class TestSerialization(TestCase, SerializationMixin):
with tempfile.NamedTemporaryFile() as f: with tempfile.NamedTemporaryFile() as f:
njt = torch.nested.nested_tensor([[1, 2, 3], [4, 5]], layout=torch.jagged) njt = torch.nested.nested_tensor([[1, 2, 3], [4, 5]], layout=torch.jagged)
torch.save(njt, f) torch.save(njt, f)
filename = Path(f.name) filename = pathlib.Path(f.name)
import_string = "import torch._dynamo;" if should_import else "" import_string = "import torch._dynamo;" if should_import else ""
err_msg = ( err_msg = (
"_pickle.UnpicklingError: Weights only load failed. ``torch.nested`` and ``torch._dynamo``" "_pickle.UnpicklingError: Weights only load failed. ``torch.nested`` and ``torch._dynamo``"

View File

@ -89,7 +89,7 @@ class TestTypeHints(TestCase):
""" """
Run documentation examples through mypy. Run documentation examples through mypy.
""" """
fn = Path(__file__).absolute().parent / "generated_type_hints_smoketest.py" fn = Path(__file__).resolve().parent / "generated_type_hints_smoketest.py"
fn.write_text(get_all_examples()) fn.write_text(get_all_examples())
# OK, so here's the deal. mypy treats installed packages # OK, so here's the deal. mypy treats installed packages
@ -130,7 +130,7 @@ class TestTypeHints(TestCase):
) )
except OSError: except OSError:
raise unittest.SkipTest("cannot symlink") from None raise unittest.SkipTest("cannot symlink") from None
repo_rootdir = Path(__file__).absolute().parent.parent repo_rootdir = Path(__file__).resolve().parent.parent
# TODO: Would be better not to chdir here, this affects the # TODO: Would be better not to chdir here, this affects the
# entire process! # entire process!
with set_cwd(str(repo_rootdir)): with set_cwd(str(repo_rootdir)):

View File

@ -13,7 +13,7 @@ from pathlib import Path
from typing import Any from typing import Any
PYTORCH_ROOTDIR = Path(__file__).absolute().parent.parent PYTORCH_ROOTDIR = Path(__file__).resolve().parent.parent
TORCH_DIR = PYTORCH_ROOTDIR / "torch" TORCH_DIR = PYTORCH_ROOTDIR / "torch"
TORCH_LIB_DIR = TORCH_DIR / "lib" TORCH_LIB_DIR = TORCH_DIR / "lib"
BUILD_DIR = PYTORCH_ROOTDIR / "build" BUILD_DIR = PYTORCH_ROOTDIR / "build"
@ -110,7 +110,7 @@ def main() -> None:
print("More than 100 items needs to be rebuild, run `ninja torch_python` first") print("More than 100 items needs to be rebuild, run `ninja torch_python` first")
sys.exit(-1) sys.exit(-1)
for idx, (name, cmd) in enumerate(build_plan): for idx, (name, cmd) in enumerate(build_plan):
print(f"[{idx + 1} / {len(build_plan)}] Building {name}") print(f"[{idx + 1 } / {len(build_plan)}] Building {name}")
if args.verbose: if args.verbose:
print(cmd) print(cmd)
subprocess.check_call(["sh", "-c", cmd], cwd=BUILD_DIR) subprocess.check_call(["sh", "-c", cmd], cwd=BUILD_DIR)

View File

@ -7,7 +7,7 @@ from pathlib import Path
# <project folder> # <project folder>
HOME_DIR = os.environ["HOME"] HOME_DIR = os.environ["HOME"]
TOOLS_FOLDER = str(Path(__file__).absolute().parents[2]) TOOLS_FOLDER = str(Path(__file__).resolve().parents[2])
# <profile folder> # <profile folder>

View File

@ -85,7 +85,7 @@ if __name__ == "__main__":
args.hip_version = None if args.hip_version == "" else args.hip_version args.hip_version = None if args.hip_version == "" else args.hip_version
args.xpu_version = None if args.xpu_version == "" else args.xpu_version args.xpu_version = None if args.xpu_version == "" else args.xpu_version
pytorch_root = Path(__file__).absolute().parent.parent pytorch_root = Path(__file__).parent.parent
version_path = pytorch_root / "torch" / "version.py" version_path = pytorch_root / "torch" / "version.py"
# Attempt to get tag first, fall back to sha if a tag was not found # Attempt to get tag first, fall back to sha if a tag was not found
tagged_version = get_tag(pytorch_root) tagged_version = get_tag(pytorch_root)

View File

@ -280,7 +280,7 @@ def main(args: list[str]) -> None:
gen_unboxing(native_functions=native_functions, cpu_fm=cpu_fm, selector=selector) gen_unboxing(native_functions=native_functions, cpu_fm=cpu_fm, selector=selector)
if options.output_dependencies: if options.output_dependencies:
depfile_path = Path(options.output_dependencies).absolute() depfile_path = Path(options.output_dependencies).resolve()
depfile_name = depfile_path.name depfile_name = depfile_path.name
depfile_stem = depfile_path.stem depfile_stem = depfile_path.stem

View File

@ -182,7 +182,7 @@ def check_file(
for match in RESULTS_RE.finditer(proc.stdout.decode()): for match in RESULTS_RE.finditer(proc.stdout.decode()):
# Convert the reported path to an absolute path. # Convert the reported path to an absolute path.
abs_path = str(Path(match["file"]).absolute()) abs_path = str(Path(match["file"]).resolve())
message = LintMessage( message = LintMessage(
path=abs_path, path=abs_path,
name=match["code"], name=match["code"],
@ -262,7 +262,7 @@ def main() -> None:
print(json.dumps(err_msg._asdict()), flush=True) print(json.dumps(err_msg._asdict()), flush=True)
sys.exit(0) sys.exit(0)
abs_build_dir = Path(args.build_dir).absolute() abs_build_dir = Path(args.build_dir).resolve()
# Get the absolute path to clang-tidy and use this instead of the relative # Get the absolute path to clang-tidy and use this instead of the relative
# path such as .lintbin/clang-tidy. The problem here is that os.chdir is # path such as .lintbin/clang-tidy. The problem here is that os.chdir is

View File

@ -85,13 +85,13 @@ def extract_include_arg(include_dirs: list[Path], i: int, args: list[str]) -> No
for name in PRE_INCLUDE_ARGS: for name in PRE_INCLUDE_ARGS:
path = extract_one(name, i, args) path = extract_one(name, i, args)
if path is not None: if path is not None:
include_dirs.insert(0, Path(path).absolute()) include_dirs.insert(0, Path(path).resolve())
return return
for name in POST_INCLUDE_ARGS: for name in POST_INCLUDE_ARGS:
path = extract_one(name, i, args) path = extract_one(name, i, args)
if path is not None: if path is not None:
include_dirs.append(Path(path).absolute()) include_dirs.append(Path(path).resolve())
return return
@ -110,7 +110,7 @@ if __name__ == "__main__":
depfile_path = Path(args[i + 1]) depfile_path = Path(args[i + 1])
elif arg == "-c": elif arg == "-c":
# Include the base path of the cuda file # Include the base path of the cuda file
include_dirs.append(Path(args[i + 1]).absolute().parent) include_dirs.append(Path(args[i + 1]).resolve().parent)
else: else:
extract_include_arg(include_dirs, i, args) extract_include_arg(include_dirs, i, args)

View File

@ -30,7 +30,7 @@ def read_sub_write(path: str, prefix_pat: str, new_default: int) -> None:
def main(args: Any) -> None: def main(args: Any) -> None:
pytorch_dir = Path(__file__).absolute().parents[2] pytorch_dir = Path(__file__).parents[2].resolve()
onnx_dir = pytorch_dir / "third_party" / "onnx" onnx_dir = pytorch_dir / "third_party" / "onnx"
os.chdir(onnx_dir) os.chdir(onnx_dir)

View File

@ -44,7 +44,7 @@ def generate_code(
autograd_gen_dir = os.path.join(install_dir, "autograd", "generated") autograd_gen_dir = os.path.join(install_dir, "autograd", "generated")
for d in (autograd_gen_dir, python_install_dir): for d in (autograd_gen_dir, python_install_dir):
os.makedirs(d, exist_ok=True) os.makedirs(d, exist_ok=True)
autograd_dir = os.fspath(Path(__file__).absolute().parent.parent / "autograd") autograd_dir = os.fspath(Path(__file__).parent.parent / "autograd")
if subset == "pybindings" or not subset: if subset == "pybindings" or not subset:
gen_autograd_python( gen_autograd_python(

View File

@ -2,7 +2,7 @@ import sys
from pathlib import Path from pathlib import Path
REPO_ROOT = Path(__file__).absolute().parents[2] REPO_ROOT = Path(__file__).resolve().parents[2]
sys.path.append(str(REPO_ROOT)) sys.path.append(str(REPO_ROOT))
from tools.stats.import_test_stats import get_test_class_times, get_test_times from tools.stats.import_test_stats import get_test_class_times, get_test_times

View File

@ -11,7 +11,7 @@ from typing import Any, Callable, cast, Dict
from urllib.request import urlopen from urllib.request import urlopen
REPO_ROOT = Path(__file__).absolute().parents[2] REPO_ROOT = Path(__file__).resolve().parents[2]
def get_disabled_issues() -> list[str]: def get_disabled_issues() -> list[str]:

View File

@ -5,7 +5,7 @@ from pathlib import Path
from typing import Any, Dict from typing import Any, Dict
REPO_ROOT = Path(__file__).absolute().parents[2] REPO_ROOT = Path(__file__).resolve().parent.parent.parent
def flatten_data(d: Dict[str, Any]) -> Dict[str, Any]: def flatten_data(d: Dict[str, Any]) -> Dict[str, Any]:

View File

@ -32,7 +32,7 @@ def get_artifacts(repo: str, workflow_run_id: int, workflow_run_attempt: int) ->
# pytorch/pytorch/WORKFLOW_ID/RUN_ATTEMPT/artifact/NAME-SUFFIX.zip # pytorch/pytorch/WORKFLOW_ID/RUN_ATTEMPT/artifact/NAME-SUFFIX.zip
s3_filename = re.sub(FILENAME_REGEX, "", artifact_path.name) s3_filename = re.sub(FILENAME_REGEX, "", artifact_path.name)
upload_file_to_s3( upload_file_to_s3(
file_name=str(artifact_path.absolute()), file_name=str(artifact_path.resolve()),
bucket=BUCKET_NAME, bucket=BUCKET_NAME,
key=f"{repo}/{workflow_run_id}/{workflow_run_attempt}/artifact/{s3_filename}", key=f"{repo}/{workflow_run_id}/{workflow_run_attempt}/artifact/{s3_filename}",
) )

View File

@ -10,7 +10,7 @@ from typing import Any
from unittest import mock from unittest import mock
REPO_ROOT = Path(__file__).absolute().parents[3] REPO_ROOT = Path(__file__).resolve().parents[3]
sys.path.append(str(REPO_ROOT)) sys.path.append(str(REPO_ROOT))
from tools.test.heuristics.test_interface import TestTD from tools.test.heuristics.test_interface import TestTD

View File

@ -6,7 +6,7 @@ from pathlib import Path
from typing import Any from typing import Any
REPO_ROOT = Path(__file__).absolute().parents[3] REPO_ROOT = Path(__file__).resolve().parents[3]
sys.path.append(str(REPO_ROOT)) sys.path.append(str(REPO_ROOT))
import tools.testing.target_determination.heuristics.interface as interface import tools.testing.target_determination.heuristics.interface as interface

View File

@ -6,7 +6,7 @@ from pathlib import Path
from typing import Any from typing import Any
REPO_ROOT = Path(__file__).absolute().parents[3] REPO_ROOT = Path(__file__).resolve().parents[3]
sys.path.append(str(REPO_ROOT)) sys.path.append(str(REPO_ROOT))
import tools.testing.target_determination.heuristics.utils as utils import tools.testing.target_determination.heuristics.utils as utils

View File

@ -3,7 +3,7 @@ import unittest
from pathlib import Path from pathlib import Path
REPO_ROOT = Path(__file__).absolute().parents[2] REPO_ROOT = Path(__file__).resolve().parents[2]
try: try:
# using tools/ to optimize test run. # using tools/ to optimize test run.
sys.path.append(str(REPO_ROOT)) sys.path.append(str(REPO_ROOT))

View File

@ -8,7 +8,7 @@ from collections import defaultdict
from pathlib import Path from pathlib import Path
REPO_ROOT = Path(__file__).absolute().parents[2] REPO_ROOT = Path(__file__).resolve().parents[2]
try: try:
# using tools/ to optimize test run. # using tools/ to optimize test run.
sys.path.append(str(REPO_ROOT)) sys.path.append(str(REPO_ROOT))

View File

@ -10,7 +10,7 @@ from typing import Any
from unittest import mock from unittest import mock
REPO_ROOT = Path(__file__).absolute().parents[2] REPO_ROOT = Path(__file__).resolve().parents[2]
sys.path.insert(0, str(REPO_ROOT)) sys.path.insert(0, str(REPO_ROOT))
from tools.stats.upload_metrics import add_global_metric, emit_metric, global_metrics from tools.stats.upload_metrics import add_global_metric, emit_metric, global_metrics

View File

@ -9,7 +9,7 @@ from pathlib import Path
CPP_TEST_PREFIX = "cpp" CPP_TEST_PREFIX = "cpp"
CPP_TEST_PATH = "build/bin" CPP_TEST_PATH = "build/bin"
CPP_TESTS_DIR = os.path.abspath(os.getenv("CPP_TESTS_DIR", default=CPP_TEST_PATH)) CPP_TESTS_DIR = os.path.abspath(os.getenv("CPP_TESTS_DIR", default=CPP_TEST_PATH))
REPO_ROOT = Path(__file__).absolute().parents[2] REPO_ROOT = Path(__file__).resolve().parents[2]
def parse_test_module(test: str) -> str: def parse_test_module(test: str) -> str:
@ -43,7 +43,7 @@ def discover_tests(
] ]
cpp_tests_dir = ( cpp_tests_dir = (
str(base_dir.parent / CPP_TEST_PATH) if cpp_tests_dir is None else cpp_tests_dir f"{base_dir.parent}/{CPP_TEST_PATH}" if cpp_tests_dir is None else cpp_tests_dir
) )
# CPP test files are located under pytorch/build/bin. Unlike Python test, C++ tests # CPP test files are located under pytorch/build/bin. Unlike Python test, C++ tests
# are just binaries and could have any name, i.e. basic or atest # are just binaries and could have any name, i.e. basic or atest

View File

@ -4,7 +4,7 @@ import sys
from pathlib import Path from pathlib import Path
REPO_ROOT = Path(__file__).absolute().parents[2] REPO_ROOT = Path(__file__).resolve().parents[2]
sys.path.insert(0, str(REPO_ROOT)) sys.path.insert(0, str(REPO_ROOT))
from tools.stats.import_test_stats import ( from tools.stats.import_test_stats import (

View File

@ -12,7 +12,7 @@ from typing import Any
import yaml import yaml
REPO_ROOT = Path(__file__).absolute().parents[2] REPO_ROOT = Path(__file__).parents[2]
CONFIG_YML = REPO_ROOT / ".circleci" / "config.yml" CONFIG_YML = REPO_ROOT / ".circleci" / "config.yml"
WORKFLOWS_DIR = REPO_ROOT / ".github" / "workflows" WORKFLOWS_DIR = REPO_ROOT / ".github" / "workflows"

View File

@ -8,7 +8,7 @@ from pathlib import Path
from typing import Any from typing import Any
REPO_ROOT = Path(__file__).absolute().parents[2] REPO_ROOT = Path(__file__).resolve().parents[2]
# These tests are slow enough that it's worth calculating whether the patch # These tests are slow enough that it's worth calculating whether the patch
# touched any related files first. This list was manually generated, but for every # touched any related files first. This list was manually generated, but for every

View File

@ -6,7 +6,7 @@ from pathlib import Path
from typing import Any from typing import Any
REPO_ROOT = Path(__file__).absolute().parents[3] REPO_ROOT = Path(__file__).resolve().parents[3]
def gen_ci_artifact(included: list[Any], excluded: list[Any]) -> None: def gen_ci_artifact(included: list[Any], excluded: list[Any]) -> None:

View File

@ -17,7 +17,7 @@ from tools.testing.target_determination.heuristics.utils import (
from tools.testing.test_run import TestRun from tools.testing.test_run import TestRun
REPO_ROOT = Path(__file__).absolute().parents[3] REPO_ROOT = Path(__file__).parents[3]
keyword_synonyms: dict[str, list[str]] = { keyword_synonyms: dict[str, list[str]] = {
"amp": ["mixed_precision"], "amp": ["mixed_precision"],

View File

@ -16,7 +16,7 @@ from tools.testing.target_determination.heuristics.utils import normalize_rating
from tools.testing.test_run import TestRun from tools.testing.test_run import TestRun
REPO_ROOT = Path(__file__).absolute().parents[4] REPO_ROOT = Path(__file__).resolve().parents[4]
class LLM(HeuristicInterface): class LLM(HeuristicInterface):

View File

@ -20,7 +20,7 @@ from tools.testing.target_determination.heuristics.utils import (
from tools.testing.test_run import TestRun from tools.testing.test_run import TestRun
REPO_ROOT = Path(__file__).absolute().parents[4] REPO_ROOT = Path(__file__).resolve().parents[4]
class PreviouslyFailedInPR(HeuristicInterface): class PreviouslyFailedInPR(HeuristicInterface):

View File

@ -16,7 +16,7 @@ if TYPE_CHECKING:
from tools.testing.test_run import TestRun from tools.testing.test_run import TestRun
REPO_ROOT = Path(__file__).absolute().parents[4] REPO_ROOT = Path(__file__).resolve().parents[4]
def python_test_file_to_test_name(tests: set[str]) -> set[str]: def python_test_file_to_test_name(tests: set[str]) -> set[str]:

View File

@ -14,7 +14,7 @@ if TYPE_CHECKING:
from collections.abc import Sequence from collections.abc import Sequence
REPO_ROOT = Path(__file__).absolute().parents[2] REPO_ROOT = Path(__file__).resolve().parents[2]
IS_MEM_LEAK_CHECK = os.getenv("PYTORCH_TEST_CUDA_MEM_LEAK_CHECK", "0") == "1" IS_MEM_LEAK_CHECK = os.getenv("PYTORCH_TEST_CUDA_MEM_LEAK_CHECK", "0") == "1"
BUILD_ENVIRONMENT = os.getenv("BUILD_ENVIRONMENT", "") BUILD_ENVIRONMENT = os.getenv("BUILD_ENVIRONMENT", "")

View File

@ -9,7 +9,7 @@ import requests
from clickhouse import query_clickhouse # type: ignore[import] from clickhouse import query_clickhouse # type: ignore[import]
REPO_ROOT = Path(__file__).absolute().parents[2] REPO_ROOT = Path(__file__).resolve().parent.parent.parent
QUERY = """ QUERY = """
WITH most_recent_strict_commits AS ( WITH most_recent_strict_commits AS (
SELECT SELECT

View File

@ -7,7 +7,7 @@ from pathlib import Path
from typing import Any from typing import Any
REPO_ROOT = Path(__file__).absolute().parents[2] REPO_ROOT = Path(__file__).resolve().parent.parent.parent
LAST_UPDATED = 0.0 LAST_UPDATED = 0.0

View File

@ -1807,7 +1807,7 @@ class AotCodeCompiler:
@clear_on_fresh_inductor_cache @clear_on_fresh_inductor_cache
@functools.lru_cache @functools.lru_cache
def cpp_prefix_path() -> str: def cpp_prefix_path() -> str:
path = Path(__file__).absolute().parent / "codegen/cpp_prefix.h" path = Path(__file__).parent / "codegen/cpp_prefix.h"
with path.open() as f: with path.open() as f:
content = f.read() content = f.read()
_, filename = write( _, filename = write(

View File

@ -2,7 +2,7 @@
import functools import functools
import logging import logging
import os import os
from pathlib import Path import pathlib
from typing import Any, List from typing import Any, List
from torch._inductor.metrics import get_metric_table, is_metric_table_enabled from torch._inductor.metrics import get_metric_table, is_metric_table_enabled
@ -322,7 +322,7 @@ class MultiKernelCall:
) )
) )
_, _, path = get_path(key, "picked_kernel") _, _, path = get_path(key, "picked_kernel")
return Path(path) return pathlib.Path(path)
def load_cache(self): def load_cache(self):
assert self.picked_kernel is None assert self.picked_kernel is None

View File

@ -1483,9 +1483,7 @@ def _serialize_pattern(
return pattern return pattern
SERIALIZED_PATTERN_PATH = ( SERIALIZED_PATTERN_PATH = Path(__file__).parent / "fx_passes" / "serialized_patterns"
Path(__file__).absolute().parent / "fx_passes" / "serialized_patterns"
)
# This is the set of serialized patterns that we've registered. Used by # This is the set of serialized patterns that we've registered. Used by
# test_serialized_patterns_up_to_date() to ensure the patterns are up # test_serialized_patterns_up_to_date() to ensure the patterns are up

View File

@ -7,13 +7,13 @@ import json
import logging import logging
import os import os
import os.path import os.path
import pathlib
import re import re
import sys import sys
import tempfile import tempfile
import time import time
from collections import defaultdict from collections import defaultdict
from dataclasses import dataclass, field from dataclasses import dataclass, field
from pathlib import Path
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union
from weakref import WeakSet from weakref import WeakSet
@ -768,7 +768,7 @@ def make_module_path_relative(abs_path):
a relative path relative to one of the Python search paths. a relative path relative to one of the Python search paths.
""" """
abs_path = Path(abs_path).absolute() abs_path = pathlib.Path(abs_path).resolve()
for path in sys.path: for path in sys.path:
try: try:
@ -844,7 +844,7 @@ class TorchLogsFormatter(logging.Formatter):
filepath = make_module_path_relative(record.pathname) filepath = make_module_path_relative(record.pathname)
prefix = ( prefix = (
f"{record.rankprefix}{shortlevel}{record.asctime}.{int(record.msecs * 1000):06d} {record.process} " f"{record.rankprefix}{shortlevel}{record.asctime}.{int(record.msecs*1000):06d} {record.process} "
f"{filepath}:" f"{filepath}:"
f"{record.lineno}]{record.traceid}{record.artifactprefix}" f"{record.lineno}]{record.traceid}{record.artifactprefix}"
) )

View File

@ -8,7 +8,7 @@ import contextlib
import dataclasses import dataclasses
import datetime import datetime
import logging import logging
from pathlib import Path import pathlib
from typing import Any, Callable, TYPE_CHECKING from typing import Any, Callable, TYPE_CHECKING
import torch import torch
@ -91,7 +91,7 @@ class CaptureStrategy(abc.ABC):
""" """
self._verbose_print = _verbose_printer(verbose) self._verbose_print = _verbose_printer(verbose)
self._dump = dump self._dump = dump
self._artifacts_dir = Path(artifacts_dir) self._artifacts_dir = pathlib.Path(artifacts_dir)
self._timestamp = timestamp or datetime.datetime.now().strftime( self._timestamp = timestamp or datetime.datetime.now().strftime(
"%Y-%m-%d_%H-%M-%S-%f" "%Y-%m-%d_%H-%M-%S-%f"
) )

View File

@ -8,10 +8,10 @@ import inspect
import itertools import itertools
import logging import logging
import operator import operator
import pathlib
import textwrap import textwrap
import traceback import traceback
import typing import typing
from pathlib import Path
from typing import Any, Callable, Literal, Mapping, Sequence from typing import Any, Callable, Literal, Mapping, Sequence
import onnxscript import onnxscript
@ -1215,7 +1215,7 @@ def export(
profiler = _maybe_start_profiler(profile) profiler = _maybe_start_profiler(profile)
# Create the artifacts directory if it does not exist # Create the artifacts directory if it does not exist
artifacts_dir = Path(artifacts_dir) artifacts_dir = pathlib.Path(artifacts_dir)
if report or profile or dump_exported_program: if report or profile or dump_exported_program:
artifacts_dir.mkdir(parents=True, exist_ok=True) artifacts_dir.mkdir(parents=True, exist_ok=True)

View File

@ -1011,7 +1011,7 @@ class PackageExporter:
def _write_mock_file(self): def _write_mock_file(self):
if "_mock.py" not in self._written_files: if "_mock.py" not in self._written_files:
mock_file = str(Path(__file__).absolute().parent / "_mock.py") mock_file = str(Path(__file__).parent / "_mock.py")
self._write_source_string("_mock", _read_file(mock_file), is_package=False) self._write_source_string("_mock", _read_file(mock_file), is_package=False)
def _execute_dependency_graph(self): def _execute_dependency_graph(self):

View File

@ -22,6 +22,7 @@ import logging
import math import math
import operator import operator
import os import os
import pathlib
import platform import platform
import random import random
import re import re
@ -988,9 +989,9 @@ UNITTEST_ARGS = [sys.argv[0]] + remaining
torch.manual_seed(SEED) torch.manual_seed(SEED)
# CI Prefix path used only on CI environment # CI Prefix path used only on CI environment
CI_TEST_PREFIX = str(Path.cwd()) CI_TEST_PREFIX = str(Path(os.getcwd()))
CI_PT_ROOT = str(Path(CI_TEST_PREFIX).parent) CI_PT_ROOT = str(Path(os.getcwd()).parent)
CI_FUNCTORCH_ROOT = str(Path(CI_PT_ROOT) / "functorch") CI_FUNCTORCH_ROOT = str(os.path.join(Path(os.getcwd()).parent, "functorch"))
def wait_for_process(p, timeout=None): def wait_for_process(p, timeout=None):
try: try:
@ -4357,7 +4358,7 @@ class TestCase(expecttest.TestCase):
def _attempt_load_from_subprocess( def _attempt_load_from_subprocess(
self, self,
file: Path, file: pathlib.Path,
import_string: str, import_string: str,
expected_failure_message: Optional[str] = None expected_failure_message: Optional[str] = None
) -> None: ) -> None:
@ -4366,7 +4367,7 @@ class TestCase(expecttest.TestCase):
weights_only `torch.load` works as expected without global imports. weights_only `torch.load` works as expected without global imports.
Args: Args:
file (Path): The path to the checkpoint to load. file (pathlib.Path): The path to the checkpoint to load.
import_string (str): import string to add to the script import_string (str): import string to add to the script
exected_failure_message (str, optional): The expected failure message if the exected_failure_message (str, optional): The expected failure message if the
checkpoint fails to load. If None, the test will pass checkpoint fails to load. If None, the test will pass
@ -5009,11 +5010,11 @@ def disable_gc():
def find_library_location(lib_name: str) -> Path: def find_library_location(lib_name: str) -> Path:
# return the shared library file in the installed folder if exist, # return the shared library file in the installed folder if exist,
# else the file in the build folder # else the file in the build folder
torch_root = Path(torch.__file__).absolute().parent torch_root = Path(torch.__file__).resolve().parent
path = torch_root / 'lib' / lib_name path = torch_root / 'lib' / lib_name
if os.path.exists(path): if os.path.exists(path):
return path return path
torch_root = Path(__file__).absolute().parents[2] torch_root = Path(__file__).resolve().parents[2]
return torch_root / 'build' / 'lib' / lib_name return torch_root / 'build' / 'lib' / lib_name
def skip_but_pass_in_sandcastle(reason): def skip_but_pass_in_sandcastle(reason):

View File

@ -126,11 +126,11 @@ def _find_rocm_home() -> Optional[str]:
# Guess #2 # Guess #2
hipcc_path = shutil.which('hipcc') hipcc_path = shutil.which('hipcc')
if hipcc_path is not None: if hipcc_path is not None:
rocm_home_path = Path(hipcc_path).resolve().parent.parent rocm_home = os.path.dirname(os.path.dirname(
os.path.realpath(hipcc_path)))
# can be either <ROCM_HOME>/hip/bin/hipcc or <ROCM_HOME>/bin/hipcc # can be either <ROCM_HOME>/hip/bin/hipcc or <ROCM_HOME>/bin/hipcc
if rocm_home_path.name == 'hip': if os.path.basename(rocm_home) == 'hip':
rocm_home_path = rocm_home_path.parent rocm_home = os.path.dirname(rocm_home)
rocm_home = str(rocm_home_path)
else: else:
# Guess #3 # Guess #3
fallback_path = '/opt/rocm' fallback_path = '/opt/rocm'
@ -147,7 +147,8 @@ def _find_sycl_home() -> Optional[str]:
# Guess 1: for source code build developer/user, we'll have icpx in PATH, # Guess 1: for source code build developer/user, we'll have icpx in PATH,
# which will tell us the SYCL_HOME location. # which will tell us the SYCL_HOME location.
if icpx_path is not None: if icpx_path is not None:
sycl_home = str(Path(icpx_path).resolve().parent.parent) sycl_home = os.path.dirname(os.path.dirname(
os.path.realpath(icpx_path)))
# Guess 2: for users install Pytorch with XPU support, the sycl runtime is # Guess 2: for users install Pytorch with XPU support, the sycl runtime is
# inside intel-sycl-rt, which is automatically installed via pip dependency. # inside intel-sycl-rt, which is automatically installed via pip dependency.
@ -156,7 +157,7 @@ def _find_sycl_home() -> Optional[str]:
files = importlib.metadata.files('intel-sycl-rt') or [] files = importlib.metadata.files('intel-sycl-rt') or []
for f in files: for f in files:
if f.name == "libsycl.so": if f.name == "libsycl.so":
sycl_home = str(Path(f.locate()).resolve().parent.parent) sycl_home = os.path.dirname(Path(f.locate()).parent.resolve())
break break
except importlib.metadata.PackageNotFoundError: except importlib.metadata.PackageNotFoundError:
print("Trying to find SYCL_HOME from intel-sycl-rt package, but it is not installed.", print("Trying to find SYCL_HOME from intel-sycl-rt package, but it is not installed.",

View File

@ -1,7 +1,7 @@
# mypy: allow-untyped-defs # mypy: allow-untyped-defs
import os import os
import pathlib
from collections import defaultdict from collections import defaultdict
from pathlib import Path
from typing import Any, Dict, List, Set, Tuple, Union from typing import Any, Dict, List, Set, Tuple, Union
@ -211,7 +211,7 @@ def get_method_definitions(
# 3. Remove first argument after self (unless it is "*datapipes"), default args, and spaces # 3. Remove first argument after self (unless it is "*datapipes"), default args, and spaces
""" """
if root == "": if root == "":
root = str(Path(__file__).absolute().parent) root = str(pathlib.Path(__file__).parent.resolve())
file_path = [file_path] if isinstance(file_path, str) else file_path file_path = [file_path] if isinstance(file_path, str) else file_path
file_path = [os.path.join(root, path) for path in file_path] file_path = [os.path.join(root, path) for path in file_path]
file_paths = find_file_paths( file_paths = find_file_paths(
@ -288,7 +288,7 @@ def main() -> None:
mapDP_method_to_special_output_type, mapDP_method_to_special_output_type,
) )
path = Path(__file__).absolute().parent path = pathlib.Path(__file__).parent.resolve()
replacements = [ replacements = [
("${IterDataPipeMethods}", iter_method_definitions, 4), ("${IterDataPipeMethods}", iter_method_definitions, 4),
("${MapDataPipeMethods}", map_method_definitions, 4), ("${MapDataPipeMethods}", map_method_definitions, 4),

View File

@ -86,7 +86,7 @@ def write_decomposition_util_file(path: str) -> None:
def main() -> None: def main() -> None:
pytorch_dir = Path(__file__).absolute().parents[3] pytorch_dir = Path(__file__).resolve().parents[3]
upgrader_path = pytorch_dir / "torch" / "csrc" / "jit" / "runtime" upgrader_path = pytorch_dir / "torch" / "csrc" / "jit" / "runtime"
write_decomposition_util_file(str(upgrader_path)) write_decomposition_util_file(str(upgrader_path))

View File

@ -2752,7 +2752,7 @@ def get_torchgen_root() -> Path:
If you're depending on torchgen out-of-tree, you can use the root to figure If you're depending on torchgen out-of-tree, you can use the root to figure
out the path to native_functions.yaml out the path to native_functions.yaml
""" """
return Path(__file__).absolute().parent return Path(__file__).parent.resolve()
def main() -> None: def main() -> None:
@ -3043,7 +3043,7 @@ def main() -> None:
gen_declarations_yaml(native_functions=native_functions, cpu_fm=cpu_fm) gen_declarations_yaml(native_functions=native_functions, cpu_fm=cpu_fm)
if options.output_dependencies: if options.output_dependencies:
depfile_path = Path(options.output_dependencies).absolute() depfile_path = Path(options.output_dependencies).resolve()
depfile_name = depfile_path.name depfile_name = depfile_path.name
depfile_stem = depfile_path.stem depfile_stem = depfile_path.stem

View File

@ -984,7 +984,7 @@ def main() -> None:
) )
if options.output_dependencies: if options.output_dependencies:
depfile_path = Path(options.output_dependencies).absolute() depfile_path = Path(options.output_dependencies).resolve()
depfile_name = depfile_path.name depfile_name = depfile_path.name
depfile_stem = depfile_path.stem depfile_stem = depfile_path.stem

View File

@ -380,7 +380,7 @@ def main() -> None:
for up in sorted_upgrader_list: for up in sorted_upgrader_list:
print("after sort upgrader : ", next(iter(up))) print("after sort upgrader : ", next(iter(up)))
pytorch_dir = Path(__file__).absolute().parents[2] pytorch_dir = Path(__file__).resolve().parents[2]
upgrader_path = pytorch_dir / "torch" / "csrc" / "jit" / "mobile" upgrader_path = pytorch_dir / "torch" / "csrc" / "jit" / "mobile"
write_cpp(str(upgrader_path), sorted_upgrader_list) write_cpp(str(upgrader_path), sorted_upgrader_list)

View File

@ -173,7 +173,7 @@ def write_decomposition_util_file(path: str) -> None:
def main() -> None: def main() -> None:
pytorch_dir = Path(__file__).absolute().parents[2] pytorch_dir = Path(__file__).resolve().parents[2]
upgrader_path = pytorch_dir / "torch" / "csrc" / "jit" / "runtime" upgrader_path = pytorch_dir / "torch" / "csrc" / "jit" / "runtime"
write_decomposition_util_file(str(upgrader_path)) write_decomposition_util_file(str(upgrader_path))