File size: 2,920 Bytes
06f9561 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | #!/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())
|