File: test_script_is_torchelastic_launched.py

package info (click to toggle)
pytorch-cuda 2.6.0%2Bdfsg-7
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid, trixie
  • size: 161,620 kB
  • sloc: python: 1,278,832; cpp: 900,322; ansic: 82,710; asm: 7,754; java: 3,363; sh: 2,811; javascript: 2,443; makefile: 597; ruby: 195; xml: 84; objc: 68
file content (44 lines) | stat: -rwxr-xr-x 1,414 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env python3
# Owner(s): ["oncall: r2p"]

# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

"""
This is a test script that launches as part of the test cases in
run_test.py, to validate the correctness of
the method ``torch.distributed.is_torchelastic_launched()``. To do so,
we run this script with and without torchelastic and validate that the
boolean value written to the out_file is indeed what we expect (e.g.
should be False when not launched with torchelastic, True when launched with)
The script itself is not a test case hence no assertions are made in this script.

see: - test/distributed/launcher/run_test.py#test_is_torchelastic_launched()
     - test/distributed/launcher/run_test.py#test_is_not_torchelastic_launched()
"""
import argparse

import torch.distributed as dist


def parse_args():
    parser = argparse.ArgumentParser(description="test script")
    parser.add_argument(
        "--out-file",
        "--out_file",
        help="file to write indicating whether this script was launched with torchelastic",
    )
    return parser.parse_args()


def main():
    args = parse_args()
    with open(args.out_file, "w") as out:
        out.write(f"{dist.is_torchelastic_launched()}")


if __name__ == "__main__":
    main()