conftest.py 1.19 KB
Newer Older
1
2
# SPDX-License-Identifier: Apache-2.0

3
import functools
4
import gc
5
from typing import Callable, TypeVar
6
7
8

import pytest
import torch
9
from typing_extensions import ParamSpec
10

11
from vllm.distributed import cleanup_dist_env_and_memory
12
13
14
from vllm.model_executor.model_loader.tensorizer import TensorizerConfig


15
@pytest.fixture(autouse=True)
16
def cleanup():
17
    cleanup_dist_env_and_memory(shutdown_ray=True)
18
19


20
21
_P = ParamSpec("_P")
_R = TypeVar("_R")
22

23
24
25
26

def retry_until_skip(n: int):

    def decorator_retry(func: Callable[_P, _R]) -> Callable[_P, _R]:
27

28
        @functools.wraps(func)
29
        def wrapper_retry(*args: _P.args, **kwargs: _P.kwargs) -> _R:
30
31
32
33
34
35
36
            for i in range(n):
                try:
                    return func(*args, **kwargs)
                except AssertionError:
                    gc.collect()
                    torch.cuda.empty_cache()
                    if i == n - 1:
37
38
39
                        pytest.skip(f"Skipping test after {n} attempts.")

            raise AssertionError("Code should not be reached")
40

41
42
43
        return wrapper_retry

    return decorator_retry
44
45
46
47
48


@pytest.fixture(autouse=True)
def tensorizer_config():
    config = TensorizerConfig(tensorizer_uri="vllm")
49
    return config