Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #205 - Docker install not finding GPUs #262

Merged
merged 4 commits into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
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
```

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

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