def METHOD_NAME(
    device: Union[str, torch.device]
) -> Union[str, torch.device]:
    """
    Resolves a torch device to the most appropriate one.
    The ``"auto"`` device is resolved to ``"cuda"`` if CUDA is available,
    and to ``"cpu"`` otherwise. Otherwise the device is unchanged.
    """
    if device == "auto":
        if torch.cuda.is_available():
            return "cuda"
        return "cpu"
    return device