Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
vllm_cscc
Commits
faef77c0
Unverified
Commit
faef77c0
authored
Dec 29, 2024
by
Kuntai Du
Committed by
GitHub
Dec 29, 2024
Browse files
[Misc] KV cache transfer connector registry (#11481)
Signed-off-by:
KuntaiDu
<
kuntai@uchicago.edu
>
parent
dba4d9de
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
18 deletions
+38
-18
vllm/config.py
vllm/config.py
+0
-8
vllm/distributed/kv_transfer/kv_connector/factory.py
vllm/distributed/kv_transfer/kv_connector/factory.py
+38
-10
No files found.
vllm/config.py
View file @
faef77c0
...
@@ -2559,14 +2559,6 @@ class KVTransferConfig(BaseModel):
...
@@ -2559,14 +2559,6 @@ class KVTransferConfig(BaseModel):
return
KVTransferConfig
.
model_validate_json
(
cli_value
)
return
KVTransferConfig
.
model_validate_json
(
cli_value
)
def
model_post_init
(
self
,
__context
:
Any
)
->
None
:
def
model_post_init
(
self
,
__context
:
Any
)
->
None
:
supported_kv_connector
=
[
"PyNcclConnector"
,
"MooncakeConnector"
]
if
all
([
self
.
kv_connector
is
not
None
,
self
.
kv_connector
not
in
supported_kv_connector
]):
raise
ValueError
(
f
"Unsupported kv_connector:
{
self
.
kv_connector
}
. "
f
"Supported connectors are "
f
"
{
supported_kv_connector
}
."
)
if
self
.
kv_role
is
not
None
and
self
.
kv_role
not
in
[
if
self
.
kv_role
is
not
None
and
self
.
kv_role
not
in
[
"kv_producer"
,
"kv_consumer"
,
"kv_both"
"kv_producer"
,
"kv_consumer"
,
"kv_both"
...
...
vllm/distributed/kv_transfer/kv_connector/factory.py
View file @
faef77c0
from
typing
import
TYPE_CHECKING
import
importlib
from
typing
import
TYPE_CHECKING
,
Callable
,
Dict
,
Type
from
.base
import
KVConnectorBase
from
.base
import
KVConnectorBase
...
@@ -7,14 +8,41 @@ if TYPE_CHECKING:
...
@@ -7,14 +8,41 @@ if TYPE_CHECKING:
class
KVConnectorFactory
:
class
KVConnectorFactory
:
_registry
:
Dict
[
str
,
Callable
[[],
Type
[
KVConnectorBase
]]]
=
{}
@
staticmethod
@
classmethod
def
create_connector
(
rank
:
int
,
local_rank
:
int
,
def
register_connector
(
cls
,
name
:
str
,
module_path
:
str
,
class_name
:
str
)
->
None
:
"""Register a connector with a lazy-loading module and class name."""
if
name
in
cls
.
_registry
:
raise
ValueError
(
f
"Connector '
{
name
}
' is already registered."
)
def
loader
()
->
Type
[
KVConnectorBase
]:
module
=
importlib
.
import_module
(
module_path
)
return
getattr
(
module
,
class_name
)
cls
.
_registry
[
name
]
=
loader
@
classmethod
def
create_connector
(
cls
,
rank
:
int
,
local_rank
:
int
,
config
:
"VllmConfig"
)
->
KVConnectorBase
:
config
:
"VllmConfig"
)
->
KVConnectorBase
:
supported_kv_connector
=
[
"PyNcclConnector"
,
"MooncakeConnector"
]
connector_name
=
config
.
kv_transfer_config
.
kv_connector
if
config
.
kv_transfer_config
.
kv_connector
in
supported_kv_connector
:
if
connector_name
not
in
cls
.
_registry
:
from
.simple_connector
import
SimpleConnector
raise
ValueError
(
f
"Unsupported connector type:
{
connector_name
}
"
)
return
SimpleConnector
(
rank
,
local_rank
,
config
)
else
:
connector_cls
=
cls
.
_registry
[
connector_name
]()
raise
ValueError
(
f
"Unsupported connector type: "
return
connector_cls
(
rank
,
local_rank
,
config
)
f
"
{
config
.
kv_connector
}
"
)
# Register various connectors here.
# The registration should not be done in each individual file, as we want to
# only load the files corresponding to the current connector.
KVConnectorFactory
.
register_connector
(
"PyNcclConnector"
,
"vllm.distributed.kv_transfer.kv_connector.simple_connector"
,
"SimpleConnector"
)
KVConnectorFactory
.
register_connector
(
"MooncakeConnector"
,
"vllm.distributed.kv_transfer.kv_connector.simple_connector"
,
"SimpleConnector"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment