Signed-off-by: Meng <meng_chen99@163.com> Signed-off-by: Yangshen Deng <yangshen.d@outlook.com> Signed-off-by: Suli Wang <50828270+wsl2000@users.noreply.github.com> Co-authored-by: Meng <meng_chen99@163.com> Co-authored-by: Suli Wang <50828270+wsl2000@users.noreply.github.com> Co-authored-by: amy-why-3459 <wuhaiyan17@huawei.com>
47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
# SPDX-License-Identifier: Apache-2.0
|
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
|
|
|
import numpy as np
|
|
import pytest
|
|
|
|
from tests.dreamzero import openpi_client_helper
|
|
|
|
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
|
|
|
|
|
|
class FakeMsgpackNumpy:
|
|
payloads = {}
|
|
|
|
@staticmethod
|
|
def packb(obj):
|
|
key = str(len(FakeMsgpackNumpy.payloads)).encode()
|
|
FakeMsgpackNumpy.payloads[key] = obj
|
|
return key
|
|
|
|
@staticmethod
|
|
def unpackb(data):
|
|
return FakeMsgpackNumpy.payloads[data]
|
|
|
|
|
|
def test_decode_action_response_surfaces_structured_error(monkeypatch):
|
|
monkeypatch.setattr(openpi_client_helper, "msgpack_numpy", FakeMsgpackNumpy)
|
|
payload = FakeMsgpackNumpy.packb(
|
|
{
|
|
"type": "error",
|
|
"message": "Internal inference error",
|
|
}
|
|
)
|
|
|
|
with pytest.raises(RuntimeError, match="Internal inference error"):
|
|
openpi_client_helper._decode_action_response(payload)
|
|
|
|
|
|
def test_decode_action_response_converts_action_payload_to_float32(monkeypatch):
|
|
monkeypatch.setattr(openpi_client_helper, "msgpack_numpy", FakeMsgpackNumpy)
|
|
payload = FakeMsgpackNumpy.packb(np.asarray([[1.0, 2.0]], dtype=np.float64))
|
|
|
|
actions = openpi_client_helper._decode_action_response(payload)
|
|
|
|
assert actions.dtype == np.float32
|
|
np.testing.assert_array_equal(actions, np.asarray([[1.0, 2.0]], dtype=np.float32))
|