Skip to content

Commit 0029657

Browse files
remove buck2 from custom operator registration (#4233) (#4244)
Summary: Pull Request resolved: #4233 For alpha+, we need to remove all buck2 commands and buck2 dependencies from static doc and github readmes. This diff gets rid of the buck2 from custom operator registration examples. Reviewed By: larryliu0820 Differential Revision: D59661023 fbshipit-source-id: 25b4fec3f5ff71e615bc52b4b465d31a8e4c6c87 (cherry picked from commit 17ae009) Co-authored-by: Songhao Jia <[email protected]>
1 parent 63b68c9 commit 0029657

File tree

2 files changed

+7
-70
lines changed

2 files changed

+7
-70
lines changed

examples/portable/custom_ops/README.md

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Custom Operator Registration Examples (WIP)
1+
# Custom Operator Registration Examples
22
This folder contains examples to register custom operators into PyTorch as well as register its kernels into ExecuTorch runtime.
33

44
## How to run
@@ -9,7 +9,7 @@ Run:
99

1010
```bash
1111
cd executorch
12-
bash examples/portable/custom_ops/test_custom_ops.sh [cmake|buck2]
12+
bash examples/portable/custom_ops/test_custom_ops.sh
1313
```
1414

1515
## AOT registration
@@ -37,24 +37,11 @@ After the model is exported by EXIR, we need C++ implementations of these custom
3737
```
3838
For how to write these YAML entries, please refer to [`kernels/portable/README.md`](https://github.com/pytorch/executorch/blob/main/kernels/portable/README.md).
3939

40-
Currently we provide 2 build systems that links `my_ops::mul3.out` kernel (written in `custom_ops_1.cpp`) to Executor runtime: buck2 and CMake. Both instructions are listed in `examples/portable/custom_ops/test_custom_ops.sh`(test_buck2_custom_op_1 and test_cmake_custom_op_1).
40+
Currently we use Cmake as the build system to link the `my_ops::mul3.out` kernel (written in `custom_ops_1.cpp`) to the ExecuTorch runtime. See instructions in: `examples/portable/custom_ops/test_custom_ops.sh` (test_cmake_custom_op_1).
4141

4242
## Selective build
4343

44-
Note that we have defined a custom op for both `my_ops::mul3.out` and `my_ops::mul4.out` in `custom_ops.yaml`. Below is a demonstration of how to only register the operator from the model we are running into the runtime.
45-
46-
In CMake, this is done by passing in a list of operators to `gen_oplist` custom rule: `--root_ops="my_ops::mul4.out"`.
47-
48-
In Buck2, this is done by a rule called `et_operator_library`:
49-
```python
50-
et_operator_library(
51-
name = "select_custom_ops_2",
52-
ops = [
53-
"my_ops::mul4.out",
54-
],
55-
...
56-
)
57-
```
44+
Note that we have defined a custom op for both `my_ops::mul3.out` and `my_ops::mul4.out` in `custom_ops.yaml`. To reduce binary size, we can choose to only register the operators used in the model. This is done by passing in a list of operators to the `gen_oplist` custom rule, for example: `--root_ops="my_ops::mul4.out"`.
5845

5946
We then let the custom ops library depend on this target, to only register the ops we want.
6047

examples/portable/custom_ops/test_custom_ops.sh

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,6 @@ set -e
1414
# shellcheck source=/dev/null
1515
source "$(dirname "${BASH_SOURCE[0]}")/../../../.ci/scripts/utils.sh"
1616

17-
test_buck2_custom_op_1() {
18-
local model_name='custom_ops_1'
19-
echo "Exporting ${model_name}.pte"
20-
${PYTHON_EXECUTABLE} -m "examples.portable.custom_ops.${model_name}"
21-
# should save file custom_ops_1.pte
22-
23-
echo 'Running executor_runner'
24-
$BUCK run //examples/portable/executor_runner:executor_runner \
25-
--config=executorch.register_custom_op=1 -- --model_path="./${model_name}.pte"
26-
# should give correct result
27-
28-
echo "Removing ${model_name}.pte"
29-
rm "./${model_name}.pte"
30-
}
31-
3217
test_cmake_custom_op_1() {
3318
local model_name='custom_ops_1'
3419
echo "Exporting ${model_name}.pte"
@@ -51,23 +36,6 @@ test_cmake_custom_op_1() {
5136
${build_dir}/custom_ops_executor_runner --model_path="./${model_name}.pte"
5237
}
5338

54-
test_buck2_custom_op_2() {
55-
local model_name='custom_ops_2'
56-
57-
echo 'Building custom ops shared library'
58-
SO_LIB=$($BUCK build //examples/portable/custom_ops:custom_ops_aot_lib_2 --show-output | grep "buck-out" | cut -d" " -f2)
59-
60-
echo "Exporting ${model_name}.pte"
61-
${PYTHON_EXECUTABLE} -m "examples.portable.custom_ops.${model_name}" --so_library="$SO_LIB"
62-
# should save file custom_ops_2.pte
63-
64-
$BUCK run //examples/portable/executor_runner:executor_runner \
65-
--config=executorch.register_custom_op=2 -- --model_path="./${model_name}.pte"
66-
# should give correct result
67-
echo "Removing ${model_name}.pte"
68-
rm "./${model_name}.pte"
69-
}
70-
7139
get_shared_lib_ext() {
7240
UNAME=$(uname)
7341
if [[ $UNAME == "Darwin" ]];
@@ -115,24 +83,6 @@ then
11583
PYTHON_EXECUTABLE=python3
11684
fi
11785

118-
if [[ -z $BUCK ]];
119-
then
120-
BUCK=buck2
121-
fi
122-
123-
if [[ $1 == "cmake" ]];
124-
then
125-
cmake_install_executorch_lib
126-
test_cmake_custom_op_1
127-
test_cmake_custom_op_2
128-
elif [[ $1 == "buck2" ]];
129-
then
130-
test_buck2_custom_op_1
131-
test_buck2_custom_op_2
132-
else
133-
cmake_install_executorch_lib
134-
test_cmake_custom_op_1
135-
test_cmake_custom_op_2
136-
test_buck2_custom_op_1
137-
test_buck2_custom_op_2
138-
fi
86+
cmake_install_executorch_lib
87+
test_cmake_custom_op_1
88+
test_cmake_custom_op_2

0 commit comments

Comments
 (0)