__init__.py 1.99 KB
Newer Older
1
import logging
2
import os
3

4
5
import torch

6
import vllm.envs as envs
7

8
9
logger = logging.getLogger(__name__)

10
11
12
# make sure one process only loads plugins once
plugins_loaded = False

13
14
15
16
17
18

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.
    """
19
20
21
22
23
24
25

    # all processes created by vllm will load plugins,
    # and here we can inject some common environment variables
    # for all processes.

    # see https://github.com/vllm-project/vllm/issues/10480
    os.environ['TORCHINDUCTOR_COMPILE_THREADS'] = '1'
26
27
    # see https://github.com/vllm-project/vllm/issues/10619
    torch._inductor.config.compile_threads = 1
28
29
30
31
    global plugins_loaded
    if plugins_loaded:
        return
    plugins_loaded = True
32
33
34
35
36
37
38
39
40
    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')
41
42
43
    if len(discovered_plugins) == 0:
        logger.info("No plugins found.")
        return
44
45
46
47
48
49
50
51
52
53
    logger.info("Available plugins:")
    for plugin in discovered_plugins:
        logger.info("name=%s, value=%s, group=%s", plugin.name, plugin.value,
                    plugin.group)
    if allowed_plugins is None:
        logger.info("all available plugins will be loaded.")
        logger.info("set environment variable VLLM_PLUGINS to control"
                    " which plugins to load.")
    else:
        logger.info("plugins to load: %s", allowed_plugins)
54
55
56
57
58
    for plugin in discovered_plugins:
        if allowed_plugins is None or plugin.name in allowed_plugins:
            try:
                func = plugin.load()
                func()
59
                logger.info("plugin %s loaded.", plugin.name)
60
            except Exception:
61
                logger.exception("Failed to load plugin %s", plugin.name)