twanghcmut's picture
download
raw
687 Bytes
"""The one torch.device resolution helper for the whole package.
Lives at the top level rather than under onf.graph because onf.field needs it too, and
onf.graph already depends on onf.field -- putting it in the graph package would make that a
cycle. Imports torch and nothing from onf.
"""
from __future__ import annotations
import torch
def resolve_device(device: str | torch.device | None) -> torch.device:
"""None -> CUDA if available else CPU; a string/torch.device is used as given."""
if isinstance(device, torch.device):
return device
if device:
return torch.device(device)
return torch.device("cuda" if torch.cuda.is_available() else "cpu")

Xet Storage Details

Size:
687 Bytes
·
Xet hash:
b5570188bcbfcedf415d2a8e47f12e9de30f511c0c885a223563a1b2258c0824

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.