Skip to content

Commit

Permalink
Merge branch 'master' into fix-requirements-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
namannandan authored Feb 5, 2024
2 parents 62a82cf + fa0f1e3 commit 92908fd
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
project(torchserve_cpp VERSION 0.1)

set(CMAKE_CXX_STANDARD 17)
Expand Down
60 changes: 51 additions & 9 deletions cpp/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function install_folly() {
echo -e "${COLOR_GREEN}[ INFO ] Cloning folly repo ${COLOR_OFF}"
git clone https://github.com/facebook/folly.git "$FOLLY_SRC_DIR"
cd $FOLLY_SRC_DIR
git checkout tags/v2022.06.27.00
git checkout tags/v2024.01.29.00
fi

if [ ! -d "$FOLLY_BUILD_DIR" ] ; then
Expand Down Expand Up @@ -74,11 +74,21 @@ function install_kineto() {
}

function install_libtorch() {
if [ "$PLATFORM" = "Mac" ]; then
echo -e "${COLOR_GREEN}[ INFO ] Skip install libtorch on Mac ${COLOR_OFF}"
elif [ ! -d "$DEPS_DIR/libtorch" ] ; then
if [ ! -d "$DEPS_DIR/libtorch" ] ; then
cd "$DEPS_DIR" || exit
if [ "$PLATFORM" = "Linux" ]; then
if [ "$PLATFORM" = "Mac" ]; then
if [[ $(uname -m) == 'x86_64' ]]; then
echo -e "${COLOR_GREEN}[ INFO ] Install libtorch on Mac x86_64 ${COLOR_OFF}"
wget https://download.pytorch.org/libtorch/cpu/libtorch-macos-x86_64-2.2.0.zip
unzip libtorch-macos-x86_64-2.2.0.zip
rm libtorch-macos-x86_64-2.2.0.zip
else
echo -e "${COLOR_GREEN}[ INFO ] Install libtorch on Mac arm64 ${COLOR_OFF}"
wget https://download.pytorch.org/libtorch/cpu/libtorch-macos-arm64-2.2.0.zip
unzip libtorch-macos-arm64-2.2.0.zip
rm libtorch-macos-arm64-2.2.0.zip
fi
elif [ "$PLATFORM" = "Linux" ]; then
echo -e "${COLOR_GREEN}[ INFO ] Install libtorch on Linux ${COLOR_OFF}"
if [ "$CUDA" = "cu118" ]; then
wget https://download.pytorch.org/libtorch/cu118/libtorch-cxx11-abi-shared-with-deps-2.1.1%2Bcu118.zip
Expand Down Expand Up @@ -113,7 +123,7 @@ function install_yaml_cpp() {
echo -e "${COLOR_GREEN}[ INFO ] Cloning yaml-cpp repo ${COLOR_OFF}"
git clone https://github.com/jbeder/yaml-cpp.git "$YAML_CPP_SRC_DIR"
cd $YAML_CPP_SRC_DIR
git checkout tags/yaml-cpp-0.7.0
git checkout tags/0.8.0
fi

if [ ! -d "$YAML_CPP_BUILD_DIR" ] ; then
Expand All @@ -136,11 +146,42 @@ function install_yaml_cpp() {
cd "$BWD" || exit
}

function install_sentencepiece() {
SENTENCEPIECE_SRC_DIR=$BASE_DIR/third-party/sentencepiece
SENTENCEPIECE_BUILD_DIR=$DEPS_DIR/sentencepiece-build

if [ ! -d "$SENTENCEPIECE_SRC_DIR" ] ; then
echo -e "${COLOR_GREEN}[ INFO ] Cloning sentencepiece repo ${COLOR_OFF}"
git clone https://github.com/google/sentencepiece.git "$SENTENCEPIECE_SRC_DIR"
cd $SENTENCEPIECE_SRC_DIR
git checkout tags/v0.1.99
fi

if [ ! -d "$SENTENCEPIECE_BUILD_DIR" ] ; then
echo -e "${COLOR_GREEN}[ INFO ] Building sentencepiece ${COLOR_OFF}"

mkdir $SENTENCEPIECE_BUILD_DIR
cd $SENTENCEPIECE_BUILD_DIR
cmake $SENTENCEPIECE_SRC_DIR
make -i $(nproc)
if [ "$PLATFORM" = "Linux" ]; then
sudo make install
sudo ldconfig -v
elif [ "$PLATFORM" = "Mac" ]; then
make install
fi

echo -e "${COLOR_GREEN}[ INFO ] sentencepiece is installed ${COLOR_OFF}"
fi

cd "$BWD" || exit
}

function build_llama_cpp() {
BWD=$(pwd)
LLAMA_CPP_SRC_DIR=$BASE_DIR/third-party/llama.cpp
cd "${LLAMA_CPP_SRC_DIR}"
make
make LLAMA_METAL=OFF
cd "$BWD" || exit
}

Expand Down Expand Up @@ -191,7 +232,7 @@ function build() {
fi
elif [ "$PLATFORM" = "Mac" ]; then
cmake \
-DCMAKE_PREFIX_PATH="$(python -c 'import torch; print(torch.utils.cmake_prefix_path)');$DEPS_DIR;$FOLLY_CMAKE_DIR;$YAML_CPP_CMAKE_DIR" \
-DCMAKE_PREFIX_PATH="$DEPS_DIR;$FOLLY_CMAKE_DIR;$YAML_CPP_CMAKE_DIR;$DEPS_DIR/libtorch" \
-DCMAKE_INSTALL_PREFIX="$PREFIX" \
"$MAYBE_BUILD_QUIC" \
"$MAYBE_BUILD_TESTS" \
Expand Down Expand Up @@ -225,7 +266,7 @@ function build() {

function symlink_torch_libs() {
if [ "$PLATFORM" = "Linux" ]; then
ln -sf ${DEPS_DIR}/libtorch/lib/*.so* ${BUILD_DIR}/libs/
ln -sf ${DEPS_DIR}/libtorch/lib/*.so* ${LIBS_DIR}
fi
}

Expand Down Expand Up @@ -315,6 +356,7 @@ install_folly
install_kineto
install_libtorch
install_yaml_cpp
install_sentencepiece
build_llama_cpp
build
symlink_torch_libs
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/backends/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ list(APPEND BACKEND_SOURCE_FILES ${TS_BACKENDS_SRC_DIR}/handler/base_handler.cc)
list(APPEND BACKEND_SOURCE_FILES ${TS_BACKENDS_SRC_DIR}/handler/torch_scripted_handler.cc)
add_library(ts_backends_core SHARED ${BACKEND_SOURCE_FILES})
target_include_directories(ts_backends_core PUBLIC ${TS_BACKENDS_CORE_SRC_DIR})
target_link_libraries(ts_backends_core PUBLIC ts_utils ts_backends_protocol ${FOLLY_LIBRARIES})
target_link_libraries(ts_backends_core PUBLIC ts_utils ts_backends_protocol ${FOLLY_LIBRARIES} ${TORCH_LIBRARIES})
install(TARGETS ts_backends_core DESTINATION ${torchserve_cpp_SOURCE_DIR}/_build/libs)

# build exe model_worker_socket
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

add_subdirectory("../../../examples/cpp/babyllama/" "../../../test/resources/examples/babyllama/babyllama_handler/")
add_subdirectory("../../../examples/cpp/babyllama/" "${CMAKE_CURRENT_BINARY_DIR}/../../test/resources/examples/babyllama/babyllama_handler/")

add_subdirectory("../../../examples/cpp/llamacpp/" "../../../test/resources/examples/llamacpp/llamacpp_handler/")
add_subdirectory("../../../examples/cpp/llamacpp/" "${CMAKE_CURRENT_BINARY_DIR}/../../test/resources/examples/llamacpp/llamacpp_handler/")

add_subdirectory("../../../examples/cpp/mnist/" "../../../test/resources/examples/mnist/mnist_handler/")
add_subdirectory("../../../examples/cpp/mnist/" "${CMAKE_CURRENT_BINARY_DIR}/../../test/resources/examples/mnist/mnist_handler/")
2 changes: 1 addition & 1 deletion cpp/src/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ list(APPEND TS_UTILS_SOURCE_FILES ${TS_UTILS_SRC_DIR}/metrics/registry.cc)
add_library(ts_utils SHARED ${TS_UTILS_SOURCE_FILES})
target_include_directories(ts_utils PUBLIC ${TS_UTILS_SRC_DIR})
target_include_directories(ts_utils PRIVATE ${Boost_INCLUDE_DIRS})
target_link_libraries(ts_utils ${FOLLY_LIBRARIES} ${CMAKE_DL_LIBS} ${Boost_LIBRARIES} yaml-cpp)
target_link_libraries(ts_utils ${FOLLY_LIBRARIES} ${CMAKE_DL_LIBS} ${Boost_LIBRARIES} yaml-cpp::yaml-cpp)
install(TARGETS ts_utils DESTINATION ${torchserve_cpp_SOURCE_DIR}/_build/libs)

list(APPEND FOO_SOURCE_FILES ${TS_UTILS_SRC_DIR}/ifoo.hh)
Expand Down

0 comments on commit 92908fd

Please sign in to comment.