cyd0806 commited on
Commit
33305a0
·
verified ·
1 Parent(s): c1637b4

Upload apex-master/tests/L0/run_test.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. apex-master/tests/L0/run_test.py +111 -0
apex-master/tests/L0/run_test.py ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """L0 Tests Runner.
2
+
3
+ How to run this script?
4
+
5
+ 1. Run all the tests: `python /path/to/apex/tests/L0/run_test.py` If you want an xml report,
6
+ pass `--xml-report`, i.e. `python /path/to/apex/tests/L0/run_test.py --xml-report` and
7
+ the file is created in `/path/to/apex/tests/L0`.
8
+ 2. Run one of the tests (e.g. fused layer norm):
9
+ `python /path/to/apex/tests/L0/run_test.py --include run_fused_layer_norm`
10
+ 3. Run two or more of the tests (e.g. optimizers and fused layer norm):
11
+ `python /path/to/apex/tests/L0/run_test.py --include run_optimizers run_fused_layer_norm`
12
+ """
13
+ import argparse
14
+ import os
15
+ import unittest
16
+ import sys
17
+
18
+
19
+ TEST_ROOT = os.path.dirname(os.path.abspath(__file__))
20
+ TEST_DIRS = [
21
+ "run_amp",
22
+ "run_deprecated",
23
+ "run_fp16util",
24
+ "run_optimizers",
25
+ "run_fused_layer_norm",
26
+ "run_mlp",
27
+ "run_transformer",
28
+ ]
29
+ DEFAULT_TEST_DIRS = [
30
+ "run_optimizers",
31
+ "run_fused_layer_norm",
32
+ "run_mlp",
33
+ ]
34
+
35
+
36
+ def parse_args():
37
+ parser = argparse.ArgumentParser(
38
+ description="L0 test runner",
39
+ formatter_class=argparse.ArgumentDefaultsHelpFormatter,
40
+ )
41
+ parser.add_argument(
42
+ "--include",
43
+ nargs="+",
44
+ choices=TEST_DIRS,
45
+ default=DEFAULT_TEST_DIRS,
46
+ help="select a set of tests to run (defaults to ALL tests).",
47
+ )
48
+ parser.add_argument(
49
+ "--xml-report",
50
+ default=None,
51
+ action="store_true",
52
+ help="[deprecated] pass this argument to get a junit xml report. Use `--xml-dir`. (requires `xmlrunner`)",
53
+ )
54
+ parser.add_argument(
55
+ "--xml-dir",
56
+ default=None,
57
+ type=str,
58
+ help="Directory to save junit test reports. (requires `xmlrunner`)",
59
+ )
60
+ args, _ = parser.parse_known_args()
61
+ return args
62
+
63
+
64
+ def main(args: argparse.Namespace) -> None:
65
+ test_runner_kwargs = {"verbosity": 2}
66
+ Runner = unittest.TextTestRunner
67
+
68
+ xml_dir = None
69
+ if (args.xml_report is not None) or (args.xml_dir is not None):
70
+ if args.xml_report is not None:
71
+ import warnings
72
+ warnings.warn("The option of `--xml-report` is deprecated", FutureWarning)
73
+
74
+ import xmlrunner
75
+ from datetime import date # NOQA
76
+ Runner = xmlrunner.XMLTestRunner
77
+ if args.xml_report:
78
+ xml_dir = os.path.abspath(os.path.dirname(__file__))
79
+ else:
80
+ xml_dir = os.path.abspath(args.xml_dir)
81
+ if not os.path.exists(xml_dir):
82
+ os.makedirs(xml_dir)
83
+
84
+ errcode = 0
85
+ for test_dir in args.include:
86
+ if xml_dir is not None:
87
+ xml_output = os.path.join(
88
+ xml_dir,
89
+ f"""TEST_{test_dir}_{date.today().strftime("%y%m%d")}""",
90
+ )
91
+ if not os.path.exists(xml_output):
92
+ os.makedirs(xml_output)
93
+ test_runner_kwargs["output"] = xml_output
94
+
95
+ runner = Runner(**test_runner_kwargs)
96
+ test_dir = os.path.join(TEST_ROOT, test_dir)
97
+ suite = unittest.TestLoader().discover(test_dir)
98
+
99
+ print("\nExecuting tests from " + test_dir)
100
+
101
+ result = runner.run(suite)
102
+
103
+ if not result.wasSuccessful():
104
+ errcode = 1
105
+
106
+ sys.exit(errcode)
107
+
108
+
109
+ if __name__ == '__main__':
110
+ args = parse_args()
111
+ main(args)