将后端迁入 backend/,完善根目录 .gitignore,删除误提交的 .mypy_cache 缓存文件。 Co-authored-by: Cursor <cursoragent@cursor.com>
29 lines
829 B
Python
29 lines
829 B
Python
"""Torch 设备选择、类名归一化(子进程与 actionformer_gated 共用)。"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import sys
|
||
|
||
|
||
def norm_product_name(name: str) -> str:
|
||
s = (name or "").strip()
|
||
if s == "一次性医用垫单":
|
||
return "一次性使用手术单(一次性医用垫单)"
|
||
return s
|
||
|
||
|
||
def resolve_inference_device(explicit: str) -> str | None:
|
||
configured = (explicit or "").strip()
|
||
if configured:
|
||
return configured
|
||
try:
|
||
import torch
|
||
except Exception:
|
||
return None
|
||
# 有 NVIDIA 时始终优先 CUDA(含 Linux / 少数非 Mac 环境);Mac 无可用 CUDA 时再试 MPS。
|
||
if torch.cuda.is_available():
|
||
return "cuda:0"
|
||
if sys.platform == "darwin" and torch.backends.mps.is_available():
|
||
return "mps"
|
||
return None
|