-
-
Save Mistobaan/dfeb9ace90cb1ff165742175869e17ac to your computer and use it in GitHub Desktop.
Build TensorFlow Serving with Sentencepiece custom ops.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
CWD=$(pwd) | |
GPROTOBUF_URL=https://github.com/protocolbuffers/protobuf/releases/download/v3.7.0/protobuf-cpp-3.7.0.tar.gz | |
compile_gprotobuf () { | |
sudo apt-get install autoconf automake libtool curl make g++ unzip && | |
wget $GPROTOBUF_URL && | |
fname=protobuf-cpp-3.7.0.tar.gz && | |
tar xvzf $fname && rm $fname && | |
cd protobuf-3.7.0 && | |
./configure CXXFLAGS="-D_GLIBCXX_USE_CXX11_ABI=0" && | |
make && | |
make check && | |
sudo make install && | |
sudo ldconfig # refresh shared library cache. | |
cd $CWD | |
} | |
build_tensorflow_serving_and_sentencepiece () { | |
git clone -b 'r1.14' --single-branch --depth 1 https://github.com/tensorflow/serving.git && | |
mkdir -p serving/tensorflow_serving/custom_ops/sentencepiece_processor && | |
git clone https://github.com/google/sentencepiece.git serving/tensorflow_serving/custom_ops/sentencepiece_processor/sentencepiece && | |
sudo apt-get install cmake build-essential pkg-config libgoogle-perftools-dev && | |
cd serving/tensorflow_serving/custom_ops/sentencepiece_processor/sentencepiece && | |
mkdir build && | |
cd build && | |
cmake -DSPM_USE_BUILTIN_PROTOBUF=OFF -DSPM_ENABLE_TENSORFLOW_SHARED=ON .. && | |
make -j $(nproc) && | |
sudo make install && | |
sudo ldconfig -v && | |
cd $CWD && | |
cp ./BUILD ./serving/tensorflow_serving/custom_ops/sentencepiece_processor/BUILD && | |
sed -i.bak '/@org_tensorflow\/\/tensorflow\/contrib:contrib_ops_op_lib/a\ "\/\/tensorflow_serving\/custom_ops\/sentencepiece_processor:sentencepiece_processor_ops",' ./serving/tensorflow_serving/model_servers/BUILD && | |
sed -i '/name = "tensorflow_model_server",/a\ linkopts = ["-Wl,--allow-multiple-definition", "-Wl,-rpath,/usr/lib"],' ./serving/tensorflow_serving/model_servers/BUILD | |
cd serving && tools/run_in_docker.sh bazel build tensorflow_serving/model_servers:tensorflow_model_server | |
} | |
main () { | |
echo "Workdir: ${CWD}" | |
compile_gprotobuf | |
build_tensorflow_serving_and_sentencepiece | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment