monitor.py 1.95 KB
Newer Older
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3

4
5
import time

6
from vllm.config import CompilationConfig, CompilationLevel, VllmConfig
7
8
9
10
from vllm.logger import init_logger

logger = init_logger(__name__)

11
context_manager = None
12
13
torch_compile_start_time: float = 0.0

14

15
def start_monitoring_torch_compile(vllm_config: VllmConfig):
16
17
    global torch_compile_start_time
    torch_compile_start_time = time.time()
18

19
    compilation_config: CompilationConfig = vllm_config.compilation_config
20
21
    path = vllm_config.compile_debug_dump_path()
    if compilation_config.level == CompilationLevel.PIECEWISE and path:
22
        import depyf
23

24
        path.mkdir(parents=True, exist_ok=True)
25
        global context_manager
26
        context_manager = depyf.prepare_debug(path.as_posix())
27
        context_manager.__enter__()
28

29
30
31

def end_monitoring_torch_compile(vllm_config: VllmConfig):
    compilation_config: CompilationConfig = vllm_config.compilation_config
32
    if compilation_config.level == CompilationLevel.PIECEWISE:
33
34
35
        logger.info(
            "torch.compile takes %.2f s in total", compilation_config.compilation_time
        )
36
37
38
39
        global context_manager
        if context_manager is not None:
            context_manager.__exit__(None, None, None)
            context_manager = None
40
41
42
43
44
45


cudagraph_capturing_enabled: bool = True


def validate_cudagraph_capturing_enabled():
46
    # used to monitor whether a cudagraph capturing is legal at runtime.
47
48
49
50
    # should be called before any cudagraph capturing.
    # if an illegal cudagraph capturing happens, raise an error.
    global cudagraph_capturing_enabled
    if not cudagraph_capturing_enabled:
51
52
53
54
        raise RuntimeError(
            "CUDA graph capturing detected at an inappropriate "
            "time. This operation is currently disabled."
        )
55
56
57
58
59


def set_cudagraph_capturing_enabled(enabled: bool):
    global cudagraph_capturing_enabled
    cudagraph_capturing_enabled = enabled