Skip to content

Support for Dtye Selective Build from Dictionary API in OSS (cmake) #12873

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

BujSet
Copy link
Contributor

@BujSet BujSet commented Jul 25, 2025

Summary

When attempting to build minimal binary size with only a select number of operators and dtypes, it's advantageous to simply specify only the needed selections at compile time. This PR allows one to specify a JSON formatted string to select operators and dtypes to be included in the final binary. An example is also provided.

Test plan

This feature was tested with the added example in examples/selective_build/test_selective_build.sh which now has a function named test_cmake_select_ops_in_dict(). This function exemplifies the usage of the newly added dictionary API.

Copy link

pytorch-bot bot commented Jul 25, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/12873

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure, 1 Unrelated Failure

As of commit 6828f13 with merge base 45846c8 (image):

NEW FAILURE - The following job has failed:

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@BujSet BujSet self-assigned this Jul 25, 2025
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 25, 2025
@BujSet
Copy link
Contributor Author

BujSet commented Jul 25, 2025

@pytorchbot label "release notes: none"

@pytorch-bot pytorch-bot bot added the release notes: none Do not include this in the release notes label Jul 25, 2025
rm -rf ${build_dir}
retry cmake -DCMAKE_BUILD_TYPE=Release \
-DMAX_KERNEL_NUM=22 \
-DEXECUTORCH_SELECT_OPS_LIST='{"aten::add": [Scalar.Float.name]}'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be OPS_DICT? or are we re-using OPS_LIST?

@@ -66,6 +66,11 @@ option(EXECUTORCH_SELECT_ALL_OPS
"Whether to register all ops defined in portable kernel library." OFF
)

# Option to enable parsing ops and dtypes from json formatted dictionary
option(EXECUTORCH_SELECT_OPS_FROM_DICT
"Enable op selection from json formattting string during build." OFF
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a link to the supported dtype strings, e.g. https://github.com/pytorch/executorch/blame/0211a0346455f5b1ce445c2bdf6fce89a9aa04c9/shim_et/xplat/executorch/codegen/codegen.bzl#L51

^ actually I think this list is too broad and not all supported in ET 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are actually only 8 dtypes that are supported and tested. I remember seeing a list of them somewhere in the code base, will note them here.

@BujSet BujSet force-pushed the ops_dict_dtype_selection_cmake branch from 6972848 to 3e541eb Compare July 26, 2025 03:46
@BujSet BujSet force-pushed the ops_dict_dtype_selection_cmake branch from 849311e to 6828f13 Compare July 28, 2025 05:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. release notes: none Do not include this in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants