Skip to content

Commit 36420b5

Browse files
ezyangpytorchmergebot
authored andcommitted
Rename tools/codegen to torchgen (pytorch#76275)
Summary: Pull Request resolved: pytorch#76275 In preparation for addressing pytorch#73212 Diff was generated with: ``` git mv tools/codegen torchgen git grep -l 'tools.codegen' | xargs sed -i 's/tools.codegen/torchgen/g' sed -i "s/\${TOOLS_PATH}\/codegen/\${TORCH_ROOT}\/torchgen/g" caffe2/CMakeLists.txt ``` and a manual edits to: * tools/test/test_gen_backend_stubs.py * torchgen/build.bzl * torchgen/gen_backend_stubs.py aka this diff: ``` diff --git a/tools/test/test_gen_backend_stubs.py b/tools/test/test_gen_backend_stubs.py index 3dc26c6d2d..104054575e 100644 --- a/tools/test/test_gen_backend_stubs.py +++ b/tools/test/test_gen_backend_stubs.py @@ -9,7 +9,7 @@ from torchgen.gen_backend_stubs import run from torchgen.gen import _GLOBAL_PARSE_NATIVE_YAML_CACHE # noqa: F401 path = os.path.dirname(os.path.realpath(__file__)) -gen_backend_stubs_path = os.path.join(path, '../torchgen/gen_backend_stubs.py') +gen_backend_stubs_path = os.path.join(path, '../../torchgen/gen_backend_stubs.py') # gen_backend_stubs.py is an integration point that is called directly by external backends. # The tests here are to confirm that badly formed inputs result in reasonable error messages. diff --git a/torchgen/build.bzl b/torchgen/build.bzl index ed04e35a43..d00078a3cf 100644 --- a/torchgen/build.bzl +++ b/torchgen/build.bzl @@ -1,6 +1,6 @@ def define_targets(rules): rules.py_library( - name = "codegen", + name = "torchgen", srcs = rules.glob(["**/*.py"]), deps = [ rules.requirement("PyYAML"), @@ -11,6 +11,6 @@ def define_targets(rules): rules.py_binary( name = "gen", - srcs = [":codegen"], + srcs = [":torchgen"], visibility = ["//visibility:public"], ) diff --git a/torchgen/gen_backend_stubs.py b/torchgen/gen_backend_stubs.py index c1a672a655..beee7a15e0 100644 --- a/torchgen/gen_backend_stubs.py +++ b/torchgen/gen_backend_stubs.py @@ -474,7 +474,7 @@ def run( ) -> None: # Assumes that this file lives at PYTORCH_ROOT/torchgen/gen_backend_stubs.py - pytorch_root = pathlib.Path(__file__).parent.parent.parent.absolute() + pytorch_root = pathlib.Path(__file__).parent.parent.absolute() template_dir = os.path.join(pytorch_root, "aten/src/ATen/templates") def make_file_manager(install_dir: str) -> FileManager: ``` run_all_fbandroid_tests Test Plan: sandcastle Reviewed By: albanD, ngimel Differential Revision: D35770317 fbshipit-source-id: 153ac4a7fef15b1e750812a90bfafdbc8f1ebcdf (cherry picked from commit c6d485d)
1 parent 8d31706 commit 36420b5

File tree

85 files changed

+271
-271
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+271
-271
lines changed

.circleci/scripts/cpp_doc_push_script.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ sudo apt-get -y install doxygen
5656
# Generate ATen files
5757
pushd "${pt_checkout}"
5858
pip install -r requirements.txt
59-
time python -m tools.codegen.gen \
59+
time python -m torchgen.gen \
6060
-s aten/src/ATen \
6161
-d build/aten/src/ATen
6262

.jenkins/pytorch/codegen-test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ set -x
2626
rm -rf "$OUT"
2727

2828
# aten codegen
29-
python -m tools.codegen.gen \
29+
python -m torchgen.gen \
3030
-d "$OUT"/torch/share/ATen
3131

3232
# torch codegen

BUILD.bazel

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ generate_aten(
9595
aten_ufunc_generated_cuda_sources("aten/src/ATen/{}") +
9696
["aten/src/ATen/Declarations.yaml"]
9797
),
98-
generator = "//tools/codegen:gen",
98+
generator = "//torchgen:gen",
9999
)
100100

101101
libtorch_cpp_generated_sources = [
@@ -1345,7 +1345,7 @@ cc_library(
13451345
py_binary(
13461346
name = "gen_op",
13471347
srcs = ["caffe2/contrib/aten/gen_op.py"],
1348-
deps = ["//tools/codegen"],
1348+
deps = ["//torchgen"],
13491349
)
13501350

13511351
genrule(

aten/src/ATen/gen_vulkan_glsl.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import glob
55
import sys
66
import os
7-
from tools.codegen.code_template import CodeTemplate
7+
from torchgen.code_template import CodeTemplate
88

99
H_NAME = "glsl.h"
1010
CPP_NAME = "glsl.cpp"

aten/src/ATen/gen_vulkan_spv.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import os
77
import sys
88
import subprocess
9-
from tools.codegen.code_template import CodeTemplate
9+
from torchgen.code_template import CodeTemplate
1010

1111
H_NAME = "spv.h"
1212
CPP_NAME = "spv.cpp"

aten/src/ATen/native/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ If two backends have the same dispatch function, you can write `CPU, CUDA: func`
291291
to reuse the same function name in both cases.
292292

293293
Available backend options can be found by searching `dispatch_keys` in
294-
[codegen](https://github.com/pytorch/pytorch/blob/master/tools/codegen/gen.py).
294+
[codegen](https://github.com/pytorch/pytorch/blob/master/torchgen/gen.py).
295295
There are also two special "generic" backends:
296296

297297
- `CompositeExplicitAutograd` (previously known as `DefaultBackend`):

c10/core/DispatchKey.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ enum class BackendComponent : uint8_t {
9797

9898
// See Note [DispatchKeySet Internal Representation] for more details.
9999
//
100-
// NOTE: Keep the list in sync with `DispatchKey` in tools/codegen/model.py
100+
// NOTE: Keep the list in sync with `DispatchKey` in torchgen/model.py
101101
enum class DispatchKey : uint16_t {
102102

103103
// ~~~~~~~~~~~~~~~~~~~~~~~~~~ UNDEFINED ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //

caffe2/CMakeLists.txt

+5-5
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ if(INTERN_BUILD_ATEN_OPS)
6363
set(CMAKE_POSITION_INDEPENDENT_CODE ${__caffe2_CMAKE_POSITION_INDEPENDENT_CODE})
6464

6565
# Generate the headers wrapped by our operator
66-
file(GLOB_RECURSE all_python "${PROJECT_SOURCE_DIR}/tools/codegen/*.py")
66+
file(GLOB_RECURSE all_python "${PROJECT_SOURCE_DIR}/torchgen/*.py")
6767
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/contrib/aten/aten_op.h
6868
COMMAND
6969
"${PYTHON_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/contrib/aten/gen_op.py
@@ -458,10 +458,10 @@ if(NOT INTERN_BUILD_MOBILE OR NOT BUILD_CAFFE2_MOBILE)
458458
"${TOOLS_PATH}/autograd/gen_variable_type.py"
459459
"${TOOLS_PATH}/autograd/gen_inplace_or_view_type.py"
460460
"${TOOLS_PATH}/autograd/load_derivatives.py"
461-
"${TOOLS_PATH}/codegen/gen_backend_stubs.py"
462-
"${TOOLS_PATH}/codegen/gen_lazy_tensor.py"
463-
"${TOOLS_PATH}/codegen/api/lazy.py"
464-
"${TOOLS_PATH}/codegen/dest/lazy_ir.py"
461+
"${TORCH_ROOT}/torchgen/gen_backend_stubs.py"
462+
"${TORCH_ROOT}/torchgen/gen_lazy_tensor.py"
463+
"${TORCH_ROOT}/torchgen/api/lazy.py"
464+
"${TORCH_ROOT}/torchgen/dest/lazy_ir.py"
465465
WORKING_DIRECTORY "${TORCH_ROOT}")
466466

467467

caffe2/contrib/aten/gen_op.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
raise ValueError('aten_root ({}) does not exist'.format(
3838
args.aten_root))
3939
sys.path.insert(0, os.path.join(args.aten_root, '..'))
40-
from tools.codegen.code_template import CodeTemplate as CT
40+
from torchgen.code_template import CodeTemplate as CT
4141
else:
42-
from tools.codegen.code_template import CodeTemplate as CT
42+
from torchgen.code_template import CodeTemplate as CT
4343

4444
OP_TEMPLATE = CT.from_file(
4545
os.path.join(args.template_dir, 'aten_op_template.h'))

cmake/Codegen.cmake

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ if(INTERN_BUILD_ATEN_OPS)
6767
set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/../aten/src/ATen/MapAllocator.cpp PROPERTIES COMPILE_FLAGS "-fno-openmp")
6868
endif()
6969

70-
file(GLOB_RECURSE all_python "${CMAKE_CURRENT_LIST_DIR}/../tools/codegen/*.py")
70+
file(GLOB_RECURSE all_python "${CMAKE_CURRENT_LIST_DIR}/../torchgen/*.py")
7171

7272
set(GEN_ROCM_FLAG)
7373
if(USE_ROCM)
@@ -148,7 +148,7 @@ if(INTERN_BUILD_ATEN_OPS)
148148
endif()
149149

150150
set(GEN_COMMAND
151-
"${PYTHON_EXECUTABLE}" -m tools.codegen.gen
151+
"${PYTHON_EXECUTABLE}" -m torchgen.gen
152152
--source-path ${CMAKE_CURRENT_LIST_DIR}/../aten/src/ATen
153153
--install_dir ${CMAKE_BINARY_DIR}/aten/src/ATen
154154
${GEN_PER_OPERATOR_FLAG}

docs/cpp/source/check-doxygen.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pushd "$(dirname "$0")/../../.."
1616

1717
cp torch/_utils_internal.py tools/shared
1818

19-
python -m tools.codegen.gen
19+
python -m torchgen.gen
2020

2121
python tools/setup_helpers/generate_code.py \
2222
--native-functions-path aten/src/ATen/native/native_functions.yaml

test/jit/fixtures_srcs/generate_models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def div_Tensor_0_3(self: Tensor, other: Tensor) -> Tensor:
5252
fbcode/caffe2/torch/csrc/jit/mobile/upgrader_mobile.cpp
5353
5454
```
55-
python pytorch/tools/codegen/operator_versions/gen_mobile_upgraders.py
55+
python pytorch/torchgen/operator_versions/gen_mobile_upgraders.py
5656
```
5757
5858
4. Generate the test to cover upgrader.

test/mobile/test_upgrader_codegen.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from torch.testing._internal.common_utils import TestCase, run_tests
44

5-
from tools.codegen.operator_versions.gen_mobile_upgraders import (
5+
from torchgen.operator_versions.gen_mobile_upgraders import (
66
sort_upgrader,
77
write_cpp,
88
)

tools/autograd/build.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ def define_targets(rules):
99
visibility = ["//:__subpackages__"],
1010
deps = [
1111
rules.requirement("PyYAML"),
12-
"//tools/codegen",
12+
"//torchgen:torchgen",
1313
],
1414
)

tools/autograd/context.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from tools.codegen.api.autograd import NativeFunctionWithDifferentiabilityInfo as NFWDI
2-
from tools.codegen.context import native_function_manager
3-
from tools.codegen.utils import T
1+
from torchgen.api.autograd import NativeFunctionWithDifferentiabilityInfo as NFWDI
2+
from torchgen.context import native_function_manager
3+
from torchgen.utils import T
44

55
import functools
66
from typing import Callable

tools/autograd/gen_annotated_fn_args.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020

2121
from typing import Dict, List, Any
2222

23-
from tools.codegen.gen import parse_native_yaml
24-
from tools.codegen.utils import FileManager
25-
from tools.codegen.context import with_native_function
26-
from tools.codegen.model import BaseOperatorName, NativeFunction
27-
import tools.codegen.api.python as python
23+
from torchgen.gen import parse_native_yaml
24+
from torchgen.utils import FileManager
25+
from torchgen.context import with_native_function
26+
from torchgen.model import BaseOperatorName, NativeFunction
27+
import torchgen.api.python as python
2828
from .gen_python_functions import (
2929
should_generate_py_binding,
3030
is_py_torch_function,

tools/autograd/gen_autograd.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424

2525
import argparse
2626
import os
27-
from tools.codegen.api import cpp
28-
from tools.codegen.api.autograd import (
27+
from torchgen.api import cpp
28+
from torchgen.api.autograd import (
2929
match_differentiability_info,
3030
NativeFunctionWithDifferentiabilityInfo,
3131
)
32-
from tools.codegen.gen import parse_native_yaml
33-
from tools.codegen.selective_build.selector import SelectiveBuilder
32+
from torchgen.gen import parse_native_yaml
33+
from torchgen.selective_build.selector import SelectiveBuilder
3434
from typing import List
3535
from . import gen_python_functions
3636
from .gen_autograd_functions import (

tools/autograd/gen_autograd_functions.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
from typing import List, Sequence, Tuple
1010

11-
from tools.codegen.api.autograd import (
11+
from torchgen.api.autograd import (
1212
Derivative,
1313
DifferentiabilityInfo,
1414
SavedAttribute,
1515
uses_retain_variables,
1616
uses_single_grad,
1717
)
18-
from tools.codegen.api.types import (
18+
from torchgen.api.types import (
1919
Binding,
2020
BaseCType,
2121
OptionalCType,
@@ -32,9 +32,9 @@
3232
ArrayRefCType,
3333
optionalIntArrayRefT,
3434
)
35-
from tools.codegen.code_template import CodeTemplate
36-
from tools.codegen.utils import FileManager
37-
from tools.codegen.model import Argument
35+
from torchgen.code_template import CodeTemplate
36+
from torchgen.utils import FileManager
37+
from torchgen.model import Argument
3838

3939
FUNCTION_DECLARATION = CodeTemplate(
4040
"""\

tools/autograd/gen_inplace_or_view_type.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
# if updates are needed in torch/csrc/autograd/autograd_not_implemented_fallback.cpp
55
# The fallback is expected to mimick this codegen, so we should keep the two in sync.
66

7-
from tools.codegen.api import cpp
8-
from tools.codegen.api.autograd import (
7+
from torchgen.api import cpp
8+
from torchgen.api.autograd import (
99
NativeFunctionWithDifferentiabilityInfo,
1010
gen_differentiable_outputs,
1111
dispatch_strategy,
1212
)
13-
from tools.codegen.api.types import (
13+
from torchgen.api.types import (
1414
Binding,
1515
DispatcherSignature,
1616
CType,
@@ -21,9 +21,9 @@
2121
intArrayRefT,
2222
symIntArrayRefT,
2323
)
24-
from tools.codegen.code_template import CodeTemplate
25-
from tools.codegen.context import with_native_function
26-
from tools.codegen.model import (
24+
from torchgen.code_template import CodeTemplate
25+
from torchgen.context import with_native_function
26+
from torchgen.model import (
2727
Type,
2828
NativeFunction,
2929
SelfArgument,
@@ -32,7 +32,7 @@
3232
is_foreach_op,
3333
)
3434
from typing import List, Optional, Sequence, Tuple, Dict
35-
from tools.codegen.utils import FileManager
35+
from torchgen.utils import FileManager
3636
from .context import with_native_function_with_differentiability_info
3737
from .gen_trace_type import (
3838
MANUAL_AUTOGRAD,

tools/autograd/gen_python_functions.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737

3838
from .gen_trace_type import should_trace
3939

40-
from tools.codegen.code_template import CodeTemplate
41-
from tools.codegen.api import cpp
42-
from tools.codegen.api.types import CppSignatureGroup
43-
from tools.codegen.api.python import (
40+
from torchgen.code_template import CodeTemplate
41+
from torchgen.api import cpp
42+
from torchgen.api.types import CppSignatureGroup
43+
from torchgen.api.python import (
4444
PythonArgument,
4545
PythonSignature,
4646
PythonSignatureDeprecated,
@@ -57,16 +57,16 @@
5757
namedtuple_fieldnames,
5858
signature,
5959
)
60-
from tools.codegen.gen import cpp_string, parse_native_yaml
61-
from tools.codegen.context import with_native_function
62-
from tools.codegen.model import (
60+
from torchgen.gen import cpp_string, parse_native_yaml
61+
from torchgen.context import with_native_function
62+
from torchgen.model import (
6363
Argument,
6464
BaseOperatorName,
6565
NativeFunction,
6666
Type,
6767
Variant,
6868
)
69-
from tools.codegen.utils import split_name_params, YamlLoader, FileManager
69+
from torchgen.utils import split_name_params, YamlLoader, FileManager
7070

7171
from typing import Dict, Optional, List, Tuple, Set, Sequence, Callable
7272

tools/autograd/gen_trace_type.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import itertools
22
from typing import List, Sequence, Union, Dict
33

4-
from tools.codegen.api.types import DispatcherSignature
5-
from tools.codegen.api import cpp
6-
from tools.codegen.code_template import CodeTemplate
7-
from tools.codegen.context import with_native_function
8-
from tools.codegen.utils import FileManager
9-
from tools.codegen.model import (
4+
from torchgen.api.types import DispatcherSignature
5+
from torchgen.api import cpp
6+
from torchgen.code_template import CodeTemplate
7+
from torchgen.context import with_native_function
8+
from torchgen.utils import FileManager
9+
from torchgen.model import (
1010
Argument,
1111
NativeFunction,
1212
SchemaKind,

tools/autograd/gen_variable_factories.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
import re
66
from typing import Optional, List
77

8-
from tools.codegen.api.types import CppSignatureGroup
9-
from tools.codegen.api import cpp
10-
import tools.codegen.api.python as python
11-
from tools.codegen.gen import parse_native_yaml
12-
from tools.codegen.context import with_native_function
13-
from tools.codegen.utils import mapMaybe, FileManager
14-
from tools.codegen.model import NativeFunction, TensorOptionsArguments, Variant
8+
from torchgen.api.types import CppSignatureGroup
9+
from torchgen.api import cpp
10+
import torchgen.api.python as python
11+
from torchgen.gen import parse_native_yaml
12+
from torchgen.context import with_native_function
13+
from torchgen.utils import mapMaybe, FileManager
14+
from torchgen.model import NativeFunction, TensorOptionsArguments, Variant
1515

1616
OPTIONAL_TYPE_PATTERN = re.compile(r"c10::optional<(.+)>")
1717
TYPE_PATTERN = re.compile(r"(?:const\s+)?([A-Z]\w+)")

tools/autograd/gen_variable_type.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
AUTOGRAD_NOT_IMPLEMENTED_REGISTRATION,
5353
)
5454

55-
from tools.codegen.api.types import (
55+
from torchgen.api.types import (
5656
Binding,
5757
DispatcherSignature,
5858
BaseCType,
@@ -68,19 +68,19 @@
6868
TupleCType,
6969
VectorCType,
7070
)
71-
from tools.codegen.api.autograd import (
71+
from torchgen.api.autograd import (
7272
DifferentiableInput,
7373
NativeFunctionWithDifferentiabilityInfo,
7474
SavedAttribute,
7575
dispatch_strategy,
7676
gen_differentiable_outputs,
7777
is_differentiable,
7878
)
79-
from tools.codegen.api import cpp
80-
from tools.codegen.code_template import CodeTemplate
81-
from tools.codegen.context import native_function_manager, with_native_function
82-
from tools.codegen.utils import mapMaybe, FileManager
83-
from tools.codegen.model import (
79+
from torchgen.api import cpp
80+
from torchgen.code_template import CodeTemplate
81+
from torchgen.context import native_function_manager, with_native_function
82+
from torchgen.utils import mapMaybe, FileManager
83+
from torchgen.model import (
8484
Argument,
8585
NativeFunction,
8686
SchemaKind,

0 commit comments

Comments
 (0)