run_test.py 1.65 KB
Newer Older
Masaki Kozuki's avatar
Masaki Kozuki committed
1
2
3
4
5
6
7
8
9
10
11
12
"""L0 Tests Runner.

How to run this script?

1. Run all the tests: `python /path/to/apex/tests/L0/run_test.py`
2. Run one of the tests (e.g. fused layer norm):
    `python /path/to/apex/tests/L0/run_test.py --include run_fused_layer_norm`
3. Run two or more of the tests (e.g. optimizers and fused layer norm):
    `python /path/to/apex/tests/L0/run_test.py --include run_optimizers run_fused_layer_norm`
"""
import argparse
import os
Michael Carilli's avatar
Michael Carilli committed
13
14
15
16
import unittest
import sys


Masaki Kozuki's avatar
Masaki Kozuki committed
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
TEST_ROOT = os.path.dirname(os.path.abspath(__file__))
TEST_DIRS = [
    "run_amp",
    "run_fp16util",
    "run_optimizers",
    "run_fused_layer_norm",
    "run_mlp",
    "run_transformer",
]
DEFAULT_TEST_DIRS = [
    "run_optimizers",
    "run_fused_layer_norm",
    "run_mlp",
    "run_transformer",
]


def parse_args():
    parser = argparse.ArgumentParser(
        description="L0 test runner",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
    )
    parser.add_argument(
        "--include",
        nargs="+",
        choices=TEST_DIRS,
        default=DEFAULT_TEST_DIRS,
        help="select a set of tests to run (defaults to ALL tests).",
    )
    args, _ = parser.parse_known_args()
    return args


def main(args):
    runner = unittest.TextTestRunner(verbosity=2)
    errcode = 0
    for test_dir in args.include:
        test_dir = os.path.join(TEST_ROOT, test_dir)
        print(test_dir)
        suite = unittest.TestLoader().discover(test_dir)
Michael Carilli's avatar
Michael Carilli committed
57

Masaki Kozuki's avatar
Masaki Kozuki committed
58
        print("\nExecuting tests from " + test_dir)
Michael Carilli's avatar
Michael Carilli committed
59

Masaki Kozuki's avatar
Masaki Kozuki committed
60
        result = runner.run(suite)
Michael Carilli's avatar
Michael Carilli committed
61

Masaki Kozuki's avatar
Masaki Kozuki committed
62
63
        if not result.wasSuccessful():
            errcode = 1
Michael Carilli's avatar
Michael Carilli committed
64

Masaki Kozuki's avatar
Masaki Kozuki committed
65
    sys.exit(errcode)
Michael Carilli's avatar
Michael Carilli committed
66
67


Masaki Kozuki's avatar
Masaki Kozuki committed
68
69
70
if __name__ == '__main__':
    args = parse_args()
    main(args)