__init__.py 1.68 KB
Newer Older
1
import logging
2
from typing import Callable, Optional, Union
3
4

import vllm.envs as envs
5
from vllm.compilation.config import CompilationConfig
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

logger = logging.getLogger(__name__)


def load_general_plugins():
    """WARNING: plugins can be loaded for multiple times in different
    processes. They should be designed in a way that they can be loaded
    multiple times without causing issues.
    """
    import sys
    if sys.version_info < (3, 10):
        from importlib_metadata import entry_points
    else:
        from importlib.metadata import entry_points

    allowed_plugins = envs.VLLM_PLUGINS

    discovered_plugins = entry_points(group='vllm.general_plugins')
    for plugin in discovered_plugins:
        logger.info("Found general plugin: %s", plugin.name)
        if allowed_plugins is None or plugin.name in allowed_plugins:
            try:
                func = plugin.load()
                func()
                logger.info("Loaded general plugin: %s", plugin.name)
            except Exception:
                logger.exception("Failed to load general plugin: %s",
                                 plugin.name)
34
35
36
37
38
39
40
41
42
43
44
45


_torch_compile_backend: Optional[Union[Callable, str]] = None


def set_torch_compile_backend(backend: Union[Callable, str]):
    global _torch_compile_backend
    _torch_compile_backend = backend


def get_torch_compile_backend() -> Optional[Union[Callable, str]]:
    return _torch_compile_backend
46
47


48
_compilation_config: Optional[CompilationConfig] = None
49
50


51
52
53
def set_compilation_config(config: Optional[CompilationConfig]):
    global _compilation_config
    _compilation_config = config
54
55


56
57
def get_compilation_config() -> Optional[CompilationConfig]:
    return _compilation_config