forked from skypilot-org/skypilot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resnet_app_storage.py
77 lines (67 loc) · 2.69 KB
/
resnet_app_storage.py
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
import subprocess
import sky
with sky.Dag() as dag:
# The working directory contains all code and will be synced to remote.
workdir = '~/Downloads/tpu'
data_mount_path = '/tmp/imagenet'
# Clone the repo locally to workdir
subprocess.run(
'git clone https://github.com/concretevitamin/tpu '
f'{workdir} || true',
shell=True,
check=True)
subprocess.run(f'cd {workdir} && git checkout 9459fee',
shell=True,
check=True)
# The setup command. Will be run under the working directory.
setup = """\
set -e
pip install --upgrade pip
conda init bash
conda activate resnet && exists=1 || exists=0
if [ $exists -eq 0 ]; then
conda create -n resnet python=3.7 -y
conda activate resnet
conda install cudatoolkit=11.0 -y
pip install tensorflow==2.4.0 pyyaml
pip install protobuf==3.20
mkdir -p $CONDA_PREFIX/etc/conda/activate.d
echo 'CUDNN_PATH=$(dirname $(python -c "import nvidia.cudnn;print(nvidia.cudnn.__file__)"))' >> $CONDA_PREFIX/etc/conda/activate.d/env_vars.sh
echo 'export LD_LIBRARY_PATH=$CONDA_PREFIX/lib/:$CUDNN_PATH/lib:$LD_LIBRARY_PATH' >> $CONDA_PREFIX/etc/conda/activate.d/env_vars.sh
cd models && pip install -e .
fi
"""
# The command to run. Will be run under the working directory.
run = f"""\
conda activate resnet
export XLA_FLAGS=\'--xla_gpu_cuda_data_dir=/usr/local/cuda/\'
python -u models/official/resnet/resnet_main.py --use_tpu=False \
--mode=train --train_batch_size=256 --train_steps=250 \
--iterations_per_loop=125 \
--data_dir={data_mount_path} \
--model_dir=resnet-model-dir \
--amp --xla --loss_scale=128
"""
# If the backend to be added is not specified, then SkyPilot's optimizer
# will choose the backend bucket to be stored.
# S3 Example
storage = sky.Storage(source="s3://imagenet-bucket")
# GCS Example
#storage = sky.Storage(name="imagenet_test_mluo",source="gs://imagenet_test_mluo")
# Can also be from a local dir
# storage = sky.Storage(name="imagenet-bucket", source="~/imagenet-data/")
train = sky.Task(
'train',
workdir=workdir,
setup=setup,
run=run,
)
train.set_storage_mounts({
data_mount_path: storage,
})
train.set_inputs('s3://imagenet-bucket', estimated_size_gigabytes=150)
train.set_outputs('resnet-model-dir', estimated_size_gigabytes=0.1)
train.set_resources({
sky.Resources(sky.AWS(), 'p3.2xlarge'),
})
sky.launch(dag)