Skip to content

Instantly share code, notes, and snippets.

@stefanondisponibile
Created October 29, 2019 20:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stefanondisponibile/a3d9388b146db82a70fb80b391b6e3c7 to your computer and use it in GitHub Desktop.
Save stefanondisponibile/a3d9388b146db82a70fb80b391b6e3c7 to your computer and use it in GitHub Desktop.
Build TensorFlow Serving with Sentencepiece custom ops.
#!/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