Skip to content

Commit

Permalink
Enable tensorflow for content detection in a production build (#2695)
Browse files Browse the repository at this point in the history
* Enable tensorflow installation and build

* Enable tensorflow in linux build

* Enable tensorflow installation and build

* Set base image with proper CUDA and CuDNN versions for amd64 build

* Remove sudo in TF install

* Install TF to /compiled/

* Install TF to /compiled/

* Install curl

* Remove sudo

* Cleanup

* Cleanup

* cleanup dockerfile

* cleanup dockerfile

* remove experimental flag check for tensorflow

* Move BUILD_TAGS arg lower to not invalidate the cache
  • Loading branch information
cyberj0g committed Jan 4, 2023
1 parent e2c46a1 commit 82e40f9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ jobs:

- name: Install ffmpeg
if: steps.cache-ffmpeg.outputs.cache-hit != 'true'
run: BUILD_TAGS=experimental ./install_ffmpeg.sh
run: ./install_ffmpeg.sh

- name: Build binaries
run: |
Expand Down
24 changes: 12 additions & 12 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ RUN update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-12 3
RUN GRPC_HEALTH_PROBE_VERSION=v0.3.6 \
&& curl -fsSL https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-${TARGETARCH} -o /usr/bin/grpc_health_probe \
&& chmod +x /usr/bin/grpc_health_probe \
&& curl -fsSL https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-2.8.0.tar.gz | tar -C /usr/local -xzf - \
&& ldconfig /usr/local/lib

# note: for runtime, Tensorflow version needs to be compatible with CUDA and CuDNN of the image
RUN LIBTENSORFLOW_VERSION=2.6.3 \
&& curl -LO https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-${LIBTENSORFLOW_VERSION}.tar.gz \
&& mkdir /tf && tar -C /tf -xzf libtensorflow-gpu-linux-x86_64-${LIBTENSORFLOW_VERSION}.tar.gz

ENV GOPATH=/go \
GO_BUILD_DIR=/build/ \
GOFLAGS="-mod=readonly"
Expand All @@ -41,7 +45,10 @@ RUN mkdir -p /go \

COPY ./install_ffmpeg.sh ./install_ffmpeg.sh

RUN ./install_ffmpeg.sh \
ARG BUILD_TAGS
ENV BUILD_TAGS=${BUILD_TAGS}

RUN ./install_ffmpeg.sh \
&& GO111MODULE=on go get -v github.com/golangci/golangci-lint/cmd/[email protected] \
&& go get -v github.com/jstemmer/go-junit-report

Expand All @@ -51,24 +58,17 @@ RUN go mod download

COPY . .

ARG BUILD_TAGS
ENV BUILD_TAGS=${BUILD_TAGS}

RUN make livepeer livepeer_cli livepeer_bench livepeer_router

FROM --platform=$TARGETPLATFORM nvidia/cuda:10.1-cudnn7-runtime AS livepeer-amd64-base

FROM --platform=$TARGETPLATFORM nvidia/cuda:11.6.2-cudnn8-runtime-ubuntu20.04 AS livepeer-arm64-base

FROM livepeer-${TARGETARCH}-base
FROM --platform=${TARGETPLATFORM} nvidia/cuda:11.6.2-cudnn8-runtime-ubuntu20.04 AS livepeer-base

ENV NVIDIA_DRIVER_CAPABILITIES=all

COPY --from=build /build/ /usr/local/bin/
COPY --from=build /usr/bin/grpc_health_probe /usr/local/bin/grpc_health_probe
COPY --from=build /src/tasmodel.pb /tasmodel.pb
COPY --from=build /usr/share/misc/pci.ids /usr/share/misc/pci.ids

RUN ldconfig
# libtensorflow.so is required at runtime, because Ffmpeg DNN filter loads it dynamically
COPY --from=build /tf/ /usr/local/

ENTRYPOINT ["/usr/local/bin/livepeer"]
17 changes: 7 additions & 10 deletions install_ffmpeg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,15 @@ if [[ "$UNAME" == "Darwin" ]]; then
else
# If we have clang, we can compile with CUDA support!
if which clang >/dev/null; then
echo "clang detected, building with GPU support"
echo "clang detected, building with GPU and Tensorflow support"
EXTRA_FFMPEG_FLAGS="$EXTRA_FFMPEG_FLAGS --enable-cuda --enable-cuda-llvm --enable-cuvid --enable-nvenc --enable-decoder=h264_cuvid,hevc_cuvid,vp8_cuvid,vp9_cuvid --enable-filter=scale_cuda,signature_cuda,hwupload_cuda --enable-encoder=h264_nvenc,hevc_nvenc"
if [[ $BUILD_TAGS == *"experimental"* ]]; then
if [[ ! -e "/usr/local/lib/libtensorflow_framework.so" ]]; then
LIBTENSORFLOW_VERSION=2.6.3 &&
curl -LO https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-${LIBTENSORFLOW_VERSION}.tar.gz &&
sudo tar -C /usr/local -xzf libtensorflow-gpu-linux-x86_64-${LIBTENSORFLOW_VERSION}.tar.gz &&
rm libtensorflow-gpu-linux-x86_64-${LIBTENSORFLOW_VERSION}.tar.gz
fi
echo "experimental tag detected, building with Tensorflow support"
EXTRA_FFMPEG_FLAGS="$EXTRA_FFMPEG_FLAGS --enable-libtensorflow"
if [[ ! -e "${ROOT}/compiled/lib/libtensorflow_framework.so" ]]; then
LIBTENSORFLOW_VERSION=2.6.3 &&
curl -LO https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-${LIBTENSORFLOW_VERSION}.tar.gz &&
tar -C ${ROOT}/compiled/ -xzf libtensorflow-gpu-linux-x86_64-${LIBTENSORFLOW_VERSION}.tar.gz &&
rm libtensorflow-gpu-linux-x86_64-${LIBTENSORFLOW_VERSION}.tar.gz
fi
EXTRA_FFMPEG_FLAGS="$EXTRA_FFMPEG_FLAGS --enable-libtensorflow"
fi
fi

Expand Down

0 comments on commit 82e40f9

Please sign in to comment.