diff --git a/cmake/onnxruntime_python.cmake b/cmake/onnxruntime_python.cmake index e20c23d19a..986c493398 100644 --- a/cmake/onnxruntime_python.cmake +++ b/cmake/onnxruntime_python.cmake @@ -157,19 +157,21 @@ if (onnxruntime_ENABLE_EAGER_MODE OR onnxruntime_ENABLE_LAZY_TENSOR) "${REPO_ROOT}/cmake/external/protobuf/src" ${TORCH_INCLUDE_DIRS}) - if (onnxruntime_ENABLE_EAGER_MODE) - # For eager mode, torch build has a mkl dependency from torch's cmake config, - # Linking to torch libraries to avoid this unnecessary mkl dependency. - target_include_directories(onnxruntime_pybind11_state PRIVATE "${TORCH_INSTALL_PREFIX}/include" "${TORCH_INSTALL_PREFIX}/include/torch/csrc/api/include") - find_library(LIBTORCH_LIBRARY torch PATHS "${TORCH_INSTALL_PREFIX}/lib") - find_library(LIBTORCH_CPU_LIBRARY torch_cpu PATHS "${TORCH_INSTALL_PREFIX}/lib") - find_library(LIBC10_LIBRARY c10 PATHS "${TORCH_INSTALL_PREFIX}/lib") - target_link_libraries(onnxruntime_pybind11_state PRIVATE ${LIBTORCH_LIBRARY} ${LIBTORCH_CPU_LIBRARY} ${LIBC10_LIBRARY}) - endif() - + # For eager mode, torch build has a mkl dependency from torch's cmake config, + # Linking to torch libraries to avoid this unnecessary mkl dependency. + target_include_directories(onnxruntime_pybind11_state PRIVATE "${TORCH_INSTALL_PREFIX}/include" "${TORCH_INSTALL_PREFIX}/include/torch/csrc/api/include") + find_library(LIBTORCH_LIBRARY torch PATHS "${TORCH_INSTALL_PREFIX}/lib") + find_library(LIBTORCH_CPU_LIBRARY torch_cpu PATHS "${TORCH_INSTALL_PREFIX}/lib") + find_library(LIBC10_LIBRARY c10 PATHS "${TORCH_INSTALL_PREFIX}/lib") # Explicitly link torch_python to workaround https://github.com/pytorch/pytorch/issues/38122#issuecomment-694203281 find_library(TORCH_PYTHON_LIBRARY torch_python PATHS "${TORCH_INSTALL_PREFIX}/lib") - target_link_libraries(onnxruntime_pybind11_state PRIVATE ${TORCH_PYTHON_LIBRARY}) + target_link_libraries(onnxruntime_pybind11_state PRIVATE ${LIBTORCH_LIBRARY} ${LIBTORCH_CPU_LIBRARY} ${LIBC10_LIBRARY} ${TORCH_PYTHON_LIBRARY}) + if (onnxruntime_USE_CUDA) + find_library(LIBTORCH_CUDA_LIBRARY torch_cuda PATHS "${TORCH_INSTALL_PREFIX}/lib") + find_library(LIBC10_CUDA_LIBRARY c10_cuda PATHS "${TORCH_INSTALL_PREFIX}/lib") + target_link_libraries(onnxruntime_pybind11_state PRIVATE ${LIBTORCH_CUDA_LIBRARY} ${LIBC10_CUDA_LIBRARY}) + endif() + if (onnxruntime_ENABLE_EAGER_MODE) target_link_libraries(onnxruntime_pybind11_state PRIVATE onnxruntime_eager) endif() diff --git a/orttraining/orttraining/lazy_tensor/accelerator.cc b/orttraining/orttraining/lazy_tensor/accelerator.cc index 68ccc47a71..f7ecbd000d 100644 --- a/orttraining/orttraining/lazy_tensor/accelerator.cc +++ b/orttraining/orttraining/lazy_tensor/accelerator.cc @@ -10,8 +10,7 @@ #include #include // Pytorch. -#include -#include +#include #include // ORT friends. #include "core/common/logging/sinks/clog_sink.h" diff --git a/tools/ci_build/github/linux/docker/scripts/manylinux/install_deps_lort.sh b/tools/ci_build/github/linux/docker/scripts/manylinux/install_deps_lort.sh index 9274b1e827..0ff5547793 100755 --- a/tools/ci_build/github/linux/docker/scripts/manylinux/install_deps_lort.sh +++ b/tools/ci_build/github/linux/docker/scripts/manylinux/install_deps_lort.sh @@ -94,17 +94,8 @@ echo "Installing Pytorch requirements" /opt/python/cp39-cp39/bin/python3.9 -m pip install -r requirements.txt /opt/python/cp39-cp39/bin/python3.9 -m pip install flatbuffers cerberus h5py onnx echo "Building and installing Pytorch" -VERBOSE=1 BUILD_LAZY_TS_BACKEND=1 /opt/python/cp39-cp39/bin/python3.9 setup.py develop -/opt/python/cp39-cp39/bin/python3.9 -c "import torch; print(f'Installed Pytorch: {torch.__version__}')" - -echo "Installing valgrind" -cd /tmp/src -GetFile 'https://sourceware.org/pub/valgrind/valgrind-3.16.1.tar.bz2' /tmp/src/valgrind-3.16.1.tar.bz2 -tar -jxvf valgrind-3.16.1.tar.bz2 -cd valgrind-3.16.1 -./configure --prefix=/usr --libdir=/usr/lib64 --enable-only64bit --enable-tls -make -j$(getconf _NPROCESSORS_ONLN) -make install +VERBOSE=1 BUILD_LAZY_TS_BACKEND=1 /opt/python/cp39-cp39/bin/python3.9 setup.py install +cd ~ && /opt/python/cp39-cp39/bin/python3.9 -c "import torch; print(f'Installed Pytorch: {torch.__version__}')" cd / rm -rf /tmp/src