Skip to content

Migrate iOS app demo #6

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 3 commits into from
Apr 24, 2025
Merged

Migrate iOS app demo #6

merged 3 commits into from
Apr 24, 2025

Conversation

nil-is-all
Copy link
Contributor

Reproduced https://github.com/pytorch/executorch/tree/main/examples/demo-apps/apple_ios/ExecuTorchDemo and added last line in docs to point to this GitHub repo

@nil-is-all nil-is-all self-assigned this Mar 13, 2025
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Mar 13, 2025
@mergennachin
Copy link
Contributor

@nil-is-all
Copy link
Contributor Author

The structure of https://github.com/pytorch-labs/executorch-examples/blob/main/apple/ExecuTorchDemo/README.md (let's call it ExecuTorchDemo README) is different from the original docs which are reflected in the PyTorch page. I followed the structure and comments of the original docs and the PyTorch page, which match.

E.g.: ExecuTorch README directly states to clone the ExecuTorch GitHub repo under Models and Labels section.
Whereas the PyTorch page, the original docs, and now the newly created README has a designated subsection stating "Getting Started Tutorial" under Prerequisites section.

Plus other comments like the first line welcoming the user as in the PyTorch demo docs page.
Finally, I have linked the execuTorch-examples GitHub repo, following this comment in this convo.

@mergennachin
Copy link
Contributor

@nil-is-all any updates here since we last talked?

@nil-is-all
Copy link
Contributor Author

Hi @mergennachin, I made the changes for the export script, and edited the "export model" section, and completed other changes such as adding instructions for swiftPM package and editing the directory paths. Seems PyTorch was deprecated for intel macbooks, so I am looking to test this out before pushing on GitHub.

@mergennachin
Copy link
Contributor

Any updates @nil-is-all ?

We're not making this repo public until your change.

@mergennachin
Copy link
Contributor

Any updates @nil-is-all ?

@nil-is-all
Copy link
Contributor Author

@mergennachin sorry for the delay in response. I faced an issue while installing torch from source, posted it on #support channel in our Discord server too. Seems it is an open issue. I get the new mac tomorrow. While looking at ways to install, if it does not succeed, I will setup the mac and run local test tomorrow.

@mergennachin
Copy link
Contributor

Any updates @nil-is-all ? We need to finalize this ASAP

Please use this directory

https://github.com/pytorch-labs/executorch-examples/tree/main/mv2

@nil-is-all
Copy link
Contributor Author

nil-is-all commented Apr 21, 2025

Hey @mergennachin, been posting my current status on Discord. There is a current issue with the MPS Backend model which fails with a dim_order check. @digantdesai opened a new issue related to this.

I tried pushing the xcodeproj for the other two backend models by commenting out for MPS, but the current code expects all 3 backends, which @shoumikhin stated on discord. I'm awaiting his response on what changes to make to currently test just for the XNNPack and CoreML, as well as other comments I have posted in the #executorch-just-works Discord channel.

TL:DR - ready to locally test on xcode, all pre-requisites met and models exported other than MPS Backend.

@nil-is-all
Copy link
Contributor Author

Also @mergennachin, are we not using MobileNetV3? Your comment here also reiterated using this structure for mv3

@nil-is-all nil-is-all changed the title Migrate iOS app demo as README.md Migrate iOS app demo Apr 22, 2025
@@ -0,0 +1,48 @@
#!/usr/bin/env python
Copy link
Contributor

Choose a reason for hiding this comment

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

move this file to mv3/python/export.py

Comment on lines 95 to 124
```bash
import torch
import torchvision.models as models
from executorch.backends.apple.coreml.partition import CoreMLPartitioner
from executorch.backends.apple.mps.partition import MPSPartitioner
from executorch.exir.backend.backend_details import CompileSpec
from executorch.backends.xnnpack.partition.xnnpack_partitioner import XnnpackPartitioner
from executorch.exir import to_edge_transform_and_lower
import ssl
import certifi


def main() -> None:
model = models.mobilenet_v3_small(weights="DEFAULT").eval()
sample_inputs = (torch.randn(1, 3, 224, 224),)

et_program_coreml = to_edge_transform_and_lower(
torch.export.export(model, sample_inputs),
partitioner=[CoreMLPartitioner()],
).to_executorch()

et_program_mps = to_edge_transform_and_lower(
torch.export.export(model, sample_inputs),
partitioner=[MPSPartitioner([CompileSpec("use_fp16", bytes([True]))])],
).to_executorch()

et_program_xnnpack = to_edge_transform_and_lower(
torch.export.export(model, sample_inputs),
partitioner=[XnnpackPartitioner()],
).to_executorch()
Copy link
Contributor

Choose a reason for hiding this comment

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

no need to copy paste the whole code, just reference to the export.py file

@shoumikhin
Copy link
Contributor

Are we moving the app or duplicating it?

@nil-is-all
Copy link
Contributor Author

nil-is-all commented Apr 22, 2025

Are we moving the app or duplicating it?

The initial idea was to move from executorch/examples to here. The former directory has already been shifted to executorch-examples/apple/ExecuTorchDemo. Once this is up, executorch-examples/apple/ExecuTorchDemo can be removed.

@mergennachin
Copy link
Contributor

@nil-is-all please don't duplicate. do the movement atomically.

do 'git mv' command so that it preserves history.

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.

Do 'git mv' instead of copying.

@nil-is-all
Copy link
Contributor Author

@nil-is-all please don't duplicate. do the movement atomically.
do 'git mv' command so that it preserves history.

@mergennachin just to confirm the final directory, do I git mv the current mv3/apple/ExecuTorchDemo directory to apple/ExecuTorchDemo created by Anthony?

author Nikhil Viswanath Sivakumar <68182521+nil-is-all@users.noreply.github.com> 1741841357 -0500
committer Nikhil Viswanath Sivakumar <nikhilviswanath@meta.com> 1745433893 -0500
Migrate iOS Demo App

parent 5021c18
author Nikhil Viswanath Sivakumar <68182521+nil-is-all@users.noreply.github.com> 1741841357 -0500
committer Nikhil Viswanath Sivakumar <nikhilviswanath@meta.com> 1745433648 -0500
Migrate iOS Demo App

Migrate iOS app demo as README.md

Reproduced https://github.com/pytorch/executorch/tree/main/examples/demo-apps/apple_ios/ExecuTorchDemo and added last line in docs to point to this GitHub repo

Changed file path to executorch-examples/mv3/apple/MobileNetV3Demo/README.md

Changed directory and made changes after local testing

Final directory: executorch-examples/mv3/apple/ExecuTorchDemo

Changes from [current demo](https://pytorch.org/executorch/main/demo-apps-ios.html#):
1) Check Swift Package Manager version under Prerequisites
2) Export Model - export.py for backends
3) Directory changes in Final Steps

Files for iOS MV3 Demo App

export script for MV3.pte and XNNPack, CoreML, MPS backends

Update README.md

Rename mv3/apple/ExecuTorchDemo/export.py to mv3/apple/ExecuTorchDemo/python/export.py

Removed export.py code block from README.md

Added code formatting for Clone the Demo App subsection

added snapshot url

Delete mv3/apple/ExecuTorchDemo/ExecuTorchDemo/Resources/Models/MobileNet directory

atomically migrated apple/ExecuTorch to mv3/apple/ExecuTorchDemo

Updated directory structure to have python in mv3 folder

fixed typo in .gitignore

Update project.pbxproj to pin to 0.6.0 (#11)

MV2 cpp and python example (#13)

Update README.md (#12)

* Update README.md

* Update README.md

fix directory and resolve conflicts

MV2 cpp and python example (#13)

Update .gitignore (#17)
@mergennachin mergennachin merged commit b0e909a into main Apr 24, 2025
1 check passed
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 Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants