Skip to content

Commit 6f356ec

Browse files
author
David Ben-David
committed
Support dynamic loading of external KV connector implementations
Added a new 'kv_connector_module_path' field to KVTransferConfig. If a connector name is not found in the internal registry, the factory will now attempt to load it dynamically using the provided module path Signed-off-by: David Ben-David <davidb@pliops.com>
1 parent e23564c commit 6f356ec

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

vllm/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3491,6 +3491,10 @@ class KVTransferConfig:
34913491
"""The KV connector for vLLM to transmit KV caches between vLLM instances.
34923492
"""
34933493

3494+
kv_connector_module_path: Optional[str] = None
3495+
"""The Python module path to dynamically load the KV connector from.
3496+
Only supported in V1."""
3497+
34943498
engine_id: str = str(uuid.uuid4())
34953499
"""The engine id for KV transfers."""
34963500

vllm/distributed/kv_transfer/kv_connector/factory.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,17 @@ def create_connector_v1(
5858
raise ValueError("Attempting to initialize a V1 Connector, "
5959
f"but found {envs.VLLM_USE_V1=}")
6060

61-
connector_name = config.kv_transfer_config.kv_connector
62-
connector_cls = cls._registry[connector_name]()
61+
kv_transfer_config = config.kv_transfer_config
62+
connector_name = kv_transfer_config.kv_connector
63+
if connector_name in cls._registry:
64+
connector_cls = cls._registry[connector_name]()
65+
else:
66+
connector_module_path = kv_transfer_config.kv_connector_module_path
67+
if connector_module_path is None:
68+
raise ValueError(
69+
f"Unsupported connector type: {connector_name}")
70+
connector_module = importlib.import_module(connector_module_path)
71+
connector_cls = getattr(connector_module, connector_name)
6372
assert issubclass(connector_cls, KVConnectorBase_V1)
6473
logger.info("Creating v1 connector with name: %s", connector_name)
6574
# NOTE(Kuntai): v1 connector is explicitly separated into two roles.

0 commit comments

Comments
 (0)