[Security][Feature] Use Msgpack in OmniSerializer instead of pickle (#310)
Signed-off-by: gcanlin <canlinguosdu@gmail.com>
This commit is contained in:
1 parent
a7fe4fba4e
commit
97a5860681
5 files changed
+380
-64
No files matched your search
@@ -10,16 +10,38 @@ from vllm_omni.distributed.omni_connectors.utils.config import ConnectorSpec
|
||||
from vllm_omni.distributed.omni_connectors.utils.serialization import OmniSerializer
|
||||
|
||||
|
||||
def test_pickle_serialization():
|
||||
"""Test basic pickle serialization."""
|
||||
def test_basic_serialization():
|
||||
"""Test basic msgpack serialization."""
|
||||
data = {"key": "value", "list": [1, 2, 3]}
|
||||
serialized = OmniSerializer.serialize(data, method="cloudpickle")
|
||||
serialized = OmniSerializer.serialize(data)
|
||||
assert isinstance(serialized, bytes)
|
||||
|
||||
deserialized = OmniSerializer.deserialize(serialized, method="cloudpickle")
|
||||
deserialized = OmniSerializer.deserialize(serialized)
|
||||
assert data == deserialized
|
||||
|
||||
|
||||
def test_tensor_serialization():
|
||||
"""Test torch.Tensor serialization."""
|
||||
import torch
|
||||
|
||||
tensor = torch.tensor([[1.0, 2.0], [3.0, 4.0]])
|
||||
serialized = OmniSerializer.serialize(tensor)
|
||||
deserialized = OmniSerializer.deserialize(serialized)
|
||||
|
||||
assert torch.equal(tensor, deserialized)
|
||||
|
||||
|
||||
def test_ndarray_serialization():
|
||||
"""Test numpy.ndarray serialization."""
|
||||
import numpy as np
|
||||
|
||||
arr = np.array([[1, 2, 3], [4, 5, 6]])
|
||||
serialized = OmniSerializer.serialize(arr)
|
||||
deserialized = OmniSerializer.deserialize(serialized)
|
||||
|
||||
assert np.array_equal(arr, deserialized)
|
||||
|
||||
|
||||
def test_create_shm_connector():
|
||||
"""Test creating SharedMemoryConnector via Factory."""
|
||||
spec = ConnectorSpec(name="SharedMemoryConnector", extra={"shm_threshold_bytes": 1024})
|
||||
|
||||
@@ -676,7 +676,8 @@ def test_generate_pipeline_and_final_outputs(monkeypatch, fake_stage_config):
|
||||
}
|
||||
)
|
||||
|
||||
sampling_params_list = [object(), object()]
|
||||
# Use dicts instead of object() for serializable sampling params
|
||||
sampling_params_list = [{"temperature": 0.7}, {"temperature": 0.8}]
|
||||
prompts = ["hi"]
|
||||
outputs = llm.generate(prompts=prompts, sampling_params_list=sampling_params_list)
|
||||
|
||||
@@ -771,7 +772,8 @@ def test_generate_no_final_output_returns_empty(monkeypatch, fake_stage_config):
|
||||
}
|
||||
)
|
||||
|
||||
outputs = llm.generate(prompts=["p"], sampling_params_list=[object(), object()])
|
||||
# Use dicts instead of object() for serializable sampling params
|
||||
outputs = llm.generate(prompts=["p"], sampling_params_list=[{"temperature": 0.7}, {"temperature": 0.8}])
|
||||
assert outputs == []
|
||||
|
||||
|
||||
@@ -970,7 +972,8 @@ def test_generate_handles_error_messages(monkeypatch, fake_stage_config):
|
||||
)
|
||||
|
||||
# Generate should handle error gracefully (log but continue)
|
||||
sampling_params_list = [object()]
|
||||
# Use dict instead of object() for serializable sampling params
|
||||
sampling_params_list = [{"temperature": 0.7}]
|
||||
outputs = llm.generate(prompts=["hi"], sampling_params_list=sampling_params_list)
|
||||
# Should return final output (error was logged but didn't stop processing)
|
||||
assert isinstance(outputs, list)
|
||||
|
||||
Reference in new issue
Block a user