File size: 640 Bytes
ef987bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python3
"""Assign globally sorted tar sample keys to a distributed rank."""

import argparse
from dataloader_demo import sample_keys


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--rank", type=int, required=True)
    parser.add_argument("--world-size", type=int, required=True)
    args = parser.parse_args()
    if args.world_size < 1 or not 0 <= args.rank < args.world_size:
        parser.error("rank must be in [0, world-size)")
    for index, key in enumerate(sample_keys()):
        if index % args.world_size == args.rank:
            print(key)


if __name__ == "__main__":
    main()