FitGround / scripts /train /device.py
jlai300's picture
Upload FitGround source, artifacts, reports, and FIT-Clean parquet (part 4)
2559788 verified
Raw History Blame Contribute Delete
994 Bytes
"""Torch device probe used by every training script."""
from __future__ import annotations
from typing import Any
def probe_torch() -> dict[str, Any]:
info: dict[str, Any] = {
"torch_imported": False,
"version": None,
"cuda_compiled": None,
"cuda_available": False,
"device": "cpu",
"gpu_name": None,
"error": None,
}
try:
import torch
except Exception as exc: # pragma: no cover - environment dependent
info["error"] = f"{type(exc).__name__}: {exc}"
return info
info["torch_imported"] = True
info["version"] = torch.__version__
info["cuda_compiled"] = torch.version.cuda
info["cuda_available"] = bool(torch.cuda.is_available())
if info["cuda_available"]:
info["device"] = "cuda"
info["gpu_name"] = torch.cuda.get_device_name(0)
return info
def torch_device():
import torch
return torch.device("cuda" if torch.cuda.is_available() else "cpu")