Skip to content

Commit

Permalink
Fixes #205 - Docker install not finding GPUs (#262)
Browse files Browse the repository at this point in the history
Invokes docker with  --runtime=nvidia for GPU
    Added the option to specify the GPU / specific GPU ids in start.sh
    Fixed the documentation for start.sh script
    Fixed the JDK version in Dockerfile.gpu

Co-authored-by: Aaqib <maaquib@gmail.com>
  • Loading branch information
dhanainme and maaquib authored Apr 30, 2020
1 parent 9e06b12 commit e8a2c75
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 6 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ pip install -e .

* To upgrade TorchServe or model archiver from source code and make changes executable, run:

For CPU run the following command:
```bash
pip install -U -e .
```
Expand Down Expand Up @@ -249,6 +250,14 @@ To run your TorchServe Docker image and start TorchServe inside the container wi
```bash
./start.sh
```
For GPU run the following command:
```bash
./start.sh --gpu
```
For GPU with specific GPU device ids run the following command:
```bash
./start.sh --gpu_devices 1,2,3
```

## Learn More

Expand Down
4 changes: 3 additions & 1 deletion build_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

MACHINE=cpu
BRANCH_NAME="master"
DOCKER_TAG="pytorch/torchserve:latest"

for arg in "$@"
do
Expand All @@ -26,6 +27,7 @@ do
;;
-g|--gpu)
MACHINE=gpu
DOCKER_TAG="pytorch/torchserve:latest-gpu"
shift
;;
esac
Expand All @@ -37,4 +39,4 @@ git clone https://github.com/pytorch/serve.git
cd serve
git checkout $BRANCH_NAME
cd ..
docker build --file Dockerfile.$MACHINE -t torchserve:1.0 .
docker build --file Dockerfile.$MACHINE -t $DOCKER_TAG .
4 changes: 2 additions & 2 deletions docker/Dockerfile.gpu
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RUN apt-get update && \
dpkg-dev \
g++ \
python3-dev \
openjdk-8-jdk-headless \
openjdk-11-jdk-headless \
curl \
vim \
&& rm -rf /var/lib/apt/lists/* \
Expand Down Expand Up @@ -45,4 +45,4 @@ ENV TEMP=/home/model-server/tmp
ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh"]
CMD ["serve"]

LABEL maintainer="wongale@amazon.com"
LABEL maintainer="wongale@amazon.com"
5 changes: 5 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ For specific versions you can pass in the specific tag to use (ex: 0.1-cpu):
```bash
docker run --rm -it -p 8080:8080 -p 8081:8081 pytorch/torchserve:0.1-cpu
```
For GPU based image :

```bash
docker run --rm -it --gpus --gpus '"device=1,2"' -p 8080:8080 -p 8081:8081 torchserve:1.0

This comment has been minimized.

Copy link
@chauhang

chauhang May 10, 2020

Contributor

@maaquib Please remove the extra --gpus (showing up twice). Also clarify that "device=all" will enable for all gpus

This comment has been minimized.

Copy link
@maaquib

maaquib May 21, 2020

Author Collaborator

@chauhang Removed as part of #308

```

For the latest version, you can use the `latest` tag:
docker run --rm -it -p 8080:8080 -p 8081:8081 pytorch/torchserve:latest
Expand Down
34 changes: 31 additions & 3 deletions start.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,37 @@
#!/bin/bash
IMAGE_NAME="torchserve:1.0"
IMAGE_NAME="pytorch/torchserve:latest"

echo "Starting torchserve:1.0 docker image"
for arg in "$@"
do
case $arg in
-h|--help)
echo "options:"
echo "-h, --help show brief help"
echo "-g, --gpu specify to use gpu"
echo "-d, --gpu_devices to use specific gpu device ids"
exit 0
;;
-g|--gpu)
DOCKER_RUNTIME="--runtime=nvidia"
IMAGE_NAME="pytorch/torchserve:latest-gpu"
shift
;;
-d|--gpu_devices)
if test $
then
DOCKER_RUNTIME="--runtime=nvidia"
IMAGE_NAME="pytorch/torchserve:latest-gpu"
GPU_DEVICES="-e NVIDIA_VISIBLE_DEVICES=$2"
shift
fi
shift
;;
esac
done
echo "Starting $IMAGE_NAME docker image"

docker run $DOCKER_RUNTIME $GPU_DEVICES -d --rm -it -p 8080:8080 -p 8081:8081 $IMAGE_NAME > /dev/null 2>&1

This comment has been minimized.

Copy link
@chauhang

chauhang May 10, 2020

Contributor

@maaquib Please convert to use the new --gpu mechanism for docker with gpus (instead on using --runtime=nvidia


docker run -d --rm -it -p 8080:8080 -p 8081:8081 torchserve:1.0 > /dev/null 2>&1
container_id=$(docker ps --filter="ancestor=$IMAGE_NAME" -q | xargs)

sleep 30
Expand Down

0 comments on commit e8a2c75

Please sign in to comment.