fix: GPU 로 모델을 못 올려도 CPU 로 시작 · cuBLAS 받는 중 정지하면 캡처를 켜지 않게
Some checks failed
Windows / verify (push) Has been cancelled
Some checks failed
Windows / verify (push) Has been cancelled
- preload_on_start(기본값)에서 모델 로드가 GPU 오류를 내면 ERROR 로 끝나던 것을, CPU 로 바꿔 다시 올리게 했다. - cuBLAS 를 받는 중에 정지하면 받기는 계속되고, 끝난 뒤 캡처가 켜져 상태가 다시 RUNNING 이 되던 것을 고쳤다. 시작 작업마다 전용 정지 이벤트를 넘기고, 받기는 그 이벤트를 보고 멈추며, 시작 작업은 정지된 뒤에는 캡처·상태를 건드리지 않는다. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -59,3 +59,18 @@ def test_ensure_is_a_no_op_off_windows_or_on_cpu(monkeypatch):
|
||||
assert cuda_runtime.ensure(device="cuda") is False
|
||||
monkeypatch.setattr(cuda_runtime.sys, "platform", "win32")
|
||||
assert cuda_runtime.ensure(device="cpu") is False
|
||||
|
||||
|
||||
def test_download_stops_when_cancelled(tmp_path):
|
||||
import threading
|
||||
|
||||
url, sha, size = _fake_wheel(tmp_path)
|
||||
target = tmp_path / "runtime"
|
||||
cancel = threading.Event()
|
||||
cancel.set()
|
||||
|
||||
with pytest.raises(cuda_runtime.DownloadCancelled):
|
||||
cuda_runtime.download(target, None, url, sha, size, cancel=cancel)
|
||||
|
||||
assert not cuda_runtime.installed(target)
|
||||
assert list(target.iterdir()) == []
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import threading
|
||||
import time
|
||||
|
||||
import numpy as np
|
||||
@@ -194,3 +195,61 @@ def test_gpu_runtime_download_failure_runs_on_cpu(engine, monkeypatch):
|
||||
assert engine.models.device == "cpu"
|
||||
running = [s for s in statuses if s.state.value == "running"]
|
||||
assert running and "GPU 계산 파일을 받지 못했습니다" in running[0].message
|
||||
|
||||
|
||||
def test_gpu_failure_while_preloading_falls_back_to_cpu(engine, monkeypatch):
|
||||
"""기본값(preload_on_start=True)에서 GPU 로 모델이 안 올라가도 CPU 로 시작한다."""
|
||||
statuses = []
|
||||
engine._on_status = statuses.append
|
||||
engine.config.models.preload_on_start = True
|
||||
devices = []
|
||||
|
||||
def preload(progress=None):
|
||||
devices.append(engine.models.device)
|
||||
if engine.models.device == "cuda":
|
||||
raise RuntimeError("CUDA failed with error no CUDA-capable device is detected")
|
||||
|
||||
monkeypatch.setattr(engine.models, "preload", preload)
|
||||
engine.start()
|
||||
assert _wait_for(lambda: engine.lines), "CPU 로 바꾼 뒤에도 자막이 나오지 않았습니다"
|
||||
engine.stop()
|
||||
|
||||
assert devices == ["cuda", "cpu"]
|
||||
assert not any(s.state.value == "error" for s in statuses)
|
||||
running = [s for s in statuses if s.state.value == "running"]
|
||||
assert running and "CPU로" in running[0].message
|
||||
|
||||
|
||||
def test_stop_while_downloading_gpu_runtime_never_starts_capture(engine, monkeypatch):
|
||||
"""cuBLAS 를 받는 중에 정지하면 받기를 멈추고, 캡처를 켜지 않는다."""
|
||||
from livesub.models.cuda_runtime import DownloadCancelled
|
||||
|
||||
statuses = []
|
||||
engine._on_status = statuses.append
|
||||
downloading = threading.Event()
|
||||
captures = []
|
||||
|
||||
def slow_download(progress=None, device="cuda", cancel=None):
|
||||
downloading.set()
|
||||
while not cancel.is_set():
|
||||
progress("GPU 계산 파일 받는 중", 0.1)
|
||||
time.sleep(0.05)
|
||||
raise DownloadCancelled("멈춤")
|
||||
|
||||
def make_capture(cfg):
|
||||
captures.append(cfg)
|
||||
return FakeCapture()
|
||||
|
||||
monkeypatch.setattr("livesub.core.engine.cuda_runtime.ensure", slow_download)
|
||||
monkeypatch.setattr("livesub.core.engine.create_capture", make_capture)
|
||||
engine.start()
|
||||
assert downloading.wait(5)
|
||||
engine.stop()
|
||||
boot_done = _wait_for(lambda: not any(t.name == "engine-boot" for t in threading.enumerate()), 5)
|
||||
time.sleep(0.3)
|
||||
|
||||
assert boot_done, "정지했는데 시작 작업이 끝나지 않았습니다"
|
||||
assert captures == [], "정지한 뒤에 캡처가 켜졌습니다"
|
||||
assert engine.status.state.value == "idle"
|
||||
assert statuses[-1].state.value == "idle"
|
||||
assert engine.models.device == "cuda", "정지는 GPU 실패가 아니다"
|
||||
|
||||
Reference in New Issue
Block a user