forked from aws-deepracer-community/deepracer-on-the-spot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.sh
executable file
·327 lines (307 loc) · 13.5 KB
/
menu.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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
#!/bin/bash
get_team_details()
{
if [[ -f "./config.ini" ]];then
LINES=$(grep -v '^#' ./config.ini | grep -E '^MY_BASE_RESOURCES_STACK=|^MY_BASE_RESOURCES_BUCKET=')
if [[ "$(grep -E '^MY_BASE_RESOURCES_STACK=|^MY_BASE_RESOURCES_BUCKET=' ./config.ini | wc -l)" -ne "2" ]];then
echo -e "\e[1;32m File config.ini must contain variables MY_BASE_RESOURCES_STACK and MY_BASE_RESOURCES_BUCKET defined. \n Example
MY_BASE_RESOURCES_STACK=myteam-base-resources
MY_BASE_RESOURCES_BUCKET=myteam-base-resources-bucket-xxxxxxxx \e[0m (this one is created by the tool once you did all the setup)"
exit 1
fi
echo -e "File config.ini found with this configuration:"
for l in $LINES; do
env_var=$(echo $l | cut -f1 -d\=)
env_val=$(echo $l | cut -f2 -d\=)
eval export "$env_var=$env_val"
echo -e "\e[1;32m $env_var=$env_val \e[0m"
done
echo
read -p "Do you want to use this configuration to continue [Y/N]? " -n 1 -r
if ! [[ $REPLY =~ ^[Yy]$ ]];then
echo
echo -e "\e[1;32m ******** UPDATE File config.ini and try again *************** \e[0m"
exit 1
fi
echo
echo "**********************************************"
else
echo -e "\e[1;32m File config.ini does not exist. \e[0m"
exit 1
fi
}
submit_model_to_train()
{
clear
echo
echo
echo "**** DEEPRACER EC2 INSTANCE LAUNCHER MENU ****"
PS3='Choose EC2 instance type to use: '
EC2Types=("g4dn.2xlarge" "g4dn.4xlarge" "g4dn.8xlarge" "g4dn.12xlarge" "g5.2xlarge" "g5.4xlarge" "g5.8xlarge" "g5.12xlarge" "Custom value for EC2 type" "Exit")
COLUMNS=0
select ec2type in "${EC2Types[@]}"; do
case $ec2type in
"g4dn.2xlarge")
export DEEPRACER_INSTANCE_TYPE=$ec2type
echo -e "\tInstance Type selected = \e[1;32m $ec2type \e[0m"
break
;;
"g4dn.4xlarge")
export DEEPRACER_INSTANCE_TYPE=$ec2type
echo -e "\tInstance Type selected = \e[1;32m $ec2type \e[0m"
break
;;
"g4dn.8xlarge")
export DEEPRACER_INSTANCE_TYPE=$ec2type
echo "\tInstance Type selected = \e[1;32m $ec2type \e[0m"
break
;;
"g4dn.12xlarge")
export DEEPRACER_INSTANCE_TYPE=$ec2type
echo -e "\tInstance Type selected = \e[1;32m $ec2type \e[0m"
break
;;
"g5.2xlarge")
export DEEPRACER_INSTANCE_TYPE=$ec2type
echo -e "\tInstance Type selected = \e[1;32m $ec2type \e[0m"
break
;;
"g5.4xlarge")
export DEEPRACER_INSTANCE_TYPE=$ec2type
echo -e "\tInstance Type selected = \e[1;32m $ec2type \e[0m"
break
;;
"g5.8xlarge")
export DEEPRACER_INSTANCE_TYPE=$ec2type
echo -e "\tInstance Type selected = \e[1;32m $ec2type \e[0m"
break
;;
"g5.12xlarge")
export DEEPRACER_INSTANCE_TYPE=$ec2type
echo -e "\tInstance Type selected = \e[1;32m $ec2type \e[0m"
break
;;
"Custom value for EC2 type")
customec2entry=
while [ "$customec2entry" == "" ]
do
read -p "Enter EC2 Instance type:" customec2entry
done
export DEEPRACER_INSTANCE_TYPE=$customec2entry
echo -e "\tInstance Type selected = \e[1;32m $customec2entry \e[0m"
break
;;
"Exit")
echo -e "\tUser requested \e[1;31m exit \e[0m"
exit
;;
*) echo -e "\t\e[1;33;1;41m invalid option $REPLY \e[0m";;
esac
done
clear
echo
echo
echo "**** DEEPRACER EC2 INSTANCE LAUNCHER MENU ****"
PS3='Choose Spot or Standard instance lifecycle: '
EC2lifecycle=("Spot" "Standard" "Exit")
select lifecycle in "${EC2lifecycle[@]}"; do
case $lifecycle in
"Spot")
export lifecycle=$(echo $lifecycle | tr '[:upper:]' '[:lower:]')
echo -e "\tInstance lifecycle selected = \e[1;32m $lifecycle \e[0m"
break
;;
"Standard")
export lifecycle=$(echo $lifecycle | tr '[:upper:]' '[:lower:]')
echo -e "\tInstance lifecycle selected = \e[1;32m $lifecycle \e[0m"
break
;;
"Exit")
echo -e "\tUser requested \e[1;31m exit \e[0m"
exit
;;
*) echo -e "\t\e[1;33;1;41m invalid option $REPLY \e[0m";;
esac
done
if [ $lifecycle = "standard" ]
then
clear
echo "**** DEEPRACER EC2 INSTANCE LAUNCHER MENU ****"
echo
echo
PS3='Choose Maximum Uptime for the Standard Instance (in minutes): '
maxTimeToLiveInMinutes=("30" "60" "90" "120" "180" "360" "480" "720" "1440" "Custom value for Maximum Uptime" "Exit")
select TimeToLiveInMinutes in "${maxTimeToLiveInMinutes[@]}"; do
case $TimeToLiveInMinutes in
"30")
export TimeToLiveInMinutes=$TimeToLiveInMinutes
echo -e "\tMaximum Uptime selected = \e[1;32m $TimeToLiveInMinutes \e[0m"
break
;;
"60")
export TimeToLiveInMinutes=$TimeToLiveInMinutes
echo -e "\tMaximum Uptime selected = \e[1;32m $TimeToLiveInMinutes \e[0m"
break
;;
"90")
export TimeToLiveInMinutes=$TimeToLiveInMinutes
echo -e "\tMaximum Uptime selected = \e[1;32m $TimeToLiveInMinutes \e[0m"
break
;;
"120")
export TimeToLiveInMinutes=$TimeToLiveInMinutes
echo -e "\tMaximum Uptime selected = \e[1;32m $TimeToLiveInMinutes \e[0m"
break
;;
"180")
export TimeToLiveInMinutes=$TimeToLiveInMinutes
echo -e "\tMaximum Uptime selected = \e[1;32m $TimeToLiveInMinutes \e[0m"
break
;;
"360")
export TimeToLiveInMinutes=$TimeToLiveInMinutes
echo -e "\tMaximum Uptime selected = \e[1;32m $TimeToLiveInMinutes \e[0m"
break
;;
"480")
export TimeToLiveInMinutes=$TimeToLiveInMinutes
echo -e "\tMaximum Uptime selected = \e[1;32m $TimeToLiveInMinutes \e[0m"
break
;;
"720")
export TimeToLiveInMinutes=$TimeToLiveInMinutes
echo -e "\tMaximum Uptime selected = \e[1;32m $TimeToLiveInMinutes \e[0m"
break
;;
"1440")
export TimeToLiveInMinutes=$TimeToLiveInMinutes
echo -e "\tMaximum Uptime selected = \e[1;32m $TimeToLiveInMinutes \e[0m"
break
;;
"Custom value for Maximum Uptime")
customtimeentry=
while [[ ! "$customtimeentry" =~ ^[0-9]+$ ]] || [ "$customtimeentry" -gt 1440 ]
do
read -p "Enter Maximum Uptime (in minutes - Min:0 / Max:1440):" customtimeentry
done
export TimeToLiveInMinutes=$customtimeentry
echo -e "\tMaximum Uptime selected = \e[1;32m $TimeToLiveInMinutes \e[0m"
break
;;
"Exit")
echo -e "\tUser requested \e[1;31m exit \e[0m"
exit
;;
*) echo -e "\t\e[1;33;1;41m invalid option $REPLY \e[0m";;
esac
done
fi
export modelname=$(cat ~/deepracer-templates/custom-files/run.env | grep DR_LOCAL_S3_MODEL_PREFIX= | sed 's/^DR_LOCAL_S3_MODEL_PREFIX=\([^ ]*\).*$/\1/')
export numberofworkers=$(cat ~/deepracer-templates/custom-files/system.env | grep DR_WORKERS= | sed 's/^DR_WORKERS=\([^ ]*\).*$/\1/')
clear
echo
echo
echo "**** DEEPRACER EC2 INSTANCE LAUNCHER MENU ****"
echo "##### SUMMARY REPORT ####################################"
echo -e "\tInstance Type selected = \e[1;32m $DEEPRACER_INSTANCE_TYPE \e[0m"
echo -e "\tInstance lifecycle selected = \e[1;32m $lifecycle \e[0m"
if [ $lifecycle = "standard" ];then
echo -e "\tMaximum Uptime selected (in minutes) = \e[1;32m $TimeToLiveInMinutes \e[0m"
fi
echo
echo "##### RUN.ENV FREQUENTLY USED SETTINGS ##############"
grep -E '^DR_WORLD_NAME=|^DR_RACE_TYPE=|^DR_TRAIN_CHANGE_START_POSITION=|^DR_TRAIN_ALTERNATE_DRIVING_DIRECTION=|^DR_TRAIN_START_POSITION_OFFSET=|^DR_TRAIN_ROUND_ROBIN_ADVANCE_DIST=|^DR_LOCAL_S3_MODEL_PREFIX=|^DR_LOCAL_S3_PRETRAINED=|^DR_LOCAL_S3_PRETRAINED_PREFIX=|^DR_LOCAL_S3_PRETRAINED_CHECKPOINT=|^DR_UPLOAD_S3_PREFIX=|^DR_OA_NUMBER_OF_OBSTACLES=|^DR_OA_MIN_DISTANCE_BETWEEN_OBSTACLES=|^DR_OA_RANDOMIZE_OBSTACLE_LOCATIONS=|^DR_OA_IS_OBSTACLE_BOT_CAR=|^DR_OA_OBJECT_POSITIONS=|^DR_H2B_IS_LANE_CHANGE=|^DR_H2B_LOWER_LANE_CHANGE_TIME=|^DR_H2B_UPPER_LANE_CHANGE_TIME=|^DR_H2B_LANE_CHANGE_DISTANCE=|^DR_H2B_NUMBER_OF_BOT_CARS=|^DR_H2B_MIN_DISTANCE_BETWEEN_BOT_CARS=|^DR_H2B_RANDOMIZE_BOT_CAR_LOCATIONS=|^DR_H2B_BOT_CAR_SPEED=' ./custom-files/run.env
echo
echo "##### SYSTEM.ENV FREQUENTLY USED SETTINGS ##############"
grep -E '^DR_UPLOAD_S3_BUCKET=|^DR_LOCAL_S3_BUCKET=|^DR_SAGEMAKER_IMAGE=|^DR_ROBOMAKER_IMAGE=|^DR_ANALYSIS_IMAGE=|^DR_COACH_IMAGE=|^DR_WORKERS=|^CUDA_VISIBLE_DEVICES=' ./custom-files/system.env
echo "#########################################################"
echo
echo
read -p "Do you want to continue with the EC2 launch request [Y/N]? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
if [ $lifecycle = "standard" ]
then
echo ./create-$lifecycle-instance.sh $MY_BASE_RESOURCES_STACK $modelname-$RANDOM $TimeToLiveInMinutes
./create-$lifecycle-instance.sh $MY_BASE_RESOURCES_STACK $modelname-$RANDOM $TimeToLiveInMinutes
else
echo ./create-$lifecycle-instance.sh $MY_BASE_RESOURCES_STACK $modelname-$RANDOM
./create-$lifecycle-instance.sh $MY_BASE_RESOURCES_STACK $modelname-$RANDOM
fi
fi
}
download_custom_files_from_s3()
{
echo -e "\e[1;32m **************LOCAL CURRENT FILES under ./custom-files/ ************************************************* \e[0m"
echo
find ./custom-files/ -printf '%CY-%Cm-%Cd %CH:%CM:%.2CS \t%s\t%p\n' | sed -s 's/.\/custom-files\///g' | sort
echo -e "\e[1;32m **************S3 CURRENT FILES under s3://$MY_BASE_RESOURCES_BUCKET/custom_files/ ************************** \e[0m"
echo
aws s3 ls s3://$MY_BASE_RESOURCES_BUCKET/custom_files/ --recursive | sort
echo -e "\e[1;32m ****************************************************************************************************************************** \e[0m"
echo
echo
read -p "Do you want to DELETE "$PWD/custom-files/" and download current content from "s3://$MY_BASE_RESOURCES_BUCKET/custom_files/" [Y/N]? " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
rm ./custom-files/*.*
aws s3 cp s3://$MY_BASE_RESOURCES_BUCKET/custom_files/ ./custom-files/ --recursive
echo
echo -e "\e[1;32m ******** UPDATE COMPLETED *************** \e[0m"
fi
}
clear
echo
echo
echo "**** DEEPRACER EC2 INSTANCE LAUNCHER MENU ****"
get_team_details
PS3='Choose your option: '
MainOptions=("Submit model to train on EC2" "Download custom_files from S3 (overwrites CloudShell files with S3 files)" "Exit")
COLUMNS=0
select main in "${MainOptions[@]}"; do
case $main in
"Create Base resources stack (only once)")
echo -e "\tMain option selected = \e[1;32m $main \e[0m"
echo "Pending development"
break
;;
"Create Image builder (only once)")
echo -e "\tMain option selected = \e[1;32m $main \e[0m"
echo "Pending development"
break
;;
"Submit model to train on EC2")
echo -e "\tMain option selected = \e[1;32m $main \e[0m"
sleep 1 > /dev/null
submit_model_to_train
break
;;
"Add Access to EC2 from IP Address (limited number of entries)")
echo "\tMain option selected = \e[1;32m $main \e[0m"
echo "Pending development"
break
;;
"Download custom_files from S3 (overwrites CloudShell files with S3 files)")
echo -e "\tMain option selected = \e[1;32m $main \e[0m"
sleed 1 > /dev/null
download_custom_files_from_s3
break
;;
"Display configuration files")
echo -e "\tMain option selected = \e[1;32m $main \e[0m"
echo "Pending development"
break
;;
"Increment training at system.env (dr-increment-training)")
echo -e "\tMain option selected = \e[1;32m $main \e[0m"
echo "Pending development"
break
;;
"Exit")
echo -e "\tUser requested \e[1;31m exit \e[0m"
exit
;;
*) echo -e "\t\e[1;33;1;41m invalid option $REPLY \e[0m";;
esac
done