feat: whisper 分块间暂停检查与默认 float16 计算类型

- 分块转写在每个分块前检查 run 根目录 paused.flag,批量/任务暂停时
  分块粒度内中止(默认 60s 一块),当前块执行完才停
- 默认 compute_type 由 auto 改为 float16,测试断言同步更新
This commit is contained in:
2026-08-23 16:25:15 +08:00
parent 3b5bd42b60
commit 3aa05bbf76
2 changed files with 42 additions and 3 deletions
+32 -2
View File
@@ -309,7 +309,7 @@ def test_format_timestamp() -> None:
def test_whisper_success(tmp_path, monkeypatch) -> None:
"""验证成功转写会生成 SRT 并默认使用 auto 设备/计算类型。"""
"""验证成功转写会生成 SRT 并默认使用 auto 设备、float16 计算类型。"""
FakeWhisperModel.instances.clear()
_install_fake_whisper(monkeypatch)
_make_wav(tmp_path / "audio.wav", 5)
@@ -320,9 +320,39 @@ def test_whisper_success(tmp_path, monkeypatch) -> None:
assert "01:00:00,500 --> 01:00:02,250" in content
_, kwargs = FakeWhisperModel.instances[-1]
assert kwargs["device"] == "auto"
assert kwargs["compute_type"] == "auto"
assert kwargs["compute_type"] == "float16"
def test_whisper_pause_flag_stops_between_chunks(tmp_path, monkeypatch) -> None:
"""验证 paused.flag 存在时 whisper 在分块边界中止(批量暂停机制)。
run 根目录(output_dir 的上上级)的 paused.flag 由暂停接口写入,whisper
在每个分块转写前检查;检测到即抛异常,invoke 统一转 failed 响应,调度器
捕获后保持任务 PAUSED。
"""
_install_fake_whisper(monkeypatch)
_make_wav(tmp_path / "audio.wav", 5)
# 暂停信号位于 run 根目录:output_dir 为 runs/run_p/steps/whisper
# 其上上级即 runs/run_p(与调度器/OCR 的目录约定一致)。
(tmp_path / "runs" / "run_p").mkdir(parents=True)
(tmp_path / "runs" / "run_p" / "paused.flag").write_text("", encoding="utf-8")
# 注入两个分块路径,确保进入分块循环并执行至少一次暂停检查。
monkeypatch.setattr(
"nodes.whisper._split_audio",
lambda *args, **kwargs: [tmp_path / "chunk_1.wav", tmp_path / "chunk_2.wav"],
)
response = whisper_invoke(
_whisper_request(
tmp_path,
params={"language": "ja", "chunk_seconds": 60},
output_dir=str(tmp_path / "runs" / "run_p" / "steps" / "whisper"),
)
)
assert response.status == "failed"
assert "被暂停" in response.error
# 暂停时不会写出 SRT 产物。
assert not (tmp_path / "runs" / "run_p" / "steps" / "whisper" / "transcript.srt").exists()
def test_load_cuda_libraries_linux(monkeypatch) -> None:
"""验证 Linux 下进程内预加载 nvidia 动态库,含失败跳过分支。"""
import ctypes