From e59658a592af3ff15ef3fc0b35739c1573238194 Mon Sep 17 00:00:00 2001 From: Xuehai Pan Date: Tue, 25 Jun 2024 08:05:40 +0800 Subject: [PATCH 1/3] Update [ghstack-poisoned] --- aten/src/ATen/nnapi/codegen.py | 5 +- benchmarks/dynamo/common.py | 11 ++-- test/distributed/nn/jit/test_instantiator.py | 7 ++- test/export/test_serialize.py | 5 +- test/inductor/test_debug_trace.py | 5 +- test/jit/test_save_load.py | 13 ++-- test/lazy/test_ts_opinfo.py | 6 +- test/onnx/error_reproduction.py | 5 +- test/run_test.py | 13 ++-- test/test_serialization.py | 61 ++++++++++++------- test/test_tensorboard.py | 28 +++++---- test/torch_np/check_tests_conform.py | 4 +- .../numpy_tests/core/test_multiarray.py | 7 +-- tools/jit/gen_unboxing.py | 4 +- torch/jit/_monkeytype_config.py | 5 +- torch/utils/data/datapipes/gen_pyi.py | 6 +- torch/utils/model_dump/__init__.py | 19 +++--- torchgen/gen.py | 14 ++--- torchgen/gen_executorch.py | 4 +- 19 files changed, 121 insertions(+), 101 deletions(-) diff --git a/aten/src/ATen/nnapi/codegen.py b/aten/src/ATen/nnapi/codegen.py index 97b087d8349815..b81e5bc7368c51 100755 --- a/aten/src/ATen/nnapi/codegen.py +++ b/aten/src/ATen/nnapi/codegen.py @@ -7,10 +7,11 @@ we need with dlsym. We also generate a "check" wrapper that checks return values and throws C++ exceptions on errors. """ -import pathlib + import re import sys import textwrap +from pathlib import Path PREFIX = """\ @@ -231,7 +232,7 @@ def main(argv): ) ) - out_dir = pathlib.Path(__file__).absolute().parent + out_dir = Path(__file__).absolute().parent (out_dir / "nnapi_wrapper.h").write_text( PREFIX diff --git a/benchmarks/dynamo/common.py b/benchmarks/dynamo/common.py index 6bf50db7639113..8814b955e6299d 100644 --- a/benchmarks/dynamo/common.py +++ b/benchmarks/dynamo/common.py @@ -2,7 +2,6 @@ from __future__ import annotations import abc - import argparse import collections import contextlib @@ -14,7 +13,6 @@ import itertools import logging import os -import pathlib import shutil import signal import subprocess @@ -22,7 +20,7 @@ import time import weakref from contextlib import contextmanager - +from pathlib import Path from typing import ( Any, Callable, @@ -60,6 +58,7 @@ same, ) + try: from torch._dynamo.utils import ( clone_inputs, @@ -81,6 +80,7 @@ from torch.utils import _pytree as pytree from torch.utils._pytree import tree_map, tree_map_only + try: import torch_xla import torch_xla.core.xla_model as xm @@ -914,7 +914,7 @@ def speedup_experiment_onnx( 2. Running ORT with OnnxModel. Writes to ./{output_filename}, which should be - `pathlib.Path(self.output_dir) / f"{self.compiler}_{suite}_{self.dtype}_{self.mode}_{self.device}_{self.testing}.csv". + `Path(self.output_dir) / f"{self.compiler}_{suite}_{self.dtype}_{self.mode}_{self.device}_{self.testing}.csv". TODO(bowbao): Record export time and export peak memory usage. """ @@ -1326,7 +1326,7 @@ def deepcopy_model_and_inputs_to_device(self, model, example_inputs, target_devi def _generate_onnx_model_directory( cls, output_directory: str, compiler_name: str, model_name: str ) -> pathlib.Path: - model_path = pathlib.Path( + model_path = Path( output_directory, ".onnx_models", model_name, @@ -2352,7 +2352,6 @@ def get_fsdp_auto_wrap_policy(self, model_name: str): from diffusers.models.transformer_2d import Transformer2DModel from torchbenchmark.models.nanogpt.model import Block from transformers.models.llama.modeling_llama import LlamaDecoderLayer - from transformers.models.t5.modeling_t5 import T5Block from transformers.models.whisper.modeling_whisper import WhisperEncoderLayer diff --git a/test/distributed/nn/jit/test_instantiator.py b/test/distributed/nn/jit/test_instantiator.py index 03d3a6f050628a..0ece03a4be547e 100644 --- a/test/distributed/nn/jit/test_instantiator.py +++ b/test/distributed/nn/jit/test_instantiator.py @@ -1,14 +1,15 @@ #!/usr/bin/env python3 # Owner(s): ["oncall: distributed"] -import pathlib import sys +from pathlib import Path from typing import Tuple import torch import torch.distributed as dist from torch import nn, Tensor + if not dist.is_available(): print("Distributed not available, skipping tests", file=sys.stderr) sys.exit(0) @@ -45,7 +46,7 @@ def test_get_arg_return_types_from_interface(self): self.assertEqual(return_type_str, "Tuple[Tensor, int, str]") def test_instantiate_scripted_remote_module_template(self): - dir_path = pathlib.Path(instantiator.INSTANTIATED_TEMPLATE_DIR_PATH) + dir_path = Path(instantiator.INSTANTIATED_TEMPLATE_DIR_PATH) # Cleanup. file_paths = dir_path.glob(f"{instantiator._FILE_PREFIX}*.py") @@ -69,7 +70,7 @@ def test_instantiate_scripted_remote_module_template(self): self.assertEqual(num_files_after, 1) def test_instantiate_non_scripted_remote_module_template(self): - dir_path = pathlib.Path(instantiator.INSTANTIATED_TEMPLATE_DIR_PATH) + dir_path = Path(instantiator.INSTANTIATED_TEMPLATE_DIR_PATH) # Cleanup. file_paths = dir_path.glob(f"{instantiator._FILE_PREFIX}*.py") diff --git a/test/export/test_serialize.py b/test/export/test_serialize.py index 1e0a9edf238727..89650262e63620 100644 --- a/test/export/test_serialize.py +++ b/test/export/test_serialize.py @@ -7,10 +7,10 @@ # Owner(s): ["oncall: export"] import copy import io -import pathlib import tempfile import unittest import zipfile +from pathlib import Path import torch import torch._dynamo as torchdynamo @@ -38,7 +38,6 @@ TemporaryFileName, TestCase, ) - from torch.testing._internal.torchbind_impls import init_torchbind_implementations @@ -1052,7 +1051,7 @@ def forward(self, x, y): ep = export(f, inp) with TemporaryFileName() as fname: - path = pathlib.Path(fname) + path = Path(fname) save(ep, path) loaded_ep = load(path) diff --git a/test/inductor/test_debug_trace.py b/test/inductor/test_debug_trace.py index 3d11af6d995f24..bedcca31c47d38 100644 --- a/test/inductor/test_debug_trace.py +++ b/test/inductor/test_debug_trace.py @@ -1,16 +1,17 @@ # Owner(s): ["module: inductor"] import logging import os -import pathlib import re import shutil import sys import unittest +from pathlib import Path import torch from torch._inductor import config, test_operators from torch.testing._internal.inductor_utils import GPU_TYPE, HAS_GPU + try: try: from . import test_torchinductor @@ -43,7 +44,7 @@ def fn(a, b): self.assertEqual(len(cm.output), 1) m = re.match(r"WARNING.* debug trace: (.*)", cm.output[0]) self.assertTrue(m) - filename = pathlib.Path(m.group(1)) + filename = Path(m.group(1)) self.assertTrue(filename.is_dir()) self.assertGreater(filesize(filename / "fx_graph_readable.py"), 512) self.assertGreater(filesize(filename / "fx_graph_runnable.py"), 512) diff --git a/test/jit/test_save_load.py b/test/jit/test_save_load.py index d16f039798895f..7fddb75e9ecf1a 100644 --- a/test/jit/test_save_load.py +++ b/test/jit/test_save_load.py @@ -2,14 +2,15 @@ import io import os -import pathlib import sys +from pathlib import Path from typing import NamedTuple, Optional import torch from torch import Tensor from torch.testing._internal.common_utils import skipIfTorchDynamo, TemporaryFileName + # Make the helper files in test/ importable pytorch_test_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) sys.path.append(pytorch_test_dir) @@ -397,7 +398,7 @@ def forward(self, a): # Save then load. with TemporaryFileName() as fname: - path = pathlib.Path(fname) + path = Path(fname) m.save(path) m2 = torch.jit.load(path) @@ -624,7 +625,7 @@ def get_loaded_inputs(inputs): traced_module = torch.jit.trace(module, input1) traced_inputs = list(traced_module.graph.inputs()) with TemporaryFileName() as fname: - path = pathlib.Path(fname) + path = Path(fname) traced_module.save(path) print(traced_module.graph) loaded_module = torch.jit.load(path, _restore_shapes=True) @@ -640,7 +641,7 @@ def get_loaded_inputs(inputs): traced_module._c._retrieve_traced_inputs()["forward"], [input_tensor] ) with TemporaryFileName() as fname: - path = pathlib.Path(fname) + path = Path(fname) traced_module.save(path) loaded_module = torch.jit.load(path, _restore_shapes=True) loaded_inputs = list(loaded_module.graph.inputs()) @@ -659,7 +660,7 @@ def get_loaded_inputs(inputs): self.assertEqual(len(traced_module._c._retrieve_traced_inputs()), 0) with TemporaryFileName() as fname: - path = pathlib.Path(fname) + path = Path(fname) traced_module.save(path) loaded_module = torch.jit.load(path, _restore_shapes=True) loaded_inputs = list(loaded_module.graph.inputs()) @@ -1055,7 +1056,7 @@ def forward(self, a): # Save then load. with TemporaryFileName() as fname: - path = pathlib.Path(fname) + path = Path(fname) torch.jit.save_jit_module_to_flatbuffer(m, path) m2 = torch.jit.load(path) diff --git a/test/lazy/test_ts_opinfo.py b/test/lazy/test_ts_opinfo.py index 102dee3664bee0..ddad7b931f3841 100644 --- a/test/lazy/test_ts_opinfo.py +++ b/test/lazy/test_ts_opinfo.py @@ -3,7 +3,7 @@ import functools import itertools import os -import pathlib +from pathlib import Path from typing import Sequence from unittest import skip @@ -20,10 +20,10 @@ ops, ) from torch.testing._internal.common_methods_invocations import op_db - from torch.testing._internal.common_utils import run_tests, TestCase from torch.testing._internal.jit_utils import JitTestCase + torch._lazy.ts_backend.init() @@ -36,7 +36,7 @@ def remove_suffixes(l): def init_lists(): - path_to_script = pathlib.Path(os.path.abspath(os.path.dirname(__file__))) + path_to_script = Path(os.path.abspath(os.path.dirname(__file__))) TS_NATIVE_FUNCTIONS_PATH = ( path_to_script.parent.parent / "aten/src/ATen/native/ts_native_functions.yaml" ) diff --git a/test/onnx/error_reproduction.py b/test/onnx/error_reproduction.py index d2af1ec86bdfe7..4277aa2b1eb090 100644 --- a/test/onnx/error_reproduction.py +++ b/test/onnx/error_reproduction.py @@ -3,11 +3,11 @@ from __future__ import annotations import difflib -import pathlib import platform import sys import time import traceback +from pathlib import Path import numpy as np @@ -17,6 +17,7 @@ import torch + _MISMATCH_MARKDOWN_TEMPLATE = """\ ### Summary @@ -168,7 +169,7 @@ def create_mismatch_report( def save_error_report(file_name: str, text: str): - reports_dir = pathlib.Path("error_reports") + reports_dir = Path("error_reports") reports_dir.mkdir(parents=True, exist_ok=True) file_path = reports_dir / file_name with open(file_path, "w", encoding="utf-8") as f: diff --git a/test/run_test.py b/test/run_test.py index 11e4ef3eaf701b..fa349ebd7a4f9c 100755 --- a/test/run_test.py +++ b/test/run_test.py @@ -5,7 +5,6 @@ import glob import json import os -import pathlib import re import shutil import signal @@ -16,6 +15,7 @@ from collections import defaultdict from contextlib import ExitStack from datetime import datetime +from pathlib import Path from typing import Any, cast, Dict, List, NamedTuple, Optional, Sequence, Tuple, Union import pkg_resources @@ -38,7 +38,8 @@ TEST_WITH_SLOW_GRADCHECK, ) -REPO_ROOT = pathlib.Path(__file__).absolute().parent.parent + +REPO_ROOT = Path(__file__).absolute().parent.parent # using tools/ to optimize test run. sys.path.insert(0, str(REPO_ROOT)) @@ -61,7 +62,6 @@ gen_additional_test_failures_file, ) from tools.testing.target_determination.heuristics.utils import get_pr_number - from tools.testing.test_run import TestRun from tools.testing.test_selections import ( calculate_shards, @@ -71,6 +71,7 @@ THRESHOLD, ) + HAVE_TEST_SELECTION_TOOLS = True # Make sure to remove REPO_ROOT after import is done sys.path.remove(str(REPO_ROOT)) @@ -465,7 +466,7 @@ def run_test( ) else: cpp_test = os.path.join( - pathlib.Path(test_directory).parent, + Path(test_directory).parent, CPP_TEST_PATH, test_file.replace(f"{CPP_TEST_PREFIX}/", ""), ) @@ -800,11 +801,9 @@ def run_doctests(test_module, test_directory, options): Assumes the incoming test module is called doctest, and simply executes the xdoctest runner on the torch library itself. """ - import pathlib - import xdoctest - pkgpath = pathlib.Path(torch.__file__).parent + pkgpath = Path(torch.__file__).parent exclude_module_list = ["torch._vendor.*"] enabled = { diff --git a/test/test_serialization.py b/test/test_serialization.py index f22331831c39d8..9365a35de62b15 100644 --- a/test/test_serialization.py +++ b/test/test_serialization.py @@ -1,40 +1,57 @@ # Owner(s): ["module: serialization"] -import torch -import unittest -import io -import tempfile -import os +import copy import gc -import sys -import zipfile -import warnings import gzip -import copy +import io +import os import pickle -import shutil -import pathlib import platform +import shutil +import sys +import tempfile +import unittest +import warnings +import zipfile from collections import OrderedDict from copy import deepcopy from itertools import product +from pathlib import Path -from torch._utils_internal import get_file_path_2 +import torch from torch._utils import _rebuild_tensor -from torch.utils._import_utils import import_dill -from torch.serialization import check_module_version_greater_or_equal, get_default_load_endianness, \ - set_default_load_endianness, LoadEndianness - -from torch.testing._internal.common_utils import ( - IS_FILESYSTEM_UTF8_ENCODING, TemporaryDirectoryName, - TestCase, IS_FBCODE, IS_WINDOWS, TEST_DILL, run_tests, download_file, BytesIOContext, TemporaryFileName, - parametrize, instantiate_parametrized_tests, AlwaysWarnTypedStorageRemoval, serialTest, skipIfTorchDynamo) +from torch._utils_internal import get_file_path_2 +from torch.serialization import ( + check_module_version_greater_or_equal, + get_default_load_endianness, + LoadEndianness, + set_default_load_endianness, +) from torch.testing._internal.common_device_type import instantiate_device_type_tests from torch.testing._internal.common_dtype import all_types_and_complex_and +from torch.testing._internal.common_utils import ( + AlwaysWarnTypedStorageRemoval, + BytesIOContext, + download_file, + instantiate_parametrized_tests, + IS_FBCODE, + IS_FILESYSTEM_UTF8_ENCODING, + IS_WINDOWS, + parametrize, + run_tests, + serialTest, + skipIfTorchDynamo, + TemporaryDirectoryName, + TemporaryFileName, + TEST_DILL, + TestCase, +) from torch.testing._internal.two_tensor import TwoTensor # noqa: F401 +from torch.utils._import_utils import import_dill + if not IS_WINDOWS: - from mmap import MAP_SHARED, MAP_PRIVATE + from mmap import MAP_PRIVATE, MAP_SHARED else: MAP_SHARED, MAP_PRIVATE = None, None @@ -974,7 +991,7 @@ def test_pathlike_serialization(self, weights_only): model = torch.nn.Conv2d(20, 3200, kernel_size=3) with TemporaryFileName() as fname: - path = pathlib.Path(fname) + path = Path(fname) torch.save(model.state_dict(), path) torch.load(path, weights_only=weights_only) diff --git a/test/test_tensorboard.py b/test/test_tensorboard.py index 1e79a2bf910cec..763091e72240e6 100644 --- a/test/test_tensorboard.py +++ b/test/test_tensorboard.py @@ -1,13 +1,16 @@ # Owner(s): ["module: unknown"] -import expecttest import io -import numpy as np import os import shutil import sys import tempfile import unittest +from pathlib import Path + +import expecttest +import numpy as np + TEST_TENSORBOARD = True try: @@ -36,14 +39,15 @@ import torch from torch.testing._internal.common_utils import ( instantiate_parametrized_tests, + IS_MACOS, + IS_WINDOWS, parametrize, - TestCase, run_tests, TEST_WITH_CROSSREF, - IS_WINDOWS, - IS_MACOS, + TestCase, ) + def tensor_N(shape, dtype=float): numel = np.prod(shape) x = (np.arange(numel, dtype=dtype)).reshape(shape) @@ -75,15 +79,16 @@ def tearDown(self): if TEST_TENSORBOARD: + from google.protobuf import text_format + from PIL import Image from tensorboard.compat.proto.graph_pb2 import GraphDef - from torch.utils.tensorboard import summary, SummaryWriter - from torch.utils.tensorboard._utils import _prepare_video, convert_to_HWC from tensorboard.compat.proto.types_pb2 import DataType - from torch.utils.tensorboard.summary import int_to_half, tensor_proto + + from torch.utils.tensorboard import summary, SummaryWriter from torch.utils.tensorboard._convert_np import make_np from torch.utils.tensorboard._pytorch_graph import graph - from google.protobuf import text_format - from PIL import Image + from torch.utils.tensorboard._utils import _prepare_video, convert_to_HWC + from torch.utils.tensorboard.summary import int_to_half, tensor_proto class TestTensorBoardPyTorchNumpy(BaseTestCase): def test_pytorch_np(self): @@ -289,9 +294,8 @@ def test_summary_writer_close(self): self.assertTrue(passed) def test_pathlib(self): - import pathlib with tempfile.TemporaryDirectory(prefix="test_tensorboard_pathlib") as d: - p = pathlib.Path(d) + p = Path(d) with SummaryWriter(p) as writer: writer.add_scalar('test', 1) diff --git a/test/torch_np/check_tests_conform.py b/test/torch_np/check_tests_conform.py index a93c1d629368ef..05ff5357b7c7c2 100644 --- a/test/torch_np/check_tests_conform.py +++ b/test/torch_np/check_tests_conform.py @@ -1,6 +1,6 @@ -import pathlib import sys import textwrap +from pathlib import Path def check(path): @@ -62,7 +62,7 @@ def report_violation(line, lineno, header): if len(argv) != 2: raise ValueError("Usage : python check_tests_conform path/to/file/or/dir") - path = pathlib.Path(argv[1]) + path = Path(argv[1]) if path.is_dir(): # run for all files in the directory (no subdirs) diff --git a/test/torch_np/numpy_tests/core/test_multiarray.py b/test/torch_np/numpy_tests/core/test_multiarray.py index 76af79f6208418..32ebee01cf6fed 100644 --- a/test/torch_np/numpy_tests/core/test_multiarray.py +++ b/test/torch_np/numpy_tests/core/test_multiarray.py @@ -9,16 +9,14 @@ import mmap import operator import os - -import pathlib import sys import tempfile import warnings import weakref from contextlib import contextmanager from decimal import Decimal +from pathlib import Path from tempfile import mkstemp - from unittest import expectedFailure as xfail, skipIf as skipif, SkipTest import numpy @@ -37,6 +35,7 @@ xpassIfTorchDynamo, ) + # If we are going to trace through these, we should use NumPy # If testing on eager mode, we use torch._numpy if TEST_WITH_TORCHDYNAMO: @@ -3866,7 +3865,7 @@ def test_roundtrip(self, x, tmp_filename): assert_array_equal(y, x.flat) def test_roundtrip_dump_pathlib(self, x, tmp_filename): - p = pathlib.Path(tmp_filename) + p = Path(tmp_filename) x.dump(p) y = np.load(p, allow_pickle=True) assert_array_equal(y, x) diff --git a/tools/jit/gen_unboxing.py b/tools/jit/gen_unboxing.py index ee4e2fc2ddb188..15d8365c6f7104 100644 --- a/tools/jit/gen_unboxing.py +++ b/tools/jit/gen_unboxing.py @@ -1,9 +1,9 @@ # Generates RegisterCodegenUnboxedKernels.cpp, UnboxingFunctions.h and UnboxingFunctions.cpp. import argparse import os -import pathlib import sys from dataclasses import dataclass +from pathlib import Path from typing import List, Literal, Sequence, Union import yaml @@ -272,7 +272,7 @@ def main(args: List[str]) -> None: gen_unboxing(native_functions=native_functions, cpu_fm=cpu_fm, selector=selector) if options.output_dependencies: - depfile_path = pathlib.Path(options.output_dependencies).resolve() + depfile_path = Path(options.output_dependencies).resolve() depfile_name = depfile_path.name depfile_stem = depfile_path.stem diff --git a/torch/jit/_monkeytype_config.py b/torch/jit/_monkeytype_config.py index 4662869e36835c..ecf7cd865fdeb7 100644 --- a/torch/jit/_monkeytype_config.py +++ b/torch/jit/_monkeytype_config.py @@ -1,14 +1,15 @@ # mypy: allow-untyped-defs import inspect -import pathlib import sys import typing from collections import defaultdict +from pathlib import Path from types import CodeType from typing import Dict, Iterable, List, Optional import torch + _IS_MONKEYTYPE_INSTALLED = True try: import monkeytype # type: ignore[import] @@ -189,5 +190,5 @@ def jit_code_filter(code: CodeType) -> bool: ): return False - filename = pathlib.Path(code.co_filename).resolve() + filename = Path(code.co_filename).resolve() return not any(_startswith(filename, lib_path) for lib_path in LIB_PATHS) diff --git a/torch/utils/data/datapipes/gen_pyi.py b/torch/utils/data/datapipes/gen_pyi.py index cecf3636ccce49..8e62ece8a5e6d9 100644 --- a/torch/utils/data/datapipes/gen_pyi.py +++ b/torch/utils/data/datapipes/gen_pyi.py @@ -1,7 +1,7 @@ # mypy: allow-untyped-defs import os -import pathlib from collections import defaultdict +from pathlib import Path from typing import Any, Dict, List, Set, Tuple, Union @@ -179,7 +179,7 @@ def get_method_definitions(file_path: Union[str, List[str]], # 3. Remove first argument after self (unless it is "*datapipes"), default args, and spaces """ if root == "": - root = str(pathlib.Path(__file__).absolute().parent) + root = str(Path(__file__).absolute().parent) 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_paths = find_file_paths(file_path, @@ -234,7 +234,7 @@ def main() -> None: map_method_definitions = get_method_definitions(mapDP_file_path, mapDP_files_to_exclude, mapDP_deprecated_files, "MapDataPipe", mapDP_method_to_special_output_type) - path = pathlib.Path(__file__).absolute().parent + path = Path(__file__).absolute().parent replacements = [('${IterDataPipeMethods}', iter_method_definitions, 4), ('${MapDataPipeMethods}', map_method_definitions, 4)] gen_from_template(dir=str(path), diff --git a/torch/utils/model_dump/__init__.py b/torch/utils/model_dump/__init__.py index 7e2bc36d2e7131..f2cd974798f915 100644 --- a/torch/utils/model_dump/__init__.py +++ b/torch/utils/model_dump/__init__.py @@ -64,21 +64,18 @@ (they probably don't work at all right now). """ -import sys -import os -import io -import pathlib -import re import argparse -import zipfile +import io import json +import os import pickle import pprint +import re +import sys import urllib.parse - -from typing import ( - Dict, -) +import zipfile +from pathlib import Path +from typing import Dict import torch.utils.show_pickle @@ -201,7 +198,7 @@ def get_model_info( file_size = path_or_file.stat().st_size # type: ignore[attr-defined] elif isinstance(path_or_file, str): default_title = path_or_file - file_size = pathlib.Path(path_or_file).stat().st_size + file_size = Path(path_or_file).stat().st_size else: default_title = "buffer" path_or_file.seek(0, io.SEEK_END) diff --git a/torchgen/gen.py b/torchgen/gen.py index 53218712ad4b8c..6980c8b2612c3b 100644 --- a/torchgen/gen.py +++ b/torchgen/gen.py @@ -2,9 +2,9 @@ import functools import json import os -import pathlib from collections import defaultdict, namedtuple, OrderedDict from dataclasses import dataclass, field +from pathlib import Path from typing import ( Any, Callable, @@ -2715,12 +2715,12 @@ def gen_declarations_yaml( ) -def get_torchgen_root() -> pathlib.Path: +def get_torchgen_root() -> Path: """ If you're depending on torchgen out-of-tree, you can use the root to figure out the path to native_functions.yaml """ - return pathlib.Path(__file__).absolute().parent + return Path(__file__).absolute().parent def main() -> None: @@ -2882,11 +2882,11 @@ def main() -> None: # # Invalid character escape '\c'. core_install_dir = f"{options.install_dir}/core" - pathlib.Path(core_install_dir).mkdir(parents=True, exist_ok=True) + Path(core_install_dir).mkdir(parents=True, exist_ok=True) ops_install_dir = f"{options.install_dir}/ops" - pathlib.Path(ops_install_dir).mkdir(parents=True, exist_ok=True) + Path(ops_install_dir).mkdir(parents=True, exist_ok=True) aoti_install_dir = f"{options.aoti_install_dir}" - pathlib.Path(aoti_install_dir).mkdir(parents=True, exist_ok=True) + Path(aoti_install_dir).mkdir(parents=True, exist_ok=True) core_fm = make_file_manager(options=options, install_dir=core_install_dir) cpu_fm = make_file_manager(options=options) @@ -2973,7 +2973,7 @@ def main() -> None: gen_declarations_yaml(native_functions=native_functions, cpu_fm=cpu_fm) if options.output_dependencies: - depfile_path = pathlib.Path(options.output_dependencies).resolve() + depfile_path = Path(options.output_dependencies).resolve() depfile_name = depfile_path.name depfile_stem = depfile_path.stem diff --git a/torchgen/gen_executorch.py b/torchgen/gen_executorch.py index 436630bb664571..b9b8df980c41d9 100644 --- a/torchgen/gen_executorch.py +++ b/torchgen/gen_executorch.py @@ -1,8 +1,8 @@ import argparse import os -import pathlib from collections import defaultdict from dataclasses import dataclass +from pathlib import Path from typing import Any, Callable, Dict, List, Optional, Sequence, TextIO, Tuple, Union import yaml @@ -978,7 +978,7 @@ def main() -> None: ) if options.output_dependencies: - depfile_path = pathlib.Path(options.output_dependencies).resolve() + depfile_path = Path(options.output_dependencies).resolve() depfile_name = depfile_path.name depfile_stem = depfile_path.stem From c222ecb2cf6569521cd1206900f37b940dc2e5ef Mon Sep 17 00:00:00 2001 From: Xuehai Pan Date: Tue, 25 Jun 2024 08:36:40 +0800 Subject: [PATCH 2/3] Update [ghstack-poisoned] --- benchmarks/dynamo/common.py | 2 +- test/inductor/test_debug_trace.py | 2 +- test/test_serialization.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/benchmarks/dynamo/common.py b/benchmarks/dynamo/common.py index 8814b955e6299d..71f8dfe4f5aad6 100644 --- a/benchmarks/dynamo/common.py +++ b/benchmarks/dynamo/common.py @@ -1325,7 +1325,7 @@ def deepcopy_model_and_inputs_to_device(self, model, example_inputs, target_devi @classmethod def _generate_onnx_model_directory( cls, output_directory: str, compiler_name: str, model_name: str - ) -> pathlib.Path: + ) -> Path: model_path = Path( output_directory, ".onnx_models", diff --git a/test/inductor/test_debug_trace.py b/test/inductor/test_debug_trace.py index bedcca31c47d38..a2029678f48f10 100644 --- a/test/inductor/test_debug_trace.py +++ b/test/inductor/test_debug_trace.py @@ -23,7 +23,7 @@ raise -def filesize(filename: pathlib.Path): +def filesize(filename: Path): assert filename.exists(), f"{filename} is missing" return os.stat(filename).st_size diff --git a/test/test_serialization.py b/test/test_serialization.py index 9365a35de62b15..27b15246da94a0 100644 --- a/test/test_serialization.py +++ b/test/test_serialization.py @@ -3940,7 +3940,7 @@ def test_serialization_warning_s390x(self): finally: set_default_load_endianness(current_load_endian) - @parametrize('path_type', (str, pathlib.Path)) + @parametrize('path_type', (str, Path)) @parametrize('weights_only', (True, False)) @unittest.skipIf(IS_WINDOWS, "NamedTemporaryFile on windows") def test_serialization_mmap_loading(self, weights_only, path_type): From 77ac6812ba5cb323b62ba2d439c577c4f1642703 Mon Sep 17 00:00:00 2001 From: Xuehai Pan Date: Tue, 25 Jun 2024 19:02:46 +0800 Subject: [PATCH 3/3] Update [ghstack-poisoned] --- test/test_serialization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_serialization.py b/test/test_serialization.py index 34bf5829ea70e8..94d10b848b00a9 100644 --- a/test/test_serialization.py +++ b/test/test_serialization.py @@ -13,7 +13,7 @@ import unittest import warnings import zipfile -from collections import OrderedDict +from collections import namedtuple, OrderedDict from copy import deepcopy from itertools import product from pathlib import Path