Sam Estep | 2e26976 | 2021-05-14 08:21:46 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 2 | |
| 3 | import argparse |
Pritam Damania | 06d50b5 | 2020-10-22 10:53:07 -0700 | [diff] [blame] | 4 | import copy |
Shen Li | 1022443 | 2021-08-12 11:39:31 -0700 | [diff] [blame] | 5 | from datetime import datetime |
Eli Uriegas | 4982fc4 | 2021-08-16 15:30:24 -0700 | [diff] [blame] | 6 | from distutils.util import strtobool |
Nikita Shulga | 0776756 | 2021-12-14 09:23:21 -0800 | [diff] [blame] | 7 | from distutils.version import LooseVersion |
Rohan Varma | ddc22ea | 2021-11-22 09:51:34 -0800 | [diff] [blame] | 8 | import functools |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 9 | import os |
driazati | ab5cf5a | 2021-08-25 12:58:24 -0700 | [diff] [blame] | 10 | import pathlib |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 11 | import shutil |
Peter Goldsborough | c3f7e5f | 2018-04-10 11:31:23 -0700 | [diff] [blame] | 12 | import signal |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 13 | import subprocess |
| 14 | import sys |
| 15 | import tempfile |
| 16 | |
| 17 | import torch |
Zsolt Dollenstein | b004307 | 2021-08-12 10:56:55 -0700 | [diff] [blame] | 18 | from torch.utils import cpp_extension |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 19 | from torch.testing._internal.common_utils import ( |
| 20 | FILE_SCHEMA, |
| 21 | IS_IN_CI, |
| 22 | TEST_WITH_ROCM, |
| 23 | shell, |
| 24 | set_cwd, |
Alban Desmaison | 3d7abc0 | 2022-04-25 14:01:33 +0000 | [diff] [blame] | 25 | parser as common_parser, |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 26 | ) |
Shen Li | 1022443 | 2021-08-12 11:39:31 -0700 | [diff] [blame] | 27 | import torch.distributed as dist |
| 28 | from typing import Dict, Optional, List |
Jane Xu | c0adabe | 2021-03-05 13:34:17 -0800 | [diff] [blame] | 29 | |
driazati | ab5cf5a | 2021-08-25 12:58:24 -0700 | [diff] [blame] | 30 | REPO_ROOT = pathlib.Path(__file__).resolve().parent.parent |
| 31 | |
Jane Xu | c0adabe | 2021-03-05 13:34:17 -0800 | [diff] [blame] | 32 | try: |
Rong Rong (AI Infra) | 718db96 | 2021-07-06 09:04:49 -0700 | [diff] [blame] | 33 | # using tools/ to optimize test run. |
driazati | ab5cf5a | 2021-08-25 12:58:24 -0700 | [diff] [blame] | 34 | sys.path.append(str(REPO_ROOT)) |
Rong Rong (AI Infra) | 718db96 | 2021-07-06 09:04:49 -0700 | [diff] [blame] | 35 | from tools.testing.test_selections import ( |
| 36 | export_S3_test_times, |
| 37 | get_shard_based_on_S3, |
Nikita Shulga | 01cfea9 | 2021-09-14 09:38:34 -0700 | [diff] [blame] | 38 | # NS: Disable target determination |
| 39 | # get_slow_tests_based_on_S3, |
Rong Rong (AI Infra) | 718db96 | 2021-07-06 09:04:49 -0700 | [diff] [blame] | 40 | get_specified_test_cases, |
Rong Rong (AI Infra) | a5a10fe | 2021-07-12 11:20:12 -0700 | [diff] [blame] | 41 | get_reordered_tests, |
| 42 | get_test_case_configs, |
Rong Rong (AI Infra) | 718db96 | 2021-07-06 09:04:49 -0700 | [diff] [blame] | 43 | ) |
Nikita Shulga | 01cfea9 | 2021-09-14 09:38:34 -0700 | [diff] [blame] | 44 | # NS: Disable target determination |
| 45 | # from tools.testing.modulefinder_determinator import ( |
| 46 | # should_run_test, |
| 47 | # TARGET_DET_LIST, |
| 48 | # ) |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 49 | |
Rong Rong (AI Infra) | 718db96 | 2021-07-06 09:04:49 -0700 | [diff] [blame] | 50 | HAVE_TEST_SELECTION_TOOLS = True |
Jane Xu | c0adabe | 2021-03-05 13:34:17 -0800 | [diff] [blame] | 51 | except ImportError: |
Rong Rong (AI Infra) | 718db96 | 2021-07-06 09:04:49 -0700 | [diff] [blame] | 52 | HAVE_TEST_SELECTION_TOOLS = False |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 53 | print( |
| 54 | "Unable to import test_selections from tools/testing. Running without test selection stats..." |
| 55 | ) |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 56 | |
Jane Xu | f30a7a2 | 2021-03-17 12:19:27 -0700 | [diff] [blame] | 57 | |
Nikita Shulga | c2da103 | 2021-08-31 17:19:11 -0700 | [diff] [blame] | 58 | def discover_tests( |
| 59 | base_dir: Optional[pathlib.Path] = None, |
| 60 | blocklisted_patterns: Optional[List[str]] = None, |
| 61 | blocklisted_tests: Optional[List[str]] = None, |
| 62 | extra_tests: Optional[List[str]] = None) -> List[str]: |
| 63 | """ |
| 64 | Searches for all python files starting with test_ excluding one specified by patterns |
| 65 | """ |
| 66 | def skip_test_p(name: str) -> bool: |
| 67 | rc = False |
| 68 | if blocklisted_patterns is not None: |
| 69 | rc |= any(name.startswith(pattern) for pattern in blocklisted_patterns) |
| 70 | if blocklisted_tests is not None: |
| 71 | rc |= name in blocklisted_tests |
| 72 | return rc |
| 73 | cwd = pathlib.Path(__file__).resolve().parent if base_dir is None else base_dir |
| 74 | all_py_files = list(cwd.glob('**/test_*.py')) |
| 75 | rc = [str(fname.relative_to(cwd))[:-3] for fname in all_py_files] |
| 76 | # Invert slashes on Windows |
| 77 | if sys.platform == "win32": |
| 78 | rc = [name.replace('\\', '/') for name in rc] |
| 79 | rc = [test for test in rc if not skip_test_p(test)] |
| 80 | if extra_tests is not None: |
| 81 | rc += extra_tests |
| 82 | return sorted(rc) |
| 83 | |
Nikita Shulga | c2da103 | 2021-08-31 17:19:11 -0700 | [diff] [blame] | 84 | TESTS = discover_tests( |
| 85 | blocklisted_patterns=[ |
| 86 | 'ao', |
| 87 | 'bottleneck_test', |
| 88 | 'custom_backend', |
| 89 | 'custom_operator', |
wushirong | 4d01789 | 2022-02-10 10:42:24 -0800 | [diff] [blame] | 90 | 'fx', # executed by test_fx.py |
Nikita Shulga | c2da103 | 2021-08-31 17:19:11 -0700 | [diff] [blame] | 91 | 'jit', # executed by test_jit.py |
| 92 | 'mobile', |
| 93 | 'onnx', |
| 94 | 'package', # executed by test_package.py |
| 95 | 'quantization', # executed by test_quantization.py |
Alban Desmaison | 701fa16 | 2022-03-01 11:15:30 -0500 | [diff] [blame] | 96 | 'autograd', # executed by test_autograd.py |
Nikita Shulga | c2da103 | 2021-08-31 17:19:11 -0700 | [diff] [blame] | 97 | ], |
| 98 | blocklisted_tests=[ |
| 99 | 'test_bundled_images', |
| 100 | 'test_cpp_extensions_aot', |
Nikita Shulga | 01cfea9 | 2021-09-14 09:38:34 -0700 | [diff] [blame] | 101 | 'test_determination', |
Nikita Shulga | c2da103 | 2021-08-31 17:19:11 -0700 | [diff] [blame] | 102 | 'test_jit_fuser', |
| 103 | 'test_jit_simple', |
| 104 | 'test_jit_string', |
| 105 | 'test_kernel_launch_checks', |
| 106 | 'test_metal', |
| 107 | 'test_nnapi', |
Nikita Shulga | c2da103 | 2021-08-31 17:19:11 -0700 | [diff] [blame] | 108 | 'test_segment_reductions', |
| 109 | 'test_static_runtime', |
| 110 | 'test_throughput_benchmark', |
| 111 | 'test_typing', |
| 112 | "distributed/algorithms/ddp_comm_hooks/test_ddp_hooks", |
| 113 | "distributed/algorithms/quantization/test_quantization", |
| 114 | "distributed/bin/test_script", |
| 115 | "distributed/elastic/multiprocessing/bin/test_script", |
| 116 | "distributed/launcher/bin/test_script", |
| 117 | "distributed/launcher/bin/test_script_init_method", |
| 118 | "distributed/launcher/bin/test_script_is_torchelastic_launched", |
| 119 | "distributed/launcher/bin/test_script_local_rank", |
| 120 | "distributed/test_c10d_spawn", |
| 121 | 'distributions/test_transforms', |
| 122 | 'distributions/test_utils', |
| 123 | ], |
| 124 | extra_tests=[ |
| 125 | "test_cpp_extensions_aot_ninja", |
| 126 | "test_cpp_extensions_aot_no_ninja", |
| 127 | "distributed/elastic/timer/api_test", |
| 128 | "distributed/elastic/timer/local_timer_example", |
| 129 | "distributed/elastic/timer/local_timer_test", |
| 130 | "distributed/elastic/events/lib_test", |
| 131 | "distributed/elastic/metrics/api_test", |
| 132 | "distributed/elastic/utils/logging_test", |
| 133 | "distributed/elastic/utils/util_test", |
| 134 | "distributed/elastic/utils/distributed_test", |
| 135 | "distributed/elastic/multiprocessing/api_test", |
Sahan Paliskara | 0bfa2f8 | 2022-03-17 05:12:14 -0700 | [diff] [blame] | 136 | "test_deploy", |
Nikita Shulga | c2da103 | 2021-08-31 17:19:11 -0700 | [diff] [blame] | 137 | ] |
| 138 | ) |
Pritam Damania | 06d50b5 | 2020-10-22 10:53:07 -0700 | [diff] [blame] | 139 | |
Yanli Zhao | 61fca03 | 2021-10-07 09:05:05 -0700 | [diff] [blame] | 140 | FSDP_TEST = [test for test in TESTS if test.startswith("distributed/fsdp")] |
| 141 | |
Pritam Damania | 06d50b5 | 2020-10-22 10:53:07 -0700 | [diff] [blame] | 142 | # Tests need to be run with pytest. |
| 143 | USE_PYTEST_LIST = [ |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 144 | "distributed/pipeline/sync/skip/test_api", |
| 145 | "distributed/pipeline/sync/skip/test_gpipe", |
| 146 | "distributed/pipeline/sync/skip/test_inspect_skip_layout", |
| 147 | "distributed/pipeline/sync/skip/test_leak", |
| 148 | "distributed/pipeline/sync/skip/test_portal", |
| 149 | "distributed/pipeline/sync/skip/test_stash_pop", |
| 150 | "distributed/pipeline/sync/skip/test_tracker", |
| 151 | "distributed/pipeline/sync/skip/test_verify_skippables", |
| 152 | "distributed/pipeline/sync/test_balance", |
| 153 | "distributed/pipeline/sync/test_bugs", |
| 154 | "distributed/pipeline/sync/test_checkpoint", |
| 155 | "distributed/pipeline/sync/test_copy", |
| 156 | "distributed/pipeline/sync/test_deferred_batch_norm", |
| 157 | "distributed/pipeline/sync/test_dependency", |
| 158 | "distributed/pipeline/sync/test_inplace", |
| 159 | "distributed/pipeline/sync/test_microbatch", |
| 160 | "distributed/pipeline/sync/test_phony", |
| 161 | "distributed/pipeline/sync/test_pipe", |
| 162 | "distributed/pipeline/sync/test_pipeline", |
| 163 | "distributed/pipeline/sync/test_stream", |
| 164 | "distributed/pipeline/sync/test_transparency", |
| 165 | "distributed/pipeline/sync/test_worker", |
| 166 | "distributions/test_constraints", |
| 167 | "distributions/test_transforms", |
| 168 | "distributions/test_utils", |
| 169 | "test_typing", |
Aliaksandr Ivanou | ec48498 | 2021-03-11 11:16:25 -0800 | [diff] [blame] | 170 | "distributed/elastic/events/lib_test", |
Aliaksandr Ivanou | 5c8ceef | 2021-04-29 06:11:18 -0700 | [diff] [blame] | 171 | "distributed/elastic/agent/server/test/api_test", |
Sahan Paliskara | 0bfa2f8 | 2022-03-17 05:12:14 -0700 | [diff] [blame] | 172 | "test_deploy", |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 173 | ] |
Elias Ellison | 277cd74 | 2019-08-26 13:56:53 -0700 | [diff] [blame] | 174 | |
Noman Arshad | 1a8269a | 2020-07-28 07:51:28 -0700 | [diff] [blame] | 175 | WINDOWS_BLOCKLIST = [ |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 176 | "distributed/nn/jit/test_instantiator", |
| 177 | "distributed/rpc/test_faulty_agent", |
| 178 | "distributed/rpc/test_tensorpipe_agent", |
| 179 | "distributed/rpc/cuda/test_tensorpipe_agent", |
| 180 | "distributed/pipeline/sync/skip/test_api", |
| 181 | "distributed/pipeline/sync/skip/test_gpipe", |
| 182 | "distributed/pipeline/sync/skip/test_inspect_skip_layout", |
| 183 | "distributed/pipeline/sync/skip/test_leak", |
| 184 | "distributed/pipeline/sync/skip/test_portal", |
| 185 | "distributed/pipeline/sync/skip/test_stash_pop", |
| 186 | "distributed/pipeline/sync/skip/test_tracker", |
| 187 | "distributed/pipeline/sync/skip/test_verify_skippables", |
| 188 | "distributed/pipeline/sync/test_balance", |
| 189 | "distributed/pipeline/sync/test_bugs", |
| 190 | "distributed/pipeline/sync/test_checkpoint", |
| 191 | "distributed/pipeline/sync/test_copy", |
| 192 | "distributed/pipeline/sync/test_deferred_batch_norm", |
| 193 | "distributed/pipeline/sync/test_dependency", |
| 194 | "distributed/pipeline/sync/test_inplace", |
| 195 | "distributed/pipeline/sync/test_microbatch", |
| 196 | "distributed/pipeline/sync/test_phony", |
| 197 | "distributed/pipeline/sync/test_pipe", |
| 198 | "distributed/pipeline/sync/test_pipeline", |
| 199 | "distributed/pipeline/sync/test_stream", |
| 200 | "distributed/pipeline/sync/test_transparency", |
| 201 | "distributed/pipeline/sync/test_worker", |
Aliaksandr Ivanou | 5c8ceef | 2021-04-29 06:11:18 -0700 | [diff] [blame] | 202 | "distributed/elastic/agent/server/test/api_test", |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 203 | "distributed/elastic/multiprocessing/api_test", |
pritam | 37eb315 | 2022-05-21 22:33:58 +0000 | [diff] [blame] | 204 | "distributed/_shard/checkpoint/test_checkpoint" |
| 205 | "distributed/_shard/checkpoint/test_file_system_checkpoint" |
Pritam Damania | 64670e4 | 2022-02-01 22:53:18 -0800 | [diff] [blame] | 206 | "distributed/_shard/sharding_spec/test_sharding_spec", |
Wanchao Liang | 78ea86a | 2022-04-25 05:55:24 -0700 | [diff] [blame] | 207 | "distributed/_shard/sharding_plan/test_sharding_plan", |
Junjie Wang (PyTorch) | 8854739 | 2022-02-02 22:06:43 -0800 | [diff] [blame] | 208 | "distributed/_shard/sharded_tensor/test_megatron_prototype", |
Pritam Damania | 64670e4 | 2022-02-01 22:53:18 -0800 | [diff] [blame] | 209 | "distributed/_shard/sharded_tensor/test_sharded_tensor", |
Junjie Wang (PyTorch) | 19d0de8 | 2022-02-02 21:20:44 -0800 | [diff] [blame] | 210 | "distributed/_shard/sharded_tensor/test_sharded_tensor_reshard", |
Junjie Wang (PyTorch) | 7c44d56 | 2022-05-03 10:09:21 -0700 | [diff] [blame] | 211 | "distributed/_shard/sharded_tensor/ops/test_chunk", |
Junjie Wang (PyTorch) | 8854739 | 2022-02-02 22:06:43 -0800 | [diff] [blame] | 212 | "distributed/_shard/sharded_tensor/ops/test_elementwise_ops", |
Pritam Damania | 64670e4 | 2022-02-01 22:53:18 -0800 | [diff] [blame] | 213 | "distributed/_shard/sharded_tensor/ops/test_embedding", |
| 214 | "distributed/_shard/sharded_tensor/ops/test_embedding_bag", |
| 215 | "distributed/_shard/sharded_tensor/ops/test_binary_cmp", |
| 216 | "distributed/_shard/sharded_tensor/ops/test_init", |
| 217 | "distributed/_shard/sharded_tensor/ops/test_linear", |
wanchaol | be354d8 | 2022-04-11 14:56:45 -0700 | [diff] [blame] | 218 | "distributed/_shard/sharded_tensor/ops/test_math_ops", |
Junjie Wang (PyTorch) | 7c44d56 | 2022-05-03 10:09:21 -0700 | [diff] [blame] | 219 | "distributed/_shard/sharded_tensor/ops/test_matrix_ops", |
pritam | 9e52b50 | 2022-05-06 09:04:08 -0700 | [diff] [blame] | 220 | "distributed/_shard/sharded_tensor/ops/test_softmax", |
Pritam Damania | 64670e4 | 2022-02-01 22:53:18 -0800 | [diff] [blame] | 221 | "distributed/_shard/sharded_optim/test_sharded_optim", |
Junjie Wang (PyTorch) | c1037d0 | 2022-04-27 23:17:28 -0700 | [diff] [blame] | 222 | "distributed/_shard/test_partial_tensor", |
Wanchao Liang | 0524b28 | 2022-03-24 05:36:04 -0700 | [diff] [blame] | 223 | "distributed/_shard/test_replicated_tensor", |
wushirong | 4d01789 | 2022-02-10 10:42:24 -0800 | [diff] [blame] | 224 | ] + FSDP_TEST |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 225 | |
Noman Arshad | 1a8269a | 2020-07-28 07:51:28 -0700 | [diff] [blame] | 226 | ROCM_BLOCKLIST = [ |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 227 | "distributed/nn/jit/test_instantiator", |
| 228 | "distributed/rpc/test_faulty_agent", |
| 229 | "distributed/rpc/test_tensorpipe_agent", |
| 230 | "distributed/rpc/cuda/test_tensorpipe_agent", |
pritam | 37eb315 | 2022-05-21 22:33:58 +0000 | [diff] [blame] | 231 | "distributed/_shard/checkpoint/test_checkpoint" |
| 232 | "distributed/_shard/checkpoint/test_file_system_checkpoint" |
Wanchao Liang | 78ea86a | 2022-04-25 05:55:24 -0700 | [diff] [blame] | 233 | "distributed/_shard/sharding_spec/test_sharding_spec", |
| 234 | "distributed/_shard/sharding_plan/test_sharding_plan", |
Junjie Wang (PyTorch) | 8854739 | 2022-02-02 22:06:43 -0800 | [diff] [blame] | 235 | "distributed/_shard/sharded_tensor/test_megatron_prototype", |
Pritam Damania | 64670e4 | 2022-02-01 22:53:18 -0800 | [diff] [blame] | 236 | "distributed/_shard/sharded_tensor/test_sharded_tensor", |
Junjie Wang (PyTorch) | 19d0de8 | 2022-02-02 21:20:44 -0800 | [diff] [blame] | 237 | "distributed/_shard/sharded_tensor/test_sharded_tensor_reshard", |
Junjie Wang (PyTorch) | 7c44d56 | 2022-05-03 10:09:21 -0700 | [diff] [blame] | 238 | "distributed/_shard/sharded_tensor/ops/test_chunk", |
Junjie Wang (PyTorch) | 8854739 | 2022-02-02 22:06:43 -0800 | [diff] [blame] | 239 | "distributed/_shard/sharded_tensor/ops/test_elementwise_ops", |
Pritam Damania | 64670e4 | 2022-02-01 22:53:18 -0800 | [diff] [blame] | 240 | "distributed/_shard/sharded_tensor/ops/test_embedding", |
| 241 | "distributed/_shard/sharded_tensor/ops/test_embedding_bag", |
| 242 | "distributed/_shard/sharded_tensor/ops/test_binary_cmp", |
| 243 | "distributed/_shard/sharded_tensor/ops/test_init", |
| 244 | "distributed/_shard/sharded_tensor/ops/test_linear", |
wanchaol | be354d8 | 2022-04-11 14:56:45 -0700 | [diff] [blame] | 245 | "distributed/_shard/sharded_tensor/ops/test_math_ops", |
Junjie Wang (PyTorch) | 7c44d56 | 2022-05-03 10:09:21 -0700 | [diff] [blame] | 246 | "distributed/_shard/sharded_tensor/ops/test_matrix_ops", |
pritam | 9e52b50 | 2022-05-06 09:04:08 -0700 | [diff] [blame] | 247 | "distributed/_shard/sharded_tensor/ops/test_softmax", |
Pritam Damania | 64670e4 | 2022-02-01 22:53:18 -0800 | [diff] [blame] | 248 | "distributed/_shard/sharded_optim/test_sharded_optim", |
Junjie Wang (PyTorch) | c1037d0 | 2022-04-27 23:17:28 -0700 | [diff] [blame] | 249 | "distributed/_shard/test_partial_tensor", |
Wanchao Liang | 0524b28 | 2022-03-24 05:36:04 -0700 | [diff] [blame] | 250 | "distributed/_shard/test_replicated_tensor", |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 251 | "test_determination", |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 252 | "test_jit_legacy", |
| 253 | "test_type_hints", |
| 254 | "test_openmp", |
Jeff Daily | 44bbb24 | 2022-04-22 19:50:36 +0000 | [diff] [blame] | 255 | ] |
iotamudelta | a38b572 | 2018-08-06 14:48:45 -0700 | [diff] [blame] | 256 | |
Noman Arshad | 1a8269a | 2020-07-28 07:51:28 -0700 | [diff] [blame] | 257 | RUN_PARALLEL_BLOCKLIST = [ |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 258 | "test_cpp_extensions_jit", |
| 259 | "test_jit_disabled", |
| 260 | "test_mobile_optimizer", |
| 261 | "test_multiprocessing", |
| 262 | "test_multiprocessing_spawn", |
| 263 | "test_namedtuple_return_api", |
| 264 | "test_overrides", |
| 265 | "test_show_pickle", |
| 266 | "test_tensorexpr", |
| 267 | "test_cuda_primary_ctx", |
Yanli Zhao | 61fca03 | 2021-10-07 09:05:05 -0700 | [diff] [blame] | 268 | ] + FSDP_TEST |
Nikita Shulga | 72e5b7a | 2020-05-06 22:08:45 -0700 | [diff] [blame] | 269 | |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 270 | WINDOWS_COVERAGE_BLOCKLIST = [] |
peter | a1b1d0cd | 2021-01-19 14:57:07 -0800 | [diff] [blame] | 271 | |
Jane Xu | 1354ee4 | 2021-08-26 09:27:47 -0700 | [diff] [blame] | 272 | # A subset of our TEST list that validates PyTorch's ops, modules, and autograd function as expected |
| 273 | CORE_TEST_LIST = [ |
| 274 | "test_autograd", |
| 275 | "test_modules", |
| 276 | "test_nn", |
| 277 | "test_ops", |
atalman | ebca80e | 2022-03-17 02:07:50 +0000 | [diff] [blame] | 278 | "test_ops_gradients", |
| 279 | "test_ops_jit", |
Jane Xu | 1354ee4 | 2021-08-26 09:27:47 -0700 | [diff] [blame] | 280 | "test_torch" |
| 281 | ] |
Neeraj Pradhan | faa9c22 | 2020-10-13 10:54:18 -0700 | [diff] [blame] | 282 | |
Jane Xu | 0645e2b | 2021-03-18 13:19:39 -0700 | [diff] [blame] | 283 | # the JSON file to store the S3 test stats |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 284 | TEST_TIMES_FILE = ".pytorch-test-times.json" |
Jane Xu | 0645e2b | 2021-03-18 13:19:39 -0700 | [diff] [blame] | 285 | |
Jane Xu | bcbe072 | 2021-03-10 09:33:02 -0800 | [diff] [blame] | 286 | # if a test file takes longer than 5 min, we add it to TARGET_DET_LIST |
| 287 | SLOW_TEST_THRESHOLD = 300 |
| 288 | |
Pieter Noordhuis | e4cd807 | 2019-09-11 02:17:48 -0700 | [diff] [blame] | 289 | DISTRIBUTED_TESTS_CONFIG = {} |
Teng Li | 56539f5 | 2018-08-29 12:54:55 -0700 | [diff] [blame] | 290 | |
| 291 | |
Teng Li | 0988bba | 2018-09-10 23:21:36 -0700 | [diff] [blame] | 292 | if dist.is_available(): |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 293 | DISTRIBUTED_TESTS_CONFIG["test"] = {"WORLD_SIZE": "1"} |
Jithun Nair | 3c4cec5 | 2020-02-10 12:36:56 -0800 | [diff] [blame] | 294 | if not TEST_WITH_ROCM and dist.is_mpi_available(): |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 295 | DISTRIBUTED_TESTS_CONFIG["mpi"] = { |
| 296 | "WORLD_SIZE": "3", |
| 297 | "TEST_REPORT_SOURCE_OVERRIDE": "dist-mpi", |
Teng Li | 56539f5 | 2018-08-29 12:54:55 -0700 | [diff] [blame] | 298 | } |
Teng Li | 0988bba | 2018-09-10 23:21:36 -0700 | [diff] [blame] | 299 | if dist.is_nccl_available(): |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 300 | DISTRIBUTED_TESTS_CONFIG["nccl"] = { |
| 301 | "WORLD_SIZE": "2" if torch.cuda.device_count() == 2 else "3", |
| 302 | "TEST_REPORT_SOURCE_OVERRIDE": "dist-nccl", |
Teng Li | 56539f5 | 2018-08-29 12:54:55 -0700 | [diff] [blame] | 303 | } |
Jithun Nair | f1c9856 | 2020-11-25 19:50:30 -0800 | [diff] [blame] | 304 | if dist.is_gloo_available(): |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 305 | DISTRIBUTED_TESTS_CONFIG["gloo"] = { |
| 306 | "WORLD_SIZE": "2" if torch.cuda.device_count() == 2 else "3", |
| 307 | "TEST_REPORT_SOURCE_OVERRIDE": "dist-gloo", |
Pieter Noordhuis | e4cd807 | 2019-09-11 02:17:48 -0700 | [diff] [blame] | 308 | } |
Teng Li | 56539f5 | 2018-08-29 12:54:55 -0700 | [diff] [blame] | 309 | |
Peter Goldsborough | c3f7e5f | 2018-04-10 11:31:23 -0700 | [diff] [blame] | 310 | # https://stackoverflow.com/questions/2549939/get-signal-names-from-numbers-in-python |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 311 | SIGNALS_TO_NAMES_DICT = { |
| 312 | getattr(signal, n): n for n in dir(signal) if n.startswith("SIG") and "_" not in n |
| 313 | } |
Peter Goldsborough | c3f7e5f | 2018-04-10 11:31:23 -0700 | [diff] [blame] | 314 | |
Peter Goldsborough | 7978ba4 | 2018-11-07 14:27:06 -0800 | [diff] [blame] | 315 | CPP_EXTENSIONS_ERROR = """ |
Richard Zou | 6209412 | 2020-02-05 18:44:19 -0800 | [diff] [blame] | 316 | Ninja (https://ninja-build.org) is required for some of the C++ extensions |
| 317 | tests, but it could not be found. Install ninja with `pip install ninja` |
| 318 | or `conda install ninja`. Alternatively, disable said tests with |
ashish | 616beb1 | 2020-02-21 12:07:51 -0800 | [diff] [blame] | 319 | `run_test.py --exclude test_cpp_extensions_aot_ninja test_cpp_extensions_jit`. |
Peter Goldsborough | 7978ba4 | 2018-11-07 14:27:06 -0800 | [diff] [blame] | 320 | """ |
| 321 | |
Nikita Shulga | 1bda5e4 | 2020-08-26 16:14:17 -0700 | [diff] [blame] | 322 | PYTORCH_COLLECT_COVERAGE = bool(os.environ.get("PYTORCH_COLLECT_COVERAGE")) |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 323 | |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 324 | ENABLE_PR_HISTORY_REORDERING = bool( |
| 325 | os.environ.get("ENABLE_PR_HISTORY_REORDERING", "0") == "1" |
| 326 | ) |
Rong Rong (AI Infra) | b2fc6de | 2021-06-16 13:31:14 -0700 | [diff] [blame] | 327 | |
Jane Xu | 8bc0c75 | 2020-10-06 07:11:37 -0700 | [diff] [blame] | 328 | JIT_EXECUTOR_TESTS = [ |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 329 | "test_jit_profiling", |
| 330 | "test_jit_legacy", |
| 331 | "test_jit_fuser_legacy", |
Jane Xu | ba78eb8 | 2020-10-12 11:56:17 -0700 | [diff] [blame] | 332 | ] |
Jane Xu | 8bc0c75 | 2020-10-06 07:11:37 -0700 | [diff] [blame] | 333 | |
Alban Desmaison | f275b3f | 2022-03-01 11:15:30 -0500 | [diff] [blame] | 334 | DISTRIBUTED_TESTS = [test for test in TESTS if test.startswith("distributed")] |
Rong Rong (AI Infra) | f4aff3a | 2021-08-24 08:01:36 -0700 | [diff] [blame] | 335 | |
Ilya Persky | 1b08929 | 2022-02-15 08:33:59 -0800 | [diff] [blame] | 336 | TESTS_REQUIRING_LAPACK = [ |
| 337 | "distributions/test_constraints", |
| 338 | "distributions/test_distributions", |
| 339 | ] |
| 340 | |
Jane Xu | 97dfc7e | 2021-06-08 15:59:32 -0700 | [diff] [blame] | 341 | # Dictionary matching test modules (in TESTS) to lists of test cases (within that test_module) that would be run when |
| 342 | # options.run_specified_test_cases is enabled. |
| 343 | # For example: |
| 344 | # { |
| 345 | # "test_nn": ["test_doubletensor_avg_pool3d", "test_share_memory", "test_hook_requires_grad"], |
| 346 | # ... |
| 347 | # } |
Rong Rong | e41bc31 | 2021-06-11 13:56:06 -0700 | [diff] [blame] | 348 | # then for test_nn.py, we would ONLY run test_doubletensor_avg_pool3d, test_share_memory, and test_hook_requires_grad. |
Jane Xu | 97dfc7e | 2021-06-08 15:59:32 -0700 | [diff] [blame] | 349 | SPECIFIED_TEST_CASES_DICT: Dict[str, List[str]] = {} |
| 350 | |
| 351 | # The file from which the SPECIFIED_TEST_CASES_DICT will be filled, a CSV of test cases that would be run when |
| 352 | # options.run_specified_test_cases is enabled. |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 353 | SPECIFIED_TEST_CASES_FILE: str = ".pytorch_specified_test_cases.csv" |
Jane Xu | 97dfc7e | 2021-06-08 15:59:32 -0700 | [diff] [blame] | 354 | |
| 355 | |
Peter Goldsborough | 4613eef | 2018-03-14 22:12:51 -0700 | [diff] [blame] | 356 | def print_to_stderr(message): |
Peter Goldsborough | 4613eef | 2018-03-14 22:12:51 -0700 | [diff] [blame] | 357 | print(message, file=sys.stderr) |
| 358 | |
| 359 | |
Jane Xu | 97dfc7e | 2021-06-08 15:59:32 -0700 | [diff] [blame] | 360 | def get_test_case_args(test_module, using_pytest) -> List[str]: |
Jane Xu | 97dfc7e | 2021-06-08 15:59:32 -0700 | [diff] [blame] | 361 | args = [] |
Rong Rong | e41bc31 | 2021-06-11 13:56:06 -0700 | [diff] [blame] | 362 | # if test_module not specified or specified with '__all__' then run all tests |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 363 | if ( |
| 364 | test_module not in SPECIFIED_TEST_CASES_DICT |
| 365 | or "__all__" in SPECIFIED_TEST_CASES_DICT[test_module] |
| 366 | ): |
Rong Rong | e41bc31 | 2021-06-11 13:56:06 -0700 | [diff] [blame] | 367 | return args |
Jane Xu | 97dfc7e | 2021-06-08 15:59:32 -0700 | [diff] [blame] | 368 | |
| 369 | if using_pytest: |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 370 | args.append("-k") |
| 371 | args.append(" or ".join(SPECIFIED_TEST_CASES_DICT[test_module])) |
Jane Xu | 97dfc7e | 2021-06-08 15:59:32 -0700 | [diff] [blame] | 372 | else: |
| 373 | for test in SPECIFIED_TEST_CASES_DICT[test_module]: |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 374 | args.append("-k") |
Jane Xu | 97dfc7e | 2021-06-08 15:59:32 -0700 | [diff] [blame] | 375 | args.append(test) |
| 376 | |
| 377 | return args |
| 378 | |
| 379 | |
peter | a1b1d0cd | 2021-01-19 14:57:07 -0800 | [diff] [blame] | 380 | def get_executable_command(options, allow_pytest, disable_coverage=False): |
| 381 | if options.coverage and not disable_coverage: |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 382 | executable = ["coverage", "run", "--parallel-mode", "--source=torch"] |
Alexander Grund | 8649241 | 2020-07-28 08:12:41 -0700 | [diff] [blame] | 383 | else: |
| 384 | executable = [sys.executable] |
| 385 | if options.pytest: |
| 386 | if allow_pytest: |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 387 | executable += ["-m", "pytest"] |
Alexander Grund | 8649241 | 2020-07-28 08:12:41 -0700 | [diff] [blame] | 388 | else: |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 389 | print_to_stderr( |
| 390 | "Pytest cannot be used for this test. Falling back to unittest." |
| 391 | ) |
Alexander Grund | 8649241 | 2020-07-28 08:12:41 -0700 | [diff] [blame] | 392 | return executable |
| 393 | |
| 394 | |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 395 | def run_test( |
| 396 | test_module, test_directory, options, launcher_cmd=None, extra_unittest_args=None |
| 397 | ): |
Nikita Shulga | fc51047 | 2020-09-09 15:07:27 -0700 | [diff] [blame] | 398 | unittest_args = options.additional_unittest_args.copy() |
Tongzhou Wang | 0d5e4a2 | 2018-09-03 19:55:58 -0700 | [diff] [blame] | 399 | if options.verbose: |
Sam Estep | c4a6df9 | 2020-11-19 07:57:09 -0800 | [diff] [blame] | 400 | unittest_args.append(f'-{"v"*options.verbose}') # in case of pytest |
Noman Arshad | 1a8269a | 2020-07-28 07:51:28 -0700 | [diff] [blame] | 401 | if test_module in RUN_PARALLEL_BLOCKLIST: |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 402 | unittest_args = [ |
| 403 | arg for arg in unittest_args if not arg.startswith("--run-parallel") |
| 404 | ] |
Alexander Grund | 8649241 | 2020-07-28 08:12:41 -0700 | [diff] [blame] | 405 | if extra_unittest_args: |
| 406 | assert isinstance(extra_unittest_args, list) |
| 407 | unittest_args.extend(extra_unittest_args) |
Pritam Damania | 78de12f | 2020-10-29 15:18:05 -0700 | [diff] [blame] | 408 | |
| 409 | # If using pytest, replace -f with equivalent -x |
| 410 | if options.pytest: |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 411 | unittest_args = [arg if arg != "-f" else "-x" for arg in unittest_args] |
Rong Rong (AI Infra) | a5a10fe | 2021-07-12 11:20:12 -0700 | [diff] [blame] | 412 | elif IS_IN_CI: |
| 413 | # use the downloaded test cases configuration, not supported in pytest |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 414 | unittest_args.extend(["--import-slow-tests", "--import-disabled-tests"]) |
Pritam Damania | 78de12f | 2020-10-29 15:18:05 -0700 | [diff] [blame] | 415 | |
peter | a1b1d0cd | 2021-01-19 14:57:07 -0800 | [diff] [blame] | 416 | # Multiprocessing related tests cannot run with coverage. |
lixinyu | 5ed0ad4 | 2021-01-28 17:42:22 -0800 | [diff] [blame] | 417 | # Tracking issue: https://github.com/pytorch/pytorch/issues/50661 |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 418 | disable_coverage = ( |
| 419 | sys.platform == "win32" and test_module in WINDOWS_COVERAGE_BLOCKLIST |
| 420 | ) |
peter | a1b1d0cd | 2021-01-19 14:57:07 -0800 | [diff] [blame] | 421 | |
Alexander Grund | 8649241 | 2020-07-28 08:12:41 -0700 | [diff] [blame] | 422 | # Extra arguments are not supported with pytest |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 423 | executable = get_executable_command( |
| 424 | options, allow_pytest=not extra_unittest_args, disable_coverage=disable_coverage |
| 425 | ) |
Alexander Grund | 8649241 | 2020-07-28 08:12:41 -0700 | [diff] [blame] | 426 | |
Rong Rong | e41bc31 | 2021-06-11 13:56:06 -0700 | [diff] [blame] | 427 | # TODO: move this logic into common_utils.py instead of passing in "-k" individually |
Jane Xu | 97dfc7e | 2021-06-08 15:59:32 -0700 | [diff] [blame] | 428 | # The following logic for running specified tests will only run for non-distributed tests, as those are dispatched |
| 429 | # to test_distributed and not run_test (this function) |
| 430 | if options.run_specified_test_cases: |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 431 | unittest_args.extend(get_test_case_args(test_module, "pytest" in executable)) |
Jane Xu | 97dfc7e | 2021-06-08 15:59:32 -0700 | [diff] [blame] | 432 | |
| 433 | # Can't call `python -m unittest test_*` here because it doesn't run code |
| 434 | # in `if __name__ == '__main__': `. So call `python test_*.py` instead. |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 435 | argv = [test_module + ".py"] + unittest_args |
Jane Xu | 97dfc7e | 2021-06-08 15:59:32 -0700 | [diff] [blame] | 436 | |
Alexander Grund | 8649241 | 2020-07-28 08:12:41 -0700 | [diff] [blame] | 437 | command = (launcher_cmd or []) + executable + argv |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 438 | print_to_stderr("Executing {} ... [{}]".format(command, datetime.now())) |
Junjie Bai | ef499cd | 2019-04-19 09:47:52 -0700 | [diff] [blame] | 439 | return shell(command, test_directory) |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 440 | |
| 441 | |
Alexander Grund | 8649241 | 2020-07-28 08:12:41 -0700 | [diff] [blame] | 442 | def test_cuda_primary_ctx(test_module, test_directory, options): |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 443 | return run_test( |
| 444 | test_module, test_directory, options, extra_unittest_args=["--subprocess"] |
| 445 | ) |
SsnL | 8482efb | 2019-07-16 10:05:53 -0700 | [diff] [blame] | 446 | |
Rohan Varma | ddc22ea | 2021-11-22 09:51:34 -0800 | [diff] [blame] | 447 | run_test_with_subprocess = functools.partial(run_test, extra_unittest_args=["--subprocess"]) |
| 448 | |
| 449 | |
Rohan Varma | 9554ebe | 2021-11-22 09:51:34 -0800 | [diff] [blame] | 450 | def get_run_test_with_subprocess_fn(): |
| 451 | return lambda test_module, test_directory, options: run_test_with_subprocess(test_module, test_directory, options) |
| 452 | |
| 453 | |
Richard Zou | 6209412 | 2020-02-05 18:44:19 -0800 | [diff] [blame] | 454 | |
Rong Rong (AI Infra) | 40d2fe1 | 2021-06-24 09:19:16 -0700 | [diff] [blame] | 455 | def _test_cpp_extensions_aot(test_directory, options, use_ninja): |
Richard Zou | 6209412 | 2020-02-05 18:44:19 -0800 | [diff] [blame] | 456 | if use_ninja: |
| 457 | try: |
| 458 | cpp_extension.verify_ninja_availability() |
| 459 | except RuntimeError: |
| 460 | print(CPP_EXTENSIONS_ERROR) |
| 461 | return 1 |
| 462 | |
| 463 | # Wipe the build folder, if it exists already |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 464 | cpp_extensions_test_dir = os.path.join(test_directory, "cpp_extensions") |
| 465 | cpp_extensions_test_build_dir = os.path.join(cpp_extensions_test_dir, "build") |
Richard Zou | 6209412 | 2020-02-05 18:44:19 -0800 | [diff] [blame] | 466 | if os.path.exists(cpp_extensions_test_build_dir): |
| 467 | shutil.rmtree(cpp_extensions_test_build_dir) |
| 468 | |
| 469 | # Build the test cpp extensions modules |
| 470 | shell_env = os.environ.copy() |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 471 | shell_env["USE_NINJA"] = str(1 if use_ninja else 0) |
| 472 | cmd = [sys.executable, "setup.py", "install", "--root", "./install"] |
Richard Zou | 6209412 | 2020-02-05 18:44:19 -0800 | [diff] [blame] | 473 | return_code = shell(cmd, cwd=cpp_extensions_test_dir, env=shell_env) |
Peter Goldsborough | c3f7e5f | 2018-04-10 11:31:23 -0700 | [diff] [blame] | 474 | if return_code != 0: |
| 475 | return return_code |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 476 | if sys.platform != "win32": |
| 477 | return_code = shell( |
| 478 | cmd, |
| 479 | cwd=os.path.join(cpp_extensions_test_dir, "no_python_abi_suffix_test"), |
| 480 | env=shell_env, |
| 481 | ) |
Peter Goldsborough | 6f2307b | 2018-11-27 17:33:54 -0800 | [diff] [blame] | 482 | if return_code != 0: |
| 483 | return return_code |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 484 | |
Richard Zou | 6209412 | 2020-02-05 18:44:19 -0800 | [diff] [blame] | 485 | # "install" the test modules and run tests |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 486 | python_path = os.environ.get("PYTHONPATH", "") |
Rong Rong (AI Infra) | 40d2fe1 | 2021-06-24 09:19:16 -0700 | [diff] [blame] | 487 | from shutil import copyfile |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 488 | |
| 489 | test_module = "test_cpp_extensions_aot" + ("_ninja" if use_ninja else "_no_ninja") |
| 490 | copyfile( |
| 491 | test_directory + "/test_cpp_extensions_aot.py", |
| 492 | test_directory + "/" + test_module + ".py", |
| 493 | ) |
Peter Goldsborough | 6404904 | 2018-03-10 16:16:40 -0800 | [diff] [blame] | 494 | try: |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 495 | cpp_extensions = os.path.join(test_directory, "cpp_extensions") |
| 496 | install_directory = "" |
Francisco Massa | b240cc9 | 2018-04-29 18:10:03 +0200 | [diff] [blame] | 497 | # install directory is the one that is named site-packages |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 498 | for root, directories, _ in os.walk(os.path.join(cpp_extensions, "install")): |
Francisco Massa | b240cc9 | 2018-04-29 18:10:03 +0200 | [diff] [blame] | 499 | for directory in directories: |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 500 | if "-packages" in directory: |
Francisco Massa | b240cc9 | 2018-04-29 18:10:03 +0200 | [diff] [blame] | 501 | install_directory = os.path.join(root, directory) |
peterjc123 | 63af898 | 2018-04-03 01:53:25 +0800 | [diff] [blame] | 502 | |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 503 | assert install_directory, "install_directory must not be empty" |
| 504 | os.environ["PYTHONPATH"] = os.pathsep.join([install_directory, python_path]) |
Alexander Grund | 8649241 | 2020-07-28 08:12:41 -0700 | [diff] [blame] | 505 | return run_test(test_module, test_directory, options) |
Peter Goldsborough | 6404904 | 2018-03-10 16:16:40 -0800 | [diff] [blame] | 506 | finally: |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 507 | os.environ["PYTHONPATH"] = python_path |
| 508 | if os.path.exists(test_directory + "/" + test_module + ".py"): |
| 509 | os.remove(test_directory + "/" + test_module + ".py") |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 510 | |
| 511 | |
Alexander Grund | 8649241 | 2020-07-28 08:12:41 -0700 | [diff] [blame] | 512 | def test_cpp_extensions_aot_ninja(test_module, test_directory, options): |
Rong Rong (AI Infra) | 40d2fe1 | 2021-06-24 09:19:16 -0700 | [diff] [blame] | 513 | return _test_cpp_extensions_aot(test_directory, options, use_ninja=True) |
Richard Zou | 6209412 | 2020-02-05 18:44:19 -0800 | [diff] [blame] | 514 | |
| 515 | |
Alexander Grund | 8649241 | 2020-07-28 08:12:41 -0700 | [diff] [blame] | 516 | def test_cpp_extensions_aot_no_ninja(test_module, test_directory, options): |
Rong Rong (AI Infra) | 40d2fe1 | 2021-06-24 09:19:16 -0700 | [diff] [blame] | 517 | return _test_cpp_extensions_aot(test_directory, options, use_ninja=False) |
Richard Zou | 6209412 | 2020-02-05 18:44:19 -0800 | [diff] [blame] | 518 | |
| 519 | |
Alexander Grund | 8649241 | 2020-07-28 08:12:41 -0700 | [diff] [blame] | 520 | def test_distributed(test_module, test_directory, options): |
Nikita Shulga | b587354 | 2021-05-10 10:50:23 -0700 | [diff] [blame] | 521 | # MPI tests are broken with Python-3.9 |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 522 | mpi_available = subprocess.call( |
| 523 | "command -v mpiexec", shell=True |
| 524 | ) == 0 and sys.version_info < (3, 9) |
Edward Z. Yang | 3f3b686 | 2018-03-14 07:44:58 -0400 | [diff] [blame] | 525 | if options.verbose and not mpi_available: |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 526 | print_to_stderr("MPI not available -- MPI backend tests will be skipped") |
Teng Li | 56539f5 | 2018-08-29 12:54:55 -0700 | [diff] [blame] | 527 | config = DISTRIBUTED_TESTS_CONFIG |
Teng Li | 56539f5 | 2018-08-29 12:54:55 -0700 | [diff] [blame] | 528 | for backend, env_vars in config.items(): |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 529 | if sys.platform == "win32" and backend != "gloo": |
gunandrose4u | f07ac6a | 2020-09-25 12:35:42 -0700 | [diff] [blame] | 530 | continue |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 531 | if backend == "mpi" and not mpi_available: |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 532 | continue |
Peter Goldsborough | 4613eef | 2018-03-14 22:12:51 -0700 | [diff] [blame] | 533 | for with_init_file in {True, False}: |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 534 | if sys.platform == "win32" and not with_init_file: |
gunandrose4u | f07ac6a | 2020-09-25 12:35:42 -0700 | [diff] [blame] | 535 | continue |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 536 | tmp_dir = tempfile.mkdtemp() |
Edward Z. Yang | 3f3b686 | 2018-03-14 07:44:58 -0400 | [diff] [blame] | 537 | if options.verbose: |
Rohan Varma | b22abbe | 2020-09-08 23:08:55 -0700 | [diff] [blame] | 538 | init_str = "with {} init_method" |
| 539 | with_init = init_str.format("file" if with_init_file else "env") |
Peter Goldsborough | 4613eef | 2018-03-14 22:12:51 -0700 | [diff] [blame] | 540 | print_to_stderr( |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 541 | "Running distributed tests for the {} backend {}".format( |
| 542 | backend, with_init |
| 543 | ) |
| 544 | ) |
Catherine Lee | 56ea57d | 2022-05-03 23:01:42 +0000 | [diff] [blame] | 545 | old_environ = dict(os.environ) |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 546 | os.environ["TEMP_DIR"] = tmp_dir |
| 547 | os.environ["BACKEND"] = backend |
| 548 | os.environ["INIT_METHOD"] = "env://" |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 549 | os.environ.update(env_vars) |
Peter Goldsborough | 4613eef | 2018-03-14 22:12:51 -0700 | [diff] [blame] | 550 | if with_init_file: |
Pritam Damania | 2d671ca | 2021-08-20 12:09:49 -0700 | [diff] [blame] | 551 | if test_module == "test_distributed_spawn": |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 552 | init_method = f"{FILE_SCHEMA}{tmp_dir}/" |
Teng Li | 56539f5 | 2018-08-29 12:54:55 -0700 | [diff] [blame] | 553 | else: |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 554 | init_method = f"{FILE_SCHEMA}{tmp_dir}/shared_init_file" |
| 555 | os.environ["INIT_METHOD"] = init_method |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 556 | try: |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 557 | os.mkdir(os.path.join(tmp_dir, "barrier")) |
| 558 | os.mkdir(os.path.join(tmp_dir, "test_dir")) |
| 559 | if backend == "mpi": |
Simeon Monov | dc94182 | 2018-04-17 20:34:33 -0700 | [diff] [blame] | 560 | # test mpiexec for --noprefix option |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 561 | with open(os.devnull, "w") as devnull: |
| 562 | allowrunasroot_opt = ( |
| 563 | "--allow-run-as-root" |
| 564 | if subprocess.call( |
| 565 | 'mpiexec --allow-run-as-root -n 1 bash -c ""', |
| 566 | shell=True, |
| 567 | stdout=devnull, |
| 568 | stderr=subprocess.STDOUT, |
| 569 | ) |
| 570 | == 0 |
| 571 | else "" |
| 572 | ) |
| 573 | noprefix_opt = ( |
| 574 | "--noprefix" |
| 575 | if subprocess.call( |
| 576 | f'mpiexec {allowrunasroot_opt} -n 1 --noprefix bash -c ""', |
| 577 | shell=True, |
| 578 | stdout=devnull, |
| 579 | stderr=subprocess.STDOUT, |
| 580 | ) |
| 581 | == 0 |
| 582 | else "" |
| 583 | ) |
Simeon Monov | dc94182 | 2018-04-17 20:34:33 -0700 | [diff] [blame] | 584 | |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 585 | mpiexec = ["mpiexec", "-n", "3", noprefix_opt, allowrunasroot_opt] |
Simeon Monov | dc94182 | 2018-04-17 20:34:33 -0700 | [diff] [blame] | 586 | |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 587 | return_code = run_test( |
| 588 | test_module, test_directory, options, launcher_cmd=mpiexec |
| 589 | ) |
Peter Goldsborough | c3f7e5f | 2018-04-10 11:31:23 -0700 | [diff] [blame] | 590 | else: |
Rohan Varma | f02efc7 | 2021-11-11 06:09:11 -0800 | [diff] [blame] | 591 | return_code = run_test(test_module, test_directory, options, extra_unittest_args=["--subprocess"]) |
Peter Goldsborough | c3f7e5f | 2018-04-10 11:31:23 -0700 | [diff] [blame] | 592 | if return_code != 0: |
| 593 | return return_code |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 594 | finally: |
| 595 | shutil.rmtree(tmp_dir) |
Catherine Lee | 56ea57d | 2022-05-03 23:01:42 +0000 | [diff] [blame] | 596 | os.environ.clear() |
| 597 | os.environ.update(old_environ) |
Peter Goldsborough | c3f7e5f | 2018-04-10 11:31:23 -0700 | [diff] [blame] | 598 | return 0 |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 599 | |
| 600 | |
| 601 | CUSTOM_HANDLERS = { |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 602 | "test_cuda_primary_ctx": test_cuda_primary_ctx, |
| 603 | "test_cpp_extensions_aot_no_ninja": test_cpp_extensions_aot_no_ninja, |
| 604 | "test_cpp_extensions_aot_ninja": test_cpp_extensions_aot_ninja, |
| 605 | "distributed/test_distributed_spawn": test_distributed, |
Rohan Varma | 9554ebe | 2021-11-22 09:51:34 -0800 | [diff] [blame] | 606 | "distributed/test_c10d_nccl": get_run_test_with_subprocess_fn(), |
| 607 | "distributed/test_c10d_gloo": get_run_test_with_subprocess_fn(), |
Rohan Varma | 3bd7dbf | 2021-11-29 10:56:20 -0800 | [diff] [blame] | 608 | "distributed/test_c10d_common": get_run_test_with_subprocess_fn(), |
| 609 | "distributed/test_c10d_spawn_gloo": get_run_test_with_subprocess_fn(), |
| 610 | "distributed/test_c10d_spawn_nccl": get_run_test_with_subprocess_fn(), |
| 611 | "distributed/test_store": get_run_test_with_subprocess_fn(), |
| 612 | "distributed/test_pg_wrapper": get_run_test_with_subprocess_fn(), |
Rohan Varma | 250d0bd | 2021-11-29 10:56:20 -0800 | [diff] [blame] | 613 | "distributed/rpc/test_faulty_agent": get_run_test_with_subprocess_fn(), |
| 614 | "distributed/rpc/test_tensorpipe_agent": get_run_test_with_subprocess_fn(), |
| 615 | "distributed/rpc/cuda/test_tensorpipe_agent": get_run_test_with_subprocess_fn(), |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 616 | } |
| 617 | |
Simeon Monov | 24b4931 | 2018-04-16 11:33:50 -0700 | [diff] [blame] | 618 | def parse_test_module(test): |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 619 | return test.split(".")[0] |
Simeon Monov | 24b4931 | 2018-04-16 11:33:50 -0700 | [diff] [blame] | 620 | |
| 621 | |
| 622 | class TestChoices(list): |
| 623 | def __init__(self, *args, **kwargs): |
| 624 | super(TestChoices, self).__init__(args[0]) |
| 625 | |
| 626 | def __contains__(self, item): |
| 627 | return list.__contains__(self, parse_test_module(item)) |
| 628 | |
| 629 | |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 630 | def parse_args(): |
| 631 | parser = argparse.ArgumentParser( |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 632 | description="Run the PyTorch unit test suite", |
| 633 | epilog="where TESTS is any of: {}".format(", ".join(TESTS)), |
| 634 | formatter_class=argparse.RawTextHelpFormatter, |
Alban Desmaison | 3d7abc0 | 2022-04-25 14:01:33 +0000 | [diff] [blame] | 635 | parents=[common_parser] |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 636 | ) |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 637 | parser.add_argument( |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 638 | "-v", |
| 639 | "--verbose", |
| 640 | action="count", |
Sam Estep | c4a6df9 | 2020-11-19 07:57:09 -0800 | [diff] [blame] | 641 | default=0, |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 642 | help="print verbose information and test-by-test results", |
| 643 | ) |
| 644 | parser.add_argument("--jit", "--jit", action="store_true", help="run all jit tests") |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 645 | parser.add_argument( |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 646 | "--distributed-tests", |
| 647 | "--distributed-tests", |
| 648 | action="store_true", |
| 649 | help="run all distributed tests", |
| 650 | ) |
Elias Ellison | f6e5846 | 2019-05-30 14:03:31 -0700 | [diff] [blame] | 651 | parser.add_argument( |
Jane Xu | 1354ee4 | 2021-08-26 09:27:47 -0700 | [diff] [blame] | 652 | "-core", |
| 653 | "--core", |
| 654 | action="store_true", |
| 655 | help="Only run core tests, or tests that validate PyTorch's ops, modules," |
| 656 | "and autograd. They are defined by CORE_TEST_LIST." |
| 657 | ) |
| 658 | parser.add_argument( |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 659 | "-pt", |
| 660 | "--pytest", |
| 661 | action="store_true", |
| 662 | help="If true, use `pytest` to execute the tests. E.g., this runs " |
| 663 | "TestTorch with pytest in verbose and coverage mode: " |
| 664 | "python run_test.py -vci torch -pt", |
| 665 | ) |
Rong Rong (AI Infra) | f4aff3a | 2021-08-24 08:01:36 -0700 | [diff] [blame] | 666 | parser.add_argument( |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 667 | "-c", |
| 668 | "--coverage", |
| 669 | action="store_true", |
| 670 | help="enable coverage", |
| 671 | default=PYTORCH_COLLECT_COVERAGE, |
| 672 | ) |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 673 | parser.add_argument( |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 674 | "-i", |
| 675 | "--include", |
| 676 | nargs="+", |
Simeon Monov | 24b4931 | 2018-04-16 11:33:50 -0700 | [diff] [blame] | 677 | choices=TestChoices(TESTS), |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 678 | default=TESTS, |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 679 | metavar="TESTS", |
| 680 | help="select a set of tests to include (defaults to ALL tests)." |
| 681 | " tests must be a part of the TESTS list defined in run_test.py", |
| 682 | ) |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 683 | parser.add_argument( |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 684 | "-x", |
| 685 | "--exclude", |
| 686 | nargs="+", |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 687 | choices=TESTS, |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 688 | metavar="TESTS", |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 689 | default=[], |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 690 | help="select a set of tests to exclude", |
| 691 | ) |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 692 | parser.add_argument( |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 693 | "-f", |
| 694 | "--first", |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 695 | choices=TESTS, |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 696 | metavar="TESTS", |
| 697 | help="select the test to start from (excludes previous tests)", |
| 698 | ) |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 699 | parser.add_argument( |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 700 | "-l", |
| 701 | "--last", |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 702 | choices=TESTS, |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 703 | metavar="TESTS", |
| 704 | help="select the last test to run (excludes following tests)", |
| 705 | ) |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 706 | parser.add_argument( |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 707 | "--bring-to-front", |
| 708 | nargs="+", |
James Reed | 7597741 | 2019-08-14 18:06:14 -0700 | [diff] [blame] | 709 | choices=TestChoices(TESTS), |
| 710 | default=[], |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 711 | metavar="TESTS", |
| 712 | help="select a set of tests to run first. This can be used in situations" |
| 713 | " where you want to run all tests, but care more about some set, " |
| 714 | "e.g. after making a change to a specific component", |
| 715 | ) |
James Reed | 7597741 | 2019-08-14 18:06:14 -0700 | [diff] [blame] | 716 | parser.add_argument( |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 717 | "--ignore-win-blocklist", |
| 718 | action="store_true", |
| 719 | help="always run blocklisted windows tests", |
| 720 | ) |
Nikita Shulga | b5b62b3 | 2021-11-23 18:44:14 -0800 | [diff] [blame] | 721 | # NS: Disable target determination until it can be made more reliable |
| 722 | # parser.add_argument( |
| 723 | # "--determine-from", |
| 724 | # help="File of affected source filenames to determine which tests to run.", |
| 725 | # ) |
Yunus Rahbar | 7cee787 | 2020-03-03 17:29:14 -0800 | [diff] [blame] | 726 | parser.add_argument( |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 727 | "--continue-through-error", |
| 728 | action="store_true", |
| 729 | help="Runs the full test suite despite one of the tests failing", |
| 730 | default=strtobool(os.environ.get("CONTINUE_THROUGH_ERROR", "False")), |
| 731 | ) |
Eli Uriegas | f71cccc | 2020-07-08 17:24:06 -0700 | [diff] [blame] | 732 | parser.add_argument( |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 733 | "additional_unittest_args", |
| 734 | nargs="*", |
| 735 | help="additional arguments passed through to unittest, e.g., " |
| 736 | "python run_test.py -i sparse -- TestSparse.test_factory_size_check", |
| 737 | ) |
Jane (Yuan) Xu | 6acd7b6 | 2020-10-02 11:10:12 -0700 | [diff] [blame] | 738 | parser.add_argument( |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 739 | "--export-past-test-times", |
| 740 | nargs="?", |
Jane Xu | f30a7a2 | 2021-03-17 12:19:27 -0700 | [diff] [blame] | 741 | type=str, |
Jane Xu | 0645e2b | 2021-03-18 13:19:39 -0700 | [diff] [blame] | 742 | const=TEST_TIMES_FILE, |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 743 | help="dumps test times from previous S3 stats into a file, format JSON", |
Jane Xu | f30a7a2 | 2021-03-17 12:19:27 -0700 | [diff] [blame] | 744 | ) |
| 745 | parser.add_argument( |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 746 | "--shard", |
Jane (Yuan) Xu | 6acd7b6 | 2020-10-02 11:10:12 -0700 | [diff] [blame] | 747 | nargs=2, |
| 748 | type=int, |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 749 | help="runs a shard of the tests (taking into account other selections), e.g., " |
| 750 | "--shard 2 3 will break up the selected tests into 3 shards and run the tests " |
| 751 | "in the 2nd shard (the first number should not exceed the second)", |
Jane (Yuan) Xu | 6acd7b6 | 2020-10-02 11:10:12 -0700 | [diff] [blame] | 752 | ) |
Jane Xu | 8bc0c75 | 2020-10-06 07:11:37 -0700 | [diff] [blame] | 753 | parser.add_argument( |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 754 | "--exclude-jit-executor", |
| 755 | action="store_true", |
| 756 | help="exclude tests that are run for a specific jit config", |
Jane Xu | 8bc0c75 | 2020-10-06 07:11:37 -0700 | [diff] [blame] | 757 | ) |
Jane Xu | 97dfc7e | 2021-06-08 15:59:32 -0700 | [diff] [blame] | 758 | parser.add_argument( |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 759 | "--exclude-distributed-tests", |
| 760 | action="store_true", |
| 761 | help="exclude distributed tests", |
Rong Rong (AI Infra) | f4aff3a | 2021-08-24 08:01:36 -0700 | [diff] [blame] | 762 | ) |
| 763 | parser.add_argument( |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 764 | "--run-specified-test-cases", |
| 765 | nargs="?", |
Jane Xu | 97dfc7e | 2021-06-08 15:59:32 -0700 | [diff] [blame] | 766 | type=str, |
| 767 | const=SPECIFIED_TEST_CASES_FILE, |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 768 | help="load specified test cases file dumped from previous OSS CI stats, format CSV. " |
| 769 | " If all test cases should run for a <test_module> please add a single row: \n" |
| 770 | " test_filename,test_case_name\n" |
| 771 | " ...\n" |
| 772 | " <test_module>,__all__\n" |
| 773 | " ...\n" |
| 774 | 'how we use the stats will be based on option "--use-specified-test-cases-by".', |
Rong Rong | e41bc31 | 2021-06-11 13:56:06 -0700 | [diff] [blame] | 775 | ) |
| 776 | parser.add_argument( |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 777 | "--use-specified-test-cases-by", |
Rong Rong | e41bc31 | 2021-06-11 13:56:06 -0700 | [diff] [blame] | 778 | type=str, |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 779 | choices=["include", "bring-to-front"], |
| 780 | default="include", |
Rong Rong | e41bc31 | 2021-06-11 13:56:06 -0700 | [diff] [blame] | 781 | help='used together with option "--run-specified-test-cases". When specified test case ' |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 782 | "file is set, this option allows the user to control whether to only run the specified test " |
| 783 | "modules or to simply bring the specified modules to front and also run the remaining " |
| 784 | "modules. Note: regardless of this option, we will only run the specified test cases " |
| 785 | " within a specified test module. For unspecified test modules with the bring-to-front " |
| 786 | "option, all test cases will be run, as one may expect.", |
Jane Xu | 97dfc7e | 2021-06-08 15:59:32 -0700 | [diff] [blame] | 787 | ) |
Alban Desmaison | 7e919bd | 2022-02-22 09:52:11 -0500 | [diff] [blame] | 788 | parser.add_argument( |
| 789 | "--dry-run", |
| 790 | action="store_true", |
| 791 | help="Only list the test that will run.", |
| 792 | ) |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 793 | return parser.parse_args() |
| 794 | |
| 795 | |
Simeon Monov | 24b4931 | 2018-04-16 11:33:50 -0700 | [diff] [blame] | 796 | def find_test_index(test, selected_tests, find_last_index=False): |
SsnL | ffd6138 | 2019-01-16 22:56:56 -0800 | [diff] [blame] | 797 | """Find the index of the first or last occurrence of a given test/test module in the list of selected tests. |
Simeon Monov | 24b4931 | 2018-04-16 11:33:50 -0700 | [diff] [blame] | 798 | |
SsnL | ffd6138 | 2019-01-16 22:56:56 -0800 | [diff] [blame] | 799 | This function is used to determine the indices when slicing the list of selected tests when |
Simeon Monov | 24b4931 | 2018-04-16 11:33:50 -0700 | [diff] [blame] | 800 | ``options.first``(:attr:`find_last_index`=False) and/or ``options.last``(:attr:`find_last_index`=True) are used. |
| 801 | |
| 802 | :attr:`selected_tests` can be a list that contains multiple consequent occurrences of tests |
| 803 | as part of the same test module, e.g.: |
| 804 | |
| 805 | ``` |
| 806 | selected_tests = ['autograd', 'cuda', **'torch.TestTorch.test_acos', |
| 807 | 'torch.TestTorch.test_tan', 'torch.TestTorch.test_add'**, 'utils'] |
| 808 | ``` |
| 809 | |
Tongzhou Wang | 0d5e4a2 | 2018-09-03 19:55:58 -0700 | [diff] [blame] | 810 | If :attr:`test`='torch' and :attr:`find_last_index`=False, result should be **2**. |
| 811 | If :attr:`test`='torch' and :attr:`find_last_index`=True, result should be **4**. |
Simeon Monov | 24b4931 | 2018-04-16 11:33:50 -0700 | [diff] [blame] | 812 | |
Samuel Marks | e6779d4 | 2020-12-28 09:33:01 -0800 | [diff] [blame] | 813 | Args: |
Simeon Monov | 24b4931 | 2018-04-16 11:33:50 -0700 | [diff] [blame] | 814 | test (str): Name of test to lookup |
| 815 | selected_tests (list): List of tests |
| 816 | find_last_index (bool, optional): should we lookup the index of first or last |
| 817 | occurrence (first is default) |
| 818 | |
| 819 | Returns: |
Brian Wignall | e7fe64f | 2019-12-02 20:15:54 -0800 | [diff] [blame] | 820 | index of the first or last occurrence of the given test |
Simeon Monov | 24b4931 | 2018-04-16 11:33:50 -0700 | [diff] [blame] | 821 | """ |
| 822 | idx = 0 |
| 823 | found_idx = -1 |
| 824 | for t in selected_tests: |
| 825 | if t.startswith(test): |
| 826 | found_idx = idx |
| 827 | if not find_last_index: |
| 828 | break |
| 829 | idx += 1 |
| 830 | return found_idx |
| 831 | |
| 832 | |
| 833 | def exclude_tests(exclude_list, selected_tests, exclude_message=None): |
Simeon Monov | 24b4931 | 2018-04-16 11:33:50 -0700 | [diff] [blame] | 834 | for exclude_test in exclude_list: |
Richard Zou | 6209412 | 2020-02-05 18:44:19 -0800 | [diff] [blame] | 835 | tests_copy = selected_tests[:] |
Simeon Monov | 24b4931 | 2018-04-16 11:33:50 -0700 | [diff] [blame] | 836 | for test in tests_copy: |
| 837 | if test.startswith(exclude_test): |
| 838 | if exclude_message is not None: |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 839 | print_to_stderr("Excluding {} {}".format(test, exclude_message)) |
Simeon Monov | 24b4931 | 2018-04-16 11:33:50 -0700 | [diff] [blame] | 840 | selected_tests.remove(test) |
| 841 | return selected_tests |
| 842 | |
| 843 | |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 844 | def get_selected_tests(options): |
Rong Rong (AI Infra) | f4aff3a | 2021-08-24 08:01:36 -0700 | [diff] [blame] | 845 | # First make sure run specific test cases options are processed. |
Rong Rong | e41bc31 | 2021-06-11 13:56:06 -0700 | [diff] [blame] | 846 | if options.run_specified_test_cases: |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 847 | if options.use_specified_test_cases_by == "include": |
Rong Rong | e41bc31 | 2021-06-11 13:56:06 -0700 | [diff] [blame] | 848 | options.include = list(SPECIFIED_TEST_CASES_DICT.keys()) |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 849 | elif options.use_specified_test_cases_by == "bring-to-front": |
Rong Rong | e41bc31 | 2021-06-11 13:56:06 -0700 | [diff] [blame] | 850 | options.bring_to_front = list(SPECIFIED_TEST_CASES_DICT.keys()) |
| 851 | |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 852 | selected_tests = options.include |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 853 | |
Rong Rong (AI Infra) | f4aff3a | 2021-08-24 08:01:36 -0700 | [diff] [blame] | 854 | # filter if there's JIT only and distributed only test options |
| 855 | if options.jit: |
| 856 | selected_tests = list( |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 857 | filter(lambda test_name: "jit" in test_name, selected_tests) |
| 858 | ) |
Rong Rong (AI Infra) | f4aff3a | 2021-08-24 08:01:36 -0700 | [diff] [blame] | 859 | |
| 860 | if options.distributed_tests: |
| 861 | selected_tests = list( |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 862 | filter(lambda test_name: test_name in DISTRIBUTED_TESTS, selected_tests) |
| 863 | ) |
Rong Rong (AI Infra) | f4aff3a | 2021-08-24 08:01:36 -0700 | [diff] [blame] | 864 | |
Jane Xu | 1354ee4 | 2021-08-26 09:27:47 -0700 | [diff] [blame] | 865 | # Filter to only run core tests when --core option is specified |
| 866 | if options.core: |
| 867 | selected_tests = list( |
| 868 | filter(lambda test_name: test_name in CORE_TEST_LIST, selected_tests) |
| 869 | ) |
| 870 | |
Rong Rong (AI Infra) | f4aff3a | 2021-08-24 08:01:36 -0700 | [diff] [blame] | 871 | # process reordering |
James Reed | 7597741 | 2019-08-14 18:06:14 -0700 | [diff] [blame] | 872 | if options.bring_to_front: |
| 873 | to_front = set(options.bring_to_front) |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 874 | selected_tests = options.bring_to_front + list( |
| 875 | filter(lambda name: name not in to_front, selected_tests) |
| 876 | ) |
James Reed | 7597741 | 2019-08-14 18:06:14 -0700 | [diff] [blame] | 877 | |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 878 | if options.first: |
Simeon Monov | 24b4931 | 2018-04-16 11:33:50 -0700 | [diff] [blame] | 879 | first_index = find_test_index(options.first, selected_tests) |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 880 | selected_tests = selected_tests[first_index:] |
| 881 | |
| 882 | if options.last: |
Simeon Monov | 24b4931 | 2018-04-16 11:33:50 -0700 | [diff] [blame] | 883 | last_index = find_test_index(options.last, selected_tests, find_last_index=True) |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 884 | selected_tests = selected_tests[: last_index + 1] |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 885 | |
Rong Rong (AI Infra) | f4aff3a | 2021-08-24 08:01:36 -0700 | [diff] [blame] | 886 | # process exclusion |
Jane Xu | 8bc0c75 | 2020-10-06 07:11:37 -0700 | [diff] [blame] | 887 | if options.exclude_jit_executor: |
| 888 | options.exclude.extend(JIT_EXECUTOR_TESTS) |
| 889 | |
Rong Rong (AI Infra) | f4aff3a | 2021-08-24 08:01:36 -0700 | [diff] [blame] | 890 | if options.exclude_distributed_tests: |
| 891 | options.exclude.extend(DISTRIBUTED_TESTS) |
| 892 | |
Andrey Talman | 622cff3 | 2022-04-07 15:37:09 -0700 | [diff] [blame] | 893 | # these tests failing in CUDA 11.6 temporary disabling. issue https://github.com/pytorch/pytorch/issues/75375 |
| 894 | if torch.version.cuda is not None and LooseVersion(torch.version.cuda) == "11.6": |
| 895 | options.exclude.extend(["distributions/test_constraints"]) |
| 896 | |
Simeon Monov | 24b4931 | 2018-04-16 11:33:50 -0700 | [diff] [blame] | 897 | selected_tests = exclude_tests(options.exclude, selected_tests) |
| 898 | |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 899 | if sys.platform == "win32" and not options.ignore_win_blocklist: |
| 900 | target_arch = os.environ.get("VSCMD_ARG_TGT_ARCH") |
| 901 | if target_arch != "x64": |
| 902 | WINDOWS_BLOCKLIST.append("cpp_extensions_aot_no_ninja") |
| 903 | WINDOWS_BLOCKLIST.append("cpp_extensions_aot_ninja") |
| 904 | WINDOWS_BLOCKLIST.append("cpp_extensions_jit") |
| 905 | WINDOWS_BLOCKLIST.append("jit") |
| 906 | WINDOWS_BLOCKLIST.append("jit_fuser") |
peterjc123 | d45f3d0 | 2018-04-12 18:12:39 +0800 | [diff] [blame] | 907 | |
Ilya Persky | bc514cb | 2022-01-06 08:53:50 -0800 | [diff] [blame] | 908 | # This is exception that's caused by this issue https://github.com/pytorch/pytorch/issues/69460 |
Andrey Talman | 77a4b89 | 2021-12-13 20:47:33 -0800 | [diff] [blame] | 909 | # This below code should be removed once this issue is solved |
Nikita Shulga | 24ee1d1 | 2021-12-14 14:45:47 -0800 | [diff] [blame] | 910 | if torch.version.cuda is not None and LooseVersion(torch.version.cuda) >= "11.5": |
Andrey Talman | 77a4b89 | 2021-12-13 20:47:33 -0800 | [diff] [blame] | 911 | WINDOWS_BLOCKLIST.append("test_cpp_extensions_aot") |
| 912 | WINDOWS_BLOCKLIST.append("test_cpp_extensions_aot_ninja") |
| 913 | WINDOWS_BLOCKLIST.append("test_cpp_extensions_aot_no_ninja") |
| 914 | |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 915 | selected_tests = exclude_tests(WINDOWS_BLOCKLIST, selected_tests, "on Windows") |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 916 | |
iotamudelta | a38b572 | 2018-08-06 14:48:45 -0700 | [diff] [blame] | 917 | elif TEST_WITH_ROCM: |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 918 | selected_tests = exclude_tests(ROCM_BLOCKLIST, selected_tests, "on ROCm") |
iotamudelta | a38b572 | 2018-08-06 14:48:45 -0700 | [diff] [blame] | 919 | |
Rong Rong (AI Infra) | f4aff3a | 2021-08-24 08:01:36 -0700 | [diff] [blame] | 920 | # sharding |
Jane Xu | caf76c2 | 2021-06-07 15:03:19 -0700 | [diff] [blame] | 921 | if options.shard: |
| 922 | assert len(options.shard) == 2, "Unexpected shard format" |
| 923 | assert min(options.shard) > 0, "Shards must be positive numbers" |
| 924 | which_shard, num_shards = options.shard |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 925 | assert ( |
| 926 | which_shard <= num_shards |
| 927 | ), "Selected shard must be less than or equal to total number of shards" |
| 928 | assert num_shards <= len( |
| 929 | selected_tests |
| 930 | ), f"Number of shards must be less than {len(selected_tests)}" |
Rong Rong (AI Infra) | 718db96 | 2021-07-06 09:04:49 -0700 | [diff] [blame] | 931 | # TODO: fix this to use test_times_filename, but currently this is not working |
| 932 | # because setting the export arg immeidately halts the test execution. |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 933 | selected_tests = get_shard_based_on_S3( |
| 934 | which_shard, num_shards, selected_tests, TEST_TIMES_FILE |
| 935 | ) |
Jane Xu | caf76c2 | 2021-06-07 15:03:19 -0700 | [diff] [blame] | 936 | |
Ilya Persky | bc514cb | 2022-01-06 08:53:50 -0800 | [diff] [blame] | 937 | # skip all distributed tests if distributed package is not available. |
| 938 | if not dist.is_available(): |
| 939 | selected_tests = exclude_tests(DISTRIBUTED_TESTS, selected_tests, |
| 940 | "PyTorch is built without distributed support.") |
| 941 | |
Ilya Persky | 1b08929 | 2022-02-15 08:33:59 -0800 | [diff] [blame] | 942 | # skip tests that require LAPACK when it's not available |
| 943 | if not torch._C.has_lapack: |
| 944 | selected_tests = exclude_tests(TESTS_REQUIRING_LAPACK, selected_tests, |
| 945 | "PyTorch is built without LAPACK support.") |
| 946 | |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 947 | return selected_tests |
| 948 | |
| 949 | |
Nikita Shulga | 1bda5e4 | 2020-08-26 16:14:17 -0700 | [diff] [blame] | 950 | def run_test_module(test: str, test_directory: str, options) -> Optional[str]: |
| 951 | test_module = parse_test_module(test) |
| 952 | |
| 953 | # Printing the date here can help diagnose which tests are slow |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 954 | print_to_stderr("Running {} ... [{}]".format(test, datetime.now())) |
Nikita Shulga | b00cdfe | 2021-03-12 09:51:27 -0800 | [diff] [blame] | 955 | handler = CUSTOM_HANDLERS.get(test_module, run_test) |
Nikita Shulga | 1bda5e4 | 2020-08-26 16:14:17 -0700 | [diff] [blame] | 956 | return_code = handler(test_module, test_directory, options) |
| 957 | assert isinstance(return_code, int) and not isinstance( |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 958 | return_code, bool |
| 959 | ), "Return code should be an integer" |
Nikita Shulga | 1bda5e4 | 2020-08-26 16:14:17 -0700 | [diff] [blame] | 960 | if return_code == 0: |
| 961 | return None |
| 962 | |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 963 | message = f"{test} failed!" |
Nikita Shulga | 1bda5e4 | 2020-08-26 16:14:17 -0700 | [diff] [blame] | 964 | if return_code < 0: |
| 965 | # subprocess.Popen returns the child process' exit signal as |
| 966 | # return code -N, where N is the signal number. |
| 967 | signal_name = SIGNALS_TO_NAMES_DICT[-return_code] |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 968 | message += f" Received signal: {signal_name}" |
Nikita Shulga | 1bda5e4 | 2020-08-26 16:14:17 -0700 | [diff] [blame] | 969 | return message |
| 970 | |
driazati | 187a524 | 2021-04-22 10:25:41 -0700 | [diff] [blame] | 971 | |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 972 | def main(): |
| 973 | options = parse_args() |
Jane Xu | f30a7a2 | 2021-03-17 12:19:27 -0700 | [diff] [blame] | 974 | |
Rong Rong (AI Infra) | 718db96 | 2021-07-06 09:04:49 -0700 | [diff] [blame] | 975 | # TODO: move this export & download function in tools/ folder |
Jane Xu | 0645e2b | 2021-03-18 13:19:39 -0700 | [diff] [blame] | 976 | test_times_filename = options.export_past_test_times |
Jane Xu | f30a7a2 | 2021-03-17 12:19:27 -0700 | [diff] [blame] | 977 | if test_times_filename: |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 978 | print( |
| 979 | f"Exporting past test times from S3 to {test_times_filename}, no tests will be run." |
| 980 | ) |
Rong Rong (AI Infra) | 718db96 | 2021-07-06 09:04:49 -0700 | [diff] [blame] | 981 | export_S3_test_times(test_times_filename) |
Jane Xu | f30a7a2 | 2021-03-17 12:19:27 -0700 | [diff] [blame] | 982 | return |
| 983 | |
Jane Xu | 97dfc7e | 2021-06-08 15:59:32 -0700 | [diff] [blame] | 984 | specified_test_cases_filename = options.run_specified_test_cases |
| 985 | if specified_test_cases_filename: |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 986 | print( |
| 987 | f"Loading specified test cases to run from {specified_test_cases_filename}." |
| 988 | ) |
Rong Rong (AI Infra) | 718db96 | 2021-07-06 09:04:49 -0700 | [diff] [blame] | 989 | global SPECIFIED_TEST_CASES_DICT |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 990 | SPECIFIED_TEST_CASES_DICT = get_specified_test_cases( |
| 991 | specified_test_cases_filename, TESTS |
| 992 | ) |
Jane Xu | 97dfc7e | 2021-06-08 15:59:32 -0700 | [diff] [blame] | 993 | |
driazati | ab5cf5a | 2021-08-25 12:58:24 -0700 | [diff] [blame] | 994 | test_directory = str(REPO_ROOT / "test") |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 995 | selected_tests = get_selected_tests(options) |
Simeon Monov | 24b4931 | 2018-04-16 11:33:50 -0700 | [diff] [blame] | 996 | |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 997 | if options.verbose: |
Alban Desmaison | 7e919bd | 2022-02-22 09:52:11 -0500 | [diff] [blame] | 998 | print_to_stderr("Selected tests:\n {}".format("\n ".join(selected_tests))) |
| 999 | |
| 1000 | if options.dry_run: |
| 1001 | return |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 1002 | |
Nikita Shulga | 1bda5e4 | 2020-08-26 16:14:17 -0700 | [diff] [blame] | 1003 | if options.coverage and not PYTORCH_COLLECT_COVERAGE: |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 1004 | shell(["coverage", "erase"]) |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 1005 | |
Nikita Shulga | 01cfea9 | 2021-09-14 09:38:34 -0700 | [diff] [blame] | 1006 | # NS: Disable target determination until it can be made more reliable |
| 1007 | # if options.determine_from is not None and os.path.exists(options.determine_from): |
| 1008 | # slow_tests = get_slow_tests_based_on_S3( |
| 1009 | # TESTS, TARGET_DET_LIST, SLOW_TEST_THRESHOLD |
| 1010 | # ) |
| 1011 | # print_to_stderr( |
| 1012 | # "Added the following tests to target_det tests as calculated based on S3:" |
| 1013 | # ) |
| 1014 | # print_to_stderr(slow_tests) |
| 1015 | # with open(options.determine_from, "r") as fh: |
| 1016 | # touched_files = [ |
| 1017 | # os.path.normpath(name.strip()) |
| 1018 | # for name in fh.read().split("\n") |
| 1019 | # if len(name.strip()) > 0 |
| 1020 | # ] |
| 1021 | # # HACK: Ensure the 'test' paths can be traversed by Modulefinder |
| 1022 | # sys.path.append(test_directory) |
| 1023 | # selected_tests = [ |
| 1024 | # test |
| 1025 | # for test in selected_tests |
| 1026 | # if should_run_test( |
| 1027 | # TARGET_DET_LIST + slow_tests, test, touched_files, options |
| 1028 | # ) |
| 1029 | # ] |
| 1030 | # sys.path.remove(test_directory) |
Yunus Rahbar | 7cee787 | 2020-03-03 17:29:14 -0800 | [diff] [blame] | 1031 | |
Rong Rong (AI Infra) | 57d8bcc | 2021-06-07 17:53:08 -0700 | [diff] [blame] | 1032 | if IS_IN_CI: |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 1033 | selected_tests = get_reordered_tests( |
| 1034 | selected_tests, ENABLE_PR_HISTORY_REORDERING |
| 1035 | ) |
Rong Rong (AI Infra) | a5a10fe | 2021-07-12 11:20:12 -0700 | [diff] [blame] | 1036 | # downloading test cases configuration to local environment |
driazati | ab5cf5a | 2021-08-25 12:58:24 -0700 | [diff] [blame] | 1037 | get_test_case_configs(dirpath=test_directory) |
driazati | 187a524 | 2021-04-22 10:25:41 -0700 | [diff] [blame] | 1038 | |
Eli Uriegas | f71cccc | 2020-07-08 17:24:06 -0700 | [diff] [blame] | 1039 | has_failed = False |
| 1040 | failure_messages = [] |
Nikita Shulga | 1bda5e4 | 2020-08-26 16:14:17 -0700 | [diff] [blame] | 1041 | try: |
| 1042 | for test in selected_tests: |
Pritam Damania | 06d50b5 | 2020-10-22 10:53:07 -0700 | [diff] [blame] | 1043 | options_clone = copy.deepcopy(options) |
| 1044 | if test in USE_PYTEST_LIST: |
| 1045 | options_clone.pytest = True |
| 1046 | err_message = run_test_module(test, test_directory, options_clone) |
Nikita Shulga | 1bda5e4 | 2020-08-26 16:14:17 -0700 | [diff] [blame] | 1047 | if err_message is None: |
| 1048 | continue |
Eli Uriegas | f71cccc | 2020-07-08 17:24:06 -0700 | [diff] [blame] | 1049 | has_failed = True |
Nikita Shulga | 1bda5e4 | 2020-08-26 16:14:17 -0700 | [diff] [blame] | 1050 | failure_messages.append(err_message) |
Pritam Damania | 06d50b5 | 2020-10-22 10:53:07 -0700 | [diff] [blame] | 1051 | if not options_clone.continue_through_error: |
Nikita Shulga | 1bda5e4 | 2020-08-26 16:14:17 -0700 | [diff] [blame] | 1052 | raise RuntimeError(err_message) |
| 1053 | print_to_stderr(err_message) |
| 1054 | finally: |
| 1055 | if options.coverage: |
Nikita Shulga | 6f381de | 2020-12-18 17:07:05 -0800 | [diff] [blame] | 1056 | from coverage import Coverage |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 1057 | |
driazati | ab5cf5a | 2021-08-25 12:58:24 -0700 | [diff] [blame] | 1058 | with set_cwd(test_directory): |
Nikita Shulga | 6f381de | 2020-12-18 17:07:05 -0800 | [diff] [blame] | 1059 | cov = Coverage() |
| 1060 | if PYTORCH_COLLECT_COVERAGE: |
| 1061 | cov.load() |
| 1062 | cov.combine(strict=False) |
| 1063 | cov.save() |
| 1064 | if not PYTORCH_COLLECT_COVERAGE: |
| 1065 | cov.html_report() |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 1066 | |
Eli Uriegas | f71cccc | 2020-07-08 17:24:06 -0700 | [diff] [blame] | 1067 | if options.continue_through_error and has_failed: |
| 1068 | for err in failure_messages: |
Jane Xu | 8595416 | 2020-10-23 14:13:12 -0700 | [diff] [blame] | 1069 | print_to_stderr(err) |
Eli Uriegas | f71cccc | 2020-07-08 17:24:06 -0700 | [diff] [blame] | 1070 | sys.exit(1) |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 1071 | |
driazati | 67d8e7b | 2021-08-25 11:19:49 -0700 | [diff] [blame] | 1072 | |
| 1073 | if __name__ == "__main__": |
Peter Goldsborough | 53876c4 | 2018-03-09 13:02:02 -0800 | [diff] [blame] | 1074 | main() |