| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | import pytest |
| 4 | |
| 5 | from vllm.distributed import cleanup_dist_env_and_memory |
| 6 | from vllm.v1.worker.workspace import reset_workspace_manager |
| 7 | |
| 8 | NEEDS_CLEAN_ENTRY = frozenset( |
| 9 | { |
| 10 | # Fail unless they start from a clean distributed and memory state, |
| 11 | # which they used to get only as a side effect of the preceding test |
| 12 | # cleaning up after itself. |
| 13 | "test_moe_layer.py", |
| 14 | "test_modular_oai_triton_moe.py", |
| 15 | "test_ocp_mx_moe.py", |
| 16 | "test_zero_expert_moe.py", |
| 17 | # Execute no test on ROCm, where this was measured, so nothing is known |
| 18 | # about how they behave without the per-test cleanup. Cleaned on entry |
| 19 | # as a precaution; drop once they have been seen green without it. |
| 20 | "test_batched_deepgemm.py", |
| 21 | "test_deepep_deepgemm_moe.py", |
| 22 | "test_deepep_moe.py", |
| 23 | "test_deepep_v2_moe.py", |
| 24 | "test_deepgemm.py", |
| 25 | "test_grouped_topk.py", |
| 26 | "test_mxfp4_moe.py", |
| 27 | "test_shared_fused_moe_routed_transform.py", |
| 28 | "test_silu_mul_per_token_group_quant_fp8_colmajor.py", |
| 29 | "test_situ_mul_fp8_quant.py", |
| 30 | } |
| 31 | ) |
| 32 | |
| 33 | |
| 34 | def pytest_addoption(parser): |
| 35 | parser.addoption( |
| 36 | "--subtests", action="store", type=str, default=None, help="subtest ids" |
| 37 | ) |
| 38 | |
| 39 | |
| 40 | @pytest.fixture |
| 41 | def subtests(request): |
| 42 | return request.config.getoption("--subtests") |
| 43 | |
| 44 | |
| 45 | @pytest.fixture() |
| 46 | def should_do_global_cleanup_after_test() -> bool: |
| 47 | """Drop the per-test global cleanup for this directory. |
| 48 | |
| 49 | A full ``gc.collect()`` plus an emptied caching allocator after each of the |
| 50 | ~1450 small kernel tests per shard costs more than the tests themselves. |
| 51 | The tests that depend on isolation get a clean state on entry instead, in |
| 52 | the hook below. |
| 53 | """ |
| 54 | return False |
| 55 | |
| 56 | |
| 57 | def pytest_runtest_setup(item): |
| 58 | # Not tryfirst: the skipping plugin evaluates skip marks in a tryfirst |
| 59 | # hook, so tests about to be skipped never reach this, while fixture setup |
| 60 | # still runs afterwards. |
| 61 | if item.path.name in NEEDS_CLEAN_ENTRY or "dist_init" in item.fixturenames: |
| 62 | reset_workspace_manager() |
| 63 | cleanup_dist_env_and_memory() |