Skip to content

Commit 88256a8

Browse files
committed
[V1][Metrics][Plugin] Add plugin support for custom StatLoggerBase implementations via vllm.stat_logger_plugins
Signed-off-by: tovam <tovam@pliops.com>
1 parent 4e5affe commit 88256a8

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

docs/design/plugin_system.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Every plugin has three parts:
4141

4242
1. **Plugin group**: The name of the entry point group. vLLM uses the entry point group `vllm.general_plugins` to register general plugins. This is the key of `entry_points` in the `setup.py` file. Always use `vllm.general_plugins` for vLLM's general plugins.
4343
2. **Plugin name**: The name of the plugin. This is the value in the dictionary of the `entry_points` dictionary. In the example above, the plugin name is `register_dummy_model`. Plugins can be filtered by their names using the `VLLM_PLUGINS` environment variable. To load only a specific plugin, set `VLLM_PLUGINS` to the plugin name.
44-
3. **Plugin value**: The fully qualified name of the function to register in the plugin system. In the example above, the plugin value is `vllm_add_dummy_model:register`, which refers to a function named `register` in the `vllm_add_dummy_model` module.
44+
3. **Plugin value**: The fully qualified name of the function or module to register in the plugin system. In the example above, the plugin value is `vllm_add_dummy_model:register`, which refers to a function named `register` in the `vllm_add_dummy_model` module.
4545

4646
## Types of supported plugins
4747

@@ -51,6 +51,8 @@ Every plugin has three parts:
5151

5252
- **IO Processor plugins** (with group name `vllm.io_processor_plugins`): The primary use case for these plugins is to register custom pre/post processing of the model prompt and model output for poling models. The plugin function returns the IOProcessor's class fully qualified name.
5353

54+
- **Stat logger plugins** (with group name `vllm.stat_logger_plugins`): The primary use case for these plugins is to register custom, out-of-the-tree loggers into vLLM. The entry point should be a class that subclasses StatLoggerBase.
55+
5456
## Guidelines for Writing Plugins
5557

5658
- **Being re-entrant**: The function specified in the entry point should be re-entrant, meaning it can be called multiple times without causing issues. This is necessary because the function might be called multiple times in some processes.

vllm/v1/metrics/loggers.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from vllm.config import SupportsMetricsInfo, VllmConfig
1212
from vllm.logger import init_logger
13+
from vllm.plugins import load_plugins_by_group
1314
from vllm.v1.core.kv_cache_utils import PrefixCachingMetrics
1415
from vllm.v1.engine import FinishReason
1516
from vllm.v1.metrics.prometheus import unregister_vllm_metrics
@@ -637,6 +638,23 @@ def build_1_2_5_buckets(max_value: int) -> list[int]:
637638
return build_buckets([1, 2, 5], max_value)
638639

639640

641+
def load_stat_logger_plugin_factories() -> list[StatLoggerFactory]:
642+
factories: list[StatLoggerFactory] = []
643+
644+
for name, plugin_class in load_plugins_by_group(
645+
"vllm.stat_logger_plugins").items():
646+
if not isinstance(plugin_class, type) or not issubclass(
647+
plugin_class, StatLoggerBase):
648+
logger.warning(
649+
"Stat logger plugin %s is not a valid subclass "
650+
"of StatLoggerBase. Skipping.", name)
651+
continue
652+
653+
factories.append(plugin_class)
654+
655+
return factories
656+
657+
640658
class StatLoggerManager:
641659
"""
642660
StatLoggerManager:
@@ -664,6 +682,9 @@ def __init__(
664682
if custom_stat_loggers is not None:
665683
factories.extend(custom_stat_loggers)
666684

685+
# Load plugin-based stat loggers
686+
factories.extend(load_stat_logger_plugin_factories())
687+
667688
if enable_default_loggers and logger.isEnabledFor(logging.INFO):
668689
if client_count > 1:
669690
logger.warning(

0 commit comments

Comments
 (0)