[Bugfix][TTS] Make CosyVoice3 TRT plan publication concurrency-safe (#6955)

Signed-off-by: BANANASJIM <bananasjim1@gmail.com>
This commit is contained in:
Jim Ban authored and GitHub committed 2026-09-03 06:44:42 +00:00
1 parent 2b47faf601
commit 711daacabf
2 files changed
+148 -5

No files matched your search

@@ -1,5 +1,5 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
"""TensorRT engine for the CosyVoice3 flow-decoder (CFM) DiT estimator.
The estimator is the per-step network the conditional flow-matching ODE solver
@@ -26,6 +26,7 @@ from __future__ import annotations
import os
import queue
import uuid
import torch
from vllm.logger import init_logger
@@ -52,6 +53,26 @@ def _is_fp16_onnx(onnx_path: str) -> bool:
return "fp16" in name or "autocast" in name
def _write_plan_atomically(engine_bytes, plan_path: str) -> None:
tmp = f"{plan_path}.tmp.{os.getpid()}.{uuid.uuid4().hex}"
tmp_created = False
try:
with open(tmp, "xb") as f:
tmp_created = True
f.write(engine_bytes)
os.replace(tmp, plan_path)
tmp_created = False
except BaseException:
if tmp_created:
try:
os.unlink(tmp)
except FileNotFoundError:
pass
except OSError:
logger.warning("Failed to remove temporary TensorRT plan %s", tmp, exc_info=True)
raise
def _convert_onnx_to_trt(onnx_path: str, plan_path: str, strongly_typed: bool) -> None:
import tensorrt as trt
@@ -96,10 +117,7 @@ def _convert_onnx_to_trt(onnx_path: str, plan_path: str, strongly_typed: bool) -
engine_bytes = builder.build_serialized_network(network, config)
if engine_bytes is None:
raise RuntimeError(f"TensorRT failed to build flow-estimator engine from {onnx_path}")
tmp = plan_path + ".tmp"
with open(tmp, "wb") as f:
f.write(engine_bytes)
os.replace(tmp, plan_path)
_write_plan_atomically(engine_bytes, plan_path)
logger.info("Wrote flow-estimator TensorRT engine to %s", plan_path)