-
Notifications
You must be signed in to change notification settings - Fork 685
Updating documentation for cmake dtype selective build #12112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2e8c622
060fc14
3bb664f
9ec7dc2
e9745f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,17 +36,20 @@ The basic flow looks like this: | |
|
||
## APIs | ||
|
||
We expose a CMake macro `[gen_selected_ops](https://github.com/pytorch/executorch/blob/main/tools/cmake/Codegen.cmake#L12)`, to allow users specifying op info: | ||
We expose a CMake macro [gen_selected_ops](https://github.com/pytorch/executorch/blob/main/tools/cmake/Codegen.cmake#L12), to allow users specifying op info: | ||
|
||
``` | ||
gen_selected_ops( | ||
LIB_NAME # the name of the selective build operator library to be generated | ||
OPS_SCHEMA_YAML # path to a yaml file containing operators to be selected | ||
ROOT_OPS # comma separated operator names to be selected | ||
INCLUDE_ALL_OPS # boolean flag to include all operators | ||
LIB_NAME # the name of the selective build operator library to be generated | ||
OPS_SCHEMA_YAML # path to a yaml file containing operators to be selected | ||
ROOT_OPS # comma separated operator names to be selected | ||
INCLUDE_ALL_OPS # boolean flag to include all operators | ||
OPS_FROM_MODEL # path to a pte file of model to select operators from | ||
DTYPE_SELECTIVE_BUILD # boolean flag to enable dtye selection | ||
) | ||
``` | ||
|
||
The macro makes a call to gen_oplist.py, which requires a [distinct selection](https://github.com/BujSet/executorch/blob/main/codegen/tools/gen_oplist.py#L222-L228) of API choice. `OPS_SCHEMA_YAML`, `ROOT_OPS`, `INCLUDE_ALL_OPS`, and `OPS_FROM_MODEL` are mutually exclusive options, and should not be used in conjunction. | ||
|
||
### Select all ops | ||
|
||
|
@@ -62,31 +65,29 @@ Context: each kernel library is designed to have a yaml file associated with it. | |
|
||
This API lets users pass in a list of operator names. Note that this API can be combined with the API above and we will create a allowlist from the union of both API inputs. | ||
|
||
### Select ops from model | ||
|
||
## Example Walkthrough | ||
This API lets users pass in a pte file of an exported model. When used, the pte file will be parsed to generate a yaml file that enumerates the operators and dtypes used in the model. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the fact that a yaml file is generated relevant to the end user? The above documentation makes it seem like the model yaml is not a user facing construct, only the pte, or the root ops list are exposed methods of passing selective information. Also in general I would say "root" ops is misleading since ET doesnt have transitive ops. We should just call it the op list. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When using the model API, the generated YAML can be as an input to the selective build process, like when using the yaml API directly. The difference being that a user doesn't have to manually craft a yaml, but can pass in a pte. I agree, root ops is not a great name, but it seems to be used in other places as well, e.g. https://github.com/BujSet/executorch/blob/main/codegen/tools/gen_oplist.py#L234-L243. For consistency, I think we should keep it as root ops, and a separate PR should refactor this to something more meaningful, what do you think? |
||
|
||
In CMakeLists.txt we have the following logic: | ||
```cmake | ||
set(_kernel_lib) | ||
if(SELECT_ALL_OPS) | ||
gen_selected_ops("" "" "${SELECT_ALL_OPS}") | ||
elseif(SELECT_OPS_LIST) | ||
gen_selected_ops("" "${SELECT_OPS_LIST}" "") | ||
elseif(SELECT_OPS_YAML) | ||
set(_custom_ops_yaml ${EXECUTORCH_ROOT}/examples/portable/custom_ops/custom_ops.yaml) | ||
gen_selected_ops("${_custom_ops_yaml}" "" "") | ||
endif() | ||
``` | ||
Then when calling CMake, we can do: | ||
### Dtype Selective Build | ||
|
||
``` | ||
cmake -D… -DSELECT_OPS_LIST="aten::add.out,aten::mm.out” | ||
``` | ||
Beyond pruning the binary to remove unused operators, the binary size can further reduced by removing unused dtypes. For example, if your model only uses floats for the `add` operator, then including variants of the `add` operators for `doubles` and `ints` is unnecessary. The flag `DTYPE_SELECTIVE_BUILD` can be set to `ON` to support this additional optimization. Currently, dtype selective build is only supported with the model API described above. Once enabled, a header file that specifies only the operators and dtypes used by the model is created and linked against a rebuild of the `portable_kernels` lib. This feature is only supported for the portable kernels library; it's not supported for optimized, quantized or custom kernel libraries. | ||
|
||
Or | ||
## Example Walkthrough | ||
|
||
``` | ||
cmake -D… -DSELECT_OPS_YAML=ON | ||
``` | ||
In [CMakeLists.txt](https://github.com/BujSet/executorch/blob/main/examples/selective_build/CMakeLists.txt#L48-L72), we have the following cmake config options: | ||
|
||
1. `EXECUTORCH_SELECT_OPS_YAML` | ||
2. `EXECUTORCH_SELECT_OPS_LIST` | ||
3. `EXECUTORCH_SELECT_ALL_OPS` | ||
4. `EXECUTORCH_SELECT_OPS_FROM_MODEL` | ||
5. `EXECUTORCH_DTYPE_SELECTIVE_BUILD` | ||
|
||
These options allow a user to tailor the cmake build process to utilize the different APIs, and results in different invocations on the `gen_selected_ops` [function](https://github.com/BujSet/executorch/blob/main/examples/selective_build/CMakeLists.txt#L110-L123). The following table describes some examples of how the invocation changes when these configs are set: | ||
|
||
To select from either an operator name list or a schema yaml from kernel library. | ||
| Example cmake Call | Resultant `gen_selected_ops` Invocation | | ||
| :----: | :---:| | ||
|<code><br> cmake -D… -DSELECT_OPS_LIST="aten::add.out,aten::mm.out" <br></code> | <code><br> gen_selected_ops("" "${SELECT_OPS_LIST}" "" "" "") <br></code> | | ||
|<code><br> cmake -D… -DSELECT_OPS_YAML=ON <br></code> | <code><br> set(_custom_ops_yaml ${EXECUTORCH_ROOT}/examples/portable/custom_ops/custom_ops.yaml) <br> gen_selected_ops("${_custom_ops_yaml}" "" "") <br></code> | | ||
|<code><br> cmake -D… -DEXECUTORCH_SELECT_OPS_FROM_MODEL="model.pte.out" <br></code> | <code><br> gen_selected_ops("" "" "" "${_model_path}" "") <br></code> | | ||
|<code><br> cmake -D… -DEXECUTORCH_SELECT_OPS_FROM_MODEL="model.pte.out" -DEXECUTORCH_DTYPE_SELECTIVE_BUILD=ON<br></code> | <code><br> gen_selected_ops("" "" "" "${_model_path}" "ON") <br></code> | |
Uh oh!
There was an error while loading. Please reload this page.