Skip to content

Commit 222a2e4

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 9360d34 commit 222a2e4

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
@@ -12,6 +12,7 @@
1212
from vllm.distributed.kv_transfer.kv_connector.v1.metrics import (
1313
KVConnectorLogging)
1414
from vllm.logger import init_logger
15+
from vllm.plugins import load_plugins_by_group
1516
from vllm.v1.core.kv_cache_utils import PrefixCachingMetrics
1617
from vllm.v1.engine import FinishReason
1718
from vllm.v1.metrics.prometheus import unregister_vllm_metrics
@@ -657,6 +658,23 @@ def build_1_2_5_buckets(max_value: int) -> list[int]:
657658
return build_buckets([1, 2, 5], max_value)
658659

659660

661+
def load_stat_logger_plugin_factories() -> list[StatLoggerFactory]:
662+
factories: list[StatLoggerFactory] = []
663+
664+
for name, plugin_class in load_plugins_by_group(
665+
"vllm.stat_logger_plugins").items():
666+
if not isinstance(plugin_class, type) or not issubclass(
667+
plugin_class, StatLoggerBase):
668+
logger.warning(
669+
"Stat logger plugin %s is not a valid subclass "
670+
"of StatLoggerBase. Skipping.", name)
671+
continue
672+
673+
factories.append(plugin_class)
674+
675+
return factories
676+
677+
660678
class StatLoggerManager:
661679
"""
662680
StatLoggerManager:
@@ -684,6 +702,9 @@ def __init__(
684702
if custom_stat_loggers is not None:
685703
factories.extend(custom_stat_loggers)
686704

705+
# Load plugin-based stat loggers
706+
factories.extend(load_stat_logger_plugin_factories())
707+
687708
if enable_default_loggers and logger.isEnabledFor(logging.INFO):
688709
if client_count > 1:
689710
logger.warning(

0 commit comments

Comments
 (0)