To optimize binary size of ExecuTorch runtime, selective build can be used. This folder contains examples to select only the operators needed for ExecuTorch build. We provide APIs for both CMake build and buck2 build. This example will demonstrate both. You can find more information on how to use buck2 macros in wiki.
Prerequisite: finish the setting up wiki.
Run:
cd executorch bash examples/selective_build/test_selective_build.sh [cmake|buck2]
Check out targets.bzl
for demo of 3 selective build APIs:
--config executorch.select_ops=all
: Select all ops from the dependency kernel libraries, register all of them into ExecuTorch runtime.--config executorch.select_ops=list
: Only select ops from ops
kwarg in et_operator_library
macro.--config executorch.select_ops=yaml
: Only select from a yaml file from ops_schema_yaml_target
kwarg in et_operator_library
macro.Other configs:
--config executorch.max_kernel_num=N
: Only allocate memory for the required number of operators. Take this result from selected_operators.yaml
.--config executorch.dtype_selective_build_lib=<executorch_generated_lib_name>
: Use dtype selective build. For each op, we register the dtypes that are used. Eg. if the model only uses the float implementation of add, then only the float add will be registered. Pass in the executorch_generated_lib name (see buck2 model example in targets.bzl).Check out CMakeLists.txt
for demo of 3 selective build APIs:
SELECT_ALL_OPS
SELECT_OPS_LIST
SELECT_OPS_YAML
Other configs:
MAX_KERNEL_NUM=N
We have one more API incoming: only select from an exported model file (.pte).