Download scripts/test_runtime.py from matthiastl/tyger-onnx: direct link, hf CLI and curl.
- Browser
- Download file 1.49 kB
-
https://huggingface.co/matthiastl/tyger-onnx/resolve/main/scripts/test_runtime.py
- Command line
-
hf download hf://matthiastl/tyger-onnx/scripts/test_runtime.py
-
curl -L -o test_runtime.py https://huggingface.co/matthiastl/tyger-onnx/resolve/main/scripts/test_runtime.py
1.49 kB
| """The packaged runtime (`tyger_onnx.Tyger`) gives the same events, on the same frames, as the port that was scored | |
| (`turns.py` on `port.py`'s frames), on the first 3 test calls, listening and speaking. | |
| ../sava-onnx/.venv/bin/python -I -m pytest test_runtime.py | |
| """ | |
| from __future__ import annotations | |
| import sys | |
| from pathlib import Path | |
| import numpy as np | |
| HERE = Path(__file__).parent | |
| sys.path[:0] = [str(HERE), str(HERE.parent)] | |
| import port # noqa: E402 | |
| import turns # noqa: E402 | |
| import tyger_ref as tr # noqa: E402 | |
| from tyger_onnx import Tyger # noqa: E402 | |
| from vendor.tyger_s2s.constants import HOP_FRAMES, HOP_N # noqa: E402 | |
| def runtime_events(folder, user, agent, mode, hops): | |
| tyger, events = Tyger(folder=folder), [] | |
| for k in range(hops): | |
| frame = 0 | |
| for e in tyger.process(user[k * HOP_N:(k + 1) * HOP_N], agent[k * HOP_N:(k + 1) * HOP_N], mode): | |
| if e["kind"] in turns.EVENTS: | |
| events.append((e["kind"], k * HOP_FRAMES + frame)) | |
| frame += e["kind"] == "FRAME" | |
| return events | |
| def test_runtime_matches_scored_port(): | |
| folder = HERE / "export" | |
| gru = port.TurnTaker(folder / "turn_taker.onnx", 4) | |
| for name, mode, user, agent in tr.segments(3): | |
| frames = np.load(HERE / "runs" / "int8" / f"{name}-{mode}.npz") | |
| want = turns.with_rules(gru, frames, mode, user, agent) | |
| assert runtime_events(folder, user, agent, mode, len(frames["act"]) // HOP_FRAMES) == want, (name, mode) | |