Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

distributed_train.py 1.8 KB

You have to be logged in to leave a comment. Sign In
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
  1. #!/usr/bin/env python3 -u
  2. # Copyright (c) 2017-present, Facebook, Inc.
  3. # All rights reserved.
  4. #
  5. # This source code is licensed under the license found in the LICENSE file in
  6. # the root directory of this source tree. An additional grant of patent rights
  7. # can be found in the PATENTS file in the same directory.
  8. import os
  9. import socket
  10. import subprocess
  11. from train import main as single_process_main
  12. from fairseq import distributed_utils, options
  13. def main(args):
  14. if args.distributed_init_method is None and args.distributed_port > 0:
  15. # We can determine the init method automatically for Slurm.
  16. node_list = os.environ.get('SLURM_JOB_NODELIST')
  17. if node_list is not None:
  18. try:
  19. hostnames = subprocess.check_output(['scontrol', 'show', 'hostnames', node_list])
  20. args.distributed_init_method = 'tcp://{host}:{port}'.format(
  21. host=hostnames.split()[0].decode('utf-8'),
  22. port=args.distributed_port)
  23. args.distributed_rank = int(os.environ.get('SLURM_PROCID'))
  24. args.device_id = int(os.environ.get('SLURM_LOCALID'))
  25. except subprocess.CalledProcessError as e: # scontrol failed
  26. raise e
  27. except FileNotFoundError as e: # Slurm is not installed
  28. pass
  29. if args.distributed_init_method is None:
  30. raise ValueError('--distributed-init-method or --distributed-port '
  31. 'must be specified for distributed training')
  32. args.distributed_rank = distributed_utils.distributed_init(args)
  33. print('| initialized host {} as rank {}'.format(socket.gethostname(), args.distributed_rank))
  34. single_process_main(args)
  35. if __name__ == '__main__':
  36. parser = options.get_training_parser()
  37. args = options.parse_args_and_arch(parser)
  38. main(args)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...