mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-21 05:34:18 +08:00
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/40199 Mobile custom selective build has already been covered by `test/mobile/custom_build/build.sh`. It builds a CLI binary with host-toolchain and runs on host machine to check correctness of the result. But that custom build test doesn't cover the android/gradle build part. And we cannot use it to measure and track the in-APK size of custom build library. So this PR adds the selective build test coverage for android NDK build. Also integrate with the CI to upload the custom build size to scuba. TODO: Ideally it should build android/test_app and measure the in-APK size. But the test_app hasn't been covered by any CI yet and is currently broken, so build & measure AAR instead (which can be inaccurate as we plan to pack C++ header files into AAR soon). Sample result: https://fburl.com/scuba/pytorch_binary_size/skxwb1gh ``` +---------------------+-------------+-------------------+-----------+----------+ | build_mode | arch | lib | Build Num | Size | +---------------------+-------------+-------------------+-----------+----------+ | custom-build-single | armeabi-v7a | libpytorch_jni.so | 5901579 | 3.68 MiB | | prebuild | armeabi-v7a | libpytorch_jni.so | 5901014 | 6.23 MiB | | prebuild | x86_64 | libpytorch_jni.so | 5901014 | 7.67 MiB | +---------------------+-------------+-------------------+-----------+----------+ ``` Test Plan: Imported from OSS Differential Revision: D22111115 Pulled By: ljk53 fbshipit-source-id: 11d24efbc49a85f851ecd0e481d14123f405b3a9
33 lines
1.1 KiB
Bash
Executable File
33 lines
1.1 KiB
Bash
Executable File
#!/bin/bash
|
|
###############################################################################
|
|
# This script tests the custom selective build flow for PyTorch Android, which
|
|
# optimizes library size by only including ops used by a specific model.
|
|
###############################################################################
|
|
|
|
set -eux
|
|
|
|
PYTORCH_DIR="$(cd $(dirname $0)/..; pwd -P)"
|
|
PYTORCH_ANDROID_DIR="${PYTORCH_DIR}/android"
|
|
BUILD_ROOT="${PYTORCH_DIR}/build_pytorch_android_custom"
|
|
|
|
source "${PYTORCH_ANDROID_DIR}/common.sh"
|
|
|
|
prepare_model_and_dump_root_ops() {
|
|
cd "${BUILD_ROOT}"
|
|
MODEL="${BUILD_ROOT}/MobileNetV2.pt"
|
|
ROOT_OPS="${BUILD_ROOT}/MobileNetV2.yaml"
|
|
python "${PYTORCH_ANDROID_DIR}/test_app/make_assets_custom.py"
|
|
cp "${MODEL}" "${PYTORCH_ANDROID_DIR}/test_app/app/src/main/assets/mobilenet2.pt"
|
|
}
|
|
|
|
# Start building
|
|
mkdir -p "${BUILD_ROOT}"
|
|
check_android_sdk
|
|
check_gradle
|
|
parse_abis_list "$@"
|
|
prepare_model_and_dump_root_ops
|
|
SELECTED_OP_LIST="${ROOT_OPS}" build_android
|
|
|
|
# TODO: change this to build test_app instead
|
|
$GRADLE_PATH -PABI_FILTERS=$ABIS_LIST -p $PYTORCH_ANDROID_DIR clean assembleRelease
|