mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
[pytorch][mobile] change mobile build scripts to build PyTorch by default (#34203)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/34203 Currently cmake and mobile build scripts still build libcaffe2 by default. To build pytorch mobile users have to set environment variable BUILD_PYTORCH_MOBILE=1 or set cmake option BUILD_CAFFE2_MOBILE=OFF. PyTorch mobile has been released for a while. It's about time to change CMake and build scripts to build libtorch by default. Changed caffe2 CI job to build libcaffe2 by setting BUILD_CAFFE2_MOBILE=1 environment variable. Only found android CI for libcaffe2 - do we ever have iOS CI for libcaffe2? Test Plan: Imported from OSS Differential Revision: D20267274 Pulled By: ljk53 fbshipit-source-id: 9d997032a599c874d62fbcfc4f5d4fbf8323a12e
This commit is contained in:
committed by
Facebook Github Bot
parent
b50825e011
commit
9a5e9d8cec
@ -1522,7 +1522,6 @@ jobs:
|
||||
if [ -n "${SELECTED_OP_LIST}" ]; then
|
||||
export SELECTED_OP_LIST="${PROJ_ROOT}/ios/TestApp/custom_build/${SELECTED_OP_LIST}"
|
||||
fi
|
||||
export BUILD_PYTORCH_MOBILE=1
|
||||
export IOS_ARCH=${IOS_ARCH}
|
||||
export IOS_PLATFORM=${IOS_PLATFORM}
|
||||
unbuffer ${PROJ_ROOT}/scripts/build_ios.sh 2>&1 | ts
|
||||
|
@ -30,7 +30,6 @@ cat ${PROJ_ROOT}/scripts/build_ios.sh
|
||||
echo "########################################################"
|
||||
echo "IOS_ARCH: ${IOS_ARCH}"
|
||||
echo "IOS_PLATFORM: ${IOS_PLATFORM}"
|
||||
export BUILD_PYTORCH_MOBILE=1
|
||||
export IOS_ARCH=${IOS_ARCH}
|
||||
export IOS_PLATFORM=${IOS_PLATFORM}
|
||||
unbuffer ${PROJ_ROOT}/scripts/build_ios.sh 2>&1 | ts
|
||||
|
@ -443,7 +443,6 @@
|
||||
if [ -n "${SELECTED_OP_LIST}" ]; then
|
||||
export SELECTED_OP_LIST="${PROJ_ROOT}/ios/TestApp/custom_build/${SELECTED_OP_LIST}"
|
||||
fi
|
||||
export BUILD_PYTORCH_MOBILE=1
|
||||
export IOS_ARCH=${IOS_ARCH}
|
||||
export IOS_PLATFORM=${IOS_PLATFORM}
|
||||
unbuffer ${PROJ_ROOT}/scripts/build_ios.sh 2>&1 | ts
|
||||
|
@ -104,7 +104,7 @@ if [[ "${BUILD_ENVIRONMENT}" == *-android* ]]; then
|
||||
build_args+=("BUILD_TEST=ON")
|
||||
build_args+=("USE_OBSERVERS=ON")
|
||||
build_args+=("USE_ZSTD=ON")
|
||||
"${ROOT_DIR}/scripts/build_android.sh" $(build_to_cmake ${build_args[@]}) "$@"
|
||||
BUILD_CAFFE2_MOBILE=1 "${ROOT_DIR}/scripts/build_android.sh" $(build_to_cmake ${build_args[@]}) "$@"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
@ -105,7 +105,6 @@ if [[ "${BUILD_ENVIRONMENT}" == *-android* ]]; then
|
||||
elif [[ "${BUILD_ENVIRONMENT}" == *-x86_64* ]]; then
|
||||
build_args+=("-DANDROID_ABI=x86_64")
|
||||
fi
|
||||
export BUILD_PYTORCH_MOBILE=1
|
||||
exec ./scripts/build_android.sh "${build_args[@]}" "$@"
|
||||
fi
|
||||
|
||||
|
@ -121,7 +121,7 @@ option(BUILD_CUSTOM_PROTOBUF "Build and use Caffe2's own protobuf under third_pa
|
||||
option(BUILD_PYTHON "Build Python binaries" ON)
|
||||
option(BUILD_CAFFE2_OPS "Build Caffe2 operators" ON)
|
||||
option(BUILD_SHARED_LIBS "Build libcaffe2.so" ON)
|
||||
option(BUILD_CAFFE2_MOBILE "Build libcaffe2 for mobile (deprecating)" ON)
|
||||
option(BUILD_CAFFE2_MOBILE "Build libcaffe2 for mobile (deprecating)" OFF)
|
||||
option(USE_STATIC_DISPATCH "Use static dispatch for ATen operators" OFF)
|
||||
cmake_dependent_option(
|
||||
CAFFE2_LINK_LOCAL_PROTOBUF "If set, build protobuf inside libcaffe2.so." ON
|
||||
|
@ -62,7 +62,7 @@ mkdir -p $OUT_DIR
|
||||
pushd $PYTORCH_DIR
|
||||
python $PYTORCH_DIR/setup.py clean
|
||||
|
||||
ANDROID_ABI=$abi BUILD_PYTORCH_MOBILE=1 VERBOSE=1 ANDROID_DEBUG_SYMBOLS=1 $PYTORCH_DIR/scripts/build_android.sh -DANDROID_CCACHE=$(which ccache)
|
||||
ANDROID_ABI=$abi VERBOSE=1 ANDROID_DEBUG_SYMBOLS=1 $PYTORCH_DIR/scripts/build_android.sh -DANDROID_CCACHE=$(which ccache)
|
||||
|
||||
cp -R $PYTORCH_DIR/build_android/install/lib $OUT_DIR/
|
||||
cp -R $PYTORCH_DIR/build_android/install/include $OUT_DIR/
|
||||
@ -97,4 +97,3 @@ find $PYTORCH_ANDROID_DIR -type f -name *apk
|
||||
find $PYTORCH_ANDROID_DIR -type f -name *apk | xargs echo "To install apk run: $ANDROID_HOME/platform-tools/adb install -r "
|
||||
|
||||
popd
|
||||
|
||||
|
@ -485,7 +485,7 @@ if (NOT INTERN_BUILD_MOBILE OR NOT BUILD_CAFFE2_MOBILE)
|
||||
${TORCH_SRC_DIR}/csrc/jit/mobile/type_parser.cpp
|
||||
)
|
||||
|
||||
if (NOT INTERN_DISABLE_MOBILE_INTERP AND BUILD_CAFFE2_MOBILE)
|
||||
if (NOT INTERN_DISABLE_MOBILE_INTERP)
|
||||
set (MOBILE_SRCS
|
||||
${TORCH_SRC_DIR}/csrc/jit/mobile/function.cpp
|
||||
${TORCH_SRC_DIR}/csrc/jit/mobile/import.cpp
|
||||
|
@ -22,7 +22,7 @@ For simulator build, we run unit tests as the last step of our CI workflow. Thos
|
||||
|
||||
The benchmark folder contains two scripts that help you setup the benchmark project. The `setup.rb` does the heavy-lifting jobs of setting up the XCode project, whereas the `trace_model.py` is a Python script that you can tweak to generate your model for benchmarking. Simply follow the steps below to setup the project
|
||||
|
||||
1. In the PyTorch root directory, run `BUILD_PYTORCH_MOBILE=1 IOS_ARCH=arm64 ./scripts/build_ios.sh` to generate the custom build from **Master** branch
|
||||
1. In the PyTorch root directory, run `IOS_ARCH=arm64 ./scripts/build_ios.sh` to generate the custom build from **Master** branch
|
||||
2. Navigate to the `benchmark` folder, run `python trace_model.py` to generate your model.
|
||||
3. In the same directory, open `config.json`. Those are the input parameters you can tweak.
|
||||
4. Again, in the same directory, run `ruby setup.rb` to setup the XCode project.
|
||||
@ -47,6 +47,3 @@ To run the script, simply type the command below and make sure your phone is con
|
||||
Open the app on your device, the benchmark result will be displayed on the screen.
|
||||
|
||||
> Note This requires ios-deploy to be installed. Please have a look at [ios-deploy](https://github.com/ios-control/ios-deploy). To quickly install it, use `npm -g i ios-deploy`
|
||||
|
||||
|
||||
|
||||
|
@ -55,8 +55,8 @@ cd $BUILD_ROOT
|
||||
|
||||
CMAKE_ARGS=()
|
||||
|
||||
if [ -n "${BUILD_PYTORCH_MOBILE:-}" ]; then
|
||||
CMAKE_ARGS+=("-DBUILD_CAFFE2_MOBILE=OFF")
|
||||
if [ -z "${BUILD_CAFFE2_MOBILE:-}" ]; then
|
||||
# Build PyTorch mobile
|
||||
CMAKE_ARGS+=("-DUSE_STATIC_DISPATCH=ON")
|
||||
CMAKE_ARGS+=("-DCMAKE_PREFIX_PATH=$(python -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')")
|
||||
CMAKE_ARGS+=("-DPYTHON_EXECUTABLE=$(python -c 'import sys; print(sys.executable)')")
|
||||
@ -66,6 +66,8 @@ if [ -n "${BUILD_PYTORCH_MOBILE:-}" ]; then
|
||||
CMAKE_ARGS+=("-DSELECTED_OP_LIST=${SELECTED_OP_LIST}")
|
||||
fi
|
||||
else
|
||||
# Build Caffe2 mobile
|
||||
CMAKE_ARGS+=("-DBUILD_CAFFE2_MOBILE=ON")
|
||||
# Build protobuf from third_party so we have a host protoc binary.
|
||||
echo "Building protoc"
|
||||
$CAFFE2_ROOT/scripts/build_host_protoc.sh
|
||||
|
@ -17,8 +17,8 @@ cd $BUILD_ROOT
|
||||
|
||||
CMAKE_ARGS=()
|
||||
|
||||
if [ -n "${BUILD_PYTORCH_MOBILE:-}" ]; then
|
||||
CMAKE_ARGS+=("-DBUILD_CAFFE2_MOBILE=OFF")
|
||||
if [ -z "${BUILD_CAFFE2_MOBILE:-}" ]; then
|
||||
# Build PyTorch mobile
|
||||
CMAKE_ARGS+=("-DUSE_STATIC_DISPATCH=ON")
|
||||
CMAKE_ARGS+=("-DCMAKE_PREFIX_PATH=$(python -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')")
|
||||
CMAKE_ARGS+=("-DPYTHON_EXECUTABLE=$(python -c 'import sys; print(sys.executable)')")
|
||||
@ -33,6 +33,8 @@ if [ -n "${BUILD_PYTORCH_MOBILE:-}" ]; then
|
||||
CMAKE_ARGS+=("-DCMAKE_CXX_FLAGS=-fembed-bitcode")
|
||||
fi
|
||||
else
|
||||
# Build Caffe2 mobile
|
||||
CMAKE_ARGS+=("-DBUILD_CAFFE2_MOBILE=ON")
|
||||
# Build protobuf from third_party so we have a host protoc binary.
|
||||
echo "Building protoc"
|
||||
BITCODE_FLAGS="-DCMAKE_C_FLAGS=-fembed-bitcode -DCMAKE_CXX_FLAGS=-fembed-bitcode "
|
||||
|
@ -21,7 +21,6 @@ mkdir -p $BUILD_ROOT
|
||||
cd $BUILD_ROOT
|
||||
|
||||
CMAKE_ARGS=()
|
||||
CMAKE_ARGS+=("-DBUILD_CAFFE2_MOBILE=OFF")
|
||||
CMAKE_ARGS+=("-DUSE_STATIC_DISPATCH=ON")
|
||||
CMAKE_ARGS+=("-DCMAKE_PREFIX_PATH=$(python -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')")
|
||||
CMAKE_ARGS+=("-DPYTHON_EXECUTABLE=$(python -c 'import sys; print(sys.executable)')")
|
||||
|
@ -71,7 +71,7 @@ mkdir -p $OUT_DIR
|
||||
pushd $PYTORCH_DIR
|
||||
python $PYTORCH_DIR/setup.py clean
|
||||
|
||||
ANDROID_ABI=$abi BUILD_PYTORCH_MOBILE=1 $PYTORCH_DIR/scripts/build_android.sh -DANDROID_CCACHE=$(which ccache)
|
||||
ANDROID_ABI=$abi $PYTORCH_DIR/scripts/build_android.sh -DANDROID_CCACHE=$(which ccache)
|
||||
|
||||
cp -R $PYTORCH_DIR/build_android/install/lib $OUT_DIR/
|
||||
cp -R $PYTORCH_DIR/build_android/install/include $OUT_DIR/
|
||||
@ -103,4 +103,3 @@ fi
|
||||
|
||||
find $PYTORCH_ANDROID_DIR -type f -name *aar | xargs ls -lah
|
||||
popd
|
||||
|
||||
|
Reference in New Issue
Block a user