[Refactor] msgspec standardisation for data entry key names and improved type checks (#3149)
Signed-off-by: Divyansh Singhvi <divyanshsinghvi@gmail.com> Signed-off-by: dsinghvi <divyanshsinghvi@gmail.com>
This commit is contained in:
1 parent
9a60e11e3d
commit
e40076e872
25 files changed
+1047
-686
No files matched your search
@@ -12,7 +12,7 @@ from pytest_mock import MockerFixture
|
||||
from vllm.v1.core.sched.scheduler import Scheduler as VLLMScheduler
|
||||
from vllm.v1.request import RequestStatus
|
||||
|
||||
from vllm_omni.data_entry_keys import OmniPayload
|
||||
from vllm_omni.data_entry_keys import CodesStruct, MetaStruct, OmniPayload, OmniPayloadStruct
|
||||
from vllm_omni.distributed.omni_connectors.transfer_adapter.base import OmniTransferAdapterBase
|
||||
from vllm_omni.distributed.omni_connectors.transfer_adapter.chunk_transfer_adapter import (
|
||||
OmniChunkTransferAdapter,
|
||||
@@ -140,11 +140,54 @@ def test_save_async(build_adapter):
|
||||
assert task["is_finished"] is False
|
||||
|
||||
|
||||
def test_send_single_request_struct_without_meta_does_not_crash(build_adapter, monkeypatch):
|
||||
"""Producer may return a struct with ``meta=None`` (e.g. payload that
|
||||
carries only ``embed`` or ``codes``). The sender's ``meta is not None``
|
||||
guard handles this without AttributeError; ``finished_flag`` is None and
|
||||
the cleanup path is not triggered.
|
||||
"""
|
||||
adapter, _ = build_adapter(stage_id=1)
|
||||
request = _req("req-no-meta", RequestStatus.WAITING, external_req_id="ext-no-meta")
|
||||
|
||||
adapter.custom_process_next_stage_input_func = lambda **kwargs: OmniPayloadStruct(
|
||||
codes=CodesStruct(audio=torch.tensor([1, 2], dtype=torch.long)),
|
||||
)
|
||||
cleanup_calls = []
|
||||
monkeypatch.setattr(adapter, "cleanup", lambda *a, **kw: cleanup_calls.append((a, kw)))
|
||||
|
||||
adapter._send_single_request({"pooling_output": None, "request": request, "is_finished": False})
|
||||
|
||||
assert cleanup_calls == [] # no terminal cleanup; meta.finished is unobservable
|
||||
|
||||
|
||||
def test_send_single_request_empty_struct_goes_on_wire(build_adapter, monkeypatch):
|
||||
"""Pin the contract: an explicitly empty ``OmniPayloadStruct()`` passes
|
||||
the ``payload_data is None`` check and gets sent. To skip a chunk, the
|
||||
producer must return ``None``, not an empty struct. (Filtering empty
|
||||
structs at the adapter would require introspecting all struct fields on
|
||||
every send and was rejected for cost vs. value.)
|
||||
"""
|
||||
adapter, connector = build_adapter(stage_id=1)
|
||||
request = _req("req-empty", RequestStatus.WAITING, external_req_id="ext-empty")
|
||||
|
||||
adapter.custom_process_next_stage_input_func = lambda **kwargs: OmniPayloadStruct()
|
||||
monkeypatch.setattr(adapter, "cleanup", lambda *a, **kw: None)
|
||||
|
||||
adapter._send_single_request({"pooling_output": None, "request": request, "is_finished": False})
|
||||
|
||||
assert connector.put.called
|
||||
sent_payload = connector.put.call_args.kwargs["data"]
|
||||
assert isinstance(sent_payload, OmniPayloadStruct)
|
||||
assert sent_payload.meta is None # confirms it's the empty struct on the wire
|
||||
|
||||
|
||||
def test_send_single_request_cleans_up_after_finished_payload(build_adapter, monkeypatch):
|
||||
adapter, _ = build_adapter(stage_id=1)
|
||||
request = _req("req-finished", RequestStatus.FINISHED_STOPPED, external_req_id="ext-finished")
|
||||
|
||||
adapter.custom_process_next_stage_input_func = lambda **kwargs: {"x": [1], "finished": True}
|
||||
adapter.custom_process_next_stage_input_func = lambda **kwargs: OmniPayloadStruct(
|
||||
meta=MetaStruct(finished=torch.tensor(True, dtype=torch.bool))
|
||||
)
|
||||
cleanup_calls = []
|
||||
monkeypatch.setattr(adapter, "cleanup", lambda *a, **kw: cleanup_calls.append((a, kw)))
|
||||
|
||||
@@ -604,3 +647,42 @@ def test_omni_ar_scheduler_finish_requests(mocker: MockerFixture):
|
||||
OmniARScheduler.finish_requests(sched, ["r1"], RequestStatus.FINISHED_ABORTED)
|
||||
|
||||
assert order == ["adapter", "super"]
|
||||
|
||||
|
||||
def test_wire_round_trip_struct_to_dict_contract():
|
||||
"""Pin the wire contract: encoding ``OmniPayloadStruct`` and decoding it
|
||||
yields a dict equivalent to ``to_dict(struct)``.
|
||||
|
||||
The chunk-adapter sender uses struct attribute access while the receiver
|
||||
uses dict-key access. This works only because ``OmniMsgpackDecoder`` has
|
||||
no target type and decodes structs back to plain dicts. If this test
|
||||
breaks, the receiver's dict access will silently drop fields or KeyError.
|
||||
"""
|
||||
from vllm_omni.data_entry_keys import CodesStruct, to_dict
|
||||
from vllm_omni.distributed.omni_connectors.utils.serialization import (
|
||||
OmniMsgpackDecoder,
|
||||
OmniMsgpackEncoder,
|
||||
)
|
||||
|
||||
struct = OmniPayloadStruct(
|
||||
meta=MetaStruct(
|
||||
finished=torch.tensor(True, dtype=torch.bool),
|
||||
left_context_size=12,
|
||||
),
|
||||
codes=CodesStruct(audio=torch.tensor([1, 2, 3], dtype=torch.int64)),
|
||||
)
|
||||
|
||||
encoded = OmniMsgpackEncoder().encode(struct)
|
||||
decoded = OmniMsgpackDecoder().decode(encoded)
|
||||
|
||||
assert isinstance(decoded, dict)
|
||||
assert isinstance(decoded["meta"], dict)
|
||||
assert isinstance(decoded["meta"]["finished"], torch.Tensor)
|
||||
assert bool(decoded["meta"]["finished"].item()) is True
|
||||
assert decoded["meta"]["left_context_size"] == 12
|
||||
assert torch.equal(decoded["codes"]["audio"], torch.tensor([1, 2, 3], dtype=torch.int64))
|
||||
|
||||
expected = to_dict(struct)
|
||||
assert set(decoded.keys()) == set(expected.keys())
|
||||
assert set(decoded["meta"].keys()) == set(expected["meta"].keys())
|
||||
assert set(decoded["codes"].keys()) == set(expected["codes"].keys())
|
||||
Reference in new issue
Block a user