Download tests/test_full_duplex_audio_contract.py from Tinghong-Ye22/code-HFD: direct link, hf CLI and curl.
- Browser
- Download file 1.83 kB
-
https://huggingface.co/Tinghong-Ye22/code-HFD/resolve/main/tests/test_full_duplex_audio_contract.py
- Command line
-
hf download hf://Tinghong-Ye22/code-HFD/tests/test_full_duplex_audio_contract.py
-
curl -L -o test_full_duplex_audio_contract.py https://huggingface.co/Tinghong-Ye22/code-HFD/resolve/main/tests/test_full_duplex_audio_contract.py
1.83 kB
| from __future__ import annotations | |
| import json | |
| import pytest | |
| from psi.data.seed.full_duplex_audio_contract import ( | |
| HFD_ONLINE_ENCODER_CONTRACT, | |
| encoder_contract_payload, | |
| validate_encoder_cache, | |
| write_json_atomic, | |
| ) | |
| def _write_fake_model(path): | |
| path.mkdir() | |
| (path / "config.json").write_text('{"model_type": "qwen2_5_omni"}\n') | |
| (path / "tokenizer_config.json").write_text('{"model_max_length": 32768}\n') | |
| def test_verified_encoder_cache_contract_is_accepted(tmp_path): | |
| model = tmp_path / "model" | |
| cache = tmp_path / "cache" | |
| _write_fake_model(model) | |
| contract = encoder_contract_payload(model) | |
| write_json_atomic(cache / "_reports" / "encoder_contract.json", contract) | |
| write_json_atomic( | |
| cache / "_reports" / "online_hidden_verify.json", | |
| { | |
| **contract, | |
| "verified_sources": 2, | |
| "verified_windows": 3, | |
| "mismatched_windows": 0, | |
| "max_abs_error": 0.0, | |
| }, | |
| ) | |
| accepted = validate_encoder_cache(cache, model) | |
| assert accepted["encoder_contract"] == HFD_ONLINE_ENCODER_CONTRACT | |
| def test_non_exact_online_report_is_rejected(tmp_path): | |
| model = tmp_path / "model" | |
| cache = tmp_path / "cache" | |
| _write_fake_model(model) | |
| contract = encoder_contract_payload(model) | |
| write_json_atomic(cache / "_reports" / "encoder_contract.json", contract) | |
| report = { | |
| **contract, | |
| "verified_windows": 1, | |
| "mismatched_windows": 1, | |
| "max_abs_error": 0.125, | |
| } | |
| report_path = cache / "_reports" / "online_hidden_verify.json" | |
| report_path.parent.mkdir(parents=True, exist_ok=True) | |
| report_path.write_text(json.dumps(report)) | |
| with pytest.raises(RuntimeError, match="failed exact online equivalence"): | |
| validate_encoder_cache(cache, model) | |