44import importlib
55from typing import TYPE_CHECKING , Callable
66
7+ # yapf: disable
78import vllm .envs as envs
8- from vllm .distributed .kv_transfer .kv_connector .base import KVConnectorBase
9+ from vllm .distributed .kv_transfer .kv_connector .base import (
10+ KVConnectorBase , KVConnectorBaseType )
911from vllm .distributed .kv_transfer .kv_connector .v1 import KVConnectorRole
1012from vllm .logger import init_logger
1113
14+ # yapf: enable
15+
1216if TYPE_CHECKING :
13- from vllm .config import VllmConfig
17+ from vllm .config import KVTransferConfig , VllmConfig
1418
1519logger = init_logger (__name__ )
1620
@@ -42,17 +46,7 @@ def create_connector(
4246 f"but found { envs .VLLM_USE_V1 = } " )
4347
4448 kv_transfer_config = config .kv_transfer_config
45- connector_name = kv_transfer_config .kv_connector
46- if connector_name in cls ._registry :
47- connector_cls = cls ._registry [connector_name ]()
48- else :
49- connector_module_path = kv_transfer_config .kv_connector_module_path
50- if connector_module_path is None :
51- raise ValueError (
52- f"Unsupported connector type: { connector_name } " )
53- connector_module = importlib .import_module (connector_module_path )
54- connector_cls = getattr (connector_module , connector_name )
55- assert issubclass (connector_cls , KVConnectorBase )
49+ connector_cls = cls .get_connector_class (kv_transfer_config )
5650 logger .info ("Creating v1 connector with name: %s and engine_id: %s" ,
5751 connector_cls .__name__ , kv_transfer_config .engine_id )
5852 # NOTE(Kuntai): v1 connector is explicitly separated into two roles.
@@ -65,6 +59,23 @@ def create_connector(
6559 # We build separately to enforce strict separation
6660 return connector_cls (config , role )
6761
62+ @classmethod
63+ def get_connector_class (
64+ cls , kv_transfer_config : "KVTransferConfig"
65+ ) -> type [KVConnectorBaseType ]:
66+ """Get the connector class by name."""
67+ connector_name = kv_transfer_config .kv_connector
68+ if connector_name in cls ._registry :
69+ connector_cls = cls ._registry [connector_name ]()
70+ else :
71+ connector_module_path = kv_transfer_config .kv_connector_module_path
72+ if connector_module_path is None :
73+ raise ValueError (
74+ f"Unsupported connector type: { connector_name } " )
75+ connector_module = importlib .import_module (connector_module_path )
76+ connector_cls = getattr (connector_module , connector_name )
77+ return connector_cls
78+
6879
6980# Register various connectors here.
7081# The registration should not be done in each individual file, as we want to
0 commit comments