Skip to content

iOS demo app. #557

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

Closed
wants to merge 1 commit into from
Closed

iOS demo app. #557

wants to merge 1 commit into from

Conversation

shoumikhin
Copy link
Contributor

@shoumikhin shoumikhin commented Sep 30, 2023

Summary:

Pre-flight:

  • Clone executorch repo
  • Install the recommended buck2 binary version at /tmp/buck2
  • cd path/to/executorch
  • Sync and update git submodules
  • Make sure you have Python 3.11+ installed (standard on Ventura+) and pip pointing to it
  • Run ./install_requirements.sh to install PyTorch dependencies
# Build flatbuffers compiler

cd third-party/flatbuffers && rm -rf cmake-out && mkdir cmake-out && cd cmake-out

cmake .. && cmake --build . --target flatc

cd ../../..

# Configure executorch

rm -rf cmake-out && mkdir cmake-out && cd cmake-out

cmake .. -G Xcode -DCMAKE_TOOLCHAIN_FILE=../third-party/pytorch/cmake/iOS.cmake -DBUCK2=/tmp/buck2 -DPYTHON_EXECUTABLE=$(which python3) -DFLATC_EXECUTABLE=$(realpath ../third-party/flatbuffers/cmake-out/flatc) -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=$(pwd) -DEXECUTORCH_BUILD_XNNPACK=ON -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON -DCMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM=<YOUR_TEAM_ID>  # -DPLATFORM=SIMULATOR

# Build executorch

cmake --build . --config Release

# Copy executorch libs

cd Release

mkdir -p ../../examples/ios_demo_apps/ExecuTorchDemo/ExecuTorchDemo/Frameworks/executorch/

cp libclog.a libcpuinfo.a libexecutorch.a libextension_data_loader.a libportable_kernels.a libportable_ops_lib.a libpthreadpool.a libxnnpack_backend.a libXNNPACK.a ../../examples/ios_demo_apps/ExecuTorchDemo/ExecuTorchDemo/Frameworks/executorch/

cd ../..

# Download the labels and bundle with the app

mkdir -p examples/ios_demo_apps/ExecuTorchDemo/ExecuTorchDemo/Resources/Models/MobileNet/

curl https://raw.githubusercontent.com/pytorch/hub/master/imagenet_classes.txt -o examples/ios_demo_apps/ExecuTorchDemo/ExecuTorchDemo/Resources/Models/MobileNet/imagenet_classes.txt

# Export a MobileNet v3 model backed with XNNPACK delegate and copy it over to bundle with the app

export FLATC_EXECUTABLE=$(realpath third-party/flatbuffers/cmake-out/flatc)

python3 -m examples.export.export_example --model_name="mv3"
python3 -m examples.backend.xnnpack_examples --model_name="mv3" --delegate

cp mv3.pte mv3_xnnpack_fp32.pte examples/ios_demo_apps/ExecuTorchDemo/ExecuTorchDemo/Resources/Models/MobileNet/

Post-flight:

  • Open executorch/examples/ios_demo_apps/ExecuTorchDemo/ExecuTorchDemo.xcodeproj
  • Set the header search path for MobileNetClassifier target pointing to the dir containing the executorch repo
  • Run the app and tests

Differential Revision: D49800418

@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 Sep 30, 2023
@netlify
Copy link

netlify bot commented Sep 30, 2023

Deploy Preview for resplendent-gnome-14e531 canceled.

Name Link
🔨 Latest commit b303e6d
🔍 Latest deploy log https://app.netlify.com/sites/resplendent-gnome-14e531/deploys/651ba5310c704f00087e5473

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D49800418

Copy link
Contributor

@kimishpatel kimishpatel left a comment

Choose a reason for hiding this comment

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

for model files bundled here, I am gonna suggest to have a python script that generates this files and link them as steps in the tutorial:
e.g.

  • python generate_mv2.py --delegate...
  • copy the pte file to
  • ..

isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
03C818472AC7A1190084CC29 /* libImageClassification.a in Frameworks */,
Copy link
Contributor

Choose a reason for hiding this comment

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

what are the ids? and how are they connect to libs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are not related, they are part of the xcode project, which is currently hardcoded, but we'll generate it eventually and get rid of this file.

Copy link
Contributor

@kimishpatel kimishpatel left a comment

Choose a reason for hiding this comment

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

sending it back for 2 things

  1. if we can make model generation as part of the script that should be invoked, that would be good.
  2. documentation as to how to enable your own delegate. this will help apple

std::vector<torch::executor::Span<uint8_t>> plannedSpans_;
std::unique_ptr<torch::executor::HierarchicalAllocator> plannedMemory_;
std::unique_ptr<torch::executor::MemoryManager> memoryManager_;
std::unique_ptr<torch::executor::Method> forward_;
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe call it method_ for consistency

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D49800418

1 similar comment
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D49800418

@kimishpatel
Copy link
Contributor

for ios toolchain for cmake, I think we should standardize it. Apple's PR also has sometihng like that but it is part of their PR

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D49800418

2 similar comments
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D49800418

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D49800418

@shoumikhin
Copy link
Contributor Author

for ios toolchain for cmake, I think we should standardize it. Apple's PR also has sometihng like that but it is part of their PR

They should be able to use ours, as shown in PR summary

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D49800418

4 similar comments
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D49800418

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D49800418

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D49800418

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D49800418

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D49800418

Summary: Pull Request resolved: #557

Reviewed By: cccclai

Differential Revision: D49800418

fbshipit-source-id: c4233781166453bca131c5fe0c2d76ad60f20448
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D49800418

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in f9e23ea.

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. fb-exported Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants