-
-
Notifications
You must be signed in to change notification settings - Fork 984
/
Copy pathMakefile
158 lines (139 loc) · 4.74 KB
/
Makefile
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# Copyright Contributors to the Pyro project.
#
# SPDX-License-Identifier: Apache-2.0
.PHONY: help create-host-workspace build build-gpu run run-gpu notebook notebook-gpu
DOCKER_FILE=Dockerfile
BASE_IMG=ubuntu:18.04
BASE_CUDA_IMG=nvidia/cuda:11.5.0-cudnn8-runtime-ubuntu18.04
DOCKER_CMD=docker
DOCKER_GPU_CMD=nvidia-docker
HOST_WORK_DIR=${HOME}/pyro_docker
UID=$(shell id -u)
GID=$(shell id -g)
OSTYPE=$(shell uname)
USER=pyromancer
DOCKER_WORK_DIR=/home/${USER}/workspace/shared
pyro_git_url=https://github.com/pyro-ppl/pyro.git
# Optional args
python_version?=3.6
pytorch_branch?=release
pyro_branch?=release
cmd?=bash
# Determine name of docker image
build run notebook: img_prefix=pyro-cpu
build-gpu run-gpu notebook-gpu: img_prefix=pyro-gpu
build run lab: img_prefix=pyro-cpu
build-gpu run-gpu lab-gpu: img_prefix=pyro-gpu
ifeq ($(img), )
IMG_NAME=${img_prefix}-${pyro_branch}-${python_version}
else
IMG_NAME=${img}
endif
help:
@fgrep -h "##" ${MAKEFILE_LIST} | fgrep -v fgrep | sed -e 's/##//'
##
##Available targets:
##
build: ##
## Build a docker image for running Pyro on a CPU.
## Requires nvidia-docker (https://github.com/NVIDIA/nvidia-docker).
## Args:
## python_version: version of python to use. default - python 3.6
## pytorch_branch: whether to build PyTorch from conda or from source
## (git branch specified by pytorch_branch)
## default - latest pytorch version on conda
## pyro_branch: whether to use the released Pyro wheel or a git branch.
## default - latest pyro-ppl wheel on pypi
##
${DOCKER_CMD} build -t ${IMG_NAME} \
--build-arg base_img=${BASE_IMG} \
--build-arg uid=${UID} \
--build-arg gid=${GID} \
--build-arg ostype=${OSTYPE} \
--build-arg python_version=${python_version} \
--build-arg pytorch_branch=${pytorch_branch} \
--build-arg pyro_git_url=${pyro_git_url} \
--build-arg pyro_branch=${pyro_branch} -f ${DOCKER_FILE} .
build-gpu: ##
## Build a docker image for running Pyro on a GPU.
## Requires nvidia-docker (https://github.com/NVIDIA/nvidia-docker).
## Args:
## python_version: version of python to use. default - python 3.6
## pytorch_branch: whether to build PyTorch from conda or from source
## (git branch specified by pytorch_branch)
## default - latest pytorch version on conda
## pyro_branch: whether to use the released Pyro wheel or a git branch.
## default - latest pyro-ppl wheel on pypi
##
${DOCKER_GPU_CMD} build -t ${IMG_NAME} \
--build-arg base_img=${BASE_CUDA_IMG} \
--build-arg uid=${UID} \
--build-arg gid=${GID} \
--build-arg ostype=${OSTYPE} \
--build-arg cuda=1 \
--build-arg python_version=${python_version} \
--build-arg pytorch_branch=${pytorch_branch} \
--build-arg pyro_git_url=${pyro_git_url} \
--build-arg pyro_branch=${pyro_branch} -f ${DOCKER_FILE} .
create-host-workspace: ##
## Create shared volume on the host for sharing files with the container.
##
mkdir -p ${HOST_WORK_DIR}
run: create-host-workspace
run: ##
## Start a Pyro CPU docker instance, and run the command `cmd`.
## Args:
## img: use image name given by `img`.
## cmd: command invoked on running a docker instance.
## default - bash
##
docker run --init -it --user ${USER} \
-v ${HOST_WORK_DIR}:${DOCKER_WORK_DIR} \
${IMG_NAME} ${cmd}
run-gpu: create-host-workspace
run-gpu: ##
## Start a Pyro GPU docker instance, and run the command `cmd`.
## Args:
## img: use image name given by `img`.
## cmd: command invoked on running a docker instance.
## default - bash
##
docker run --init --runtime=nvidia -it --user ${USER} \
-v ${HOST_WORK_DIR}:${DOCKER_WORK_DIR} \
${IMG_NAME} ${cmd}
notebook: create-host-workspace
notebook: ##
## Start a jupyter notebook on the Pyro CPU docker container.
## Args:
## img: use image name given by `img`.
##
docker run --init -it -p 8888:8888 --user ${USER} \
-v ${HOST_WORK_DIR}:${DOCKER_WORK_DIR} \
${IMG_NAME}
notebook-gpu: create-host-workspace
notebook-gpu: ##
## Start a jupyter notebook on the Pyro GPU docker container.
## Args:
## img: use image name given by `img`.
##
docker run --runtime=nvidia --init -it -p 8888:8888 --user ${USER} \
-v ${HOST_WORK_DIR}:${DOCKER_WORK_DIR} \
${IMG_NAME}
notebook: create-host-workspace
lab: ##
## Start jupyterlab on the Pyro CPU docker container.
## Args:
## img: use image name given by `img`.
##
docker run --init -it -p 8888:8888 --user ${USER} \
-v ${HOST_WORK_DIR}:${DOCKER_WORK_DIR} \
${IMG_NAME} jupyter lab --port=8888 --no-browser --ip=0.0.0.0
lab-gpu: create-host-workspace
lab-gpu: ##
## Start jupyterlab on the Pyro GPU docker container.
## Args:
## img: use image name given by `img`.
##
docker run --runtime=nvidia --init -it -p 8888:8888 --user ${USER} \
-v ${HOST_WORK_DIR}:${DOCKER_WORK_DIR} \
${IMG_NAME} jupyter lab --port=8888 --no-browser --ip=0.0.0.0