mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 12:54:11 +08:00
[Mobile] Update build_mobile.sh to allow lite interpreter and tracing based builds (#84647)
Summary: Currently, build_mobile.sh doesn't allow lite interpreter builds or tracing based selective builds. build_mobile.sh is used for host builds of PyTorch for Mobile deployment. Additionally, certain flags such as `USE_BLAS` were not being respected as they should be. This change addresses that as well. Test Plan: Build using: ``` cat /tmp/selected_ops.yaml - aten::add - aten::sub ``` ``` BUILD_PYTORCH_MOBILE_WITH_HOST_TOOLCHAIN=1 USE_LIGHTWEIGHT_DISPATCH=0 BUILD_LITE_INTERPRETER=1 SELECTED_OP_LIST=/tmp/selected_ops.yaml ./scripts/build_mobile.sh ``` ``` cat /tmp/main.cpp int main() { auto m = torch::jit::_load_for_mobile("/tmp/path_to_model.ptl"); auto res = m.forward({}); return 0; } ``` Test using: ``` g++ /tmp/main.cpp -L build_mobile/lib/ -I build_mobile/install/include/ -lpthread -lc10 -ltorch_cpu -ltorch -lXNNPACK -lpytorch_qnnpack -lcpuinfo -lclog -lpthreadpool -lgloo -lkineto -lfmt -ldl -lc10 ``` Reviewers: Subscribers: Tasks: Tags: Pull Request resolved: https://github.com/pytorch/pytorch/pull/84647 Approved by: https://github.com/JacobSzwejbka, https://github.com/cccclai
This commit is contained in:
committed by
PyTorch MergeBot
parent
27e5299ee3
commit
747f27a9ad
@ -590,6 +590,10 @@ endif()
|
||||
# INTERN_BUILD_ATEN_OPS is used to control whether to build ATen/TH operators.
|
||||
set(INTERN_BUILD_ATEN_OPS ON)
|
||||
|
||||
if(NOT DEFINED USE_BLAS)
|
||||
set(USE_BLAS ON)
|
||||
endif()
|
||||
|
||||
# Build libtorch mobile library, which contains ATen/TH ops and native support for
|
||||
# TorchScript model, but doesn't contain not-yet-unified caffe2 ops;
|
||||
if(INTERN_BUILD_MOBILE)
|
||||
@ -608,7 +612,11 @@ if(INTERN_BUILD_MOBILE)
|
||||
set(USE_FBGEMM OFF)
|
||||
set(USE_QNNPACK OFF)
|
||||
set(INTERN_DISABLE_ONNX ON)
|
||||
set(INTERN_USE_EIGEN_BLAS ON)
|
||||
if(USE_BLAS)
|
||||
set(INTERN_USE_EIGEN_BLAS ON)
|
||||
else()
|
||||
set(INTERN_USE_EIGEN_BLAS OFF)
|
||||
endif()
|
||||
# Disable developing mobile interpreter for actual mobile build.
|
||||
# Enable it elsewhere to capture build error.
|
||||
set(INTERN_DISABLE_MOBILE_INTERP ON)
|
||||
|
@ -19,6 +19,7 @@ CMAKE_ARGS+=("-DCMAKE_PREFIX_PATH=$(python -c 'import sysconfig; print(sysconfig
|
||||
CMAKE_ARGS+=("-DPYTHON_EXECUTABLE=$(python -c 'import sys; print(sys.executable)')")
|
||||
CMAKE_ARGS+=("-DBUILD_CUSTOM_PROTOBUF=OFF")
|
||||
CMAKE_ARGS+=("-DBUILD_SHARED_LIBS=OFF")
|
||||
|
||||
# custom build with selected ops
|
||||
if [ -n "${SELECTED_OP_LIST}" ]; then
|
||||
SELECTED_OP_LIST="$(cd $(dirname $SELECTED_OP_LIST); pwd -P)/$(basename $SELECTED_OP_LIST)"
|
||||
@ -35,6 +36,32 @@ if [ -x "$(command -v ninja)" ]; then
|
||||
CMAKE_ARGS+=("-GNinja")
|
||||
fi
|
||||
|
||||
# Don't build artifacts we don't need
|
||||
CMAKE_ARGS+=("-DBUILD_TEST=OFF")
|
||||
CMAKE_ARGS+=("-DBUILD_BINARY=OFF")
|
||||
|
||||
# If there exists env variable and it equals to 1, build lite interpreter.
|
||||
# Default behavior is to build full jit interpreter.
|
||||
# cmd: BUILD_LITE_INTERPRETER=1 ./scripts/build_mobile.sh
|
||||
if [ "x${BUILD_LITE_INTERPRETER}" == "x1" ]; then
|
||||
CMAKE_ARGS+=("-DBUILD_LITE_INTERPRETER=ON")
|
||||
else
|
||||
CMAKE_ARGS+=("-DBUILD_LITE_INTERPRETER=OFF")
|
||||
fi
|
||||
if [ "x${TRACING_BASED}" == "x1" ]; then
|
||||
CMAKE_ARGS+=("-DTRACING_BASED=ON")
|
||||
else
|
||||
CMAKE_ARGS+=("-DTRACING_BASED=OFF")
|
||||
fi
|
||||
|
||||
# Lightweight dispatch bypasses the PyTorch Dispatcher.
|
||||
if [ "${USE_LIGHTWEIGHT_DISPATCH}" == 1 ]; then
|
||||
CMAKE_ARGS+=("-DUSE_LIGHTWEIGHT_DISPATCH=ON")
|
||||
CMAKE_ARGS+=("-DSTATIC_DISPATCH_BACKEND=CPU")
|
||||
else
|
||||
CMAKE_ARGS+=("-DUSE_LIGHTWEIGHT_DISPATCH=OFF")
|
||||
fi
|
||||
|
||||
# Disable unused dependencies
|
||||
CMAKE_ARGS+=("-DUSE_ROCM=OFF")
|
||||
CMAKE_ARGS+=("-DUSE_CUDA=OFF")
|
||||
@ -45,6 +72,10 @@ CMAKE_ARGS+=("-DUSE_LMDB=OFF")
|
||||
CMAKE_ARGS+=("-DUSE_LEVELDB=OFF")
|
||||
CMAKE_ARGS+=("-DUSE_MPI=OFF")
|
||||
CMAKE_ARGS+=("-DUSE_OPENMP=OFF")
|
||||
CMAKE_ARGS+=("-DUSE_MKLDNN=OFF")
|
||||
CMAKE_ARGS+=("-DUSE_NNPACK=OFF")
|
||||
CMAKE_ARGS+=("-DUSE_NUMPY=OFF")
|
||||
CMAKE_ARGS+=("-DUSE_BLAS=OFF")
|
||||
|
||||
# Only toggle if VERBOSE=1
|
||||
if [ "${VERBOSE:-}" == '1' ]; then
|
||||
|
Reference in New Issue
Block a user