-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstage_imagenet.py
More file actions
57 lines (49 loc) · 1.54 KB
/
stage_imagenet.py
File metadata and controls
57 lines (49 loc) · 1.54 KB
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
"""Stage ImageNet data onto local SSDs."""
import argparse
import os
import os.path
import subprocess
import time
parser = argparse.ArgumentParser(
description='Stage ImageNet to SSDs.')
parser.add_argument(
'basedir', type=str,
help='Base directory containing {train,val}.tar')
def get_num_nodes():
"""Return the number of nodes in the job."""
# TODO: Support Slurm, etc.
if 'NUM_COMPUTE_NODES' in os.environ:
return int(os.environ['NUM_COMPUTE_NODES'])
raise RuntimeError('Could not get world size')
def stage_file(basedir, filename, dstdir='imagenet'):
"""Stage a single file."""
ssd = os.environ['BBPATH']
# Broadcast tar file.
subprocess.run(
['jsrun',
'--nrs', str(get_num_nodes()),
'--rs_per_host', '1',
'--tasks_per_rs', '4',
'--cpu_per_rs', 'ALL_CPUS',
'dbcast',
os.path.join(basedir, filename),
os.path.join(ssd, dstdir, filename)],
check=True)
# Untar.
subprocess.run(
['jsrun',
'--nrs', str(get_num_nodes()),
'--rs_per_host', '1',
'--tasks_per_rs', '1',
'--cpu_per_rs', 'ALL_CPUS',
'tar', 'xf',
os.path.join(ssd, dstdir, filename),
'-C', os.path.join(ssd, dstdir)],
check=True)
if __name__ == '__main__':
args = parser.parse_args()
start = time.perf_counter()
stage_file(args.basedir, 'train.tar')
stage_file(args.basedir, 'val.tar')
total_time = time.perf_counter() - start
print(f'Staged in {total_time:.4f} s')