monitor.py 2.05 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, CompilationMode, 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
    path = vllm_config.compile_debug_dump_path()
21
    if compilation_config.mode == CompilationMode.VLLM_COMPILE and path:
22
        import depyf
23

24
        path.mkdir(parents=True, exist_ok=True)
25
        logger.debug("Dumping depyf output to %s", path)
26
        global context_manager
27
        context_manager = depyf.prepare_debug(path.as_posix())
28
        context_manager.__enter__()
29

30
31
32

def end_monitoring_torch_compile(vllm_config: VllmConfig):
    compilation_config: CompilationConfig = vllm_config.compilation_config
33
    if compilation_config.mode == CompilationMode.VLLM_COMPILE:
34
35
36
37
        logger.info_once(
            "torch.compile takes %.2f s in total",
            compilation_config.compilation_time,
            scope="local",
38
        )
39
40
41
42
        global context_manager
        if context_manager is not None:
            context_manager.__exit__(None, None, None)
            context_manager = None
43
44
45
46
47
48


cudagraph_capturing_enabled: bool = True


def validate_cudagraph_capturing_enabled():
49
    # used to monitor whether a cudagraph capturing is legal at runtime.
50
51
52
53
    # 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:
54
55
56
57
        raise RuntimeError(
            "CUDA graph capturing detected at an inappropriate "
            "time. This operation is currently disabled."
        )
58
59
60
61
62


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