-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathMakefile
157 lines (123 loc) · 4.25 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
157
#################
# General setup #
#################
GIT_BRANCH=main # IF YOU WANT TO AUTOMATICALLY SET UP THE VM ON A SPECIFIC BRANCH
# The following variables are assumed to already exist as environment variables locally,
# or can be uncommented and edited below.
#GITHUB_USER_TOKEN=$(GITHUB_USER_TOKEN)
#GITHUB_ACCESS_TOKEN=$(GITHUB_ACCESS_TOKEN)
#NEPTUNE_API_TOKEN=$(NEPTUNE_API_TOKEN)
#######
# TPU #
#######
# Shared set-up.
#BASE_CMD=gcloud alpha compute tpus tpu-vm
#BASE_NAME=popcorn
#WORKER=all
#PORT=8889
#NUM_DEVICES=8
BASE_CMD=gcloud alpha compute tpus tpu-vm
BASE_NAME=poppy# popcorn
WORKER=all
PORT=8889
NUM_DEVICES=8
# Basic v3 TPU configuration.
PROJECT=research-294715#int-research-tpu-trc-2
ZONE=us-central1-a
ACCELERATOR_TYPE=v3-$(NUM_DEVICES)
NAME=$(BASE_NAME)-$(ACCELERATOR_TYPE)
RUNTIME_VERSION=v2-alpha
.PHONY: set_project
set_project:
gcloud config set project $(PROJECT)
.PHONY: create_vm
create_vm:
$(BASE_CMD) create $(NAME) --zone $(ZONE) \
--project $(PROJECT) \
--accelerator-type $(ACCELERATOR_TYPE) \
--version $(RUNTIME_VERSION) \
.PHONY: prepare_vm
prepare_vm:
$(BASE_CMD) ssh --zone $(ZONE) $(NAME) \
--project $(PROJECT) \
--worker=$(WORKER) \
--command="git clone -b ${GIT_BRANCH} https://${GITHUB_USER_TOKEN}:${GITHUB_ACCESS_TOKEN}@github.com/instadeepai/popcorn.git"
.PHONY: create
create: create_vm prepare_vm
.PHONY: start
start:
$(BASE_CMD) start $(NAME) --zone=$(ZONE) --project $(PROJECT)
.PHONY: connect
connect:
$(BASE_CMD) ssh $(NAME) --zone $(ZONE) --project $(PROJECT)
#.PHONY: connect_redirect_port
#connect_redirect_port: # IF YOU WANT TO REDIRECT NOTEBOOKS
# $(BASE_CMD) ssh $(NAME) --zone $(ZONE) --project $(PROJECT) -- -N -f -L $(PORT):localhost:$(PORT)
.PHONY: list
list:
$(BASE_CMD) list --zone=$(ZONE) --project $(PROJECT)
.PHONY: describe
describe:
$(BASE_CMD) describe $(NAME) --zone=$(ZONE) --project $(PROJECT)
.PHONY: stop
stop:
$(BASE_CMD) stop $(NAME) --zone=$(ZONE) --project $(PROJECT)
.PHONY: delete
delete:
$(BASE_CMD) delete $(NAME) --zone $(ZONE) --project $(PROJECT)
.PHONY: run
run:
$(BASE_CMD) ssh --zone $(ZONE) $(NAME) --project $(PROJECT) --worker=$(WORKER) --command="$(command)"
##########
# Docker #
##########
SHELL := /bin/bash
# variables
WORK_DIR = $(PWD)
USER_ID = $$(id -u)
GROUP_ID = $$(id -g)
DOCKER_BUILD_ARGS = \
--build-arg USER_ID=$(USER_ID) \
--build-arg GROUP_ID=$(GROUP_ID) \
--build-arg GITHUB_USER_TOKEN=$(GITHUB_USER_TOKEN) \
--build-arg GITHUB_ACCESS_TOKEN=$(GITHUB_ACCESS_TOKEN)
DOCKER_RUN_FLAGS = --rm --privileged -p ${PORT}:${PORT} --network host
#DOCKER_RUN_FLAGS_LOCAL = --rm --privileged -p ${PORT}:${PORT}
DOCKER_VARS_TO_PASS = -e NEPTUNE_API_TOKEN=$(NEPTUNE_API_TOKEN)
DOCKER_IMAGE_NAME = popcorn
DOCKER_CONTAINER_NAME = popcorn_container
.PHONY: clean
clean:
find . -type f -name "*.DS_Store" -ls -delete
find . | grep -E "(__pycache__|\.pyc|\.pyo)" | xargs rm -rfv
find . | grep -E ".pytest_cache" | xargs rm -rfv
find . | grep -E "nul" | xargs rm -rfv
.PHONY: docker_build_tpu
docker_build_tpu:
sudo docker build -t $(DOCKER_IMAGE_NAME) $(DOCKER_BUILD_ARGS) -f docker/tpu.Dockerfile .
.PHONY: docker_build_local
docker_build_local:
sudo docker build -t $(DOCKER_IMAGE_NAME) $(DOCKER_BUILD_ARGS) -f docker/local.Dockerfile .
.PHONY: docker_run
docker_run:
sudo docker run $(DOCKER_RUN_FLAGS) --name $(DOCKER_CONTAINER_NAME) $(DOCKER_VARS_TO_PASS) -v $(WORK_DIR):/app $(DOCKER_IMAGE_NAME) $(command)
.PHONY: docker_start
docker_start:
sudo docker run -itd $(DOCKER_RUN_FLAGS) --name $(DOCKER_CONTAINER_NAME) $(DOCKER_VARS_TO_PASS) -v $(WORK_DIR):/app $(DOCKER_IMAGE_NAME)
.PHONY: docker_enter
docker_enter:
sudo docker exec -it $(DOCKER_CONTAINER_NAME) /bin/bash
.PHONY: docker_interactive
docker_interactive: docker_start docker_enter
echo "Running container $(DOCKER_CONTAINER_NAME) in interactive mode."
.PHONY: docker_kill
docker_kill:
sudo docker kill $(DOCKER_CONTAINER_NAME)
.PHONY: docker_list
docker_list:
sudo docker ps
#.PHONY: docker_notebook
#docker_notebook: docker_run_local
# #echo "Make sure you have properly exposed your VM before, with the gcloud ssh command followed by -- -N -f -L $(PORT):localhost:$(PORT)"
# jupyter notebook --port=$(PORT) --no-browser --ip=0.0.0.0 --allow-root
# echo "Go to http://localhost:${PORT} and enter token above."