diff --git a/.github/workflows/_ios-build-test.yml b/.github/workflows/_ios-build-test.yml index 7473862dd85..1a1954318eb 100644 --- a/.github/workflows/_ios-build-test.yml +++ b/.github/workflows/_ios-build-test.yml @@ -7,14 +7,6 @@ on: required: true type: string description: Top-level label for what's being built/tested. - ios-platform: - required: true - type: string - description: Which iOS platform to build for. - ios-arch: - required: true - type: string - description: Which iOS arch to build for. sync-tag: required: false type: string @@ -31,8 +23,6 @@ on: env: GIT_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} BUILD_ENVIRONMENT: ${{ inputs.build-environment }} - IOS_PLATFORM: ${{ inputs.ios-platform }} - IOS_ARCH: ${{ inputs.ios-arch }} jobs: filter: @@ -63,6 +53,16 @@ jobs: matrix: ${{ fromJSON(needs.filter.outputs.test-matrix) }} fail-fast: false runs-on: ${{ matrix.runner }} + env: + IOS_PLATFORM: ${{ matrix.ios_platform }} + IOS_ARCH: ${{ matrix.ios_arch }} + BUILD_LITE_INTERPRETER: ${{ matrix.use_lite_interpreter }} + USE_PYTORCH_METAL: ${{ matrix.use_metal }} + USE_COREML_DELEGATE: ${{ matrix.use_coreml }} + CUSTOM_OP_LIST: ${{ matrix.use_custom_op_list }} + # TODO: Bump it to 2.2.0 after cherry pick this or figure out a better way + # to get this version instead of hard coding it here + PYTORCH_VERSION: 2.1.0 timeout-minutes: 240 steps: # [see note: pytorch repo ref] @@ -70,26 +70,13 @@ jobs: uses: pytorch/pytorch/.github/actions/checkout-pytorch@main - name: Populate CI build options + shell: bash run: | - # Most builds use the lite interpreter, if certain builds shouldn't - # build the lite interpreter this env variable should get over-written - # in the following case statement - echo "BUILD_LITE_INTERPRETER=1" >> "${GITHUB_ENV}" + set -ex - case ${BUILD_ENVIRONMENT} in - *metal*) - echo "USE_PYTORCH_METAL=1" >> "${GITHUB_ENV}" - ;; - *full_jit*) - echo "BUILD_LITE_INTERPRETER=0" >> "${GITHUB_ENV}" - ;; - *custom*) - echo "SELECTED_OP_LIST=${GITHUB_WORKSPACE}/ios/TestApp/custom_build/mobilenetv2.yaml" >> "${GITHUB_ENV}" - ;; - *coreml*) - echo "USE_COREML_DELEGATE=1" >> "${GITHUB_ENV}" - ;; - esac + if [ -n "${CUSTOM_OP_LIST:-}" ]; then + echo "SELECTED_OP_LIST=${GITHUB_WORKSPACE}/ios/TestApp/custom_build/${CUSTOM_OP_LIST}" >> "${GITHUB_ENV}" + fi - name: Install brew dependencies uses: nick-fields/retry@v2.8.2 @@ -116,54 +103,67 @@ jobs: retry_wait_seconds: 90 command: | set -x - cd ios/TestApp - # install fastlane + + pushd ios/TestApp + # Install fastlane sudo gem install bundler && bundle install bundle update fastlane + popd - - name: Build PyTorch Mobile Runtime + - name: Build PyTorch mobile runtime + shell: bash run: | + set -eux # shellcheck disable=SC1091 export TCLLIBPATH="/usr/local/lib" - python -VV ${CONDA_RUN} scripts/build_ios.sh - name: Build TestApp - if: inputs.ios-platform == 'SIMULATOR' + if: matrix.ios_platform == 'SIMULATOR' timeout-minutes: 15 run: | - # run the ruby build script + # Run the ruby build script if ! [ -x "$(command -v xcodebuild)" ]; then echo 'Error: xcodebuild is not installed.' exit 1 fi ruby scripts/xcode_build.rb -i build_ios/install -x ios/TestApp/TestApp.xcodeproj -p "${IOS_PLATFORM}" - - name: Run Simulator Tests - if: inputs.ios-platform == 'SIMULATOR' + - name: Run simulator tests + if: matrix.ios_platform == 'SIMULATOR' + shell: bash run: | + set -eux # shellcheck disable=SC1091 - # use the pytorch nightly build to generate models - ${CONDA_RUN} pip3 install --pre torch torchvision torchaudio -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html - # generate models for differnet backends - cd "${GITHUB_WORKSPACE}/ios/TestApp/benchmark" + # Use the pytorch nightly build to generate models + ${CONDA_RUN} pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cpu + + # Generate models for differnet backends + pushd "${GITHUB_WORKSPACE}/ios/TestApp/benchmark" mkdir -p ../models + # NB: Both of the following scripts only export models with lite interpreter if [ "${USE_COREML_DELEGATE}" == 1 ]; then ${CONDA_RUN} python coreml_backend.py else - cd "${GITHUB_WORKSPACE}" + pushd "${GITHUB_WORKSPACE}" ${CONDA_RUN} python test/mobile/model_test/gen_test_model.py ios-test + popd fi - cd "${GITHUB_WORKSPACE}/ios/TestApp/benchmark" + if [ "${BUILD_LITE_INTERPRETER}" == 1 ]; then echo "Setting up the TestApp for LiteInterpreter" ruby setup.rb --lite 1 else + # Generate some models for JIT without lite interpreter + ${CONDA_RUN} python trace_model.py + echo "Setting up the TestApp for Full JIT" ruby setup.rb fi - cd "${GITHUB_WORKSPACE}/ios/TestApp" - # instruments -s -devices + popd + + pushd "${GITHUB_WORKSPACE}/ios/TestApp" + # Instruments -s -devices if [ "${BUILD_LITE_INTERPRETER}" == 1 ]; then if [ "${USE_COREML_DELEGATE}" == 1 ]; then bundle exec fastlane scan --only_testing TestAppTests/TestAppTests/testCoreML @@ -173,9 +173,282 @@ jobs: else bundle exec fastlane scan --only_testing TestAppTests/TestAppTests/testFullJIT fi + popd - - name: Dump Simulator Tests On a Failure - if: failure() && inputs.ios-platform == 'SIMULATOR' + - name: Dump simulator tests on failure + if: failure() && matrix.ios_platform == 'SIMULATOR' run: | echo "Simulator Tests Logs:" cat /Users/runner/Library/Logs/scan/*.log + + - name: Prepare the build artifacts for upload + shell: bash + run: | + set -eux + + # The structure of the folder is as follows: + # + # RUNNER_TEMP/ + # └── IOS_ARCH/ + # ├── LICENSE + # ├── install + # │ ├── include + # │ │ └── headers + # │ └── lib + # │ ├── libXNNPACK.a + # │ ├── libc10.a + # │ ├── libclog.a + # │ ├── libcpuinfo.a + # │ ├── libeigen_blas.a + # │ ├── libpthreadpool.a + # │ ├── libpytorch_qnnpack.a + # │ ├── libtorch.a + # │ └── libtorch_cpu.a + # ├── src + # │ └── LibTorch-Lite.h + # └── version.txt + SETUP_DIR="${RUNNER_TEMP}/${IOS_ARCH}" + mkdir -p "${SETUP_DIR}/src" + + cp -R "${GITHUB_WORKSPACE}/build_ios/install" "${SETUP_DIR}" + # Copy the umbrella header and license + if [ "${BUILD_LITE_INTERPRETER}" == 1 ]; then + cp "${GITHUB_WORKSPACE}/ios/LibTorch-Lite.h" "${SETUP_DIR}/src" + else + cp "${GITHUB_WORKSPACE}/ios/LibTorch.h" "${SETUP_DIR}/src" + fi + + # Copy license and version + cp "${GITHUB_WORKSPACE}/LICENSE" "${SETUP_DIR}" + echo "${PYTORCH_VERSION}" > "${SETUP_DIR}"/version.txt + + # Save the podspec for the upload job later + if [ "${BUILD_LITE_INTERPRETER}" == "1" ]; then + DATE=$(date -u +%Y%m%d) + cp "${GITHUB_WORKSPACE}"/ios/LibTorch-Lite-Nightly.podspec.template "${SETUP_DIR}"/LibTorch-Lite-Nightly.podspec + sed -i '' -e "s/IOS_NIGHTLY_BUILD_VERSION/${PYTORCH_VERSION}.${DATE}/g" "${SETUP_DIR}"/LibTorch-Lite-Nightly.podspec + + cp "${GITHUB_WORKSPACE}"/ios/LibTorch-Lite.podspec.template "${SETUP_DIR}"/LibTorch-Lite.podspec + sed -i '' -e "s/IOS_BUILD_VERSION/${PYTORCH_VERSION}/g" "${SETUP_DIR}"/LibTorch-Lite.podspec + else + # NB: There is no nightly build without lite interpreter atm + cp "${GITHUB_WORKSPACE}"/ios/LibTorch.podspec.template "${SETUP_DIR}"/LibTorch.podspec + sed -i '' -e "s/IOS_BUILD_VERSION/${PYTORCH_VERSION}/g" "${SETUP_DIR}"/LibTorch.podspec + fi + + pushd "${SETUP_DIR}" + # NB: It's important to zip all the files before uploading because the GHA will upload + # all files sequentially which is both slow and has too many requests. More info is at + # https://github.com/actions/upload-artifact#too-many-uploads-resulting-in-429-responses + zip -r "${IOS_ARCH}.zip" install src version.txt LICENSE ./*.podspec + popd + + - uses: actions/upload-artifact@v3 + with: + name: pytorch-ios-build-artifacts-${{ matrix.ios_arch }} + if-no-files-found: error + path: ${{ runner.temp }}/${{ matrix.ios_arch }}/${{ matrix.ios_arch }}.zip + + upload-ios-artifacts: + # NB: this job run on GitHub MacOS ephemeral runner so that it can use lipo + # to create the fat iOS binaries for both x86_64 and arm64 + runs-on: macos-12 + needs: build + # NB: Only upload release build, if we need it, we could also turn on nightly here + environment: ${{ (github.event_name == 'push' && (github.event.ref == 'refs/heads/nightly' || startsWith(github.event.ref, 'refs/tags/v'))) && 'ios-upload' || '' }} + steps: + - uses: actions/checkout@v3 + + # For awscli S3 upload + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + cache: pip + + # For cocoapods pod upload + - uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.2' + bundler-cache: true + + - name: Download arm64 artifacts + uses: actions/download-artifact@v3 + with: + name: pytorch-ios-build-artifacts-arm64 + + - name: Download x86_64 artifacts + uses: actions/download-artifact@v3 + with: + name: pytorch-ios-build-artifacts-x86_64 + + - name: Unzip arm64 and x86_64 artifacts + shell: bash + run: | + set -eux + + for ARCH in "arm64" "x86_64"; do + TMP_DIR="${RUNNER_TEMP}/${ARCH}" + mkdir -p "${TMP_DIR}" + + cp "${ARCH}.zip" "${TMP_DIR}" + + pushd "${TMP_DIR}" + unzip -o "${ARCH}.zip" + popd + done + + - name: Prepare the artifact + env: + IS_NIGHTLY: ${{ github.event.ref == 'refs/heads/nightly' }} + shell: bash + working-directory: ${{ runner.temp }}/arm64 + run: | + set -eux + + DEST_DIR="${RUNNER_TEMP}"/ios + echo "DEST_DIR=${DEST_DIR}" >> "$GITHUB_ENV" + + # Prepare all the sub directories + mkdir -p "${DEST_DIR}"/install/lib + + # Copy header and share files, arm64 or x86_64 both work + cp -R install/include "${DEST_DIR}"/install + cp -R install/share "${DEST_DIR}"/install + # The last dash is important to copy only files under src + cp -R src "${DEST_DIR}" + cp LICENSE "${DEST_DIR}" + + if [ "${IS_NIGHTLY}" == true ]; then + PYTORCH_VERSION=$(cat version.txt) + DATE=$(date -u +%Y%m%d) + echo "${PYTORCH_VERSION}.${DATE}" > "${DEST_DIR}"/version.txt + else + cp version.txt "${DEST_DIR}" + fi + PYTORCH_VERSION=$(cat "${DEST_DIR}"/version.txt) + echo "PYTORCH_VERSION=${PYTORCH_VERSION}" >> "$GITHUB_ENV" + + pushd install/lib + # shellcheck disable=SC2207 + LIBRARIES=($(ls ./*.a)) + popd + + for LIB in "${LIBRARIES[@]}"; do + FROM_LIBS=("${RUNNER_TEMP}"/arm64/install/lib/"${LIB}" "${RUNNER_TEMP}"/x86_64/install/lib/"${LIB}") + # Create a fat binary for both arm64 and x86_64 + lipo -create "${FROM_LIBS[@]}" -o "${DEST_DIR}"/install/lib/"${LIB}" + # Print the info + lipo -i "${DEST_DIR}"/install/lib/"${LIB}" + done + + BUILD_LITE_INTERPRETER=1 + if [ -f "${RUNNER_TEMP}"/arm64/LibTorch.podspec ]; then + # If LibTorch.podspec is used instead of LibTorch-Lite.podspec, the artifact is built + # without lite interpreter + BUILD_LITE_INTERPRETER=0 + fi + echo "BUILD_LITE_INTERPRETER=${BUILD_LITE_INTERPRETER}" >> "$GITHUB_ENV" + + - name: Prepare the podspec + env: + IS_NIGHTLY: ${{ github.event.ref == 'refs/heads/nightly' }} + shell: bash + working-directory: ${{ env.DEST_DIR }} + run: | + set -eux + + ARTIFACT_NAME=libtorch + SPEC_NAME=LibTorch + + if [ "${BUILD_LITE_INTERPRETER}" == "1" ]; then + ARTIFACT_NAME="${ARTIFACT_NAME}_lite_ios" + SPEC_NAME="${SPEC_NAME}-Lite" + else + ARTIFACT_NAME="${ARTIFACT_NAME}_ios" + fi + + if [ "${IS_NIGHTLY}" == true ]; then + ARTIFACT_NAME="${ARTIFACT_NAME}_nightly_${PYTORCH_VERSION}.zip" + SPEC_NAME="${SPEC_NAME}-Nightly" + else + ARTIFACT_NAME="${ARTIFACT_NAME}_${PYTORCH_VERSION}.zip" + fi + + SPEC_NAME_WITH_VERSION="${SPEC_NAME}-${PYTORCH_VERSION}.podspec" + SPEC_NAME="${SPEC_NAME}.podspec" + + # Also copy the spec file + cp "${RUNNER_TEMP}"/arm64/"${SPEC_NAME}" "${SPEC_NAME_WITH_VERSION}" + + # NB: It's important to zip all the files before uploading because the GHA will upload + # all files sequentially which is both slow and has too many requests. More info is at + # https://github.com/actions/upload-artifact#too-many-uploads-resulting-in-429-responses + zip -r "${ARTIFACT_NAME}" install src version.txt LICENSE + + { + echo "ARTIFACT_NAME=${ARTIFACT_NAME}" + echo "SPEC_NAME_WITH_VERSION=${SPEC_NAME_WITH_VERSION}" + echo "SPEC_NAME=${SPEC_NAME}" + } >> "$GITHUB_ENV" + + - uses: actions/upload-artifact@v3 + with: + name: pytorch-ios-artifacts + if-no-files-found: error + path: ${{ env.DEST_DIR }}/${{ env.ARTIFACT_NAME }} + + - uses: actions/upload-artifact@v3 + with: + name: pytorch-ios-podspec + if-no-files-found: error + path: ${{ env.DEST_DIR }}/${{ env.SPEC_NAME_WITH_VERSION }} + + - name: Set DRY_RUN + if: ${{ github.event_name == 'push' && (github.event.ref == 'refs/heads/nightly' || (startsWith(github.event.ref, 'refs/tags/v'))) }} + shell: bash + run: | + echo "DRY_RUN=disabled" >> "$GITHUB_ENV" + + - name: Upload the artifact to S3 + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_PYTORCH_UPLOADER_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_PYTORCH_UPLOADER_SECRET_ACCESS_KEY }} + IS_NIGHTLY: ${{ github.event.ref == 'refs/heads/nightly' }} + shell: bash + working-directory: ${{ env.DEST_DIR }} + run: | + set -eux + + pip install -q awscli==1.29.40 + + DRY_RUN=${DRY_RUN:-enabled} + AWS_S3_CP="aws s3 cp --dryrun" + if [ "${DRY_RUN}" == "disabled" ]; then + AWS_S3_CP="aws s3 cp" + fi + + if [ "${IS_NIGHTLY}" == true ]; then + BUCKET_NAME="ossci-ios-build" + else + BUCKET_NAME="ossci-ios" + fi + + ${AWS_S3_CP} "${ARTIFACT_NAME}" "s3://${BUCKET_NAME}/" --acl public-read + ${AWS_S3_CP} "${SPEC_NAME_WITH_VERSION}" "s3://${BUCKET_NAME}/" --acl public-read + + - name: Upload the artifact to cocoapods (nightly only) + env: + # We need to set this secret to upload to cocoapods. However, we might want + # to NOT set this for PROD release so that we can upload the artifacts manually + COCOAPODS_TRUNK_TOKEN: ${{ secrets.COCOAPODS_TRUNK_TOKEN || '' }} + if: ${{ github.event_name == 'push' && github.event.ref == 'refs/heads/nightly' && env.COCOAPODS_TRUNK_TOKEN != '' }} + shell: bash + working-directory: ${{ runner.temp }}/arm64 + run: | + set -eux + + gem install cocoapods + + pod trunk me + # Upload the spec to cocoapods + pod trunk push --verbose --allow-warnings --use-libraries --skip-import-validation "${SPEC_NAME}" diff --git a/.github/workflows/build-ios-binaries.yml b/.github/workflows/build-ios-binaries.yml new file mode 100644 index 00000000000..06ede79d39b --- /dev/null +++ b/.github/workflows/build-ios-binaries.yml @@ -0,0 +1,70 @@ +name: Build iOS binaries + +on: + push: + branches: + - nightly + tags: + # NOTE: Binary build pipelines should only get triggered on release candidate builds + # Release candidate tags look like: v1.11.0-rc1 + - v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+ + paths: + - .github/workflows/build-ios-binaries.yml + - .github/workflows/_ios-build-test.yml + pull_request: + paths: + - .github/workflows/build-ios-binaries.yml + - .github/workflows/_ios-build-test.yml + # NB: We can use this workflow dispatch to test and build iOS binaries manually + workflow_dispatch: + inputs: + use_lite_interpreter: + description: "Use PyTorch lite interpreter?" + type: string + default: 1 + use_coreml: + description: "Use Apple Core ML?" + type: string + default: 1 + use_custom_op_list: + description: "Specify the custom ops list to include in the binaries" + type: string + default: "" + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.event_name == 'workflow_dispatch' }} + cancel-in-progress: true + +jobs: + # TODO: Figure out how to migrate this job to M1 runner + ios-build-test: + name: ios-build-test + uses: ./.github/workflows/_ios-build-test.yml + with: + build-environment: ios-build-test + sync-tag: ios-build-test + test-matrix: | + { include: [ + { config: "default", + shard: 1, + num_shards: 1, + runner: "macos-12", + ios_platform: "SIMULATOR", + ios_arch: "x86_64", + use_lite_interpreter: ${{ inputs.use_lite_interpreter || 1 }}, + use_metal: 0, + use_coreml: ${{ inputs.use_coreml || 1 }}, + use_custom_op_list: ${{ inputs.use_custom_op_list || '' }} + }, + { config: "default", + shard: 1, + num_shards: 1, + runner: "macos-12", + ios_platform: "OS", + ios_arch: "arm64", + use_lite_interpreter: ${{ inputs.use_lite_interpreter || 1 }}, + use_metal: 1, + use_coreml: ${{ inputs.use_coreml || 1 }}, + use_custom_op_list: ${{ inputs.use_custom_op_list || '' }} + } + ]} diff --git a/.github/workflows/periodic.yml b/.github/workflows/periodic.yml index 7597db1b339..65566074a01 100644 --- a/.github/workflows/periodic.yml +++ b/.github/workflows/periodic.yml @@ -112,30 +112,38 @@ jobs: cuda-version: "11.8" test-matrix: ${{ needs.win-vs2019-cuda11_8-py3-build.outputs.test-matrix }} - ios-12-5-1-x86-64-coreml: - name: ios-12-5-1-x86-64-coreml + # TODO: Figure out how to migrate this job to M1 runner + ios-build-test: + name: ios-build-test if: github.event_name != 'schedule' || github.event.schedule == '45 0,8,16 * * 1-5' || github.event.schedule == '45 4 * * 0,6' uses: ./.github/workflows/_ios-build-test.yml with: - build-environment: ios-12-5-1-x86-64-coreml - ios-platform: SIMULATOR - ios-arch: x86_64 + build-environment: ios-build-test + sync-tag: ios-build-test test-matrix: | { include: [ - { config: "default", shard: 1, num_shards: 1, runner: "macos-12" }, - ]} - - ios-12-5-1-arm64-custom-ops: - name: ios-12-5-1-arm64-custom-ops - if: github.event_name != 'schedule' || github.event.schedule == '45 0,8,16 * * 1-5' || github.event.schedule == '45 4 * * 0,6' - uses: ./.github/workflows/_ios-build-test.yml - with: - build-environment: ios-12-5-1-arm64-custom-ops - ios-platform: OS - ios-arch: arm64 - test-matrix: | - { include: [ - { config: "default", shard: 1, num_shards: 1, runner: "macos-12" }, + { config: "default", + shard: 1, + num_shards: 1, + runner: "macos-12", + ios_platform: "SIMULATOR", + ios_arch: "x86_64", + use_lite_interpreter: 1, + use_metal: 0, + use_coreml: 1, + use_custom_op_list: "" + }, + { config: "default", + shard: 1, + num_shards: 1, + runner: "macos-12", + ios_platform: "OS", + ios_arch: "arm64", + use_lite_interpreter: 1, + use_metal: 1, + use_coreml: 1, + use_custom_op_list: "mobilenetv2.yaml" + } ]} buck-build-test: diff --git a/cmake/iOS.cmake b/cmake/iOS.cmake index d42ea4c9232..7b0fe056b05 100644 --- a/cmake/iOS.cmake +++ b/cmake/iOS.cmake @@ -53,9 +53,9 @@ set(CMAKE_RANLIB ranlib CACHE FILEPATH "" FORCE) set(PKG_CONFIG_EXECUTABLE pkg-config CACHE FILEPATH "" FORCE) # Setup iOS platform unless specified manually with IOS_PLATFORM -if(NOT DEFINED IOS_PLATFORM) +if(NOT IOS_PLATFORM) set(IOS_PLATFORM "OS") -endif(NOT DEFINED IOS_PLATFORM) +endif(NOT IOS_PLATFORM) set(IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING "Type of iOS Platform") # Check the platform selection and setup for developer root @@ -118,9 +118,9 @@ set(CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a") # (where install_name_tool was hardcoded) and where CMAKE_INSTALL_NAME_TOOL isn't in the cache # and still cmake didn't fail in CMakeFindBinUtils.cmake (because it isn't rerun) # hardcode CMAKE_INSTALL_NAME_TOOL here to install_name_tool, so it behaves as it did before, Alex -if(NOT DEFINED CMAKE_INSTALL_NAME_TOOL) +if(NOT CMAKE_INSTALL_NAME_TOOL) find_program(CMAKE_INSTALL_NAME_TOOL install_name_tool) -endif(NOT DEFINED CMAKE_INSTALL_NAME_TOOL) +endif(NOT CMAKE_INSTALL_NAME_TOOL) # Setup iOS deployment target set(IOS_DEPLOYMENT_TARGET ${IOS_DEPLOYMENT_TARGET} CACHE STRING "Minimum iOS version") @@ -130,17 +130,17 @@ set(IOS_DEPLOYMENT_TARGET ${IOS_DEPLOYMENT_TARGET} CACHE STRING "Minimum iOS ver exec_program(/usr/bin/xcode-select ARGS -print-path OUTPUT_VARIABLE CMAKE_XCODE_DEVELOPER_DIR) set(XCODE_POST_43_ROOT "${CMAKE_XCODE_DEVELOPER_DIR}/Platforms/${IOS_PLATFORM_LOCATION}/Developer") set(XCODE_PRE_43_ROOT "/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer") -if(NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT) +if(NOT CMAKE_IOS_DEVELOPER_ROOT) if(EXISTS ${XCODE_POST_43_ROOT}) set(CMAKE_IOS_DEVELOPER_ROOT ${XCODE_POST_43_ROOT}) elseif(EXISTS ${XCODE_PRE_43_ROOT}) set(CMAKE_IOS_DEVELOPER_ROOT ${XCODE_PRE_43_ROOT}) endif(EXISTS ${XCODE_POST_43_ROOT}) -endif(NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT) +endif(NOT CMAKE_IOS_DEVELOPER_ROOT) set(CMAKE_IOS_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT} CACHE PATH "Location of iOS Platform") # Find and use the most recent iOS sdk unless specified manually with CMAKE_IOS_SDK_ROOT -if(NOT DEFINED CMAKE_IOS_SDK_ROOT) +if(NOT CMAKE_IOS_SDK_ROOT) file(GLOB _CMAKE_IOS_SDKS "${CMAKE_IOS_DEVELOPER_ROOT}/SDKs/*") if(_CMAKE_IOS_SDKS) list(SORT _CMAKE_IOS_SDKS) @@ -150,7 +150,7 @@ if(NOT DEFINED CMAKE_IOS_SDK_ROOT) message(FATAL_ERROR "No iOS SDK's found in default search path ${CMAKE_IOS_DEVELOPER_ROOT}. Manually set CMAKE_IOS_SDK_ROOT or install the iOS SDK.") endif(_CMAKE_IOS_SDKS) message(STATUS "Toolchain using default iOS SDK: ${CMAKE_IOS_SDK_ROOT}") -endif(NOT DEFINED CMAKE_IOS_SDK_ROOT) +endif(NOT CMAKE_IOS_SDK_ROOT) set(CMAKE_IOS_SDK_ROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Location of the selected iOS SDK") # Set the sysroot default to the most recent SDK diff --git a/ios/LibTorch-Lite.podspec b/ios/LibTorch-Lite.podspec.template similarity index 93% rename from ios/LibTorch-Lite.podspec rename to ios/LibTorch-Lite.podspec.template index 96b759f2215..50f4012b6c5 100644 --- a/ios/LibTorch-Lite.podspec +++ b/ios/LibTorch-Lite.podspec.template @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'LibTorch-Lite' - s.version = '1.13.0' + s.version = 'IOS_BUILD_VERSION' s.authors = 'PyTorch Team' s.license = { :type => 'BSD' } s.homepage = 'https://github.com/pytorch/pytorch' @@ -33,5 +33,5 @@ Pod::Spec.new do |s| 'VALID_ARCHS' => 'x86_64 arm64' } s.library = ['c++', 'stdc++'] - s.frameworks = 'Accelerate' + s.frameworks = 'Accelerate', 'MetalPerformanceShaders', 'CoreML' end diff --git a/ios/LibTorch.podspec b/ios/LibTorch.podspec.template similarity index 92% rename from ios/LibTorch.podspec rename to ios/LibTorch.podspec.template index 6cee4993cca..90738b3f8d1 100644 --- a/ios/LibTorch.podspec +++ b/ios/LibTorch.podspec.template @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'LibTorch' - s.version = '1.13.0' + s.version = 'IOS_BUILD_VERSION' s.authors = 'PyTorch Team' s.license = { :type => 'BSD' } s.homepage = 'https://github.com/pytorch/pytorch' @@ -33,5 +33,5 @@ Pod::Spec.new do |s| 'VALID_ARCHS' => 'x86_64 arm64' } s.library = ['c++', 'stdc++'] - s.frameworks = 'Accelerate' + s.frameworks = 'Accelerate', 'MetalPerformanceShaders', 'CoreML' end diff --git a/ios/TestApp/benchmark/coreml_backend.py b/ios/TestApp/benchmark/coreml_backend.py index 140080b2e83..e192b8b2bd1 100644 --- a/ios/TestApp/benchmark/coreml_backend.py +++ b/ios/TestApp/benchmark/coreml_backend.py @@ -32,6 +32,7 @@ def main(): mlmodel = torch._C._jit_to_backend("coreml", model, compile_spec) print(mlmodel._c._get_method("forward").graph) mlmodel._save_for_lite_interpreter("../models/model_coreml.ptl") + torch.jit.save(mlmodel, "../models/model_coreml.pt") if __name__ == "__main__": diff --git a/ios/TestApp/benchmark/trace_model.py b/ios/TestApp/benchmark/trace_model.py index 39158f04498..d223ceea862 100644 --- a/ios/TestApp/benchmark/trace_model.py +++ b/ios/TestApp/benchmark/trace_model.py @@ -9,5 +9,5 @@ traced_script_module = torch.jit.trace(model, example) optimized_scripted_module = optimize_for_mobile(traced_script_module) torch.jit.save(optimized_scripted_module, "../models/model.pt") exported_optimized_scripted_module = ( - optimized_scripted_module._save_for_lite_interpreter("../models/model_lite.ptl") + optimized_scripted_module._save_for_lite_interpreter("../models/model.ptl") )