feat: whisper 分块间暂停检查与默认 float16 计算类型
- 分块转写在每个分块前检查 run 根目录 paused.flag,批量/任务暂停时 分块粒度内中止(默认 60s 一块),当前块执行完才停 - 默认 compute_type 由 auto 改为 float16,测试断言同步更新
This commit is contained in:
+10
-1
@@ -22,6 +22,9 @@ from wov_sdk.models import InvokeRequest, InvokeResponse
|
||||
# 转写进度日志:输出到主进程控制台,长音频分块时可见每块进度。
|
||||
logger = get_logger("whisper")
|
||||
|
||||
# 暂停信号文件名:位于 run 根目录(<storage>/runs/<run_id>/paused.flag),
|
||||
# 与 subtitle-ocr 节点约定一致;批量暂停时由暂停接口写入,分块间检查即中止。
|
||||
PAUSE_FLAG = "paused.flag"
|
||||
|
||||
def _is_windows() -> bool:
|
||||
"""判断当前是否为 Windows,供测试单独注入覆盖。"""
|
||||
@@ -216,7 +219,7 @@ def invoke(request: InvokeRequest) -> InvokeResponse:
|
||||
model_path = resolve_model_path(request.params)
|
||||
device = str(request.params.get("device") or os.getenv("WHISPER_DEVICE", "auto"))
|
||||
# auto 让 faster-whisper 根据硬件自动选择 float16/int8 等计算类型。
|
||||
compute_type = str(request.params.get("compute_type") or "auto")
|
||||
compute_type = str(request.params.get("compute_type") or "float16")
|
||||
model = WhisperModel(
|
||||
model_path,
|
||||
device=device,
|
||||
@@ -241,6 +244,12 @@ def invoke(request: InvokeRequest) -> InvokeResponse:
|
||||
srt_number = 1
|
||||
transcribe_started = time.monotonic()
|
||||
for chunk_index, chunk in enumerate(chunks, start=1):
|
||||
# 暂停检查:批量暂停时在 run 根目录写 paused.flag,whisper 在分块
|
||||
# 之间检查该信号(默认 60s 一块,暂停粒度不超过一块),检测到即抛
|
||||
# 异常,由 invoke 转 failed、调度器保持任务 PAUSED,继续时整个节点
|
||||
# 重新转写(whisper 没有节点级断点存档,产物只在结束时一次性写出)。
|
||||
if (Path(request.output_dir).parent.parent / PAUSE_FLAG).exists():
|
||||
raise RuntimeError(f"whisper 被暂停(run {request.run_id})")
|
||||
chunk_started = time.monotonic()
|
||||
segments, _info = model.transcribe(
|
||||
str(chunk),
|
||||
|
||||
Reference in New Issue
Block a user