Skip to content

Commit b62d39e

Browse files
linbinyupytorchmergebot
authored andcommitted
Consolidate all python targets in the tools folder (#80408)
Summary: All buck targets that points to caffe2/tools folder are now moved to tools/BUCK. This also eliminates all python library/binary import in pt_defs.bzl, which caused T124308913. Test Plan: CI Differential Revision: D37468313 Pull Request resolved: pytorch/pytorch#80408 Approved by: https://github.com/seemethere, https://github.com/malfet
1 parent 70e86b4 commit b62d39e

17 files changed

+807
-213
lines changed

.github/workflows/_buck-build-test.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,15 @@ jobs:
6262
command: |
6363
sh scripts/buck_setup.sh
6464
65-
- name: Build C10
65+
- name: Build tools
66+
run: |
67+
buck build tools: --keep-going
68+
69+
- name: Run tools tests
70+
run: |
71+
buck test tools:selective_build_test tools:gen_oplist_test tools:gen_operators_yaml_test
72+
73+
- name: Build c10
6674
run: |
6775
buck build c10:c10
6876

.lintrunner.toml

+9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ exclude_patterns = [
1616
'torch/lib/**',
1717
'venv/**',
1818
'**/*.pyi',
19+
'tools/test/test_selective_build.py',
1920
]
2021
command = [
2122
'python3',
@@ -145,6 +146,10 @@ include_patterns = [
145146
exclude_patterns = [
146147
# (linbinyu) copied from internal repo
147148
'tools/code_analyzer/gen_operators_yaml.py',
149+
'tools/gen_vulkan_spv.py',
150+
'tools/test/gen_operators_yaml_test.py',
151+
'tools/test/gen_oplist_test.py',
152+
'tools/test/test_selective_build.py',
148153
]
149154
command = [
150155
'python3',
@@ -334,6 +339,7 @@ exclude_patterns = [
334339
command = [
335340
'python3',
336341
'tools/linter/adapters/grep_linter.py',
342+
# @lint-ignore TXT2
337343
'--pattern= ',
338344
'--linter-name=TABS',
339345
'--error-name=saw some tabs',
@@ -565,6 +571,9 @@ include_patterns = [
565571
'torch/_decomp/**/*.py',
566572
'test/onnx/**/*.py',
567573
]
574+
exclude_patterns = [
575+
'tools/gen_vulkan_spv.py',
576+
]
568577
command = [
569578
'python3',
570579
'tools/linter/adapters/black_linter.py',

buckbuild.bzl

+7-97
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
load("@bazel_skylib//lib:paths.bzl", "paths")
55
load("//tools/build_defs:fb_native_wrapper.bzl", "fb_native")
6-
load("//tools/build_defs:fb_python_binary.bzl", "fb_python_binary")
7-
load("//tools/build_defs:fb_python_library.bzl", "fb_python_library")
86
load("//tools/build_defs:fb_xplat_cxx_library.bzl", "fb_xplat_cxx_library")
97
load("//tools/build_defs:fb_xplat_genrule.bzl", "fb_xplat_genrule")
108
load("//tools/build_defs:fbsource_utils.bzl", "is_arvr_mode")
@@ -416,7 +414,7 @@ def gen_aten_files(
416414
name = name,
417415
default_outs = ["."],
418416
outs = get_aten_generated_files(backends),
419-
cmd = "$(exe {}:gen_aten_bin) ".format(ROOT) + " ".join([
417+
cmd = "$(exe {}torchgen:gen) ".format(ROOT_PATH) + " ".join([
420418
"--source-path $(location {}:aten_src_path)/aten/src/ATen".format(ROOT),
421419
"--install_dir $OUT",
422420
] + extra_params),
@@ -442,7 +440,7 @@ def gen_aten_unboxing_files(
442440
name = genrule_name,
443441
default_outs = ["."],
444442
outs = get_unboxing_generated_files(),
445-
cmd = "$(exe {}:gen_unboxing_bin) ".format(ROOT) + " ".join([
443+
cmd = "$(exe {}tools:gen_unboxing_bin) ".format(ROOT_PATH) + " ".join([
446444
"--source-path $(location {}:aten_src_path)/aten/src/ATen".format(ROOT),
447445
"--install_dir $OUT",
448446
] + extra_params),
@@ -515,7 +513,7 @@ def pt_operator_query_codegen(
515513
# @lint-ignore BUCKLINT
516514
fb_native.genrule(
517515
name = oplist_dir_name,
518-
cmd = ("$(exe {}:gen_oplist) ".format(ROOT) +
516+
cmd = ("$(exe {}tools:gen_oplist) ".format(ROOT_PATH) +
519517
"--model_file_list_path $(@query_outputs 'attrfilter(labels, pt_operator_library, deps(set({deps})))') " +
520518
("" if enforce_traced_op_list else "--allow_include_all_overloads ") +
521519
"--output_dir $OUT ").format(deps = " ".join(["\"{}\"".format(d) for d in deps])),
@@ -620,7 +618,7 @@ def gen_aten_libtorch_files(name, extra_params = [], compatible_with = [], apple
620618
outs = get_generate_code_bin_outs(),
621619
default_outs = ["."],
622620
bash = "mkdir -p tools && " +
623-
"$(exe {}tools/setup_helpers:generate_code_bin) ".format(ROOT_PATH) + " ".join(
621+
"$(exe {}tools:generate_code_bin) ".format(ROOT_PATH) + " ".join(
624622
# Mobile build only needs libtorch - skip python bindings for now, except
625623
# for ovrsource, which needs Python bindings.
626624
(["--subset libtorch"] if not is_arvr_mode() else []) + [
@@ -630,7 +628,7 @@ def gen_aten_libtorch_files(name, extra_params = [], compatible_with = [], apple
630628
] + extra_params,
631629
),
632630
cmd_exe = "@powershell -Command New-Item -Path tools -ItemType Directory -Force; " +
633-
"$(exe {}tools/setup_helpers:generate_code_bin) ".format(ROOT_PATH) + " ".join(
631+
"$(exe {}tools:generate_code_bin) ".format(ROOT_PATH) + " ".join(
634632
# Mobile build only needs libtorch - skip python bindings for now, except
635633
# for ovrsource, which needs Python bindings.
636634
(["--subset libtorch"] if not is_arvr_mode() else []) + [
@@ -950,7 +948,7 @@ def define_buck_targets(
950948
"torch/csrc/api/include/torch/version.h.in",
951949
"version.txt",
952950
],
953-
cmd = "$(exe {}tools/setup_helpers:gen-version-header) ".format(ROOT_PATH) + " ".join([
951+
cmd = "$(exe {}tools:gen-version-header) ".format(ROOT_PATH) + " ".join([
954952
"--template-path",
955953
"torch/csrc/api/include/torch/version.h.in",
956954
"--version-path",
@@ -995,28 +993,13 @@ def define_buck_targets(
995993
],
996994
)
997995

998-
fb_python_library(
999-
name = "substitutelib",
1000-
srcs = ["tools/substitute.py"],
1001-
base_module = "",
1002-
)
1003-
1004-
fb_python_binary(
1005-
name = "substitute",
1006-
main_module = "tools.substitute",
1007-
visibility = ["PUBLIC"],
1008-
deps = [
1009-
":substitutelib",
1010-
],
1011-
)
1012-
1013996
# @lint-ignore BUCKLINT
1014997
fb_native.genrule(
1015998
name = "generate_aten_config",
1016999
srcs = [
10171000
"aten/src/ATen/Config.h.in",
10181001
],
1019-
cmd = "$(exe :substitute) " + " ".join([
1002+
cmd = "$(exe {}tools:substitute) ".format(ROOT_PATH) + " ".join([
10201003
"--install_dir",
10211004
"$OUT",
10221005
"--input-file",
@@ -1072,79 +1055,6 @@ def define_buck_targets(
10721055
default_outs = ["."],
10731056
)
10741057

1075-
fb_python_binary(
1076-
name = "gen_aten_bin",
1077-
main_module = "torchgen.gen",
1078-
visibility = [
1079-
"PUBLIC",
1080-
],
1081-
deps = [
1082-
ROOT_PATH + "torchgen:torchgen",
1083-
],
1084-
)
1085-
1086-
fb_python_binary(
1087-
name = "gen_unboxing_bin",
1088-
main_module = "tools.jit.gen_unboxing",
1089-
visibility = [
1090-
"PUBLIC",
1091-
],
1092-
deps = [
1093-
ROOT_PATH + "tools/jit:jit",
1094-
],
1095-
)
1096-
1097-
fb_python_library(
1098-
name = "gen_oplist_lib",
1099-
srcs = subdir_glob([
1100-
("tools/code_analyzer", "gen_oplist.py"),
1101-
("tools/code_analyzer", "gen_op_registration_allowlist.py"),
1102-
]),
1103-
base_module = "",
1104-
tests = [
1105-
":gen_oplist_test",
1106-
],
1107-
deps = [
1108-
third_party("pyyaml"),
1109-
ROOT_PATH + "tools/lite_interpreter:gen_selected_mobile_ops_header",
1110-
ROOT_PATH + "torchgen:torchgen",
1111-
],
1112-
)
1113-
1114-
fb_python_library(
1115-
name = "gen_operators_yaml_lib",
1116-
srcs = subdir_glob([
1117-
("tools/code_analyzer", "gen_operators_yaml.py"),
1118-
("tools/code_analyzer", "gen_op_registration_allowlist.py"),
1119-
]),
1120-
base_module = "",
1121-
tests = [
1122-
":gen_operators_yaml_test",
1123-
],
1124-
deps = [
1125-
third_party("pyyaml"),
1126-
ROOT_PATH + "torchgen:torchgen",
1127-
],
1128-
)
1129-
1130-
fb_python_binary(
1131-
name = "gen_oplist",
1132-
main_module = "gen_oplist",
1133-
visibility = ["PUBLIC"],
1134-
deps = [
1135-
":gen_oplist_lib",
1136-
],
1137-
)
1138-
1139-
fb_python_binary(
1140-
name = "gen_operators_yaml",
1141-
main_module = "gen_operators_yaml",
1142-
visibility = ["PUBLIC"],
1143-
deps = [
1144-
":gen_operators_yaml_lib",
1145-
],
1146-
)
1147-
11481058
gen_aten_files(
11491059
name = "gen_aten",
11501060
extra_flags = get_aten_codegen_extra_params(USED_PT_BACKENDS),

cmake/VulkanCodegen.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ if(NOT USE_VULKAN_SHADERC_RUNTIME)
6262
execute_process(
6363
COMMAND
6464
"${PYTHON_EXECUTABLE}"
65-
${CMAKE_CURRENT_LIST_DIR}/../aten/src/ATen/gen_vulkan_spv.py
65+
${CMAKE_CURRENT_LIST_DIR}/../tools/gen_vulkan_spv.py
6666
--glsl-path ${CMAKE_CURRENT_LIST_DIR}/../aten/src/ATen/native/vulkan/glsl
6767
--output-path ${VULKAN_GEN_OUTPUT_PATH}
6868
--glslc-path=${GLSLC_PATH}

pt_ops.bzl

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def pt_operator_library(
3939
name = name,
4040
out = "model_operators.yaml",
4141
cmd = (
42-
"$(exe {root}:gen_operators_yaml) " +
42+
"$(exe {exe}) " +
4343
"{optionally_root_ops} " +
4444
"{optionally_training_root_ops} " +
4545
"--rule_name {rule_name} " +
@@ -52,7 +52,7 @@ def pt_operator_library(
5252
"{optionally_model_traced_backends} " +
5353
"{optionally_include_all_operators}"
5454
).format(
55-
root = "//" if IS_OSS else "//xplat/caffe2",
55+
exe = "//tools:gen_operators_yaml" if IS_OSS else "//xplat/caffe2/tools:gen_operators_yaml",
5656
rule_name = name,
5757
model_name = model_name,
5858
dep_graph_yaml = "none" if IS_OSS else "$(location //xplat/caffe2:pytorch_op_deps)/fb/pytorch_op_deps.yaml ",

0 commit comments

Comments
 (0)