fix: GPU 로 모델을 못 올려도 CPU 로 시작 · cuBLAS 받는 중 정지하면 캡처를 켜지 않게
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:
EJClaw
2026-11-05 15:11:19 +09:00
parent 176e06c4bd
commit c2e600fa3d
4 changed files with 136 additions and 18 deletions

View File

@@ -18,6 +18,7 @@ import hashlib
import logging
import os
import sys
import threading
import urllib.request
import zipfile
from collections.abc import Callable
@@ -43,6 +44,10 @@ _WHEEL_DIR = "nvidia/cublas/bin/"
ProgressCallback = Callable[[str, float], None]
class DownloadCancelled(Exception):
"""사용자가 받는 도중에 번역을 정지했다."""
#: os.add_dll_directory 가 돌려준 핸들. 닫히면 검색 경로에서 빠지므로 붙잡아 둔다.
_dll_dir_handle = None
#: 불러온 DLL 핸들. 참조가 사라지면 내려갈 수 있으므로 들고 있는다.
@@ -69,11 +74,13 @@ def _system_has_cublas() -> bool:
return True
def ensure(progress: ProgressCallback | None = None, device: str = "cuda") -> bool:
def ensure(progress: ProgressCallback | None = None, device: str = "cuda",
cancel: threading.Event | None = None) -> bool:
"""GPU 를 쓸 수 있게 cuBLAS 를 준비한다. 새로 받았거나 불러왔으면 True.
Windows 가 아니거나 CPU 로 돌릴 때는 아무것도 하지 않는다. 받기·불러오기에
실패하면 예외를 그대로 올린다. 호출한 쪽이 CPU 로 바꿀지 정한다.
`cancel` 이 켜지면 받기를 멈추고 `DownloadCancelled` 를 올린다.
"""
global _ready
if sys.platform != "win32" or device != "cuda":
@@ -85,7 +92,7 @@ def ensure(progress: ProgressCallback | None = None, device: str = "cuda") -> bo
log.info("시스템에 있는 cuBLAS 를 씁니다.")
else:
if not installed(directory):
download(directory, progress)
download(directory, progress, cancel=cancel)
activate(directory)
_ready = True
return True
@@ -93,7 +100,7 @@ def ensure(progress: ProgressCallback | None = None, device: str = "cuda") -> bo
def download(directory: Path, progress: ProgressCallback | None = None,
url: str = WHEEL_URL, sha256: str = WHEEL_SHA256,
size: int = WHEEL_SIZE) -> None:
size: int = WHEEL_SIZE, cancel: threading.Event | None = None) -> None:
"""공식 패키지를 받아 DLL 두 개만 꺼낸다. 끝나면 패키지 파일은 지운다."""
directory.mkdir(parents=True, exist_ok=True)
part = directory / "cublas.whl.part"
@@ -105,6 +112,8 @@ def download(directory: Path, progress: ProgressCallback | None = None,
try:
with urllib.request.urlopen(url, timeout=30) as resp, part.open("wb") as out:
while chunk := resp.read(1 << 20):
if cancel is not None and cancel.is_set():
raise DownloadCancelled("GPU 계산 파일 받기를 멈췄습니다")
out.write(chunk)
digest.update(chunk)
done += len(chunk)