Skip to content

Separate CoreML util and inmemoryfs targets to be reusable #9481

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

Merged
merged 5 commits into from
Mar 24, 2025

Conversation

jathu
Copy link
Contributor

@jathu jathu commented Mar 21, 2025

Summary

In this diff, we separate the targets for coreml/runtime/util and coreml/runtime/inmemoryfs.

Why?

As part of #9019, we want to support CoreML export out-of-the-box. Unfortunately, part of the workflow now includes installing an executorch+coreml binding as a pip wheel:

pip install "$COREML_DIR_PATH/runtime/inmemoryfs"

This then gets used throughout the library. i.e.

So we want to now bake this pybinding into the main wheel. Ultimately this executorchcoreml module, gets built using inmemoryfs:

ext_modules = [
Pybind11Extension(
"executorchcoreml",
[
"../util/json_util.cpp",
"inmemory_filesystem.cpp",
"inmemory_filesystem_py.cpp",
"inmemory_filesystem_utils.cpp",
"memory_buffer.cpp",
"memory_stream.cpp",
"reversed_memory_stream.cpp",
],
define_macros=[("VERSION_INFO", __version__)],
cxx_std=cxx_std,
extra_compile_args=["-mmacosx-version-min=10.15", "-g"],
include_dirs=[
"../../third-party/nlohmann_json/single_include",
".",
"../util",
],
),
]

So, to enable creating a pybinding target, we must first decouple the util and inmemoryfs libraries so they can be used in coremldelegate and the future pybinding.

Test plan

This should really be a no-op w.r.t. builds. So, CI +

$ ./install_executorch.sh --pybind coreml

cc @larryliu0820 @lucylq

Copy link

pytorch-bot bot commented Mar 21, 2025

🔗 Helpful Links

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

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

⏳ No Failures, 6 Pending

As of commit 6c82a26 with merge base 06ec67c (image):
💚 Looks good so far! There are no failures yet. 💚

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

@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 Mar 21, 2025
@jathu jathu added module: build/install Issues related to the cmake and buck2 builds, and to installing ExecuTorch ciflow/trunk topic: not user facing labels Mar 21, 2025
@jathu jathu marked this pull request as ready for review March 21, 2025 00:49
@jathu jathu removed the request for review from cccclai March 21, 2025 01:04
Copy link
Contributor

@mergennachin mergennachin left a comment

Choose a reason for hiding this comment

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

See inline comments

@jathu jathu force-pushed the jathu/split-coreml branch 2 times, most recently from 1f3966d to 05b129a Compare March 21, 2025 14:52
@jathu jathu force-pushed the jathu/split-coreml branch 4 times, most recently from d9f8ff5 to 639128b Compare March 21, 2025 19:11
@jathu jathu requested a review from mergennachin March 21, 2025 19:11
@jathu jathu force-pushed the jathu/split-coreml branch from 639128b to 7f6cdc3 Compare March 21, 2025 19:13
@jathu jathu marked this pull request as draft March 21, 2025 19:32
@jathu jathu force-pushed the jathu/split-coreml branch from 7f6cdc3 to a03a108 Compare March 21, 2025 19:41
@jathu jathu force-pushed the jathu/split-coreml branch 4 times, most recently from 3172a23 to ecbceb5 Compare March 23, 2025 22:28
@jathu jathu marked this pull request as ready for review March 23, 2025 22:53
@jathu jathu force-pushed the jathu/split-coreml branch 2 times, most recently from 067d471 to fdc8ffc Compare March 24, 2025 16:48
Copy link
Contributor

@swolchok swolchok left a comment

Choose a reason for hiding this comment

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

seems fine, leaving accept for @shoumikhin

@jathu jathu force-pushed the jathu/split-coreml branch from fdc8ffc to b0a8f96 Compare March 24, 2025 18:14
@jathu jathu requested a review from metascroy as a code owner March 24, 2025 18:14
@jathu jathu force-pushed the jathu/split-coreml branch 2 times, most recently from 43afb06 to edb05ce Compare March 24, 2025 18:43
@shoumikhin
Copy link
Contributor

LGTM and I'd also asked @cymbalrush to glance

@jathu jathu force-pushed the jathu/split-coreml branch from edb05ce to f96e713 Compare March 24, 2025 20:48
@jathu jathu requested a review from GregoryComer as a code owner March 24, 2025 20:48
@jathu jathu force-pushed the jathu/split-coreml branch from f96e713 to 6c82a26 Compare March 24, 2025 22:45
@jathu jathu merged commit cb583f3 into main Mar 24, 2025
172 checks passed
@jathu jathu deleted the jathu/split-coreml branch March 24, 2025 23:56
jathu added a commit that referenced this pull request Mar 25, 2025
### Summary
Context: #9481

We now create the pybinding target for inmemoryfs. Note that the build
recipe is from the wheel builder:


https://github.com/pytorch/executorch/blob/5fdfa511966208c7e237a9e920a7c63f513b4fb7/backends/apple/coreml/runtime/inmemoryfs/setup.py#L17-L38

### Test plan
```
$ cmake -B cmake-out -S . -DEXECUTORCH_BUILD_PYBIND=ON -DEXECUTORCH_BUILD_COREML=ON
$ cmake --build cmake-out -j$(sysctl -n hw.ncpu) --target executorchcoreml

$ ./install_executorch.sh --pybind coreml
```

cc @larryliu0820 @lucylq
jathu added a commit that referenced this pull request Mar 26, 2025
### Summary
Context: #9481

* Include the `executorchcoreml` pybinding in the builds
* Remove separate installation option
* Turn on CoreML by default for macOS builds
* Add a dependency on coremltools for macOS

### Test plan

CI

```
$ rm -rf cmake-out pip-out dist && ./install_executorch.sh
$ ./examples/models/llama/install_requirements.sh
$ .ci/scripts/test_llama.sh -model stories110M -build_tool cmake -dtype fp32 -mode coreml
$ .ci/scripts/test_llama.sh -model stories110M -build_tool cmake -dtype fp32 -mode xnnpack+custom+quantize_kv
```

cc @larryliu0820 @lucylq
kirklandsign pushed a commit that referenced this pull request Apr 11, 2025
### Summary
Context: #9481

* Include the `executorchcoreml` pybinding in the builds
* Remove separate installation option
* Turn on CoreML by default for macOS builds
* Add a dependency on coremltools for macOS

### Test plan

CI

```
$ rm -rf cmake-out pip-out dist && ./install_executorch.sh
$ ./examples/models/llama/install_requirements.sh
$ .ci/scripts/test_llama.sh -model stories110M -build_tool cmake -dtype fp32 -mode coreml
$ .ci/scripts/test_llama.sh -model stories110M -build_tool cmake -dtype fp32 -mode xnnpack+custom+quantize_kv
```

cc @larryliu0820 @lucylq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/trunk CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. module: build/install Issues related to the cmake and buck2 builds, and to installing ExecuTorch topic: not user facing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants