audio_zen/utils.py
def prepare_device(n_gpu: int, keep_reproducibility=False):
    """
    Choose to use CPU or GPU depend on the value of "n_gpu".

    Args:
        n_gpu(int): the number of GPUs used in the experiment. if n_gpu == 0, use CPU; if n_gpu >= 1, use GPU.
        keep_reproducibility (bool): if we need to consider the repeatability of experiment, set keep_reproducibility to True.

    See Also
        Reproducibility: https://pytorch.org/docs/stable/notes/randomness.html
    """
    if n_gpu == 0:
        print("Using CPU in the experiment.")
        device = torch.device("cpu")
    else:
        # possibly at the cost of reduced performance
        if keep_reproducibility:
            print("Using CuDNN deterministic mode in the experiment.")
            torch.backends.cudnn.benchmark = False  # ensures that CUDA selects the same convolution algorithm each time
            torch.set_deterministic(True)  # configures PyTorch only to use deterministic implementation
        else:
            # causes cuDNN to benchmark multiple convolution algorithms and select the fastest
            torch.backends.cudnn.benchmark = True

        device = torch.device("cuda:0")

    return device

    Choose to use CPU or GPU depend on the value of "n_gpu".

    Args:
        n_gpu(int): the number of GPUs used in the experiment. if n_gpu == 0, use CPU; if n_gpu >= 1, use GPU.
        keep_reproducibility (bool): if we need to consider the repeatability of experiment, set keep_reproducibility to True.

    See Also
        Reproducibility: https://pytorch.org/docs/stable/notes/randomness.html
    
Choose to use CPU or GPU depend on the value of "n_gpu".
Choose to use CPU or GPU depend on the value of " n_gpu " .
def prepare_device(n_gpu: int, keep_reproducibility=False):
    if n_gpu == 0:
        print("Using CPU in the experiment.")
        device = torch.device("cpu")
    else:
        if keep_reproducibility:
            print("Using CuDNN deterministic mode in the experiment.")
            torch.backends.cudnn.benchmark = False  
            torch.set_deterministic(True)  
        else:
            torch.backends.cudnn.benchmark = True
        device = torch.device("cuda:0")
    return device
def prepare_device ( n_gpu : int , keep_reproducibility = False ) : if n_gpu == 0 : print ( "Using CPU in the experiment." ) device = torch . device ( "cpu" ) else : if keep_reproducibility : print ( "Using CuDNN deterministic mode in the experiment." ) torch . backends . cudnn . benchmark = False torch . set_deterministic ( True ) else : torch . backends . cudnn . benchmark = True device = torch . device ( "cuda:0" ) return device
Choose to use CPU or GPU depend on the value of "n_gpu".
Choose to use CPU or GPU depend on the value of " n_gpu " .
"""
    Choose to use CPU or GPU depend on the value of "n_gpu".

    Args:
        n_gpu(int): the number of GPUs used in the experiment. if n_gpu == 0, use CPU; if n_gpu >= 1, use GPU.
        keep_reproducibility (bool): if we need to consider the repeatability of experiment, set keep_reproducibility to True.

    See Also
        Reproducibility: https://pytorch.org/docs/stable/notes/randomness.html
    """ # possibly at the cost of reduced performance # ensures that CUDA selects the same convolution algorithm each time # configures PyTorch only to use deterministic implementation # causes cuDNN to benchmark multiple convolution algorithms and select the fastest
n_gpu
int
the number of GPUs used in the experiment. if n_gpu == 0, use CPU; if n_gpu >= 1, use GPU.
the number of GPUs used in the experiment . if n_gpu == 0 use CPU ; if n_gpu > = 1 use GPU .
keep_reproducibility
if we need to consider the repeatability of experiment, set keep_reproducibility to True.
if we need to consider the repeatability of experiment set keep_reproducibility to True .