From eddfcb09a27df9b4722a2ed5845df0459f8ecad9 Mon Sep 17 00:00:00 2001 From: Jon Janzen Date: Mon, 27 Jul 2026 09:27:20 -0700 Subject: [PATCH] migrate dirs whose runtime.python_binary kwargs are fbcode-only (#21388) Summary: Pull Request resolved: https://github.com/pytorch/executorch/pull/21388 Chunk 9 of fbcode/executorch TARGETS->BUCK migration. 4 directories that were attempted in earlier chunks but reverted because their `runtime.python_binary` calls use kwargs the xplat macro rejects (`main_src`, `srcs = ["data_utils.py"]` triggering the "default_only is not allowed to be specified" error, etc.). Migrated using the chunk-6 gate-everything-on-is_fbcode pattern: each dir now has a thin BUCK calling `define_common_targets(is_fbcode = is_fbcode())` and a targets.bzl whose `define_common_targets` early-returns when not in fbcode. This preserves the pre-migration behavior where these dirs were fbcode-only by virtue of being TARGETS-only. Directories migrated: - devtools/inspector - examples/devtools/scripts - extension/pybindings/fb/test - extension/training/examples/CIFAR CIFAR's existing targets.bzl was edited to add `is_fbcode = False` param and an early-return guard at the top of `define_common_targets`. runtime/test was attempted but reverted: the dir's PACKAGE file calls `ci.buckconfig("executorch.event_tracer_enabled", "true")` and that buckconfig key is not on the xplat allowlist, so xplat fails to evaluate the package once it has a BUCK file. Needs a separate fix to the PACKAGE file (probably gating the ci.buckconfig call on is_fbcode) before this dir can be migrated. Reviewed By: mzlee Differential Revision: D109082048 --- .../CIFAR/TARGETS => devtools/inspector/BUCK | 5 +- devtools/inspector/TARGETS | 78 ------------------ devtools/inspector/targets.bzl | 80 +++++++++++++++++++ examples/devtools/scripts/BUCK | 9 +++ examples/devtools/scripts/targets.bzl | 31 +++++++ extension/training/examples/CIFAR/BUCK | 9 +++ extension/training/examples/CIFAR/targets.bzl | 9 ++- 7 files changed, 138 insertions(+), 83 deletions(-) rename extension/training/examples/CIFAR/TARGETS => devtools/inspector/BUCK (53%) delete mode 100644 devtools/inspector/TARGETS create mode 100644 devtools/inspector/targets.bzl create mode 100644 examples/devtools/scripts/BUCK create mode 100644 examples/devtools/scripts/targets.bzl create mode 100644 extension/training/examples/CIFAR/BUCK diff --git a/extension/training/examples/CIFAR/TARGETS b/devtools/inspector/BUCK similarity index 53% rename from extension/training/examples/CIFAR/TARGETS rename to devtools/inspector/BUCK index 2341af9282f..f559a6f1cfe 100644 --- a/extension/training/examples/CIFAR/TARGETS +++ b/devtools/inspector/BUCK @@ -1,8 +1,9 @@ # Any targets that should be shared between fbcode and xplat must be defined in -# targets.bzl. This file can contain fbcode-only targets. +# targets.bzl. +load("@fbsource//tools/build_defs:fbsource_utils.bzl", "is_fbcode") load(":targets.bzl", "define_common_targets") oncall("executorch") -define_common_targets() +define_common_targets(is_fbcode = is_fbcode()) diff --git a/devtools/inspector/TARGETS b/devtools/inspector/TARGETS deleted file mode 100644 index bc3ab199be9..00000000000 --- a/devtools/inspector/TARGETS +++ /dev/null @@ -1,78 +0,0 @@ -load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") - -oncall("executorch") - -runtime.python_library( - name = "inspector", - srcs = [ - "_inspector.py", - ], - deps = [ - "fbsource//third-party/pypi/ipython:ipython", - "fbsource//third-party/pypi/numpy:numpy", - "fbsource//third-party/pypi/pandas:pandas", - "fbsource//third-party/pypi/tabulate:tabulate", - ":inspector_utils", - ":vgf_neural_statistics", - "//executorch/devtools/debug_format:et_schema", - "//executorch/devtools/etdump:schema_flatcc", - "//executorch/devtools/etrecord:etrecord", - "//executorch/exir:lib", - "//executorch/devtools/inspector:intermediate_output_capturer", - "//executorch/devtools/inspector/numerical_comparator:lib", - ], -) - -runtime.python_library( - name = "vgf_neural_statistics", - srcs = [ - "vgf_neural_statistics.py", - ], -) - -runtime.python_binary( - name = "inspector_cli", - main_function = ".inspector_cli.main", - main_src = "inspector_cli.py", - deps = [ - "//executorch/devtools:lib", - "//executorch/devtools/inspector:lib", - ], -) - -runtime.python_library( - name = "inspector_utils", - srcs = [ - "_inspector_utils.py", - ], - deps = [ - "fbsource//third-party/pypi/matplotlib:matplotlib", - "fbsource//third-party/pypi/numpy:numpy", - "//caffe2:torch", - "//executorch/devtools/debug_format:base_schema", - "//executorch/devtools/debug_format:et_schema", - "//executorch/devtools/etdump:schema_flatcc", - "//executorch/devtools/etdump:serialize", - "//executorch/devtools/etrecord:etrecord", - ], -) - -runtime.python_library( - name = "intermediate_output_capturer", - srcs = [ - "_intermediate_output_capturer.py", - ], - deps = [ - "//executorch/devtools/inspector:inspector_utils", - ], -) - -runtime.python_library( - name = "lib", - srcs = ["__init__.py"], - deps = [ - ":inspector", - ":inspector_utils", - ":vgf_neural_statistics", - ], -) diff --git a/devtools/inspector/targets.bzl b/devtools/inspector/targets.bzl new file mode 100644 index 00000000000..d049d75d2bf --- /dev/null +++ b/devtools/inspector/targets.bzl @@ -0,0 +1,80 @@ +load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") + +def define_common_targets(is_fbcode = False): + if not is_fbcode: + return + + runtime.python_library( + name = "inspector", + srcs = [ + "_inspector.py", + ], + deps = [ + "fbsource//third-party/pypi/ipython:ipython", + "fbsource//third-party/pypi/numpy:numpy", + "fbsource//third-party/pypi/pandas:pandas", + "fbsource//third-party/pypi/tabulate:tabulate", + ":inspector_utils", + ":vgf_neural_statistics", + "//executorch/devtools/debug_format:et_schema", + "//executorch/devtools/etdump:schema_flatcc", + "//executorch/devtools/etrecord:etrecord", + "//executorch/exir:lib", + "//executorch/devtools/inspector:intermediate_output_capturer", + "//executorch/devtools/inspector/numerical_comparator:lib", + ], + ) + + runtime.python_library( + name = "vgf_neural_statistics", + srcs = [ + "vgf_neural_statistics.py", + ], + ) + + runtime.python_binary( + name = "inspector_cli", + main_function = ".inspector_cli.main", + main_src = "inspector_cli.py", + deps = [ + "//executorch/devtools:lib", + "//executorch/devtools/inspector:lib", + ], + ) + + runtime.python_library( + name = "inspector_utils", + srcs = [ + "_inspector_utils.py", + ], + deps = [ + "fbsource//third-party/pypi/matplotlib:matplotlib", + "fbsource//third-party/pypi/numpy:numpy", + "//caffe2:torch", + "//executorch/devtools/debug_format:base_schema", + "//executorch/devtools/debug_format:et_schema", + "//executorch/devtools/etdump:schema_flatcc", + "//executorch/devtools/etdump:serialize", + "//executorch/devtools/etrecord:etrecord", + ], + ) + + runtime.python_library( + name = "intermediate_output_capturer", + srcs = [ + "_intermediate_output_capturer.py", + ], + deps = [ + "//executorch/devtools/inspector:inspector_utils", + ], + ) + + runtime.python_library( + name = "lib", + srcs = ["__init__.py"], + deps = [ + ":inspector", + ":inspector_utils", + ":vgf_neural_statistics", + ], + ) diff --git a/examples/devtools/scripts/BUCK b/examples/devtools/scripts/BUCK new file mode 100644 index 00000000000..f559a6f1cfe --- /dev/null +++ b/examples/devtools/scripts/BUCK @@ -0,0 +1,9 @@ +# Any targets that should be shared between fbcode and xplat must be defined in +# targets.bzl. + +load("@fbsource//tools/build_defs:fbsource_utils.bzl", "is_fbcode") +load(":targets.bzl", "define_common_targets") + +oncall("executorch") + +define_common_targets(is_fbcode = is_fbcode()) diff --git a/examples/devtools/scripts/targets.bzl b/examples/devtools/scripts/targets.bzl new file mode 100644 index 00000000000..130dc9d40a7 --- /dev/null +++ b/examples/devtools/scripts/targets.bzl @@ -0,0 +1,31 @@ +load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") + +def define_common_targets(is_fbcode = False): + if not is_fbcode: + return + + runtime.python_binary( + name = "export_bundled_program", + main_function = ".export_bundled_program.main", + main_src = "export_bundled_program.py", + deps = [ + "//caffe2:torch", + "//executorch/devtools:lib", + "//executorch/devtools/bundled_program:config", + "//executorch/devtools/bundled_program/serialize:lib", + "//executorch/examples/models:models", + "//executorch/extension/export_util:export_util", + ], + ) + + runtime.python_binary( + name = "gen_sample_etrecord", + srcs = ["gen_sample_etrecord.py"], + main_function = "executorch.examples.devtools.scripts.gen_sample_etrecord.main", + deps = [ + "//executorch/devtools:lib", + "//executorch/devtools/etrecord:etrecord", + "//executorch/examples/models:models", + "//executorch/exir:lib", + ], + ) diff --git a/extension/training/examples/CIFAR/BUCK b/extension/training/examples/CIFAR/BUCK new file mode 100644 index 00000000000..f559a6f1cfe --- /dev/null +++ b/extension/training/examples/CIFAR/BUCK @@ -0,0 +1,9 @@ +# Any targets that should be shared between fbcode and xplat must be defined in +# targets.bzl. + +load("@fbsource//tools/build_defs:fbsource_utils.bzl", "is_fbcode") +load(":targets.bzl", "define_common_targets") + +oncall("executorch") + +define_common_targets(is_fbcode = is_fbcode()) diff --git a/extension/training/examples/CIFAR/targets.bzl b/extension/training/examples/CIFAR/targets.bzl index 786160d65b3..64ff7915f99 100644 --- a/extension/training/examples/CIFAR/targets.bzl +++ b/extension/training/examples/CIFAR/targets.bzl @@ -1,11 +1,14 @@ load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") -def define_common_targets(): +def define_common_targets(is_fbcode = False): """Defines targets that should be shared between fbcode and xplat. - The directory containing this targets.bzl file should also contain both - TARGETS and BUCK files that call this function. + Originally an fbcode-only TARGETS dir; the runtime.python_binary calls + here use srcs=[...] which the xplat python_binary macro rejects, so the + body is gated on is_fbcode to preserve pre-migration behavior. """ + if not is_fbcode: + return runtime.python_library( name = "model",