Verify Qwen3-TTS hybrid recovery after in-flight cancellation

This commit is contained in:
tzhouam committed 2026-09-24 15:29:41 +08:00
1 parent 6d0b758dbe
commit b4179a9c1c
13 files changed
+633 -6

No files matched your search

@@ -0,0 +1,112 @@
#!/usr/bin/env python3
"""Audit the pinned native-Windows Qwen3-TTS in-flight cancel/restart probe."""
from __future__ import annotations
import argparse
import hashlib
import json
import wave
from pathlib import Path
ARTIFACT_HASHES = {
"server_sha256": "999c6af252077195adb723b96da9ee5d3cd291dc7c7a4b32dc493ae148035529",
"talker_sha256": "5227dcbc4df7c5533341d111cc469fa491a48e722b23dd10f553181b52dff2d9",
"codec_sha256": "70dc95dbfdd9aa5d9d406236ff771d061bf17b0cda02a72513953355606e719b",
"punc_sha256": "faf4a43e3135bc307a66194685af00f756e6f4c28c7d9e2dd8f3517cddca5c45",
}
PREFILL = "qwen3_tts[customvoice]: prefill role="
PCM_SHA256 = "57f60228e2b456f6dfefc7e49df862c7bff6ba7cf39231ef1824f615948a1539"
def sha256(path: Path) -> str:
with path.open("rb") as stream:
return hashlib.file_digest(stream, "sha256").hexdigest()
def clean_ledger(value: dict) -> bool:
return (value["reserved"] == {"host_ram": 0}
and value["owners"] == [] and value["quarantined"] == [])
def audit(root: Path) -> dict:
report_path = root / "tts_restart_report.json"
first_log = root / "tts_restart_server.log"
second_log = root / "tts_restart_server_restart.log"
wav_path = root / "tts_restart.wav"
hardware_path = root / "hardware.json"
run = json.loads(report_path.read_text(encoding="utf-8"))
before = run["execution_plan"]
after = run["restart_check"]["fresh_execution_plan"]
abort = run["abort_check"]
restart = run["restart_check"]
if run["status"] != "passed" or run["measured_count"] != 1:
raise ValueError("TTS probe did not pass the declared single-request recovery scope")
if any(plan["artifact_sha256"] != ARTIFACT_HASHES for plan in (before, after)):
raise ValueError("TTS artifact hashes changed between sessions")
if any(plan["placement"] != "Radeon Vulkan0 talker/codec + CPU FP32 code predictor"
or plan["expected_gpu_name"] != "AMD Radeon(TM) 890M Graphics"
or plan["ggml_vk_visible_devices"] != "1" for plan in (before, after)):
raise ValueError("TTS execution placement changed")
if any(row["pcm_sha256"] != PCM_SHA256 or row["frames"] != 61440
for row in (run["checks"][0], run["measured"][0], restart["fresh_request"])):
raise ValueError("TTS fresh request differs from the pinned complete-WAV output")
if (not restart["same_pcm_as_before_abort"] or restart["late_output"]
or abort["stale_output"] or not abort["worker_exited"]
or abort["prefills_after_abort_request_start"] <= abort["prefills_before_abort_request"]):
raise ValueError("TTS cancellation or fresh-stage recovery failed")
if not all(clean_ledger(value) for value in (
abort["ledger_after_abort"], restart["first_runtime_ledger_after_shutdown"],
run["ledger_after_shutdown"],
)):
raise ValueError("TTS RAM reservation or quarantine remained")
if (before["worker_generation"] == after["worker_generation"]
or restart["fresh_request"]["stage_event"]["worker_generation"]
!= after["worker_generation"]):
raise ValueError("TTS fresh request reused the cancelled worker")
logs = [path.read_text(encoding="utf-8", errors="replace") for path in (first_log, second_log)]
if (logs[0].count(PREFILL) < abort["prefills_after_abort_request_start"]
or logs[1].count(PREFILL) < 1
or any("desc=AMD Radeon(TM) 890M Graphics" not in log
or "code_pred CPU-pinned" not in log
or "codec: GPU default - loading weights onto Vulkan0" not in log
for log in logs)):
raise ValueError("TTS raw server logs do not verify prefill and hybrid placement")
with wave.open(str(wav_path), "rb") as wav:
if wav.getnchannels() != 1 or wav.getsampwidth() != 2 or wav.getframerate() != 24000:
raise ValueError("saved WAV format differs from the declared output")
if wav.getnframes() != 61440 or hashlib.sha256(wav.readframes(61440)).hexdigest() != PCM_SHA256:
raise ValueError("saved WAV payload differs from the stage-reported PCM")
files = [report_path, first_log, second_log, wav_path, hardware_path]
return {
"status": "passed",
"scope": "one native Windows hybrid TTS cancellation after backend prefill and fresh StageRuntime request",
"old_generation": before["worker_generation"],
"new_generation": after["worker_generation"],
"first_server_prefills": logs[0].count(PREFILL),
"fresh_server_prefills": logs[1].count(PREFILL),
"fresh_pcm_sha256": PCM_SHA256,
"ledger_cleared": True,
"files": {path.name: {"bytes": path.stat().st_size, "sha256": sha256(path)} for path in files},
"limits": [
"The stage returns a complete WAV, not incremental playable audio.",
"A fresh StageRuntime starts after cancellation; no same-session state migration is claimed.",
"One recovery case is not concurrency or sustained reliability qualification.",
],
}
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--evidence-dir", type=Path, required=True)
args = parser.parse_args()
result = audit(args.evidence_dir)
(args.evidence_dir / "audit_report.json").write_text(
json.dumps(result, indent=2) + "\n", encoding="utf-8"
)
print(json.dumps({"status": result["status"], "fresh_pcm_sha256": result["fresh_pcm_sha256"]}))
if __name__ == "__main__":
main()
@@ -42,11 +42,15 @@ async def main() -> None:
parser.add_argument("--warmups", type=int, default=1)
parser.add_argument("--repeats", type=int, default=20)
parser.add_argument("--abort-check", action="store_true")
parser.add_argument("--restart-check", action="store_true",
help="After in-flight cancellation, start a fresh stage and verify audio")
parser.add_argument("--capacity-gib", type=int, default=16)
parser.add_argument("--reserve-gib", type=int, default=8)
args = parser.parse_args()
if args.warmups < 0 or args.repeats <= 0 or args.reserve_gib <= 0 or args.capacity_gib < args.reserve_gib:
parser.error("invalid warmup/repeat count or memory budget")
if args.restart_check and not args.abort_check:
parser.error("--restart-check requires --abort-check")
from vllm_omni.config.stage_config import DeployConfig, StageDeployConfig, merge_pipeline_deploy
from vllm_omni.engine.stage_runtime import StageRuntime
@@ -149,18 +153,85 @@ async def main() -> None:
report["nearest_rank_p95_wall_s"] = _rank(walls, 0.95)
report["all_same_pcm_sha256"] = len({row["pcm_sha256"] for row in report["measured"]}) == 1
if args.abort_check:
def started_tts_prefills() -> int:
log = Path(args.server_log).read_text(encoding="utf-8", errors="replace")
return log.count("qwen3_tts[customvoice]: prefill role=")
prefills_before_abort = started_tts_prefills()
request_id = f"tts-abort-{time.monotonic_ns()}"
await pool.submit_initial(request_id, state, {"text": second, "voice": "ryan", "seed": 42})
await asyncio.sleep(0.01)
deadline = time.monotonic() + 10
while started_tts_prefills() <= prefills_before_abort:
if time.monotonic() >= deadline:
raise TimeoutError("abort request did not reach the owned TTS server")
await asyncio.sleep(0.02)
premature = pool.poll_graph_output(0)
if premature is not None:
premature.release_stage_buffers()
raise RuntimeError("TTS request completed before in-flight cancellation")
await pool.abort_requests([request_id])
await asyncio.sleep(0.1)
stale = pool.poll_graph_output(0)
report["abort_check"] = {
"stale_output": pool.poll_graph_output(0) is not None,
"prefills_before_abort_request": prefills_before_abort,
"prefills_after_abort_request_start": started_tts_prefills(),
"stale_output": stale is not None,
"worker_exited": pool.stage_client._proc.poll() is not None,
"ledger_after_abort": runtime.resource_ledger.snapshot(),
}
if stale is not None:
stale.release_stage_buffers()
if report["abort_check"]["stale_output"] or not report["abort_check"]["worker_exited"]:
raise RuntimeError("CrispASR cancellation left stale output or live worker")
if args.restart_check:
old_generation = report["execution_plan"]["worker_generation"]
runtime.shutdown()
released = runtime.resource_ledger.snapshot()
if released["reserved"]["host_ram"] or released["quarantined"]:
raise RuntimeError("cancelled TTS stage retained a host-RAM reservation")
server_log = Path(args.server_log)
restart_log = server_log.with_name(
server_log.stem + "_restart" + server_log.suffix
)
restart_deploy = DeployConfig(
async_chunk=False,
stages=[StageDeployConfig(
stage_id=0,
backend={**backend, "log_file": str(restart_log)},
resource_budget=deploy.stages[0].resource_budget,
)],
)
restart_configs = [
stage.to_omegaconf()
for stage in merge_pipeline_deploy(pipeline, restart_deploy)
]
runtime = StageRuntime(
restart_configs, "local-qwen-tts-crisp-restart", "",
stage_init_timeout=180, async_chunk=False,
)
restarted_at = time.perf_counter()
runtime.initialize()
fresh_startup_s = time.perf_counter() - restarted_at
pool = runtime.stage_pools[0]
state = SimpleNamespace(sampling_params_list=[None])
fresh_plan = pool.stage_client.execution_plan
if fresh_plan["worker_generation"] == old_generation:
raise RuntimeError("restart reused the cancelled TTS worker generation")
restarted = await request_one(first)
late = pool.poll_graph_output(0)
report["restart_check"] = {
"first_runtime_ledger_after_shutdown": released,
"fresh_startup_s": fresh_startup_s,
"fresh_server_log": str(restart_log),
"fresh_execution_plan": fresh_plan,
"fresh_request": restarted,
"same_pcm_as_before_abort": restarted["pcm_sha256"] == report["checks"][0]["pcm_sha256"],
"late_output": late is not None,
}
if late is not None:
late.release_stage_buffers()
if late is not None or not report["restart_check"]["same_pcm_as_before_abort"]:
raise RuntimeError("fresh TTS stage emitted extra or changed audio")
report["status"] = "passed"
except BaseException as exc:
report["status"] = "failed"