Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Migrate serving tutorial to TorchScript #1310

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 43 additions & 57 deletions demo/predictor_service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,71 +1,59 @@
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved

FROM ubuntu:16.04
FROM ubuntu:18.04

# Install Caffe2 + dependencies
# Install dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
ca-certificates \
cmake \
curl \
git \
libgoogle-glog-dev \
libgtest-dev \
libiomp-dev \
libleveldb-dev \
liblmdb-dev \
libopencv-dev \
libopenmpi-dev \
libsnappy-dev \
openmpi-bin \
openmpi-doc \
python-dev \
python-pip
RUN pip install --upgrade pip
RUN pip install setuptools wheel
RUN pip install future numpy protobuf typing hypothesis pyyaml
RUN apt-get install -y --no-install-recommends \
libgflags-dev \
cmake
RUN git clone https://github.com/pytorch/pytorch.git
WORKDIR pytorch
RUN git submodule update --init --recursive
RUN python setup.py install
libcurl4-openssl-dev \
libgflags-dev \
unzip

# Install Thrift + dependencies
WORKDIR /
RUN apt-get update && apt-get install -y \
libboost-dev \
libboost-test-dev \
libboost-program-options-dev \
libboost-filesystem-dev \
libboost-thread-dev \
libevent-dev \
automake \
libtool \
curl \
flex \
bison \
pkg-config \
libssl-dev
RUN curl https://www-us.apache.org/dist/thrift/0.11.0/thrift-0.11.0.tar.gz --output thrift-0.11.0.tar.gz
RUN tar -xvf thrift-0.11.0.tar.gz
WORKDIR thrift-0.11.0
RUN ./bootstrap.sh
RUN ./configure
RUN make
RUN make install

# Install Pistache (REST framework)
libboost-dev \
libboost-test-dev \
libboost-program-options-dev \
libboost-filesystem-dev \
libboost-thread-dev \
libevent-dev \
automake \
libtool \
flex \
bison \
pkg-config \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*
RUN curl https://downloads.apache.org/thrift/0.13.0/thrift-0.13.0.tar.gz --output thrift-0.13.0.tar.gz \
&& tar -xvf thrift-0.13.0.tar.gz \
&& rm thrift-0.13.0.tar.gz
WORKDIR /thrift-0.13.0
RUN ./bootstrap.sh \
&& ./configure \
&& make \
&& make install

# Install Pistache (C++ REST framework)
WORKDIR /
RUN git clone https://github.com/oktal/pistache.git
WORKDIR /pistache
RUN git submodule update --init
RUN mkdir build
RUN git submodule update --init \
&& mkdir build
WORKDIR /pistache/build
RUN cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release ..
RUN make
RUN make install
RUN cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release .. \
&& make \
&& make install

# Install libcurl
RUN apt-get install -y libcurl4-openssl-dev
# Install libtorch
WORKDIR /
RUN curl https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-1.4.0%2Bcpu.zip --output libtorch.zip \
&& unzip libtorch.zip \
&& rm libtorch.zip

# Copy local files to /app
COPY . /app
Expand All @@ -76,10 +64,8 @@ RUN thrift -r --gen cpp predictor.thrift
RUN make

# Add library search paths
RUN echo '/pytorch/build/lib/' >> /etc/ld.so.conf.d/local.conf
RUN echo '/usr/local/lib/' >> /etc/ld.so.conf.d/local.conf
RUN ldconfig
ENV LD_LIBRARY_PATH /libtorch/lib:/usr/local/lib

# Open ports
# Expose ports for Thrift and REST
EXPOSE 9090
EXPOSE 8080
11 changes: 5 additions & 6 deletions demo/predictor_service/Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved

CPPFLAGS += -g -std=c++11 -std=c++14 \
-I./gen-cpp \
-I/pytorch -I/pytorch/build \
-I/pytorch/aten/src/ \
-I/pytorch/third_party/protobuf/src/
-I./gen-cpp \
-I/libtorch/include \
-Wno-deprecated-declarations
CLIENT_LDFLAGS += -lthrift
SERVER_LDFLAGS += -L/pytorch/build/lib \
-lthrift -lpistache -lpthread -lcaffe2 -lprotobuf -lc10 -lcurl
SERVER_LDFLAGS += -L/libtorch/lib \
-lthrift -lpistache -lpthread -ltorch -lc10 -lcurl -lgflags

server: server.o gen-cpp/Predictor.o
g++ $^ $(SERVER_LDFLAGS) -o $@
Expand Down
4 changes: 2 additions & 2 deletions demo/predictor_service/predictor.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
namespace cpp predictor_service

service Predictor {
// Returns list of scores for each label
map<string,list<double>> predict(1:string doc),
// Returns scores for each class
map<string,double> predict(1:string doc),
}
Loading