55from typing import TYPE_CHECKING , Callable
66
77import vllm .envs as envs
8- from vllm .config import KVTransferConfig
9- from vllm .distributed .kv_transfer .kv_connector .base import KVConnectorBaseType
10- from vllm .distributed .kv_transfer .kv_connector .v1 import (KVConnectorBase_V1 ,
11- KVConnectorRole )
8+ from vllm .distributed .kv_transfer .kv_connector .base import KVConnectorBase
9+ from vllm .distributed .kv_transfer .kv_connector .v1 import KVConnectorRole
1210from vllm .logger import init_logger
1311
14- from .base import KVConnectorBase
15-
1612if TYPE_CHECKING :
1713 from vllm .config import VllmConfig
1814
1915logger = init_logger (__name__ )
2016
2117
2218class KVConnectorFactory :
23- _registry : dict [str , Callable [[], type [KVConnectorBaseType ]]] = {}
19+ _registry : dict [str , Callable [[], type [KVConnectorBase ]]] = {}
2420
2521 @classmethod
2622 def register_connector (cls , name : str , module_path : str ,
@@ -29,28 +25,23 @@ def register_connector(cls, name: str, module_path: str,
2925 if name in cls ._registry :
3026 raise ValueError (f"Connector '{ name } ' is already registered." )
3127
32- def loader () -> type [KVConnectorBaseType ]:
28+ def loader () -> type [KVConnectorBase ]:
3329 module = importlib .import_module (module_path )
3430 return getattr (module , class_name )
3531
3632 cls ._registry [name ] = loader
3733
3834 @classmethod
39- def create_connector_v0 (cls , rank : int , local_rank : int ,
40- config : "VllmConfig" ) -> KVConnectorBase :
41- if envs .VLLM_USE_V1 :
42- raise ValueError ("Attempting to initialize a V0 Connector, "
35+ def create_connector (
36+ cls ,
37+ config : "VllmConfig" ,
38+ role : KVConnectorRole ,
39+ ) -> KVConnectorBase :
40+ if not envs .VLLM_USE_V1 :
41+ raise ValueError ("Attempting to initialize a V1 Connector, "
4342 f"but found { envs .VLLM_USE_V1 = } " )
4443
45- connector_cls = cls .get_connector_class (config .kv_transfer_config )
46- assert issubclass (connector_cls , KVConnectorBase )
47- return connector_cls (rank , local_rank , config )
48-
49- @classmethod
50- def get_connector_class (
51- cls , kv_transfer_config : "KVTransferConfig"
52- ) -> type [KVConnectorBaseType ]:
53- """Get the connector class by name."""
44+ kv_transfer_config = config .kv_transfer_config
5445 connector_name = kv_transfer_config .kv_connector
5546 if connector_name in cls ._registry :
5647 connector_cls = cls ._registry [connector_name ]()
@@ -61,21 +52,7 @@ def get_connector_class(
6152 f"Unsupported connector type: { connector_name } " )
6253 connector_module = importlib .import_module (connector_module_path )
6354 connector_cls = getattr (connector_module , connector_name )
64- return connector_cls
65-
66- @classmethod
67- def create_connector_v1 (
68- cls ,
69- config : "VllmConfig" ,
70- role : KVConnectorRole ,
71- ) -> KVConnectorBase_V1 :
72- if not envs .VLLM_USE_V1 :
73- raise ValueError ("Attempting to initialize a V1 Connector, "
74- f"but found { envs .VLLM_USE_V1 = } " )
75-
76- kv_transfer_config = config .kv_transfer_config
77- connector_cls = cls .get_connector_class (kv_transfer_config )
78- assert issubclass (connector_cls , KVConnectorBase_V1 )
55+ assert issubclass (connector_cls , KVConnectorBase )
7956 logger .info ("Creating v1 connector with name: %s and engine_id: %s" ,
8057 connector_cls .__name__ , kv_transfer_config .engine_id )
8158 # NOTE(Kuntai): v1 connector is explicitly separated into two roles.
@@ -92,25 +69,6 @@ def create_connector_v1(
9269# Register various connectors here.
9370# The registration should not be done in each individual file, as we want to
9471# only load the files corresponding to the current connector.
95- KVConnectorFactory .register_connector (
96- "PyNcclConnector" ,
97- "vllm.distributed.kv_transfer.kv_connector.simple_connector" ,
98- "SimpleConnector" )
99-
100- KVConnectorFactory .register_connector (
101- "MooncakeConnector" ,
102- "vllm.distributed.kv_transfer.kv_connector.simple_connector" ,
103- "SimpleConnector" )
104-
105- KVConnectorFactory .register_connector (
106- "LMCacheConnector" ,
107- "vllm.distributed.kv_transfer.kv_connector.lmcache_connector" ,
108- "LMCacheConnector" )
109-
110- KVConnectorFactory .register_connector (
111- "MooncakeStoreConnector" ,
112- "vllm.distributed.kv_transfer.kv_connector.mooncake_store_connector" ,
113- "MooncakeStoreConnector" )
11472
11573KVConnectorFactory .register_connector (
11674 "SharedStorageConnector" ,
0 commit comments