55from  typing  import  TYPE_CHECKING , Callable 
66
77import  vllm .envs  as  envs 
8+ from  vllm .config  import  KVTransferConfig 
89from  vllm .distributed .kv_transfer .kv_connector .base  import  KVConnectorBaseType 
910from  vllm .distributed .kv_transfer .kv_connector .v1  import  (KVConnectorBase_V1 ,
1011                                                          KVConnectorRole )
@@ -41,25 +42,15 @@ def create_connector_v0(cls, rank: int, local_rank: int,
4142            raise  ValueError ("Attempting to initialize a V0 Connector, " 
4243                             f"but found { envs .VLLM_USE_V1 = }  )
4344
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 )
4946        assert  issubclass (connector_cls , KVConnectorBase )
5047        return  connector_cls (rank , local_rank , config )
5148
5249    @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.""" 
6354        connector_name  =  kv_transfer_config .kv_connector 
6455        if  connector_name  in  cls ._registry :
6556            connector_cls  =  cls ._registry [connector_name ]()
@@ -70,9 +61,23 @@ def create_connector_v1(
7061                    f"Unsupported connector type: { connector_name }  )
7162            connector_module  =  importlib .import_module (connector_module_path )
7263            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 )
7378        assert  issubclass (connector_cls , KVConnectorBase_V1 )
7479        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 )
7681        # NOTE(Kuntai): v1 connector is explicitly separated into two roles. 
7782        # Scheduler connector: 
7883        # - Co-locate with scheduler process 
0 commit comments