Download scripts/infer/validate_speech_qa_runtime.py from Tinghong-Ye22/code-HFD: direct link, hf CLI and curl.
- Browser
- Download file 2.92 kB
-
https://huggingface.co/Tinghong-Ye22/code-HFD/resolve/main/scripts/infer/validate_speech_qa_runtime.py
- Command line
-
hf download hf://Tinghong-Ye22/code-HFD/scripts/infer/validate_speech_qa_runtime.py
-
curl -L -o validate_speech_qa_runtime.py https://huggingface.co/Tinghong-Ye22/code-HFD/resolve/main/scripts/infer/validate_speech_qa_runtime.py
2.92 kB
| #!/usr/bin/env python3 | |
| """Validate optional formal speech/QA runtime inputs without loading a model. | |
| This is intentionally a startup contract check. It does not run Qwen, | |
| Talker or Token2Wav, and therefore cannot be mistaken for a speech-quality | |
| benchmark. The action renderer calls it only when the optional runtime is | |
| explicitly enabled. | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| import os | |
| import sys | |
| def _parser() -> argparse.ArgumentParser: | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--qa-checkpoint", default="") | |
| parser.add_argument("--qa-sha256", default="") | |
| parser.add_argument("--solver", default=os.environ.get("HFD_SPEECH_SOLVER", "euler")) | |
| parser.add_argument( | |
| "--solver-steps", | |
| type=int, | |
| default=int(os.environ.get("HFD_SPEECH_SOLVER_STEPS", "6")), | |
| ) | |
| parser.add_argument( | |
| "--codec-chunk-codes", | |
| type=int, | |
| default=int(os.environ.get("HFD_SPEECH_CODEC_CHUNK_CODES", "36")), | |
| ) | |
| parser.add_argument( | |
| "--first-chunk-codes", | |
| type=int, | |
| default=int(os.environ.get("HFD_SPEECH_FIRST_CHUNK_CODES", "36")), | |
| ) | |
| parser.add_argument( | |
| "--playback-buffer-seconds", | |
| type=float, | |
| default=float(os.environ.get("HFD_SPEECH_PLAYBACK_BUFFER_SECONDS", "0.20")), | |
| ) | |
| return parser | |
| def main(argv: list[str] | None = None) -> int: | |
| args = _parser().parse_args(argv) | |
| # Import through the source tree so this check works before package install. | |
| from psi.runtime import QAPrivateKVConfig, SpeechRuntimeConfig, validate_qa_checkpoint | |
| speech = SpeechRuntimeConfig( | |
| solver=args.solver, | |
| solver_steps=args.solver_steps, | |
| codec_chunk_codes=args.codec_chunk_codes, | |
| first_chunk_codes=args.first_chunk_codes, | |
| playback_buffer_seconds=args.playback_buffer_seconds, | |
| ).validate() | |
| payload: dict[str, object] = { | |
| "speech": { | |
| "solver": speech.solver, | |
| "solver_steps": speech.solver_steps, | |
| "codec_chunk_codes": speech.codec_chunk_codes, | |
| "first_chunk_codes": speech.first_chunk_codes, | |
| "playback_buffer_seconds": speech.playback_buffer_seconds, | |
| "fused_flash_kv": speech.fused_flash_kv, | |
| "max_pending_chunks": speech.max_pending_chunks, | |
| }, | |
| "qa": {"enabled": bool(args.qa_checkpoint)}, | |
| } | |
| if args.qa_checkpoint: | |
| qa_cfg = QAPrivateKVConfig( | |
| enabled=True, | |
| checkpoint=args.qa_checkpoint, | |
| expected_sha256=args.qa_sha256 or QAPrivateKVConfig().expected_sha256, | |
| ).validate() | |
| payload["qa"] = validate_qa_checkpoint( | |
| qa_cfg.checkpoint, | |
| expected_sha256=qa_cfg.expected_sha256, | |
| ) | |
| print(json.dumps(payload, ensure_ascii=False, sort_keys=True)) | |
| return 0 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |