forked from pytorch/serve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.sh
executable file
·54 lines (46 loc) · 1.69 KB
/
start.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
IMAGE_NAME="pytorch/torchserve:latest"
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="--gpus all"
IMAGE_NAME="pytorch/torchserve:dev-gpu"
shift
;;
-d|--gpu_devices)
if test $
then
IMAGE_NAME="pytorch/torchserve:dev-gpu"
GPU_DEVICES='--gpus '"\"device=$2\""''
shift
fi
shift
;;
esac
done
echo "Starting $IMAGE_NAME docker image"
docker run $DOCKER_RUNTIME $GPU_DEVICES -d --rm -it -p 127.0.0.1:8080:8080 -p 127.0.0.1:8081:8081 $IMAGE_NAME > /dev/null 2>&1
container_id=$(docker ps --filter="ancestor=$IMAGE_NAME" -q | xargs)
sleep 30
echo "Successfully started torchserve in docker"
echo "Registering resnet-18 model"
response=$(curl --write-out %{http_code} --silent --output /dev/null --retry 5 -X POST "http://localhost:8081/models?url=https://torchserve.pytorch.org/mar_files/resnet-18.mar&initial_workers=1&synchronous=true")
if [ ! "$response" == 200 ]
then
echo "failed to register model with torchserve"
else
echo "successfully registered resnet-18 model with torchserve"
fi
echo "TorchServe is up and running with resnet-18 model"
echo "Management APIs are accessible on http://127.0.0.1:8081"
echo "Inference APIs are accessible on http://127.0.0.1:8080"
echo "For more details refer TorchServe documentation"
echo "To stop docker container for TorchServe use command : docker container stop $container_id"