Skip to content

Commit

Permalink
Merge pull request #907 from anarkiwi/cudatorchserve
Browse files Browse the repository at this point in the history
Build torchserve container with both cpu (default) and cuda versions.
  • Loading branch information
anarkiwi authored Oct 10, 2023
2 parents 914b38b + 538165a commit c7ebcc5
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 130 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
sox \
uhd-host \
wget \
&& grep -h 'git clone' docker/*|sed -E 's/RUN\s+git clone\s+//g'|sort|uniq|xargs -L1 git clone
&& grep -h 'git clone' docker/*|grep -v pytorch|sed -E 's/RUN\s+git clone\s+//g'|sort|uniq|xargs -L1 git clone
- name: Install dependencies
run: |
for repodir in flatbuffers json libsigmf gr-iqtlabs ; do \
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/docker-extras.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,40 @@ on:

jobs:
buildx-torchserve:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::$(echo $GITHUB_REF | cut -d / -f 3)
- name: Change for main
id: change_version
run: if [ "${{ steps.get_version.outputs.VERSION }}" == "main" ]; then echo ::set-output name=VERSION::latest; else echo ::set-output name=VERSION::${{ steps.get_version.outputs.VERSION }}; fi
- name: Set up qemu
uses: docker/setup-qemu-action@v3
with:
platforms: all
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Docker Login
env:
DOCKER_PASSWORD: ${{ secrets.DOCKER_TOKEN }}
run: |
echo "${DOCKER_PASSWORD}" | docker login --username "${{ secrets.DOCKER_USERNAME }}" --password-stdin
if: github.repository == 'iqtlabs/gamutrf' && github.event_name == 'push'
- name: Build and push platforms
uses: docker/build-push-action@v5
with:
context: docker
file: docker/Dockerfile.torchserve
platforms: linux/amd64,linux/arm64
push: true
tags: iqtlabs/gamutrf-torchserve:${{ steps.change_version.outputs.VERSION }}
if: github.repository == 'iqtlabs/gamutrf' && github.event_name == 'push'
buildx-cuda-torchserve:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
15 changes: 15 additions & 0 deletions docker/Dockerfile.cuda-torchserve
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM nvidia/cuda:11.8.0-runtime-ubuntu22.04
ENV DEBIAN_FRONTEND=noninteractive
WORKDIR /root
RUN apt-get update && \
apt-get install -y \
git \
python3-pip
RUN pip config set global.no-cache-dir false && \
git clone https://github.com/pytorch/serve -b v0.8.2 && \
cd serve && \
python3 ./ts_scripts/install_dependencies.py --cuda cu118 --environment prod && \
pip3 install . && \
cd .. && \
rm -rf serve
RUN /usr/local/bin/torchserve --help
87 changes: 8 additions & 79 deletions docker/Dockerfile.torchserve
Original file line number Diff line number Diff line change
@@ -1,86 +1,15 @@
FROM --platform=$BUILDPLATFORM ubuntu:22.04 as git-cloner
WORKDIR /root
RUN apt-get update && \
apt-get install -y \
ca-certificates \
git \
python3
RUN git clone https://github.com/google/shaderc -b v2023.6
RUN git clone https://github.com/pytorch/pytorch -b v2.1.0
RUN git clone https://github.com/pytorch/serve -b v0.8.2
WORKDIR /root/shaderc
RUN ./utils/git-sync-deps
WORKDIR /root/pytorch
RUN git submodule update --init --recursive

FROM ubuntu:22.04 as shader-compiler
WORKDIR /root
RUN apt-get update && \
apt-get install -y \
build-essential \
cmake \
git \
ninja-build \
python3-dev \
python3-pip
COPY --from=git-cloner /root/shaderc /root/shaderc
WORKDIR /root/shaderc/build
RUN cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DSHADERC_SKIP_TESTS=on .. && ninja && ninja install

FROM ubuntu:22.04 as pytorch-compiler
FROM ubuntu:22.04
ENV DEBIAN_FRONTEND=noninteractive
ENV USE_CUDA=0
ENV USE_VULKAN=1
ENV USE_VULKAN_SHADERC_RUNTIME=1
ENV USE_VULKAN_WRAPPER=0
WORKDIR /root
COPY --from=shader-compiler /usr/local /usr/local
COPY --from=git-cloner /root/pytorch /root/pytorch
RUN apt-get update && \
apt-get install -y \
build-essential \
cmake \
git \
libvulkan-dev \
ninja-build \
python3-dev \
python3-pip
WORKDIR /root/pytorch
COPY pytorch-patch.txt /root/pytorch
RUN patch -p1 < pytorch-patch.txt
RUN pip3 install -U pyyaml
RUN python3 setup.py install && python3 setup.py develop
RUN python3 -c "import torch ; assert(torch.is_vulkan_available())"

FROM ubuntu:22.04 as torchserve-builder
RUN apt-get update && \
apt-get install -y \
build-essential \
cmake \
git \
libvulkan-dev \
ninja-build \
openjdk-17-jdk \
python3-dev \
python3-pip
WORKDIR /root
COPY --from=git-cloner /root/serve /root/serve
WORKDIR /root/serve
COPY torchserve-patch.txt /root/serve
RUN patch -p1 < torchserve-patch.txt
COPY --from=pytorch-compiler /usr/local /usr/local
RUN python3 -c "import torch ; assert(torch.is_vulkan_available())"
RUN python3 ./ts_scripts/install_dependencies.py --environment prod
RUN pip3 install .

FROM ubuntu:22.04
RUN apt-get update && \
apt-get install -y \
libvulkan1 \
openjdk-17-jre \
python3 \
python3-pip
WORKDIR /root
COPY --from=torchserve-builder /usr/local /usr/local
RUN python3 -c "import torch ; assert(torch.is_vulkan_available())"
RUN pip config set global.no-cache-dir false && \
git clone https://github.com/pytorch/serve -b v0.8.2 && \
cd serve && \
python3 ./ts_scripts/install_dependencies.py --environment prod && \
pip3 install . && \
cd .. && \
rm -rf serve
RUN /usr/local/bin/torchserve --help
25 changes: 0 additions & 25 deletions docker/pytorch-patch.txt

This file was deleted.

25 changes: 0 additions & 25 deletions docker/torchserve-patch.txt

This file was deleted.

0 comments on commit c7ebcc5

Please sign in to comment.