File tree Expand file tree Collapse file tree 3 files changed +25
-18
lines changed Expand file tree Collapse file tree 3 files changed +25
-18
lines changed Original file line number Diff line number Diff line change @@ -55,10 +55,20 @@ def cleanup():
55
55
torch .cuda .empty_cache ()
56
56
57
57
58
+ @pytest .fixture ()
59
+ def should_do_global_cleanup_after_test () -> bool :
60
+ """Allow subdirectories to skip global cleanup by overriding this fixture.
61
+ This can provide a ~10x speedup for non-GPU unit tests since they don't need
62
+ to initialize torch.
63
+ """
64
+ return True
65
+
66
+
58
67
@pytest .fixture (autouse = True )
59
- def cleanup_fixture ():
68
+ def cleanup_fixture (should_do_global_cleanup_after_test : bool ):
60
69
yield
61
- cleanup ()
70
+ if should_do_global_cleanup_after_test :
71
+ cleanup ()
62
72
63
73
64
74
@pytest .fixture (scope = "session" )
Original file line number Diff line number Diff line change
1
+ import pytest
2
+
3
+
4
+ @pytest .fixture ()
5
+ def should_do_global_cleanup_after_test () -> bool :
6
+ """Disable the global cleanup fixture for tests in this directory. This
7
+ provides a ~10x speedup for unit tests that don't load a model to GPU.
8
+
9
+ This requires that tests in this directory clean up after themselves if they
10
+ use the GPU.
11
+ """
12
+ return False
Original file line number Diff line number Diff line change 1
- import contextlib
2
- import gc
3
-
4
1
import pytest
5
- import ray
6
- import torch
7
2
3
+ from tests .conftest import cleanup
8
4
from vllm import LLM
9
- from vllm .model_executor .parallel_utils .parallel_state import (
10
- destroy_model_parallel )
11
5
from vllm .model_executor .utils import set_random_seed
12
6
13
7
14
- def cleanup ():
15
- destroy_model_parallel ()
16
- with contextlib .suppress (AssertionError ):
17
- torch .distributed .destroy_process_group ()
18
- gc .collect ()
19
- torch .cuda .empty_cache ()
20
- ray .shutdown ()
21
-
22
-
23
8
@pytest .fixture
24
9
def baseline_llm_generator (common_llm_kwargs , per_test_common_llm_kwargs ,
25
10
baseline_llm_kwargs , seed ):
You can’t perform that action at this time.
0 commit comments