monitor.py 1.94 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
        path.mkdir(parents=True, exist_ok=True)
24
        global context_manager
25
        context_manager = depyf.prepare_debug(path.as_posix())
26
        context_manager.__enter__()
27

28
29
30

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


cudagraph_capturing_enabled: bool = True


def validate_cudagraph_capturing_enabled():
44
    # used to monitor whether a cudagraph capturing is legal at runtime.
45
46
47
48
49
50
51
52
53
54
55
    # 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:
        raise RuntimeError("CUDA graph capturing detected at an inappropriate "
                           "time. This operation is currently disabled.")


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