Skip to content

Advise on how to run the training example on iOS #8282

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
YuanTingHsieh opened this issue Feb 6, 2025 · 6 comments
Closed

Advise on how to run the training example on iOS #8282

YuanTingHsieh opened this issue Feb 6, 2025 · 6 comments
Assignees
Labels
module: ios Issues related to iOS code, build, and execution module: training Issues related to training models on edge devices triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@YuanTingHsieh
Copy link

YuanTingHsieh commented Feb 6, 2025

🚀 The feature, motivation and pitch

Hello team,

I was wondering if it is possible to run the train_xor or a similar training example on an iOS device.
So be able to do
#import <executorch/extension/training/training_module.h>

I have followed this guide: https://pytorch.org/executorch/main/apple-runtime and was able to build the xcframework using a local copy of executorch, add it to the Xcode project, and run it on an iOS device.

I guess I need to compile and package the libraries in https://github.com/pytorch/executorch/tree/main/extension/training to the App, but I don't know how to do that, could you give some pointers?

Thanks!

Alternatives

No response

Additional context

No response

RFC (Optional)

No response

cc @shoumikhin @JacobSzwejbka

@mergennachin mergennachin added module: training Issues related to training models on edge devices module: ios Issues related to iOS code, build, and execution labels Feb 6, 2025
@JacobSzwejbka JacobSzwejbka added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Feb 6, 2025
@shoumikhin
Copy link
Contributor

We can make it a part of executorch.xcframework for now and then consider how to make a standalone .xcframework for it.
@YuanTingHsieh you can try adding the training extension same way as we have the module extension at https://github.com/pytorch/executorch/blob/main/build/build_apple_frameworks.sh
Search for module wording, and you'll need to enable the EXECUTORCH_BUILD_EXTENSION_TRAINING cmake flag.
You'd also need to amend https://github.com/pytorch/executorch/blob/main/build/cmake_deps.toml#L151 to let Cmake leverage Buck to find the headers, etc.
Rebuild the frameworks and check if executorch.xcframework contains the required libs and headers eventually.

@YuanTingHsieh
Copy link
Author

@shoumikhin thanks for the quick response!
I did add some lines to that file:

diff --git a/build/build_apple_frameworks.sh b/build/build_apple_frameworks.sh
index a6494fb..316c430 100755
--- a/build/build_apple_frameworks.sh
+++ b/build/build_apple_frameworks.sh
@@ -33,6 +33,7 @@ libextension_apple.a,\
 libextension_data_loader.a,\
 libextension_module.a,\
 libextension_tensor.a,\
+libextension_training.a,\
 :$HEADERS_PATH"
 
 FRAMEWORK_BACKEND_COREML="backend_coreml:\
@@ -166,6 +167,7 @@ cmake_build() {
         -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
         -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
         -DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \
+        -DEXECUTORCH_BUILD_EXTENSION_TRAINING=ON \
         -DEXECUTORCH_BUILD_KERNELS_CUSTOM=$CUSTOM \
         -DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=$OPTIMIZED \
         -DEXECUTORCH_BUILD_KERNELS_QUANTIZED=$QUANTIZED \
@@ -198,6 +200,8 @@ check_command "$BUCK2"
 "$SOURCE_ROOT_DIR"/build/print_exported_headers.py --buck2=$(realpath "$BUCK2") --targets \
   //extension/module: \
   //extension/tensor: \
+  //extension/training/module: \
+  //extension/training/optimizer: \
 | rsync -av --files-from=- "$SOURCE_ROOT_DIR" "$HEADERS_PATH/executorch"
 
 cp "$SOURCE_ROOT_DIR/extension/apple/ExecuTorch/Exported/"*.h "$HEADERS_PATH/executorch"

and I notice you already have "extension_training" defined here: https://github.com/pytorch/executorch/blob/main/build/cmake_deps.toml#L214-L224

So I modified the build_apple_frameworks.sh and do a build:
./build/build_apple_frameworks.sh --coreml --mps --xnnpack --custom --optimized --portable --quantized --Debug

Copy over the following xcframework

backend_coreml
backend_mps
backend_xnnpack
executorch
kernels_portable

But when I try to build using Xcode I got this error:

Ld /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/ExecuTorchDemo.app/ExecuTorchDemo.debug.dylib normal (in target 'App' from project 'ExecuTorchDemo')
    cd /Users/yuantingh/Downloads/executorch/examples/demo-apps/apple_ios/ExecuTorchDemo
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -Xlinker -reproducible -target arm64-apple-ios17.0 -dynamiclib -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.2.sdk -O0 -L/Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Intermediates.noindex/EagerLinkingTBDs/Debug-iphoneos -L/Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos -F/Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Intermediates.noindex/EagerLinkingTBDs/Debug-iphoneos -F/Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos -filelist /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Intermediates.noindex/ExecuTorchDemo.build/Debug-iphoneos/App.build/Objects-normal/arm64/ExecuTorchDemo.LinkFileList -install_name @rpath/ExecuTorchDemo.debug.dylib -dead_strip -Xlinker -object_path_lto -Xlinker /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Intermediates.noindex/ExecuTorchDemo.build/Debug-iphoneos/App.build/Objects-normal/arm64/ExecuTorchDemo_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -Xlinker -debug_variant -fobjc-link-runtime -fprofile-instr-generate -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos -L/usr/lib/swift -Xlinker -add_ast_path -Xlinker /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Intermediates.noindex/ExecuTorchDemo.build/Debug-iphoneos/App.build/Objects-normal/arm64/ExecuTorchDemo.swiftmodule -lc++ -all_load -Xlinker -alias -Xlinker _main -Xlinker ___debug_main_executable_dylib_entry_point -lbackend_mps-ios-debug -lexecutorch-ios-debug -lkernels_portable-ios-debug -lbackend_xnnpack-ios-debug -lbackend_coreml-ios-debug -framework Accelerate -framework Metal -lsqlite3 -framework CoreML -framework MetalPerformanceShadersGraph -framework MetalPerformanceShaders -lMobileNetClassifier -Xlinker -no_adhoc_codesign -Xlinker -dependency_info -Xlinker /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Intermediates.noindex/ExecuTorchDemo.build/Debug-iphoneos/App.build/Objects-normal/arm64/ExecuTorchDemo_dependency_info.dat -o /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/ExecuTorchDemo.app/ExecuTorchDemo.debug.dylib -Xlinker -add_ast_path -Xlinker /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Intermediates.noindex/ExecuTorchDemo.build/Debug-iphoneos/MobileNetClassifier.build/Objects-normal/arm64/MobileNetClassifier.swiftmodule

duplicate symbol 'executorch::extension::FileDataLoader::from(char const*, unsigned long)' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[28](file_data_loader.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[23](file_data_loader.o)
duplicate symbol 'executorch::extension::Module::method_names()' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[30](module.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[25](module.o)
duplicate symbol 'executorch::extension::Module::Module(std::__1::shared_ptr<executorch::runtime::Program>, std::__1::unique_ptr<executorch::runtime::MemoryAllocator, std::__1::default_delete<executorch::runtime::MemoryAllocator>>, std::__1::unique_ptr<executorch::runtime::MemoryAllocator, std::__1::default_delete<executorch::runtime::MemoryAllocator>>, std::__1::unique_ptr<executorch::runtime::EventTracer, std::__1::default_delete<executorch::runtime::EventTracer>>)' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[30](module.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[25](module.o)
duplicate symbol 'executorch::extension::FileDataLoader::load(unsigned long, unsigned long, executorch::runtime::DataLoader::SegmentInfo const&) const' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[28](file_data_loader.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[23](file_data_loader.o)
duplicate symbol 'executorch::extension::Module::Module(std::__1::unique_ptr<executorch::runtime::DataLoader, std::__1::default_delete<executorch::runtime::DataLoader>>, std::__1::unique_ptr<executorch::runtime::MemoryAllocator, std::__1::default_delete<executorch::runtime::MemoryAllocator>>, std::__1::unique_ptr<executorch::runtime::MemoryAllocator, std::__1::default_delete<executorch::runtime::MemoryAllocator>>, std::__1::unique_ptr<executorch::runtime::EventTracer, std::__1::default_delete<executorch::runtime::EventTracer>>)' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[30](module.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[25](module.o)
duplicate symbol 'executorch::extension::Module::method_meta(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&)' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[30](module.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[25](module.o)
duplicate symbol 'torch::executor::function::et_copy_index(executorch::runtime::KernelRuntimeContext&, executorch::runtime::EValue**)' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[33](et_copy_index.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[2](et_copy_index.o)
duplicate symbol 'vtable for executorch::extension::FileDataLoader' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[28](file_data_loader.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[23](file_data_loader.o)
duplicate symbol 'executorch::extension::FileDataLoader::load_into(unsigned long, unsigned long, executorch::runtime::DataLoader::SegmentInfo const&, void*) const' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[28](file_data_loader.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[23](file_data_loader.o)
duplicate symbol 'typeinfo for executorch::extension::FileDataLoader' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[28](file_data_loader.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[23](file_data_loader.o)
duplicate symbol 'executorch::extension::MmapDataLoader::from(char const*, executorch::extension::MmapDataLoader::MlockConfig)' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[29](mmap_data_loader.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[24](mmap_data_loader.o)
duplicate symbol 'executorch::extension::Module::Module(std::__1::unique_ptr<executorch::runtime::DataLoader, std::__1::default_delete<executorch::runtime::DataLoader>>, std::__1::unique_ptr<executorch::runtime::MemoryAllocator, std::__1::default_delete<executorch::runtime::MemoryAllocator>>, std::__1::unique_ptr<executorch::runtime::MemoryAllocator, std::__1::default_delete<executorch::runtime::MemoryAllocator>>, std::__1::unique_ptr<executorch::runtime::EventTracer, std::__1::default_delete<executorch::runtime::EventTracer>>)' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[30](module.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[25](module.o)
duplicate symbol 'executorch::extension::FileDataLoader::size() const' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[28](file_data_loader.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[23](file_data_loader.o)
duplicate symbol 'executorch::extension::Module::Module(std::__1::shared_ptr<executorch::runtime::Program>, std::__1::unique_ptr<executorch::runtime::MemoryAllocator, std::__1::default_delete<executorch::runtime::MemoryAllocator>>, std::__1::unique_ptr<executorch::runtime::MemoryAllocator, std::__1::default_delete<executorch::runtime::MemoryAllocator>>, std::__1::unique_ptr<executorch::runtime::EventTracer, std::__1::default_delete<executorch::runtime::EventTracer>>)' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[30](module.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[25](module.o)
duplicate symbol 'executorch::extension::MmapDataLoader::~MmapDataLoader()' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[29](mmap_data_loader.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[24](mmap_data_loader.o)
duplicate symbol 'executorch::extension::Module::load_method(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, executorch::runtime::EventTracer*)' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[30](module.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[25](module.o)
duplicate symbol 'executorch::extension::MmapDataLoader::size() const' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[29](mmap_data_loader.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[24](mmap_data_loader.o)
duplicate symbol 'vtable for executorch::extension::MmapDataLoader' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[29](mmap_data_loader.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[24](mmap_data_loader.o)
duplicate symbol 'executorch::extension::Module::Module(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, executorch::extension::Module::LoadMode, std::__1::unique_ptr<executorch::runtime::EventTracer, std::__1::default_delete<executorch::runtime::EventTracer>>)' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[30](module.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[25](module.o)
duplicate symbol 'executorch::extension::MmapDataLoader::~MmapDataLoader()' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[29](mmap_data_loader.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[24](mmap_data_loader.o)
duplicate symbol 'executorch::extension::MmapDataLoader::~MmapDataLoader()' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[29](mmap_data_loader.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[24](mmap_data_loader.o)
duplicate symbol 'executorch::extension::Module::load(executorch::runtime::Program::Verification)' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[30](module.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[25](module.o)
duplicate symbol 'torch::executor::function::et_view(executorch::runtime::KernelRuntimeContext&, executorch::runtime::EValue**)' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[34](et_view.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[3](et_view.o)
duplicate symbol 'executorch::extension::FileDataLoader::~FileDataLoader()' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[28](file_data_loader.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[23](file_data_loader.o)
duplicate symbol 'executorch::extension::Module::Module(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, executorch::extension::Module::LoadMode, std::__1::unique_ptr<executorch::runtime::EventTracer, std::__1::default_delete<executorch::runtime::EventTracer>>)' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[30](module.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[25](module.o)
duplicate symbol 'executorch::extension::FileDataLoader::~FileDataLoader()' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[28](file_data_loader.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[23](file_data_loader.o)
duplicate symbol 'executorch::extension::MmapDataLoader::load(unsigned long, unsigned long, executorch::runtime::DataLoader::SegmentInfo const&) const' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[29](mmap_data_loader.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[24](mmap_data_loader.o)
duplicate symbol 'executorch::extension::Module::execute(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, std::__1::vector<executorch::runtime::EValue, std::__1::allocator<executorch::runtime::EValue>> const&)' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[30](module.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[25](module.o)
duplicate symbol 'executorch::extension::Module::set_inputs(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, std::__1::vector<executorch::runtime::EValue, std::__1::allocator<executorch::runtime::EValue>> const&)' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[30](module.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[25](module.o)
duplicate symbol 'typeinfo name for executorch::extension::FileDataLoader' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[28](file_data_loader.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[23](file_data_loader.o)
duplicate symbol 'typeinfo name for executorch::extension::MmapDataLoader' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[29](mmap_data_loader.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[24](mmap_data_loader.o)
duplicate symbol 'executorch::extension::Module::set_input(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, executorch::runtime::EValue const&, unsigned long)' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[30](module.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[25](module.o)
duplicate symbol 'executorch::extension::Module::set_output(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, executorch::runtime::EValue, unsigned long)' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[30](module.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[25](module.o)
duplicate symbol 'executorch::extension::FileDataLoader::~FileDataLoader()' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[28](file_data_loader.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[23](file_data_loader.o)
duplicate symbol 'typeinfo for executorch::extension::MmapDataLoader' in:
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[29](mmap_data_loader.o)
    /Users/yuantingh/Library/Developer/Xcode/DerivedData/ExecuTorchDemo-fvzhndovogcuddbacmnoflrmuvtz/Build/Products/Debug-iphoneos/libexecutorch-ios-debug.a[24](mmap_data_loader.o)
ld: 35 duplicate symbols
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Any help is appreciated!

@shoumikhin
Copy link
Contributor

@YuanTingHsieh please try playing with the deps listed for the training target here https://github.com/pytorch/executorch/blob/main/build/cmake_deps.toml#L222
Chances are it's missing the extension_module as a dep to avoid duplicated symbols.

@YuanTingHsieh
Copy link
Author

@shoumikhin thanks for the reply!

I added:

diff --git a/build/cmake_deps.toml b/build/cmake_deps.toml
index c768070..701421a 100644
--- a/build/cmake_deps.toml
+++ b/build/cmake_deps.toml
@@ -220,7 +220,11 @@ filters = [
   ".cpp$",
 ]
 deps = [
+  "executorch",
   "executorch_core",
+  "extension_data_loader",
+  "extension_module",
+  "extension_tensor",
 ]
 

then I am able to do:

#import <executorch/extension/training/module/training_module.h>
#import <executorch/extension/training/optimizer/sgd.h>

std::unique_ptr<training::TrainingModule> _module;

Now I try to use it and realize it needs FileDataLoader
So I am trying to compile/export that header to be imported using Obj-C as well.
Do you think this is the right way?

Thanks!

@shoumikhin
Copy link
Contributor

@YuanTingHsieh please try adding //extension/data_loader: to this list of the Buck targets which public headers we copy to the resulting .xcframework .

@YuanTingHsieh
Copy link
Author

@shoumikhin thanks for the help!

After added that I can run the training example now.

diff --git a/build/build_apple_frameworks.sh b/build/build_apple_frameworks.sh
index a6494fb..14fa6b5 100755
--- a/build/build_apple_frameworks.sh
+++ b/build/build_apple_frameworks.sh
@@ -33,6 +33,7 @@ libextension_apple.a,\
 libextension_data_loader.a,\
 libextension_module.a,\
 libextension_tensor.a,\
+libextension_training.a,\
 :$HEADERS_PATH"
 
 FRAMEWORK_BACKEND_COREML="backend_coreml:\
@@ -166,6 +167,7 @@ cmake_build() {
         -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
         -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
         -DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \
+        -DEXECUTORCH_BUILD_EXTENSION_TRAINING=ON \
         -DEXECUTORCH_BUILD_KERNELS_CUSTOM=$CUSTOM \
         -DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=$OPTIMIZED \
         -DEXECUTORCH_BUILD_KERNELS_QUANTIZED=$QUANTIZED \
@@ -198,6 +200,9 @@ check_command "$BUCK2"
 "$SOURCE_ROOT_DIR"/build/print_exported_headers.py --buck2=$(realpath "$BUCK2") --targets \
   //extension/module: \
   //extension/tensor: \
+  //extension/data_loader: \
+  //extension/training/module: \
+  //extension/training/optimizer: \
 | rsync -av --files-from=- "$SOURCE_ROOT_DIR" "$HEADERS_PATH/executorch"
 
 cp "$SOURCE_ROOT_DIR/extension/apple/ExecuTorch/Exported/"*.h "$HEADERS_PATH/executorch"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: ios Issues related to iOS code, build, and execution module: training Issues related to training models on edge devices triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

No branches or pull requests

4 participants