def METHOD_NAME(gpu):
    """
    Translates input gpu argument into a device id.
    Args:
        gpu: True/False if GPU should be enabled, also supports a device id/string/instance
    Returns:
        device id
    """
    # Return if this is already a torch device
    # pylint: disable=E1101
    if isinstance(gpu, torch.device):
        return gpu
    # Always return -1 if gpu is None or an accelerator device is unavailable
    if gpu is None or not Models.hasaccelerator():
        return -1
    # Default to device 0 if gpu is True and not otherwise specified
    if isinstance(gpu, bool):
        return 0 if gpu else -1
    # Return gpu as device id if gpu flag is an int
    return int(gpu)