5
5
from typing import TYPE_CHECKING , Callable
6
6
7
7
import vllm .envs as envs
8
+ from vllm .config import KVTransferConfig
8
9
from vllm .distributed .kv_transfer .kv_connector .base import KVConnectorBaseType
9
10
from vllm .distributed .kv_transfer .kv_connector .v1 import (KVConnectorBase_V1 ,
10
11
KVConnectorRole )
@@ -41,25 +42,15 @@ def create_connector_v0(cls, rank: int, local_rank: int,
41
42
raise ValueError ("Attempting to initialize a V0 Connector, "
42
43
f"but found { envs .VLLM_USE_V1 = } " )
43
44
44
- connector_name = config .kv_transfer_config .kv_connector
45
- if connector_name not in cls ._registry :
46
- raise ValueError (f"Unsupported connector type: { connector_name } " )
47
-
48
- connector_cls = cls ._registry [connector_name ]()
45
+ connector_cls = cls .get_connector_class (config .kv_transfer_config )
49
46
assert issubclass (connector_cls , KVConnectorBase )
50
47
return connector_cls (rank , local_rank , config )
51
48
52
49
@classmethod
53
- def create_connector_v1 (
54
- cls ,
55
- config : "VllmConfig" ,
56
- role : KVConnectorRole ,
57
- ) -> KVConnectorBase_V1 :
58
- if not envs .VLLM_USE_V1 :
59
- raise ValueError ("Attempting to initialize a V1 Connector, "
60
- f"but found { envs .VLLM_USE_V1 = } " )
61
-
62
- kv_transfer_config = config .kv_transfer_config
50
+ def get_connector_class (
51
+ cls , kv_transfer_config : "KVTransferConfig"
52
+ ) -> type [KVConnectorBaseType ]:
53
+ """Get the connector class by name."""
63
54
connector_name = kv_transfer_config .kv_connector
64
55
if connector_name in cls ._registry :
65
56
connector_cls = cls ._registry [connector_name ]()
@@ -70,9 +61,23 @@ def create_connector_v1(
70
61
f"Unsupported connector type: { connector_name } " )
71
62
connector_module = importlib .import_module (connector_module_path )
72
63
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 )
73
78
assert issubclass (connector_cls , KVConnectorBase_V1 )
74
79
logger .info ("Creating v1 connector with name: %s and engine_id: %s" ,
75
- connector_name , kv_transfer_config .engine_id )
80
+ connector_cls . __name__ , kv_transfer_config .engine_id )
76
81
# NOTE(Kuntai): v1 connector is explicitly separated into two roles.
77
82
# Scheduler connector:
78
83
# - Co-locate with scheduler process
0 commit comments