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
288ca110
Unverified
Commit
288ca110
authored
Mar 04, 2025
by
Kuntai Du
Committed by
GitHub
Mar 04, 2025
Browse files
[Security] Serialize using safetensors instead of pickle in Mooncake Pipe (#14228)
Signed-off-by:
KuntaiDu
<
kuntai@uchicago.edu
>
parent
c2bd2196
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
6 deletions
+6
-6
vllm/distributed/kv_transfer/kv_pipe/mooncake_pipe.py
vllm/distributed/kv_transfer/kv_pipe/mooncake_pipe.py
+6
-6
No files found.
vllm/distributed/kv_transfer/kv_pipe/mooncake_pipe.py
View file @
288ca110
...
@@ -2,13 +2,14 @@
...
@@ -2,13 +2,14 @@
import
json
import
json
import
os
import
os
import
pickle
from
concurrent.futures
import
ThreadPoolExecutor
from
concurrent.futures
import
ThreadPoolExecutor
from
dataclasses
import
dataclass
from
dataclasses
import
dataclass
from
typing
import
Optional
,
Union
from
typing
import
Optional
,
Union
import
torch
import
torch
import
zmq
import
zmq
from
safetensors.torch
import
load
as
safetensors_load
from
safetensors.torch
import
save
as
safetensors_save
from
vllm.config
import
KVTransferConfig
from
vllm.config
import
KVTransferConfig
from
vllm.distributed.kv_transfer.kv_pipe.base
import
KVPipeBase
from
vllm.distributed.kv_transfer.kv_pipe.base
import
KVPipeBase
...
@@ -237,14 +238,13 @@ class MooncakePipe(KVPipeBase):
...
@@ -237,14 +238,13 @@ class MooncakePipe(KVPipeBase):
return
hash
(
tensor
.
data_ptr
())
return
hash
(
tensor
.
data_ptr
())
def
_send_impl
(
self
,
tensor
:
torch
.
Tensor
)
->
None
:
def
_send_impl
(
self
,
tensor
:
torch
.
Tensor
)
->
None
:
"""Implement the tensor sending logic."""
"""Implement the tensor sending logic using safetensors."""
value_bytes
=
pickle
.
dumps
(
tensor
)
self
.
transfer_engine
.
send_bytes
(
safetensors_save
({
"tensor"
:
tensor
}))
self
.
transfer_engine
.
send_bytes
(
value_bytes
)
def
_recv_impl
(
self
)
->
torch
.
Tensor
:
def
_recv_impl
(
self
)
->
torch
.
Tensor
:
"""Implement the tensor receiving logic."""
"""Implement the tensor receiving logic
using safetensors
."""
data
=
self
.
transfer_engine
.
recv_bytes
()
data
=
self
.
transfer_engine
.
recv_bytes
()
return
pickle
.
load
s
(
data
)
return
safetensors_
load
(
data
)
[
"tensor"
].
to
(
self
.
device
)
def
send_tensor
(
self
,
tensor
:
Optional
[
torch
.
Tensor
])
->
None
:
def
send_tensor
(
self
,
tensor
:
Optional
[
torch
.
Tensor
])
->
None
:
"""Send tensor to the target process."""
"""Send tensor to the target process."""
...
...
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