2018-03-09 21:02:02 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
|
|
import argparse
|
2025-01-14 15:59:00 +00:00
|
|
|
import contextlib
|
2020-10-22 17:53:07 +00:00
|
|
|
import copy
|
2024-03-11 15:35:45 +00:00
|
|
|
import glob
|
2023-03-26 04:52:55 +00:00
|
|
|
import json
|
2018-03-09 21:02:02 +00:00
|
|
|
import os
|
2024-11-20 22:53:09 +00:00
|
|
|
import platform
|
2023-10-05 16:40:37 +00:00
|
|
|
import re
|
2018-03-09 21:02:02 +00:00
|
|
|
import shutil
|
2018-04-10 18:31:23 +00:00
|
|
|
import signal
|
2018-03-09 21:02:02 +00:00
|
|
|
import subprocess
|
|
|
|
|
import sys
|
|
|
|
|
import tempfile
|
2023-08-16 18:23:09 +00:00
|
|
|
import time
|
2023-11-30 04:01:57 +00:00
|
|
|
from collections import defaultdict
|
2025-01-21 19:22:20 +00:00
|
|
|
from collections.abc import Sequence
|
2023-10-05 16:40:37 +00:00
|
|
|
from contextlib import ExitStack
|
2023-03-26 04:52:55 +00:00
|
|
|
from datetime import datetime
|
2024-06-29 23:28:38 +00:00
|
|
|
from pathlib import Path
|
2025-01-21 19:22:20 +00:00
|
|
|
from typing import Any, cast, NamedTuple, Optional, Union
|
2018-03-09 21:02:02 +00:00
|
|
|
|
2023-05-17 20:27:51 +00:00
|
|
|
import pkg_resources
|
|
|
|
|
|
2018-03-09 21:02:02 +00:00
|
|
|
import torch
|
2023-03-26 04:52:55 +00:00
|
|
|
import torch.distributed as dist
|
|
|
|
|
from torch.multiprocessing import current_process, get_context
|
2021-08-12 18:39:31 +00:00
|
|
|
from torch.testing._internal.common_utils import (
|
Discover and run C++ tests with run_test.py (#99559)
This depends on [pytest-cpp](https://github.com/pytest-dev/pytest-cpp) to discover and run C++ tests with pytest. C++ tests are built under `${WORKSPACE}/build/bin` directory and copied to the test job under the same path.
* To expose them to `run_test`, I choose to use the mock path prefix `cpp`, for example `build/bin/c10_Array_test` would be named as `cpp/c10_Array_test` and the `python test/run_test.py --cpp -i cpp/c10_Array_test` would run the test in the same way as other Python tests. I could copy them from `build/bin` to `test/cpp`, but it will be mixed with the source code and CMake file. So this looks easier
* Some executable under `build/bin` are not C++ tests, and they are exclude, for example `build/bin/torch_shm_manager`
* C++ tests need to run with pytest directly as python command doesn't understand it
* The change is gated by the new `--cpp` argument to `run_test.py`, for example `python test/run_test.py --cpp` will run all available C++ tests
* The tests can be run in parallel
* Failing tests can be retried with `--reruns=2` and `--sw`
```
============================= test session starts ==============================
platform darwin -- Python 3.9.15, pytest-7.2.0, pluggy-1.0.0 -- /Users/huydo/miniconda3/envs/py3.9/bin/python3
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/Users/huydo/Storage/mine/pytorch/test/.hypothesis/examples')
rootdir: /Users/huydo/Storage/mine/pytorch, configfile: pytest.ini
plugins: xdoctest-1.1.0, cpp-2.3.0, rerunfailures-10.3, shard-0.1.2, flakefinder-1.1.0, hypothesis-6.56.4, xdist-3.0.2, repeat-0.9.1
collecting ... collected 3 items / 2 deselected / 1 selected
Running 1 items in this shard: build/bin/scalar_tensor_test::TestScalarTensor.TestScalarTensorMPS
stepwise: skipping 2 already passed items.
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS FAILED [100%]
```
* `--import-slow-tests` and `--import-disabled-tests` won't work for now and that's ok to have it as a future task.
I also add `pytest-cpp==2.3.0` to Linux Docker, MacOS, and Windows.
### Testing
Build PyTorch and run `python test/run_test.py --cpp` on my laptop. CI change would come later in a separate PR. Also running `python test/run_test.py --help` now shows all C++ test discovered under `build/bin`
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99559
Approved by: https://github.com/clee2000
2023-04-22 00:23:31 +00:00
|
|
|
get_report_path,
|
2023-03-26 04:52:55 +00:00
|
|
|
IS_CI,
|
2024-02-26 22:21:09 +00:00
|
|
|
IS_MACOS,
|
2024-04-29 23:39:50 +00:00
|
|
|
IS_WINDOWS,
|
2023-03-31 18:36:53 +00:00
|
|
|
retry_shell,
|
2023-03-26 04:52:55 +00:00
|
|
|
set_cwd,
|
|
|
|
|
shell,
|
2024-04-08 15:53:55 +00:00
|
|
|
TEST_CUDA,
|
Do not collect and skip non-disabled tests when rerunning disabled tests (#102107)
The console log blows up to much when running in rerun disabled tests mode (x50) https://hud.pytorch.org/pytorch/pytorch/commit/e132f09e8878418fb98a4b76a441a324452354ec. Each log is around 1GB and the whole uncompressed logs is ~50GB. After compression, it will be around 1GB, still too big. The increase comes mainly from the multiple SKIPPED message for non-disabled tests, which is expected due to how SkipTest and pytest-flakyfinder currently work.
I update `test/conftest.py` to completely ignore skipped tests when rerunning disabled test instead of collecting then skipping 50 tests each. The benefit of doing is is much more than I originally expect:
* Rerun disabled tests jobs now finish in less than half an hour as they should be
* Fix OOM runner crash because of too many collected tests
* Fix verbosity issue as now only disabled tests are run x50 times. There are only few hundreds of them atm
* Fix timed out issue when rerunning disabled distributed and ASAN tests. They are just too slow when running at x50
### Testing
When rerunning disabled tests https://github.com/pytorch/pytorch/actions/runs/5084508614, only disabled tests on the platform are run, for example `test_ops_jit` on https://ossci-raw-job-status.s3.amazonaws.com/log/13770164954 only ran 100 tests (`test_variant_consistency_jit_linalg_lu_cuda_float32` + `test_variant_consistency_jit_linalg_lu_factor_cuda_complex64`) x50.
```
Executing ['/opt/conda/envs/py_3.10/bin/python', '-bb', 'test_ops_jit.py', '--shard-id=1', '--num-shards=2', '-v', '-vv', '-rfEX', '-p', 'no:xdist', '--use-pytest', '--sc=test_ops_jit_1', '--flake-finder', '--flake-runs=50', '--import-slow-tests', '--import-disabled-tests', '--rerun-disabled-tests'] ... [2023-05-25 21:32:49.763856]
Expand the folded group to see the log file of test_ops_jit 2/2
##[group]PRINTING LOG FILE of test_ops_jit 2/2 (/var/lib/jenkins/workspace/test/test-reports/test_ops_jit_h2wr_t2c.log)
Test results will be stored in test-reports/python-pytest/test_ops_jit/test_ops_jit-51a83bd44549074e.xml
============================= test session starts ==============================
platform linux -- Python 3.10.11, pytest-7.3.1, pluggy-1.0.0 -- /opt/conda/envs/py_3.10/bin/python
cachedir: .pytest_cache
hypothesis profile 'pytorch_ci' -> database=None, max_examples=50, derandomize=True, suppress_health_check=[HealthCheck.too_slow]
rootdir: /var/lib/jenkins/workspace
configfile: pytest.ini
plugins: hypothesis-5.35.1, cpp-2.3.0, flakefinder-1.1.0, rerunfailures-11.1.2, shard-0.1.2, xdist-3.3.0, xdoctest-1.1.0
collecting ... collected 1084 items
Running 100 items in this shard: test/test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_cuda_float32 (x50), test/test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_factor_cuda_complex64 (x50)
stepcurrent: Cannot find last run test, not skipping
test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_cuda_float32 PASSED [2.1876s] [ 1%]
test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_factor_cuda_complex64 PASSED [4.5615s] [ 2%]
```
* [pull](https://github.com/pytorch/pytorch/actions/runs/5093566864)
* [trunk](https://github.com/pytorch/pytorch/actions/runs/5095364311)
* [periodic](https://github.com/pytorch/pytorch/actions/runs/5095378850)
* [slow](https://github.com/pytorch/pytorch/actions/runs/5095390285)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/102107
Approved by: https://github.com/clee2000, https://github.com/malfet
2023-05-27 12:10:32 +00:00
|
|
|
TEST_WITH_ASAN,
|
2024-02-29 18:53:43 +00:00
|
|
|
TEST_WITH_CROSSREF,
|
2023-03-26 04:52:55 +00:00
|
|
|
TEST_WITH_ROCM,
|
2023-07-10 18:20:08 +00:00
|
|
|
TEST_WITH_SLOW_GRADCHECK,
|
2021-08-25 18:19:49 +00:00
|
|
|
)
|
2021-03-05 21:34:17 +00:00
|
|
|
|
2021-08-25 19:58:24 +00:00
|
|
|
|
2023-08-22 16:36:17 +00:00
|
|
|
# using tools/ to optimize test run.
|
2025-01-04 14:17:20 +00:00
|
|
|
REPO_ROOT = Path(__file__).resolve().parent.parent
|
2023-08-22 16:36:17 +00:00
|
|
|
sys.path.insert(0, str(REPO_ROOT))
|
2024-07-16 03:46:39 +00:00
|
|
|
|
2023-10-30 23:31:40 +00:00
|
|
|
from tools.stats.import_test_stats import (
|
|
|
|
|
ADDITIONAL_CI_FILES_FOLDER,
|
|
|
|
|
TEST_CLASS_TIMES_FILE,
|
|
|
|
|
TEST_TIMES_FILE,
|
|
|
|
|
)
|
2023-09-26 17:06:49 +00:00
|
|
|
from tools.stats.upload_metrics import add_global_metric, emit_metric
|
2024-01-30 03:02:24 +00:00
|
|
|
from tools.testing.discover_tests import (
|
|
|
|
|
CPP_TEST_PATH,
|
|
|
|
|
CPP_TEST_PREFIX,
|
|
|
|
|
CPP_TESTS_DIR,
|
|
|
|
|
parse_test_module,
|
|
|
|
|
TESTS,
|
|
|
|
|
)
|
2024-03-01 23:08:10 +00:00
|
|
|
from tools.testing.do_target_determination_for_s3 import import_results
|
2024-04-17 00:18:24 +00:00
|
|
|
from tools.testing.target_determination.gen_artifact import gen_ci_artifact
|
2024-05-21 16:29:29 +00:00
|
|
|
from tools.testing.target_determination.heuristics.previously_failed_in_pr import (
|
|
|
|
|
gen_additional_test_failures_file,
|
|
|
|
|
)
|
2024-05-04 03:08:44 +00:00
|
|
|
from tools.testing.target_determination.heuristics.utils import get_pr_number
|
2023-10-30 23:31:40 +00:00
|
|
|
from tools.testing.test_run import TestRun
|
2023-08-22 16:36:17 +00:00
|
|
|
from tools.testing.test_selections import (
|
|
|
|
|
calculate_shards,
|
|
|
|
|
get_test_case_configs,
|
|
|
|
|
NUM_PROCS,
|
|
|
|
|
ShardedTest,
|
|
|
|
|
THRESHOLD,
|
|
|
|
|
)
|
2024-10-22 16:48:57 +00:00
|
|
|
from tools.testing.upload_artifacts import zip_and_upload_artifacts
|
2023-06-24 03:10:46 +00:00
|
|
|
|
2024-06-29 23:28:38 +00:00
|
|
|
|
2023-08-22 16:36:17 +00:00
|
|
|
# Make sure to remove REPO_ROOT after import is done
|
|
|
|
|
sys.path.remove(str(REPO_ROOT))
|
2018-03-09 21:02:02 +00:00
|
|
|
|
2024-07-16 03:46:39 +00:00
|
|
|
|
2023-08-22 16:36:17 +00:00
|
|
|
HAVE_TEST_SELECTION_TOOLS = True
|
2024-05-06 22:02:16 +00:00
|
|
|
TEST_CONFIG = os.getenv("TEST_CONFIG", "")
|
2024-05-14 17:35:12 +00:00
|
|
|
BUILD_ENVIRONMENT = os.getenv("BUILD_ENVIRONMENT", "")
|
2023-03-31 18:36:53 +00:00
|
|
|
RERUN_DISABLED_TESTS = os.getenv("PYTORCH_TEST_RERUN_DISABLED_TESTS", "0") == "1"
|
Do not collect and skip non-disabled tests when rerunning disabled tests (#102107)
The console log blows up to much when running in rerun disabled tests mode (x50) https://hud.pytorch.org/pytorch/pytorch/commit/e132f09e8878418fb98a4b76a441a324452354ec. Each log is around 1GB and the whole uncompressed logs is ~50GB. After compression, it will be around 1GB, still too big. The increase comes mainly from the multiple SKIPPED message for non-disabled tests, which is expected due to how SkipTest and pytest-flakyfinder currently work.
I update `test/conftest.py` to completely ignore skipped tests when rerunning disabled test instead of collecting then skipping 50 tests each. The benefit of doing is is much more than I originally expect:
* Rerun disabled tests jobs now finish in less than half an hour as they should be
* Fix OOM runner crash because of too many collected tests
* Fix verbosity issue as now only disabled tests are run x50 times. There are only few hundreds of them atm
* Fix timed out issue when rerunning disabled distributed and ASAN tests. They are just too slow when running at x50
### Testing
When rerunning disabled tests https://github.com/pytorch/pytorch/actions/runs/5084508614, only disabled tests on the platform are run, for example `test_ops_jit` on https://ossci-raw-job-status.s3.amazonaws.com/log/13770164954 only ran 100 tests (`test_variant_consistency_jit_linalg_lu_cuda_float32` + `test_variant_consistency_jit_linalg_lu_factor_cuda_complex64`) x50.
```
Executing ['/opt/conda/envs/py_3.10/bin/python', '-bb', 'test_ops_jit.py', '--shard-id=1', '--num-shards=2', '-v', '-vv', '-rfEX', '-p', 'no:xdist', '--use-pytest', '--sc=test_ops_jit_1', '--flake-finder', '--flake-runs=50', '--import-slow-tests', '--import-disabled-tests', '--rerun-disabled-tests'] ... [2023-05-25 21:32:49.763856]
Expand the folded group to see the log file of test_ops_jit 2/2
##[group]PRINTING LOG FILE of test_ops_jit 2/2 (/var/lib/jenkins/workspace/test/test-reports/test_ops_jit_h2wr_t2c.log)
Test results will be stored in test-reports/python-pytest/test_ops_jit/test_ops_jit-51a83bd44549074e.xml
============================= test session starts ==============================
platform linux -- Python 3.10.11, pytest-7.3.1, pluggy-1.0.0 -- /opt/conda/envs/py_3.10/bin/python
cachedir: .pytest_cache
hypothesis profile 'pytorch_ci' -> database=None, max_examples=50, derandomize=True, suppress_health_check=[HealthCheck.too_slow]
rootdir: /var/lib/jenkins/workspace
configfile: pytest.ini
plugins: hypothesis-5.35.1, cpp-2.3.0, flakefinder-1.1.0, rerunfailures-11.1.2, shard-0.1.2, xdist-3.3.0, xdoctest-1.1.0
collecting ... collected 1084 items
Running 100 items in this shard: test/test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_cuda_float32 (x50), test/test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_factor_cuda_complex64 (x50)
stepcurrent: Cannot find last run test, not skipping
test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_cuda_float32 PASSED [2.1876s] [ 1%]
test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_factor_cuda_complex64 PASSED [4.5615s] [ 2%]
```
* [pull](https://github.com/pytorch/pytorch/actions/runs/5093566864)
* [trunk](https://github.com/pytorch/pytorch/actions/runs/5095364311)
* [periodic](https://github.com/pytorch/pytorch/actions/runs/5095378850)
* [slow](https://github.com/pytorch/pytorch/actions/runs/5095390285)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/102107
Approved by: https://github.com/clee2000, https://github.com/malfet
2023-05-27 12:10:32 +00:00
|
|
|
DISTRIBUTED_TEST_PREFIX = "distributed"
|
2024-01-18 15:56:15 +00:00
|
|
|
INDUCTOR_TEST_PREFIX = "inductor"
|
2024-05-14 17:35:12 +00:00
|
|
|
IS_SLOW = "slow" in TEST_CONFIG or "slow" in BUILD_ENVIRONMENT
|
2024-11-20 22:53:09 +00:00
|
|
|
IS_S390X = platform.machine() == "s390x"
|
2023-03-31 18:36:53 +00:00
|
|
|
|
|
|
|
|
|
2023-01-06 22:19:07 +00:00
|
|
|
# Note [ROCm parallel CI testing]
|
|
|
|
|
# https://github.com/pytorch/pytorch/pull/85770 added file-granularity parallel testing.
|
2023-01-30 18:28:32 +00:00
|
|
|
# In .ci/pytorch/test.sh, TEST_CONFIG == "default", CUDA and HIP_VISIBLE_DEVICES is set to 0.
|
2023-01-06 22:19:07 +00:00
|
|
|
# This results in multiple test files sharing the same GPU.
|
|
|
|
|
# This should be a supported use case for ROCm, but it exposed issues in the kernel driver resulting in hangs.
|
|
|
|
|
# See https://github.com/pytorch/pytorch/issues/90940.
|
|
|
|
|
#
|
|
|
|
|
# Further, ROCm self-hosted runners have up to 4 GPUs.
|
|
|
|
|
# Device visibility was set to 0 to match CUDA test behavior, but this was wasting available GPU resources.
|
|
|
|
|
# Assigning each Pool worker their own dedicated GPU avoids the ROCm oversubscription issues.
|
|
|
|
|
# This should also result in better overall wall clock time since all GPUs can be utilized.
|
2023-01-04 19:40:05 +00:00
|
|
|
def maybe_set_hip_visible_devies():
|
|
|
|
|
# Special handling of ROCm GHA runners for parallel (file granularity) tests.
|
|
|
|
|
if torch.version.hip:
|
|
|
|
|
p = current_process()
|
2023-03-26 04:52:55 +00:00
|
|
|
if p.name != "MainProcess":
|
2023-01-04 19:40:05 +00:00
|
|
|
# this is a Process from a parallel Pool, not the MainProcess
|
2023-03-26 04:52:55 +00:00
|
|
|
os.environ["HIP_VISIBLE_DEVICES"] = str(p._identity[0] % NUM_PROCS)
|
2023-01-04 19:40:05 +00:00
|
|
|
|
|
|
|
|
|
2022-12-16 05:32:11 +00:00
|
|
|
def strtobool(s):
|
2024-07-07 16:02:13 +00:00
|
|
|
return s.lower() not in {"", "0", "false", "off"}
|
2022-12-16 05:32:11 +00:00
|
|
|
|
|
|
|
|
|
Run C++ tests on CI with run_test.py (#99956)
After https://github.com/pytorch/pytorch/pull/99559, we can now run C++ test with `run_test.py`. Although advance features such as `--import-slow-tests` and `--import-disabled-tests` won't work for now, there will still be a gain in reliability and performance as C++ can now be retried and run in parallel.
This covers all C++ tests in the CI including aten, libtorch, and Vulkan C++ tests across all platforms Linux, Windows, MacOS.
Notes:
* To support C++ test discovery, the env variable `CPP_TESTS_DIR` can be set to where the C++ test binaries is located
* Support pytest -k argument via run_test as this is used by pytest-cpp to replace `--gtest-filter`
* The XML output is in pytest format, but it's ok now because we don't have slow test or flaky test support for C++ test yet
* ~~I need to figure out why conftest.py doesn't work when I invoke pytest directly for C++ test, so `--sc` is not available for C++ tests at the moment. Proper pytest plugin like stepwise works fine though. I'll investigate and fix it in a separate PR~~ Found the cause, `conftest.py` is per directory and needs to be in any arbitrary directory that holds C++ test
* Two tests `test_api` and `test_tensorexpr` timed out on ASAN, I suspect that ASAN is now used on top of the python executable, which is slower than running native C++ code. IMO, it's ok to run these tests as before on ASAN for now
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99956
Approved by: https://github.com/clee2000, https://github.com/ZainRizvi
2023-05-09 21:24:12 +00:00
|
|
|
class TestChoices(list):
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
super().__init__(args[0])
|
|
|
|
|
|
|
|
|
|
def __contains__(self, item):
|
|
|
|
|
return list.__contains__(self, parse_test_module(item))
|
|
|
|
|
|
|
|
|
|
|
2021-10-07 16:05:05 +00:00
|
|
|
FSDP_TEST = [test for test in TESTS if test.startswith("distributed/fsdp")]
|
|
|
|
|
|
2020-07-28 14:51:28 +00:00
|
|
|
WINDOWS_BLOCKLIST = [
|
2021-08-12 18:39:31 +00:00
|
|
|
"distributed/nn/jit/test_instantiator",
|
|
|
|
|
"distributed/rpc/test_faulty_agent",
|
|
|
|
|
"distributed/rpc/test_tensorpipe_agent",
|
2022-06-01 00:07:48 +00:00
|
|
|
"distributed/rpc/test_share_memory",
|
2021-08-12 18:39:31 +00:00
|
|
|
"distributed/rpc/cuda/test_tensorpipe_agent",
|
|
|
|
|
"distributed/pipeline/sync/skip/test_api",
|
|
|
|
|
"distributed/pipeline/sync/skip/test_gpipe",
|
|
|
|
|
"distributed/pipeline/sync/skip/test_inspect_skip_layout",
|
|
|
|
|
"distributed/pipeline/sync/skip/test_leak",
|
|
|
|
|
"distributed/pipeline/sync/skip/test_portal",
|
|
|
|
|
"distributed/pipeline/sync/skip/test_stash_pop",
|
|
|
|
|
"distributed/pipeline/sync/skip/test_tracker",
|
|
|
|
|
"distributed/pipeline/sync/skip/test_verify_skippables",
|
|
|
|
|
"distributed/pipeline/sync/test_balance",
|
|
|
|
|
"distributed/pipeline/sync/test_bugs",
|
|
|
|
|
"distributed/pipeline/sync/test_checkpoint",
|
|
|
|
|
"distributed/pipeline/sync/test_copy",
|
|
|
|
|
"distributed/pipeline/sync/test_deferred_batch_norm",
|
|
|
|
|
"distributed/pipeline/sync/test_dependency",
|
|
|
|
|
"distributed/pipeline/sync/test_inplace",
|
|
|
|
|
"distributed/pipeline/sync/test_microbatch",
|
|
|
|
|
"distributed/pipeline/sync/test_phony",
|
|
|
|
|
"distributed/pipeline/sync/test_pipe",
|
|
|
|
|
"distributed/pipeline/sync/test_pipeline",
|
|
|
|
|
"distributed/pipeline/sync/test_stream",
|
|
|
|
|
"distributed/pipeline/sync/test_transparency",
|
|
|
|
|
"distributed/pipeline/sync/test_worker",
|
2021-04-29 13:11:18 +00:00
|
|
|
"distributed/elastic/agent/server/test/api_test",
|
2021-08-12 18:39:31 +00:00
|
|
|
"distributed/elastic/multiprocessing/api_test",
|
2022-05-21 22:33:58 +00:00
|
|
|
"distributed/_shard/checkpoint/test_checkpoint"
|
|
|
|
|
"distributed/_shard/checkpoint/test_file_system_checkpoint"
|
2022-02-02 06:53:18 +00:00
|
|
|
"distributed/_shard/sharding_spec/test_sharding_spec",
|
2022-04-25 12:55:24 +00:00
|
|
|
"distributed/_shard/sharding_plan/test_sharding_plan",
|
2022-02-02 06:53:18 +00:00
|
|
|
"distributed/_shard/sharded_tensor/test_sharded_tensor",
|
2022-02-03 05:20:44 +00:00
|
|
|
"distributed/_shard/sharded_tensor/test_sharded_tensor_reshard",
|
2022-02-02 06:53:18 +00:00
|
|
|
"distributed/_shard/sharded_tensor/ops/test_embedding",
|
|
|
|
|
"distributed/_shard/sharded_tensor/ops/test_embedding_bag",
|
|
|
|
|
"distributed/_shard/sharded_tensor/ops/test_binary_cmp",
|
|
|
|
|
"distributed/_shard/sharded_tensor/ops/test_init",
|
|
|
|
|
"distributed/_shard/sharded_optim/test_sharded_optim",
|
2022-02-10 18:42:24 +00:00
|
|
|
] + FSDP_TEST
|
2018-03-09 21:02:02 +00:00
|
|
|
|
2020-07-28 14:51:28 +00:00
|
|
|
ROCM_BLOCKLIST = [
|
2021-08-12 18:39:31 +00:00
|
|
|
"distributed/rpc/test_faulty_agent",
|
|
|
|
|
"distributed/rpc/test_tensorpipe_agent",
|
2022-06-01 00:07:48 +00:00
|
|
|
"distributed/rpc/test_share_memory",
|
2021-08-12 18:39:31 +00:00
|
|
|
"distributed/rpc/cuda/test_tensorpipe_agent",
|
2022-05-21 22:33:58 +00:00
|
|
|
"distributed/_shard/checkpoint/test_checkpoint"
|
|
|
|
|
"distributed/_shard/checkpoint/test_file_system_checkpoint"
|
2022-04-25 12:55:24 +00:00
|
|
|
"distributed/_shard/sharding_spec/test_sharding_spec",
|
2022-02-02 06:53:18 +00:00
|
|
|
"distributed/_shard/sharded_tensor/ops/test_embedding",
|
|
|
|
|
"distributed/_shard/sharded_tensor/ops/test_embedding_bag",
|
|
|
|
|
"distributed/_shard/sharded_tensor/ops/test_binary_cmp",
|
|
|
|
|
"distributed/_shard/sharded_tensor/ops/test_init",
|
|
|
|
|
"distributed/_shard/sharded_optim/test_sharded_optim",
|
2021-08-12 18:39:31 +00:00
|
|
|
"test_determination",
|
|
|
|
|
"test_jit_legacy",
|
2022-10-12 18:37:50 +00:00
|
|
|
"test_cuda_nvml_based_avail",
|
2023-10-06 08:47:15 +00:00
|
|
|
"test_jit_cuda_fuser",
|
2025-01-07 20:38:21 +00:00
|
|
|
"distributed/tensor/test_attention",
|
2022-04-22 19:50:36 +00:00
|
|
|
]
|
2018-08-06 21:48:45 +00:00
|
|
|
|
2024-11-20 22:53:09 +00:00
|
|
|
# whitelist of tests for s390x
|
|
|
|
|
S390X_TESTLIST = [
|
|
|
|
|
"backends/xeon/test_launch.py",
|
|
|
|
|
"benchmark_utils/test_benchmark_utils.py",
|
|
|
|
|
"cpp/apply_utils_test",
|
|
|
|
|
"cpp/atest",
|
|
|
|
|
"cpp/basic",
|
|
|
|
|
"cpp/broadcast_test",
|
|
|
|
|
"cpp/cpu_generator_test",
|
|
|
|
|
"cpp/Dict_test",
|
|
|
|
|
"cpp/Dimname_test",
|
|
|
|
|
"cpp/dlconvertor_test",
|
|
|
|
|
"cpp/extension_backend_test",
|
|
|
|
|
"cpp/lazy_tensor_test",
|
|
|
|
|
"cpp/legacy_vmap_test",
|
|
|
|
|
"cpp/NamedTensor_test",
|
|
|
|
|
"cpp/native_test",
|
|
|
|
|
"cpp/operators_test",
|
|
|
|
|
"cpp/scalar_tensor_test",
|
|
|
|
|
"cpp/scalar_test",
|
|
|
|
|
"cpp/tensor_iterator_test",
|
|
|
|
|
"cpp/test_api",
|
|
|
|
|
"cpp/undefined_tensor_test",
|
|
|
|
|
"cpp/wrapdim_test",
|
|
|
|
|
"distributions/test_constraints",
|
|
|
|
|
"doctests",
|
|
|
|
|
"dynamo/test_activation_checkpointing",
|
|
|
|
|
"dynamo/test_after_aot",
|
|
|
|
|
"dynamo/test_aot_autograd",
|
|
|
|
|
"dynamo/test_aot_autograd_cache",
|
|
|
|
|
"dynamo/test_autograd_function",
|
|
|
|
|
"dynamo/test_backends",
|
|
|
|
|
"dynamo/test_backward_higher_order_ops",
|
|
|
|
|
"dynamo/test_base_output",
|
|
|
|
|
"dynamo/test_bytecode_utils",
|
2025-01-28 03:50:02 +00:00
|
|
|
"dynamo/test_callback",
|
2024-11-20 22:53:09 +00:00
|
|
|
"dynamo/test_compile",
|
|
|
|
|
"dynamo/test_comptime",
|
|
|
|
|
"dynamo/test_config",
|
|
|
|
|
"dynamo/test_ctx_manager",
|
|
|
|
|
"dynamo/test_cudagraphs",
|
|
|
|
|
"dynamo/test_cudagraphs_expandable_segments",
|
|
|
|
|
"dynamo/test_debug_utils",
|
|
|
|
|
"dynamo/test_decorators",
|
|
|
|
|
"dynamo/test_deviceguard",
|
|
|
|
|
"dynamo/test_export",
|
|
|
|
|
"dynamo/test_export_mutations",
|
|
|
|
|
"dynamo/test_frame_init",
|
|
|
|
|
"dynamo/test_fx_passes_pre_grad",
|
|
|
|
|
"dynamo/test_global",
|
|
|
|
|
"dynamo/test_guard_manager",
|
|
|
|
|
"dynamo/test_higher_order_ops",
|
|
|
|
|
"dynamo/test_hooks",
|
|
|
|
|
"dynamo/test_input_attr_tracking",
|
|
|
|
|
"dynamo/test_interop",
|
|
|
|
|
"dynamo/test_logging",
|
|
|
|
|
"dynamo/test_minifier",
|
|
|
|
|
"dynamo/test_model_output",
|
|
|
|
|
"dynamo/test_modes",
|
|
|
|
|
"dynamo/test_modules",
|
|
|
|
|
"dynamo/test_nops",
|
|
|
|
|
"dynamo/test_optimizers",
|
|
|
|
|
"dynamo/test_pre_dispatch",
|
|
|
|
|
"dynamo/test_profiler",
|
|
|
|
|
"dynamo/test_python_autograd",
|
|
|
|
|
"dynamo/test_recompiles",
|
|
|
|
|
"dynamo/test_recompile_ux",
|
|
|
|
|
"dynamo/test_reconstruct",
|
|
|
|
|
"dynamo/test_reorder_logs",
|
|
|
|
|
"dynamo/test_repros",
|
|
|
|
|
"dynamo/test_resume",
|
|
|
|
|
"dynamo/test_sdpa",
|
|
|
|
|
"dynamo/test_skip_non_tensor",
|
|
|
|
|
"dynamo/test_sources",
|
|
|
|
|
"dynamo/test_structured_trace",
|
|
|
|
|
"dynamo/test_subclasses",
|
|
|
|
|
"dynamo/test_subgraphs",
|
|
|
|
|
"dynamo/test_torchrec",
|
|
|
|
|
"dynamo/test_unspec",
|
|
|
|
|
"dynamo/test_utils",
|
|
|
|
|
"dynamo/test_verify_correctness",
|
|
|
|
|
"dynamo/test_view",
|
|
|
|
|
"export/test_db",
|
|
|
|
|
"export/test_experimental",
|
|
|
|
|
"export/test_export",
|
|
|
|
|
"export/test_export_nonstrict",
|
|
|
|
|
"export/test_export_training_ir_to_run_decomp",
|
|
|
|
|
"export/test_functionalized_assertions",
|
|
|
|
|
"export/test_hop",
|
|
|
|
|
"export/test_lift_unlift",
|
|
|
|
|
"export/test_passes",
|
|
|
|
|
"export/test_pass_infra",
|
|
|
|
|
"export/test_retraceability",
|
|
|
|
|
"export/test_schema",
|
|
|
|
|
"export/test_serdes",
|
|
|
|
|
"export/test_serialize",
|
|
|
|
|
"export/test_sparse",
|
|
|
|
|
"export/test_swap",
|
|
|
|
|
"export/test_tools",
|
|
|
|
|
"export/test_torchbind",
|
|
|
|
|
"export/test_tree_utils",
|
|
|
|
|
"export/test_unflatten",
|
|
|
|
|
"export/test_unflatten_training_ir",
|
|
|
|
|
"export/test_verifier",
|
|
|
|
|
"functorch/test_ac",
|
|
|
|
|
"functorch/test_control_flow",
|
|
|
|
|
"functorch/test_eager_transforms",
|
|
|
|
|
"functorch/test_logging",
|
|
|
|
|
"functorch/test_minifier",
|
|
|
|
|
"higher_order_ops/test_with_effects.py",
|
|
|
|
|
"inductor/test_auto_functionalize",
|
|
|
|
|
"inductor/test_autoheuristic",
|
|
|
|
|
"inductor/test_b2b_gemm",
|
|
|
|
|
"inductor/test_benchmarking",
|
|
|
|
|
"inductor/test_ck_backend",
|
|
|
|
|
"inductor/test_codecache",
|
|
|
|
|
"inductor/test_codegen_triton",
|
|
|
|
|
"inductor/test_combo_kernels",
|
|
|
|
|
"inductor/test_compiled_autograd",
|
|
|
|
|
"inductor/test_compiled_optimizers",
|
|
|
|
|
"inductor/test_compile_worker",
|
|
|
|
|
"inductor/test_config",
|
|
|
|
|
"inductor/test_control_flow",
|
|
|
|
|
"inductor/test_coordinate_descent_tuner",
|
|
|
|
|
"inductor/test_cpp_wrapper_hipify",
|
|
|
|
|
"inductor/test_cpu_cpp_wrapper",
|
|
|
|
|
"inductor/test_cudagraph_trees",
|
|
|
|
|
"inductor/test_cudagraph_trees_expandable_segments",
|
|
|
|
|
"inductor/test_cuda_repro",
|
|
|
|
|
"inductor/test_custom_lowering",
|
|
|
|
|
"inductor/test_cutlass_backend",
|
|
|
|
|
"inductor/test_debug_trace",
|
|
|
|
|
"inductor/test_decompose_mem_bound_mm",
|
|
|
|
|
"inductor/test_dependencies",
|
|
|
|
|
"inductor/test_distributed_patterns",
|
|
|
|
|
"inductor/test_efficient_conv_bn_eval",
|
|
|
|
|
"inductor/test_extension_backend",
|
|
|
|
|
"inductor/test_external_callables",
|
|
|
|
|
"inductor/test_flex_attention",
|
|
|
|
|
"inductor/test_flex_decoding",
|
|
|
|
|
"inductor/test_foreach",
|
|
|
|
|
"inductor/test_fp8",
|
|
|
|
|
"inductor/test_fx_fusion",
|
|
|
|
|
"inductor/test_graph_transform_observer",
|
|
|
|
|
"inductor/test_group_batch_fusion",
|
S390x ci periodic tests (#125401)
Periodically run testsuite for s390x
**Dependencies update**
Package z3-solver is updated from version 4.12.2.0 to version 4.12.6.0. This is a minor version update, so no functional change is expected.
The reason for update is build on s390x. pypi doesn't provide binary build for z3-solver for versions 4.12.2.0 or 4.12.6.0 for s390x. Unfortunately, version 4.12.2.0 fails to build with newer gcc used on s390x builders, but those errors are fixed in version 4.12.6.0. Due to this minor version bump fixes build on s390x.
```
# pip3 install z3-solver==4.12.2.0
...
In file included from /tmp/pip-install-756iytc6/z3-solver_ce6f750b780b4146a9a7c01e52672071/core/src/util/region.cpp:53:
/tmp/pip-install-756iytc6/z3-solver_ce6f750b780b4146a9a7c01e52672071/core/src/util/region.cpp: In member function ‘void* region::allocate(size_t)’:
/tmp/pip-install-756iytc6/z3-solver_ce6f750b780b4146a9a7c01e52672071/core/src/util/tptr.h:29:62: error: ‘uintptr_t’ does not name a type
29 | #define ALIGN(T, PTR) reinterpret_cast<T>(((reinterpret_cast<uintptr_t>(PTR) >> PTR_ALIGNMENT) + \
| ^~~~~~~~~
/tmp/pip-install-756iytc6/z3-solver_ce6f750b780b4146a9a7c01e52672071/core/src/util/region.cpp:82:22: note: in expansion of macro ‘ALIGN’
82 | m_curr_ptr = ALIGN(char *, new_curr_ptr);
| ^~~~~
/tmp/pip-install-756iytc6/z3-solver_ce6f750b780b4146a9a7c01e52672071/core/src/util/region.cpp:57:1: note: ‘uintptr_t’ is defined in header ‘<cstdint>’; did you forget to ‘#include <cstdint>’?
56 | #include "util/page.h"
+++ |+#include <cstdint>
57 |
```
**Python paths update**
On AlmaLinux 8 s390x, old paths:
```
python -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())'
/usr/lib/python3.12/site-packages
```
Total result is `/usr/lib/python3.12/site-packages/torch;/usr/lib/python3.12/site-packages`
New paths:
```
python -c 'import site; print(";".join([x for x in site.getsitepackages()] + [x + "/torch" for x in site.getsitepackages()]))'
/usr/local/lib64/python3.12/site-packages;/usr/local/lib/python3.12/site-packages;/usr/lib64/python3.12/site-packages;/usr/lib/python3.12/site-packages;/usr/local/lib64/python3.12/site-packages/torch;/usr/local/lib/python3.12/site-packages/torch;/usr/lib64/python3.12/site-packages/torch;/usr/lib/python3.12/site-packages/torch
```
```
# python -c 'import torch ; print(torch)'
<module 'torch' from '/usr/local/lib64/python3.12/site-packages/torch/__init__.py'>
```
`pip3 install dist/*.whl` installs torch into `/usr/local/lib64/python3.12/site-packages`, and later it's not found by cmake with old paths:
```
CMake Error at CMakeLists.txt:9 (find_package):
By not providing "FindTorch.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Torch", but
CMake did not find one.
```
https://github.com/pytorch/pytorch/actions/runs/10994060107/job/30521868178?pr=125401
**Builders availability**
Build took 60 minutes
Tests took: 150, 110, 65, 55, 115, 85, 50, 70, 105, 110 minutes (split into 10 shards)
60 + 150 + 110 + 65 + 55 + 115 + 85 + 50 + 70 + 105 + 110 = 975 minutes used. Let's double it. It would be 1950 minutes.
We have 20 machines * 24 hours = 20 * 24 * 60 = 20 * 1440 = 28800 minutes
We currently run 5 nightly binaries builds, each on average 90 minutes build, 15 minutes test, 5 minutes upload, 110 minutes total for each, 550 minutes total. Doubling would be 1100 minutes.
That leaves 28800 - 1100 = 27700 minutes total. Periodic tests would use will leave 25750 minutes.
Nightly binaries build + nightly tests = 3050 minutes.
25750 / 3050 = 8.44. So we could do both 8 more times for additional CI runs for any reason. And that is with pretty good safety margin.
**Skip test_tensorexpr**
On s390x, pytorch is built without llvm.
Even if it would be built with llvm, llvm currently doesn't support used features on s390x and test fails with errors like:
```
JIT session error: Unsupported target machine architecture in ELF object pytorch-jitted-objectbuffer
unknown file: Failure
C++ exception with description "valOrErr INTERNAL ASSERT FAILED at "/var/lib/jenkins/workspace/torch/csrc/jit/tensorexpr/llvm_jit.h":34, please report a bug to PyTorch. Unexpected failure in LLVM JIT: Failed to materialize symbols: { (main, { func }) }
```
**Disable cpp/static_runtime_test on s390x**
Quantization is not fully supported on s390x in pytorch yet.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/125401
Approved by: https://github.com/malfet
Co-authored-by: Nikita Shulga <2453524+malfet@users.noreply.github.com>
2025-01-10 18:21:07 +00:00
|
|
|
"inductor/test_gpu_cpp_wrapper",
|
2024-11-20 22:53:09 +00:00
|
|
|
"inductor/test_halide",
|
|
|
|
|
"inductor/test_indexing",
|
|
|
|
|
"inductor/test_inductor_freezing",
|
|
|
|
|
"inductor/test_loop_ordering",
|
|
|
|
|
"inductor/test_memory",
|
|
|
|
|
"inductor/test_memory_planning",
|
|
|
|
|
"inductor/test_metrics",
|
|
|
|
|
"inductor/test_minifier",
|
|
|
|
|
"inductor/test_minifier_isolate",
|
|
|
|
|
"inductor/test_mmdecomp",
|
|
|
|
|
"inductor/test_padding",
|
|
|
|
|
"inductor/test_pad_mm",
|
|
|
|
|
"inductor/test_profiler",
|
|
|
|
|
"inductor/test_scatter_optimization",
|
|
|
|
|
"inductor/test_smoke",
|
|
|
|
|
"inductor/test_standalone_compile",
|
|
|
|
|
"inductor/test_torchbind",
|
|
|
|
|
"inductor/test_triton_cpu_backend",
|
|
|
|
|
"inductor/test_triton_extension_backend",
|
|
|
|
|
"inductor/test_triton_heuristics",
|
|
|
|
|
"inductor/test_triton_kernels",
|
|
|
|
|
"inductor/test_utils",
|
|
|
|
|
"inductor/test_xpu_basic",
|
|
|
|
|
"lazy/test_bindings",
|
|
|
|
|
"lazy/test_debug_util",
|
|
|
|
|
"lazy/test_extract_compiled_graph",
|
|
|
|
|
"lazy/test_functionalization",
|
|
|
|
|
"lazy/test_generator",
|
|
|
|
|
"lazy/test_reuse_ir",
|
|
|
|
|
"lazy/test_step_closures",
|
|
|
|
|
"lazy/test_ts_opinfo",
|
|
|
|
|
"nn/test_convolution.py",
|
|
|
|
|
"nn/test_dropout.py",
|
|
|
|
|
"nn/test_embedding.py",
|
|
|
|
|
"nn/test_init.py",
|
|
|
|
|
"nn/test_lazy_modules.py",
|
|
|
|
|
"nn/test_load_state_dict.py",
|
|
|
|
|
"nn/test_module_hooks.py",
|
|
|
|
|
"nn/test_multihead_attention.py",
|
|
|
|
|
"nn/test_packed_sequence.py",
|
|
|
|
|
"nn/test_parametrization.py",
|
|
|
|
|
"nn/test_pooling.py",
|
|
|
|
|
"nn/test_pruning.py",
|
|
|
|
|
"optim/test_lrscheduler",
|
|
|
|
|
"optim/test_swa_utils",
|
|
|
|
|
"profiler/test_cpp_thread",
|
|
|
|
|
"profiler/test_execution_trace",
|
|
|
|
|
"profiler/test_memory_profiler",
|
|
|
|
|
"profiler/test_record_function",
|
|
|
|
|
"profiler/test_torch_tidy",
|
|
|
|
|
"test_autocast",
|
|
|
|
|
"test_autograd",
|
|
|
|
|
"test_autograd_fallback",
|
|
|
|
|
"test_autoload",
|
|
|
|
|
"test_autoload_disable",
|
|
|
|
|
"test_autoload_enable",
|
|
|
|
|
"test_bundled_inputs",
|
|
|
|
|
"test_comparison_utils",
|
|
|
|
|
"test_compile_benchmark_util",
|
|
|
|
|
"test_complex",
|
|
|
|
|
"test_content_store",
|
|
|
|
|
"test_cpp_api_parity",
|
|
|
|
|
"test_cpp_extensions_aot_ninja",
|
|
|
|
|
"test_cpp_extensions_aot_no_ninja",
|
|
|
|
|
"test_cpp_extensions_jit",
|
|
|
|
|
"test_cpp_extensions_mtia_backend",
|
|
|
|
|
"test_cpp_extensions_stream_and_event",
|
|
|
|
|
"test_cuda",
|
|
|
|
|
"test_cuda_expandable_segments",
|
|
|
|
|
"test_cuda_multigpu",
|
|
|
|
|
"test_cuda_nvml_based_avail",
|
|
|
|
|
"test_cuda_primary_ctx",
|
|
|
|
|
"test_cuda_sanitizer",
|
|
|
|
|
"test_cuda_trace",
|
|
|
|
|
"test_custom_ops",
|
|
|
|
|
"test_datapipe",
|
|
|
|
|
"test_deploy",
|
|
|
|
|
"test_dispatch",
|
|
|
|
|
"test_dlpack",
|
|
|
|
|
"test_dynamic_shapes",
|
|
|
|
|
"test_expanded_weights",
|
|
|
|
|
"test_fake_tensor",
|
|
|
|
|
"test_file_check",
|
|
|
|
|
"test_flop_counter",
|
|
|
|
|
"test_functionalization",
|
|
|
|
|
"test_functionalization_of_rng_ops",
|
|
|
|
|
"test_functional_optim",
|
|
|
|
|
"test_function_schema",
|
|
|
|
|
"test_futures",
|
|
|
|
|
"test_hub",
|
|
|
|
|
"test_import_stats",
|
|
|
|
|
"test_indexing",
|
|
|
|
|
"test_itt",
|
|
|
|
|
"test_legacy_vmap",
|
|
|
|
|
"test_logging",
|
|
|
|
|
"test_masked",
|
|
|
|
|
"test_maskedtensor",
|
|
|
|
|
"test_matmul_cuda",
|
|
|
|
|
"test_mkldnn",
|
|
|
|
|
"test_mkldnn_fusion",
|
|
|
|
|
"test_mkldnn_verbose",
|
|
|
|
|
"test_mkl_verbose",
|
|
|
|
|
"test_mobile_optimizer",
|
|
|
|
|
"test_module_tracker",
|
|
|
|
|
"test_monitor",
|
|
|
|
|
"test_namedtuple_return_api",
|
|
|
|
|
"test_native_mha",
|
|
|
|
|
"test_nestedtensor",
|
|
|
|
|
"test_numba_integration",
|
|
|
|
|
"test_numpy_interop",
|
|
|
|
|
"test_openmp",
|
|
|
|
|
"test_out_dtype_op",
|
|
|
|
|
"test_overrides",
|
|
|
|
|
"test_package",
|
|
|
|
|
"test_per_overload_api",
|
|
|
|
|
"test_prims",
|
|
|
|
|
"test_pruning_op",
|
|
|
|
|
"test_python_dispatch",
|
|
|
|
|
"test_scatter_gather_ops",
|
|
|
|
|
"test_segment_reductions",
|
|
|
|
|
"test_serialization",
|
|
|
|
|
"test_set_default_mobile_cpu_allocator",
|
|
|
|
|
"test_shape_ops",
|
|
|
|
|
"test_show_pickle",
|
|
|
|
|
"test_sort_and_select",
|
|
|
|
|
"test_spectral_ops",
|
|
|
|
|
"test_stateless",
|
|
|
|
|
"test_subclass",
|
|
|
|
|
"test_tensorboard",
|
|
|
|
|
"test_tensor_creation_ops",
|
|
|
|
|
"test_tensorexpr",
|
|
|
|
|
"test_tensorexpr_pybind",
|
|
|
|
|
"test_torch",
|
|
|
|
|
"test_transformers",
|
|
|
|
|
"test_type_hints",
|
|
|
|
|
"test_type_info",
|
|
|
|
|
"test_type_promotion",
|
|
|
|
|
"test_typing",
|
|
|
|
|
"test_utils",
|
|
|
|
|
"test_view_ops",
|
|
|
|
|
"test_vulkan",
|
|
|
|
|
"test_weak",
|
|
|
|
|
"test_xnnpack_integration",
|
|
|
|
|
"torch_np/numpy_tests/core/test_dlpack",
|
|
|
|
|
"torch_np/numpy_tests/core/test_dtype",
|
|
|
|
|
"torch_np/numpy_tests/core/test_einsum",
|
|
|
|
|
"torch_np/numpy_tests/core/test_getlimits",
|
|
|
|
|
"torch_np/numpy_tests/core/test_indexing",
|
|
|
|
|
"torch_np/numpy_tests/core/test_numeric",
|
|
|
|
|
"torch_np/numpy_tests/core/test_numerictypes",
|
|
|
|
|
"torch_np/numpy_tests/core/test_scalar_ctors",
|
|
|
|
|
"torch_np/numpy_tests/core/test_scalarinherit",
|
|
|
|
|
"torch_np/numpy_tests/core/test_scalarmath",
|
|
|
|
|
"torch_np/numpy_tests/core/test_scalar_methods",
|
|
|
|
|
"torch_np/numpy_tests/core/test_shape_base",
|
|
|
|
|
"torch_np/numpy_tests/fft/test_helper",
|
|
|
|
|
"torch_np/numpy_tests/fft/test_pocketfft",
|
|
|
|
|
"torch_np/numpy_tests/lib/test_arraypad",
|
|
|
|
|
"torch_np/numpy_tests/lib/test_arraysetops",
|
|
|
|
|
"torch_np/numpy_tests/lib/test_function_base",
|
|
|
|
|
"torch_np/numpy_tests/lib/test_histograms",
|
|
|
|
|
"torch_np/numpy_tests/lib/test_index_tricks",
|
|
|
|
|
"torch_np/numpy_tests/lib/test_shape_base_",
|
|
|
|
|
"torch_np/numpy_tests/lib/test_twodim_base",
|
|
|
|
|
"torch_np/numpy_tests/lib/test_type_check",
|
|
|
|
|
"torch_np/numpy_tests/linalg/test_linalg",
|
|
|
|
|
"torch_np/test_basic",
|
|
|
|
|
"torch_np/test_binary_ufuncs",
|
|
|
|
|
"torch_np/test_dtype",
|
|
|
|
|
"torch_np/test_function_base",
|
|
|
|
|
"torch_np/test_ndarray_methods",
|
|
|
|
|
"torch_np/test_nep50_examples",
|
|
|
|
|
"torch_np/test_random",
|
|
|
|
|
"torch_np/test_reductions",
|
|
|
|
|
"torch_np/test_scalars_0D_arrays",
|
|
|
|
|
"torch_np/test_ufuncs_basic",
|
|
|
|
|
"torch_np/test_unary_ufuncs",
|
|
|
|
|
"xpu/test_conv.py",
|
|
|
|
|
"xpu/test_gemm.py",
|
|
|
|
|
]
|
|
|
|
|
|
2024-01-23 08:20:37 +00:00
|
|
|
XPU_BLOCKLIST = [
|
|
|
|
|
"test_autograd",
|
2024-08-09 23:58:50 +00:00
|
|
|
"profiler/test_cpp_thread",
|
|
|
|
|
"profiler/test_execution_trace",
|
|
|
|
|
"profiler/test_memory_profiler",
|
|
|
|
|
"profiler/test_profiler",
|
|
|
|
|
"profiler/test_profiler_tree",
|
|
|
|
|
"profiler/test_record_function",
|
|
|
|
|
"profiler/test_torch_tidy",
|
2024-01-23 08:20:37 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
XPU_TEST = [
|
|
|
|
|
"test_xpu",
|
|
|
|
|
]
|
|
|
|
|
|
2023-04-19 19:29:03 +00:00
|
|
|
# The tests inside these files should never be run in parallel with each other
|
2020-07-28 14:51:28 +00:00
|
|
|
RUN_PARALLEL_BLOCKLIST = [
|
2025-01-23 00:31:37 +00:00
|
|
|
"test_extension_utils",
|
2021-08-12 18:39:31 +00:00
|
|
|
"test_cpp_extensions_jit",
|
2022-07-11 22:11:58 +00:00
|
|
|
"test_cpp_extensions_open_device_registration",
|
2024-04-25 18:48:49 +00:00
|
|
|
"test_cpp_extensions_stream_and_event",
|
|
|
|
|
"test_cpp_extensions_mtia_backend",
|
2021-08-12 18:39:31 +00:00
|
|
|
"test_jit_disabled",
|
|
|
|
|
"test_mobile_optimizer",
|
|
|
|
|
"test_multiprocessing",
|
|
|
|
|
"test_multiprocessing_spawn",
|
|
|
|
|
"test_namedtuple_return_api",
|
|
|
|
|
"test_overrides",
|
|
|
|
|
"test_show_pickle",
|
|
|
|
|
"test_tensorexpr",
|
|
|
|
|
"test_cuda_primary_ctx",
|
2022-08-11 10:21:40 +00:00
|
|
|
"test_cuda_trace",
|
2024-03-19 01:35:34 +00:00
|
|
|
"inductor/test_benchmark_fusion",
|
2022-10-12 18:37:50 +00:00
|
|
|
"test_cuda_nvml_based_avail",
|
2023-08-09 14:59:37 +00:00
|
|
|
# temporarily sets a global config
|
|
|
|
|
"test_autograd_fallback",
|
Add compiler bisector (#131936)
This is a utility to aid the torch.compile debugging. You provide a function that returns True on success, False on failure, or do something out of process and run bisect_helper `good | bad`.
The bisector will first go through backends - `eager`, `aot_eager`, `aot_eager_decomp_partition`, `inductor` to find the first failing backend. Then, it will go through subsystems within the backend - currently limited but could be expanded - and try to find the first subsystem for which disabling fixes the problem. Once it has found the failing subsystem, it will find the number of times the subsystem is applied, and then bisect through it.
An example usage of how to hook it up for aot_eager_decomp_partition and decomposition subsystem is :
```
from torch._inductor.bisect_helper import BisectionManager
if op in CURRENT_DECOMPOSITION_TABLE:
if BisectionManager.disable_subsystem("aot_eager_decomp_partition", "decomposition", lambda: repr(op)):
return NotImplemented
```
Once it has discovered the problematic change, it will print out the associated debug info, and you can set the same limits with `TORCH_BISECT_BACKEND` `TORCH_BISECT_SUBSYSTEM` and `TORCH_BISECT_MAX`.
We could add further options as an automated way of going through a check list for checking divergence - e.g., the mode to emulate amp casts.
Fix for https://github.com/pytorch/pytorch/issues/126546
Pull Request resolved: https://github.com/pytorch/pytorch/pull/131936
Approved by: https://github.com/ezyang
2024-10-09 17:10:52 +00:00
|
|
|
"inductor/test_compiler_bisector",
|
2021-10-07 16:05:05 +00:00
|
|
|
] + FSDP_TEST
|
2021-08-25 18:19:49 +00:00
|
|
|
|
2023-04-19 19:29:03 +00:00
|
|
|
# Test files that should always be run serially with other test files,
|
|
|
|
|
# but it's okay if the tests inside them are run in parallel with each other.
|
2022-10-03 16:59:39 +00:00
|
|
|
CI_SERIAL_LIST = [
|
2023-03-26 04:52:55 +00:00
|
|
|
"test_nn",
|
|
|
|
|
"test_fake_tensor",
|
|
|
|
|
"test_cpp_api_parity",
|
|
|
|
|
"test_reductions",
|
|
|
|
|
"test_fx_backends",
|
|
|
|
|
"test_cpp_extensions_jit",
|
|
|
|
|
"test_torch",
|
|
|
|
|
"test_tensor_creation_ops",
|
|
|
|
|
"test_dispatch",
|
2023-04-07 18:26:35 +00:00
|
|
|
"test_python_dispatch", # torch.library creation and deletion must be serialized
|
2023-03-26 04:52:55 +00:00
|
|
|
"test_spectral_ops", # Cause CUDA illegal memory access https://github.com/pytorch/pytorch/issues/88916
|
|
|
|
|
"nn/test_pooling",
|
|
|
|
|
"nn/test_convolution", # Doesn't respect set_per_process_memory_fraction, results in OOM for other tests in slow gradcheck
|
|
|
|
|
"distributions/test_distributions",
|
|
|
|
|
"test_fx", # gets SIGKILL
|
|
|
|
|
"functorch/test_memory_efficient_fusion", # Cause CUDA OOM on ROCm
|
2023-03-31 18:36:53 +00:00
|
|
|
"test_utils", # OOM
|
|
|
|
|
"test_sort_and_select", # OOM
|
|
|
|
|
"test_backward_compatible_arguments", # OOM
|
|
|
|
|
"test_autocast", # OOM
|
|
|
|
|
"test_native_mha", # OOM
|
|
|
|
|
"test_module_hooks", # OOM
|
2024-03-12 10:31:22 +00:00
|
|
|
"inductor/test_max_autotune",
|
Add Lowering for FlexAttention Backwards (#125515)
# Summary
#### What does this PR do?
It enables Inductor to actually generate the fused flex attention kernel for the backwards
I did some other things along the way:
- Abstract out the 'build_subgraph_buffer' subroutine and make it reusable between flex attention and flex_attention backwards. In total we need too build 3 subgraphs for fwd + bwd. 1 for the fwd graph and then 2 in the bwd. The FAv2 algorithm recomputes the parts of the forward (more efficiently since we already have the row_max via logsumexp), therefore we need to inline both the fwd graph and the joint graph in the bwds kernel.
- The version of the backwards kernel is from a somewhat older version of the triton tutorial implementation. I think that we should update in a follow up to a newer version. Notably the blocks need to be square for this to work as currently implemented. I am sure there are many opportunities for optimization.
- I didnt correctly register the decomp table + IndexMode when I landed: https://github.com/pytorch/pytorch/pull/123902, this remedies that.
- The rel_bias helper func was reversed in terms of causality. I updated and then add a test specific for "future causal" attention.
- This PRs but the main point that I think still needs to be worked out is the store_output call. I have it hacked up to be 'fake' but I dont think we want to land that and likely want to just have a mutated 'dq' and a stored_output 'dk'
- I also needed to update the `TritonTemplateKernel` to actually accept multiple subgraphs (modifications)
- I updated the benchmark to also profile bwds performance
### Benchmark Numbers:
_The current implementation is not parallelizing over ctx length in the bwd_
FWD Speedups
| Type | Speedup | shape | score_mod | dtype |
|---------|-----------|--------------------|-------------|----------------|
| Average | 0.991 | | | |
| Max | 1.182 | (16, 16, 4096, 64) | noop | torch.bfloat16 |
| Min | 0.796 | (2, 16, 512, 256) | head_bias | torch.bfloat16 |
BWD Speedups
| Type | Speedup | shape | score_mod | dtype |
|---------|-----------|--------------------|-------------|----------------|
| Average | 0.291 | | | |
| Max | 0.652 | (8, 16, 512, 64) | head_bias | torch.bfloat16 |
| Min | 0.073 | (2, 16, 4096, 128) | head_bias | torch.bfloat16 |
<details>
<summary>Full Data</summary>
| shape | score_mod | dtype | fwd_eager_time | fwd_compiled_time | bwd_eager_time | bwd_compiled_time | fwd_speedup | bwd_speedup |
|---------------------|---------------|----------------|------------------|---------------------|------------------|---------------------|---------------|---------------|
| (2, 16, 512, 64) | noop | torch.bfloat16 | 19.936 | 19.092 | 57.851 | 193.564 | 1.044 | 0.299 |
| (2, 16, 512, 64) | causal_mask | torch.bfloat16 | 19.955 | 19.497 | 57.662 | 206.278 | 1.024 | 0.280 |
| (2, 16, 512, 64) | relative_bias | torch.bfloat16 | 19.455 | 21.297 | 57.674 | 195.219 | 0.913 | 0.295 |
| (2, 16, 512, 64) | head_bias | torch.bfloat16 | 19.958 | 21.289 | 57.674 | 193.859 | 0.938 | 0.298 |
| (2, 16, 512, 128) | noop | torch.bfloat16 | 28.157 | 28.615 | 82.831 | 454.211 | 0.984 | 0.182 |
| (2, 16, 512, 128) | causal_mask | torch.bfloat16 | 28.154 | 28.444 | 83.091 | 432.083 | 0.990 | 0.192 |
| (2, 16, 512, 128) | relative_bias | torch.bfloat16 | 28.722 | 27.897 | 83.175 | 446.789 | 1.030 | 0.186 |
| (2, 16, 512, 128) | head_bias | torch.bfloat16 | 28.299 | 27.673 | 83.052 | 459.179 | 1.023 | 0.181 |
| (2, 16, 512, 256) | noop | torch.bfloat16 | 41.167 | 50.504 | 175.019 | 1083.545 | 0.815 | 0.162 |
| (2, 16, 512, 256) | causal_mask | torch.bfloat16 | 41.656 | 51.933 | 175.078 | 1171.176 | 0.802 | 0.149 |
| (2, 16, 512, 256) | relative_bias | torch.bfloat16 | 41.697 | 50.722 | 175.159 | 1097.312 | 0.822 | 0.160 |
| (2, 16, 512, 256) | head_bias | torch.bfloat16 | 41.690 | 52.387 | 175.184 | 1097.336 | 0.796 | 0.160 |
| (2, 16, 1024, 64) | noop | torch.bfloat16 | 39.232 | 37.454 | 127.847 | 612.430 | 1.047 | 0.209 |
| (2, 16, 1024, 64) | causal_mask | torch.bfloat16 | 39.930 | 39.599 | 127.755 | 665.359 | 1.008 | 0.192 |
| (2, 16, 1024, 64) | relative_bias | torch.bfloat16 | 39.417 | 41.304 | 127.902 | 614.990 | 0.954 | 0.208 |
| (2, 16, 1024, 64) | head_bias | torch.bfloat16 | 39.965 | 42.034 | 127.953 | 613.273 | 0.951 | 0.209 |
| (2, 16, 1024, 128) | noop | torch.bfloat16 | 63.964 | 71.024 | 226.510 | 1637.669 | 0.901 | 0.138 |
| (2, 16, 1024, 128) | causal_mask | torch.bfloat16 | 63.843 | 72.451 | 226.750 | 1558.949 | 0.881 | 0.145 |
| (2, 16, 1024, 128) | relative_bias | torch.bfloat16 | 64.301 | 70.487 | 226.651 | 1610.063 | 0.912 | 0.141 |
| (2, 16, 1024, 128) | head_bias | torch.bfloat16 | 64.033 | 71.394 | 226.676 | 1668.511 | 0.897 | 0.136 |
| (2, 16, 1024, 256) | noop | torch.bfloat16 | 129.348 | 141.390 | 507.337 | 4405.175 | 0.915 | 0.115 |
| (2, 16, 1024, 256) | causal_mask | torch.bfloat16 | 129.538 | 145.680 | 507.178 | 4768.874 | 0.889 | 0.106 |
| (2, 16, 1024, 256) | relative_bias | torch.bfloat16 | 129.438 | 142.782 | 507.004 | 4401.002 | 0.907 | 0.115 |
| (2, 16, 1024, 256) | head_bias | torch.bfloat16 | 129.058 | 146.242 | 507.547 | 4434.251 | 0.883 | 0.114 |
| (2, 16, 4096, 64) | noop | torch.bfloat16 | 481.606 | 409.120 | 1440.890 | 14147.269 | 1.177 | 0.102 |
| (2, 16, 4096, 64) | causal_mask | torch.bfloat16 | 480.227 | 438.847 | 1434.419 | 14973.386 | 1.094 | 0.096 |
| (2, 16, 4096, 64) | relative_bias | torch.bfloat16 | 480.831 | 458.104 | 1432.935 | 14193.253 | 1.050 | 0.101 |
| (2, 16, 4096, 64) | head_bias | torch.bfloat16 | 480.749 | 452.497 | 1437.040 | 14084.869 | 1.062 | 0.102 |
| (2, 16, 4096, 128) | noop | torch.bfloat16 | 872.534 | 848.275 | 2600.895 | 35156.849 | 1.029 | 0.074 |
| (2, 16, 4096, 128) | causal_mask | torch.bfloat16 | 872.647 | 868.279 | 2587.581 | 31919.531 | 1.005 | 0.081 |
| (2, 16, 4096, 128) | relative_bias | torch.bfloat16 | 871.484 | 827.644 | 2593.989 | 34805.634 | 1.053 | 0.075 |
| (2, 16, 4096, 128) | head_bias | torch.bfloat16 | 871.422 | 856.437 | 2602.482 | 35708.591 | 1.017 | 0.073 |
| (2, 16, 4096, 256) | noop | torch.bfloat16 | 1904.497 | 1758.183 | 6122.416 | 66754.593 | 1.083 | 0.092 |
| (2, 16, 4096, 256) | causal_mask | torch.bfloat16 | 1911.174 | 1762.821 | 6113.207 | 72759.392 | 1.084 | 0.084 |
| (2, 16, 4096, 256) | relative_bias | torch.bfloat16 | 1911.254 | 1727.108 | 6123.530 | 66577.988 | 1.107 | 0.092 |
| (2, 16, 4096, 256) | head_bias | torch.bfloat16 | 1916.977 | 1801.804 | 6118.158 | 67359.680 | 1.064 | 0.091 |
| (8, 16, 512, 64) | noop | torch.bfloat16 | 44.984 | 43.974 | 170.276 | 262.259 | 1.023 | 0.649 |
| (8, 16, 512, 64) | causal_mask | torch.bfloat16 | 45.001 | 46.265 | 170.509 | 274.893 | 0.973 | 0.620 |
| (8, 16, 512, 64) | relative_bias | torch.bfloat16 | 45.466 | 48.211 | 170.606 | 262.759 | 0.943 | 0.649 |
| (8, 16, 512, 64) | head_bias | torch.bfloat16 | 45.481 | 48.435 | 170.267 | 261.265 | 0.939 | 0.652 |
| (8, 16, 512, 128) | noop | torch.bfloat16 | 72.565 | 74.736 | 313.220 | 773.126 | 0.971 | 0.405 |
| (8, 16, 512, 128) | causal_mask | torch.bfloat16 | 72.015 | 75.755 | 313.311 | 775.513 | 0.951 | 0.404 |
| (8, 16, 512, 128) | relative_bias | torch.bfloat16 | 72.105 | 74.189 | 313.806 | 769.238 | 0.972 | 0.408 |
| (8, 16, 512, 128) | head_bias | torch.bfloat16 | 72.005 | 74.364 | 313.509 | 775.237 | 0.968 | 0.404 |
| (8, 16, 512, 256) | noop | torch.bfloat16 | 138.656 | 165.453 | 663.707 | 2672.067 | 0.838 | 0.248 |
| (8, 16, 512, 256) | causal_mask | torch.bfloat16 | 139.096 | 172.613 | 663.593 | 2926.538 | 0.806 | 0.227 |
| (8, 16, 512, 256) | relative_bias | torch.bfloat16 | 139.500 | 168.417 | 663.938 | 2658.629 | 0.828 | 0.250 |
| (8, 16, 512, 256) | head_bias | torch.bfloat16 | 139.776 | 173.549 | 662.920 | 2667.266 | 0.805 | 0.249 |
| (8, 16, 1024, 64) | noop | torch.bfloat16 | 134.883 | 125.004 | 484.706 | 1195.254 | 1.079 | 0.406 |
| (8, 16, 1024, 64) | causal_mask | torch.bfloat16 | 134.297 | 132.875 | 485.420 | 1234.953 | 1.011 | 0.393 |
| (8, 16, 1024, 64) | relative_bias | torch.bfloat16 | 134.839 | 139.231 | 485.470 | 1198.556 | 0.968 | 0.405 |
| (8, 16, 1024, 64) | head_bias | torch.bfloat16 | 133.822 | 136.449 | 485.608 | 1189.198 | 0.981 | 0.408 |
| (8, 16, 1024, 128) | noop | torch.bfloat16 | 235.470 | 234.765 | 886.094 | 2662.944 | 1.003 | 0.333 |
| (8, 16, 1024, 128) | causal_mask | torch.bfloat16 | 236.305 | 241.382 | 886.293 | 2646.984 | 0.979 | 0.335 |
| (8, 16, 1024, 128) | relative_bias | torch.bfloat16 | 236.414 | 233.980 | 885.250 | 2642.178 | 1.010 | 0.335 |
| (8, 16, 1024, 128) | head_bias | torch.bfloat16 | 237.176 | 239.040 | 885.754 | 2665.242 | 0.992 | 0.332 |
| (8, 16, 1024, 256) | noop | torch.bfloat16 | 504.445 | 517.855 | 1978.956 | 9592.906 | 0.974 | 0.206 |
| (8, 16, 1024, 256) | causal_mask | torch.bfloat16 | 502.428 | 536.002 | 1978.611 | 10607.342 | 0.937 | 0.187 |
| (8, 16, 1024, 256) | relative_bias | torch.bfloat16 | 503.396 | 523.960 | 1977.993 | 9539.284 | 0.961 | 0.207 |
| (8, 16, 1024, 256) | head_bias | torch.bfloat16 | 503.818 | 536.014 | 1980.131 | 9576.262 | 0.940 | 0.207 |
| (8, 16, 4096, 64) | noop | torch.bfloat16 | 1970.139 | 1674.930 | 5750.940 | 16724.134 | 1.176 | 0.344 |
| (8, 16, 4096, 64) | causal_mask | torch.bfloat16 | 1959.036 | 1775.056 | 5780.512 | 17390.350 | 1.104 | 0.332 |
| (8, 16, 4096, 64) | relative_bias | torch.bfloat16 | 1947.198 | 1773.869 | 5780.643 | 16779.699 | 1.098 | 0.345 |
| (8, 16, 4096, 64) | head_bias | torch.bfloat16 | 1963.935 | 1829.502 | 5780.018 | 16703.259 | 1.073 | 0.346 |
| (8, 16, 4096, 128) | noop | torch.bfloat16 | 3582.711 | 3362.623 | 10436.069 | 36415.565 | 1.065 | 0.287 |
| (8, 16, 4096, 128) | causal_mask | torch.bfloat16 | 3581.504 | 3499.472 | 10346.869 | 36164.959 | 1.023 | 0.286 |
| (8, 16, 4096, 128) | relative_bias | torch.bfloat16 | 3589.779 | 3337.849 | 10529.621 | 36261.696 | 1.075 | 0.290 |
| (8, 16, 4096, 128) | head_bias | torch.bfloat16 | 3602.265 | 3436.444 | 10458.660 | 36507.790 | 1.048 | 0.286 |
| (8, 16, 4096, 256) | noop | torch.bfloat16 | 7695.923 | 7126.275 | 24643.009 | 140949.081 | 1.080 | 0.175 |
| (8, 16, 4096, 256) | causal_mask | torch.bfloat16 | 7679.939 | 7186.252 | 24538.105 | 157156.067 | 1.069 | 0.156 |
| (8, 16, 4096, 256) | relative_bias | torch.bfloat16 | 7681.374 | 6994.832 | 24549.713 | 140077.179 | 1.098 | 0.175 |
| (8, 16, 4096, 256) | head_bias | torch.bfloat16 | 7679.822 | 7212.278 | 24627.823 | 140675.003 | 1.065 | 0.175 |
| (16, 16, 512, 64) | noop | torch.bfloat16 | 80.126 | 78.291 | 333.719 | 541.165 | 1.023 | 0.617 |
| (16, 16, 512, 64) | causal_mask | torch.bfloat16 | 80.065 | 81.696 | 333.779 | 551.113 | 0.980 | 0.606 |
| (16, 16, 512, 64) | relative_bias | torch.bfloat16 | 80.138 | 86.715 | 333.364 | 542.118 | 0.924 | 0.615 |
| (16, 16, 512, 64) | head_bias | torch.bfloat16 | 80.415 | 85.204 | 333.294 | 536.840 | 0.944 | 0.621 |
| (16, 16, 512, 128) | noop | torch.bfloat16 | 134.964 | 138.025 | 607.093 | 1333.102 | 0.978 | 0.455 |
| (16, 16, 512, 128) | causal_mask | torch.bfloat16 | 134.192 | 141.523 | 606.269 | 1424.318 | 0.948 | 0.426 |
| (16, 16, 512, 128) | relative_bias | torch.bfloat16 | 135.711 | 138.639 | 606.283 | 1327.974 | 0.979 | 0.457 |
| (16, 16, 512, 128) | head_bias | torch.bfloat16 | 135.552 | 140.555 | 607.107 | 1347.370 | 0.964 | 0.451 |
| (16, 16, 512, 256) | noop | torch.bfloat16 | 275.113 | 315.144 | 1301.583 | 5268.153 | 0.873 | 0.247 |
| (16, 16, 512, 256) | causal_mask | torch.bfloat16 | 274.867 | 328.106 | 1302.513 | 5770.594 | 0.838 | 0.226 |
| (16, 16, 512, 256) | relative_bias | torch.bfloat16 | 276.052 | 321.770 | 1302.904 | 5241.920 | 0.858 | 0.249 |
| (16, 16, 512, 256) | head_bias | torch.bfloat16 | 271.409 | 328.839 | 1302.142 | 5266.037 | 0.825 | 0.247 |
| (16, 16, 1024, 64) | noop | torch.bfloat16 | 260.489 | 237.463 | 955.884 | 1817.558 | 1.097 | 0.526 |
| (16, 16, 1024, 64) | causal_mask | torch.bfloat16 | 262.378 | 254.350 | 955.280 | 1843.807 | 1.032 | 0.518 |
| (16, 16, 1024, 64) | relative_bias | torch.bfloat16 | 261.338 | 268.253 | 956.038 | 1820.036 | 0.974 | 0.525 |
| (16, 16, 1024, 64) | head_bias | torch.bfloat16 | 262.153 | 264.156 | 956.023 | 1810.076 | 0.992 | 0.528 |
| (16, 16, 1024, 128) | noop | torch.bfloat16 | 476.475 | 461.413 | 1760.578 | 4306.521 | 1.033 | 0.409 |
| (16, 16, 1024, 128) | causal_mask | torch.bfloat16 | 473.794 | 479.178 | 1761.277 | 4619.439 | 0.989 | 0.381 |
| (16, 16, 1024, 128) | relative_bias | torch.bfloat16 | 473.839 | 463.282 | 1758.692 | 4290.562 | 1.023 | 0.410 |
| (16, 16, 1024, 128) | head_bias | torch.bfloat16 | 472.979 | 472.896 | 1763.086 | 4367.931 | 1.000 | 0.404 |
| (16, 16, 1024, 256) | noop | torch.bfloat16 | 1014.184 | 1026.764 | 3922.997 | 19104.147 | 0.988 | 0.205 |
| (16, 16, 1024, 256) | causal_mask | torch.bfloat16 | 1013.217 | 1039.046 | 3928.382 | 21086.281 | 0.975 | 0.186 |
| (16, 16, 1024, 256) | relative_bias | torch.bfloat16 | 1008.519 | 1015.278 | 3922.133 | 18980.652 | 0.993 | 0.207 |
| (16, 16, 1024, 256) | head_bias | torch.bfloat16 | 1011.360 | 1047.542 | 3931.245 | 19069.172 | 0.965 | 0.206 |
| (16, 16, 4096, 64) | noop | torch.bfloat16 | 3929.850 | 3325.667 | 11411.704 | 23344.280 | 1.182 | 0.489 |
| (16, 16, 4096, 64) | causal_mask | torch.bfloat16 | 3885.262 | 3581.544 | 11390.515 | 23725.639 | 1.085 | 0.480 |
| (16, 16, 4096, 64) | relative_bias | torch.bfloat16 | 3865.737 | 3537.308 | 11489.901 | 23406.330 | 1.093 | 0.491 |
| (16, 16, 4096, 64) | head_bias | torch.bfloat16 | 3880.530 | 3665.249 | 11484.411 | 23299.496 | 1.059 | 0.493 |
| (16, 16, 4096, 128) | noop | torch.bfloat16 | 7030.306 | 6745.715 | 20621.264 | 57464.096 | 1.042 | 0.359 |
| (16, 16, 4096, 128) | causal_mask | torch.bfloat16 | 7095.414 | 7034.385 | 20410.656 | 61660.511 | 1.009 | 0.331 |
| (16, 16, 4096, 128) | relative_bias | torch.bfloat16 | 7084.779 | 6686.497 | 20315.161 | 57243.969 | 1.060 | 0.355 |
| (16, 16, 4096, 128) | head_bias | torch.bfloat16 | 7075.367 | 6863.305 | 20494.385 | 58481.953 | 1.031 | 0.350 |
| (16, 16, 4096, 256) | noop | torch.bfloat16 | 15612.741 | 14297.482 | 55306.847 | 281161.865 | 1.092 | 0.197 |
| (16, 16, 4096, 256) | causal_mask | torch.bfloat16 | 15326.592 | 14263.878 | 55227.806 | 313063.232 | 1.075 | 0.176 |
| (16, 16, 4096, 256) | relative_bias | torch.bfloat16 | 15297.963 | 14007.379 | 54558.029 | 279529.175 | 1.092 | 0.195 |
| (16, 16, 4096, 256) | head_bias | torch.bfloat16 | 15216.160 | 14276.027 | 55081.581 | 280996.826 | 1.066 | 0.196 |
</details>
Pull Request resolved: https://github.com/pytorch/pytorch/pull/125515
Approved by: https://github.com/Chillee
2024-05-17 00:41:55 +00:00
|
|
|
"inductor/test_cutlass_backend", # slow due to many nvcc compilation steps,
|
|
|
|
|
"inductor/test_flex_attention", # OOM
|
2022-10-03 16:59:39 +00:00
|
|
|
]
|
[ONNX] Run ONNX tests as part of standard run_test script (#99215)
<!--
copilot:all
-->
### <samp>🤖 Generated by Copilot at dcbf7e2</samp>
### Summary
📝🧹🚩
<!--
1. 📝 for simplifying the `./scripts/onnx/test.sh` script
2. 🧹 for refactoring the `test/onnx/dynamo/test_exporter_api.py` file
3. 🚩 for adding the `--onnx` flag to `test/run_test.py` and updating the `TESTS` list
-->
This pull request improves the ONNX testing infrastructure in PyTorch by refactoring the test code, normalizing the scope names, adding a flag to run only the ONNX tests, and simplifying the test script.
> _To export PyTorch models to ONNX_
> _We refactored some scripts and contexts_
> _We used `common_utils`_
> _And normalized the scopes_
> _And added a flag to run the tests_
### Walkthrough
* Simplify `./scripts/onnx/test.sh` to use `run_test.py` with `--onnx` flag instead of `pytest` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-0017f5b22ae1329acb0f54af8d9811c9b6180a72dac70d7a5b89d7c23c958198L44-R46))
* Remove `onnx` test from `TESTS` list in `test/run_test.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7L127-R127)). Replace with `onnx_caffe2`.
* Add `onnx/test_pytorch_onnx_onnxruntime_cuda` and `onnx/test_models` tests to `blocklisted_tests` list in `test/run_test.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7R154-R155))
* Add `ONNX_SERIAL_LIST` list to `test/run_test.py` to specify ONNX tests that must run serially ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7R296-R301))
* Add `ONNX_TESTS` list to `test/run_test.py` to store all ONNX tests ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7R370))
* Add `--onnx` flag to `parse_args` function in `test/run_test.py` to run only ONNX tests ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7R920-R928))
* Include `ONNX_SERIAL_LIST` in `must_serial` function in `test/run_test.py` to run ONNX tests serially or parallelly based on memory usage ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7R1120))
* Filter selected tests based on `--onnx` flag in `get_selected_tests` function in `test/run_test.py` to exclude non-ONNX tests ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7R1158-R1165))
### Other minor changes to accommodate this change
* Replace `unittest` module with `common_utils.TestCase` in `test/onnx/dynamo/test_exporter_api.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L4), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L29-R28), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L71-R70), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L147-R146))
* Import `TemporaryFileName` class from `common_utils` in `test/onnx/dynamo/test_exporter_api.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L19-R18))
* Use `common_utils.TemporaryFileName` instead of `TemporaryFileName` in `TestDynamoExportAPI` class in `test/onnx/dynamo/test_exporter_api.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L92-R91), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L110-R109), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L129-R128))
* Use `common_utils.run_tests` instead of `unittest.main` in `test/onnx/dynamo/test_exporter_api.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L155-R154))
* Add `re` module to `test/onnx/test_utility_funs.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7R6))
* Add `_remove_test_environment_prefix_from_scope_name` function to `test/onnx/test_utility_funs.py` to normalize scope names of ONNX nodes ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7R32-R58))
* Use `_remove_test_environment_prefix_from_scope_name` function to compare scope names of ONNX nodes in `TestUtilityFuns` class in `test/onnx/test_utility_funs.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7L1099-R1133), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7L1119-R1152), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7L1170-R1188), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7L1181-R1199), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7L1220-R1239), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7L1235-R1258))
Fixes #98626
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99215
Approved by: https://github.com/huydhn, https://github.com/titaiwangms
2023-04-18 00:49:08 +00:00
|
|
|
# A subset of onnx tests that cannot run in parallel due to high memory usage.
|
|
|
|
|
ONNX_SERIAL_LIST = [
|
|
|
|
|
"onnx/test_models",
|
|
|
|
|
"onnx/test_models_quantized_onnxruntime",
|
|
|
|
|
"onnx/test_models_onnxruntime",
|
|
|
|
|
"onnx/test_custom_ops",
|
|
|
|
|
"onnx/test_utility_funs",
|
|
|
|
|
]
|
2022-10-03 16:59:39 +00:00
|
|
|
|
2021-08-26 16:27:47 +00:00
|
|
|
# A subset of our TEST list that validates PyTorch's ops, modules, and autograd function as expected
|
|
|
|
|
CORE_TEST_LIST = [
|
|
|
|
|
"test_autograd",
|
2023-08-09 14:59:37 +00:00
|
|
|
"test_autograd_fallback",
|
2021-08-26 16:27:47 +00:00
|
|
|
"test_modules",
|
|
|
|
|
"test_nn",
|
|
|
|
|
"test_ops",
|
2022-03-17 02:07:50 +00:00
|
|
|
"test_ops_gradients",
|
2022-11-02 17:52:15 +00:00
|
|
|
"test_ops_fwd_gradients",
|
2022-03-17 02:07:50 +00:00
|
|
|
"test_ops_jit",
|
2023-03-26 04:52:55 +00:00
|
|
|
"test_torch",
|
2021-08-26 16:27:47 +00:00
|
|
|
]
|
2020-10-13 17:54:18 +00:00
|
|
|
|
2022-10-13 03:31:28 +00:00
|
|
|
|
2021-03-10 17:33:02 +00:00
|
|
|
# if a test file takes longer than 5 min, we add it to TARGET_DET_LIST
|
|
|
|
|
SLOW_TEST_THRESHOLD = 300
|
|
|
|
|
|
2019-09-11 09:17:48 +00:00
|
|
|
DISTRIBUTED_TESTS_CONFIG = {}
|
2018-08-29 19:54:55 +00:00
|
|
|
|
|
|
|
|
|
2018-09-11 06:21:36 +00:00
|
|
|
if dist.is_available():
|
2021-08-12 18:39:31 +00:00
|
|
|
DISTRIBUTED_TESTS_CONFIG["test"] = {"WORLD_SIZE": "1"}
|
2020-02-10 20:36:56 +00:00
|
|
|
if not TEST_WITH_ROCM and dist.is_mpi_available():
|
2021-08-12 18:39:31 +00:00
|
|
|
DISTRIBUTED_TESTS_CONFIG["mpi"] = {
|
|
|
|
|
"WORLD_SIZE": "3",
|
|
|
|
|
"TEST_REPORT_SOURCE_OVERRIDE": "dist-mpi",
|
2018-08-29 19:54:55 +00:00
|
|
|
}
|
2018-09-11 06:21:36 +00:00
|
|
|
if dist.is_nccl_available():
|
2021-08-12 18:39:31 +00:00
|
|
|
DISTRIBUTED_TESTS_CONFIG["nccl"] = {
|
2024-10-20 19:49:41 +00:00
|
|
|
"WORLD_SIZE": f"{torch.cuda.device_count()}",
|
2021-08-12 18:39:31 +00:00
|
|
|
"TEST_REPORT_SOURCE_OVERRIDE": "dist-nccl",
|
2018-08-29 19:54:55 +00:00
|
|
|
}
|
2020-11-26 03:50:30 +00:00
|
|
|
if dist.is_gloo_available():
|
2021-08-12 18:39:31 +00:00
|
|
|
DISTRIBUTED_TESTS_CONFIG["gloo"] = {
|
2024-10-20 19:49:41 +00:00
|
|
|
# TODO: retire testing gloo with CUDA
|
|
|
|
|
"WORLD_SIZE": f"{torch.cuda.device_count()}",
|
2021-08-12 18:39:31 +00:00
|
|
|
"TEST_REPORT_SOURCE_OVERRIDE": "dist-gloo",
|
2019-09-11 09:17:48 +00:00
|
|
|
}
|
2024-10-14 19:54:27 +00:00
|
|
|
# Test with UCC backend is deprecated.
|
|
|
|
|
# See https://github.com/pytorch/pytorch/pull/137161
|
|
|
|
|
# if dist.is_ucc_available():
|
|
|
|
|
# DISTRIBUTED_TESTS_CONFIG["ucc"] = {
|
2024-10-20 19:49:41 +00:00
|
|
|
# "WORLD_SIZE": f"{torch.cuda.device_count()}",
|
2024-10-14 19:54:27 +00:00
|
|
|
# "TEST_REPORT_SOURCE_OVERRIDE": "dist-ucc",
|
|
|
|
|
# "UCX_TLS": "tcp,cuda",
|
|
|
|
|
# "UCC_TLS": "nccl,ucp,cuda",
|
|
|
|
|
# "UCC_TL_UCP_TUNE": "cuda:0", # don't use UCP TL on CUDA as it is not well supported
|
|
|
|
|
# "UCC_EC_CUDA_USE_COOPERATIVE_LAUNCH": "n", # CI nodes (M60) fail if it is on
|
|
|
|
|
# }
|
2018-08-29 19:54:55 +00:00
|
|
|
|
2018-04-10 18:31:23 +00:00
|
|
|
# https://stackoverflow.com/questions/2549939/get-signal-names-from-numbers-in-python
|
2021-08-12 18:39:31 +00:00
|
|
|
SIGNALS_TO_NAMES_DICT = {
|
|
|
|
|
getattr(signal, n): n for n in dir(signal) if n.startswith("SIG") and "_" not in n
|
|
|
|
|
}
|
2018-04-10 18:31:23 +00:00
|
|
|
|
2018-11-07 22:27:06 +00:00
|
|
|
CPP_EXTENSIONS_ERROR = """
|
Add option to use ninja to compile ahead-of-time cpp_extensions (#32495)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/32495
Background
------------------------------
Previously, ninja was used to compile+link inline cpp_extensions and
ahead-of-time cpp_extensions were compiled with distutils. This PR adds
the ability to compile (but not link) ahead-of-time cpp_extensions with ninja.
The main motivation for this is to speed up cpp_extension builds: distutils
does not make use of parallelism. With this PR, using the new option, on my machine,
- torchvision compilation goes from 3m43s to 49s
- nestedtensor compilation goes from 2m0s to 28s.
User-facing changes
------------------------------
I added a `use_ninja` flag to BuildExtension. This defaults to
`True`. When `use_ninja` is True:
- it will attempt to use ninja.
- If we cannot use ninja, then this throws a warning and falls back to
distutils.
- Situations we cannot use ninja: Windows (NYI, I'll open a new issue
for this), if ninja cannot be found on the system.
Implementation Details
------------------------------
This PR makes this change in two steps. Please me know if it would be
easier to review this if I split this up into a stacked diff.
Those changes are:
1) refactor _write_ninja_file to separate the policy (what compiler flags
to pass) from the mechanism (how to write the ninja file and do compilation).
2) call _write_ninja_file and _run_ninja_build while building
ahead-of-time cpp_extensions. These are only used to compile objects;
distutils still handles the linking.
Change 1: refactor _write_ninja_file to seperate policy from mechanism
- I split _write_ninja_file into: _write_ninja_file and
_write_ninja_file_to_build_library
- I renamed _build_extension_module to _run_ninja_build
Change 2: Call _write_ninja_file while building ahead-of-time
cpp_extensions
- _write_ninja_file_and_compile_objects calls _write_ninja_file to only
build object files.
- We monkey-patch distutils.CCompiler.compile to call
_write_ninja_files_and_compile_objects
- distutils still handles the linking step. The linking step is not a
bottleneck so it was not a concern.
- This change only works on unix-based systems. Our code for windows
goes down a different codepath and I did not want to mess with that.
- If a system does not support ninja, we raise a warning and fall back
to the original compilation path.
Test Plan
------------------------------
Adhoc testing
- I built torchvision using pytorch master and printed out the build
commands. Next, I used this branch to build torchvision and looked at
the ninja file. I compared the ninja file with the build commands and
asserted that they were functionally the same.
- I repeated the above for pytorch/nestedtensor.
PyTorch test suite
- I split `test_cpp_extensions` into `test_cpp_extensions_aot` and
`test_cpp_extensions_jit`. The AOT (ahead-of-time) version tests
ahead-of-time and the JIT version tests just-in-time (not to be confused
with TorchScript)
- `test_cpp_extensions_aot` gets run TWICE by run_test.py, once with
a module that was built with ninja, and once with a module that was
built without ninja.
- run_test.py asserts that when we are building with use_ninja=True,
ninja is actually available on the system.
Test Plan: Imported from OSS
Differential Revision: D19730432
Pulled By: zou3519
fbshipit-source-id: 819590d01cf65e8da5a1e8019b8b3084792fee90
2020-02-06 02:44:19 +00:00
|
|
|
Ninja (https://ninja-build.org) is required for some of the C++ extensions
|
|
|
|
|
tests, but it could not be found. Install ninja with `pip install ninja`
|
|
|
|
|
or `conda install ninja`. Alternatively, disable said tests with
|
2020-02-21 20:07:51 +00:00
|
|
|
`run_test.py --exclude test_cpp_extensions_aot_ninja test_cpp_extensions_jit`.
|
2018-11-07 22:27:06 +00:00
|
|
|
"""
|
|
|
|
|
|
2020-08-26 23:14:17 +00:00
|
|
|
PYTORCH_COLLECT_COVERAGE = bool(os.environ.get("PYTORCH_COLLECT_COVERAGE"))
|
2018-03-09 21:02:02 +00:00
|
|
|
|
2020-10-06 14:11:37 +00:00
|
|
|
JIT_EXECUTOR_TESTS = [
|
2021-08-12 18:39:31 +00:00
|
|
|
"test_jit_profiling",
|
|
|
|
|
"test_jit_legacy",
|
|
|
|
|
"test_jit_fuser_legacy",
|
2020-10-12 18:56:17 +00:00
|
|
|
]
|
2020-10-06 14:11:37 +00:00
|
|
|
|
2024-01-18 15:56:15 +00:00
|
|
|
INDUCTOR_TESTS = [test for test in TESTS if test.startswith(INDUCTOR_TEST_PREFIX)]
|
Do not collect and skip non-disabled tests when rerunning disabled tests (#102107)
The console log blows up to much when running in rerun disabled tests mode (x50) https://hud.pytorch.org/pytorch/pytorch/commit/e132f09e8878418fb98a4b76a441a324452354ec. Each log is around 1GB and the whole uncompressed logs is ~50GB. After compression, it will be around 1GB, still too big. The increase comes mainly from the multiple SKIPPED message for non-disabled tests, which is expected due to how SkipTest and pytest-flakyfinder currently work.
I update `test/conftest.py` to completely ignore skipped tests when rerunning disabled test instead of collecting then skipping 50 tests each. The benefit of doing is is much more than I originally expect:
* Rerun disabled tests jobs now finish in less than half an hour as they should be
* Fix OOM runner crash because of too many collected tests
* Fix verbosity issue as now only disabled tests are run x50 times. There are only few hundreds of them atm
* Fix timed out issue when rerunning disabled distributed and ASAN tests. They are just too slow when running at x50
### Testing
When rerunning disabled tests https://github.com/pytorch/pytorch/actions/runs/5084508614, only disabled tests on the platform are run, for example `test_ops_jit` on https://ossci-raw-job-status.s3.amazonaws.com/log/13770164954 only ran 100 tests (`test_variant_consistency_jit_linalg_lu_cuda_float32` + `test_variant_consistency_jit_linalg_lu_factor_cuda_complex64`) x50.
```
Executing ['/opt/conda/envs/py_3.10/bin/python', '-bb', 'test_ops_jit.py', '--shard-id=1', '--num-shards=2', '-v', '-vv', '-rfEX', '-p', 'no:xdist', '--use-pytest', '--sc=test_ops_jit_1', '--flake-finder', '--flake-runs=50', '--import-slow-tests', '--import-disabled-tests', '--rerun-disabled-tests'] ... [2023-05-25 21:32:49.763856]
Expand the folded group to see the log file of test_ops_jit 2/2
##[group]PRINTING LOG FILE of test_ops_jit 2/2 (/var/lib/jenkins/workspace/test/test-reports/test_ops_jit_h2wr_t2c.log)
Test results will be stored in test-reports/python-pytest/test_ops_jit/test_ops_jit-51a83bd44549074e.xml
============================= test session starts ==============================
platform linux -- Python 3.10.11, pytest-7.3.1, pluggy-1.0.0 -- /opt/conda/envs/py_3.10/bin/python
cachedir: .pytest_cache
hypothesis profile 'pytorch_ci' -> database=None, max_examples=50, derandomize=True, suppress_health_check=[HealthCheck.too_slow]
rootdir: /var/lib/jenkins/workspace
configfile: pytest.ini
plugins: hypothesis-5.35.1, cpp-2.3.0, flakefinder-1.1.0, rerunfailures-11.1.2, shard-0.1.2, xdist-3.3.0, xdoctest-1.1.0
collecting ... collected 1084 items
Running 100 items in this shard: test/test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_cuda_float32 (x50), test/test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_factor_cuda_complex64 (x50)
stepcurrent: Cannot find last run test, not skipping
test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_cuda_float32 PASSED [2.1876s] [ 1%]
test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_factor_cuda_complex64 PASSED [4.5615s] [ 2%]
```
* [pull](https://github.com/pytorch/pytorch/actions/runs/5093566864)
* [trunk](https://github.com/pytorch/pytorch/actions/runs/5095364311)
* [periodic](https://github.com/pytorch/pytorch/actions/runs/5095378850)
* [slow](https://github.com/pytorch/pytorch/actions/runs/5095390285)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/102107
Approved by: https://github.com/clee2000, https://github.com/malfet
2023-05-27 12:10:32 +00:00
|
|
|
DISTRIBUTED_TESTS = [test for test in TESTS if test.startswith(DISTRIBUTED_TEST_PREFIX)]
|
2024-01-22 18:53:54 +00:00
|
|
|
TORCH_EXPORT_TESTS = [test for test in TESTS if test.startswith("export")]
|
2024-12-10 22:15:31 +00:00
|
|
|
AOT_DISPATCH_TESTS = [
|
|
|
|
|
test for test in TESTS if test.startswith("functorch/test_aotdispatch")
|
|
|
|
|
]
|
2022-09-24 01:17:04 +00:00
|
|
|
FUNCTORCH_TESTS = [test for test in TESTS if test.startswith("functorch")]
|
[ONNX] Run ONNX tests as part of standard run_test script (#99215)
<!--
copilot:all
-->
### <samp>🤖 Generated by Copilot at dcbf7e2</samp>
### Summary
📝🧹🚩
<!--
1. 📝 for simplifying the `./scripts/onnx/test.sh` script
2. 🧹 for refactoring the `test/onnx/dynamo/test_exporter_api.py` file
3. 🚩 for adding the `--onnx` flag to `test/run_test.py` and updating the `TESTS` list
-->
This pull request improves the ONNX testing infrastructure in PyTorch by refactoring the test code, normalizing the scope names, adding a flag to run only the ONNX tests, and simplifying the test script.
> _To export PyTorch models to ONNX_
> _We refactored some scripts and contexts_
> _We used `common_utils`_
> _And normalized the scopes_
> _And added a flag to run the tests_
### Walkthrough
* Simplify `./scripts/onnx/test.sh` to use `run_test.py` with `--onnx` flag instead of `pytest` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-0017f5b22ae1329acb0f54af8d9811c9b6180a72dac70d7a5b89d7c23c958198L44-R46))
* Remove `onnx` test from `TESTS` list in `test/run_test.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7L127-R127)). Replace with `onnx_caffe2`.
* Add `onnx/test_pytorch_onnx_onnxruntime_cuda` and `onnx/test_models` tests to `blocklisted_tests` list in `test/run_test.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7R154-R155))
* Add `ONNX_SERIAL_LIST` list to `test/run_test.py` to specify ONNX tests that must run serially ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7R296-R301))
* Add `ONNX_TESTS` list to `test/run_test.py` to store all ONNX tests ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7R370))
* Add `--onnx` flag to `parse_args` function in `test/run_test.py` to run only ONNX tests ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7R920-R928))
* Include `ONNX_SERIAL_LIST` in `must_serial` function in `test/run_test.py` to run ONNX tests serially or parallelly based on memory usage ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7R1120))
* Filter selected tests based on `--onnx` flag in `get_selected_tests` function in `test/run_test.py` to exclude non-ONNX tests ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7R1158-R1165))
### Other minor changes to accommodate this change
* Replace `unittest` module with `common_utils.TestCase` in `test/onnx/dynamo/test_exporter_api.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L4), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L29-R28), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L71-R70), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L147-R146))
* Import `TemporaryFileName` class from `common_utils` in `test/onnx/dynamo/test_exporter_api.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L19-R18))
* Use `common_utils.TemporaryFileName` instead of `TemporaryFileName` in `TestDynamoExportAPI` class in `test/onnx/dynamo/test_exporter_api.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L92-R91), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L110-R109), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L129-R128))
* Use `common_utils.run_tests` instead of `unittest.main` in `test/onnx/dynamo/test_exporter_api.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L155-R154))
* Add `re` module to `test/onnx/test_utility_funs.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7R6))
* Add `_remove_test_environment_prefix_from_scope_name` function to `test/onnx/test_utility_funs.py` to normalize scope names of ONNX nodes ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7R32-R58))
* Use `_remove_test_environment_prefix_from_scope_name` function to compare scope names of ONNX nodes in `TestUtilityFuns` class in `test/onnx/test_utility_funs.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7L1099-R1133), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7L1119-R1152), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7L1170-R1188), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7L1181-R1199), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7L1220-R1239), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7L1235-R1258))
Fixes #98626
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99215
Approved by: https://github.com/huydhn, https://github.com/titaiwangms
2023-04-18 00:49:08 +00:00
|
|
|
ONNX_TESTS = [test for test in TESTS if test.startswith("onnx")]
|
Discover and run C++ tests with run_test.py (#99559)
This depends on [pytest-cpp](https://github.com/pytest-dev/pytest-cpp) to discover and run C++ tests with pytest. C++ tests are built under `${WORKSPACE}/build/bin` directory and copied to the test job under the same path.
* To expose them to `run_test`, I choose to use the mock path prefix `cpp`, for example `build/bin/c10_Array_test` would be named as `cpp/c10_Array_test` and the `python test/run_test.py --cpp -i cpp/c10_Array_test` would run the test in the same way as other Python tests. I could copy them from `build/bin` to `test/cpp`, but it will be mixed with the source code and CMake file. So this looks easier
* Some executable under `build/bin` are not C++ tests, and they are exclude, for example `build/bin/torch_shm_manager`
* C++ tests need to run with pytest directly as python command doesn't understand it
* The change is gated by the new `--cpp` argument to `run_test.py`, for example `python test/run_test.py --cpp` will run all available C++ tests
* The tests can be run in parallel
* Failing tests can be retried with `--reruns=2` and `--sw`
```
============================= test session starts ==============================
platform darwin -- Python 3.9.15, pytest-7.2.0, pluggy-1.0.0 -- /Users/huydo/miniconda3/envs/py3.9/bin/python3
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/Users/huydo/Storage/mine/pytorch/test/.hypothesis/examples')
rootdir: /Users/huydo/Storage/mine/pytorch, configfile: pytest.ini
plugins: xdoctest-1.1.0, cpp-2.3.0, rerunfailures-10.3, shard-0.1.2, flakefinder-1.1.0, hypothesis-6.56.4, xdist-3.0.2, repeat-0.9.1
collecting ... collected 3 items / 2 deselected / 1 selected
Running 1 items in this shard: build/bin/scalar_tensor_test::TestScalarTensor.TestScalarTensorMPS
stepwise: skipping 2 already passed items.
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS FAILED [100%]
```
* `--import-slow-tests` and `--import-disabled-tests` won't work for now and that's ok to have it as a future task.
I also add `pytest-cpp==2.3.0` to Linux Docker, MacOS, and Windows.
### Testing
Build PyTorch and run `python test/run_test.py --cpp` on my laptop. CI change would come later in a separate PR. Also running `python test/run_test.py --help` now shows all C++ test discovered under `build/bin`
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99559
Approved by: https://github.com/clee2000
2023-04-22 00:23:31 +00:00
|
|
|
CPP_TESTS = [test for test in TESTS if test.startswith(CPP_TEST_PREFIX)]
|
2022-07-24 23:14:13 +00:00
|
|
|
|
2022-02-15 16:33:59 +00:00
|
|
|
TESTS_REQUIRING_LAPACK = [
|
|
|
|
|
"distributions/test_constraints",
|
|
|
|
|
"distributions/test_distributions",
|
|
|
|
|
]
|
|
|
|
|
|
2022-11-02 17:52:15 +00:00
|
|
|
# These are just the slowest ones, this isn't an exhaustive list.
|
|
|
|
|
TESTS_NOT_USING_GRADCHECK = [
|
|
|
|
|
# Note that you should use skipIfSlowGradcheckEnv if you do not wish to
|
|
|
|
|
# skip all the tests in that file, e.g. test_mps
|
|
|
|
|
"doctests",
|
|
|
|
|
"test_meta",
|
|
|
|
|
"test_hub",
|
|
|
|
|
"test_fx",
|
|
|
|
|
"test_decomp",
|
|
|
|
|
"test_cpp_extensions_jit",
|
|
|
|
|
"test_jit",
|
|
|
|
|
"test_ops",
|
|
|
|
|
"test_ops_jit",
|
|
|
|
|
"dynamo/test_recompile_ux",
|
|
|
|
|
"inductor/test_smoke",
|
|
|
|
|
"test_quantization",
|
|
|
|
|
]
|
2021-06-08 22:59:32 +00:00
|
|
|
|
2023-03-26 04:52:55 +00:00
|
|
|
|
2018-03-15 05:12:51 +00:00
|
|
|
def print_to_stderr(message):
|
|
|
|
|
print(message, file=sys.stderr)
|
|
|
|
|
|
|
|
|
|
|
Discover and run C++ tests with run_test.py (#99559)
This depends on [pytest-cpp](https://github.com/pytest-dev/pytest-cpp) to discover and run C++ tests with pytest. C++ tests are built under `${WORKSPACE}/build/bin` directory and copied to the test job under the same path.
* To expose them to `run_test`, I choose to use the mock path prefix `cpp`, for example `build/bin/c10_Array_test` would be named as `cpp/c10_Array_test` and the `python test/run_test.py --cpp -i cpp/c10_Array_test` would run the test in the same way as other Python tests. I could copy them from `build/bin` to `test/cpp`, but it will be mixed with the source code and CMake file. So this looks easier
* Some executable under `build/bin` are not C++ tests, and they are exclude, for example `build/bin/torch_shm_manager`
* C++ tests need to run with pytest directly as python command doesn't understand it
* The change is gated by the new `--cpp` argument to `run_test.py`, for example `python test/run_test.py --cpp` will run all available C++ tests
* The tests can be run in parallel
* Failing tests can be retried with `--reruns=2` and `--sw`
```
============================= test session starts ==============================
platform darwin -- Python 3.9.15, pytest-7.2.0, pluggy-1.0.0 -- /Users/huydo/miniconda3/envs/py3.9/bin/python3
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/Users/huydo/Storage/mine/pytorch/test/.hypothesis/examples')
rootdir: /Users/huydo/Storage/mine/pytorch, configfile: pytest.ini
plugins: xdoctest-1.1.0, cpp-2.3.0, rerunfailures-10.3, shard-0.1.2, flakefinder-1.1.0, hypothesis-6.56.4, xdist-3.0.2, repeat-0.9.1
collecting ... collected 3 items / 2 deselected / 1 selected
Running 1 items in this shard: build/bin/scalar_tensor_test::TestScalarTensor.TestScalarTensorMPS
stepwise: skipping 2 already passed items.
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS FAILED [100%]
```
* `--import-slow-tests` and `--import-disabled-tests` won't work for now and that's ok to have it as a future task.
I also add `pytest-cpp==2.3.0` to Linux Docker, MacOS, and Windows.
### Testing
Build PyTorch and run `python test/run_test.py --cpp` on my laptop. CI change would come later in a separate PR. Also running `python test/run_test.py --help` now shows all C++ test discovered under `build/bin`
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99559
Approved by: https://github.com/clee2000
2023-04-22 00:23:31 +00:00
|
|
|
def get_executable_command(options, disable_coverage=False, is_cpp_test=False):
|
2021-01-19 22:57:07 +00:00
|
|
|
if options.coverage and not disable_coverage:
|
Discover and run C++ tests with run_test.py (#99559)
This depends on [pytest-cpp](https://github.com/pytest-dev/pytest-cpp) to discover and run C++ tests with pytest. C++ tests are built under `${WORKSPACE}/build/bin` directory and copied to the test job under the same path.
* To expose them to `run_test`, I choose to use the mock path prefix `cpp`, for example `build/bin/c10_Array_test` would be named as `cpp/c10_Array_test` and the `python test/run_test.py --cpp -i cpp/c10_Array_test` would run the test in the same way as other Python tests. I could copy them from `build/bin` to `test/cpp`, but it will be mixed with the source code and CMake file. So this looks easier
* Some executable under `build/bin` are not C++ tests, and they are exclude, for example `build/bin/torch_shm_manager`
* C++ tests need to run with pytest directly as python command doesn't understand it
* The change is gated by the new `--cpp` argument to `run_test.py`, for example `python test/run_test.py --cpp` will run all available C++ tests
* The tests can be run in parallel
* Failing tests can be retried with `--reruns=2` and `--sw`
```
============================= test session starts ==============================
platform darwin -- Python 3.9.15, pytest-7.2.0, pluggy-1.0.0 -- /Users/huydo/miniconda3/envs/py3.9/bin/python3
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/Users/huydo/Storage/mine/pytorch/test/.hypothesis/examples')
rootdir: /Users/huydo/Storage/mine/pytorch, configfile: pytest.ini
plugins: xdoctest-1.1.0, cpp-2.3.0, rerunfailures-10.3, shard-0.1.2, flakefinder-1.1.0, hypothesis-6.56.4, xdist-3.0.2, repeat-0.9.1
collecting ... collected 3 items / 2 deselected / 1 selected
Running 1 items in this shard: build/bin/scalar_tensor_test::TestScalarTensor.TestScalarTensorMPS
stepwise: skipping 2 already passed items.
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS FAILED [100%]
```
* `--import-slow-tests` and `--import-disabled-tests` won't work for now and that's ok to have it as a future task.
I also add `pytest-cpp==2.3.0` to Linux Docker, MacOS, and Windows.
### Testing
Build PyTorch and run `python test/run_test.py --cpp` on my laptop. CI change would come later in a separate PR. Also running `python test/run_test.py --help` now shows all C++ test discovered under `build/bin`
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99559
Approved by: https://github.com/clee2000
2023-04-22 00:23:31 +00:00
|
|
|
if not is_cpp_test:
|
|
|
|
|
executable = ["coverage", "run", "--parallel-mode", "--source=torch"]
|
|
|
|
|
else:
|
|
|
|
|
# TODO: C++ with coverage is not yet supported
|
|
|
|
|
executable = []
|
2020-07-28 15:12:41 +00:00
|
|
|
else:
|
Discover and run C++ tests with run_test.py (#99559)
This depends on [pytest-cpp](https://github.com/pytest-dev/pytest-cpp) to discover and run C++ tests with pytest. C++ tests are built under `${WORKSPACE}/build/bin` directory and copied to the test job under the same path.
* To expose them to `run_test`, I choose to use the mock path prefix `cpp`, for example `build/bin/c10_Array_test` would be named as `cpp/c10_Array_test` and the `python test/run_test.py --cpp -i cpp/c10_Array_test` would run the test in the same way as other Python tests. I could copy them from `build/bin` to `test/cpp`, but it will be mixed with the source code and CMake file. So this looks easier
* Some executable under `build/bin` are not C++ tests, and they are exclude, for example `build/bin/torch_shm_manager`
* C++ tests need to run with pytest directly as python command doesn't understand it
* The change is gated by the new `--cpp` argument to `run_test.py`, for example `python test/run_test.py --cpp` will run all available C++ tests
* The tests can be run in parallel
* Failing tests can be retried with `--reruns=2` and `--sw`
```
============================= test session starts ==============================
platform darwin -- Python 3.9.15, pytest-7.2.0, pluggy-1.0.0 -- /Users/huydo/miniconda3/envs/py3.9/bin/python3
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/Users/huydo/Storage/mine/pytorch/test/.hypothesis/examples')
rootdir: /Users/huydo/Storage/mine/pytorch, configfile: pytest.ini
plugins: xdoctest-1.1.0, cpp-2.3.0, rerunfailures-10.3, shard-0.1.2, flakefinder-1.1.0, hypothesis-6.56.4, xdist-3.0.2, repeat-0.9.1
collecting ... collected 3 items / 2 deselected / 1 selected
Running 1 items in this shard: build/bin/scalar_tensor_test::TestScalarTensor.TestScalarTensorMPS
stepwise: skipping 2 already passed items.
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS FAILED [100%]
```
* `--import-slow-tests` and `--import-disabled-tests` won't work for now and that's ok to have it as a future task.
I also add `pytest-cpp==2.3.0` to Linux Docker, MacOS, and Windows.
### Testing
Build PyTorch and run `python test/run_test.py --cpp` on my laptop. CI change would come later in a separate PR. Also running `python test/run_test.py --help` now shows all C++ test discovered under `build/bin`
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99559
Approved by: https://github.com/clee2000
2023-04-22 00:23:31 +00:00
|
|
|
if not is_cpp_test:
|
|
|
|
|
executable = [sys.executable, "-bb"]
|
|
|
|
|
else:
|
|
|
|
|
executable = ["pytest"]
|
|
|
|
|
|
2020-07-28 15:12:41 +00:00
|
|
|
return executable
|
|
|
|
|
|
|
|
|
|
|
2021-08-12 18:39:31 +00:00
|
|
|
def run_test(
|
2023-10-30 23:31:40 +00:00
|
|
|
test_module: ShardedTest,
|
Test distributed backends in parallel (#84034)
This allows multiple backends (nccl, gloo) to be tested in parallel and speed up the process. The improvement is mainly in the 1st distributed CUDA shard where the long pole `distributed/test_distributed_spawn` test is executed:
* [linux-bionic-cuda11.6-py3.10-gcc7 / test (distributed, 1, 2, linux.8xlarge.nvidia.gpu)](https://github.com/pytorch/pytorch/runs/8007596825?check_suite_focus=true#logs) takes 1h24m. This is better than the current average expectation of 2h12m
On the other hand, there is no improvement for the following two jobs:
* [linux-focal-py3.7-gcc7 / test (distributed, 1, 1, linux.2xlarge)](https://github.com/pytorch/pytorch/runs/8007417353?check_suite_focus=true#logs) takes 1h47m
* [linux-bionic-cuda11.6-py3.10-gcc7 / test (distributed, 2, 2, linux.8xlarge.nvidia.gpu)](https://github.com/pytorch/pytorch/runs/8007596870?check_suite_focus=true#logs) takes 1h40m
This is still a gain though because it allows us to add more shards for distributed test if needed.
Issue https://github.com/pytorch/pytorch/issues/83694
Pull Request resolved: https://github.com/pytorch/pytorch/pull/84034
Approved by: https://github.com/wanchaol
2022-09-01 03:48:52 +00:00
|
|
|
test_directory,
|
|
|
|
|
options,
|
|
|
|
|
launcher_cmd=None,
|
|
|
|
|
extra_unittest_args=None,
|
|
|
|
|
env=None,
|
2024-03-11 15:35:45 +00:00
|
|
|
print_log=True,
|
2022-09-23 20:45:20 +00:00
|
|
|
) -> int:
|
2024-08-15 15:49:40 +00:00
|
|
|
scribe_token = os.getenv("SCRIBE_GRAPHQL_ACCESS_TOKEN", "")
|
|
|
|
|
if scribe_token:
|
|
|
|
|
print_to_stderr("SCRIBE_GRAPHQL_ACCESS_TOKEN is set")
|
|
|
|
|
else:
|
|
|
|
|
print_to_stderr("SCRIBE_GRAPHQL_ACCESS_TOKEN is NOT set")
|
|
|
|
|
|
2024-02-21 00:40:19 +00:00
|
|
|
env = env or os.environ.copy()
|
2023-01-04 19:40:05 +00:00
|
|
|
maybe_set_hip_visible_devies()
|
2024-05-23 21:08:12 +00:00
|
|
|
unittest_args = options.additional_args.copy()
|
2023-10-30 23:31:40 +00:00
|
|
|
test_file = test_module.name
|
2023-04-25 20:56:04 +00:00
|
|
|
stepcurrent_key = test_file
|
2023-05-16 21:52:36 +00:00
|
|
|
|
Do not collect and skip non-disabled tests when rerunning disabled tests (#102107)
The console log blows up to much when running in rerun disabled tests mode (x50) https://hud.pytorch.org/pytorch/pytorch/commit/e132f09e8878418fb98a4b76a441a324452354ec. Each log is around 1GB and the whole uncompressed logs is ~50GB. After compression, it will be around 1GB, still too big. The increase comes mainly from the multiple SKIPPED message for non-disabled tests, which is expected due to how SkipTest and pytest-flakyfinder currently work.
I update `test/conftest.py` to completely ignore skipped tests when rerunning disabled test instead of collecting then skipping 50 tests each. The benefit of doing is is much more than I originally expect:
* Rerun disabled tests jobs now finish in less than half an hour as they should be
* Fix OOM runner crash because of too many collected tests
* Fix verbosity issue as now only disabled tests are run x50 times. There are only few hundreds of them atm
* Fix timed out issue when rerunning disabled distributed and ASAN tests. They are just too slow when running at x50
### Testing
When rerunning disabled tests https://github.com/pytorch/pytorch/actions/runs/5084508614, only disabled tests on the platform are run, for example `test_ops_jit` on https://ossci-raw-job-status.s3.amazonaws.com/log/13770164954 only ran 100 tests (`test_variant_consistency_jit_linalg_lu_cuda_float32` + `test_variant_consistency_jit_linalg_lu_factor_cuda_complex64`) x50.
```
Executing ['/opt/conda/envs/py_3.10/bin/python', '-bb', 'test_ops_jit.py', '--shard-id=1', '--num-shards=2', '-v', '-vv', '-rfEX', '-p', 'no:xdist', '--use-pytest', '--sc=test_ops_jit_1', '--flake-finder', '--flake-runs=50', '--import-slow-tests', '--import-disabled-tests', '--rerun-disabled-tests'] ... [2023-05-25 21:32:49.763856]
Expand the folded group to see the log file of test_ops_jit 2/2
##[group]PRINTING LOG FILE of test_ops_jit 2/2 (/var/lib/jenkins/workspace/test/test-reports/test_ops_jit_h2wr_t2c.log)
Test results will be stored in test-reports/python-pytest/test_ops_jit/test_ops_jit-51a83bd44549074e.xml
============================= test session starts ==============================
platform linux -- Python 3.10.11, pytest-7.3.1, pluggy-1.0.0 -- /opt/conda/envs/py_3.10/bin/python
cachedir: .pytest_cache
hypothesis profile 'pytorch_ci' -> database=None, max_examples=50, derandomize=True, suppress_health_check=[HealthCheck.too_slow]
rootdir: /var/lib/jenkins/workspace
configfile: pytest.ini
plugins: hypothesis-5.35.1, cpp-2.3.0, flakefinder-1.1.0, rerunfailures-11.1.2, shard-0.1.2, xdist-3.3.0, xdoctest-1.1.0
collecting ... collected 1084 items
Running 100 items in this shard: test/test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_cuda_float32 (x50), test/test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_factor_cuda_complex64 (x50)
stepcurrent: Cannot find last run test, not skipping
test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_cuda_float32 PASSED [2.1876s] [ 1%]
test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_factor_cuda_complex64 PASSED [4.5615s] [ 2%]
```
* [pull](https://github.com/pytorch/pytorch/actions/runs/5093566864)
* [trunk](https://github.com/pytorch/pytorch/actions/runs/5095364311)
* [periodic](https://github.com/pytorch/pytorch/actions/runs/5095378850)
* [slow](https://github.com/pytorch/pytorch/actions/runs/5095390285)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/102107
Approved by: https://github.com/clee2000, https://github.com/malfet
2023-05-27 12:10:32 +00:00
|
|
|
is_distributed_test = test_file.startswith(DISTRIBUTED_TEST_PREFIX)
|
2023-05-16 21:52:36 +00:00
|
|
|
is_cpp_test = test_file.startswith(CPP_TEST_PREFIX)
|
2023-05-24 07:45:43 +00:00
|
|
|
# NB: Rerun disabled tests depends on pytest-flakefinder and it doesn't work with
|
|
|
|
|
# pytest-cpp atm. We also don't have support to disable C++ test yet, so it's ok
|
|
|
|
|
# to just return successfully here
|
|
|
|
|
if is_cpp_test and RERUN_DISABLED_TESTS:
|
|
|
|
|
print_to_stderr(
|
|
|
|
|
"Skipping C++ tests when running under RERUN_DISABLED_TESTS mode"
|
|
|
|
|
)
|
|
|
|
|
return 0
|
|
|
|
|
|
2023-10-30 23:31:40 +00:00
|
|
|
if is_cpp_test:
|
More random stepcurrent (#113620)
Distributed tests for different backends have the same name, so they end up clashing using the current stepcurrent key, so tests were not being run.
Disabled the following tests because they are failing:
test_ddp_has_finalized
test_broadcast_object_list
<details>
```
2023-11-14T06:44:01.0428686Z
2023-11-14T06:44:01.0430447Z distributed/test_distributed_spawn.py::TestDistBackendWithSpawn::test_broadcast_object_list <- ../../../../opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/distributed/distributed_test.py INFO:numba.cuda.cudadrv.driver:init
2023-11-14T06:44:01.0431048Z [1699943450.893723] [99f90b6e6ff3:10028:0] ucc_context.c:402 UCC ERROR failed to create tl context for cuda
2023-11-14T06:44:01.0431625Z [1699943450.914385] [99f90b6e6ff3:10029:0] ucc_context.c:402 UCC ERROR failed to create tl context for cuda
2023-11-14T06:44:01.0432314Z [rank1]:[2023-11-14 06:30:51,405] torch.testing._internal.common_distributed: [ERROR] Caught exception:
2023-11-14T06:44:01.0433178Z [rank1]:[2023-11-14 06:30:51,405] torch.testing._internal.common_distributed: [ERROR] Traceback (most recent call last):
2023-11-14T06:44:01.0434677Z [rank1]:[2023-11-14 06:30:51,405] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/common_distributed.py", line 658, in run_test
2023-11-14T06:44:01.0435435Z [rank1]:[2023-11-14 06:30:51,405] torch.testing._internal.common_distributed: [ERROR] getattr(self, test_name)()
2023-11-14T06:44:01.0436895Z [rank1]:[2023-11-14 06:30:51,405] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/common_distributed.py", line 544, in wrapper
2023-11-14T06:44:01.0437500Z [rank1]:[2023-11-14 06:30:51,405] torch.testing._internal.common_distributed: [ERROR] fn()
2023-11-14T06:44:01.0438917Z [rank1]:[2023-11-14 06:30:51,405] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/common_utils.py", line 2536, in wrapper
2023-11-14T06:44:01.0439637Z [rank1]:[2023-11-14 06:30:51,405] torch.testing._internal.common_distributed: [ERROR] method(*args, **kwargs)
2023-11-14T06:44:01.0441122Z [rank1]:[2023-11-14 06:30:51,405] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/common_distributed.py", line 143, in wrapper
2023-11-14T06:44:01.0441873Z [rank1]:[2023-11-14 06:30:51,405] torch.testing._internal.common_distributed: [ERROR] return func(*args, **kwargs)
2023-11-14T06:44:01.0443340Z [rank1]:[2023-11-14 06:30:51,405] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/common_distributed.py", line 274, in wrapper
2023-11-14T06:44:01.0444077Z [rank1]:[2023-11-14 06:30:51,405] torch.testing._internal.common_distributed: [ERROR] ret = func(*args, **kwargs)
2023-11-14T06:44:01.0445769Z [rank1]:[2023-11-14 06:30:51,405] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/distributed/distributed_test.py", line 7717, in test_broadcast_object_list
2023-11-14T06:44:01.0446732Z [rank1]:[2023-11-14 06:30:51,405] torch.testing._internal.common_distributed: [ERROR] return self._test_broadcast_object_list()
2023-11-14T06:44:01.0448433Z [rank1]:[2023-11-14 06:30:51,405] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/distributed/distributed_test.py", line 7683, in _test_broadcast_object_list
2023-11-14T06:44:01.0449187Z [rank1]:[2023-11-14 06:30:51,405] torch.testing._internal.common_distributed: [ERROR] dist.broadcast_object_list(
2023-11-14T06:44:01.0450553Z [rank1]:[2023-11-14 06:30:51,405] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/distributed/c10d_logger.py", line 72, in wrapper
2023-11-14T06:44:01.0451621Z [rank1]:[2023-11-14 06:30:51,405] torch.testing._internal.common_distributed: [ERROR] return func(*args, **kwargs)
2023-11-14T06:44:01.0453161Z [rank1]:[2023-11-14 06:30:51,405] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/distributed/distributed_c10d.py", line 2650, in broadcast_object_list
2023-11-14T06:44:01.0454065Z [rank1]:[2023-11-14 06:30:51,405] torch.testing._internal.common_distributed: [ERROR] broadcast(object_sizes_tensor, src=src, group=group)
2023-11-14T06:44:01.0455441Z [rank1]:[2023-11-14 06:30:51,405] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/distributed/c10d_logger.py", line 72, in wrapper
2023-11-14T06:44:01.0456183Z [rank1]:[2023-11-14 06:30:51,405] torch.testing._internal.common_distributed: [ERROR] return func(*args, **kwargs)
2023-11-14T06:44:01.0457775Z [rank1]:[2023-11-14 06:30:51,405] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/distributed/distributed_c10d.py", line 1947, in broadcast
2023-11-14T06:44:01.0458649Z [rank1]:[2023-11-14 06:30:51,405] torch.testing._internal.common_distributed: [ERROR] work = default_pg.broadcast([tensor], opts)
2023-11-14T06:44:01.0460923Z [rank1]:[2023-11-14 06:30:51,405] torch.testing._internal.common_distributed: [ERROR] RuntimeError: [/var/lib/jenkins/workspace/torch/csrc/distributed/c10d/ProcessGroupUCC.cpp:488] [Rank 1][ProcessGroupUCC-0][READY]failed to init cuda collective, error code -1: Operation is not supported, system error code 2
2023-11-14T06:44:01.0461471Z [rank1]:[2023-11-14 06:30:51,405] torch.testing._internal.common_distributed: [ERROR]
2023-11-14T06:44:01.0462430Z [rank1]:[2023-11-14 06:30:51,405] torch.testing._internal.common_distributed: [ERROR] To execute this test, run the following from the base repo dir:
2023-11-14T06:44:01.0463552Z [rank1]:[2023-11-14 06:30:51,405] torch.testing._internal.common_distributed: [ERROR] python test/distributed/test_distributed_spawn.py -k test_broadcast_object_list
2023-11-14T06:44:01.0464082Z [rank1]:[2023-11-14 06:30:51,405] torch.testing._internal.common_distributed: [ERROR]
2023-11-14T06:44:01.0465136Z [rank1]:[2023-11-14 06:30:51,405] torch.testing._internal.common_distributed: [ERROR] This message can be suppressed by setting PYTORCH_PRINT_REPRO_ON_FAILURE=0
2023-11-14T06:44:01.0465945Z [rank1]:[2023-11-14 06:30:51,405] torch.testing._internal.common_distributed: [ERROR] exiting process 1 with exit code: 10
2023-11-14T06:44:01.0466605Z [1699943451.005633] [99f90b6e6ff3:10029:0] parser.c:2034 UCX WARN unused environment variables: UCX_COMMIT; UCX_HOME
2023-11-14T06:44:01.0467303Z [1699943451.005633] [99f90b6e6ff3:10029:0] parser.c:2034 UCX WARN (set UCX_WARN_UNUSED_ENV_VARS=n to suppress this warning)
2023-11-14T06:44:01.0467972Z [rank0]:[2023-11-14 06:30:51,462] torch.testing._internal.common_distributed: [ERROR] Caught exception:
2023-11-14T06:44:01.0468743Z [rank0]:[2023-11-14 06:30:51,462] torch.testing._internal.common_distributed: [ERROR] Traceback (most recent call last):
2023-11-14T06:44:01.0470233Z [rank0]:[2023-11-14 06:30:51,462] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/common_distributed.py", line 658, in run_test
2023-11-14T06:44:01.0471106Z [rank0]:[2023-11-14 06:30:51,462] torch.testing._internal.common_distributed: [ERROR] getattr(self, test_name)()
2023-11-14T06:44:01.0472581Z [rank0]:[2023-11-14 06:30:51,462] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/common_distributed.py", line 544, in wrapper
2023-11-14T06:44:01.0473162Z [rank0]:[2023-11-14 06:30:51,462] torch.testing._internal.common_distributed: [ERROR] fn()
2023-11-14T06:44:01.0474581Z [rank0]:[2023-11-14 06:30:51,462] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/common_utils.py", line 2536, in wrapper
2023-11-14T06:44:01.0475314Z [rank0]:[2023-11-14 06:30:51,462] torch.testing._internal.common_distributed: [ERROR] method(*args, **kwargs)
2023-11-14T06:44:01.0476776Z [rank0]:[2023-11-14 06:30:51,462] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/common_distributed.py", line 143, in wrapper
2023-11-14T06:44:01.0477535Z [rank0]:[2023-11-14 06:30:51,462] torch.testing._internal.common_distributed: [ERROR] return func(*args, **kwargs)
2023-11-14T06:44:01.0478993Z [rank0]:[2023-11-14 06:30:51,462] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/common_distributed.py", line 274, in wrapper
2023-11-14T06:44:01.0479886Z [rank0]:[2023-11-14 06:30:51,462] torch.testing._internal.common_distributed: [ERROR] ret = func(*args, **kwargs)
2023-11-14T06:44:01.0481593Z [rank0]:[2023-11-14 06:30:51,462] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/distributed/distributed_test.py", line 7717, in test_broadcast_object_list
2023-11-14T06:44:01.0482429Z [rank0]:[2023-11-14 06:30:51,462] torch.testing._internal.common_distributed: [ERROR] return self._test_broadcast_object_list()
2023-11-14T06:44:01.0484145Z [rank0]:[2023-11-14 06:30:51,462] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/distributed/distributed_test.py", line 7683, in _test_broadcast_object_list
2023-11-14T06:44:01.0484886Z [rank0]:[2023-11-14 06:30:51,462] torch.testing._internal.common_distributed: [ERROR] dist.broadcast_object_list(
2023-11-14T06:44:01.0486271Z [rank0]:[2023-11-14 06:30:51,462] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/distributed/c10d_logger.py", line 72, in wrapper
2023-11-14T06:44:01.0487018Z [rank0]:[2023-11-14 06:30:51,462] torch.testing._internal.common_distributed: [ERROR] return func(*args, **kwargs)
2023-11-14T06:44:01.0488559Z [rank0]:[2023-11-14 06:30:51,462] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/distributed/distributed_c10d.py", line 2650, in broadcast_object_list
2023-11-14T06:44:01.0489470Z [rank0]:[2023-11-14 06:30:51,462] torch.testing._internal.common_distributed: [ERROR] broadcast(object_sizes_tensor, src=src, group=group)
2023-11-14T06:44:01.0491078Z [rank0]:[2023-11-14 06:30:51,462] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/distributed/c10d_logger.py", line 72, in wrapper
2023-11-14T06:44:01.0491912Z [rank0]:[2023-11-14 06:30:51,462] torch.testing._internal.common_distributed: [ERROR] return func(*args, **kwargs)
2023-11-14T06:44:01.0493369Z [rank0]:[2023-11-14 06:30:51,462] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/distributed/distributed_c10d.py", line 1947, in broadcast
2023-11-14T06:44:01.0494419Z [rank0]:[2023-11-14 06:30:51,462] torch.testing._internal.common_distributed: [ERROR] work = default_pg.broadcast([tensor], opts)
2023-11-14T06:44:01.0496679Z [rank0]:[2023-11-14 06:30:51,462] torch.testing._internal.common_distributed: [ERROR] RuntimeError: [/var/lib/jenkins/workspace/torch/csrc/distributed/c10d/ProcessGroupUCC.cpp:488] [Rank 0][ProcessGroupUCC-0][READY]failed to init cuda collective, error code -1: Operation is not supported, system error code 2
2023-11-14T06:44:01.0497211Z [rank0]:[2023-11-14 06:30:51,462] torch.testing._internal.common_distributed: [ERROR]
2023-11-14T06:44:01.0498198Z [rank0]:[2023-11-14 06:30:51,462] torch.testing._internal.common_distributed: [ERROR] To execute this test, run the following from the base repo dir:
2023-11-14T06:44:01.0499291Z [rank0]:[2023-11-14 06:30:51,462] torch.testing._internal.common_distributed: [ERROR] python test/distributed/test_distributed_spawn.py -k test_broadcast_object_list
2023-11-14T06:44:01.0499838Z [rank0]:[2023-11-14 06:30:51,462] torch.testing._internal.common_distributed: [ERROR]
2023-11-14T06:44:01.0500881Z [rank0]:[2023-11-14 06:30:51,462] torch.testing._internal.common_distributed: [ERROR] This message can be suppressed by setting PYTORCH_PRINT_REPRO_ON_FAILURE=0
2023-11-14T06:44:01.0501667Z [rank0]:[2023-11-14 06:30:51,462] torch.testing._internal.common_distributed: [ERROR] exiting process 0 with exit code: 10
2023-11-14T06:44:01.0502343Z [1699943451.002362] [99f90b6e6ff3:10028:0] parser.c:2034 UCX WARN unused environment variables: UCX_COMMIT; UCX_HOME
2023-11-14T06:44:01.0503024Z [1699943451.002362] [99f90b6e6ff3:10028:0] parser.c:2034 UCX WARN (set UCX_WARN_UNUSED_ENV_VARS=n to suppress this warning)
2023-11-14T06:44:01.0503411Z ('RERUN', {'yellow': True}) [6.1102s] [100%]
```
</details>
test_ddp_sync_bn_training_vs_eval
<details>
```
2023-11-14T06:44:01.1494815Z
2023-11-14T06:44:01.1496630Z distributed/test_distributed_spawn.py::TestDistBackendWithSpawn::test_ddp_sync_bn_training_vs_eval <- ../../../../opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/distributed/distributed_test.py INFO:numba.cuda.cudadrv.driver:init
2023-11-14T06:44:01.1497290Z [1699943779.976037] [99f90b6e6ff3:10758:0] parser.c:2034 UCX WARN unused environment variables: UCX_COMMIT; UCX_HOME
2023-11-14T06:44:01.1498119Z [1699943779.976037] [99f90b6e6ff3:10758:0] parser.c:2034 UCX WARN (set UCX_WARN_UNUSED_ENV_VARS=n to suppress this warning)
2023-11-14T06:44:01.1498808Z STAGE:2023-11-14 06:36:20 10758:10758 ActivityProfilerController.cpp:314] Completed Stage: Warm Up
2023-11-14T06:44:01.1499465Z [1699943779.970792] [99f90b6e6ff3:10757:0] parser.c:2034 UCX WARN unused environment variables: UCX_COMMIT; UCX_HOME
2023-11-14T06:44:01.1500160Z [1699943779.970792] [99f90b6e6ff3:10757:0] parser.c:2034 UCX WARN (set UCX_WARN_UNUSED_ENV_VARS=n to suppress this warning)
2023-11-14T06:44:01.1500820Z STAGE:2023-11-14 06:36:20 10757:10757 ActivityProfilerController.cpp:314] Completed Stage: Warm Up
2023-11-14T06:44:01.1501556Z STAGE:2023-11-14 06:36:20 10758:10758 ActivityProfilerController.cpp:320] Completed Stage: Collection
2023-11-14T06:44:01.1502239Z STAGE:2023-11-14 06:36:20 10757:10757 ActivityProfilerController.cpp:320] Completed Stage: Collection
2023-11-14T06:44:01.1502952Z STAGE:2023-11-14 06:36:20 10757:10757 ActivityProfilerController.cpp:324] Completed Stage: Post Processing
2023-11-14T06:44:01.1503678Z STAGE:2023-11-14 06:36:20 10758:10758 ActivityProfilerController.cpp:324] Completed Stage: Post Processing
2023-11-14T06:44:01.1504350Z [rank0]:[2023-11-14 06:36:20,668] torch.testing._internal.common_distributed: [ERROR] Caught exception:
2023-11-14T06:44:01.1505119Z [rank0]:[2023-11-14 06:36:20,668] torch.testing._internal.common_distributed: [ERROR] Traceback (most recent call last):
2023-11-14T06:44:01.1506729Z [rank0]:[2023-11-14 06:36:20,668] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/common_distributed.py", line 658, in run_test
2023-11-14T06:44:01.1507492Z [rank0]:[2023-11-14 06:36:20,668] torch.testing._internal.common_distributed: [ERROR] getattr(self, test_name)()
2023-11-14T06:44:01.1508992Z [rank0]:[2023-11-14 06:36:20,668] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/common_distributed.py", line 544, in wrapper
2023-11-14T06:44:01.1509578Z [rank0]:[2023-11-14 06:36:20,668] torch.testing._internal.common_distributed: [ERROR] fn()
2023-11-14T06:44:01.1510994Z [rank0]:[2023-11-14 06:36:20,668] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/common_utils.py", line 2536, in wrapper
2023-11-14T06:44:01.1511725Z [rank0]:[2023-11-14 06:36:20,668] torch.testing._internal.common_distributed: [ERROR] method(*args, **kwargs)
2023-11-14T06:44:01.1513193Z [rank0]:[2023-11-14 06:36:20,668] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/common_distributed.py", line 174, in wrapper
2023-11-14T06:44:01.1513962Z [rank0]:[2023-11-14 06:36:20,668] torch.testing._internal.common_distributed: [ERROR] return func(*args, **kwargs)
2023-11-14T06:44:01.1515697Z [rank0]:[2023-11-14 06:36:20,668] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/distributed/distributed_test.py", line 9230, in test_ddp_sync_bn_training_vs_eval
2023-11-14T06:44:01.1516529Z [rank0]:[2023-11-14 06:36:20,668] torch.testing._internal.common_distributed: [ERROR] self.assertNotEqual([], all_gather_calls)
2023-11-14T06:44:01.1518019Z [rank0]:[2023-11-14 06:36:20,668] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/common_utils.py", line 3448, in assertNotEqual
2023-11-14T06:44:01.1518910Z [rank0]:[2023-11-14 06:36:20,668] torch.testing._internal.common_distributed: [ERROR] with self.assertRaises(AssertionError, msg=msg):
2023-11-14T06:44:01.1520177Z [rank0]:[2023-11-14 06:36:20,668] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/unittest/case.py", line 226, in __exit__
2023-11-14T06:44:01.1521062Z [rank0]:[2023-11-14 06:36:20,668] torch.testing._internal.common_distributed: [ERROR] self._raiseFailure("{} not raised".format(exc_name))
2023-11-14T06:44:01.1522238Z [rank0]:[2023-11-14 06:36:20,668] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/unittest/case.py", line 163, in _raiseFailure
2023-11-14T06:44:01.1523099Z [rank0]:[2023-11-14 06:36:20,668] torch.testing._internal.common_distributed: [ERROR] raise self.test_case.failureException(msg)
2023-11-14T06:44:01.1523923Z [rank0]:[2023-11-14 06:36:20,668] torch.testing._internal.common_distributed: [ERROR] AssertionError: AssertionError not raised
2023-11-14T06:44:01.1524470Z [rank0]:[2023-11-14 06:36:20,668] torch.testing._internal.common_distributed: [ERROR]
2023-11-14T06:44:01.1525481Z [rank0]:[2023-11-14 06:36:20,668] torch.testing._internal.common_distributed: [ERROR] To execute this test, run the following from the base repo dir:
2023-11-14T06:44:01.1526632Z [rank0]:[2023-11-14 06:36:20,668] torch.testing._internal.common_distributed: [ERROR] python test/distributed/test_distributed_spawn.py -k test_ddp_sync_bn_training_vs_eval
2023-11-14T06:44:01.1527180Z [rank0]:[2023-11-14 06:36:20,668] torch.testing._internal.common_distributed: [ERROR]
2023-11-14T06:44:01.1528223Z [rank0]:[2023-11-14 06:36:20,668] torch.testing._internal.common_distributed: [ERROR] This message can be suppressed by setting PYTORCH_PRINT_REPRO_ON_FAILURE=0
2023-11-14T06:44:01.1529029Z [rank0]:[2023-11-14 06:36:20,668] torch.testing._internal.common_distributed: [ERROR] exiting process 0 with exit code: 10
2023-11-14T06:44:01.1529786Z [rank1]:[2023-11-14 06:36:20,890] torch.testing._internal.common_distributed: [ERROR] Caught exception:
2023-11-14T06:44:01.1530576Z [rank1]:[2023-11-14 06:36:20,890] torch.testing._internal.common_distributed: [ERROR] Traceback (most recent call last):
2023-11-14T06:44:01.1532383Z [rank1]:[2023-11-14 06:36:20,890] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/common_distributed.py", line 658, in run_test
2023-11-14T06:44:01.1533127Z [rank1]:[2023-11-14 06:36:20,890] torch.testing._internal.common_distributed: [ERROR] getattr(self, test_name)()
2023-11-14T06:44:01.1534608Z [rank1]:[2023-11-14 06:36:20,890] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/common_distributed.py", line 544, in wrapper
2023-11-14T06:44:01.1535194Z [rank1]:[2023-11-14 06:36:20,890] torch.testing._internal.common_distributed: [ERROR] fn()
2023-11-14T06:44:01.1536817Z [rank1]:[2023-11-14 06:36:20,890] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/common_utils.py", line 2536, in wrapper
2023-11-14T06:44:01.1537575Z [rank1]:[2023-11-14 06:36:20,890] torch.testing._internal.common_distributed: [ERROR] method(*args, **kwargs)
2023-11-14T06:44:01.1539036Z [rank1]:[2023-11-14 06:36:20,890] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/common_distributed.py", line 174, in wrapper
2023-11-14T06:44:01.1539800Z [rank1]:[2023-11-14 06:36:20,890] torch.testing._internal.common_distributed: [ERROR] return func(*args, **kwargs)
2023-11-14T06:44:01.1541531Z [rank1]:[2023-11-14 06:36:20,890] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/distributed/distributed_test.py", line 9230, in test_ddp_sync_bn_training_vs_eval
2023-11-14T06:44:01.1542388Z [rank1]:[2023-11-14 06:36:20,890] torch.testing._internal.common_distributed: [ERROR] self.assertNotEqual([], all_gather_calls)
2023-11-14T06:44:01.1544015Z [rank1]:[2023-11-14 06:36:20,890] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/common_utils.py", line 3448, in assertNotEqual
2023-11-14T06:44:01.1544907Z [rank1]:[2023-11-14 06:36:20,890] torch.testing._internal.common_distributed: [ERROR] with self.assertRaises(AssertionError, msg=msg):
2023-11-14T06:44:01.1546061Z [rank1]:[2023-11-14 06:36:20,890] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/unittest/case.py", line 226, in __exit__
2023-11-14T06:44:01.1546944Z [rank1]:[2023-11-14 06:36:20,890] torch.testing._internal.common_distributed: [ERROR] self._raiseFailure("{} not raised".format(exc_name))
2023-11-14T06:44:01.1548142Z [rank1]:[2023-11-14 06:36:20,890] torch.testing._internal.common_distributed: [ERROR] File "/opt/conda/envs/py_3.10/lib/python3.10/unittest/case.py", line 163, in _raiseFailure
2023-11-14T06:44:01.1548991Z [rank1]:[2023-11-14 06:36:20,890] torch.testing._internal.common_distributed: [ERROR] raise self.test_case.failureException(msg)
2023-11-14T06:44:01.1549806Z [rank1]:[2023-11-14 06:36:20,890] torch.testing._internal.common_distributed: [ERROR] AssertionError: AssertionError not raised
2023-11-14T06:44:01.1550350Z [rank1]:[2023-11-14 06:36:20,890] torch.testing._internal.common_distributed: [ERROR]
2023-11-14T06:44:01.1551304Z [rank1]:[2023-11-14 06:36:20,890] torch.testing._internal.common_distributed: [ERROR] To execute this test, run the following from the base repo dir:
2023-11-14T06:44:01.1552462Z [rank1]:[2023-11-14 06:36:20,890] torch.testing._internal.common_distributed: [ERROR] python test/distributed/test_distributed_spawn.py -k test_ddp_sync_bn_training_vs_eval
2023-11-14T06:44:01.1553095Z [rank1]:[2023-11-14 06:36:20,890] torch.testing._internal.common_distributed: [ERROR]
2023-11-14T06:44:01.1554166Z [rank1]:[2023-11-14 06:36:20,890] torch.testing._internal.common_distributed: [ERROR] This message can be suppressed by setting PYTORCH_PRINT_REPRO_ON_FAILURE=0
2023-11-14T06:44:01.1554976Z [rank1]:[2023-11-14 06:36:20,890] torch.testing._internal.common_distributed: [ERROR] exiting process 1 with exit code: 10
2023-11-14T06:44:01.1555235Z ('RERUN', {'yellow': True}) [6.6107s] [100%]
```
</details>
test_backend_full_group
<details>
```
2023-11-14T22:51:56.4502470Z FAILED [5.2125s] distributed/test_distributed_spawn.py::TestDistBackendWithSpawn::test_backend_full_group - RuntimeError: Process 0 exited with error code 10 and exception:
2023-11-14T22:51:56.4502665Z Traceback (most recent call last):
2023-11-14T22:51:56.4503603Z File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/common_distributed.py", line 658, in run_test
2023-11-14T22:51:56.4503796Z getattr(self, test_name)()
2023-11-14T22:51:56.4504710Z File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/common_distributed.py", line 544, in wrapper
2023-11-14T22:51:56.4504845Z fn()
2023-11-14T22:51:56.4505737Z File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/common_utils.py", line 2536, in wrapper
2023-11-14T22:51:56.4505896Z method(*args, **kwargs)
2023-11-14T22:51:56.4506823Z File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/common_distributed.py", line 174, in wrapper
2023-11-14T22:51:56.4506992Z return func(*args, **kwargs)
2023-11-14T22:51:56.4508285Z File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/distributed/distributed_test.py", line 882, in test_backend_full_group
2023-11-14T22:51:56.4508640Z self._test_group_override_backend(self._init_full_group_test)
2023-11-14T22:51:56.4509798Z File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/distributed/distributed_test.py", line 852, in _test_group_override_backend
2023-11-14T22:51:56.4510104Z group, group_id, rank = initializer(backend=new_backend)
2023-11-14T22:51:56.4510629Z UnboundLocalError: local variable 'new_backend' referenced before assignment
2023-11-14T22:51:56.4510650Z
2023-11-14T22:51:56.4510987Z To execute this test, run the following from the base repo dir:
2023-11-14T22:51:56.4511525Z python test/distributed/test_distributed_spawn.py -k test_backend_full_group
2023-11-14T22:51:56.4511545Z
2023-11-14T22:51:56.4511970Z This message can be suppressed by setting PYTORCH_PRINT_REPRO_ON_FAILURE=0
2023-11-14T22:51:56.4511989Z
2023-11-14T22:51:56.4512242Z Process 1 exited with error code 10 and exception:
2023-11-14T22:51:56.4512454Z Traceback (most recent call last):
2023-11-14T22:51:56.4513380Z File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/common_distributed.py", line 658, in run_test
2023-11-14T22:51:56.4513687Z getattr(self, test_name)()
2023-11-14T22:51:56.4514612Z File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/common_distributed.py", line 544, in wrapper
2023-11-14T22:51:56.4514746Z fn()
2023-11-14T22:51:56.4515633Z File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/common_utils.py", line 2536, in wrapper
2023-11-14T22:51:56.4515791Z method(*args, **kwargs)
2023-11-14T22:51:56.4516708Z File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/common_distributed.py", line 174, in wrapper
2023-11-14T22:51:56.4516895Z return func(*args, **kwargs)
2023-11-14T22:51:56.4518008Z File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/distributed/distributed_test.py", line 882, in test_backend_full_group
2023-11-14T22:51:56.4518352Z self._test_group_override_backend(self._init_full_group_test)
2023-11-14T22:51:56.4519509Z File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/distributed/distributed_test.py", line 852, in _test_group_override_backend
2023-11-14T22:51:56.4519813Z group, group_id, rank = initializer(backend=new_backend)
2023-11-14T22:51:56.4520334Z UnboundLocalError: local variable 'new_backend' referenced before assignment
2023-11-14T22:51:56.4520355Z
2023-11-14T22:51:56.4528843Z To execute this test, run the following from the base repo dir:
2023-11-14T22:51:56.4529492Z python test/distributed/test_distributed_spawn.py -k test_backend_full_group
2023-11-14T22:51:56.4529681Z
2023-11-14T22:51:56.4530122Z This message can be suppressed by setting PYTORCH_PRINT_REPRO_ON_FAILURE=0
2023-11-14T22:51:56.4530423Z !!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
```
</details>
pretty sure the solution for this one is to add ucc in _test_group_override_backend
https://ossci-raw-job-status.s3.amazonaws.com/log/18651430019
https://ossci-raw-job-status.s3.amazonaws.com/log/18651430132
Pull Request resolved: https://github.com/pytorch/pytorch/pull/113620
Approved by: https://github.com/huydhn
2023-11-15 21:56:10 +00:00
|
|
|
stepcurrent_key = f"{test_file}_{os.urandom(8).hex()}"
|
2023-10-30 23:31:40 +00:00
|
|
|
else:
|
|
|
|
|
unittest_args.extend(
|
|
|
|
|
[
|
2024-01-23 18:39:30 +00:00
|
|
|
f"--shard-id={test_module.shard}",
|
2023-10-30 23:31:40 +00:00
|
|
|
f"--num-shards={test_module.num_shards}",
|
|
|
|
|
]
|
|
|
|
|
)
|
2024-01-23 18:39:30 +00:00
|
|
|
stepcurrent_key = f"{test_file}_{test_module.shard}_{os.urandom(8).hex()}"
|
2023-03-31 18:36:53 +00:00
|
|
|
|
2018-09-04 02:55:58 +00:00
|
|
|
if options.verbose:
|
Add Lowering for FlexAttention Backwards (#125515)
# Summary
#### What does this PR do?
It enables Inductor to actually generate the fused flex attention kernel for the backwards
I did some other things along the way:
- Abstract out the 'build_subgraph_buffer' subroutine and make it reusable between flex attention and flex_attention backwards. In total we need too build 3 subgraphs for fwd + bwd. 1 for the fwd graph and then 2 in the bwd. The FAv2 algorithm recomputes the parts of the forward (more efficiently since we already have the row_max via logsumexp), therefore we need to inline both the fwd graph and the joint graph in the bwds kernel.
- The version of the backwards kernel is from a somewhat older version of the triton tutorial implementation. I think that we should update in a follow up to a newer version. Notably the blocks need to be square for this to work as currently implemented. I am sure there are many opportunities for optimization.
- I didnt correctly register the decomp table + IndexMode when I landed: https://github.com/pytorch/pytorch/pull/123902, this remedies that.
- The rel_bias helper func was reversed in terms of causality. I updated and then add a test specific for "future causal" attention.
- This PRs but the main point that I think still needs to be worked out is the store_output call. I have it hacked up to be 'fake' but I dont think we want to land that and likely want to just have a mutated 'dq' and a stored_output 'dk'
- I also needed to update the `TritonTemplateKernel` to actually accept multiple subgraphs (modifications)
- I updated the benchmark to also profile bwds performance
### Benchmark Numbers:
_The current implementation is not parallelizing over ctx length in the bwd_
FWD Speedups
| Type | Speedup | shape | score_mod | dtype |
|---------|-----------|--------------------|-------------|----------------|
| Average | 0.991 | | | |
| Max | 1.182 | (16, 16, 4096, 64) | noop | torch.bfloat16 |
| Min | 0.796 | (2, 16, 512, 256) | head_bias | torch.bfloat16 |
BWD Speedups
| Type | Speedup | shape | score_mod | dtype |
|---------|-----------|--------------------|-------------|----------------|
| Average | 0.291 | | | |
| Max | 0.652 | (8, 16, 512, 64) | head_bias | torch.bfloat16 |
| Min | 0.073 | (2, 16, 4096, 128) | head_bias | torch.bfloat16 |
<details>
<summary>Full Data</summary>
| shape | score_mod | dtype | fwd_eager_time | fwd_compiled_time | bwd_eager_time | bwd_compiled_time | fwd_speedup | bwd_speedup |
|---------------------|---------------|----------------|------------------|---------------------|------------------|---------------------|---------------|---------------|
| (2, 16, 512, 64) | noop | torch.bfloat16 | 19.936 | 19.092 | 57.851 | 193.564 | 1.044 | 0.299 |
| (2, 16, 512, 64) | causal_mask | torch.bfloat16 | 19.955 | 19.497 | 57.662 | 206.278 | 1.024 | 0.280 |
| (2, 16, 512, 64) | relative_bias | torch.bfloat16 | 19.455 | 21.297 | 57.674 | 195.219 | 0.913 | 0.295 |
| (2, 16, 512, 64) | head_bias | torch.bfloat16 | 19.958 | 21.289 | 57.674 | 193.859 | 0.938 | 0.298 |
| (2, 16, 512, 128) | noop | torch.bfloat16 | 28.157 | 28.615 | 82.831 | 454.211 | 0.984 | 0.182 |
| (2, 16, 512, 128) | causal_mask | torch.bfloat16 | 28.154 | 28.444 | 83.091 | 432.083 | 0.990 | 0.192 |
| (2, 16, 512, 128) | relative_bias | torch.bfloat16 | 28.722 | 27.897 | 83.175 | 446.789 | 1.030 | 0.186 |
| (2, 16, 512, 128) | head_bias | torch.bfloat16 | 28.299 | 27.673 | 83.052 | 459.179 | 1.023 | 0.181 |
| (2, 16, 512, 256) | noop | torch.bfloat16 | 41.167 | 50.504 | 175.019 | 1083.545 | 0.815 | 0.162 |
| (2, 16, 512, 256) | causal_mask | torch.bfloat16 | 41.656 | 51.933 | 175.078 | 1171.176 | 0.802 | 0.149 |
| (2, 16, 512, 256) | relative_bias | torch.bfloat16 | 41.697 | 50.722 | 175.159 | 1097.312 | 0.822 | 0.160 |
| (2, 16, 512, 256) | head_bias | torch.bfloat16 | 41.690 | 52.387 | 175.184 | 1097.336 | 0.796 | 0.160 |
| (2, 16, 1024, 64) | noop | torch.bfloat16 | 39.232 | 37.454 | 127.847 | 612.430 | 1.047 | 0.209 |
| (2, 16, 1024, 64) | causal_mask | torch.bfloat16 | 39.930 | 39.599 | 127.755 | 665.359 | 1.008 | 0.192 |
| (2, 16, 1024, 64) | relative_bias | torch.bfloat16 | 39.417 | 41.304 | 127.902 | 614.990 | 0.954 | 0.208 |
| (2, 16, 1024, 64) | head_bias | torch.bfloat16 | 39.965 | 42.034 | 127.953 | 613.273 | 0.951 | 0.209 |
| (2, 16, 1024, 128) | noop | torch.bfloat16 | 63.964 | 71.024 | 226.510 | 1637.669 | 0.901 | 0.138 |
| (2, 16, 1024, 128) | causal_mask | torch.bfloat16 | 63.843 | 72.451 | 226.750 | 1558.949 | 0.881 | 0.145 |
| (2, 16, 1024, 128) | relative_bias | torch.bfloat16 | 64.301 | 70.487 | 226.651 | 1610.063 | 0.912 | 0.141 |
| (2, 16, 1024, 128) | head_bias | torch.bfloat16 | 64.033 | 71.394 | 226.676 | 1668.511 | 0.897 | 0.136 |
| (2, 16, 1024, 256) | noop | torch.bfloat16 | 129.348 | 141.390 | 507.337 | 4405.175 | 0.915 | 0.115 |
| (2, 16, 1024, 256) | causal_mask | torch.bfloat16 | 129.538 | 145.680 | 507.178 | 4768.874 | 0.889 | 0.106 |
| (2, 16, 1024, 256) | relative_bias | torch.bfloat16 | 129.438 | 142.782 | 507.004 | 4401.002 | 0.907 | 0.115 |
| (2, 16, 1024, 256) | head_bias | torch.bfloat16 | 129.058 | 146.242 | 507.547 | 4434.251 | 0.883 | 0.114 |
| (2, 16, 4096, 64) | noop | torch.bfloat16 | 481.606 | 409.120 | 1440.890 | 14147.269 | 1.177 | 0.102 |
| (2, 16, 4096, 64) | causal_mask | torch.bfloat16 | 480.227 | 438.847 | 1434.419 | 14973.386 | 1.094 | 0.096 |
| (2, 16, 4096, 64) | relative_bias | torch.bfloat16 | 480.831 | 458.104 | 1432.935 | 14193.253 | 1.050 | 0.101 |
| (2, 16, 4096, 64) | head_bias | torch.bfloat16 | 480.749 | 452.497 | 1437.040 | 14084.869 | 1.062 | 0.102 |
| (2, 16, 4096, 128) | noop | torch.bfloat16 | 872.534 | 848.275 | 2600.895 | 35156.849 | 1.029 | 0.074 |
| (2, 16, 4096, 128) | causal_mask | torch.bfloat16 | 872.647 | 868.279 | 2587.581 | 31919.531 | 1.005 | 0.081 |
| (2, 16, 4096, 128) | relative_bias | torch.bfloat16 | 871.484 | 827.644 | 2593.989 | 34805.634 | 1.053 | 0.075 |
| (2, 16, 4096, 128) | head_bias | torch.bfloat16 | 871.422 | 856.437 | 2602.482 | 35708.591 | 1.017 | 0.073 |
| (2, 16, 4096, 256) | noop | torch.bfloat16 | 1904.497 | 1758.183 | 6122.416 | 66754.593 | 1.083 | 0.092 |
| (2, 16, 4096, 256) | causal_mask | torch.bfloat16 | 1911.174 | 1762.821 | 6113.207 | 72759.392 | 1.084 | 0.084 |
| (2, 16, 4096, 256) | relative_bias | torch.bfloat16 | 1911.254 | 1727.108 | 6123.530 | 66577.988 | 1.107 | 0.092 |
| (2, 16, 4096, 256) | head_bias | torch.bfloat16 | 1916.977 | 1801.804 | 6118.158 | 67359.680 | 1.064 | 0.091 |
| (8, 16, 512, 64) | noop | torch.bfloat16 | 44.984 | 43.974 | 170.276 | 262.259 | 1.023 | 0.649 |
| (8, 16, 512, 64) | causal_mask | torch.bfloat16 | 45.001 | 46.265 | 170.509 | 274.893 | 0.973 | 0.620 |
| (8, 16, 512, 64) | relative_bias | torch.bfloat16 | 45.466 | 48.211 | 170.606 | 262.759 | 0.943 | 0.649 |
| (8, 16, 512, 64) | head_bias | torch.bfloat16 | 45.481 | 48.435 | 170.267 | 261.265 | 0.939 | 0.652 |
| (8, 16, 512, 128) | noop | torch.bfloat16 | 72.565 | 74.736 | 313.220 | 773.126 | 0.971 | 0.405 |
| (8, 16, 512, 128) | causal_mask | torch.bfloat16 | 72.015 | 75.755 | 313.311 | 775.513 | 0.951 | 0.404 |
| (8, 16, 512, 128) | relative_bias | torch.bfloat16 | 72.105 | 74.189 | 313.806 | 769.238 | 0.972 | 0.408 |
| (8, 16, 512, 128) | head_bias | torch.bfloat16 | 72.005 | 74.364 | 313.509 | 775.237 | 0.968 | 0.404 |
| (8, 16, 512, 256) | noop | torch.bfloat16 | 138.656 | 165.453 | 663.707 | 2672.067 | 0.838 | 0.248 |
| (8, 16, 512, 256) | causal_mask | torch.bfloat16 | 139.096 | 172.613 | 663.593 | 2926.538 | 0.806 | 0.227 |
| (8, 16, 512, 256) | relative_bias | torch.bfloat16 | 139.500 | 168.417 | 663.938 | 2658.629 | 0.828 | 0.250 |
| (8, 16, 512, 256) | head_bias | torch.bfloat16 | 139.776 | 173.549 | 662.920 | 2667.266 | 0.805 | 0.249 |
| (8, 16, 1024, 64) | noop | torch.bfloat16 | 134.883 | 125.004 | 484.706 | 1195.254 | 1.079 | 0.406 |
| (8, 16, 1024, 64) | causal_mask | torch.bfloat16 | 134.297 | 132.875 | 485.420 | 1234.953 | 1.011 | 0.393 |
| (8, 16, 1024, 64) | relative_bias | torch.bfloat16 | 134.839 | 139.231 | 485.470 | 1198.556 | 0.968 | 0.405 |
| (8, 16, 1024, 64) | head_bias | torch.bfloat16 | 133.822 | 136.449 | 485.608 | 1189.198 | 0.981 | 0.408 |
| (8, 16, 1024, 128) | noop | torch.bfloat16 | 235.470 | 234.765 | 886.094 | 2662.944 | 1.003 | 0.333 |
| (8, 16, 1024, 128) | causal_mask | torch.bfloat16 | 236.305 | 241.382 | 886.293 | 2646.984 | 0.979 | 0.335 |
| (8, 16, 1024, 128) | relative_bias | torch.bfloat16 | 236.414 | 233.980 | 885.250 | 2642.178 | 1.010 | 0.335 |
| (8, 16, 1024, 128) | head_bias | torch.bfloat16 | 237.176 | 239.040 | 885.754 | 2665.242 | 0.992 | 0.332 |
| (8, 16, 1024, 256) | noop | torch.bfloat16 | 504.445 | 517.855 | 1978.956 | 9592.906 | 0.974 | 0.206 |
| (8, 16, 1024, 256) | causal_mask | torch.bfloat16 | 502.428 | 536.002 | 1978.611 | 10607.342 | 0.937 | 0.187 |
| (8, 16, 1024, 256) | relative_bias | torch.bfloat16 | 503.396 | 523.960 | 1977.993 | 9539.284 | 0.961 | 0.207 |
| (8, 16, 1024, 256) | head_bias | torch.bfloat16 | 503.818 | 536.014 | 1980.131 | 9576.262 | 0.940 | 0.207 |
| (8, 16, 4096, 64) | noop | torch.bfloat16 | 1970.139 | 1674.930 | 5750.940 | 16724.134 | 1.176 | 0.344 |
| (8, 16, 4096, 64) | causal_mask | torch.bfloat16 | 1959.036 | 1775.056 | 5780.512 | 17390.350 | 1.104 | 0.332 |
| (8, 16, 4096, 64) | relative_bias | torch.bfloat16 | 1947.198 | 1773.869 | 5780.643 | 16779.699 | 1.098 | 0.345 |
| (8, 16, 4096, 64) | head_bias | torch.bfloat16 | 1963.935 | 1829.502 | 5780.018 | 16703.259 | 1.073 | 0.346 |
| (8, 16, 4096, 128) | noop | torch.bfloat16 | 3582.711 | 3362.623 | 10436.069 | 36415.565 | 1.065 | 0.287 |
| (8, 16, 4096, 128) | causal_mask | torch.bfloat16 | 3581.504 | 3499.472 | 10346.869 | 36164.959 | 1.023 | 0.286 |
| (8, 16, 4096, 128) | relative_bias | torch.bfloat16 | 3589.779 | 3337.849 | 10529.621 | 36261.696 | 1.075 | 0.290 |
| (8, 16, 4096, 128) | head_bias | torch.bfloat16 | 3602.265 | 3436.444 | 10458.660 | 36507.790 | 1.048 | 0.286 |
| (8, 16, 4096, 256) | noop | torch.bfloat16 | 7695.923 | 7126.275 | 24643.009 | 140949.081 | 1.080 | 0.175 |
| (8, 16, 4096, 256) | causal_mask | torch.bfloat16 | 7679.939 | 7186.252 | 24538.105 | 157156.067 | 1.069 | 0.156 |
| (8, 16, 4096, 256) | relative_bias | torch.bfloat16 | 7681.374 | 6994.832 | 24549.713 | 140077.179 | 1.098 | 0.175 |
| (8, 16, 4096, 256) | head_bias | torch.bfloat16 | 7679.822 | 7212.278 | 24627.823 | 140675.003 | 1.065 | 0.175 |
| (16, 16, 512, 64) | noop | torch.bfloat16 | 80.126 | 78.291 | 333.719 | 541.165 | 1.023 | 0.617 |
| (16, 16, 512, 64) | causal_mask | torch.bfloat16 | 80.065 | 81.696 | 333.779 | 551.113 | 0.980 | 0.606 |
| (16, 16, 512, 64) | relative_bias | torch.bfloat16 | 80.138 | 86.715 | 333.364 | 542.118 | 0.924 | 0.615 |
| (16, 16, 512, 64) | head_bias | torch.bfloat16 | 80.415 | 85.204 | 333.294 | 536.840 | 0.944 | 0.621 |
| (16, 16, 512, 128) | noop | torch.bfloat16 | 134.964 | 138.025 | 607.093 | 1333.102 | 0.978 | 0.455 |
| (16, 16, 512, 128) | causal_mask | torch.bfloat16 | 134.192 | 141.523 | 606.269 | 1424.318 | 0.948 | 0.426 |
| (16, 16, 512, 128) | relative_bias | torch.bfloat16 | 135.711 | 138.639 | 606.283 | 1327.974 | 0.979 | 0.457 |
| (16, 16, 512, 128) | head_bias | torch.bfloat16 | 135.552 | 140.555 | 607.107 | 1347.370 | 0.964 | 0.451 |
| (16, 16, 512, 256) | noop | torch.bfloat16 | 275.113 | 315.144 | 1301.583 | 5268.153 | 0.873 | 0.247 |
| (16, 16, 512, 256) | causal_mask | torch.bfloat16 | 274.867 | 328.106 | 1302.513 | 5770.594 | 0.838 | 0.226 |
| (16, 16, 512, 256) | relative_bias | torch.bfloat16 | 276.052 | 321.770 | 1302.904 | 5241.920 | 0.858 | 0.249 |
| (16, 16, 512, 256) | head_bias | torch.bfloat16 | 271.409 | 328.839 | 1302.142 | 5266.037 | 0.825 | 0.247 |
| (16, 16, 1024, 64) | noop | torch.bfloat16 | 260.489 | 237.463 | 955.884 | 1817.558 | 1.097 | 0.526 |
| (16, 16, 1024, 64) | causal_mask | torch.bfloat16 | 262.378 | 254.350 | 955.280 | 1843.807 | 1.032 | 0.518 |
| (16, 16, 1024, 64) | relative_bias | torch.bfloat16 | 261.338 | 268.253 | 956.038 | 1820.036 | 0.974 | 0.525 |
| (16, 16, 1024, 64) | head_bias | torch.bfloat16 | 262.153 | 264.156 | 956.023 | 1810.076 | 0.992 | 0.528 |
| (16, 16, 1024, 128) | noop | torch.bfloat16 | 476.475 | 461.413 | 1760.578 | 4306.521 | 1.033 | 0.409 |
| (16, 16, 1024, 128) | causal_mask | torch.bfloat16 | 473.794 | 479.178 | 1761.277 | 4619.439 | 0.989 | 0.381 |
| (16, 16, 1024, 128) | relative_bias | torch.bfloat16 | 473.839 | 463.282 | 1758.692 | 4290.562 | 1.023 | 0.410 |
| (16, 16, 1024, 128) | head_bias | torch.bfloat16 | 472.979 | 472.896 | 1763.086 | 4367.931 | 1.000 | 0.404 |
| (16, 16, 1024, 256) | noop | torch.bfloat16 | 1014.184 | 1026.764 | 3922.997 | 19104.147 | 0.988 | 0.205 |
| (16, 16, 1024, 256) | causal_mask | torch.bfloat16 | 1013.217 | 1039.046 | 3928.382 | 21086.281 | 0.975 | 0.186 |
| (16, 16, 1024, 256) | relative_bias | torch.bfloat16 | 1008.519 | 1015.278 | 3922.133 | 18980.652 | 0.993 | 0.207 |
| (16, 16, 1024, 256) | head_bias | torch.bfloat16 | 1011.360 | 1047.542 | 3931.245 | 19069.172 | 0.965 | 0.206 |
| (16, 16, 4096, 64) | noop | torch.bfloat16 | 3929.850 | 3325.667 | 11411.704 | 23344.280 | 1.182 | 0.489 |
| (16, 16, 4096, 64) | causal_mask | torch.bfloat16 | 3885.262 | 3581.544 | 11390.515 | 23725.639 | 1.085 | 0.480 |
| (16, 16, 4096, 64) | relative_bias | torch.bfloat16 | 3865.737 | 3537.308 | 11489.901 | 23406.330 | 1.093 | 0.491 |
| (16, 16, 4096, 64) | head_bias | torch.bfloat16 | 3880.530 | 3665.249 | 11484.411 | 23299.496 | 1.059 | 0.493 |
| (16, 16, 4096, 128) | noop | torch.bfloat16 | 7030.306 | 6745.715 | 20621.264 | 57464.096 | 1.042 | 0.359 |
| (16, 16, 4096, 128) | causal_mask | torch.bfloat16 | 7095.414 | 7034.385 | 20410.656 | 61660.511 | 1.009 | 0.331 |
| (16, 16, 4096, 128) | relative_bias | torch.bfloat16 | 7084.779 | 6686.497 | 20315.161 | 57243.969 | 1.060 | 0.355 |
| (16, 16, 4096, 128) | head_bias | torch.bfloat16 | 7075.367 | 6863.305 | 20494.385 | 58481.953 | 1.031 | 0.350 |
| (16, 16, 4096, 256) | noop | torch.bfloat16 | 15612.741 | 14297.482 | 55306.847 | 281161.865 | 1.092 | 0.197 |
| (16, 16, 4096, 256) | causal_mask | torch.bfloat16 | 15326.592 | 14263.878 | 55227.806 | 313063.232 | 1.075 | 0.176 |
| (16, 16, 4096, 256) | relative_bias | torch.bfloat16 | 15297.963 | 14007.379 | 54558.029 | 279529.175 | 1.092 | 0.195 |
| (16, 16, 4096, 256) | head_bias | torch.bfloat16 | 15216.160 | 14276.027 | 55081.581 | 280996.826 | 1.066 | 0.196 |
</details>
Pull Request resolved: https://github.com/pytorch/pytorch/pull/125515
Approved by: https://github.com/Chillee
2024-05-17 00:41:55 +00:00
|
|
|
unittest_args.append(f'-{"v" * options.verbose}') # in case of pytest
|
Discover and run C++ tests with run_test.py (#99559)
This depends on [pytest-cpp](https://github.com/pytest-dev/pytest-cpp) to discover and run C++ tests with pytest. C++ tests are built under `${WORKSPACE}/build/bin` directory and copied to the test job under the same path.
* To expose them to `run_test`, I choose to use the mock path prefix `cpp`, for example `build/bin/c10_Array_test` would be named as `cpp/c10_Array_test` and the `python test/run_test.py --cpp -i cpp/c10_Array_test` would run the test in the same way as other Python tests. I could copy them from `build/bin` to `test/cpp`, but it will be mixed with the source code and CMake file. So this looks easier
* Some executable under `build/bin` are not C++ tests, and they are exclude, for example `build/bin/torch_shm_manager`
* C++ tests need to run with pytest directly as python command doesn't understand it
* The change is gated by the new `--cpp` argument to `run_test.py`, for example `python test/run_test.py --cpp` will run all available C++ tests
* The tests can be run in parallel
* Failing tests can be retried with `--reruns=2` and `--sw`
```
============================= test session starts ==============================
platform darwin -- Python 3.9.15, pytest-7.2.0, pluggy-1.0.0 -- /Users/huydo/miniconda3/envs/py3.9/bin/python3
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/Users/huydo/Storage/mine/pytorch/test/.hypothesis/examples')
rootdir: /Users/huydo/Storage/mine/pytorch, configfile: pytest.ini
plugins: xdoctest-1.1.0, cpp-2.3.0, rerunfailures-10.3, shard-0.1.2, flakefinder-1.1.0, hypothesis-6.56.4, xdist-3.0.2, repeat-0.9.1
collecting ... collected 3 items / 2 deselected / 1 selected
Running 1 items in this shard: build/bin/scalar_tensor_test::TestScalarTensor.TestScalarTensorMPS
stepwise: skipping 2 already passed items.
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS FAILED [100%]
```
* `--import-slow-tests` and `--import-disabled-tests` won't work for now and that's ok to have it as a future task.
I also add `pytest-cpp==2.3.0` to Linux Docker, MacOS, and Windows.
### Testing
Build PyTorch and run `python test/run_test.py --cpp` on my laptop. CI change would come later in a separate PR. Also running `python test/run_test.py --help` now shows all C++ test discovered under `build/bin`
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99559
Approved by: https://github.com/clee2000
2023-04-22 00:23:31 +00:00
|
|
|
|
2023-03-31 18:36:53 +00:00
|
|
|
if test_file in RUN_PARALLEL_BLOCKLIST:
|
2021-08-12 18:39:31 +00:00
|
|
|
unittest_args = [
|
|
|
|
|
arg for arg in unittest_args if not arg.startswith("--run-parallel")
|
|
|
|
|
]
|
Discover and run C++ tests with run_test.py (#99559)
This depends on [pytest-cpp](https://github.com/pytest-dev/pytest-cpp) to discover and run C++ tests with pytest. C++ tests are built under `${WORKSPACE}/build/bin` directory and copied to the test job under the same path.
* To expose them to `run_test`, I choose to use the mock path prefix `cpp`, for example `build/bin/c10_Array_test` would be named as `cpp/c10_Array_test` and the `python test/run_test.py --cpp -i cpp/c10_Array_test` would run the test in the same way as other Python tests. I could copy them from `build/bin` to `test/cpp`, but it will be mixed with the source code and CMake file. So this looks easier
* Some executable under `build/bin` are not C++ tests, and they are exclude, for example `build/bin/torch_shm_manager`
* C++ tests need to run with pytest directly as python command doesn't understand it
* The change is gated by the new `--cpp` argument to `run_test.py`, for example `python test/run_test.py --cpp` will run all available C++ tests
* The tests can be run in parallel
* Failing tests can be retried with `--reruns=2` and `--sw`
```
============================= test session starts ==============================
platform darwin -- Python 3.9.15, pytest-7.2.0, pluggy-1.0.0 -- /Users/huydo/miniconda3/envs/py3.9/bin/python3
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/Users/huydo/Storage/mine/pytorch/test/.hypothesis/examples')
rootdir: /Users/huydo/Storage/mine/pytorch, configfile: pytest.ini
plugins: xdoctest-1.1.0, cpp-2.3.0, rerunfailures-10.3, shard-0.1.2, flakefinder-1.1.0, hypothesis-6.56.4, xdist-3.0.2, repeat-0.9.1
collecting ... collected 3 items / 2 deselected / 1 selected
Running 1 items in this shard: build/bin/scalar_tensor_test::TestScalarTensor.TestScalarTensorMPS
stepwise: skipping 2 already passed items.
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS FAILED [100%]
```
* `--import-slow-tests` and `--import-disabled-tests` won't work for now and that's ok to have it as a future task.
I also add `pytest-cpp==2.3.0` to Linux Docker, MacOS, and Windows.
### Testing
Build PyTorch and run `python test/run_test.py --cpp` on my laptop. CI change would come later in a separate PR. Also running `python test/run_test.py --help` now shows all C++ test discovered under `build/bin`
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99559
Approved by: https://github.com/clee2000
2023-04-22 00:23:31 +00:00
|
|
|
|
2020-07-28 15:12:41 +00:00
|
|
|
if extra_unittest_args:
|
|
|
|
|
assert isinstance(extra_unittest_args, list)
|
|
|
|
|
unittest_args.extend(extra_unittest_args)
|
2020-10-29 22:18:05 +00:00
|
|
|
|
|
|
|
|
# If using pytest, replace -f with equivalent -x
|
|
|
|
|
if options.pytest:
|
2023-04-25 20:56:04 +00:00
|
|
|
unittest_args.extend(
|
Do not collect and skip non-disabled tests when rerunning disabled tests (#102107)
The console log blows up to much when running in rerun disabled tests mode (x50) https://hud.pytorch.org/pytorch/pytorch/commit/e132f09e8878418fb98a4b76a441a324452354ec. Each log is around 1GB and the whole uncompressed logs is ~50GB. After compression, it will be around 1GB, still too big. The increase comes mainly from the multiple SKIPPED message for non-disabled tests, which is expected due to how SkipTest and pytest-flakyfinder currently work.
I update `test/conftest.py` to completely ignore skipped tests when rerunning disabled test instead of collecting then skipping 50 tests each. The benefit of doing is is much more than I originally expect:
* Rerun disabled tests jobs now finish in less than half an hour as they should be
* Fix OOM runner crash because of too many collected tests
* Fix verbosity issue as now only disabled tests are run x50 times. There are only few hundreds of them atm
* Fix timed out issue when rerunning disabled distributed and ASAN tests. They are just too slow when running at x50
### Testing
When rerunning disabled tests https://github.com/pytorch/pytorch/actions/runs/5084508614, only disabled tests on the platform are run, for example `test_ops_jit` on https://ossci-raw-job-status.s3.amazonaws.com/log/13770164954 only ran 100 tests (`test_variant_consistency_jit_linalg_lu_cuda_float32` + `test_variant_consistency_jit_linalg_lu_factor_cuda_complex64`) x50.
```
Executing ['/opt/conda/envs/py_3.10/bin/python', '-bb', 'test_ops_jit.py', '--shard-id=1', '--num-shards=2', '-v', '-vv', '-rfEX', '-p', 'no:xdist', '--use-pytest', '--sc=test_ops_jit_1', '--flake-finder', '--flake-runs=50', '--import-slow-tests', '--import-disabled-tests', '--rerun-disabled-tests'] ... [2023-05-25 21:32:49.763856]
Expand the folded group to see the log file of test_ops_jit 2/2
##[group]PRINTING LOG FILE of test_ops_jit 2/2 (/var/lib/jenkins/workspace/test/test-reports/test_ops_jit_h2wr_t2c.log)
Test results will be stored in test-reports/python-pytest/test_ops_jit/test_ops_jit-51a83bd44549074e.xml
============================= test session starts ==============================
platform linux -- Python 3.10.11, pytest-7.3.1, pluggy-1.0.0 -- /opt/conda/envs/py_3.10/bin/python
cachedir: .pytest_cache
hypothesis profile 'pytorch_ci' -> database=None, max_examples=50, derandomize=True, suppress_health_check=[HealthCheck.too_slow]
rootdir: /var/lib/jenkins/workspace
configfile: pytest.ini
plugins: hypothesis-5.35.1, cpp-2.3.0, flakefinder-1.1.0, rerunfailures-11.1.2, shard-0.1.2, xdist-3.3.0, xdoctest-1.1.0
collecting ... collected 1084 items
Running 100 items in this shard: test/test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_cuda_float32 (x50), test/test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_factor_cuda_complex64 (x50)
stepcurrent: Cannot find last run test, not skipping
test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_cuda_float32 PASSED [2.1876s] [ 1%]
test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_factor_cuda_complex64 PASSED [4.5615s] [ 2%]
```
* [pull](https://github.com/pytorch/pytorch/actions/runs/5093566864)
* [trunk](https://github.com/pytorch/pytorch/actions/runs/5095364311)
* [periodic](https://github.com/pytorch/pytorch/actions/runs/5095378850)
* [slow](https://github.com/pytorch/pytorch/actions/runs/5095390285)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/102107
Approved by: https://github.com/clee2000, https://github.com/malfet
2023-05-27 12:10:32 +00:00
|
|
|
get_pytest_args(
|
|
|
|
|
options,
|
|
|
|
|
is_cpp_test=is_cpp_test,
|
|
|
|
|
is_distributed_test=is_distributed_test,
|
|
|
|
|
)
|
2023-04-25 20:56:04 +00:00
|
|
|
)
|
2023-10-30 23:31:40 +00:00
|
|
|
unittest_args.extend(test_module.get_pytest_args())
|
[BE][tests] show local variables on failure in tests (#131151)
------
As per the title, add argument `--locals` for `unittest` and `--showlocals --tb=long` for `pytest` in CI.
Some failures cannot be reproduced on the local machine but exist on cloud CI. This change allows us to investigate the test failure more easily.
Example output: https://github.com/pytorch/pytorch/actions/runs/9961546996/job/27523888353?pr=130710#step:20:3361
```text
/opt/conda/envs/py_3.8/lib/python3.8/site-packages/sympy/core/function.py:307:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
cls = FloorDiv, base = -1.00000000000000, divisor = -1.00000000000000
@classmethod
def eval(cls, base, divisor):
# python test/test_dynamic_shapes.py -k TestDimConstraints.test_dim_constraints_solve_full
# Assert triggered by inequality solver
# assert base.is_integer, base
# assert divisor.is_integer, divisor
# We don't provide the same error message as in Python because SymPy
# makes it difficult to check the types.
if divisor.is_zero:
raise ZeroDivisionError("division by zero")
if base in (int_oo, -int_oo, sympy.oo, -sympy.oo) and divisor in (
int_oo,
-int_oo,
sympy.oo,
-sympy.oo,
):
return sympy.nan
if base is sympy.nan or divisor is sympy.nan:
return sympy.nan
if base.is_zero:
return sympy.S.Zero
if base.is_integer and divisor == 1:
return base
if base.is_integer and divisor == -1:
return sympy.Mul(base, -1)
if (
isinstance(base, sympy.Number)
and isinstance(divisor, sympy.Number)
and (
base in (int_oo, -int_oo, sympy.oo, -sympy.oo)
or divisor in (int_oo, -int_oo, sympy.oo, -sympy.oo)
)
):
r = float(base) / float(divisor)
if r == math.inf:
return int_oo
elif r == -math.inf:
return -int_oo
elif math.isnan(r):
return sympy.nan
else:
return sympy.Integer(math.floor(r))
if isinstance(base, sympy.Integer) and isinstance(divisor, sympy.Integer):
return sympy.Integer(int(base) // int(divisor))
if isinstance(base, FloorDiv):
return FloorDiv(base.args[0], base.args[1] * divisor)
# Expands (x + y) // b into x // b + y // b.
# This only works if floor is an identity, i.e. x / b is an integer.
for term in sympy.Add.make_args(base):
quotient = term / divisor
if quotient.is_integer and isinstance(divisor, sympy.Integer):
# NB: this is correct even if the divisor is not an integer, but it
# creates rational expressions that cause problems with dynamic
# shapes.
return FloorDiv(base - term, divisor) + quotient
try:
gcd = sympy.gcd(base, divisor)
if gcd != 1:
> return FloorDiv(
sympy.simplify(base / gcd), sympy.simplify(divisor / gcd)
)
base = -1.00000000000000
cls = FloorDiv
divisor = -1.00000000000000
gcd = 1.00000000000000
quotient = 1.00000000000000
term = -1.00000000000000
/opt/conda/envs/py_3.8/lib/python3.8/site-packages/torch/utils/_sympy/functions.py:159:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
args = (FloorDiv, -1.00000000000000, -1.00000000000000), kwargs = {}
@wraps(func)
def wrapper(*args, **kwargs):
try:
> retval = cfunc(*args, **kwargs)
E RecursionError: maximum recursion depth exceeded in comparison
E
E To execute this test, run the following from the base repo dir:
E python test/test_sympy_utils.py -k TestValueRanges.test_binary_ref_fn_floordiv_dtype_float
E
E This message can be suppressed by setting PYTORCH_PRINT_REPRO_ON_FAILURE=0
args = (FloorDiv, -1.00000000000000, -1.00000000000000)
cfunc = <functools._lru_cache_wrapper object at 0x7fc5303173a0>
func = <function Function.__new__ at 0x7fc530317280>
kwargs = {}
```
Pull Request resolved: https://github.com/pytorch/pytorch/pull/131151
Approved by: https://github.com/ezyang
2024-07-29 16:04:26 +00:00
|
|
|
replacement = {"-f": "-x"}
|
|
|
|
|
unittest_args = [replacement.get(arg, arg) for arg in unittest_args]
|
|
|
|
|
|
|
|
|
|
if options.showlocals:
|
|
|
|
|
if options.pytest:
|
|
|
|
|
unittest_args.extend(["--showlocals", "--tb=long", "--color=yes"])
|
|
|
|
|
else:
|
|
|
|
|
unittest_args.append("--locals")
|
Discover and run C++ tests with run_test.py (#99559)
This depends on [pytest-cpp](https://github.com/pytest-dev/pytest-cpp) to discover and run C++ tests with pytest. C++ tests are built under `${WORKSPACE}/build/bin` directory and copied to the test job under the same path.
* To expose them to `run_test`, I choose to use the mock path prefix `cpp`, for example `build/bin/c10_Array_test` would be named as `cpp/c10_Array_test` and the `python test/run_test.py --cpp -i cpp/c10_Array_test` would run the test in the same way as other Python tests. I could copy them from `build/bin` to `test/cpp`, but it will be mixed with the source code and CMake file. So this looks easier
* Some executable under `build/bin` are not C++ tests, and they are exclude, for example `build/bin/torch_shm_manager`
* C++ tests need to run with pytest directly as python command doesn't understand it
* The change is gated by the new `--cpp` argument to `run_test.py`, for example `python test/run_test.py --cpp` will run all available C++ tests
* The tests can be run in parallel
* Failing tests can be retried with `--reruns=2` and `--sw`
```
============================= test session starts ==============================
platform darwin -- Python 3.9.15, pytest-7.2.0, pluggy-1.0.0 -- /Users/huydo/miniconda3/envs/py3.9/bin/python3
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/Users/huydo/Storage/mine/pytorch/test/.hypothesis/examples')
rootdir: /Users/huydo/Storage/mine/pytorch, configfile: pytest.ini
plugins: xdoctest-1.1.0, cpp-2.3.0, rerunfailures-10.3, shard-0.1.2, flakefinder-1.1.0, hypothesis-6.56.4, xdist-3.0.2, repeat-0.9.1
collecting ... collected 3 items / 2 deselected / 1 selected
Running 1 items in this shard: build/bin/scalar_tensor_test::TestScalarTensor.TestScalarTensorMPS
stepwise: skipping 2 already passed items.
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS FAILED [100%]
```
* `--import-slow-tests` and `--import-disabled-tests` won't work for now and that's ok to have it as a future task.
I also add `pytest-cpp==2.3.0` to Linux Docker, MacOS, and Windows.
### Testing
Build PyTorch and run `python test/run_test.py --cpp` on my laptop. CI change would come later in a separate PR. Also running `python test/run_test.py --help` now shows all C++ test discovered under `build/bin`
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99559
Approved by: https://github.com/clee2000
2023-04-22 00:23:31 +00:00
|
|
|
|
2024-02-03 23:54:27 +00:00
|
|
|
# NB: These features are not available for C++ tests, but there is little incentive
|
|
|
|
|
# to implement it because we have never seen a flaky C++ test before.
|
Discover and run C++ tests with run_test.py (#99559)
This depends on [pytest-cpp](https://github.com/pytest-dev/pytest-cpp) to discover and run C++ tests with pytest. C++ tests are built under `${WORKSPACE}/build/bin` directory and copied to the test job under the same path.
* To expose them to `run_test`, I choose to use the mock path prefix `cpp`, for example `build/bin/c10_Array_test` would be named as `cpp/c10_Array_test` and the `python test/run_test.py --cpp -i cpp/c10_Array_test` would run the test in the same way as other Python tests. I could copy them from `build/bin` to `test/cpp`, but it will be mixed with the source code and CMake file. So this looks easier
* Some executable under `build/bin` are not C++ tests, and they are exclude, for example `build/bin/torch_shm_manager`
* C++ tests need to run with pytest directly as python command doesn't understand it
* The change is gated by the new `--cpp` argument to `run_test.py`, for example `python test/run_test.py --cpp` will run all available C++ tests
* The tests can be run in parallel
* Failing tests can be retried with `--reruns=2` and `--sw`
```
============================= test session starts ==============================
platform darwin -- Python 3.9.15, pytest-7.2.0, pluggy-1.0.0 -- /Users/huydo/miniconda3/envs/py3.9/bin/python3
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/Users/huydo/Storage/mine/pytorch/test/.hypothesis/examples')
rootdir: /Users/huydo/Storage/mine/pytorch, configfile: pytest.ini
plugins: xdoctest-1.1.0, cpp-2.3.0, rerunfailures-10.3, shard-0.1.2, flakefinder-1.1.0, hypothesis-6.56.4, xdist-3.0.2, repeat-0.9.1
collecting ... collected 3 items / 2 deselected / 1 selected
Running 1 items in this shard: build/bin/scalar_tensor_test::TestScalarTensor.TestScalarTensorMPS
stepwise: skipping 2 already passed items.
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS FAILED [100%]
```
* `--import-slow-tests` and `--import-disabled-tests` won't work for now and that's ok to have it as a future task.
I also add `pytest-cpp==2.3.0` to Linux Docker, MacOS, and Windows.
### Testing
Build PyTorch and run `python test/run_test.py --cpp` on my laptop. CI change would come later in a separate PR. Also running `python test/run_test.py --help` now shows all C++ test discovered under `build/bin`
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99559
Approved by: https://github.com/clee2000
2023-04-22 00:23:31 +00:00
|
|
|
if IS_CI and not is_cpp_test:
|
Add a mode to rerun all disabled tests (without running anything else) (#88646)
Rerun all disabled test to gather their latest result so that we can close disabled tickets automatically. When running under this mode (RERUN_DISABLED_TESTS=true), only disabled tests are run while the rest are skipped `<skipped message="Test is enabled but --rerun-disabled-tests verification mode is set, so only disabled tests are run" type="skip"/>`
The logic is roughly as follows, the test runs multiple times (n=50)
* If the disabled test passes, and it's flaky, do nothing because it's still flaky. In the test report, we'll see the test passes with the following skipped message:
```
<testcase classname="TestMultiprocessing" file="test_multiprocessing.py" line="357" name="test_fs" time="0.000" timestamp="0001-01-01T00:00:00">
<skipped message="{"flaky": True, "num_red": 4, "num_green": 0, "max_num_retries": 3, "rerun_disabled_test": true}" type="skip"/>
</testcase>
```
* If the disabled test passes every single time, and it is not flaky anymore, mark it so that it can be closed later. We will see the test runs and passes, i.e.
```
<testcase classname="TestCommonCUDA" name="test_out_warning_linalg_lu_factor_cuda" time="0.170" file="test_ops.py" />
```
* If the disabled test fails after all retries, this is also expected. So only report this but don't fail the job (because we don't care about red signals here), we'll see the test is skipped (without the `flaky` field), i.e.
```
<testcase classname="TestMultiprocessing" file="test_multiprocessing.py" line="357" name="test_fs" time="0.000" timestamp="0001-01-01T00:00:00">
<skipped message="{"num_red": 4, "num_green": 0, "max_num_retries": 3, "rerun_disabled_test": true}" type="skip"/>
</testcase>
```
This runs at the same schedule as `mem_leak_check` (daily). The change to update test stats, and (potentially) grouping on HUD will come in separated PRs.
### Testing
* pull https://github.com/pytorch/pytorch/actions/runs/3447434434
* trunk https://github.com/pytorch/pytorch/actions/runs/3447434928
Pull Request resolved: https://github.com/pytorch/pytorch/pull/88646
Approved by: https://github.com/clee2000
2022-11-15 05:08:26 +00:00
|
|
|
ci_args = ["--import-slow-tests", "--import-disabled-tests"]
|
2023-03-31 18:36:53 +00:00
|
|
|
if RERUN_DISABLED_TESTS:
|
Add a mode to rerun all disabled tests (without running anything else) (#88646)
Rerun all disabled test to gather their latest result so that we can close disabled tickets automatically. When running under this mode (RERUN_DISABLED_TESTS=true), only disabled tests are run while the rest are skipped `<skipped message="Test is enabled but --rerun-disabled-tests verification mode is set, so only disabled tests are run" type="skip"/>`
The logic is roughly as follows, the test runs multiple times (n=50)
* If the disabled test passes, and it's flaky, do nothing because it's still flaky. In the test report, we'll see the test passes with the following skipped message:
```
<testcase classname="TestMultiprocessing" file="test_multiprocessing.py" line="357" name="test_fs" time="0.000" timestamp="0001-01-01T00:00:00">
<skipped message="{"flaky": True, "num_red": 4, "num_green": 0, "max_num_retries": 3, "rerun_disabled_test": true}" type="skip"/>
</testcase>
```
* If the disabled test passes every single time, and it is not flaky anymore, mark it so that it can be closed later. We will see the test runs and passes, i.e.
```
<testcase classname="TestCommonCUDA" name="test_out_warning_linalg_lu_factor_cuda" time="0.170" file="test_ops.py" />
```
* If the disabled test fails after all retries, this is also expected. So only report this but don't fail the job (because we don't care about red signals here), we'll see the test is skipped (without the `flaky` field), i.e.
```
<testcase classname="TestMultiprocessing" file="test_multiprocessing.py" line="357" name="test_fs" time="0.000" timestamp="0001-01-01T00:00:00">
<skipped message="{"num_red": 4, "num_green": 0, "max_num_retries": 3, "rerun_disabled_test": true}" type="skip"/>
</testcase>
```
This runs at the same schedule as `mem_leak_check` (daily). The change to update test stats, and (potentially) grouping on HUD will come in separated PRs.
### Testing
* pull https://github.com/pytorch/pytorch/actions/runs/3447434434
* trunk https://github.com/pytorch/pytorch/actions/runs/3447434928
Pull Request resolved: https://github.com/pytorch/pytorch/pull/88646
Approved by: https://github.com/clee2000
2022-11-15 05:08:26 +00:00
|
|
|
ci_args.append("--rerun-disabled-tests")
|
2021-07-12 18:20:12 +00:00
|
|
|
# use the downloaded test cases configuration, not supported in pytest
|
Add a mode to rerun all disabled tests (without running anything else) (#88646)
Rerun all disabled test to gather their latest result so that we can close disabled tickets automatically. When running under this mode (RERUN_DISABLED_TESTS=true), only disabled tests are run while the rest are skipped `<skipped message="Test is enabled but --rerun-disabled-tests verification mode is set, so only disabled tests are run" type="skip"/>`
The logic is roughly as follows, the test runs multiple times (n=50)
* If the disabled test passes, and it's flaky, do nothing because it's still flaky. In the test report, we'll see the test passes with the following skipped message:
```
<testcase classname="TestMultiprocessing" file="test_multiprocessing.py" line="357" name="test_fs" time="0.000" timestamp="0001-01-01T00:00:00">
<skipped message="{"flaky": True, "num_red": 4, "num_green": 0, "max_num_retries": 3, "rerun_disabled_test": true}" type="skip"/>
</testcase>
```
* If the disabled test passes every single time, and it is not flaky anymore, mark it so that it can be closed later. We will see the test runs and passes, i.e.
```
<testcase classname="TestCommonCUDA" name="test_out_warning_linalg_lu_factor_cuda" time="0.170" file="test_ops.py" />
```
* If the disabled test fails after all retries, this is also expected. So only report this but don't fail the job (because we don't care about red signals here), we'll see the test is skipped (without the `flaky` field), i.e.
```
<testcase classname="TestMultiprocessing" file="test_multiprocessing.py" line="357" name="test_fs" time="0.000" timestamp="0001-01-01T00:00:00">
<skipped message="{"num_red": 4, "num_green": 0, "max_num_retries": 3, "rerun_disabled_test": true}" type="skip"/>
</testcase>
```
This runs at the same schedule as `mem_leak_check` (daily). The change to update test stats, and (potentially) grouping on HUD will come in separated PRs.
### Testing
* pull https://github.com/pytorch/pytorch/actions/runs/3447434434
* trunk https://github.com/pytorch/pytorch/actions/runs/3447434928
Pull Request resolved: https://github.com/pytorch/pytorch/pull/88646
Approved by: https://github.com/clee2000
2022-11-15 05:08:26 +00:00
|
|
|
unittest_args.extend(ci_args)
|
Discover and run C++ tests with run_test.py (#99559)
This depends on [pytest-cpp](https://github.com/pytest-dev/pytest-cpp) to discover and run C++ tests with pytest. C++ tests are built under `${WORKSPACE}/build/bin` directory and copied to the test job under the same path.
* To expose them to `run_test`, I choose to use the mock path prefix `cpp`, for example `build/bin/c10_Array_test` would be named as `cpp/c10_Array_test` and the `python test/run_test.py --cpp -i cpp/c10_Array_test` would run the test in the same way as other Python tests. I could copy them from `build/bin` to `test/cpp`, but it will be mixed with the source code and CMake file. So this looks easier
* Some executable under `build/bin` are not C++ tests, and they are exclude, for example `build/bin/torch_shm_manager`
* C++ tests need to run with pytest directly as python command doesn't understand it
* The change is gated by the new `--cpp` argument to `run_test.py`, for example `python test/run_test.py --cpp` will run all available C++ tests
* The tests can be run in parallel
* Failing tests can be retried with `--reruns=2` and `--sw`
```
============================= test session starts ==============================
platform darwin -- Python 3.9.15, pytest-7.2.0, pluggy-1.0.0 -- /Users/huydo/miniconda3/envs/py3.9/bin/python3
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/Users/huydo/Storage/mine/pytorch/test/.hypothesis/examples')
rootdir: /Users/huydo/Storage/mine/pytorch, configfile: pytest.ini
plugins: xdoctest-1.1.0, cpp-2.3.0, rerunfailures-10.3, shard-0.1.2, flakefinder-1.1.0, hypothesis-6.56.4, xdist-3.0.2, repeat-0.9.1
collecting ... collected 3 items / 2 deselected / 1 selected
Running 1 items in this shard: build/bin/scalar_tensor_test::TestScalarTensor.TestScalarTensorMPS
stepwise: skipping 2 already passed items.
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS FAILED [100%]
```
* `--import-slow-tests` and `--import-disabled-tests` won't work for now and that's ok to have it as a future task.
I also add `pytest-cpp==2.3.0` to Linux Docker, MacOS, and Windows.
### Testing
Build PyTorch and run `python test/run_test.py --cpp` on my laptop. CI change would come later in a separate PR. Also running `python test/run_test.py --help` now shows all C++ test discovered under `build/bin`
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99559
Approved by: https://github.com/clee2000
2023-04-22 00:23:31 +00:00
|
|
|
|
2023-03-31 18:36:53 +00:00
|
|
|
if test_file in PYTEST_SKIP_RETRIES:
|
2023-03-15 22:12:00 +00:00
|
|
|
if not options.pytest:
|
2023-03-26 04:52:55 +00:00
|
|
|
raise RuntimeError(
|
|
|
|
|
"A test running without pytest cannot skip retries using "
|
|
|
|
|
"the PYTEST_SKIP_RETRIES set."
|
|
|
|
|
)
|
2023-03-15 22:12:00 +00:00
|
|
|
unittest_args = [arg for arg in unittest_args if "--reruns" not in arg]
|
2020-10-29 22:18:05 +00:00
|
|
|
|
2020-07-28 15:12:41 +00:00
|
|
|
# Extra arguments are not supported with pytest
|
Discover and run C++ tests with run_test.py (#99559)
This depends on [pytest-cpp](https://github.com/pytest-dev/pytest-cpp) to discover and run C++ tests with pytest. C++ tests are built under `${WORKSPACE}/build/bin` directory and copied to the test job under the same path.
* To expose them to `run_test`, I choose to use the mock path prefix `cpp`, for example `build/bin/c10_Array_test` would be named as `cpp/c10_Array_test` and the `python test/run_test.py --cpp -i cpp/c10_Array_test` would run the test in the same way as other Python tests. I could copy them from `build/bin` to `test/cpp`, but it will be mixed with the source code and CMake file. So this looks easier
* Some executable under `build/bin` are not C++ tests, and they are exclude, for example `build/bin/torch_shm_manager`
* C++ tests need to run with pytest directly as python command doesn't understand it
* The change is gated by the new `--cpp` argument to `run_test.py`, for example `python test/run_test.py --cpp` will run all available C++ tests
* The tests can be run in parallel
* Failing tests can be retried with `--reruns=2` and `--sw`
```
============================= test session starts ==============================
platform darwin -- Python 3.9.15, pytest-7.2.0, pluggy-1.0.0 -- /Users/huydo/miniconda3/envs/py3.9/bin/python3
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/Users/huydo/Storage/mine/pytorch/test/.hypothesis/examples')
rootdir: /Users/huydo/Storage/mine/pytorch, configfile: pytest.ini
plugins: xdoctest-1.1.0, cpp-2.3.0, rerunfailures-10.3, shard-0.1.2, flakefinder-1.1.0, hypothesis-6.56.4, xdist-3.0.2, repeat-0.9.1
collecting ... collected 3 items / 2 deselected / 1 selected
Running 1 items in this shard: build/bin/scalar_tensor_test::TestScalarTensor.TestScalarTensorMPS
stepwise: skipping 2 already passed items.
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS FAILED [100%]
```
* `--import-slow-tests` and `--import-disabled-tests` won't work for now and that's ok to have it as a future task.
I also add `pytest-cpp==2.3.0` to Linux Docker, MacOS, and Windows.
### Testing
Build PyTorch and run `python test/run_test.py --cpp` on my laptop. CI change would come later in a separate PR. Also running `python test/run_test.py --help` now shows all C++ test discovered under `build/bin`
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99559
Approved by: https://github.com/clee2000
2023-04-22 00:23:31 +00:00
|
|
|
executable = get_executable_command(options, is_cpp_test=is_cpp_test)
|
|
|
|
|
if not executable:
|
|
|
|
|
# If there is no eligible executable returning here, it means an unsupported
|
|
|
|
|
# case such as coverage for C++ test. So just returning ok makes sense
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
if test_file.startswith(CPP_TEST_PREFIX):
|
Run C++ tests on CI with run_test.py (#99956)
After https://github.com/pytorch/pytorch/pull/99559, we can now run C++ test with `run_test.py`. Although advance features such as `--import-slow-tests` and `--import-disabled-tests` won't work for now, there will still be a gain in reliability and performance as C++ can now be retried and run in parallel.
This covers all C++ tests in the CI including aten, libtorch, and Vulkan C++ tests across all platforms Linux, Windows, MacOS.
Notes:
* To support C++ test discovery, the env variable `CPP_TESTS_DIR` can be set to where the C++ test binaries is located
* Support pytest -k argument via run_test as this is used by pytest-cpp to replace `--gtest-filter`
* The XML output is in pytest format, but it's ok now because we don't have slow test or flaky test support for C++ test yet
* ~~I need to figure out why conftest.py doesn't work when I invoke pytest directly for C++ test, so `--sc` is not available for C++ tests at the moment. Proper pytest plugin like stepwise works fine though. I'll investigate and fix it in a separate PR~~ Found the cause, `conftest.py` is per directory and needs to be in any arbitrary directory that holds C++ test
* Two tests `test_api` and `test_tensorexpr` timed out on ASAN, I suspect that ASAN is now used on top of the python executable, which is slower than running native C++ code. IMO, it's ok to run these tests as before on ASAN for now
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99956
Approved by: https://github.com/clee2000, https://github.com/ZainRizvi
2023-05-09 21:24:12 +00:00
|
|
|
# C++ tests are not the regular test directory
|
|
|
|
|
if CPP_TESTS_DIR:
|
|
|
|
|
cpp_test = os.path.join(
|
|
|
|
|
CPP_TESTS_DIR,
|
|
|
|
|
test_file.replace(f"{CPP_TEST_PREFIX}/", ""),
|
|
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
cpp_test = os.path.join(
|
2024-06-29 23:28:38 +00:00
|
|
|
Path(test_directory).parent,
|
Discover and run C++ tests with run_test.py (#99559)
This depends on [pytest-cpp](https://github.com/pytest-dev/pytest-cpp) to discover and run C++ tests with pytest. C++ tests are built under `${WORKSPACE}/build/bin` directory and copied to the test job under the same path.
* To expose them to `run_test`, I choose to use the mock path prefix `cpp`, for example `build/bin/c10_Array_test` would be named as `cpp/c10_Array_test` and the `python test/run_test.py --cpp -i cpp/c10_Array_test` would run the test in the same way as other Python tests. I could copy them from `build/bin` to `test/cpp`, but it will be mixed with the source code and CMake file. So this looks easier
* Some executable under `build/bin` are not C++ tests, and they are exclude, for example `build/bin/torch_shm_manager`
* C++ tests need to run with pytest directly as python command doesn't understand it
* The change is gated by the new `--cpp` argument to `run_test.py`, for example `python test/run_test.py --cpp` will run all available C++ tests
* The tests can be run in parallel
* Failing tests can be retried with `--reruns=2` and `--sw`
```
============================= test session starts ==============================
platform darwin -- Python 3.9.15, pytest-7.2.0, pluggy-1.0.0 -- /Users/huydo/miniconda3/envs/py3.9/bin/python3
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/Users/huydo/Storage/mine/pytorch/test/.hypothesis/examples')
rootdir: /Users/huydo/Storage/mine/pytorch, configfile: pytest.ini
plugins: xdoctest-1.1.0, cpp-2.3.0, rerunfailures-10.3, shard-0.1.2, flakefinder-1.1.0, hypothesis-6.56.4, xdist-3.0.2, repeat-0.9.1
collecting ... collected 3 items / 2 deselected / 1 selected
Running 1 items in this shard: build/bin/scalar_tensor_test::TestScalarTensor.TestScalarTensorMPS
stepwise: skipping 2 already passed items.
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS FAILED [100%]
```
* `--import-slow-tests` and `--import-disabled-tests` won't work for now and that's ok to have it as a future task.
I also add `pytest-cpp==2.3.0` to Linux Docker, MacOS, and Windows.
### Testing
Build PyTorch and run `python test/run_test.py --cpp` on my laptop. CI change would come later in a separate PR. Also running `python test/run_test.py --help` now shows all C++ test discovered under `build/bin`
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99559
Approved by: https://github.com/clee2000
2023-04-22 00:23:31 +00:00
|
|
|
CPP_TEST_PATH,
|
|
|
|
|
test_file.replace(f"{CPP_TEST_PREFIX}/", ""),
|
|
|
|
|
)
|
Run C++ tests on CI with run_test.py (#99956)
After https://github.com/pytorch/pytorch/pull/99559, we can now run C++ test with `run_test.py`. Although advance features such as `--import-slow-tests` and `--import-disabled-tests` won't work for now, there will still be a gain in reliability and performance as C++ can now be retried and run in parallel.
This covers all C++ tests in the CI including aten, libtorch, and Vulkan C++ tests across all platforms Linux, Windows, MacOS.
Notes:
* To support C++ test discovery, the env variable `CPP_TESTS_DIR` can be set to where the C++ test binaries is located
* Support pytest -k argument via run_test as this is used by pytest-cpp to replace `--gtest-filter`
* The XML output is in pytest format, but it's ok now because we don't have slow test or flaky test support for C++ test yet
* ~~I need to figure out why conftest.py doesn't work when I invoke pytest directly for C++ test, so `--sc` is not available for C++ tests at the moment. Proper pytest plugin like stepwise works fine though. I'll investigate and fix it in a separate PR~~ Found the cause, `conftest.py` is per directory and needs to be in any arbitrary directory that holds C++ test
* Two tests `test_api` and `test_tensorexpr` timed out on ASAN, I suspect that ASAN is now used on top of the python executable, which is slower than running native C++ code. IMO, it's ok to run these tests as before on ASAN for now
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99956
Approved by: https://github.com/clee2000, https://github.com/ZainRizvi
2023-05-09 21:24:12 +00:00
|
|
|
|
|
|
|
|
argv = [
|
|
|
|
|
cpp_test if sys.platform != "win32" else cpp_test + ".exe"
|
Discover and run C++ tests with run_test.py (#99559)
This depends on [pytest-cpp](https://github.com/pytest-dev/pytest-cpp) to discover and run C++ tests with pytest. C++ tests are built under `${WORKSPACE}/build/bin` directory and copied to the test job under the same path.
* To expose them to `run_test`, I choose to use the mock path prefix `cpp`, for example `build/bin/c10_Array_test` would be named as `cpp/c10_Array_test` and the `python test/run_test.py --cpp -i cpp/c10_Array_test` would run the test in the same way as other Python tests. I could copy them from `build/bin` to `test/cpp`, but it will be mixed with the source code and CMake file. So this looks easier
* Some executable under `build/bin` are not C++ tests, and they are exclude, for example `build/bin/torch_shm_manager`
* C++ tests need to run with pytest directly as python command doesn't understand it
* The change is gated by the new `--cpp` argument to `run_test.py`, for example `python test/run_test.py --cpp` will run all available C++ tests
* The tests can be run in parallel
* Failing tests can be retried with `--reruns=2` and `--sw`
```
============================= test session starts ==============================
platform darwin -- Python 3.9.15, pytest-7.2.0, pluggy-1.0.0 -- /Users/huydo/miniconda3/envs/py3.9/bin/python3
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/Users/huydo/Storage/mine/pytorch/test/.hypothesis/examples')
rootdir: /Users/huydo/Storage/mine/pytorch, configfile: pytest.ini
plugins: xdoctest-1.1.0, cpp-2.3.0, rerunfailures-10.3, shard-0.1.2, flakefinder-1.1.0, hypothesis-6.56.4, xdist-3.0.2, repeat-0.9.1
collecting ... collected 3 items / 2 deselected / 1 selected
Running 1 items in this shard: build/bin/scalar_tensor_test::TestScalarTensor.TestScalarTensorMPS
stepwise: skipping 2 already passed items.
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS FAILED [100%]
```
* `--import-slow-tests` and `--import-disabled-tests` won't work for now and that's ok to have it as a future task.
I also add `pytest-cpp==2.3.0` to Linux Docker, MacOS, and Windows.
### Testing
Build PyTorch and run `python test/run_test.py --cpp` on my laptop. CI change would come later in a separate PR. Also running `python test/run_test.py --help` now shows all C++ test discovered under `build/bin`
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99559
Approved by: https://github.com/clee2000
2023-04-22 00:23:31 +00:00
|
|
|
] + unittest_args
|
|
|
|
|
else:
|
|
|
|
|
# Can't call `python -m unittest test_*` here because it doesn't run code
|
|
|
|
|
# in `if __name__ == '__main__': `. So call `python test_*.py` instead.
|
|
|
|
|
argv = [test_file + ".py"] + unittest_args
|
2021-06-08 22:59:32 +00:00
|
|
|
|
2022-09-23 20:45:20 +00:00
|
|
|
os.makedirs(REPO_ROOT / "test" / "test-reports", exist_ok=True)
|
2024-01-26 00:17:29 +00:00
|
|
|
if options.pipe_logs:
|
2023-10-05 16:40:37 +00:00
|
|
|
log_fd, log_path = tempfile.mkstemp(
|
|
|
|
|
dir=REPO_ROOT / "test" / "test-reports",
|
|
|
|
|
prefix=f"{sanitize_file_name(str(test_module))}_",
|
|
|
|
|
suffix="_toprint.log",
|
|
|
|
|
)
|
|
|
|
|
os.close(log_fd)
|
Discover and run C++ tests with run_test.py (#99559)
This depends on [pytest-cpp](https://github.com/pytest-dev/pytest-cpp) to discover and run C++ tests with pytest. C++ tests are built under `${WORKSPACE}/build/bin` directory and copied to the test job under the same path.
* To expose them to `run_test`, I choose to use the mock path prefix `cpp`, for example `build/bin/c10_Array_test` would be named as `cpp/c10_Array_test` and the `python test/run_test.py --cpp -i cpp/c10_Array_test` would run the test in the same way as other Python tests. I could copy them from `build/bin` to `test/cpp`, but it will be mixed with the source code and CMake file. So this looks easier
* Some executable under `build/bin` are not C++ tests, and they are exclude, for example `build/bin/torch_shm_manager`
* C++ tests need to run with pytest directly as python command doesn't understand it
* The change is gated by the new `--cpp` argument to `run_test.py`, for example `python test/run_test.py --cpp` will run all available C++ tests
* The tests can be run in parallel
* Failing tests can be retried with `--reruns=2` and `--sw`
```
============================= test session starts ==============================
platform darwin -- Python 3.9.15, pytest-7.2.0, pluggy-1.0.0 -- /Users/huydo/miniconda3/envs/py3.9/bin/python3
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/Users/huydo/Storage/mine/pytorch/test/.hypothesis/examples')
rootdir: /Users/huydo/Storage/mine/pytorch, configfile: pytest.ini
plugins: xdoctest-1.1.0, cpp-2.3.0, rerunfailures-10.3, shard-0.1.2, flakefinder-1.1.0, hypothesis-6.56.4, xdist-3.0.2, repeat-0.9.1
collecting ... collected 3 items / 2 deselected / 1 selected
Running 1 items in this shard: build/bin/scalar_tensor_test::TestScalarTensor.TestScalarTensorMPS
stepwise: skipping 2 already passed items.
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS FAILED [100%]
```
* `--import-slow-tests` and `--import-disabled-tests` won't work for now and that's ok to have it as a future task.
I also add `pytest-cpp==2.3.0` to Linux Docker, MacOS, and Windows.
### Testing
Build PyTorch and run `python test/run_test.py --cpp` on my laptop. CI change would come later in a separate PR. Also running `python test/run_test.py --help` now shows all C++ test discovered under `build/bin`
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99559
Approved by: https://github.com/clee2000
2023-04-22 00:23:31 +00:00
|
|
|
|
2020-07-28 15:12:41 +00:00
|
|
|
command = (launcher_cmd or []) + executable + argv
|
2024-04-24 19:44:51 +00:00
|
|
|
should_retry = (
|
|
|
|
|
"--subprocess" not in command
|
|
|
|
|
and not RERUN_DISABLED_TESTS
|
|
|
|
|
and not is_cpp_test
|
|
|
|
|
and "-n" not in command
|
|
|
|
|
)
|
2023-05-01 21:51:53 +00:00
|
|
|
timeout = (
|
2024-01-26 00:17:29 +00:00
|
|
|
None
|
|
|
|
|
if not options.enable_timeout
|
|
|
|
|
else THRESHOLD * 6
|
2024-05-14 17:35:12 +00:00
|
|
|
if IS_SLOW
|
2023-09-26 16:18:38 +00:00
|
|
|
else THRESHOLD * 3
|
2024-01-23 18:39:30 +00:00
|
|
|
if should_retry
|
2023-05-01 21:51:53 +00:00
|
|
|
and isinstance(test_module, ShardedTest)
|
|
|
|
|
and test_module.time is not None
|
Set timeout for C++ tests (#125517)
Looking at the unrelated Windows timeout failure on https://github.com/pytorch/pytorch/pull/125199, it looks like we don't have a timeout value set for C++ tests atm. In this case, a C++ test on Windows timed out after 2+ hours.
```
2024-05-02T23:35:34.0639067Z Running cpp/c10_TypeList_test 1/1 ... [2024-05-02 23:35:34.059021]
2024-05-02T23:35:34.0641108Z Executing ['pytest', 'C:\\actions-runner\\_work\\pytorch\\pytorch\\build\\win_tmp\\build\\torch\\test\\c10_TypeList_test.exe', '-m', 'not serial', '-v', '-vv', '-rfEX', '-n', '2', '--junit-xml-reruns', 'test-reports\\python-pytest\\test\\run_test\\test\\run_test-c898ddeff8f33cbf.xml', '-x', '--reruns=2'] ... [2024-05-02 23:35:34.062137]
2024-05-03T02:45:33.7862004Z Process SpawnPoolWorker-2:
2024-05-03T02:45:33.7927201Z Traceback (most recent call last):
2024-05-03T02:45:33.7928032Z File "C:\Jenkins\Miniconda3\lib\multiprocessing\process.py", line 315, in _bootstrap
2024-05-03T02:45:33.7928722Z self.run()
2024-05-03T02:45:33.7929722Z File "C:\Jenkins\Miniconda3\lib\multiprocessing\process.py", line 108, in run
2024-05-03T02:45:33.7931639Z self._target(*self._args, **self._kwargs)
2024-05-03T02:45:33.7932435Z File "C:\Jenkins\Miniconda3\lib\multiprocessing\pool.py", line 114, in worker
2024-05-03T02:45:33.7933338Z task = get()
2024-05-03T02:45:33.7933946Z File "C:\Jenkins\Miniconda3\lib\multiprocessing\queues.py", line 365, in get
2024-05-03T02:45:33.7935219Z res = self._reader.recv_bytes()
2024-05-03T02:45:33.7935897Z File "C:\Jenkins\Miniconda3\lib\multiprocessing\connection.py", line 221, in recv_bytes
2024-05-03T02:45:33.7936609Z buf = self._recv_bytes(maxlength)
2024-05-03T02:45:33.7937302Z File "C:\Jenkins\Miniconda3\lib\multiprocessing\connection.py", line 310, in _recv_bytes
2024-05-03T02:45:33.7938316Z waitres = _winapi.WaitForMultipleObjects(
2024-05-03T02:45:33.7938766Z KeyboardInterrupt
```
Retrying was working, but it was already too late to finish the job. I'm setting the same default `THRESHOLD * 3` timeout value here for C++ tests.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/125517
Approved by: https://github.com/clee2000
2024-05-07 16:41:38 +00:00
|
|
|
else THRESHOLD * 3
|
|
|
|
|
if is_cpp_test
|
2023-05-01 21:51:53 +00:00
|
|
|
else None
|
|
|
|
|
)
|
2023-06-24 03:10:46 +00:00
|
|
|
print_to_stderr(f"Executing {command} ... [{datetime.now()}]")
|
Discover and run C++ tests with run_test.py (#99559)
This depends on [pytest-cpp](https://github.com/pytest-dev/pytest-cpp) to discover and run C++ tests with pytest. C++ tests are built under `${WORKSPACE}/build/bin` directory and copied to the test job under the same path.
* To expose them to `run_test`, I choose to use the mock path prefix `cpp`, for example `build/bin/c10_Array_test` would be named as `cpp/c10_Array_test` and the `python test/run_test.py --cpp -i cpp/c10_Array_test` would run the test in the same way as other Python tests. I could copy them from `build/bin` to `test/cpp`, but it will be mixed with the source code and CMake file. So this looks easier
* Some executable under `build/bin` are not C++ tests, and they are exclude, for example `build/bin/torch_shm_manager`
* C++ tests need to run with pytest directly as python command doesn't understand it
* The change is gated by the new `--cpp` argument to `run_test.py`, for example `python test/run_test.py --cpp` will run all available C++ tests
* The tests can be run in parallel
* Failing tests can be retried with `--reruns=2` and `--sw`
```
============================= test session starts ==============================
platform darwin -- Python 3.9.15, pytest-7.2.0, pluggy-1.0.0 -- /Users/huydo/miniconda3/envs/py3.9/bin/python3
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/Users/huydo/Storage/mine/pytorch/test/.hypothesis/examples')
rootdir: /Users/huydo/Storage/mine/pytorch, configfile: pytest.ini
plugins: xdoctest-1.1.0, cpp-2.3.0, rerunfailures-10.3, shard-0.1.2, flakefinder-1.1.0, hypothesis-6.56.4, xdist-3.0.2, repeat-0.9.1
collecting ... collected 3 items / 2 deselected / 1 selected
Running 1 items in this shard: build/bin/scalar_tensor_test::TestScalarTensor.TestScalarTensorMPS
stepwise: skipping 2 already passed items.
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS FAILED [100%]
```
* `--import-slow-tests` and `--import-disabled-tests` won't work for now and that's ok to have it as a future task.
I also add `pytest-cpp==2.3.0` to Linux Docker, MacOS, and Windows.
### Testing
Build PyTorch and run `python test/run_test.py --cpp` on my laptop. CI change would come later in a separate PR. Also running `python test/run_test.py --help` now shows all C++ test discovered under `build/bin`
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99559
Approved by: https://github.com/clee2000
2023-04-22 00:23:31 +00:00
|
|
|
|
2023-10-05 16:40:37 +00:00
|
|
|
with ExitStack() as stack:
|
|
|
|
|
output = None
|
2024-01-26 00:17:29 +00:00
|
|
|
if options.pipe_logs:
|
2023-10-05 16:40:37 +00:00
|
|
|
output = stack.enter_context(open(log_path, "w"))
|
2023-11-30 04:01:57 +00:00
|
|
|
|
2024-01-23 18:39:30 +00:00
|
|
|
if should_retry:
|
|
|
|
|
ret_code, was_rerun = run_test_retries(
|
|
|
|
|
command,
|
|
|
|
|
test_directory,
|
|
|
|
|
env,
|
|
|
|
|
timeout,
|
|
|
|
|
stepcurrent_key,
|
|
|
|
|
output,
|
|
|
|
|
options.continue_through_error,
|
2023-11-30 04:01:57 +00:00
|
|
|
)
|
|
|
|
|
else:
|
2024-01-23 18:39:30 +00:00
|
|
|
command.extend([f"--sc={stepcurrent_key}", "--print-items"])
|
2023-11-30 04:01:57 +00:00
|
|
|
ret_code, was_rerun = retry_shell(
|
|
|
|
|
command,
|
|
|
|
|
test_directory,
|
|
|
|
|
stdout=output,
|
|
|
|
|
stderr=output,
|
|
|
|
|
env=env,
|
|
|
|
|
timeout=timeout,
|
2024-05-07 16:20:00 +00:00
|
|
|
retries=0,
|
2023-11-30 04:01:57 +00:00
|
|
|
)
|
|
|
|
|
|
2024-03-29 22:41:41 +00:00
|
|
|
# Pytest return code 5 means no test is collected. Exit code 4 is
|
|
|
|
|
# returned when the binary is not a C++ test executable, but 4 can
|
|
|
|
|
# also be returned if the file fails before running any tests. All
|
|
|
|
|
# binary files under build/bin that are not C++ test at the time of
|
|
|
|
|
# this writing have been excluded and new ones should be added to
|
|
|
|
|
# the list of exclusions in tools/testing/discover_tests.py
|
|
|
|
|
ret_code = 0 if ret_code == 5 else ret_code
|
2023-11-30 04:01:57 +00:00
|
|
|
|
2024-03-11 15:35:45 +00:00
|
|
|
if options.pipe_logs and print_log:
|
2023-11-30 04:01:57 +00:00
|
|
|
handle_log_file(
|
|
|
|
|
test_module, log_path, failed=(ret_code != 0), was_rerun=was_rerun
|
|
|
|
|
)
|
|
|
|
|
return ret_code
|
|
|
|
|
|
|
|
|
|
|
2025-01-14 15:59:00 +00:00
|
|
|
def install_cpp_extensions(cpp_extensions_test_dir, env=os.environ):
|
|
|
|
|
# Wipe the build folder, if it exists already
|
|
|
|
|
cpp_extensions_test_build_dir = os.path.join(cpp_extensions_test_dir, "build")
|
|
|
|
|
if os.path.exists(cpp_extensions_test_build_dir):
|
|
|
|
|
shutil.rmtree(cpp_extensions_test_build_dir)
|
|
|
|
|
|
|
|
|
|
# Build the test cpp extensions modules
|
|
|
|
|
cmd = [sys.executable, "setup.py", "install", "--root", "./install"]
|
|
|
|
|
return_code = shell(cmd, cwd=cpp_extensions_test_dir, env=env)
|
|
|
|
|
if return_code != 0:
|
|
|
|
|
return None, return_code
|
|
|
|
|
|
|
|
|
|
install_directory = ""
|
|
|
|
|
# install directory is the one that is named site-packages
|
|
|
|
|
for root, directories, _ in os.walk(
|
|
|
|
|
os.path.join(cpp_extensions_test_dir, "install")
|
|
|
|
|
):
|
|
|
|
|
for directory in directories:
|
|
|
|
|
if "-packages" in directory:
|
|
|
|
|
install_directory = os.path.join(root, directory)
|
|
|
|
|
|
|
|
|
|
assert install_directory, "install_directory must not be empty"
|
|
|
|
|
return install_directory, 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@contextlib.contextmanager
|
|
|
|
|
def extend_python_path(install_directory):
|
|
|
|
|
python_path = os.environ.get("PYTHONPATH", "")
|
|
|
|
|
try:
|
|
|
|
|
os.environ["PYTHONPATH"] = os.pathsep.join([install_directory, python_path])
|
|
|
|
|
yield
|
|
|
|
|
finally:
|
|
|
|
|
os.environ["PYTHONPATH"] = python_path
|
|
|
|
|
|
|
|
|
|
|
2024-07-03 01:50:15 +00:00
|
|
|
def try_set_cpp_stack_traces(env, command, set=True):
|
|
|
|
|
# Print full c++ stack traces during retries
|
2024-08-26 21:02:29 +00:00
|
|
|
env = env or {}
|
|
|
|
|
env["TORCH_SHOW_CPP_STACKTRACES"] = "1" if set else "0"
|
2024-07-03 01:50:15 +00:00
|
|
|
return env
|
|
|
|
|
|
|
|
|
|
|
2024-01-23 18:39:30 +00:00
|
|
|
def run_test_retries(
|
|
|
|
|
command,
|
|
|
|
|
test_directory,
|
|
|
|
|
env,
|
|
|
|
|
timeout,
|
|
|
|
|
stepcurrent_key,
|
|
|
|
|
output,
|
|
|
|
|
continue_through_error,
|
2023-11-30 04:01:57 +00:00
|
|
|
):
|
2024-07-03 01:50:15 +00:00
|
|
|
# Run the test with -x to stop at first failure. Rerun the test by itself.
|
|
|
|
|
# If it succeeds, move on to the rest of the tests in a new process. If it
|
|
|
|
|
# still fails, see below
|
2024-01-23 18:39:30 +00:00
|
|
|
#
|
|
|
|
|
# If continue through error is not set, then we fail fast.
|
|
|
|
|
#
|
|
|
|
|
# If continue through error is set, then we skip that test, and keep going.
|
|
|
|
|
# Basically if the same test fails 3 times in a row, skip the test on the
|
|
|
|
|
# next run, but still fail in the end. I take advantage of the value saved
|
|
|
|
|
# in stepcurrent to keep track of the most recently run test (which is the
|
|
|
|
|
# one that failed if there was a failure).
|
|
|
|
|
|
|
|
|
|
def print_to_file(s):
|
|
|
|
|
print(s, file=output, flush=True)
|
2023-11-30 04:01:57 +00:00
|
|
|
|
|
|
|
|
num_failures = defaultdict(int)
|
|
|
|
|
|
2024-01-23 18:39:30 +00:00
|
|
|
print_items = ["--print-items"]
|
2023-11-30 04:01:57 +00:00
|
|
|
sc_command = f"--sc={stepcurrent_key}"
|
|
|
|
|
while True:
|
2024-01-23 18:39:30 +00:00
|
|
|
ret_code, _ = retry_shell(
|
|
|
|
|
command + [sc_command] + print_items,
|
2023-03-31 18:36:53 +00:00
|
|
|
test_directory,
|
2023-10-05 16:40:37 +00:00
|
|
|
stdout=output,
|
|
|
|
|
stderr=output,
|
2023-03-31 18:36:53 +00:00
|
|
|
env=env,
|
|
|
|
|
timeout=timeout,
|
2024-01-23 18:39:30 +00:00
|
|
|
retries=0, # no retries here, we do it ourselves, this is because it handles timeout exceptions well
|
2023-03-31 18:36:53 +00:00
|
|
|
)
|
2024-03-29 22:41:41 +00:00
|
|
|
ret_code = 0 if ret_code == 5 else ret_code
|
2024-07-03 01:50:15 +00:00
|
|
|
if ret_code == 0 and not sc_command.startswith("--rs="):
|
2023-11-30 04:01:57 +00:00
|
|
|
break # Got to the end of the test suite successfully
|
|
|
|
|
signal_name = f" ({SIGNALS_TO_NAMES_DICT[-ret_code]})" if ret_code < 0 else ""
|
2024-01-23 18:39:30 +00:00
|
|
|
print_to_file(f"Got exit code {ret_code}{signal_name}")
|
Discover and run C++ tests with run_test.py (#99559)
This depends on [pytest-cpp](https://github.com/pytest-dev/pytest-cpp) to discover and run C++ tests with pytest. C++ tests are built under `${WORKSPACE}/build/bin` directory and copied to the test job under the same path.
* To expose them to `run_test`, I choose to use the mock path prefix `cpp`, for example `build/bin/c10_Array_test` would be named as `cpp/c10_Array_test` and the `python test/run_test.py --cpp -i cpp/c10_Array_test` would run the test in the same way as other Python tests. I could copy them from `build/bin` to `test/cpp`, but it will be mixed with the source code and CMake file. So this looks easier
* Some executable under `build/bin` are not C++ tests, and they are exclude, for example `build/bin/torch_shm_manager`
* C++ tests need to run with pytest directly as python command doesn't understand it
* The change is gated by the new `--cpp` argument to `run_test.py`, for example `python test/run_test.py --cpp` will run all available C++ tests
* The tests can be run in parallel
* Failing tests can be retried with `--reruns=2` and `--sw`
```
============================= test session starts ==============================
platform darwin -- Python 3.9.15, pytest-7.2.0, pluggy-1.0.0 -- /Users/huydo/miniconda3/envs/py3.9/bin/python3
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/Users/huydo/Storage/mine/pytorch/test/.hypothesis/examples')
rootdir: /Users/huydo/Storage/mine/pytorch, configfile: pytest.ini
plugins: xdoctest-1.1.0, cpp-2.3.0, rerunfailures-10.3, shard-0.1.2, flakefinder-1.1.0, hypothesis-6.56.4, xdist-3.0.2, repeat-0.9.1
collecting ... collected 3 items / 2 deselected / 1 selected
Running 1 items in this shard: build/bin/scalar_tensor_test::TestScalarTensor.TestScalarTensorMPS
stepwise: skipping 2 already passed items.
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS FAILED [100%]
```
* `--import-slow-tests` and `--import-disabled-tests` won't work for now and that's ok to have it as a future task.
I also add `pytest-cpp==2.3.0` to Linux Docker, MacOS, and Windows.
### Testing
Build PyTorch and run `python test/run_test.py --cpp` on my laptop. CI change would come later in a separate PR. Also running `python test/run_test.py --help` now shows all C++ test discovered under `build/bin`
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99559
Approved by: https://github.com/clee2000
2023-04-22 00:23:31 +00:00
|
|
|
|
2024-07-03 01:50:15 +00:00
|
|
|
# Read what just failed/ran
|
2024-02-02 03:07:52 +00:00
|
|
|
try:
|
|
|
|
|
with open(
|
|
|
|
|
REPO_ROOT / ".pytest_cache/v/cache/stepcurrent" / stepcurrent_key
|
|
|
|
|
) as f:
|
|
|
|
|
current_failure = f.read()
|
|
|
|
|
except FileNotFoundError:
|
|
|
|
|
print_to_file(
|
|
|
|
|
"No stepcurrent file found. Either pytest didn't get to run (e.g. import error)"
|
|
|
|
|
+ " or file got deleted (contact dev infra)"
|
|
|
|
|
)
|
|
|
|
|
break
|
2023-11-30 04:01:57 +00:00
|
|
|
|
2024-07-03 01:50:15 +00:00
|
|
|
env = try_set_cpp_stack_traces(env, command, set=False)
|
|
|
|
|
if ret_code != 0:
|
|
|
|
|
num_failures[current_failure] += 1
|
|
|
|
|
|
|
|
|
|
if ret_code == 0:
|
|
|
|
|
# Rerunning the previously failing test succeeded, so now we can
|
|
|
|
|
# skip it and move on
|
|
|
|
|
sc_command = f"--scs={stepcurrent_key}"
|
|
|
|
|
print_to_file(
|
|
|
|
|
"Test succeeeded in new process, continuing with the rest of the tests"
|
|
|
|
|
)
|
|
|
|
|
elif num_failures[current_failure] >= 3:
|
2024-01-23 18:39:30 +00:00
|
|
|
if not continue_through_error:
|
|
|
|
|
print_to_file("Stopping at first consistent failure")
|
|
|
|
|
break
|
2023-11-30 04:01:57 +00:00
|
|
|
sc_command = f"--scs={stepcurrent_key}"
|
2024-07-03 01:50:15 +00:00
|
|
|
print_to_file(
|
|
|
|
|
"Test failed consistently, "
|
|
|
|
|
"continuing with the rest of the tests due to continue-through-error being set"
|
|
|
|
|
)
|
2023-11-30 04:01:57 +00:00
|
|
|
else:
|
2024-07-03 01:50:15 +00:00
|
|
|
env = try_set_cpp_stack_traces(env, command, set=True)
|
|
|
|
|
sc_command = f"--rs={stepcurrent_key}"
|
|
|
|
|
print_to_file("Retrying single test...")
|
2024-01-23 18:39:30 +00:00
|
|
|
print_items = [] # do not continue printing them, massive waste of space
|
2023-11-30 04:01:57 +00:00
|
|
|
|
|
|
|
|
consistent_failures = [x[1:-1] for x in num_failures.keys() if num_failures[x] >= 3]
|
|
|
|
|
flaky_failures = [x[1:-1] for x in num_failures.keys() if 0 < num_failures[x] < 3]
|
|
|
|
|
if len(flaky_failures) > 0:
|
2024-01-23 18:39:30 +00:00
|
|
|
print_to_file(
|
|
|
|
|
"The following tests failed and then succeeded when run in a new process"
|
|
|
|
|
+ f"{flaky_failures}",
|
2023-10-05 16:40:37 +00:00
|
|
|
)
|
2023-11-30 04:01:57 +00:00
|
|
|
if len(consistent_failures) > 0:
|
2024-01-23 18:39:30 +00:00
|
|
|
print_to_file(f"The following tests failed consistently: {consistent_failures}")
|
2023-11-30 04:01:57 +00:00
|
|
|
return 1, True
|
2024-02-02 03:07:52 +00:00
|
|
|
return ret_code, any(x > 0 for x in num_failures.values())
|
2018-03-09 21:02:02 +00:00
|
|
|
|
|
|
|
|
|
2023-03-31 06:31:17 +00:00
|
|
|
def run_test_with_subprocess(test_module, test_directory, options):
|
2021-08-12 18:39:31 +00:00
|
|
|
return run_test(
|
|
|
|
|
test_module, test_directory, options, extra_unittest_args=["--subprocess"]
|
|
|
|
|
)
|
2019-07-16 17:05:53 +00:00
|
|
|
|
2022-07-28 16:35:01 +00:00
|
|
|
|
2021-06-24 16:19:16 +00:00
|
|
|
def _test_cpp_extensions_aot(test_directory, options, use_ninja):
|
Add option to use ninja to compile ahead-of-time cpp_extensions (#32495)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/32495
Background
------------------------------
Previously, ninja was used to compile+link inline cpp_extensions and
ahead-of-time cpp_extensions were compiled with distutils. This PR adds
the ability to compile (but not link) ahead-of-time cpp_extensions with ninja.
The main motivation for this is to speed up cpp_extension builds: distutils
does not make use of parallelism. With this PR, using the new option, on my machine,
- torchvision compilation goes from 3m43s to 49s
- nestedtensor compilation goes from 2m0s to 28s.
User-facing changes
------------------------------
I added a `use_ninja` flag to BuildExtension. This defaults to
`True`. When `use_ninja` is True:
- it will attempt to use ninja.
- If we cannot use ninja, then this throws a warning and falls back to
distutils.
- Situations we cannot use ninja: Windows (NYI, I'll open a new issue
for this), if ninja cannot be found on the system.
Implementation Details
------------------------------
This PR makes this change in two steps. Please me know if it would be
easier to review this if I split this up into a stacked diff.
Those changes are:
1) refactor _write_ninja_file to separate the policy (what compiler flags
to pass) from the mechanism (how to write the ninja file and do compilation).
2) call _write_ninja_file and _run_ninja_build while building
ahead-of-time cpp_extensions. These are only used to compile objects;
distutils still handles the linking.
Change 1: refactor _write_ninja_file to seperate policy from mechanism
- I split _write_ninja_file into: _write_ninja_file and
_write_ninja_file_to_build_library
- I renamed _build_extension_module to _run_ninja_build
Change 2: Call _write_ninja_file while building ahead-of-time
cpp_extensions
- _write_ninja_file_and_compile_objects calls _write_ninja_file to only
build object files.
- We monkey-patch distutils.CCompiler.compile to call
_write_ninja_files_and_compile_objects
- distutils still handles the linking step. The linking step is not a
bottleneck so it was not a concern.
- This change only works on unix-based systems. Our code for windows
goes down a different codepath and I did not want to mess with that.
- If a system does not support ninja, we raise a warning and fall back
to the original compilation path.
Test Plan
------------------------------
Adhoc testing
- I built torchvision using pytorch master and printed out the build
commands. Next, I used this branch to build torchvision and looked at
the ninja file. I compared the ninja file with the build commands and
asserted that they were functionally the same.
- I repeated the above for pytorch/nestedtensor.
PyTorch test suite
- I split `test_cpp_extensions` into `test_cpp_extensions_aot` and
`test_cpp_extensions_jit`. The AOT (ahead-of-time) version tests
ahead-of-time and the JIT version tests just-in-time (not to be confused
with TorchScript)
- `test_cpp_extensions_aot` gets run TWICE by run_test.py, once with
a module that was built with ninja, and once with a module that was
built without ninja.
- run_test.py asserts that when we are building with use_ninja=True,
ninja is actually available on the system.
Test Plan: Imported from OSS
Differential Revision: D19730432
Pulled By: zou3519
fbshipit-source-id: 819590d01cf65e8da5a1e8019b8b3084792fee90
2020-02-06 02:44:19 +00:00
|
|
|
if use_ninja:
|
|
|
|
|
try:
|
2023-10-03 01:22:44 +00:00
|
|
|
from torch.utils import cpp_extension
|
|
|
|
|
|
Add option to use ninja to compile ahead-of-time cpp_extensions (#32495)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/32495
Background
------------------------------
Previously, ninja was used to compile+link inline cpp_extensions and
ahead-of-time cpp_extensions were compiled with distutils. This PR adds
the ability to compile (but not link) ahead-of-time cpp_extensions with ninja.
The main motivation for this is to speed up cpp_extension builds: distutils
does not make use of parallelism. With this PR, using the new option, on my machine,
- torchvision compilation goes from 3m43s to 49s
- nestedtensor compilation goes from 2m0s to 28s.
User-facing changes
------------------------------
I added a `use_ninja` flag to BuildExtension. This defaults to
`True`. When `use_ninja` is True:
- it will attempt to use ninja.
- If we cannot use ninja, then this throws a warning and falls back to
distutils.
- Situations we cannot use ninja: Windows (NYI, I'll open a new issue
for this), if ninja cannot be found on the system.
Implementation Details
------------------------------
This PR makes this change in two steps. Please me know if it would be
easier to review this if I split this up into a stacked diff.
Those changes are:
1) refactor _write_ninja_file to separate the policy (what compiler flags
to pass) from the mechanism (how to write the ninja file and do compilation).
2) call _write_ninja_file and _run_ninja_build while building
ahead-of-time cpp_extensions. These are only used to compile objects;
distutils still handles the linking.
Change 1: refactor _write_ninja_file to seperate policy from mechanism
- I split _write_ninja_file into: _write_ninja_file and
_write_ninja_file_to_build_library
- I renamed _build_extension_module to _run_ninja_build
Change 2: Call _write_ninja_file while building ahead-of-time
cpp_extensions
- _write_ninja_file_and_compile_objects calls _write_ninja_file to only
build object files.
- We monkey-patch distutils.CCompiler.compile to call
_write_ninja_files_and_compile_objects
- distutils still handles the linking step. The linking step is not a
bottleneck so it was not a concern.
- This change only works on unix-based systems. Our code for windows
goes down a different codepath and I did not want to mess with that.
- If a system does not support ninja, we raise a warning and fall back
to the original compilation path.
Test Plan
------------------------------
Adhoc testing
- I built torchvision using pytorch master and printed out the build
commands. Next, I used this branch to build torchvision and looked at
the ninja file. I compared the ninja file with the build commands and
asserted that they were functionally the same.
- I repeated the above for pytorch/nestedtensor.
PyTorch test suite
- I split `test_cpp_extensions` into `test_cpp_extensions_aot` and
`test_cpp_extensions_jit`. The AOT (ahead-of-time) version tests
ahead-of-time and the JIT version tests just-in-time (not to be confused
with TorchScript)
- `test_cpp_extensions_aot` gets run TWICE by run_test.py, once with
a module that was built with ninja, and once with a module that was
built without ninja.
- run_test.py asserts that when we are building with use_ninja=True,
ninja is actually available on the system.
Test Plan: Imported from OSS
Differential Revision: D19730432
Pulled By: zou3519
fbshipit-source-id: 819590d01cf65e8da5a1e8019b8b3084792fee90
2020-02-06 02:44:19 +00:00
|
|
|
cpp_extension.verify_ninja_availability()
|
|
|
|
|
except RuntimeError:
|
2023-10-03 01:22:44 +00:00
|
|
|
print_to_stderr(CPP_EXTENSIONS_ERROR)
|
Add option to use ninja to compile ahead-of-time cpp_extensions (#32495)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/32495
Background
------------------------------
Previously, ninja was used to compile+link inline cpp_extensions and
ahead-of-time cpp_extensions were compiled with distutils. This PR adds
the ability to compile (but not link) ahead-of-time cpp_extensions with ninja.
The main motivation for this is to speed up cpp_extension builds: distutils
does not make use of parallelism. With this PR, using the new option, on my machine,
- torchvision compilation goes from 3m43s to 49s
- nestedtensor compilation goes from 2m0s to 28s.
User-facing changes
------------------------------
I added a `use_ninja` flag to BuildExtension. This defaults to
`True`. When `use_ninja` is True:
- it will attempt to use ninja.
- If we cannot use ninja, then this throws a warning and falls back to
distutils.
- Situations we cannot use ninja: Windows (NYI, I'll open a new issue
for this), if ninja cannot be found on the system.
Implementation Details
------------------------------
This PR makes this change in two steps. Please me know if it would be
easier to review this if I split this up into a stacked diff.
Those changes are:
1) refactor _write_ninja_file to separate the policy (what compiler flags
to pass) from the mechanism (how to write the ninja file and do compilation).
2) call _write_ninja_file and _run_ninja_build while building
ahead-of-time cpp_extensions. These are only used to compile objects;
distutils still handles the linking.
Change 1: refactor _write_ninja_file to seperate policy from mechanism
- I split _write_ninja_file into: _write_ninja_file and
_write_ninja_file_to_build_library
- I renamed _build_extension_module to _run_ninja_build
Change 2: Call _write_ninja_file while building ahead-of-time
cpp_extensions
- _write_ninja_file_and_compile_objects calls _write_ninja_file to only
build object files.
- We monkey-patch distutils.CCompiler.compile to call
_write_ninja_files_and_compile_objects
- distutils still handles the linking step. The linking step is not a
bottleneck so it was not a concern.
- This change only works on unix-based systems. Our code for windows
goes down a different codepath and I did not want to mess with that.
- If a system does not support ninja, we raise a warning and fall back
to the original compilation path.
Test Plan
------------------------------
Adhoc testing
- I built torchvision using pytorch master and printed out the build
commands. Next, I used this branch to build torchvision and looked at
the ninja file. I compared the ninja file with the build commands and
asserted that they were functionally the same.
- I repeated the above for pytorch/nestedtensor.
PyTorch test suite
- I split `test_cpp_extensions` into `test_cpp_extensions_aot` and
`test_cpp_extensions_jit`. The AOT (ahead-of-time) version tests
ahead-of-time and the JIT version tests just-in-time (not to be confused
with TorchScript)
- `test_cpp_extensions_aot` gets run TWICE by run_test.py, once with
a module that was built with ninja, and once with a module that was
built without ninja.
- run_test.py asserts that when we are building with use_ninja=True,
ninja is actually available on the system.
Test Plan: Imported from OSS
Differential Revision: D19730432
Pulled By: zou3519
fbshipit-source-id: 819590d01cf65e8da5a1e8019b8b3084792fee90
2020-02-06 02:44:19 +00:00
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
# Wipe the build folder, if it exists already
|
2021-08-12 18:39:31 +00:00
|
|
|
cpp_extensions_test_dir = os.path.join(test_directory, "cpp_extensions")
|
|
|
|
|
cpp_extensions_test_build_dir = os.path.join(cpp_extensions_test_dir, "build")
|
Add option to use ninja to compile ahead-of-time cpp_extensions (#32495)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/32495
Background
------------------------------
Previously, ninja was used to compile+link inline cpp_extensions and
ahead-of-time cpp_extensions were compiled with distutils. This PR adds
the ability to compile (but not link) ahead-of-time cpp_extensions with ninja.
The main motivation for this is to speed up cpp_extension builds: distutils
does not make use of parallelism. With this PR, using the new option, on my machine,
- torchvision compilation goes from 3m43s to 49s
- nestedtensor compilation goes from 2m0s to 28s.
User-facing changes
------------------------------
I added a `use_ninja` flag to BuildExtension. This defaults to
`True`. When `use_ninja` is True:
- it will attempt to use ninja.
- If we cannot use ninja, then this throws a warning and falls back to
distutils.
- Situations we cannot use ninja: Windows (NYI, I'll open a new issue
for this), if ninja cannot be found on the system.
Implementation Details
------------------------------
This PR makes this change in two steps. Please me know if it would be
easier to review this if I split this up into a stacked diff.
Those changes are:
1) refactor _write_ninja_file to separate the policy (what compiler flags
to pass) from the mechanism (how to write the ninja file and do compilation).
2) call _write_ninja_file and _run_ninja_build while building
ahead-of-time cpp_extensions. These are only used to compile objects;
distutils still handles the linking.
Change 1: refactor _write_ninja_file to seperate policy from mechanism
- I split _write_ninja_file into: _write_ninja_file and
_write_ninja_file_to_build_library
- I renamed _build_extension_module to _run_ninja_build
Change 2: Call _write_ninja_file while building ahead-of-time
cpp_extensions
- _write_ninja_file_and_compile_objects calls _write_ninja_file to only
build object files.
- We monkey-patch distutils.CCompiler.compile to call
_write_ninja_files_and_compile_objects
- distutils still handles the linking step. The linking step is not a
bottleneck so it was not a concern.
- This change only works on unix-based systems. Our code for windows
goes down a different codepath and I did not want to mess with that.
- If a system does not support ninja, we raise a warning and fall back
to the original compilation path.
Test Plan
------------------------------
Adhoc testing
- I built torchvision using pytorch master and printed out the build
commands. Next, I used this branch to build torchvision and looked at
the ninja file. I compared the ninja file with the build commands and
asserted that they were functionally the same.
- I repeated the above for pytorch/nestedtensor.
PyTorch test suite
- I split `test_cpp_extensions` into `test_cpp_extensions_aot` and
`test_cpp_extensions_jit`. The AOT (ahead-of-time) version tests
ahead-of-time and the JIT version tests just-in-time (not to be confused
with TorchScript)
- `test_cpp_extensions_aot` gets run TWICE by run_test.py, once with
a module that was built with ninja, and once with a module that was
built without ninja.
- run_test.py asserts that when we are building with use_ninja=True,
ninja is actually available on the system.
Test Plan: Imported from OSS
Differential Revision: D19730432
Pulled By: zou3519
fbshipit-source-id: 819590d01cf65e8da5a1e8019b8b3084792fee90
2020-02-06 02:44:19 +00:00
|
|
|
if os.path.exists(cpp_extensions_test_build_dir):
|
|
|
|
|
shutil.rmtree(cpp_extensions_test_build_dir)
|
|
|
|
|
|
|
|
|
|
# Build the test cpp extensions modules
|
|
|
|
|
shell_env = os.environ.copy()
|
2021-08-12 18:39:31 +00:00
|
|
|
shell_env["USE_NINJA"] = str(1 if use_ninja else 0)
|
2024-12-11 14:55:47 +00:00
|
|
|
install_cmd = [sys.executable, "setup.py", "install", "--root", "./install"]
|
|
|
|
|
wheel_cmd = [sys.executable, "setup.py", "bdist_wheel"]
|
|
|
|
|
return_code = shell(install_cmd, cwd=cpp_extensions_test_dir, env=shell_env)
|
2018-04-10 18:31:23 +00:00
|
|
|
if return_code != 0:
|
|
|
|
|
return return_code
|
2021-08-12 18:39:31 +00:00
|
|
|
if sys.platform != "win32":
|
2024-12-11 14:55:47 +00:00
|
|
|
exts_to_build = [(install_cmd, "no_python_abi_suffix_test")]
|
|
|
|
|
if TEST_CUDA:
|
|
|
|
|
exts_to_build.append((wheel_cmd, "python_agnostic_extension"))
|
|
|
|
|
for cmd, extension_dir in exts_to_build:
|
|
|
|
|
return_code = shell(
|
|
|
|
|
cmd,
|
|
|
|
|
cwd=os.path.join(cpp_extensions_test_dir, extension_dir),
|
|
|
|
|
env=shell_env,
|
|
|
|
|
)
|
|
|
|
|
if return_code != 0:
|
|
|
|
|
return return_code
|
2018-03-09 21:02:02 +00:00
|
|
|
|
2021-06-24 16:19:16 +00:00
|
|
|
from shutil import copyfile
|
2021-08-25 18:19:49 +00:00
|
|
|
|
2023-03-26 04:52:55 +00:00
|
|
|
os.environ["USE_NINJA"] = shell_env["USE_NINJA"]
|
2021-08-12 18:39:31 +00:00
|
|
|
test_module = "test_cpp_extensions_aot" + ("_ninja" if use_ninja else "_no_ninja")
|
|
|
|
|
copyfile(
|
|
|
|
|
test_directory + "/test_cpp_extensions_aot.py",
|
|
|
|
|
test_directory + "/" + test_module + ".py",
|
|
|
|
|
)
|
2018-03-11 00:16:40 +00:00
|
|
|
try:
|
2021-08-12 18:39:31 +00:00
|
|
|
cpp_extensions = os.path.join(test_directory, "cpp_extensions")
|
|
|
|
|
install_directory = ""
|
2018-04-29 16:10:03 +00:00
|
|
|
# install directory is the one that is named site-packages
|
2021-08-12 18:39:31 +00:00
|
|
|
for root, directories, _ in os.walk(os.path.join(cpp_extensions, "install")):
|
2018-04-29 16:10:03 +00:00
|
|
|
for directory in directories:
|
2021-08-12 18:39:31 +00:00
|
|
|
if "-packages" in directory:
|
2018-04-29 16:10:03 +00:00
|
|
|
install_directory = os.path.join(root, directory)
|
2018-04-02 17:53:25 +00:00
|
|
|
|
2021-08-12 18:39:31 +00:00
|
|
|
assert install_directory, "install_directory must not be empty"
|
2025-01-14 15:59:00 +00:00
|
|
|
with extend_python_path(install_directory):
|
|
|
|
|
return run_test(ShardedTest(test_module, 1, 1), test_directory, options)
|
2018-03-11 00:16:40 +00:00
|
|
|
finally:
|
2021-08-12 18:39:31 +00:00
|
|
|
if os.path.exists(test_directory + "/" + test_module + ".py"):
|
|
|
|
|
os.remove(test_directory + "/" + test_module + ".py")
|
2023-03-26 04:52:55 +00:00
|
|
|
os.environ.pop("USE_NINJA")
|
2018-03-09 21:02:02 +00:00
|
|
|
|
|
|
|
|
|
2020-07-28 15:12:41 +00:00
|
|
|
def test_cpp_extensions_aot_ninja(test_module, test_directory, options):
|
2021-06-24 16:19:16 +00:00
|
|
|
return _test_cpp_extensions_aot(test_directory, options, use_ninja=True)
|
Add option to use ninja to compile ahead-of-time cpp_extensions (#32495)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/32495
Background
------------------------------
Previously, ninja was used to compile+link inline cpp_extensions and
ahead-of-time cpp_extensions were compiled with distutils. This PR adds
the ability to compile (but not link) ahead-of-time cpp_extensions with ninja.
The main motivation for this is to speed up cpp_extension builds: distutils
does not make use of parallelism. With this PR, using the new option, on my machine,
- torchvision compilation goes from 3m43s to 49s
- nestedtensor compilation goes from 2m0s to 28s.
User-facing changes
------------------------------
I added a `use_ninja` flag to BuildExtension. This defaults to
`True`. When `use_ninja` is True:
- it will attempt to use ninja.
- If we cannot use ninja, then this throws a warning and falls back to
distutils.
- Situations we cannot use ninja: Windows (NYI, I'll open a new issue
for this), if ninja cannot be found on the system.
Implementation Details
------------------------------
This PR makes this change in two steps. Please me know if it would be
easier to review this if I split this up into a stacked diff.
Those changes are:
1) refactor _write_ninja_file to separate the policy (what compiler flags
to pass) from the mechanism (how to write the ninja file and do compilation).
2) call _write_ninja_file and _run_ninja_build while building
ahead-of-time cpp_extensions. These are only used to compile objects;
distutils still handles the linking.
Change 1: refactor _write_ninja_file to seperate policy from mechanism
- I split _write_ninja_file into: _write_ninja_file and
_write_ninja_file_to_build_library
- I renamed _build_extension_module to _run_ninja_build
Change 2: Call _write_ninja_file while building ahead-of-time
cpp_extensions
- _write_ninja_file_and_compile_objects calls _write_ninja_file to only
build object files.
- We monkey-patch distutils.CCompiler.compile to call
_write_ninja_files_and_compile_objects
- distutils still handles the linking step. The linking step is not a
bottleneck so it was not a concern.
- This change only works on unix-based systems. Our code for windows
goes down a different codepath and I did not want to mess with that.
- If a system does not support ninja, we raise a warning and fall back
to the original compilation path.
Test Plan
------------------------------
Adhoc testing
- I built torchvision using pytorch master and printed out the build
commands. Next, I used this branch to build torchvision and looked at
the ninja file. I compared the ninja file with the build commands and
asserted that they were functionally the same.
- I repeated the above for pytorch/nestedtensor.
PyTorch test suite
- I split `test_cpp_extensions` into `test_cpp_extensions_aot` and
`test_cpp_extensions_jit`. The AOT (ahead-of-time) version tests
ahead-of-time and the JIT version tests just-in-time (not to be confused
with TorchScript)
- `test_cpp_extensions_aot` gets run TWICE by run_test.py, once with
a module that was built with ninja, and once with a module that was
built without ninja.
- run_test.py asserts that when we are building with use_ninja=True,
ninja is actually available on the system.
Test Plan: Imported from OSS
Differential Revision: D19730432
Pulled By: zou3519
fbshipit-source-id: 819590d01cf65e8da5a1e8019b8b3084792fee90
2020-02-06 02:44:19 +00:00
|
|
|
|
|
|
|
|
|
2020-07-28 15:12:41 +00:00
|
|
|
def test_cpp_extensions_aot_no_ninja(test_module, test_directory, options):
|
2021-06-24 16:19:16 +00:00
|
|
|
return _test_cpp_extensions_aot(test_directory, options, use_ninja=False)
|
Add option to use ninja to compile ahead-of-time cpp_extensions (#32495)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/32495
Background
------------------------------
Previously, ninja was used to compile+link inline cpp_extensions and
ahead-of-time cpp_extensions were compiled with distutils. This PR adds
the ability to compile (but not link) ahead-of-time cpp_extensions with ninja.
The main motivation for this is to speed up cpp_extension builds: distutils
does not make use of parallelism. With this PR, using the new option, on my machine,
- torchvision compilation goes from 3m43s to 49s
- nestedtensor compilation goes from 2m0s to 28s.
User-facing changes
------------------------------
I added a `use_ninja` flag to BuildExtension. This defaults to
`True`. When `use_ninja` is True:
- it will attempt to use ninja.
- If we cannot use ninja, then this throws a warning and falls back to
distutils.
- Situations we cannot use ninja: Windows (NYI, I'll open a new issue
for this), if ninja cannot be found on the system.
Implementation Details
------------------------------
This PR makes this change in two steps. Please me know if it would be
easier to review this if I split this up into a stacked diff.
Those changes are:
1) refactor _write_ninja_file to separate the policy (what compiler flags
to pass) from the mechanism (how to write the ninja file and do compilation).
2) call _write_ninja_file and _run_ninja_build while building
ahead-of-time cpp_extensions. These are only used to compile objects;
distutils still handles the linking.
Change 1: refactor _write_ninja_file to seperate policy from mechanism
- I split _write_ninja_file into: _write_ninja_file and
_write_ninja_file_to_build_library
- I renamed _build_extension_module to _run_ninja_build
Change 2: Call _write_ninja_file while building ahead-of-time
cpp_extensions
- _write_ninja_file_and_compile_objects calls _write_ninja_file to only
build object files.
- We monkey-patch distutils.CCompiler.compile to call
_write_ninja_files_and_compile_objects
- distutils still handles the linking step. The linking step is not a
bottleneck so it was not a concern.
- This change only works on unix-based systems. Our code for windows
goes down a different codepath and I did not want to mess with that.
- If a system does not support ninja, we raise a warning and fall back
to the original compilation path.
Test Plan
------------------------------
Adhoc testing
- I built torchvision using pytorch master and printed out the build
commands. Next, I used this branch to build torchvision and looked at
the ninja file. I compared the ninja file with the build commands and
asserted that they were functionally the same.
- I repeated the above for pytorch/nestedtensor.
PyTorch test suite
- I split `test_cpp_extensions` into `test_cpp_extensions_aot` and
`test_cpp_extensions_jit`. The AOT (ahead-of-time) version tests
ahead-of-time and the JIT version tests just-in-time (not to be confused
with TorchScript)
- `test_cpp_extensions_aot` gets run TWICE by run_test.py, once with
a module that was built with ninja, and once with a module that was
built without ninja.
- run_test.py asserts that when we are building with use_ninja=True,
ninja is actually available on the system.
Test Plan: Imported from OSS
Differential Revision: D19730432
Pulled By: zou3519
fbshipit-source-id: 819590d01cf65e8da5a1e8019b8b3084792fee90
2020-02-06 02:44:19 +00:00
|
|
|
|
|
|
|
|
|
2024-07-09 06:14:10 +00:00
|
|
|
def test_autoload_enable(test_module, test_directory, options):
|
|
|
|
|
return _test_autoload(test_directory, options, enable=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_autoload_disable(test_module, test_directory, options):
|
|
|
|
|
return _test_autoload(test_directory, options, enable=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _test_autoload(test_directory, options, enable=True):
|
|
|
|
|
cpp_extensions_test_dir = os.path.join(test_directory, "cpp_extensions")
|
2025-01-14 15:59:00 +00:00
|
|
|
install_directory, return_code = install_cpp_extensions(cpp_extensions_test_dir)
|
2024-07-09 06:14:10 +00:00
|
|
|
if return_code != 0:
|
|
|
|
|
return return_code
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
os.environ["TORCH_DEVICE_BACKEND_AUTOLOAD"] = str(int(enable))
|
2025-01-14 15:59:00 +00:00
|
|
|
with extend_python_path(install_directory):
|
|
|
|
|
cmd = [sys.executable, "test_autoload.py"]
|
|
|
|
|
return_code = shell(cmd, cwd=test_directory, env=os.environ)
|
|
|
|
|
return return_code
|
2024-07-09 06:14:10 +00:00
|
|
|
finally:
|
|
|
|
|
os.environ.pop("TORCH_DEVICE_BACKEND_AUTOLOAD")
|
|
|
|
|
|
|
|
|
|
|
2025-01-14 15:59:00 +00:00
|
|
|
def run_test_with_openreg(test_module, test_directory, options):
|
|
|
|
|
openreg_dir = os.path.join(
|
|
|
|
|
test_directory, "cpp_extensions", "open_registration_extension"
|
|
|
|
|
)
|
|
|
|
|
install_dir, return_code = install_cpp_extensions(openreg_dir)
|
|
|
|
|
if return_code != 0:
|
|
|
|
|
return return_code
|
|
|
|
|
|
|
|
|
|
with extend_python_path(install_dir):
|
|
|
|
|
return run_test(test_module, test_directory, options)
|
|
|
|
|
|
|
|
|
|
|
2020-07-28 15:12:41 +00:00
|
|
|
def test_distributed(test_module, test_directory, options):
|
2021-05-10 17:50:23 +00:00
|
|
|
# MPI tests are broken with Python-3.9
|
2021-08-12 18:39:31 +00:00
|
|
|
mpi_available = subprocess.call(
|
|
|
|
|
"command -v mpiexec", shell=True
|
|
|
|
|
) == 0 and sys.version_info < (3, 9)
|
2018-03-14 11:44:58 +00:00
|
|
|
if options.verbose and not mpi_available:
|
2021-08-12 18:39:31 +00:00
|
|
|
print_to_stderr("MPI not available -- MPI backend tests will be skipped")
|
2022-10-13 03:31:28 +00:00
|
|
|
|
2018-08-29 19:54:55 +00:00
|
|
|
config = DISTRIBUTED_TESTS_CONFIG
|
2022-10-12 21:17:25 +00:00
|
|
|
for backend, env_vars in config.items():
|
|
|
|
|
if sys.platform == "win32" and backend != "gloo":
|
|
|
|
|
continue
|
|
|
|
|
if backend == "mpi" and not mpi_available:
|
|
|
|
|
continue
|
|
|
|
|
for with_init_file in {True, False}:
|
2021-08-12 18:39:31 +00:00
|
|
|
if sys.platform == "win32" and not with_init_file:
|
2020-09-25 19:35:42 +00:00
|
|
|
continue
|
2018-03-09 21:02:02 +00:00
|
|
|
tmp_dir = tempfile.mkdtemp()
|
2018-03-14 11:44:58 +00:00
|
|
|
if options.verbose:
|
2020-09-09 06:08:55 +00:00
|
|
|
init_str = "with {} init_method"
|
|
|
|
|
with_init = init_str.format("file" if with_init_file else "env")
|
2018-03-15 05:12:51 +00:00
|
|
|
print_to_stderr(
|
2023-07-21 15:23:48 +00:00
|
|
|
f"Running distributed tests for the {backend} backend {with_init}"
|
2021-08-25 18:19:49 +00:00
|
|
|
)
|
2022-05-03 23:01:42 +00:00
|
|
|
old_environ = dict(os.environ)
|
2021-08-12 18:39:31 +00:00
|
|
|
os.environ["TEMP_DIR"] = tmp_dir
|
|
|
|
|
os.environ["BACKEND"] = backend
|
2018-03-09 21:02:02 +00:00
|
|
|
os.environ.update(env_vars)
|
|
|
|
|
try:
|
2021-08-12 18:39:31 +00:00
|
|
|
os.mkdir(os.path.join(tmp_dir, "barrier"))
|
|
|
|
|
os.mkdir(os.path.join(tmp_dir, "test_dir"))
|
|
|
|
|
if backend == "mpi":
|
2018-04-18 03:34:33 +00:00
|
|
|
# test mpiexec for --noprefix option
|
2021-08-12 18:39:31 +00:00
|
|
|
with open(os.devnull, "w") as devnull:
|
|
|
|
|
allowrunasroot_opt = (
|
|
|
|
|
"--allow-run-as-root"
|
|
|
|
|
if subprocess.call(
|
|
|
|
|
'mpiexec --allow-run-as-root -n 1 bash -c ""',
|
|
|
|
|
shell=True,
|
|
|
|
|
stdout=devnull,
|
|
|
|
|
stderr=subprocess.STDOUT,
|
|
|
|
|
)
|
|
|
|
|
== 0
|
|
|
|
|
else ""
|
2021-08-25 18:19:49 +00:00
|
|
|
)
|
2021-08-12 18:39:31 +00:00
|
|
|
noprefix_opt = (
|
|
|
|
|
"--noprefix"
|
|
|
|
|
if subprocess.call(
|
|
|
|
|
f'mpiexec {allowrunasroot_opt} -n 1 --noprefix bash -c ""',
|
|
|
|
|
shell=True,
|
|
|
|
|
stdout=devnull,
|
|
|
|
|
stderr=subprocess.STDOUT,
|
|
|
|
|
)
|
|
|
|
|
== 0
|
|
|
|
|
else ""
|
2021-08-25 18:19:49 +00:00
|
|
|
)
|
|
|
|
|
|
2021-08-12 18:39:31 +00:00
|
|
|
mpiexec = ["mpiexec", "-n", "3", noprefix_opt, allowrunasroot_opt]
|
2022-10-12 21:17:25 +00:00
|
|
|
|
|
|
|
|
return_code = run_test(
|
|
|
|
|
test_module, test_directory, options, launcher_cmd=mpiexec
|
2021-08-12 18:39:31 +00:00
|
|
|
)
|
2018-04-10 18:31:23 +00:00
|
|
|
else:
|
2023-03-26 04:52:55 +00:00
|
|
|
return_code = run_test(
|
|
|
|
|
test_module,
|
|
|
|
|
test_directory,
|
|
|
|
|
options,
|
|
|
|
|
extra_unittest_args=["--subprocess"],
|
|
|
|
|
)
|
2022-10-12 21:17:25 +00:00
|
|
|
if return_code != 0:
|
|
|
|
|
return return_code
|
2018-03-09 21:02:02 +00:00
|
|
|
finally:
|
2022-10-12 21:17:25 +00:00
|
|
|
shutil.rmtree(tmp_dir)
|
2022-05-03 23:01:42 +00:00
|
|
|
os.environ.clear()
|
|
|
|
|
os.environ.update(old_environ)
|
2018-04-10 18:31:23 +00:00
|
|
|
return 0
|
2018-03-09 21:02:02 +00:00
|
|
|
|
|
|
|
|
|
2022-08-22 20:07:23 +00:00
|
|
|
def run_doctests(test_module, test_directory, options):
|
|
|
|
|
"""
|
|
|
|
|
Assumes the incoming test module is called doctest, and simply executes the
|
|
|
|
|
xdoctest runner on the torch library itself.
|
|
|
|
|
"""
|
2023-03-26 04:52:55 +00:00
|
|
|
import xdoctest
|
|
|
|
|
|
2024-06-29 23:28:38 +00:00
|
|
|
pkgpath = Path(torch.__file__).parent
|
2022-08-22 20:07:23 +00:00
|
|
|
|
2023-11-21 11:51:20 +00:00
|
|
|
exclude_module_list = ["torch._vendor.*"]
|
2022-08-22 20:07:23 +00:00
|
|
|
enabled = {
|
|
|
|
|
# TODO: expose these options to the user
|
2022-12-29 05:32:42 +00:00
|
|
|
# For now disable all feature-conditional tests
|
2022-08-22 20:07:23 +00:00
|
|
|
# 'lapack': 'auto',
|
|
|
|
|
# 'cuda': 'auto',
|
|
|
|
|
# 'cuda1': 'auto',
|
|
|
|
|
# 'qengine': 'auto',
|
2023-03-26 04:52:55 +00:00
|
|
|
"lapack": 0,
|
|
|
|
|
"cuda": 0,
|
|
|
|
|
"cuda1": 0,
|
|
|
|
|
"qengine": 0,
|
|
|
|
|
"autograd_profiler": 0,
|
|
|
|
|
"cpp_ext": 0,
|
|
|
|
|
"monitor": 0,
|
2023-03-07 18:31:37 +00:00
|
|
|
"onnx": "auto",
|
2022-08-22 20:07:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Resolve "auto" based on a test to determine if the feature is available.
|
2023-03-26 04:52:55 +00:00
|
|
|
if enabled["cuda"] == "auto" and torch.cuda.is_available():
|
|
|
|
|
enabled["cuda"] = True
|
2022-08-22 20:07:23 +00:00
|
|
|
|
2023-03-26 04:52:55 +00:00
|
|
|
if (
|
|
|
|
|
enabled["cuda1"] == "auto"
|
|
|
|
|
and torch.cuda.is_available()
|
|
|
|
|
and torch.cuda.device_count() > 1
|
|
|
|
|
):
|
|
|
|
|
enabled["cuda1"] = True
|
2022-08-22 20:07:23 +00:00
|
|
|
|
2023-03-26 04:52:55 +00:00
|
|
|
if enabled["lapack"] == "auto" and torch._C.has_lapack:
|
|
|
|
|
enabled["lapack"] = True
|
2022-08-22 20:07:23 +00:00
|
|
|
|
2023-03-26 04:52:55 +00:00
|
|
|
if enabled["qengine"] == "auto":
|
2022-08-22 20:07:23 +00:00
|
|
|
try:
|
|
|
|
|
# Is there a better check if quantization is enabled?
|
2023-07-22 23:03:32 +00:00
|
|
|
import torch.ao.nn.quantized as nnq # NOQA: F401
|
2023-03-26 04:52:55 +00:00
|
|
|
|
|
|
|
|
torch.backends.quantized.engine = "qnnpack"
|
|
|
|
|
torch.backends.quantized.engine = "fbgemm"
|
2022-08-22 20:07:23 +00:00
|
|
|
except (ImportError, RuntimeError):
|
|
|
|
|
...
|
|
|
|
|
else:
|
2023-03-26 04:52:55 +00:00
|
|
|
enabled["qengine"] = True
|
2022-08-22 20:07:23 +00:00
|
|
|
|
2023-03-07 18:31:37 +00:00
|
|
|
if enabled["onnx"] == "auto":
|
|
|
|
|
try:
|
2023-07-22 23:03:32 +00:00
|
|
|
import onnx # NOQA: F401
|
|
|
|
|
import onnxruntime # NOQA: F401
|
|
|
|
|
import onnxscript # NOQA: F401
|
2023-03-07 18:31:37 +00:00
|
|
|
except ImportError:
|
2023-04-06 23:09:12 +00:00
|
|
|
exclude_module_list.append("torch.onnx.*")
|
2023-03-07 18:31:37 +00:00
|
|
|
enabled["onnx"] = False
|
|
|
|
|
else:
|
|
|
|
|
enabled["onnx"] = True
|
|
|
|
|
|
2022-08-22 20:07:23 +00:00
|
|
|
# Set doctest environment variables
|
2023-03-26 04:52:55 +00:00
|
|
|
if enabled["cuda"]:
|
|
|
|
|
os.environ["TORCH_DOCTEST_CUDA"] = "1"
|
2022-08-22 20:07:23 +00:00
|
|
|
|
2023-03-26 04:52:55 +00:00
|
|
|
if enabled["cuda1"]:
|
|
|
|
|
os.environ["TORCH_DOCTEST_CUDA1"] = "1"
|
2022-08-22 20:07:23 +00:00
|
|
|
|
2023-03-26 04:52:55 +00:00
|
|
|
if enabled["lapack"]:
|
|
|
|
|
os.environ["TORCH_DOCTEST_LAPACK"] = "1"
|
2022-08-22 20:07:23 +00:00
|
|
|
|
2023-03-26 04:52:55 +00:00
|
|
|
if enabled["qengine"]:
|
|
|
|
|
os.environ["TORCH_DOCTEST_QENGINE"] = "1"
|
2022-08-22 20:07:23 +00:00
|
|
|
|
2023-03-26 04:52:55 +00:00
|
|
|
if enabled["autograd_profiler"]:
|
|
|
|
|
os.environ["TORCH_DOCTEST_AUTOGRAD_PROFILER"] = "1"
|
2022-12-29 05:32:42 +00:00
|
|
|
|
2023-03-26 04:52:55 +00:00
|
|
|
if enabled["cpp_ext"]:
|
|
|
|
|
os.environ["TORCH_DOCTEST_CPP_EXT"] = "1"
|
2022-12-29 05:32:42 +00:00
|
|
|
|
2023-03-26 04:52:55 +00:00
|
|
|
if enabled["monitor"]:
|
|
|
|
|
os.environ["TORCH_DOCTEST_MONITOR"] = "1"
|
2022-12-29 05:32:42 +00:00
|
|
|
|
2023-03-07 18:31:37 +00:00
|
|
|
if enabled["onnx"]:
|
2023-03-26 04:52:55 +00:00
|
|
|
os.environ["TORCH_DOCTEST_ONNX"] = "1"
|
2023-03-07 18:31:37 +00:00
|
|
|
|
2024-12-11 01:35:55 +00:00
|
|
|
if torch.mps.is_available():
|
|
|
|
|
os.environ["TORCH_DOCTEST_MPS"] = "1"
|
|
|
|
|
|
2022-12-29 05:32:42 +00:00
|
|
|
if 0:
|
|
|
|
|
# TODO: could try to enable some of these
|
2023-03-26 04:52:55 +00:00
|
|
|
os.environ["TORCH_DOCTEST_QUANTIZED_DYNAMIC"] = "1"
|
2023-03-30 06:21:28 +00:00
|
|
|
os.environ["TORCH_DOCTEST_ANOMALY"] = "1"
|
2023-03-26 04:52:55 +00:00
|
|
|
os.environ["TORCH_DOCTEST_AUTOGRAD"] = "1"
|
|
|
|
|
os.environ["TORCH_DOCTEST_HUB"] = "1"
|
|
|
|
|
os.environ["TORCH_DOCTEST_DATALOADER"] = "1"
|
|
|
|
|
os.environ["TORCH_DOCTEST_FUTURES"] = "1"
|
2022-12-29 05:32:42 +00:00
|
|
|
|
2022-08-22 20:07:23 +00:00
|
|
|
pkgpath = os.path.dirname(torch.__file__)
|
2022-12-29 05:32:42 +00:00
|
|
|
|
2022-08-22 20:07:23 +00:00
|
|
|
xdoctest_config = {
|
2023-03-26 04:52:55 +00:00
|
|
|
"global_exec": r"\n".join(
|
|
|
|
|
[
|
|
|
|
|
"from torch import nn",
|
|
|
|
|
"import torch.nn.functional as F",
|
|
|
|
|
"import torch",
|
|
|
|
|
]
|
|
|
|
|
),
|
|
|
|
|
"analysis": "static", # set to "auto" to test doctests in compiled modules
|
|
|
|
|
"style": "google",
|
|
|
|
|
"options": "+IGNORE_WHITESPACE",
|
2022-08-22 20:07:23 +00:00
|
|
|
}
|
|
|
|
|
xdoctest_verbose = max(1, options.verbose)
|
|
|
|
|
run_summary = xdoctest.runner.doctest_module(
|
2023-03-26 04:52:55 +00:00
|
|
|
os.fspath(pkgpath),
|
|
|
|
|
config=xdoctest_config,
|
|
|
|
|
verbose=xdoctest_verbose,
|
|
|
|
|
command=options.xdoctest_command,
|
|
|
|
|
argv=[],
|
|
|
|
|
exclude=exclude_module_list,
|
|
|
|
|
)
|
|
|
|
|
result = 1 if run_summary.get("n_failed", 0) else 0
|
2022-08-22 20:07:23 +00:00
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
2023-10-05 16:40:37 +00:00
|
|
|
def sanitize_file_name(file: str):
|
|
|
|
|
return file.replace("\\", ".").replace("/", ".").replace(" ", "_")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def handle_log_file(
|
|
|
|
|
test: ShardedTest, file_path: str, failed: bool, was_rerun: bool
|
|
|
|
|
) -> None:
|
2023-03-31 18:36:53 +00:00
|
|
|
test = str(test)
|
2024-01-26 21:14:25 +00:00
|
|
|
with open(file_path, errors="ignore") as f:
|
|
|
|
|
full_text = f.read()
|
|
|
|
|
|
|
|
|
|
new_file = "test/test-reports/" + sanitize_file_name(
|
|
|
|
|
f"{test}_{os.urandom(8).hex()}_.log"
|
|
|
|
|
)
|
|
|
|
|
os.rename(file_path, REPO_ROOT / new_file)
|
2023-10-05 16:40:37 +00:00
|
|
|
|
|
|
|
|
if not failed and not was_rerun and "=== RERUNS ===" not in full_text:
|
|
|
|
|
# If success + no retries (idk how else to check for test level retries
|
2024-01-26 21:14:25 +00:00
|
|
|
# other than reparse xml), print only what tests ran
|
2023-10-05 16:40:37 +00:00
|
|
|
print_to_stderr(
|
|
|
|
|
f"\n{test} was successful, full logs can be found in artifacts with path {new_file}"
|
|
|
|
|
)
|
|
|
|
|
for line in full_text.splitlines():
|
|
|
|
|
if re.search("Running .* items in this shard:", line):
|
2024-01-26 21:14:25 +00:00
|
|
|
print_to_stderr(line.rstrip())
|
2022-09-23 20:45:20 +00:00
|
|
|
print_to_stderr("")
|
2023-10-05 16:40:37 +00:00
|
|
|
return
|
2024-01-26 21:14:25 +00:00
|
|
|
|
|
|
|
|
# otherwise: print entire file
|
|
|
|
|
print_to_stderr(f"\nPRINTING LOG FILE of {test} ({new_file})")
|
2023-10-05 16:40:37 +00:00
|
|
|
print_to_stderr(full_text)
|
2024-01-26 21:14:25 +00:00
|
|
|
print_to_stderr(f"FINISHED PRINTING LOG FILE of {test} ({new_file})\n")
|
2022-09-23 20:45:20 +00:00
|
|
|
|
|
|
|
|
|
2024-01-23 18:39:30 +00:00
|
|
|
def get_pytest_args(options, is_cpp_test=False, is_distributed_test=False):
|
2023-03-31 18:36:53 +00:00
|
|
|
if RERUN_DISABLED_TESTS:
|
Do not collect and skip non-disabled tests when rerunning disabled tests (#102107)
The console log blows up to much when running in rerun disabled tests mode (x50) https://hud.pytorch.org/pytorch/pytorch/commit/e132f09e8878418fb98a4b76a441a324452354ec. Each log is around 1GB and the whole uncompressed logs is ~50GB. After compression, it will be around 1GB, still too big. The increase comes mainly from the multiple SKIPPED message for non-disabled tests, which is expected due to how SkipTest and pytest-flakyfinder currently work.
I update `test/conftest.py` to completely ignore skipped tests when rerunning disabled test instead of collecting then skipping 50 tests each. The benefit of doing is is much more than I originally expect:
* Rerun disabled tests jobs now finish in less than half an hour as they should be
* Fix OOM runner crash because of too many collected tests
* Fix verbosity issue as now only disabled tests are run x50 times. There are only few hundreds of them atm
* Fix timed out issue when rerunning disabled distributed and ASAN tests. They are just too slow when running at x50
### Testing
When rerunning disabled tests https://github.com/pytorch/pytorch/actions/runs/5084508614, only disabled tests on the platform are run, for example `test_ops_jit` on https://ossci-raw-job-status.s3.amazonaws.com/log/13770164954 only ran 100 tests (`test_variant_consistency_jit_linalg_lu_cuda_float32` + `test_variant_consistency_jit_linalg_lu_factor_cuda_complex64`) x50.
```
Executing ['/opt/conda/envs/py_3.10/bin/python', '-bb', 'test_ops_jit.py', '--shard-id=1', '--num-shards=2', '-v', '-vv', '-rfEX', '-p', 'no:xdist', '--use-pytest', '--sc=test_ops_jit_1', '--flake-finder', '--flake-runs=50', '--import-slow-tests', '--import-disabled-tests', '--rerun-disabled-tests'] ... [2023-05-25 21:32:49.763856]
Expand the folded group to see the log file of test_ops_jit 2/2
##[group]PRINTING LOG FILE of test_ops_jit 2/2 (/var/lib/jenkins/workspace/test/test-reports/test_ops_jit_h2wr_t2c.log)
Test results will be stored in test-reports/python-pytest/test_ops_jit/test_ops_jit-51a83bd44549074e.xml
============================= test session starts ==============================
platform linux -- Python 3.10.11, pytest-7.3.1, pluggy-1.0.0 -- /opt/conda/envs/py_3.10/bin/python
cachedir: .pytest_cache
hypothesis profile 'pytorch_ci' -> database=None, max_examples=50, derandomize=True, suppress_health_check=[HealthCheck.too_slow]
rootdir: /var/lib/jenkins/workspace
configfile: pytest.ini
plugins: hypothesis-5.35.1, cpp-2.3.0, flakefinder-1.1.0, rerunfailures-11.1.2, shard-0.1.2, xdist-3.3.0, xdoctest-1.1.0
collecting ... collected 1084 items
Running 100 items in this shard: test/test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_cuda_float32 (x50), test/test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_factor_cuda_complex64 (x50)
stepcurrent: Cannot find last run test, not skipping
test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_cuda_float32 PASSED [2.1876s] [ 1%]
test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_factor_cuda_complex64 PASSED [4.5615s] [ 2%]
```
* [pull](https://github.com/pytorch/pytorch/actions/runs/5093566864)
* [trunk](https://github.com/pytorch/pytorch/actions/runs/5095364311)
* [periodic](https://github.com/pytorch/pytorch/actions/runs/5095378850)
* [slow](https://github.com/pytorch/pytorch/actions/runs/5095390285)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/102107
Approved by: https://github.com/clee2000, https://github.com/malfet
2023-05-27 12:10:32 +00:00
|
|
|
# Distributed tests are too slow, so running them x50 will cause the jobs to timeout after
|
|
|
|
|
# 3+ hours. So, let's opt for less number of reruns. We need at least 150 instances of the
|
2024-11-12 21:17:43 +00:00
|
|
|
# test every 2 weeks to satisfy the SQL query (15 x 14 = 210). The same logic applies
|
Do not collect and skip non-disabled tests when rerunning disabled tests (#102107)
The console log blows up to much when running in rerun disabled tests mode (x50) https://hud.pytorch.org/pytorch/pytorch/commit/e132f09e8878418fb98a4b76a441a324452354ec. Each log is around 1GB and the whole uncompressed logs is ~50GB. After compression, it will be around 1GB, still too big. The increase comes mainly from the multiple SKIPPED message for non-disabled tests, which is expected due to how SkipTest and pytest-flakyfinder currently work.
I update `test/conftest.py` to completely ignore skipped tests when rerunning disabled test instead of collecting then skipping 50 tests each. The benefit of doing is is much more than I originally expect:
* Rerun disabled tests jobs now finish in less than half an hour as they should be
* Fix OOM runner crash because of too many collected tests
* Fix verbosity issue as now only disabled tests are run x50 times. There are only few hundreds of them atm
* Fix timed out issue when rerunning disabled distributed and ASAN tests. They are just too slow when running at x50
### Testing
When rerunning disabled tests https://github.com/pytorch/pytorch/actions/runs/5084508614, only disabled tests on the platform are run, for example `test_ops_jit` on https://ossci-raw-job-status.s3.amazonaws.com/log/13770164954 only ran 100 tests (`test_variant_consistency_jit_linalg_lu_cuda_float32` + `test_variant_consistency_jit_linalg_lu_factor_cuda_complex64`) x50.
```
Executing ['/opt/conda/envs/py_3.10/bin/python', '-bb', 'test_ops_jit.py', '--shard-id=1', '--num-shards=2', '-v', '-vv', '-rfEX', '-p', 'no:xdist', '--use-pytest', '--sc=test_ops_jit_1', '--flake-finder', '--flake-runs=50', '--import-slow-tests', '--import-disabled-tests', '--rerun-disabled-tests'] ... [2023-05-25 21:32:49.763856]
Expand the folded group to see the log file of test_ops_jit 2/2
##[group]PRINTING LOG FILE of test_ops_jit 2/2 (/var/lib/jenkins/workspace/test/test-reports/test_ops_jit_h2wr_t2c.log)
Test results will be stored in test-reports/python-pytest/test_ops_jit/test_ops_jit-51a83bd44549074e.xml
============================= test session starts ==============================
platform linux -- Python 3.10.11, pytest-7.3.1, pluggy-1.0.0 -- /opt/conda/envs/py_3.10/bin/python
cachedir: .pytest_cache
hypothesis profile 'pytorch_ci' -> database=None, max_examples=50, derandomize=True, suppress_health_check=[HealthCheck.too_slow]
rootdir: /var/lib/jenkins/workspace
configfile: pytest.ini
plugins: hypothesis-5.35.1, cpp-2.3.0, flakefinder-1.1.0, rerunfailures-11.1.2, shard-0.1.2, xdist-3.3.0, xdoctest-1.1.0
collecting ... collected 1084 items
Running 100 items in this shard: test/test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_cuda_float32 (x50), test/test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_factor_cuda_complex64 (x50)
stepcurrent: Cannot find last run test, not skipping
test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_cuda_float32 PASSED [2.1876s] [ 1%]
test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_factor_cuda_complex64 PASSED [4.5615s] [ 2%]
```
* [pull](https://github.com/pytorch/pytorch/actions/runs/5093566864)
* [trunk](https://github.com/pytorch/pytorch/actions/runs/5095364311)
* [periodic](https://github.com/pytorch/pytorch/actions/runs/5095378850)
* [slow](https://github.com/pytorch/pytorch/actions/runs/5095390285)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/102107
Approved by: https://github.com/clee2000, https://github.com/malfet
2023-05-27 12:10:32 +00:00
|
|
|
# to ASAN, which is also slow
|
|
|
|
|
count = 15 if is_distributed_test or TEST_WITH_ASAN else 50
|
2022-11-18 00:11:42 +00:00
|
|
|
# When under rerun-disabled-tests mode, run the same tests multiple times to determine their
|
|
|
|
|
# flakiness status. Default to 50 re-runs
|
Do not collect and skip non-disabled tests when rerunning disabled tests (#102107)
The console log blows up to much when running in rerun disabled tests mode (x50) https://hud.pytorch.org/pytorch/pytorch/commit/e132f09e8878418fb98a4b76a441a324452354ec. Each log is around 1GB and the whole uncompressed logs is ~50GB. After compression, it will be around 1GB, still too big. The increase comes mainly from the multiple SKIPPED message for non-disabled tests, which is expected due to how SkipTest and pytest-flakyfinder currently work.
I update `test/conftest.py` to completely ignore skipped tests when rerunning disabled test instead of collecting then skipping 50 tests each. The benefit of doing is is much more than I originally expect:
* Rerun disabled tests jobs now finish in less than half an hour as they should be
* Fix OOM runner crash because of too many collected tests
* Fix verbosity issue as now only disabled tests are run x50 times. There are only few hundreds of them atm
* Fix timed out issue when rerunning disabled distributed and ASAN tests. They are just too slow when running at x50
### Testing
When rerunning disabled tests https://github.com/pytorch/pytorch/actions/runs/5084508614, only disabled tests on the platform are run, for example `test_ops_jit` on https://ossci-raw-job-status.s3.amazonaws.com/log/13770164954 only ran 100 tests (`test_variant_consistency_jit_linalg_lu_cuda_float32` + `test_variant_consistency_jit_linalg_lu_factor_cuda_complex64`) x50.
```
Executing ['/opt/conda/envs/py_3.10/bin/python', '-bb', 'test_ops_jit.py', '--shard-id=1', '--num-shards=2', '-v', '-vv', '-rfEX', '-p', 'no:xdist', '--use-pytest', '--sc=test_ops_jit_1', '--flake-finder', '--flake-runs=50', '--import-slow-tests', '--import-disabled-tests', '--rerun-disabled-tests'] ... [2023-05-25 21:32:49.763856]
Expand the folded group to see the log file of test_ops_jit 2/2
##[group]PRINTING LOG FILE of test_ops_jit 2/2 (/var/lib/jenkins/workspace/test/test-reports/test_ops_jit_h2wr_t2c.log)
Test results will be stored in test-reports/python-pytest/test_ops_jit/test_ops_jit-51a83bd44549074e.xml
============================= test session starts ==============================
platform linux -- Python 3.10.11, pytest-7.3.1, pluggy-1.0.0 -- /opt/conda/envs/py_3.10/bin/python
cachedir: .pytest_cache
hypothesis profile 'pytorch_ci' -> database=None, max_examples=50, derandomize=True, suppress_health_check=[HealthCheck.too_slow]
rootdir: /var/lib/jenkins/workspace
configfile: pytest.ini
plugins: hypothesis-5.35.1, cpp-2.3.0, flakefinder-1.1.0, rerunfailures-11.1.2, shard-0.1.2, xdist-3.3.0, xdoctest-1.1.0
collecting ... collected 1084 items
Running 100 items in this shard: test/test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_cuda_float32 (x50), test/test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_factor_cuda_complex64 (x50)
stepcurrent: Cannot find last run test, not skipping
test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_cuda_float32 PASSED [2.1876s] [ 1%]
test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_factor_cuda_complex64 PASSED [4.5615s] [ 2%]
```
* [pull](https://github.com/pytorch/pytorch/actions/runs/5093566864)
* [trunk](https://github.com/pytorch/pytorch/actions/runs/5095364311)
* [periodic](https://github.com/pytorch/pytorch/actions/runs/5095378850)
* [slow](https://github.com/pytorch/pytorch/actions/runs/5095390285)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/102107
Approved by: https://github.com/clee2000, https://github.com/malfet
2023-05-27 12:10:32 +00:00
|
|
|
rerun_options = ["--flake-finder", f"--flake-runs={count}"]
|
2022-11-18 00:11:42 +00:00
|
|
|
else:
|
|
|
|
|
# When under the normal mode, retry a failed test 2 more times. -x means stop at the first
|
|
|
|
|
# failure
|
2023-04-25 20:56:04 +00:00
|
|
|
rerun_options = ["-x", "--reruns=2"]
|
2022-11-18 00:11:42 +00:00
|
|
|
|
2023-02-28 22:09:01 +00:00
|
|
|
pytest_args = [
|
2022-11-18 00:11:42 +00:00
|
|
|
"-vv",
|
2023-03-16 04:22:42 +00:00
|
|
|
"-rfEX",
|
2022-11-18 00:11:42 +00:00
|
|
|
]
|
Discover and run C++ tests with run_test.py (#99559)
This depends on [pytest-cpp](https://github.com/pytest-dev/pytest-cpp) to discover and run C++ tests with pytest. C++ tests are built under `${WORKSPACE}/build/bin` directory and copied to the test job under the same path.
* To expose them to `run_test`, I choose to use the mock path prefix `cpp`, for example `build/bin/c10_Array_test` would be named as `cpp/c10_Array_test` and the `python test/run_test.py --cpp -i cpp/c10_Array_test` would run the test in the same way as other Python tests. I could copy them from `build/bin` to `test/cpp`, but it will be mixed with the source code and CMake file. So this looks easier
* Some executable under `build/bin` are not C++ tests, and they are exclude, for example `build/bin/torch_shm_manager`
* C++ tests need to run with pytest directly as python command doesn't understand it
* The change is gated by the new `--cpp` argument to `run_test.py`, for example `python test/run_test.py --cpp` will run all available C++ tests
* The tests can be run in parallel
* Failing tests can be retried with `--reruns=2` and `--sw`
```
============================= test session starts ==============================
platform darwin -- Python 3.9.15, pytest-7.2.0, pluggy-1.0.0 -- /Users/huydo/miniconda3/envs/py3.9/bin/python3
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/Users/huydo/Storage/mine/pytorch/test/.hypothesis/examples')
rootdir: /Users/huydo/Storage/mine/pytorch, configfile: pytest.ini
plugins: xdoctest-1.1.0, cpp-2.3.0, rerunfailures-10.3, shard-0.1.2, flakefinder-1.1.0, hypothesis-6.56.4, xdist-3.0.2, repeat-0.9.1
collecting ... collected 3 items / 2 deselected / 1 selected
Running 1 items in this shard: build/bin/scalar_tensor_test::TestScalarTensor.TestScalarTensorMPS
stepwise: skipping 2 already passed items.
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS FAILED [100%]
```
* `--import-slow-tests` and `--import-disabled-tests` won't work for now and that's ok to have it as a future task.
I also add `pytest-cpp==2.3.0` to Linux Docker, MacOS, and Windows.
### Testing
Build PyTorch and run `python test/run_test.py --cpp` on my laptop. CI change would come later in a separate PR. Also running `python test/run_test.py --help` now shows all C++ test discovered under `build/bin`
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99559
Approved by: https://github.com/clee2000
2023-04-22 00:23:31 +00:00
|
|
|
if not is_cpp_test:
|
|
|
|
|
# C++ tests need to be run with pytest directly, not via python
|
2024-01-23 18:39:30 +00:00
|
|
|
# We have a custom pytest shard that conflicts with the normal plugin
|
2023-05-31 04:46:25 +00:00
|
|
|
pytest_args.extend(["-p", "no:xdist", "--use-pytest"])
|
2023-05-16 21:52:36 +00:00
|
|
|
else:
|
|
|
|
|
# Use pytext-dist to run C++ tests in parallel as running them sequentially using run_test
|
|
|
|
|
# is much slower than running them directly
|
2023-05-24 06:50:51 +00:00
|
|
|
pytest_args.extend(["-n", str(NUM_PROCS)])
|
2023-05-16 21:52:36 +00:00
|
|
|
|
|
|
|
|
if IS_CI:
|
|
|
|
|
# Add the option to generate XML test report here as C++ tests
|
|
|
|
|
# won't go into common_utils
|
|
|
|
|
test_report_path = get_report_path(pytest=True)
|
|
|
|
|
pytest_args.extend(["--junit-xml-reruns", test_report_path])
|
Run C++ tests on CI with run_test.py (#99956)
After https://github.com/pytorch/pytorch/pull/99559, we can now run C++ test with `run_test.py`. Although advance features such as `--import-slow-tests` and `--import-disabled-tests` won't work for now, there will still be a gain in reliability and performance as C++ can now be retried and run in parallel.
This covers all C++ tests in the CI including aten, libtorch, and Vulkan C++ tests across all platforms Linux, Windows, MacOS.
Notes:
* To support C++ test discovery, the env variable `CPP_TESTS_DIR` can be set to where the C++ test binaries is located
* Support pytest -k argument via run_test as this is used by pytest-cpp to replace `--gtest-filter`
* The XML output is in pytest format, but it's ok now because we don't have slow test or flaky test support for C++ test yet
* ~~I need to figure out why conftest.py doesn't work when I invoke pytest directly for C++ test, so `--sc` is not available for C++ tests at the moment. Proper pytest plugin like stepwise works fine though. I'll investigate and fix it in a separate PR~~ Found the cause, `conftest.py` is per directory and needs to be in any arbitrary directory that holds C++ test
* Two tests `test_api` and `test_tensorexpr` timed out on ASAN, I suspect that ASAN is now used on top of the python executable, which is slower than running native C++ code. IMO, it's ok to run these tests as before on ASAN for now
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99956
Approved by: https://github.com/clee2000, https://github.com/ZainRizvi
2023-05-09 21:24:12 +00:00
|
|
|
|
|
|
|
|
if options.pytest_k_expr:
|
|
|
|
|
pytest_args.extend(["-k", options.pytest_k_expr])
|
Discover and run C++ tests with run_test.py (#99559)
This depends on [pytest-cpp](https://github.com/pytest-dev/pytest-cpp) to discover and run C++ tests with pytest. C++ tests are built under `${WORKSPACE}/build/bin` directory and copied to the test job under the same path.
* To expose them to `run_test`, I choose to use the mock path prefix `cpp`, for example `build/bin/c10_Array_test` would be named as `cpp/c10_Array_test` and the `python test/run_test.py --cpp -i cpp/c10_Array_test` would run the test in the same way as other Python tests. I could copy them from `build/bin` to `test/cpp`, but it will be mixed with the source code and CMake file. So this looks easier
* Some executable under `build/bin` are not C++ tests, and they are exclude, for example `build/bin/torch_shm_manager`
* C++ tests need to run with pytest directly as python command doesn't understand it
* The change is gated by the new `--cpp` argument to `run_test.py`, for example `python test/run_test.py --cpp` will run all available C++ tests
* The tests can be run in parallel
* Failing tests can be retried with `--reruns=2` and `--sw`
```
============================= test session starts ==============================
platform darwin -- Python 3.9.15, pytest-7.2.0, pluggy-1.0.0 -- /Users/huydo/miniconda3/envs/py3.9/bin/python3
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/Users/huydo/Storage/mine/pytorch/test/.hypothesis/examples')
rootdir: /Users/huydo/Storage/mine/pytorch, configfile: pytest.ini
plugins: xdoctest-1.1.0, cpp-2.3.0, rerunfailures-10.3, shard-0.1.2, flakefinder-1.1.0, hypothesis-6.56.4, xdist-3.0.2, repeat-0.9.1
collecting ... collected 3 items / 2 deselected / 1 selected
Running 1 items in this shard: build/bin/scalar_tensor_test::TestScalarTensor.TestScalarTensorMPS
stepwise: skipping 2 already passed items.
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS FAILED [100%]
```
* `--import-slow-tests` and `--import-disabled-tests` won't work for now and that's ok to have it as a future task.
I also add `pytest-cpp==2.3.0` to Linux Docker, MacOS, and Windows.
### Testing
Build PyTorch and run `python test/run_test.py --cpp` on my laptop. CI change would come later in a separate PR. Also running `python test/run_test.py --help` now shows all C++ test discovered under `build/bin`
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99559
Approved by: https://github.com/clee2000
2023-04-22 00:23:31 +00:00
|
|
|
|
2023-02-28 22:09:01 +00:00
|
|
|
pytest_args.extend(rerun_options)
|
|
|
|
|
return pytest_args
|
|
|
|
|
|
2023-03-26 04:52:55 +00:00
|
|
|
|
2024-03-11 15:35:45 +00:00
|
|
|
def run_ci_sanity_check(test: ShardedTest, test_directory, options):
|
|
|
|
|
assert (
|
|
|
|
|
test.name == "test_ci_sanity_check_fail"
|
|
|
|
|
), f"This handler only works for test_ci_sanity_check_fail, got {test.name}"
|
|
|
|
|
ret_code = run_test(test, test_directory, options, print_log=False)
|
|
|
|
|
# This test should fail
|
|
|
|
|
if ret_code != 1:
|
|
|
|
|
return 1
|
|
|
|
|
test_reports_dir = str(REPO_ROOT / "test/test-reports")
|
|
|
|
|
# Delete the log files and xmls generated by the test
|
|
|
|
|
for file in glob.glob(f"{test_reports_dir}/{test.name}*.log"):
|
|
|
|
|
os.remove(file)
|
|
|
|
|
for dirname in glob.glob(f"{test_reports_dir}/**/{test.name}"):
|
|
|
|
|
shutil.rmtree(dirname)
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
2018-03-09 21:02:02 +00:00
|
|
|
CUSTOM_HANDLERS = {
|
2023-03-31 06:31:17 +00:00
|
|
|
"test_cuda_primary_ctx": run_test_with_subprocess,
|
|
|
|
|
"test_cuda_nvml_based_avail": run_test_with_subprocess,
|
|
|
|
|
"test_cuda_trace": run_test_with_subprocess,
|
2021-08-12 18:39:31 +00:00
|
|
|
"test_cpp_extensions_aot_no_ninja": test_cpp_extensions_aot_no_ninja,
|
|
|
|
|
"test_cpp_extensions_aot_ninja": test_cpp_extensions_aot_ninja,
|
|
|
|
|
"distributed/test_distributed_spawn": test_distributed,
|
2022-06-30 21:15:33 +00:00
|
|
|
"distributed/algorithms/quantization/test_quantization": test_distributed,
|
2023-03-31 06:31:17 +00:00
|
|
|
"distributed/test_c10d_nccl": run_test_with_subprocess,
|
|
|
|
|
"distributed/test_c10d_gloo": run_test_with_subprocess,
|
2023-04-06 23:51:27 +00:00
|
|
|
"distributed/test_c10d_ucc": run_test_with_subprocess,
|
2023-03-31 06:31:17 +00:00
|
|
|
"distributed/test_c10d_common": run_test_with_subprocess,
|
|
|
|
|
"distributed/test_c10d_spawn_gloo": run_test_with_subprocess,
|
|
|
|
|
"distributed/test_c10d_spawn_nccl": run_test_with_subprocess,
|
|
|
|
|
"distributed/test_c10d_spawn_ucc": run_test_with_subprocess,
|
|
|
|
|
"distributed/test_store": run_test_with_subprocess,
|
|
|
|
|
"distributed/test_pg_wrapper": run_test_with_subprocess,
|
|
|
|
|
"distributed/rpc/test_faulty_agent": run_test_with_subprocess,
|
|
|
|
|
"distributed/rpc/test_tensorpipe_agent": run_test_with_subprocess,
|
|
|
|
|
"distributed/rpc/test_share_memory": run_test_with_subprocess,
|
|
|
|
|
"distributed/rpc/cuda/test_tensorpipe_agent": run_test_with_subprocess,
|
2022-08-22 20:07:23 +00:00
|
|
|
"doctests": run_doctests,
|
2024-03-11 15:35:45 +00:00
|
|
|
"test_ci_sanity_check_fail": run_ci_sanity_check,
|
2024-07-09 06:14:10 +00:00
|
|
|
"test_autoload_enable": test_autoload_enable,
|
|
|
|
|
"test_autoload_disable": test_autoload_disable,
|
2025-01-14 15:59:00 +00:00
|
|
|
"test_cpp_extensions_open_device_registration": run_test_with_openreg,
|
|
|
|
|
"test_transformers": run_test_with_openreg,
|
2018-03-09 21:02:02 +00:00
|
|
|
}
|
|
|
|
|
|
2022-07-28 16:35:01 +00:00
|
|
|
|
2023-03-26 04:52:55 +00:00
|
|
|
PYTEST_SKIP_RETRIES = {"test_public_bindings"}
|
Run more tests through pytest (#95844)
Run more tests through pytest.
Use a block list for tests that shouldn't run through pytest. As far as I can tell, the number of tests run, skipped, and xfailed for those not on the blocklist are the same.
Regarding the main module:
Usually tests are run in CI, we call `python <test file>`, which causes the file to be imported under the module name `__main__`. However, pytest searches for the module to be imported under the file name, so the file will be reimported. This can cause issues for tests that run module level code and change global state, like test_nn, which modifies lists imported from another file, or tests in test/lazy, which initialize a backend that cannot coexist with a second copy of itself.
My workaround for this is to run tests from the `__main__` module. However, this results in pytest being unable to rewrite assertions (and possibly other things but I don't know what other things pytest does right now). A better solution might be to call `pytest <test file>` directly and move all the code in run_tests(argv) to be module level code or put it in a hook in conftest.py.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/95844
Approved by: https://github.com/huydhn
2023-03-03 17:32:26 +00:00
|
|
|
|
|
|
|
|
|
2018-03-09 21:02:02 +00:00
|
|
|
def parse_args():
|
|
|
|
|
parser = argparse.ArgumentParser(
|
2021-08-12 18:39:31 +00:00
|
|
|
description="Run the PyTorch unit test suite",
|
|
|
|
|
epilog="where TESTS is any of: {}".format(", ".join(TESTS)),
|
|
|
|
|
formatter_class=argparse.RawTextHelpFormatter,
|
|
|
|
|
)
|
2018-03-09 21:02:02 +00:00
|
|
|
parser.add_argument(
|
2021-08-12 18:39:31 +00:00
|
|
|
"-v",
|
|
|
|
|
"--verbose",
|
|
|
|
|
action="count",
|
2020-11-19 15:57:09 +00:00
|
|
|
default=0,
|
Run C++ tests on CI with run_test.py (#99956)
After https://github.com/pytorch/pytorch/pull/99559, we can now run C++ test with `run_test.py`. Although advance features such as `--import-slow-tests` and `--import-disabled-tests` won't work for now, there will still be a gain in reliability and performance as C++ can now be retried and run in parallel.
This covers all C++ tests in the CI including aten, libtorch, and Vulkan C++ tests across all platforms Linux, Windows, MacOS.
Notes:
* To support C++ test discovery, the env variable `CPP_TESTS_DIR` can be set to where the C++ test binaries is located
* Support pytest -k argument via run_test as this is used by pytest-cpp to replace `--gtest-filter`
* The XML output is in pytest format, but it's ok now because we don't have slow test or flaky test support for C++ test yet
* ~~I need to figure out why conftest.py doesn't work when I invoke pytest directly for C++ test, so `--sc` is not available for C++ tests at the moment. Proper pytest plugin like stepwise works fine though. I'll investigate and fix it in a separate PR~~ Found the cause, `conftest.py` is per directory and needs to be in any arbitrary directory that holds C++ test
* Two tests `test_api` and `test_tensorexpr` timed out on ASAN, I suspect that ASAN is now used on top of the python executable, which is slower than running native C++ code. IMO, it's ok to run these tests as before on ASAN for now
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99956
Approved by: https://github.com/clee2000, https://github.com/ZainRizvi
2023-05-09 21:24:12 +00:00
|
|
|
help="Print verbose information and test-by-test results",
|
2021-08-12 18:39:31 +00:00
|
|
|
)
|
2025-01-21 19:22:20 +00:00
|
|
|
parser.add_argument(
|
|
|
|
|
"--showlocals",
|
|
|
|
|
action=argparse.BooleanOptionalAction,
|
|
|
|
|
default=strtobool(os.environ.get("TEST_SHOWLOCALS", "False")),
|
|
|
|
|
help="Show local variables in tracebacks (default: True)",
|
|
|
|
|
)
|
2021-08-12 18:39:31 +00:00
|
|
|
parser.add_argument("--jit", "--jit", action="store_true", help="run all jit tests")
|
2021-08-24 15:01:36 +00:00
|
|
|
parser.add_argument(
|
|
|
|
|
"--distributed-tests",
|
|
|
|
|
"--distributed-tests",
|
|
|
|
|
action="store_true",
|
Run C++ tests on CI with run_test.py (#99956)
After https://github.com/pytorch/pytorch/pull/99559, we can now run C++ test with `run_test.py`. Although advance features such as `--import-slow-tests` and `--import-disabled-tests` won't work for now, there will still be a gain in reliability and performance as C++ can now be retried and run in parallel.
This covers all C++ tests in the CI including aten, libtorch, and Vulkan C++ tests across all platforms Linux, Windows, MacOS.
Notes:
* To support C++ test discovery, the env variable `CPP_TESTS_DIR` can be set to where the C++ test binaries is located
* Support pytest -k argument via run_test as this is used by pytest-cpp to replace `--gtest-filter`
* The XML output is in pytest format, but it's ok now because we don't have slow test or flaky test support for C++ test yet
* ~~I need to figure out why conftest.py doesn't work when I invoke pytest directly for C++ test, so `--sc` is not available for C++ tests at the moment. Proper pytest plugin like stepwise works fine though. I'll investigate and fix it in a separate PR~~ Found the cause, `conftest.py` is per directory and needs to be in any arbitrary directory that holds C++ test
* Two tests `test_api` and `test_tensorexpr` timed out on ASAN, I suspect that ASAN is now used on top of the python executable, which is slower than running native C++ code. IMO, it's ok to run these tests as before on ASAN for now
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99956
Approved by: https://github.com/clee2000, https://github.com/ZainRizvi
2023-05-09 21:24:12 +00:00
|
|
|
help="Run all distributed tests",
|
2021-08-24 15:01:36 +00:00
|
|
|
)
|
2022-07-24 23:14:13 +00:00
|
|
|
parser.add_argument(
|
|
|
|
|
"--functorch",
|
|
|
|
|
"--functorch",
|
|
|
|
|
action="store_true",
|
|
|
|
|
help=(
|
|
|
|
|
"If this flag is present, we will only run functorch tests. "
|
2023-03-20 20:19:41 +00:00
|
|
|
"If this flag is not present, we will run all tests "
|
|
|
|
|
"(including functorch tests)."
|
2023-03-26 04:52:55 +00:00
|
|
|
),
|
2022-07-24 23:14:13 +00:00
|
|
|
)
|
2022-11-10 21:32:41 +00:00
|
|
|
parser.add_argument(
|
|
|
|
|
"--mps",
|
|
|
|
|
"--mps",
|
|
|
|
|
action="store_true",
|
2023-03-26 04:52:55 +00:00
|
|
|
help=("If this flag is present, we will only run test_mps and test_metal"),
|
2022-11-10 21:32:41 +00:00
|
|
|
)
|
2024-01-23 08:20:37 +00:00
|
|
|
parser.add_argument(
|
|
|
|
|
"--xpu",
|
|
|
|
|
"--xpu",
|
|
|
|
|
action="store_true",
|
|
|
|
|
help=("If this flag is present, we will run xpu tests except XPU_BLOCK_LIST"),
|
|
|
|
|
)
|
Discover and run C++ tests with run_test.py (#99559)
This depends on [pytest-cpp](https://github.com/pytest-dev/pytest-cpp) to discover and run C++ tests with pytest. C++ tests are built under `${WORKSPACE}/build/bin` directory and copied to the test job under the same path.
* To expose them to `run_test`, I choose to use the mock path prefix `cpp`, for example `build/bin/c10_Array_test` would be named as `cpp/c10_Array_test` and the `python test/run_test.py --cpp -i cpp/c10_Array_test` would run the test in the same way as other Python tests. I could copy them from `build/bin` to `test/cpp`, but it will be mixed with the source code and CMake file. So this looks easier
* Some executable under `build/bin` are not C++ tests, and they are exclude, for example `build/bin/torch_shm_manager`
* C++ tests need to run with pytest directly as python command doesn't understand it
* The change is gated by the new `--cpp` argument to `run_test.py`, for example `python test/run_test.py --cpp` will run all available C++ tests
* The tests can be run in parallel
* Failing tests can be retried with `--reruns=2` and `--sw`
```
============================= test session starts ==============================
platform darwin -- Python 3.9.15, pytest-7.2.0, pluggy-1.0.0 -- /Users/huydo/miniconda3/envs/py3.9/bin/python3
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/Users/huydo/Storage/mine/pytorch/test/.hypothesis/examples')
rootdir: /Users/huydo/Storage/mine/pytorch, configfile: pytest.ini
plugins: xdoctest-1.1.0, cpp-2.3.0, rerunfailures-10.3, shard-0.1.2, flakefinder-1.1.0, hypothesis-6.56.4, xdist-3.0.2, repeat-0.9.1
collecting ... collected 3 items / 2 deselected / 1 selected
Running 1 items in this shard: build/bin/scalar_tensor_test::TestScalarTensor.TestScalarTensorMPS
stepwise: skipping 2 already passed items.
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS FAILED [100%]
```
* `--import-slow-tests` and `--import-disabled-tests` won't work for now and that's ok to have it as a future task.
I also add `pytest-cpp==2.3.0` to Linux Docker, MacOS, and Windows.
### Testing
Build PyTorch and run `python test/run_test.py --cpp` on my laptop. CI change would come later in a separate PR. Also running `python test/run_test.py --help` now shows all C++ test discovered under `build/bin`
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99559
Approved by: https://github.com/clee2000
2023-04-22 00:23:31 +00:00
|
|
|
parser.add_argument(
|
|
|
|
|
"--cpp",
|
|
|
|
|
"--cpp",
|
|
|
|
|
action="store_true",
|
|
|
|
|
help=("If this flag is present, we will only run C++ tests"),
|
|
|
|
|
)
|
2021-08-26 16:27:47 +00:00
|
|
|
parser.add_argument(
|
|
|
|
|
"-core",
|
|
|
|
|
"--core",
|
|
|
|
|
action="store_true",
|
|
|
|
|
help="Only run core tests, or tests that validate PyTorch's ops, modules,"
|
2023-03-26 04:52:55 +00:00
|
|
|
"and autograd. They are defined by CORE_TEST_LIST.",
|
2021-08-26 16:27:47 +00:00
|
|
|
)
|
[ONNX] Run ONNX tests as part of standard run_test script (#99215)
<!--
copilot:all
-->
### <samp>🤖 Generated by Copilot at dcbf7e2</samp>
### Summary
📝🧹🚩
<!--
1. 📝 for simplifying the `./scripts/onnx/test.sh` script
2. 🧹 for refactoring the `test/onnx/dynamo/test_exporter_api.py` file
3. 🚩 for adding the `--onnx` flag to `test/run_test.py` and updating the `TESTS` list
-->
This pull request improves the ONNX testing infrastructure in PyTorch by refactoring the test code, normalizing the scope names, adding a flag to run only the ONNX tests, and simplifying the test script.
> _To export PyTorch models to ONNX_
> _We refactored some scripts and contexts_
> _We used `common_utils`_
> _And normalized the scopes_
> _And added a flag to run the tests_
### Walkthrough
* Simplify `./scripts/onnx/test.sh` to use `run_test.py` with `--onnx` flag instead of `pytest` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-0017f5b22ae1329acb0f54af8d9811c9b6180a72dac70d7a5b89d7c23c958198L44-R46))
* Remove `onnx` test from `TESTS` list in `test/run_test.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7L127-R127)). Replace with `onnx_caffe2`.
* Add `onnx/test_pytorch_onnx_onnxruntime_cuda` and `onnx/test_models` tests to `blocklisted_tests` list in `test/run_test.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7R154-R155))
* Add `ONNX_SERIAL_LIST` list to `test/run_test.py` to specify ONNX tests that must run serially ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7R296-R301))
* Add `ONNX_TESTS` list to `test/run_test.py` to store all ONNX tests ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7R370))
* Add `--onnx` flag to `parse_args` function in `test/run_test.py` to run only ONNX tests ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7R920-R928))
* Include `ONNX_SERIAL_LIST` in `must_serial` function in `test/run_test.py` to run ONNX tests serially or parallelly based on memory usage ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7R1120))
* Filter selected tests based on `--onnx` flag in `get_selected_tests` function in `test/run_test.py` to exclude non-ONNX tests ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7R1158-R1165))
### Other minor changes to accommodate this change
* Replace `unittest` module with `common_utils.TestCase` in `test/onnx/dynamo/test_exporter_api.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L4), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L29-R28), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L71-R70), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L147-R146))
* Import `TemporaryFileName` class from `common_utils` in `test/onnx/dynamo/test_exporter_api.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L19-R18))
* Use `common_utils.TemporaryFileName` instead of `TemporaryFileName` in `TestDynamoExportAPI` class in `test/onnx/dynamo/test_exporter_api.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L92-R91), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L110-R109), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L129-R128))
* Use `common_utils.run_tests` instead of `unittest.main` in `test/onnx/dynamo/test_exporter_api.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L155-R154))
* Add `re` module to `test/onnx/test_utility_funs.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7R6))
* Add `_remove_test_environment_prefix_from_scope_name` function to `test/onnx/test_utility_funs.py` to normalize scope names of ONNX nodes ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7R32-R58))
* Use `_remove_test_environment_prefix_from_scope_name` function to compare scope names of ONNX nodes in `TestUtilityFuns` class in `test/onnx/test_utility_funs.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7L1099-R1133), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7L1119-R1152), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7L1170-R1188), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7L1181-R1199), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7L1220-R1239), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7L1235-R1258))
Fixes #98626
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99215
Approved by: https://github.com/huydhn, https://github.com/titaiwangms
2023-04-18 00:49:08 +00:00
|
|
|
parser.add_argument(
|
|
|
|
|
"--onnx",
|
|
|
|
|
"--onnx",
|
|
|
|
|
action="store_true",
|
|
|
|
|
help=(
|
|
|
|
|
"Only run ONNX tests, or tests that validate PyTorch's ONNX export. "
|
|
|
|
|
"If this flag is not present, we will exclude ONNX tests."
|
|
|
|
|
),
|
|
|
|
|
)
|
Run C++ tests on CI with run_test.py (#99956)
After https://github.com/pytorch/pytorch/pull/99559, we can now run C++ test with `run_test.py`. Although advance features such as `--import-slow-tests` and `--import-disabled-tests` won't work for now, there will still be a gain in reliability and performance as C++ can now be retried and run in parallel.
This covers all C++ tests in the CI including aten, libtorch, and Vulkan C++ tests across all platforms Linux, Windows, MacOS.
Notes:
* To support C++ test discovery, the env variable `CPP_TESTS_DIR` can be set to where the C++ test binaries is located
* Support pytest -k argument via run_test as this is used by pytest-cpp to replace `--gtest-filter`
* The XML output is in pytest format, but it's ok now because we don't have slow test or flaky test support for C++ test yet
* ~~I need to figure out why conftest.py doesn't work when I invoke pytest directly for C++ test, so `--sc` is not available for C++ tests at the moment. Proper pytest plugin like stepwise works fine though. I'll investigate and fix it in a separate PR~~ Found the cause, `conftest.py` is per directory and needs to be in any arbitrary directory that holds C++ test
* Two tests `test_api` and `test_tensorexpr` timed out on ASAN, I suspect that ASAN is now used on top of the python executable, which is slower than running native C++ code. IMO, it's ok to run these tests as before on ASAN for now
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99956
Approved by: https://github.com/clee2000, https://github.com/ZainRizvi
2023-05-09 21:24:12 +00:00
|
|
|
parser.add_argument(
|
|
|
|
|
"-k",
|
|
|
|
|
"--pytest-k-expr",
|
|
|
|
|
default="",
|
|
|
|
|
help="Pass to pytest as its -k expr argument",
|
|
|
|
|
)
|
2021-08-12 18:39:31 +00:00
|
|
|
parser.add_argument(
|
|
|
|
|
"-c",
|
|
|
|
|
"--coverage",
|
|
|
|
|
action="store_true",
|
|
|
|
|
help="enable coverage",
|
|
|
|
|
default=PYTORCH_COLLECT_COVERAGE,
|
|
|
|
|
)
|
2018-03-09 21:02:02 +00:00
|
|
|
parser.add_argument(
|
2021-08-12 18:39:31 +00:00
|
|
|
"-i",
|
|
|
|
|
"--include",
|
|
|
|
|
nargs="+",
|
2018-04-16 18:33:50 +00:00
|
|
|
choices=TestChoices(TESTS),
|
2018-03-09 21:02:02 +00:00
|
|
|
default=TESTS,
|
2021-08-12 18:39:31 +00:00
|
|
|
metavar="TESTS",
|
|
|
|
|
help="select a set of tests to include (defaults to ALL tests)."
|
|
|
|
|
" tests must be a part of the TESTS list defined in run_test.py",
|
|
|
|
|
)
|
2018-03-09 21:02:02 +00:00
|
|
|
parser.add_argument(
|
2021-08-12 18:39:31 +00:00
|
|
|
"-x",
|
|
|
|
|
"--exclude",
|
|
|
|
|
nargs="+",
|
2018-03-09 21:02:02 +00:00
|
|
|
choices=TESTS,
|
2021-08-12 18:39:31 +00:00
|
|
|
metavar="TESTS",
|
2018-03-09 21:02:02 +00:00
|
|
|
default=[],
|
2021-08-12 18:39:31 +00:00
|
|
|
help="select a set of tests to exclude",
|
|
|
|
|
)
|
2018-03-09 21:02:02 +00:00
|
|
|
parser.add_argument(
|
2021-08-12 18:39:31 +00:00
|
|
|
"--ignore-win-blocklist",
|
|
|
|
|
action="store_true",
|
|
|
|
|
help="always run blocklisted windows tests",
|
|
|
|
|
)
|
2021-11-24 02:44:14 +00:00
|
|
|
# NS: Disable target determination until it can be made more reliable
|
|
|
|
|
# parser.add_argument(
|
|
|
|
|
# "--determine-from",
|
|
|
|
|
# help="File of affected source filenames to determine which tests to run.",
|
|
|
|
|
# )
|
2020-07-09 00:24:06 +00:00
|
|
|
parser.add_argument(
|
2021-08-12 18:39:31 +00:00
|
|
|
"--continue-through-error",
|
2022-12-16 05:32:11 +00:00
|
|
|
"--keep-going",
|
2021-08-12 18:39:31 +00:00
|
|
|
action="store_true",
|
2021-08-16 22:30:24 +00:00
|
|
|
help="Runs the full test suite despite one of the tests failing",
|
|
|
|
|
default=strtobool(os.environ.get("CONTINUE_THROUGH_ERROR", "False")),
|
|
|
|
|
)
|
2024-01-26 00:17:29 +00:00
|
|
|
parser.add_argument(
|
|
|
|
|
"--pipe-logs",
|
|
|
|
|
action="store_true",
|
|
|
|
|
help="Print logs to output file while running tests. True if in CI and env var is not set",
|
|
|
|
|
default=IS_CI and not strtobool(os.environ.get("VERBOSE_TEST_LOGS", "False")),
|
|
|
|
|
)
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
"--enable-timeout",
|
|
|
|
|
action="store_true",
|
|
|
|
|
help="Set a timeout based on the test times json file. Only works if there are test times available",
|
|
|
|
|
default=IS_CI and not strtobool(os.environ.get("NO_TEST_TIMEOUT", "False")),
|
|
|
|
|
)
|
2024-02-09 16:42:25 +00:00
|
|
|
parser.add_argument(
|
|
|
|
|
"--enable-td",
|
|
|
|
|
action="store_true",
|
|
|
|
|
help="Enables removing tests based on TD",
|
|
|
|
|
default=IS_CI
|
2024-04-08 15:53:55 +00:00
|
|
|
and (
|
|
|
|
|
TEST_WITH_CROSSREF
|
|
|
|
|
or TEST_WITH_ASAN
|
2024-05-14 17:35:12 +00:00
|
|
|
or (TEST_CONFIG == "distributed" and TEST_CUDA)
|
2024-04-29 23:39:50 +00:00
|
|
|
or (IS_WINDOWS and not TEST_CUDA)
|
2024-05-06 22:02:16 +00:00
|
|
|
or TEST_CONFIG == "nogpu_AVX512"
|
|
|
|
|
or TEST_CONFIG == "nogpu_NO_AVX2"
|
2024-06-07 20:19:18 +00:00
|
|
|
or TEST_CONFIG == "default"
|
2024-04-08 15:53:55 +00:00
|
|
|
)
|
2024-05-04 03:08:44 +00:00
|
|
|
and get_pr_number() is not None
|
2024-04-29 23:39:50 +00:00
|
|
|
and not strtobool(os.environ.get("NO_TD", "False"))
|
2024-05-14 17:35:12 +00:00
|
|
|
and not TEST_WITH_ROCM
|
|
|
|
|
and not IS_MACOS
|
2024-06-04 17:15:03 +00:00
|
|
|
and "xpu" not in BUILD_ENVIRONMENT
|
2024-05-14 17:35:12 +00:00
|
|
|
and "onnx" not in BUILD_ENVIRONMENT
|
2024-06-07 20:19:18 +00:00
|
|
|
and os.environ.get("GITHUB_WORKFLOW", "slow") in ("trunk", "pull"),
|
2024-02-09 16:42:25 +00:00
|
|
|
)
|
2020-10-02 18:10:12 +00:00
|
|
|
parser.add_argument(
|
2021-08-12 18:39:31 +00:00
|
|
|
"--shard",
|
2020-10-02 18:10:12 +00:00
|
|
|
nargs=2,
|
|
|
|
|
type=int,
|
2021-08-12 18:39:31 +00:00
|
|
|
help="runs a shard of the tests (taking into account other selections), e.g., "
|
|
|
|
|
"--shard 2 3 will break up the selected tests into 3 shards and run the tests "
|
|
|
|
|
"in the 2nd shard (the first number should not exceed the second)",
|
2020-10-02 18:10:12 +00:00
|
|
|
)
|
2020-10-06 14:11:37 +00:00
|
|
|
parser.add_argument(
|
2021-08-12 18:39:31 +00:00
|
|
|
"--exclude-jit-executor",
|
|
|
|
|
action="store_true",
|
|
|
|
|
help="exclude tests that are run for a specific jit config",
|
2020-10-06 14:11:37 +00:00
|
|
|
)
|
2024-01-22 18:53:54 +00:00
|
|
|
parser.add_argument(
|
|
|
|
|
"--exclude-torch-export-tests",
|
|
|
|
|
action="store_true",
|
|
|
|
|
help="exclude torch export tests",
|
|
|
|
|
)
|
2024-12-10 22:15:31 +00:00
|
|
|
parser.add_argument(
|
|
|
|
|
"--exclude-aot-dispatch-tests",
|
|
|
|
|
action="store_true",
|
|
|
|
|
help="exclude aot dispatch tests",
|
|
|
|
|
)
|
2021-08-24 15:01:36 +00:00
|
|
|
parser.add_argument(
|
|
|
|
|
"--exclude-distributed-tests",
|
|
|
|
|
action="store_true",
|
|
|
|
|
help="exclude distributed tests",
|
|
|
|
|
)
|
2024-01-18 15:56:15 +00:00
|
|
|
parser.add_argument(
|
|
|
|
|
"--exclude-inductor-tests",
|
|
|
|
|
action="store_true",
|
|
|
|
|
help="exclude inductor tests",
|
|
|
|
|
)
|
2022-02-22 14:52:11 +00:00
|
|
|
parser.add_argument(
|
|
|
|
|
"--dry-run",
|
|
|
|
|
action="store_true",
|
|
|
|
|
help="Only list the test that will run.",
|
|
|
|
|
)
|
2022-08-22 20:07:23 +00:00
|
|
|
parser.add_argument(
|
|
|
|
|
"--xdoctest-command",
|
2023-03-26 04:52:55 +00:00
|
|
|
default="all",
|
2022-08-22 20:07:23 +00:00
|
|
|
help=(
|
|
|
|
|
"Control the specific doctest action. "
|
|
|
|
|
"Use 'list' to simply parse doctests and check syntax. "
|
|
|
|
|
"Use 'all' to execute all doctests or specify a specific "
|
2023-03-26 04:52:55 +00:00
|
|
|
"doctest to run"
|
|
|
|
|
),
|
2022-08-22 20:07:23 +00:00
|
|
|
)
|
2023-07-05 14:34:44 +00:00
|
|
|
parser.add_argument(
|
|
|
|
|
"--no-translation-validation",
|
|
|
|
|
action="store_false",
|
|
|
|
|
help="Run tests without translation validation.",
|
|
|
|
|
)
|
2024-10-22 16:48:57 +00:00
|
|
|
parser.add_argument(
|
|
|
|
|
"--upload-artifacts-while-running",
|
|
|
|
|
action="store_true",
|
|
|
|
|
)
|
2023-02-28 19:24:37 +00:00
|
|
|
|
|
|
|
|
group = parser.add_mutually_exclusive_group()
|
|
|
|
|
group.add_argument(
|
|
|
|
|
"--dynamo",
|
|
|
|
|
action="store_true",
|
|
|
|
|
help="Run tests with TorchDynamo+EagerBackend turned on",
|
|
|
|
|
)
|
|
|
|
|
group.add_argument(
|
|
|
|
|
"--inductor",
|
|
|
|
|
action="store_true",
|
|
|
|
|
help="Run tests with TorchInductor turned on",
|
|
|
|
|
)
|
|
|
|
|
|
2024-05-23 21:08:12 +00:00
|
|
|
args, extra = parser.parse_known_args()
|
|
|
|
|
if "--" in extra:
|
|
|
|
|
extra.remove("--")
|
|
|
|
|
args.additional_args = extra
|
|
|
|
|
return args
|
2018-03-09 21:02:02 +00:00
|
|
|
|
|
|
|
|
|
2023-03-26 04:52:55 +00:00
|
|
|
def exclude_tests(
|
|
|
|
|
exclude_list, selected_tests, exclude_message=None, exact_match=False
|
|
|
|
|
):
|
2018-04-16 18:33:50 +00:00
|
|
|
for exclude_test in exclude_list:
|
Add option to use ninja to compile ahead-of-time cpp_extensions (#32495)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/32495
Background
------------------------------
Previously, ninja was used to compile+link inline cpp_extensions and
ahead-of-time cpp_extensions were compiled with distutils. This PR adds
the ability to compile (but not link) ahead-of-time cpp_extensions with ninja.
The main motivation for this is to speed up cpp_extension builds: distutils
does not make use of parallelism. With this PR, using the new option, on my machine,
- torchvision compilation goes from 3m43s to 49s
- nestedtensor compilation goes from 2m0s to 28s.
User-facing changes
------------------------------
I added a `use_ninja` flag to BuildExtension. This defaults to
`True`. When `use_ninja` is True:
- it will attempt to use ninja.
- If we cannot use ninja, then this throws a warning and falls back to
distutils.
- Situations we cannot use ninja: Windows (NYI, I'll open a new issue
for this), if ninja cannot be found on the system.
Implementation Details
------------------------------
This PR makes this change in two steps. Please me know if it would be
easier to review this if I split this up into a stacked diff.
Those changes are:
1) refactor _write_ninja_file to separate the policy (what compiler flags
to pass) from the mechanism (how to write the ninja file and do compilation).
2) call _write_ninja_file and _run_ninja_build while building
ahead-of-time cpp_extensions. These are only used to compile objects;
distutils still handles the linking.
Change 1: refactor _write_ninja_file to seperate policy from mechanism
- I split _write_ninja_file into: _write_ninja_file and
_write_ninja_file_to_build_library
- I renamed _build_extension_module to _run_ninja_build
Change 2: Call _write_ninja_file while building ahead-of-time
cpp_extensions
- _write_ninja_file_and_compile_objects calls _write_ninja_file to only
build object files.
- We monkey-patch distutils.CCompiler.compile to call
_write_ninja_files_and_compile_objects
- distutils still handles the linking step. The linking step is not a
bottleneck so it was not a concern.
- This change only works on unix-based systems. Our code for windows
goes down a different codepath and I did not want to mess with that.
- If a system does not support ninja, we raise a warning and fall back
to the original compilation path.
Test Plan
------------------------------
Adhoc testing
- I built torchvision using pytorch master and printed out the build
commands. Next, I used this branch to build torchvision and looked at
the ninja file. I compared the ninja file with the build commands and
asserted that they were functionally the same.
- I repeated the above for pytorch/nestedtensor.
PyTorch test suite
- I split `test_cpp_extensions` into `test_cpp_extensions_aot` and
`test_cpp_extensions_jit`. The AOT (ahead-of-time) version tests
ahead-of-time and the JIT version tests just-in-time (not to be confused
with TorchScript)
- `test_cpp_extensions_aot` gets run TWICE by run_test.py, once with
a module that was built with ninja, and once with a module that was
built without ninja.
- run_test.py asserts that when we are building with use_ninja=True,
ninja is actually available on the system.
Test Plan: Imported from OSS
Differential Revision: D19730432
Pulled By: zou3519
fbshipit-source-id: 819590d01cf65e8da5a1e8019b8b3084792fee90
2020-02-06 02:44:19 +00:00
|
|
|
tests_copy = selected_tests[:]
|
2018-04-16 18:33:50 +00:00
|
|
|
for test in tests_copy:
|
2023-03-26 04:52:55 +00:00
|
|
|
if (
|
|
|
|
|
not exact_match and test.startswith(exclude_test)
|
|
|
|
|
) or test == exclude_test:
|
2018-04-16 18:33:50 +00:00
|
|
|
if exclude_message is not None:
|
2023-07-19 14:40:18 +00:00
|
|
|
print_to_stderr(f"Excluding {test} {exclude_message}")
|
2018-04-16 18:33:50 +00:00
|
|
|
selected_tests.remove(test)
|
|
|
|
|
return selected_tests
|
|
|
|
|
|
|
|
|
|
|
2023-08-16 18:23:09 +00:00
|
|
|
def must_serial(file: Union[str, ShardedTest]) -> bool:
|
|
|
|
|
if isinstance(file, ShardedTest):
|
|
|
|
|
file = file.name
|
2022-10-03 16:59:39 +00:00
|
|
|
return (
|
2023-03-26 04:52:55 +00:00
|
|
|
os.getenv("PYTORCH_TEST_RUN_EVERYTHING_IN_SERIAL", "0") == "1"
|
Do not collect and skip non-disabled tests when rerunning disabled tests (#102107)
The console log blows up to much when running in rerun disabled tests mode (x50) https://hud.pytorch.org/pytorch/pytorch/commit/e132f09e8878418fb98a4b76a441a324452354ec. Each log is around 1GB and the whole uncompressed logs is ~50GB. After compression, it will be around 1GB, still too big. The increase comes mainly from the multiple SKIPPED message for non-disabled tests, which is expected due to how SkipTest and pytest-flakyfinder currently work.
I update `test/conftest.py` to completely ignore skipped tests when rerunning disabled test instead of collecting then skipping 50 tests each. The benefit of doing is is much more than I originally expect:
* Rerun disabled tests jobs now finish in less than half an hour as they should be
* Fix OOM runner crash because of too many collected tests
* Fix verbosity issue as now only disabled tests are run x50 times. There are only few hundreds of them atm
* Fix timed out issue when rerunning disabled distributed and ASAN tests. They are just too slow when running at x50
### Testing
When rerunning disabled tests https://github.com/pytorch/pytorch/actions/runs/5084508614, only disabled tests on the platform are run, for example `test_ops_jit` on https://ossci-raw-job-status.s3.amazonaws.com/log/13770164954 only ran 100 tests (`test_variant_consistency_jit_linalg_lu_cuda_float32` + `test_variant_consistency_jit_linalg_lu_factor_cuda_complex64`) x50.
```
Executing ['/opt/conda/envs/py_3.10/bin/python', '-bb', 'test_ops_jit.py', '--shard-id=1', '--num-shards=2', '-v', '-vv', '-rfEX', '-p', 'no:xdist', '--use-pytest', '--sc=test_ops_jit_1', '--flake-finder', '--flake-runs=50', '--import-slow-tests', '--import-disabled-tests', '--rerun-disabled-tests'] ... [2023-05-25 21:32:49.763856]
Expand the folded group to see the log file of test_ops_jit 2/2
##[group]PRINTING LOG FILE of test_ops_jit 2/2 (/var/lib/jenkins/workspace/test/test-reports/test_ops_jit_h2wr_t2c.log)
Test results will be stored in test-reports/python-pytest/test_ops_jit/test_ops_jit-51a83bd44549074e.xml
============================= test session starts ==============================
platform linux -- Python 3.10.11, pytest-7.3.1, pluggy-1.0.0 -- /opt/conda/envs/py_3.10/bin/python
cachedir: .pytest_cache
hypothesis profile 'pytorch_ci' -> database=None, max_examples=50, derandomize=True, suppress_health_check=[HealthCheck.too_slow]
rootdir: /var/lib/jenkins/workspace
configfile: pytest.ini
plugins: hypothesis-5.35.1, cpp-2.3.0, flakefinder-1.1.0, rerunfailures-11.1.2, shard-0.1.2, xdist-3.3.0, xdoctest-1.1.0
collecting ... collected 1084 items
Running 100 items in this shard: test/test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_cuda_float32 (x50), test/test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_factor_cuda_complex64 (x50)
stepcurrent: Cannot find last run test, not skipping
test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_cuda_float32 PASSED [2.1876s] [ 1%]
test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_factor_cuda_complex64 PASSED [4.5615s] [ 2%]
```
* [pull](https://github.com/pytorch/pytorch/actions/runs/5093566864)
* [trunk](https://github.com/pytorch/pytorch/actions/runs/5095364311)
* [periodic](https://github.com/pytorch/pytorch/actions/runs/5095378850)
* [slow](https://github.com/pytorch/pytorch/actions/runs/5095390285)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/102107
Approved by: https://github.com/clee2000, https://github.com/malfet
2023-05-27 12:10:32 +00:00
|
|
|
or DISTRIBUTED_TEST_PREFIX in os.getenv("TEST_CONFIG", "")
|
|
|
|
|
or DISTRIBUTED_TEST_PREFIX in file
|
2023-03-26 04:52:55 +00:00
|
|
|
or file in CUSTOM_HANDLERS
|
|
|
|
|
or file in RUN_PARALLEL_BLOCKLIST
|
|
|
|
|
or file in CI_SERIAL_LIST
|
|
|
|
|
or file in JIT_EXECUTOR_TESTS
|
[ONNX] Run ONNX tests as part of standard run_test script (#99215)
<!--
copilot:all
-->
### <samp>🤖 Generated by Copilot at dcbf7e2</samp>
### Summary
📝🧹🚩
<!--
1. 📝 for simplifying the `./scripts/onnx/test.sh` script
2. 🧹 for refactoring the `test/onnx/dynamo/test_exporter_api.py` file
3. 🚩 for adding the `--onnx` flag to `test/run_test.py` and updating the `TESTS` list
-->
This pull request improves the ONNX testing infrastructure in PyTorch by refactoring the test code, normalizing the scope names, adding a flag to run only the ONNX tests, and simplifying the test script.
> _To export PyTorch models to ONNX_
> _We refactored some scripts and contexts_
> _We used `common_utils`_
> _And normalized the scopes_
> _And added a flag to run the tests_
### Walkthrough
* Simplify `./scripts/onnx/test.sh` to use `run_test.py` with `--onnx` flag instead of `pytest` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-0017f5b22ae1329acb0f54af8d9811c9b6180a72dac70d7a5b89d7c23c958198L44-R46))
* Remove `onnx` test from `TESTS` list in `test/run_test.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7L127-R127)). Replace with `onnx_caffe2`.
* Add `onnx/test_pytorch_onnx_onnxruntime_cuda` and `onnx/test_models` tests to `blocklisted_tests` list in `test/run_test.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7R154-R155))
* Add `ONNX_SERIAL_LIST` list to `test/run_test.py` to specify ONNX tests that must run serially ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7R296-R301))
* Add `ONNX_TESTS` list to `test/run_test.py` to store all ONNX tests ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7R370))
* Add `--onnx` flag to `parse_args` function in `test/run_test.py` to run only ONNX tests ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7R920-R928))
* Include `ONNX_SERIAL_LIST` in `must_serial` function in `test/run_test.py` to run ONNX tests serially or parallelly based on memory usage ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7R1120))
* Filter selected tests based on `--onnx` flag in `get_selected_tests` function in `test/run_test.py` to exclude non-ONNX tests ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7R1158-R1165))
### Other minor changes to accommodate this change
* Replace `unittest` module with `common_utils.TestCase` in `test/onnx/dynamo/test_exporter_api.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L4), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L29-R28), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L71-R70), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L147-R146))
* Import `TemporaryFileName` class from `common_utils` in `test/onnx/dynamo/test_exporter_api.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L19-R18))
* Use `common_utils.TemporaryFileName` instead of `TemporaryFileName` in `TestDynamoExportAPI` class in `test/onnx/dynamo/test_exporter_api.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L92-R91), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L110-R109), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L129-R128))
* Use `common_utils.run_tests` instead of `unittest.main` in `test/onnx/dynamo/test_exporter_api.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L155-R154))
* Add `re` module to `test/onnx/test_utility_funs.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7R6))
* Add `_remove_test_environment_prefix_from_scope_name` function to `test/onnx/test_utility_funs.py` to normalize scope names of ONNX nodes ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7R32-R58))
* Use `_remove_test_environment_prefix_from_scope_name` function to compare scope names of ONNX nodes in `TestUtilityFuns` class in `test/onnx/test_utility_funs.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7L1099-R1133), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7L1119-R1152), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7L1170-R1188), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7L1181-R1199), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7L1220-R1239), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7L1235-R1258))
Fixes #98626
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99215
Approved by: https://github.com/huydhn, https://github.com/titaiwangms
2023-04-18 00:49:08 +00:00
|
|
|
or file in ONNX_SERIAL_LIST
|
2024-01-22 23:11:41 +00:00
|
|
|
or NUM_PROCS == 1
|
2022-10-03 16:59:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
Add env PYTORCH_TEST_DO_NOT_USE_PYTEST as an option to not use pytest in unit testing (#96444)
Set environment variable
```
PYTORCH_TEST_DO_NOT_USE_PYTEST=1
```
to not use pytest in pytorch unit testing.
This change is related to some recent changes, e.g. #96210, #96016, #95844, #95659, that enabled the use of pytest in many test modules. Those test modules were testing normally before, but failed immediately after pytest is used. Sample stacktraces are:
```python
root@8e3168a83ee2:/opt/pytorch/pytorch# python test/run_test.py -v -i test_optim -- -v --save-xml
Ignoring disabled issues: []
/opt/pytorch/pytorch/test/run_test.py:1225: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
if torch.version.cuda is not None and LooseVersion(torch.version.cuda) >= "11.6":
Selected tests:
test_optim
parallel (file granularity) tests:
test_optim
serial (file granularity) tests:
Ignoring disabled issues: []
Ignoring disabled issues: []
Running test_optim ... [2023-03-09 12:51:59.358110]
Executing ['/usr/local/bin/python', '-bb', 'test_optim.py', '-v', '--save-xml', '-v', '--use-pytest', '-vv', '-rfEX', '-x', '--reruns=2'] ... [2023-03-09 12:51:59.358810]
Test results will be stored in test-reports/python-pytest/test_optim/test_optim-5e41643c8bac8ace.xml
Traceback (most recent call last):
File "/opt/pytorch/pytorch/test/test_optim.py", line 4581, in <module>
run_tests()
File "/opt/pytorch/pytorch/torch/testing/_internal/common_utils.py", line 796, in run_tests
exit_code = pytest.main(args=pytest_args)
File "/usr/local/lib/python3.10/site-packages/_pytest/config/__init__.py", line 148, in main
config = _prepareconfig(args, plugins)
File "/usr/local/lib/python3.10/site-packages/_pytest/config/__init__.py", line 329, in _prepareconfig
config = pluginmanager.hook.pytest_cmdline_parse(
File "/usr/local/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
File "/usr/local/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 55, in _multicall
gen.send(outcome)
File "/usr/local/lib/python3.10/site-packages/_pytest/helpconfig.py", line 103, in pytest_cmdline_parse
config: Config = outcome.get_result()
File "/usr/local/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
raise ex[1].with_traceback(ex[2])
File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
res = hook_impl.function(*args)
File "/usr/local/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1060, in pytest_cmdline_parse
self.parse(args)
File "/usr/local/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1348, in parse
self._preparse(args, addopts=addopts)
File "/usr/local/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1231, in _preparse
self.pluginmanager.load_setuptools_entrypoints("pytest11")
File "/usr/local/lib/python3.10/site-packages/pluggy/_manager.py", line 287, in load_setuptools_entrypoints
plugin = ep.load()
File "/usr/local/lib/python3.10/importlib/metadata/__init__.py", line 171, in load
module = import_module(match.group('module'))
File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "/usr/local/lib/python3.10/site-packages/_pytest/assertion/rewrite.py", line 168, in exec_module
exec(co, module.__dict__)
File "/usr/local/lib/python3.10/site-packages/xdist/looponfail.py", line 16, in <module>
import execnet
File "/usr/local/lib/python3.10/site-packages/execnet/__init__.py", line 14, in <module>
from .gateway_base import DataFormatError
File "/usr/local/lib/python3.10/site-packages/execnet/gateway_base.py", line 1138, in <module>
FLOAT_FORMAT_SIZE = struct.calcsize(FLOAT_FORMAT)
BytesWarning: Comparison between bytes and string
FINISHED PRINTING LOG FILE of test_optim (/opt/pytorch/pytorch/test/test-reports/test_optim_1pnlesrz.log)
test_optim failed!
Traceback (most recent call last):
File "/opt/pytorch/pytorch/test/run_test.py", line 1428, in <module>
main()
File "/opt/pytorch/pytorch/test/run_test.py", line 1386, in main
raise RuntimeError(
RuntimeError: test_optim failed!
Tip: You can keep running tests even on failure by passing --keep-going to run_test.py.
If running on CI, add the 'keep-going' label to your PR and rerun your jobs.
```
I'd like to propose this option that allows users to use the good old python unit test way instead of pytest to run their testing in CI.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/96444
Approved by: https://github.com/malfet
2023-03-10 01:32:11 +00:00
|
|
|
def can_run_in_pytest(test):
|
2023-03-26 04:52:55 +00:00
|
|
|
return os.getenv("PYTORCH_TEST_DO_NOT_USE_PYTEST", "0") == "0"
|
Add env PYTORCH_TEST_DO_NOT_USE_PYTEST as an option to not use pytest in unit testing (#96444)
Set environment variable
```
PYTORCH_TEST_DO_NOT_USE_PYTEST=1
```
to not use pytest in pytorch unit testing.
This change is related to some recent changes, e.g. #96210, #96016, #95844, #95659, that enabled the use of pytest in many test modules. Those test modules were testing normally before, but failed immediately after pytest is used. Sample stacktraces are:
```python
root@8e3168a83ee2:/opt/pytorch/pytorch# python test/run_test.py -v -i test_optim -- -v --save-xml
Ignoring disabled issues: []
/opt/pytorch/pytorch/test/run_test.py:1225: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
if torch.version.cuda is not None and LooseVersion(torch.version.cuda) >= "11.6":
Selected tests:
test_optim
parallel (file granularity) tests:
test_optim
serial (file granularity) tests:
Ignoring disabled issues: []
Ignoring disabled issues: []
Running test_optim ... [2023-03-09 12:51:59.358110]
Executing ['/usr/local/bin/python', '-bb', 'test_optim.py', '-v', '--save-xml', '-v', '--use-pytest', '-vv', '-rfEX', '-x', '--reruns=2'] ... [2023-03-09 12:51:59.358810]
Test results will be stored in test-reports/python-pytest/test_optim/test_optim-5e41643c8bac8ace.xml
Traceback (most recent call last):
File "/opt/pytorch/pytorch/test/test_optim.py", line 4581, in <module>
run_tests()
File "/opt/pytorch/pytorch/torch/testing/_internal/common_utils.py", line 796, in run_tests
exit_code = pytest.main(args=pytest_args)
File "/usr/local/lib/python3.10/site-packages/_pytest/config/__init__.py", line 148, in main
config = _prepareconfig(args, plugins)
File "/usr/local/lib/python3.10/site-packages/_pytest/config/__init__.py", line 329, in _prepareconfig
config = pluginmanager.hook.pytest_cmdline_parse(
File "/usr/local/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
File "/usr/local/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 55, in _multicall
gen.send(outcome)
File "/usr/local/lib/python3.10/site-packages/_pytest/helpconfig.py", line 103, in pytest_cmdline_parse
config: Config = outcome.get_result()
File "/usr/local/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
raise ex[1].with_traceback(ex[2])
File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
res = hook_impl.function(*args)
File "/usr/local/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1060, in pytest_cmdline_parse
self.parse(args)
File "/usr/local/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1348, in parse
self._preparse(args, addopts=addopts)
File "/usr/local/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1231, in _preparse
self.pluginmanager.load_setuptools_entrypoints("pytest11")
File "/usr/local/lib/python3.10/site-packages/pluggy/_manager.py", line 287, in load_setuptools_entrypoints
plugin = ep.load()
File "/usr/local/lib/python3.10/importlib/metadata/__init__.py", line 171, in load
module = import_module(match.group('module'))
File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "/usr/local/lib/python3.10/site-packages/_pytest/assertion/rewrite.py", line 168, in exec_module
exec(co, module.__dict__)
File "/usr/local/lib/python3.10/site-packages/xdist/looponfail.py", line 16, in <module>
import execnet
File "/usr/local/lib/python3.10/site-packages/execnet/__init__.py", line 14, in <module>
from .gateway_base import DataFormatError
File "/usr/local/lib/python3.10/site-packages/execnet/gateway_base.py", line 1138, in <module>
FLOAT_FORMAT_SIZE = struct.calcsize(FLOAT_FORMAT)
BytesWarning: Comparison between bytes and string
FINISHED PRINTING LOG FILE of test_optim (/opt/pytorch/pytorch/test/test-reports/test_optim_1pnlesrz.log)
test_optim failed!
Traceback (most recent call last):
File "/opt/pytorch/pytorch/test/run_test.py", line 1428, in <module>
main()
File "/opt/pytorch/pytorch/test/run_test.py", line 1386, in main
raise RuntimeError(
RuntimeError: test_optim failed!
Tip: You can keep running tests even on failure by passing --keep-going to run_test.py.
If running on CI, add the 'keep-going' label to your PR and rerun your jobs.
```
I'd like to propose this option that allows users to use the good old python unit test way instead of pytest to run their testing in CI.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/96444
Approved by: https://github.com/malfet
2023-03-10 01:32:11 +00:00
|
|
|
|
|
|
|
|
|
2025-01-21 19:22:20 +00:00
|
|
|
def get_selected_tests(options) -> list[str]:
|
2018-03-09 21:02:02 +00:00
|
|
|
selected_tests = options.include
|
|
|
|
|
|
2024-11-20 22:53:09 +00:00
|
|
|
# for s390x, override defaults
|
|
|
|
|
if IS_S390X and selected_tests == TESTS:
|
|
|
|
|
selected_tests = S390X_TESTLIST
|
|
|
|
|
|
2021-08-24 15:01:36 +00:00
|
|
|
# filter if there's JIT only and distributed only test options
|
|
|
|
|
if options.jit:
|
|
|
|
|
selected_tests = list(
|
|
|
|
|
filter(lambda test_name: "jit" in test_name, selected_tests)
|
2021-08-25 18:19:49 +00:00
|
|
|
)
|
2021-08-24 15:01:36 +00:00
|
|
|
|
|
|
|
|
if options.distributed_tests:
|
|
|
|
|
selected_tests = list(
|
2023-03-31 18:36:53 +00:00
|
|
|
filter(lambda test_name: test_name in DISTRIBUTED_TESTS, selected_tests)
|
2021-08-25 18:19:49 +00:00
|
|
|
)
|
2021-08-24 15:01:36 +00:00
|
|
|
|
2021-08-26 16:27:47 +00:00
|
|
|
# Filter to only run core tests when --core option is specified
|
|
|
|
|
if options.core:
|
|
|
|
|
selected_tests = list(
|
|
|
|
|
filter(lambda test_name: test_name in CORE_TEST_LIST, selected_tests)
|
|
|
|
|
)
|
|
|
|
|
|
2023-03-20 20:19:41 +00:00
|
|
|
# Filter to only run functorch tests when --functorch option is specified
|
2022-07-24 23:14:13 +00:00
|
|
|
if options.functorch:
|
2022-10-14 17:26:49 +00:00
|
|
|
selected_tests = [tname for tname in selected_tests if tname in FUNCTORCH_TESTS]
|
2022-07-24 23:14:13 +00:00
|
|
|
|
Discover and run C++ tests with run_test.py (#99559)
This depends on [pytest-cpp](https://github.com/pytest-dev/pytest-cpp) to discover and run C++ tests with pytest. C++ tests are built under `${WORKSPACE}/build/bin` directory and copied to the test job under the same path.
* To expose them to `run_test`, I choose to use the mock path prefix `cpp`, for example `build/bin/c10_Array_test` would be named as `cpp/c10_Array_test` and the `python test/run_test.py --cpp -i cpp/c10_Array_test` would run the test in the same way as other Python tests. I could copy them from `build/bin` to `test/cpp`, but it will be mixed with the source code and CMake file. So this looks easier
* Some executable under `build/bin` are not C++ tests, and they are exclude, for example `build/bin/torch_shm_manager`
* C++ tests need to run with pytest directly as python command doesn't understand it
* The change is gated by the new `--cpp` argument to `run_test.py`, for example `python test/run_test.py --cpp` will run all available C++ tests
* The tests can be run in parallel
* Failing tests can be retried with `--reruns=2` and `--sw`
```
============================= test session starts ==============================
platform darwin -- Python 3.9.15, pytest-7.2.0, pluggy-1.0.0 -- /Users/huydo/miniconda3/envs/py3.9/bin/python3
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/Users/huydo/Storage/mine/pytorch/test/.hypothesis/examples')
rootdir: /Users/huydo/Storage/mine/pytorch, configfile: pytest.ini
plugins: xdoctest-1.1.0, cpp-2.3.0, rerunfailures-10.3, shard-0.1.2, flakefinder-1.1.0, hypothesis-6.56.4, xdist-3.0.2, repeat-0.9.1
collecting ... collected 3 items / 2 deselected / 1 selected
Running 1 items in this shard: build/bin/scalar_tensor_test::TestScalarTensor.TestScalarTensorMPS
stepwise: skipping 2 already passed items.
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS RERUN [100%]
../build/bin/scalar_tensor_test::TestScalarTensor::TestScalarTensorMPS FAILED [100%]
```
* `--import-slow-tests` and `--import-disabled-tests` won't work for now and that's ok to have it as a future task.
I also add `pytest-cpp==2.3.0` to Linux Docker, MacOS, and Windows.
### Testing
Build PyTorch and run `python test/run_test.py --cpp` on my laptop. CI change would come later in a separate PR. Also running `python test/run_test.py --help` now shows all C++ test discovered under `build/bin`
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99559
Approved by: https://github.com/clee2000
2023-04-22 00:23:31 +00:00
|
|
|
if options.cpp:
|
|
|
|
|
selected_tests = [tname for tname in selected_tests if tname in CPP_TESTS]
|
|
|
|
|
else:
|
|
|
|
|
# Exclude all C++ tests otherwise as they are still handled differently
|
|
|
|
|
# than Python test at the moment
|
|
|
|
|
options.exclude.extend(CPP_TESTS)
|
|
|
|
|
|
2022-11-10 21:32:41 +00:00
|
|
|
if options.mps:
|
2024-10-04 21:52:35 +00:00
|
|
|
selected_tests = [
|
|
|
|
|
"test_mps",
|
|
|
|
|
"test_metal",
|
|
|
|
|
"test_modules",
|
|
|
|
|
"nn/test_convolution",
|
|
|
|
|
"nn/test_dropout",
|
|
|
|
|
"nn/test_pooling",
|
|
|
|
|
"test_view_ops",
|
|
|
|
|
"test_nn",
|
[Inductor] Implement primitive Metal compiler (#143893)
Still work in progress, only works for element wise operations. Current implementation could be used to turn something like
```python
def f(x):
return x[:,::2].sin() + x[:, 1::2].cos()
```
into the following shader
```python
# Topologically Sorted Source Nodes: [sin, cos, add], Original ATen: [aten.sin, aten.cos, aten.add]
# Source node to ATen node mapping:
# add => add
# cos => cos
# sin => sin
# Graph fragment:
# %sin : [num_users=1] = call_function[target=torch.ops.aten.sin.default](args = (%slice_2,), kwargs = {})
# %cos : [num_users=1] = call_function[target=torch.ops.aten.cos.default](args = (%slice_4,), kwargs = {})
# %add : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sin, %cos), kwargs = {})
mps_lib = torch.mps._compile_shader("""
kernel void kernel_0(
device float* out_ptr0,
constant float* in_ptr0,
uint xindex [[thread_position_in_grid]]
) {
int x0 = xindex;
auto tmp0 = in_ptr0[2*x0];
auto tmp1 = metal::precise::sin(tmp0);
auto tmp2 = in_ptr0[2*x0 + 1];
auto tmp3 = metal::precise::cos(tmp2);
auto tmp4 = tmp1 + tmp3;
out_ptr0[x0] = static_cast<float>(tmp4);
}
""")
```
Pull Request resolved: https://github.com/pytorch/pytorch/pull/143893
Approved by: https://github.com/jansel
ghstack dependencies: #143891, #143892
2024-12-28 00:08:37 +00:00
|
|
|
"inductor/test_mps_basic",
|
2024-10-04 21:52:35 +00:00
|
|
|
]
|
2022-11-10 21:32:41 +00:00
|
|
|
else:
|
|
|
|
|
# Exclude all mps tests otherwise
|
2023-03-26 04:52:55 +00:00
|
|
|
options.exclude.extend(["test_mps", "test_metal"])
|
2022-11-10 21:32:41 +00:00
|
|
|
|
2024-01-23 08:20:37 +00:00
|
|
|
if options.xpu:
|
|
|
|
|
selected_tests = exclude_tests(XPU_BLOCKLIST, selected_tests, "on XPU")
|
|
|
|
|
else:
|
|
|
|
|
# Exclude all xpu specifc tests otherwise
|
|
|
|
|
options.exclude.extend(XPU_TEST)
|
|
|
|
|
|
[ONNX] Run ONNX tests as part of standard run_test script (#99215)
<!--
copilot:all
-->
### <samp>🤖 Generated by Copilot at dcbf7e2</samp>
### Summary
📝🧹🚩
<!--
1. 📝 for simplifying the `./scripts/onnx/test.sh` script
2. 🧹 for refactoring the `test/onnx/dynamo/test_exporter_api.py` file
3. 🚩 for adding the `--onnx` flag to `test/run_test.py` and updating the `TESTS` list
-->
This pull request improves the ONNX testing infrastructure in PyTorch by refactoring the test code, normalizing the scope names, adding a flag to run only the ONNX tests, and simplifying the test script.
> _To export PyTorch models to ONNX_
> _We refactored some scripts and contexts_
> _We used `common_utils`_
> _And normalized the scopes_
> _And added a flag to run the tests_
### Walkthrough
* Simplify `./scripts/onnx/test.sh` to use `run_test.py` with `--onnx` flag instead of `pytest` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-0017f5b22ae1329acb0f54af8d9811c9b6180a72dac70d7a5b89d7c23c958198L44-R46))
* Remove `onnx` test from `TESTS` list in `test/run_test.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7L127-R127)). Replace with `onnx_caffe2`.
* Add `onnx/test_pytorch_onnx_onnxruntime_cuda` and `onnx/test_models` tests to `blocklisted_tests` list in `test/run_test.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7R154-R155))
* Add `ONNX_SERIAL_LIST` list to `test/run_test.py` to specify ONNX tests that must run serially ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7R296-R301))
* Add `ONNX_TESTS` list to `test/run_test.py` to store all ONNX tests ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7R370))
* Add `--onnx` flag to `parse_args` function in `test/run_test.py` to run only ONNX tests ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7R920-R928))
* Include `ONNX_SERIAL_LIST` in `must_serial` function in `test/run_test.py` to run ONNX tests serially or parallelly based on memory usage ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7R1120))
* Filter selected tests based on `--onnx` flag in `get_selected_tests` function in `test/run_test.py` to exclude non-ONNX tests ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-e72503c9e3e8766e2d1bacf3fad7b88aa166e0e90a7e103e7df99357a35df8d7R1158-R1165))
### Other minor changes to accommodate this change
* Replace `unittest` module with `common_utils.TestCase` in `test/onnx/dynamo/test_exporter_api.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L4), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L29-R28), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L71-R70), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L147-R146))
* Import `TemporaryFileName` class from `common_utils` in `test/onnx/dynamo/test_exporter_api.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L19-R18))
* Use `common_utils.TemporaryFileName` instead of `TemporaryFileName` in `TestDynamoExportAPI` class in `test/onnx/dynamo/test_exporter_api.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L92-R91), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L110-R109), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L129-R128))
* Use `common_utils.run_tests` instead of `unittest.main` in `test/onnx/dynamo/test_exporter_api.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-4545f0c15c73ebe90a875e9bee6c5ca4b6b92fb1ed0ec5560d1568e0f6339d02L155-R154))
* Add `re` module to `test/onnx/test_utility_funs.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7R6))
* Add `_remove_test_environment_prefix_from_scope_name` function to `test/onnx/test_utility_funs.py` to normalize scope names of ONNX nodes ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7R32-R58))
* Use `_remove_test_environment_prefix_from_scope_name` function to compare scope names of ONNX nodes in `TestUtilityFuns` class in `test/onnx/test_utility_funs.py` ([link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7L1099-R1133), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7L1119-R1152), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7L1170-R1188), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7L1181-R1199), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7L1220-R1239), [link](https://github.com/pytorch/pytorch/pull/99215/files?diff=unified&w=0#diff-da71d2c81c9dc7ac0c47ff086fded82e4edcb67ba0cd3d8b5c983d7467343bc7L1235-R1258))
Fixes #98626
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99215
Approved by: https://github.com/huydhn, https://github.com/titaiwangms
2023-04-18 00:49:08 +00:00
|
|
|
# Filter to only run onnx tests when --onnx option is specified
|
|
|
|
|
onnx_tests = [tname for tname in selected_tests if tname in ONNX_TESTS]
|
|
|
|
|
if options.onnx:
|
|
|
|
|
selected_tests = onnx_tests
|
|
|
|
|
else:
|
|
|
|
|
# Exclude all onnx tests otherwise
|
|
|
|
|
options.exclude.extend(onnx_tests)
|
|
|
|
|
|
2021-08-24 15:01:36 +00:00
|
|
|
# process exclusion
|
2020-10-06 14:11:37 +00:00
|
|
|
if options.exclude_jit_executor:
|
|
|
|
|
options.exclude.extend(JIT_EXECUTOR_TESTS)
|
|
|
|
|
|
2021-08-24 15:01:36 +00:00
|
|
|
if options.exclude_distributed_tests:
|
|
|
|
|
options.exclude.extend(DISTRIBUTED_TESTS)
|
|
|
|
|
|
2024-01-18 15:56:15 +00:00
|
|
|
if options.exclude_inductor_tests:
|
|
|
|
|
options.exclude.extend(INDUCTOR_TESTS)
|
|
|
|
|
|
2024-01-22 18:53:54 +00:00
|
|
|
if options.exclude_torch_export_tests:
|
|
|
|
|
options.exclude.extend(TORCH_EXPORT_TESTS)
|
|
|
|
|
|
2024-12-10 22:15:31 +00:00
|
|
|
if options.exclude_aot_dispatch_tests:
|
|
|
|
|
options.exclude.extend(AOT_DISPATCH_TESTS)
|
|
|
|
|
|
2022-04-07 22:37:09 +00:00
|
|
|
# these tests failing in CUDA 11.6 temporary disabling. issue https://github.com/pytorch/pytorch/issues/75375
|
2023-11-03 17:22:46 +00:00
|
|
|
if torch.version.cuda is not None:
|
2022-04-07 22:37:09 +00:00
|
|
|
options.exclude.extend(["distributions/test_constraints"])
|
|
|
|
|
|
2024-02-14 20:52:23 +00:00
|
|
|
# these tests failing in Python 3.12 temporarily disabling
|
|
|
|
|
if sys.version_info >= (3, 12):
|
|
|
|
|
options.exclude.extend(
|
|
|
|
|
[
|
|
|
|
|
"functorch/test_dims",
|
|
|
|
|
"functorch/test_rearrange",
|
|
|
|
|
"functorch/test_parsing",
|
|
|
|
|
"functorch/test_memory_efficient_fusion",
|
|
|
|
|
"torch_np/numpy_tests/core/test_multiarray",
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
|
2018-04-16 18:33:50 +00:00
|
|
|
selected_tests = exclude_tests(options.exclude, selected_tests)
|
|
|
|
|
|
2021-08-12 18:39:31 +00:00
|
|
|
if sys.platform == "win32" and not options.ignore_win_blocklist:
|
|
|
|
|
target_arch = os.environ.get("VSCMD_ARG_TGT_ARCH")
|
|
|
|
|
if target_arch != "x64":
|
|
|
|
|
WINDOWS_BLOCKLIST.append("cpp_extensions_aot_no_ninja")
|
|
|
|
|
WINDOWS_BLOCKLIST.append("cpp_extensions_aot_ninja")
|
|
|
|
|
WINDOWS_BLOCKLIST.append("cpp_extensions_jit")
|
|
|
|
|
WINDOWS_BLOCKLIST.append("jit")
|
|
|
|
|
WINDOWS_BLOCKLIST.append("jit_fuser")
|
2018-04-12 10:12:39 +00:00
|
|
|
|
2021-08-12 18:39:31 +00:00
|
|
|
selected_tests = exclude_tests(WINDOWS_BLOCKLIST, selected_tests, "on Windows")
|
2018-03-09 21:02:02 +00:00
|
|
|
|
2018-08-06 21:48:45 +00:00
|
|
|
elif TEST_WITH_ROCM:
|
2021-08-12 18:39:31 +00:00
|
|
|
selected_tests = exclude_tests(ROCM_BLOCKLIST, selected_tests, "on ROCm")
|
2018-08-06 21:48:45 +00:00
|
|
|
|
2024-11-20 22:53:09 +00:00
|
|
|
elif IS_S390X:
|
|
|
|
|
selected_tests = exclude_tests(
|
|
|
|
|
DISTRIBUTED_TESTS,
|
|
|
|
|
selected_tests,
|
|
|
|
|
"Skip distributed tests on s390x",
|
|
|
|
|
)
|
|
|
|
|
|
2022-01-06 16:53:50 +00:00
|
|
|
# skip all distributed tests if distributed package is not available.
|
|
|
|
|
if not dist.is_available():
|
2023-03-26 04:52:55 +00:00
|
|
|
selected_tests = exclude_tests(
|
|
|
|
|
DISTRIBUTED_TESTS,
|
|
|
|
|
selected_tests,
|
|
|
|
|
"PyTorch is built without distributed support.",
|
|
|
|
|
)
|
2022-01-06 16:53:50 +00:00
|
|
|
|
2022-02-15 16:33:59 +00:00
|
|
|
# skip tests that require LAPACK when it's not available
|
|
|
|
|
if not torch._C.has_lapack:
|
2023-03-26 04:52:55 +00:00
|
|
|
selected_tests = exclude_tests(
|
|
|
|
|
TESTS_REQUIRING_LAPACK,
|
|
|
|
|
selected_tests,
|
|
|
|
|
"PyTorch is built without LAPACK support.",
|
|
|
|
|
)
|
2022-02-15 16:33:59 +00:00
|
|
|
|
2023-07-10 18:20:08 +00:00
|
|
|
if TEST_WITH_SLOW_GRADCHECK:
|
2023-03-26 04:52:55 +00:00
|
|
|
selected_tests = exclude_tests(
|
|
|
|
|
TESTS_NOT_USING_GRADCHECK,
|
|
|
|
|
selected_tests,
|
|
|
|
|
"Running in slow gradcheck mode, skipping tests "
|
|
|
|
|
"that don't use gradcheck.",
|
|
|
|
|
exact_match=True,
|
|
|
|
|
)
|
2022-11-02 17:52:15 +00:00
|
|
|
|
2023-03-31 18:36:53 +00:00
|
|
|
selected_tests = [parse_test_module(x) for x in selected_tests]
|
2023-08-16 18:23:09 +00:00
|
|
|
return selected_tests
|
2023-03-31 18:36:53 +00:00
|
|
|
|
|
|
|
|
|
2025-01-21 19:22:20 +00:00
|
|
|
def load_test_times_from_file(file: str) -> dict[str, Any]:
|
2023-10-30 23:31:40 +00:00
|
|
|
# Load previous test times to make sharding decisions
|
2023-08-21 18:39:55 +00:00
|
|
|
path = os.path.join(str(REPO_ROOT), file)
|
|
|
|
|
if not os.path.exists(path):
|
2023-10-03 01:22:44 +00:00
|
|
|
print_to_stderr(
|
2023-10-30 23:31:40 +00:00
|
|
|
f"::warning:: Failed to find test times file `{path}`. Using round robin sharding."
|
2023-10-03 01:22:44 +00:00
|
|
|
)
|
2023-08-21 18:39:55 +00:00
|
|
|
return {}
|
|
|
|
|
|
|
|
|
|
with open(path) as f:
|
2025-01-21 19:22:20 +00:00
|
|
|
test_times_file = cast(dict[str, Any], json.load(f))
|
2023-08-21 18:39:55 +00:00
|
|
|
build_environment = os.environ.get("BUILD_ENVIRONMENT")
|
2023-03-31 18:36:53 +00:00
|
|
|
test_config = os.environ.get("TEST_CONFIG")
|
2023-08-21 18:39:55 +00:00
|
|
|
if test_config in test_times_file.get(build_environment, {}):
|
2023-10-03 01:22:44 +00:00
|
|
|
print_to_stderr("Found test times from artifacts")
|
2023-08-21 18:39:55 +00:00
|
|
|
return test_times_file[build_environment][test_config]
|
|
|
|
|
elif test_config in test_times_file["default"]:
|
2023-10-03 01:22:44 +00:00
|
|
|
print_to_stderr(
|
2023-08-21 18:39:55 +00:00
|
|
|
f"::warning:: Gathered no stats from artifacts for {build_environment} build env"
|
|
|
|
|
f" and {test_config} test config. Using default build env and {test_config} test config instead."
|
2023-03-31 18:36:53 +00:00
|
|
|
)
|
2023-08-21 18:39:55 +00:00
|
|
|
return test_times_file["default"][test_config]
|
2023-03-31 18:36:53 +00:00
|
|
|
else:
|
2023-10-03 01:22:44 +00:00
|
|
|
print_to_stderr(
|
2023-08-21 18:39:55 +00:00
|
|
|
f"::warning:: Gathered no stats from artifacts for build env {build_environment} build env"
|
|
|
|
|
f" and {test_config} test config. Using default build env and default test config instead."
|
|
|
|
|
)
|
|
|
|
|
return test_times_file["default"]["default"]
|
2023-08-16 18:23:09 +00:00
|
|
|
|
|
|
|
|
|
2023-10-30 23:31:40 +00:00
|
|
|
def load_test_file_times(
|
|
|
|
|
file: str = ADDITIONAL_CI_FILES_FOLDER / TEST_TIMES_FILE,
|
2025-01-21 19:22:20 +00:00
|
|
|
) -> dict[str, float]:
|
|
|
|
|
return cast(dict[str, float], load_test_times_from_file(file))
|
2023-10-30 23:31:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def load_test_class_times(
|
|
|
|
|
file: str = ADDITIONAL_CI_FILES_FOLDER / TEST_CLASS_TIMES_FILE,
|
2025-01-21 19:22:20 +00:00
|
|
|
) -> dict[str, dict[str, float]]:
|
|
|
|
|
return cast(dict[str, dict[str, float]], load_test_times_from_file(file))
|
2023-10-30 23:31:40 +00:00
|
|
|
|
|
|
|
|
|
2025-01-21 19:22:20 +00:00
|
|
|
def get_sharding_opts(options) -> tuple[int, int]:
|
2023-08-16 18:23:09 +00:00
|
|
|
which_shard, num_shards = 1, 1
|
|
|
|
|
if options.shard:
|
|
|
|
|
assert len(options.shard) == 2, "Unexpected shard format"
|
|
|
|
|
assert min(options.shard) > 0, "Shards must be positive numbers"
|
|
|
|
|
which_shard, num_shards = options.shard
|
|
|
|
|
assert (
|
|
|
|
|
which_shard <= num_shards
|
|
|
|
|
), "Selected shard must be less than or equal to total number of shards"
|
2023-03-31 18:36:53 +00:00
|
|
|
|
2023-09-26 17:06:49 +00:00
|
|
|
return (which_shard, num_shards)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def do_sharding(
|
|
|
|
|
options,
|
2023-10-30 23:31:40 +00:00
|
|
|
selected_tests: Sequence[TestRun],
|
2025-01-21 19:22:20 +00:00
|
|
|
test_file_times: dict[str, float],
|
|
|
|
|
test_class_times: dict[str, dict[str, float]],
|
2023-09-26 17:06:49 +00:00
|
|
|
sort_by_time: bool = True,
|
2025-01-21 19:22:20 +00:00
|
|
|
) -> tuple[float, list[ShardedTest]]:
|
2023-09-26 17:06:49 +00:00
|
|
|
which_shard, num_shards = get_sharding_opts(options)
|
|
|
|
|
|
2023-08-22 16:36:17 +00:00
|
|
|
# Do sharding
|
|
|
|
|
shards = calculate_shards(
|
|
|
|
|
num_shards,
|
|
|
|
|
selected_tests,
|
|
|
|
|
test_file_times,
|
2023-10-30 23:31:40 +00:00
|
|
|
test_class_times=test_class_times,
|
2023-08-22 16:36:17 +00:00
|
|
|
must_serial=must_serial,
|
|
|
|
|
sort_by_time=sort_by_time,
|
|
|
|
|
)
|
2024-02-29 18:53:43 +00:00
|
|
|
return shards[which_shard - 1]
|
2018-03-09 21:02:02 +00:00
|
|
|
|
|
|
|
|
|
2023-08-16 18:23:09 +00:00
|
|
|
class TestFailure(NamedTuple):
|
2023-10-30 23:31:40 +00:00
|
|
|
test: TestRun
|
2023-08-16 18:23:09 +00:00
|
|
|
message: str
|
|
|
|
|
|
|
|
|
|
|
2023-06-24 03:10:46 +00:00
|
|
|
def run_test_module(
|
2023-10-30 23:31:40 +00:00
|
|
|
test: ShardedTest, test_directory: str, options
|
2023-08-16 18:23:09 +00:00
|
|
|
) -> Optional[TestFailure]:
|
2023-11-30 04:01:57 +00:00
|
|
|
try:
|
|
|
|
|
maybe_set_hip_visible_devies()
|
|
|
|
|
|
|
|
|
|
test_name = test.name
|
|
|
|
|
|
|
|
|
|
# Printing the date here can help diagnose which tests are slow
|
|
|
|
|
print_to_stderr(f"Running {str(test)} ... [{datetime.now()}]")
|
|
|
|
|
handler = CUSTOM_HANDLERS.get(test_name, run_test)
|
|
|
|
|
return_code = handler(test, test_directory, options)
|
|
|
|
|
assert isinstance(return_code, int) and not isinstance(
|
|
|
|
|
return_code, bool
|
|
|
|
|
), f"While running {str(test)} got non integer return code {return_code}"
|
|
|
|
|
if return_code == 0:
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
message = f"{str(test)} failed!"
|
|
|
|
|
if return_code < 0:
|
|
|
|
|
# subprocess.Popen returns the child process' exit signal as
|
|
|
|
|
# return code -N, where N is the signal number.
|
|
|
|
|
signal_name = SIGNALS_TO_NAMES_DICT[-return_code]
|
|
|
|
|
message += f" Received signal: {signal_name}"
|
|
|
|
|
return TestFailure(test.test, message)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
return TestFailure(test.test, f"{str(test)} failed! {e}")
|
2020-08-26 23:14:17 +00:00
|
|
|
|
2021-04-22 17:25:41 +00:00
|
|
|
|
2023-05-08 20:20:37 +00:00
|
|
|
def run_tests(
|
2025-01-21 19:22:20 +00:00
|
|
|
selected_tests: list[ShardedTest],
|
2023-08-16 18:23:09 +00:00
|
|
|
test_directory: str,
|
|
|
|
|
options,
|
2025-01-21 19:22:20 +00:00
|
|
|
failures: list[TestFailure],
|
2023-05-08 20:20:37 +00:00
|
|
|
) -> None:
|
|
|
|
|
if len(selected_tests) == 0:
|
2023-08-16 18:23:09 +00:00
|
|
|
return
|
2023-05-08 20:20:37 +00:00
|
|
|
|
2022-10-03 16:59:39 +00:00
|
|
|
# parallel = in parallel with other files
|
|
|
|
|
# serial = this file on it's own. The file might still be run in parallel with itself (ex test_ops)
|
2023-08-16 18:23:09 +00:00
|
|
|
selected_tests_parallel = [x for x in selected_tests if not must_serial(x)]
|
2023-03-26 04:52:55 +00:00
|
|
|
selected_tests_serial = [
|
|
|
|
|
x for x in selected_tests if x not in selected_tests_parallel
|
|
|
|
|
]
|
2022-10-03 16:59:39 +00:00
|
|
|
|
2023-01-06 22:19:07 +00:00
|
|
|
# See Note [ROCm parallel CI testing]
|
2023-03-26 04:52:55 +00:00
|
|
|
pool = get_context("spawn").Pool(
|
|
|
|
|
NUM_PROCS, maxtasksperchild=None if torch.version.hip else 1
|
|
|
|
|
)
|
2022-10-03 16:59:39 +00:00
|
|
|
|
2024-03-29 22:41:41 +00:00
|
|
|
# NB: This is a hack to make conftest.py and files it depends on available
|
|
|
|
|
# on CPP_TESTS_DIR. We should see if the file could be turned into a
|
|
|
|
|
# full-fledge ptest plugin instead
|
|
|
|
|
conftest_files = [
|
|
|
|
|
"conftest.py",
|
|
|
|
|
"pytest_shard_custom.py",
|
|
|
|
|
]
|
|
|
|
|
for conftest_file in conftest_files:
|
|
|
|
|
cpp_file = os.path.join(CPP_TESTS_DIR, conftest_file)
|
|
|
|
|
if (
|
|
|
|
|
options.cpp
|
|
|
|
|
and os.path.exists(CPP_TESTS_DIR)
|
|
|
|
|
and os.path.isdir(CPP_TESTS_DIR)
|
|
|
|
|
and not os.path.exists(cpp_file)
|
|
|
|
|
):
|
|
|
|
|
shutil.copy(os.path.join(test_directory, conftest_file), cpp_file)
|
Run C++ tests on CI with run_test.py (#99956)
After https://github.com/pytorch/pytorch/pull/99559, we can now run C++ test with `run_test.py`. Although advance features such as `--import-slow-tests` and `--import-disabled-tests` won't work for now, there will still be a gain in reliability and performance as C++ can now be retried and run in parallel.
This covers all C++ tests in the CI including aten, libtorch, and Vulkan C++ tests across all platforms Linux, Windows, MacOS.
Notes:
* To support C++ test discovery, the env variable `CPP_TESTS_DIR` can be set to where the C++ test binaries is located
* Support pytest -k argument via run_test as this is used by pytest-cpp to replace `--gtest-filter`
* The XML output is in pytest format, but it's ok now because we don't have slow test or flaky test support for C++ test yet
* ~~I need to figure out why conftest.py doesn't work when I invoke pytest directly for C++ test, so `--sc` is not available for C++ tests at the moment. Proper pytest plugin like stepwise works fine though. I'll investigate and fix it in a separate PR~~ Found the cause, `conftest.py` is per directory and needs to be in any arbitrary directory that holds C++ test
* Two tests `test_api` and `test_tensorexpr` timed out on ASAN, I suspect that ASAN is now used on top of the python executable, which is slower than running native C++ code. IMO, it's ok to run these tests as before on ASAN for now
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99956
Approved by: https://github.com/clee2000, https://github.com/ZainRizvi
2023-05-09 21:24:12 +00:00
|
|
|
|
2023-08-16 18:23:09 +00:00
|
|
|
def handle_error_messages(failure: Optional[TestFailure]):
|
|
|
|
|
if failure is None:
|
2023-04-19 19:29:03 +00:00
|
|
|
return False
|
2023-08-16 18:23:09 +00:00
|
|
|
failures.append(failure)
|
|
|
|
|
print_to_stderr(failure.message)
|
2023-04-19 19:29:03 +00:00
|
|
|
return True
|
|
|
|
|
|
2023-08-16 18:23:09 +00:00
|
|
|
def parallel_test_completion_callback(failure):
|
|
|
|
|
test_failed = handle_error_messages(failure)
|
2024-10-22 16:48:57 +00:00
|
|
|
if IS_CI and options.upload_artifacts_while_running:
|
|
|
|
|
zip_and_upload_artifacts(test_failed)
|
Do not collect and skip non-disabled tests when rerunning disabled tests (#102107)
The console log blows up to much when running in rerun disabled tests mode (x50) https://hud.pytorch.org/pytorch/pytorch/commit/e132f09e8878418fb98a4b76a441a324452354ec. Each log is around 1GB and the whole uncompressed logs is ~50GB. After compression, it will be around 1GB, still too big. The increase comes mainly from the multiple SKIPPED message for non-disabled tests, which is expected due to how SkipTest and pytest-flakyfinder currently work.
I update `test/conftest.py` to completely ignore skipped tests when rerunning disabled test instead of collecting then skipping 50 tests each. The benefit of doing is is much more than I originally expect:
* Rerun disabled tests jobs now finish in less than half an hour as they should be
* Fix OOM runner crash because of too many collected tests
* Fix verbosity issue as now only disabled tests are run x50 times. There are only few hundreds of them atm
* Fix timed out issue when rerunning disabled distributed and ASAN tests. They are just too slow when running at x50
### Testing
When rerunning disabled tests https://github.com/pytorch/pytorch/actions/runs/5084508614, only disabled tests on the platform are run, for example `test_ops_jit` on https://ossci-raw-job-status.s3.amazonaws.com/log/13770164954 only ran 100 tests (`test_variant_consistency_jit_linalg_lu_cuda_float32` + `test_variant_consistency_jit_linalg_lu_factor_cuda_complex64`) x50.
```
Executing ['/opt/conda/envs/py_3.10/bin/python', '-bb', 'test_ops_jit.py', '--shard-id=1', '--num-shards=2', '-v', '-vv', '-rfEX', '-p', 'no:xdist', '--use-pytest', '--sc=test_ops_jit_1', '--flake-finder', '--flake-runs=50', '--import-slow-tests', '--import-disabled-tests', '--rerun-disabled-tests'] ... [2023-05-25 21:32:49.763856]
Expand the folded group to see the log file of test_ops_jit 2/2
##[group]PRINTING LOG FILE of test_ops_jit 2/2 (/var/lib/jenkins/workspace/test/test-reports/test_ops_jit_h2wr_t2c.log)
Test results will be stored in test-reports/python-pytest/test_ops_jit/test_ops_jit-51a83bd44549074e.xml
============================= test session starts ==============================
platform linux -- Python 3.10.11, pytest-7.3.1, pluggy-1.0.0 -- /opt/conda/envs/py_3.10/bin/python
cachedir: .pytest_cache
hypothesis profile 'pytorch_ci' -> database=None, max_examples=50, derandomize=True, suppress_health_check=[HealthCheck.too_slow]
rootdir: /var/lib/jenkins/workspace
configfile: pytest.ini
plugins: hypothesis-5.35.1, cpp-2.3.0, flakefinder-1.1.0, rerunfailures-11.1.2, shard-0.1.2, xdist-3.3.0, xdoctest-1.1.0
collecting ... collected 1084 items
Running 100 items in this shard: test/test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_cuda_float32 (x50), test/test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_factor_cuda_complex64 (x50)
stepcurrent: Cannot find last run test, not skipping
test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_cuda_float32 PASSED [2.1876s] [ 1%]
test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_factor_cuda_complex64 PASSED [4.5615s] [ 2%]
```
* [pull](https://github.com/pytorch/pytorch/actions/runs/5093566864)
* [trunk](https://github.com/pytorch/pytorch/actions/runs/5095364311)
* [periodic](https://github.com/pytorch/pytorch/actions/runs/5095378850)
* [slow](https://github.com/pytorch/pytorch/actions/runs/5095390285)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/102107
Approved by: https://github.com/clee2000, https://github.com/malfet
2023-05-27 12:10:32 +00:00
|
|
|
if (
|
|
|
|
|
test_failed
|
|
|
|
|
and not options.continue_through_error
|
|
|
|
|
and not RERUN_DISABLED_TESTS
|
|
|
|
|
):
|
2022-10-03 16:59:39 +00:00
|
|
|
pool.terminate()
|
|
|
|
|
|
2024-04-17 00:23:42 +00:00
|
|
|
keep_going_message = (
|
|
|
|
|
"\n\nTip: You can keep running tests even on failure by passing --keep-going to run_test.py.\n"
|
|
|
|
|
"If running on CI, add the 'keep-going' label to your PR and rerun your jobs."
|
|
|
|
|
)
|
|
|
|
|
|
2020-08-26 23:14:17 +00:00
|
|
|
try:
|
Alternate sharding (#119078)
Changes sharding to attempt to put all serial tests on as few shards as possible. Parallel tests are then distributed across all shards, with most of which likely ending up on the non serial shards
Example: 8 minutes of serial tests, 20 minutes of parallel tests, 2 proc per machine, 6 machines
-> 8 + 20/2 = 18 total minutes of tests
-> 18 / 6 machines = 3 min per machine
-> all serial tests should fit on 3 machines (3min, 3 min, 2min)
-> majority of parallel tests should go on last 4 machines, one of which is shared with the serial tests
Move serial tests to run first
If I want to move to a purely numbers based sharding, this ensures that parallel tests are run with parallel tests as much as possible instead of interleaving serial + parallel tests, which decreases effectiveness of parallelization, while also ensuring that test reordering is still mostly effective.
See https://hud.pytorch.org/pytorch/pytorch/commit/73e816ee809ad96fda3ee0013ee96273a44e84d4 for example logs
Pull Request resolved: https://github.com/pytorch/pytorch/pull/119078
Approved by: https://github.com/huydhn
2024-02-21 16:40:27 +00:00
|
|
|
for test in selected_tests_serial:
|
|
|
|
|
options_clone = copy.deepcopy(options)
|
|
|
|
|
if can_run_in_pytest(test):
|
|
|
|
|
options_clone.pytest = True
|
|
|
|
|
failure = run_test_module(test, test_directory, options_clone)
|
|
|
|
|
test_failed = handle_error_messages(failure)
|
|
|
|
|
if (
|
|
|
|
|
test_failed
|
|
|
|
|
and not options.continue_through_error
|
|
|
|
|
and not RERUN_DISABLED_TESTS
|
|
|
|
|
):
|
2024-04-17 00:23:42 +00:00
|
|
|
raise RuntimeError(failure.message + keep_going_message)
|
|
|
|
|
|
|
|
|
|
# Run tests marked as serial first
|
|
|
|
|
for test in selected_tests_parallel:
|
|
|
|
|
options_clone = copy.deepcopy(options)
|
|
|
|
|
if can_run_in_pytest(test):
|
|
|
|
|
options_clone.pytest = True
|
2024-05-23 21:08:12 +00:00
|
|
|
options_clone.additional_args.extend(["-m", "serial"])
|
2024-04-17 00:23:42 +00:00
|
|
|
failure = run_test_module(test, test_directory, options_clone)
|
|
|
|
|
test_failed = handle_error_messages(failure)
|
|
|
|
|
if (
|
|
|
|
|
test_failed
|
|
|
|
|
and not options.continue_through_error
|
|
|
|
|
and not RERUN_DISABLED_TESTS
|
|
|
|
|
):
|
|
|
|
|
raise RuntimeError(failure.message + keep_going_message)
|
Alternate sharding (#119078)
Changes sharding to attempt to put all serial tests on as few shards as possible. Parallel tests are then distributed across all shards, with most of which likely ending up on the non serial shards
Example: 8 minutes of serial tests, 20 minutes of parallel tests, 2 proc per machine, 6 machines
-> 8 + 20/2 = 18 total minutes of tests
-> 18 / 6 machines = 3 min per machine
-> all serial tests should fit on 3 machines (3min, 3 min, 2min)
-> majority of parallel tests should go on last 4 machines, one of which is shared with the serial tests
Move serial tests to run first
If I want to move to a purely numbers based sharding, this ensures that parallel tests are run with parallel tests as much as possible instead of interleaving serial + parallel tests, which decreases effectiveness of parallelization, while also ensuring that test reordering is still mostly effective.
See https://hud.pytorch.org/pytorch/pytorch/commit/73e816ee809ad96fda3ee0013ee96273a44e84d4 for example logs
Pull Request resolved: https://github.com/pytorch/pytorch/pull/119078
Approved by: https://github.com/huydhn
2024-02-21 16:40:27 +00:00
|
|
|
|
2023-03-31 18:36:53 +00:00
|
|
|
os.environ["NUM_PARALLEL_PROCS"] = str(NUM_PROCS)
|
2022-10-03 16:59:39 +00:00
|
|
|
for test in selected_tests_parallel:
|
|
|
|
|
options_clone = copy.deepcopy(options)
|
Add env PYTORCH_TEST_DO_NOT_USE_PYTEST as an option to not use pytest in unit testing (#96444)
Set environment variable
```
PYTORCH_TEST_DO_NOT_USE_PYTEST=1
```
to not use pytest in pytorch unit testing.
This change is related to some recent changes, e.g. #96210, #96016, #95844, #95659, that enabled the use of pytest in many test modules. Those test modules were testing normally before, but failed immediately after pytest is used. Sample stacktraces are:
```python
root@8e3168a83ee2:/opt/pytorch/pytorch# python test/run_test.py -v -i test_optim -- -v --save-xml
Ignoring disabled issues: []
/opt/pytorch/pytorch/test/run_test.py:1225: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
if torch.version.cuda is not None and LooseVersion(torch.version.cuda) >= "11.6":
Selected tests:
test_optim
parallel (file granularity) tests:
test_optim
serial (file granularity) tests:
Ignoring disabled issues: []
Ignoring disabled issues: []
Running test_optim ... [2023-03-09 12:51:59.358110]
Executing ['/usr/local/bin/python', '-bb', 'test_optim.py', '-v', '--save-xml', '-v', '--use-pytest', '-vv', '-rfEX', '-x', '--reruns=2'] ... [2023-03-09 12:51:59.358810]
Test results will be stored in test-reports/python-pytest/test_optim/test_optim-5e41643c8bac8ace.xml
Traceback (most recent call last):
File "/opt/pytorch/pytorch/test/test_optim.py", line 4581, in <module>
run_tests()
File "/opt/pytorch/pytorch/torch/testing/_internal/common_utils.py", line 796, in run_tests
exit_code = pytest.main(args=pytest_args)
File "/usr/local/lib/python3.10/site-packages/_pytest/config/__init__.py", line 148, in main
config = _prepareconfig(args, plugins)
File "/usr/local/lib/python3.10/site-packages/_pytest/config/__init__.py", line 329, in _prepareconfig
config = pluginmanager.hook.pytest_cmdline_parse(
File "/usr/local/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
File "/usr/local/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 55, in _multicall
gen.send(outcome)
File "/usr/local/lib/python3.10/site-packages/_pytest/helpconfig.py", line 103, in pytest_cmdline_parse
config: Config = outcome.get_result()
File "/usr/local/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
raise ex[1].with_traceback(ex[2])
File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
res = hook_impl.function(*args)
File "/usr/local/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1060, in pytest_cmdline_parse
self.parse(args)
File "/usr/local/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1348, in parse
self._preparse(args, addopts=addopts)
File "/usr/local/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1231, in _preparse
self.pluginmanager.load_setuptools_entrypoints("pytest11")
File "/usr/local/lib/python3.10/site-packages/pluggy/_manager.py", line 287, in load_setuptools_entrypoints
plugin = ep.load()
File "/usr/local/lib/python3.10/importlib/metadata/__init__.py", line 171, in load
module = import_module(match.group('module'))
File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "/usr/local/lib/python3.10/site-packages/_pytest/assertion/rewrite.py", line 168, in exec_module
exec(co, module.__dict__)
File "/usr/local/lib/python3.10/site-packages/xdist/looponfail.py", line 16, in <module>
import execnet
File "/usr/local/lib/python3.10/site-packages/execnet/__init__.py", line 14, in <module>
from .gateway_base import DataFormatError
File "/usr/local/lib/python3.10/site-packages/execnet/gateway_base.py", line 1138, in <module>
FLOAT_FORMAT_SIZE = struct.calcsize(FLOAT_FORMAT)
BytesWarning: Comparison between bytes and string
FINISHED PRINTING LOG FILE of test_optim (/opt/pytorch/pytorch/test/test-reports/test_optim_1pnlesrz.log)
test_optim failed!
Traceback (most recent call last):
File "/opt/pytorch/pytorch/test/run_test.py", line 1428, in <module>
main()
File "/opt/pytorch/pytorch/test/run_test.py", line 1386, in main
raise RuntimeError(
RuntimeError: test_optim failed!
Tip: You can keep running tests even on failure by passing --keep-going to run_test.py.
If running on CI, add the 'keep-going' label to your PR and rerun your jobs.
```
I'd like to propose this option that allows users to use the good old python unit test way instead of pytest to run their testing in CI.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/96444
Approved by: https://github.com/malfet
2023-03-10 01:32:11 +00:00
|
|
|
if can_run_in_pytest(test):
|
2022-10-03 16:59:39 +00:00
|
|
|
options_clone.pytest = True
|
2024-05-23 21:08:12 +00:00
|
|
|
options_clone.additional_args.extend(["-m", "not serial"])
|
2023-03-26 04:52:55 +00:00
|
|
|
pool.apply_async(
|
|
|
|
|
run_test_module,
|
|
|
|
|
args=(test, test_directory, options_clone),
|
2023-04-19 19:29:03 +00:00
|
|
|
callback=parallel_test_completion_callback,
|
2023-03-26 04:52:55 +00:00
|
|
|
)
|
2022-10-03 16:59:39 +00:00
|
|
|
pool.close()
|
|
|
|
|
pool.join()
|
2023-03-31 18:36:53 +00:00
|
|
|
del os.environ["NUM_PARALLEL_PROCS"]
|
2022-10-03 16:59:39 +00:00
|
|
|
|
2020-08-26 23:14:17 +00:00
|
|
|
finally:
|
2022-10-03 16:59:39 +00:00
|
|
|
pool.terminate()
|
|
|
|
|
pool.join()
|
|
|
|
|
|
2023-08-16 18:23:09 +00:00
|
|
|
return
|
2023-05-08 20:20:37 +00:00
|
|
|
|
|
|
|
|
|
2023-05-17 20:27:51 +00:00
|
|
|
def check_pip_packages() -> None:
|
|
|
|
|
packages = [
|
|
|
|
|
"pytest-rerunfailures",
|
|
|
|
|
"pytest-flakefinder",
|
|
|
|
|
"pytest-xdist",
|
|
|
|
|
]
|
|
|
|
|
installed_packages = [i.key for i in pkg_resources.working_set]
|
|
|
|
|
for package in packages:
|
|
|
|
|
if package not in installed_packages:
|
2023-10-03 01:22:44 +00:00
|
|
|
print_to_stderr(
|
2023-05-17 20:27:51 +00:00
|
|
|
f"Missing pip dependency: {package}, please run `pip install -r .ci/docker/requirements-ci.txt`"
|
|
|
|
|
)
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
2023-05-08 20:20:37 +00:00
|
|
|
def main():
|
2023-05-17 20:27:51 +00:00
|
|
|
check_pip_packages()
|
|
|
|
|
|
2023-05-08 20:20:37 +00:00
|
|
|
options = parse_args()
|
|
|
|
|
|
2023-09-26 17:06:49 +00:00
|
|
|
# Include sharding info in all metrics
|
|
|
|
|
which_shard, num_shards = get_sharding_opts(options)
|
|
|
|
|
add_global_metric("shard", which_shard)
|
|
|
|
|
add_global_metric("num_shards", num_shards)
|
|
|
|
|
|
2023-05-08 20:20:37 +00:00
|
|
|
test_directory = str(REPO_ROOT / "test")
|
|
|
|
|
selected_tests = get_selected_tests(options)
|
|
|
|
|
|
2024-03-01 23:08:10 +00:00
|
|
|
test_prioritizations = import_results()
|
2024-10-16 18:04:25 +00:00
|
|
|
if len(test_prioritizations.get_all_tests()) == 0:
|
|
|
|
|
options.enable_td = False
|
2024-03-01 23:08:10 +00:00
|
|
|
test_prioritizations.amend_tests(selected_tests)
|
|
|
|
|
|
2024-01-05 19:05:12 +00:00
|
|
|
os.makedirs(REPO_ROOT / "test" / "test-reports", exist_ok=True)
|
|
|
|
|
|
2023-05-08 20:20:37 +00:00
|
|
|
if options.coverage and not PYTORCH_COLLECT_COVERAGE:
|
|
|
|
|
shell(["coverage", "erase"])
|
|
|
|
|
|
2024-03-01 23:08:10 +00:00
|
|
|
if IS_CI:
|
|
|
|
|
# downloading test cases configuration to local environment
|
|
|
|
|
get_test_case_configs(dirpath=test_directory)
|
2023-08-16 18:23:09 +00:00
|
|
|
|
2023-10-30 23:31:40 +00:00
|
|
|
test_file_times_dict = load_test_file_times()
|
|
|
|
|
test_class_times_dict = load_test_class_times()
|
|
|
|
|
|
2023-08-23 01:04:05 +00:00
|
|
|
class TestBatch:
|
|
|
|
|
"""Defines a set of tests with similar priority that should be run together on the current shard"""
|
2023-08-16 18:23:09 +00:00
|
|
|
|
2023-08-23 01:04:05 +00:00
|
|
|
name: str
|
2025-01-21 19:22:20 +00:00
|
|
|
sharded_tests: list[ShardedTest]
|
|
|
|
|
failures: list[TestFailure]
|
2023-08-16 18:23:09 +00:00
|
|
|
|
2023-10-30 23:31:40 +00:00
|
|
|
def __init__(
|
|
|
|
|
self, name: str, raw_tests: Sequence[TestRun], should_sort_shard: bool
|
|
|
|
|
):
|
2023-08-23 01:04:05 +00:00
|
|
|
self.name = name
|
|
|
|
|
self.failures = []
|
2024-02-29 18:53:43 +00:00
|
|
|
self.time, self.sharded_tests = do_sharding(
|
2023-10-30 23:31:40 +00:00
|
|
|
options,
|
|
|
|
|
raw_tests,
|
|
|
|
|
test_file_times_dict,
|
|
|
|
|
test_class_times_dict,
|
|
|
|
|
sort_by_time=should_sort_shard,
|
2023-08-23 01:04:05 +00:00
|
|
|
)
|
2023-08-16 18:23:09 +00:00
|
|
|
|
2023-09-01 20:23:30 +00:00
|
|
|
def __str__(self):
|
2024-02-29 18:53:43 +00:00
|
|
|
s = f"Name: {self.name} (est. time: {round(self.time / 60, 2)}min)\n"
|
2024-02-26 17:01:19 +00:00
|
|
|
serial = [test for test in self.sharded_tests if must_serial(test)]
|
|
|
|
|
parallel = [test for test in self.sharded_tests if not must_serial(test)]
|
|
|
|
|
s += f" Serial tests ({len(serial)}):\n"
|
|
|
|
|
s += "".join(f" {test}\n" for test in serial)
|
|
|
|
|
s += f" Parallel tests ({len(parallel)}):\n"
|
|
|
|
|
s += "".join(f" {test}\n" for test in parallel)
|
2023-09-01 20:23:30 +00:00
|
|
|
return s.strip()
|
|
|
|
|
|
2024-02-29 18:53:43 +00:00
|
|
|
percent_to_run = 25 if options.enable_td else 100
|
|
|
|
|
print_to_stderr(
|
|
|
|
|
f"Running {percent_to_run}% of tests based on TD"
|
|
|
|
|
if options.enable_td
|
|
|
|
|
else "Running all tests"
|
|
|
|
|
)
|
|
|
|
|
include, exclude = test_prioritizations.get_top_per_tests(percent_to_run)
|
|
|
|
|
|
|
|
|
|
test_batch = TestBatch("tests to run", include, False)
|
|
|
|
|
test_batch_exclude = TestBatch("excluded", exclude, True)
|
2024-04-17 00:18:24 +00:00
|
|
|
if IS_CI:
|
|
|
|
|
gen_ci_artifact([x.to_json() for x in include], [x.to_json() for x in exclude])
|
2023-08-16 18:23:09 +00:00
|
|
|
|
2024-04-17 00:23:42 +00:00
|
|
|
print_to_stderr(f"Running parallel tests on {NUM_PROCS} processes")
|
2024-02-26 17:01:19 +00:00
|
|
|
print_to_stderr(test_batch)
|
2024-02-29 18:53:43 +00:00
|
|
|
print_to_stderr(test_batch_exclude)
|
2023-09-01 20:23:30 +00:00
|
|
|
|
2023-08-16 18:23:09 +00:00
|
|
|
if options.dry_run:
|
|
|
|
|
return
|
2023-05-08 20:20:37 +00:00
|
|
|
|
|
|
|
|
if options.dynamo:
|
|
|
|
|
os.environ["PYTORCH_TEST_WITH_DYNAMO"] = "1"
|
2024-01-18 15:56:15 +00:00
|
|
|
|
2023-05-08 20:20:37 +00:00
|
|
|
elif options.inductor:
|
|
|
|
|
os.environ["PYTORCH_TEST_WITH_INDUCTOR"] = "1"
|
|
|
|
|
|
2023-07-05 14:34:44 +00:00
|
|
|
if not options.no_translation_validation:
|
|
|
|
|
os.environ["PYTORCH_TEST_WITH_TV"] = "1"
|
|
|
|
|
|
2023-05-08 20:20:37 +00:00
|
|
|
try:
|
2023-08-23 01:04:05 +00:00
|
|
|
# Actually run the tests
|
|
|
|
|
start_time = time.time()
|
2024-02-26 17:01:19 +00:00
|
|
|
run_tests(
|
|
|
|
|
test_batch.sharded_tests, test_directory, options, test_batch.failures
|
|
|
|
|
)
|
2024-08-15 15:29:44 +00:00
|
|
|
elapsed_time = time.time() - start_time
|
|
|
|
|
print_to_stderr(
|
|
|
|
|
f"Running test batch '{test_batch.name}' cost {round(elapsed_time, 2)} seconds"
|
|
|
|
|
)
|
2023-05-08 20:20:37 +00:00
|
|
|
|
|
|
|
|
finally:
|
2020-08-26 23:14:17 +00:00
|
|
|
if options.coverage:
|
2020-12-19 01:07:05 +00:00
|
|
|
from coverage import Coverage
|
2021-08-25 18:19:49 +00:00
|
|
|
|
2021-08-25 19:58:24 +00:00
|
|
|
with set_cwd(test_directory):
|
2020-12-19 01:07:05 +00:00
|
|
|
cov = Coverage()
|
|
|
|
|
if PYTORCH_COLLECT_COVERAGE:
|
|
|
|
|
cov.load()
|
|
|
|
|
cov.combine(strict=False)
|
|
|
|
|
cov.save()
|
|
|
|
|
if not PYTORCH_COLLECT_COVERAGE:
|
|
|
|
|
cov.html_report()
|
2018-03-09 21:02:02 +00:00
|
|
|
|
2024-02-26 17:01:19 +00:00
|
|
|
all_failures = test_batch.failures
|
2023-08-31 16:51:46 +00:00
|
|
|
|
2023-08-22 16:36:17 +00:00
|
|
|
if IS_CI:
|
2023-08-31 16:51:46 +00:00
|
|
|
for test, _ in all_failures:
|
2024-03-01 23:08:10 +00:00
|
|
|
test_stats = test_prioritizations.get_test_stats(test)
|
|
|
|
|
print_to_stderr("Emiting td_test_failure_stats_v2")
|
2023-11-07 19:40:07 +00:00
|
|
|
emit_metric(
|
2024-03-01 23:08:10 +00:00
|
|
|
"td_test_failure_stats_v2",
|
2023-11-07 19:40:07 +00:00
|
|
|
{
|
2024-03-01 23:08:10 +00:00
|
|
|
"selected_tests": selected_tests,
|
2023-11-07 19:40:07 +00:00
|
|
|
"failure": str(test),
|
2024-03-01 23:08:10 +00:00
|
|
|
**test_stats,
|
2023-11-07 19:40:07 +00:00
|
|
|
},
|
|
|
|
|
)
|
2024-05-21 16:29:29 +00:00
|
|
|
gen_additional_test_failures_file(
|
|
|
|
|
[test.test_file for test, _ in all_failures]
|
|
|
|
|
)
|
2023-08-30 15:31:38 +00:00
|
|
|
|
2023-08-31 16:51:46 +00:00
|
|
|
if len(all_failures):
|
|
|
|
|
for _, err in all_failures:
|
2020-10-23 21:13:12 +00:00
|
|
|
print_to_stderr(err)
|
Do not collect and skip non-disabled tests when rerunning disabled tests (#102107)
The console log blows up to much when running in rerun disabled tests mode (x50) https://hud.pytorch.org/pytorch/pytorch/commit/e132f09e8878418fb98a4b76a441a324452354ec. Each log is around 1GB and the whole uncompressed logs is ~50GB. After compression, it will be around 1GB, still too big. The increase comes mainly from the multiple SKIPPED message for non-disabled tests, which is expected due to how SkipTest and pytest-flakyfinder currently work.
I update `test/conftest.py` to completely ignore skipped tests when rerunning disabled test instead of collecting then skipping 50 tests each. The benefit of doing is is much more than I originally expect:
* Rerun disabled tests jobs now finish in less than half an hour as they should be
* Fix OOM runner crash because of too many collected tests
* Fix verbosity issue as now only disabled tests are run x50 times. There are only few hundreds of them atm
* Fix timed out issue when rerunning disabled distributed and ASAN tests. They are just too slow when running at x50
### Testing
When rerunning disabled tests https://github.com/pytorch/pytorch/actions/runs/5084508614, only disabled tests on the platform are run, for example `test_ops_jit` on https://ossci-raw-job-status.s3.amazonaws.com/log/13770164954 only ran 100 tests (`test_variant_consistency_jit_linalg_lu_cuda_float32` + `test_variant_consistency_jit_linalg_lu_factor_cuda_complex64`) x50.
```
Executing ['/opt/conda/envs/py_3.10/bin/python', '-bb', 'test_ops_jit.py', '--shard-id=1', '--num-shards=2', '-v', '-vv', '-rfEX', '-p', 'no:xdist', '--use-pytest', '--sc=test_ops_jit_1', '--flake-finder', '--flake-runs=50', '--import-slow-tests', '--import-disabled-tests', '--rerun-disabled-tests'] ... [2023-05-25 21:32:49.763856]
Expand the folded group to see the log file of test_ops_jit 2/2
##[group]PRINTING LOG FILE of test_ops_jit 2/2 (/var/lib/jenkins/workspace/test/test-reports/test_ops_jit_h2wr_t2c.log)
Test results will be stored in test-reports/python-pytest/test_ops_jit/test_ops_jit-51a83bd44549074e.xml
============================= test session starts ==============================
platform linux -- Python 3.10.11, pytest-7.3.1, pluggy-1.0.0 -- /opt/conda/envs/py_3.10/bin/python
cachedir: .pytest_cache
hypothesis profile 'pytorch_ci' -> database=None, max_examples=50, derandomize=True, suppress_health_check=[HealthCheck.too_slow]
rootdir: /var/lib/jenkins/workspace
configfile: pytest.ini
plugins: hypothesis-5.35.1, cpp-2.3.0, flakefinder-1.1.0, rerunfailures-11.1.2, shard-0.1.2, xdist-3.3.0, xdoctest-1.1.0
collecting ... collected 1084 items
Running 100 items in this shard: test/test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_cuda_float32 (x50), test/test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_factor_cuda_complex64 (x50)
stepcurrent: Cannot find last run test, not skipping
test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_cuda_float32 PASSED [2.1876s] [ 1%]
test_ops_jit.py::TestJitCUDA::test_variant_consistency_jit_linalg_lu_factor_cuda_complex64 PASSED [4.5615s] [ 2%]
```
* [pull](https://github.com/pytorch/pytorch/actions/runs/5093566864)
* [trunk](https://github.com/pytorch/pytorch/actions/runs/5095364311)
* [periodic](https://github.com/pytorch/pytorch/actions/runs/5095378850)
* [slow](https://github.com/pytorch/pytorch/actions/runs/5095390285)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/102107
Approved by: https://github.com/clee2000, https://github.com/malfet
2023-05-27 12:10:32 +00:00
|
|
|
|
|
|
|
|
# A disabled test is expected to fail, so there is no need to report a failure here
|
|
|
|
|
if not RERUN_DISABLED_TESTS:
|
|
|
|
|
sys.exit(1)
|
2018-03-09 21:02:02 +00:00
|
|
|
|
2021-08-25 18:19:49 +00:00
|
|
|
|
2021-08-12 18:39:31 +00:00
|
|
|
if __name__ == "__main__":
|
2018-03-09 21:02:02 +00:00
|
|
|
main()
|