當前位置: 首頁>>代碼示例>>Python>>正文


Python cuda.is_available方法代碼示例

本文整理匯總了Python中torch.cuda.is_available方法的典型用法代碼示例。如果您正苦於以下問題:Python cuda.is_available方法的具體用法?Python cuda.is_available怎麽用?Python cuda.is_available使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在torch.cuda的用法示例。


在下文中一共展示了cuda.is_available方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from torch import cuda [as 別名]
# 或者: from torch.cuda import is_available [as 別名]
def __init__(self, gen_model,disc_model,use_cuda_if_available=True):
        super(BaseGanLearner,self).__init__()
        self.model_dir = os.getcwd()
        self.gen_model = gen_model
        self.disc_model = disc_model
        self.cuda = False
        if use_cuda_if_available and cuda.is_available():
            self.cuda = True

        self.__train_history__ = {}

        self.gen_optimizer = None
        self.disc_optimizer = None
        self.gen_running_loss = None
        self.disc_running_loss = None

        self.visdom_log = None
        self.tensorboard_log = None 
開發者ID:johnolafenwa,項目名稱:TorchFusion,代碼行數:20,代碼來源:learners.py

示例2: __init__

# 需要導入模塊: from torch import cuda [as 別名]
# 或者: from torch.cuda import is_available [as 別名]
def __init__(self, dataset: Dataset, batch_size: int, source_names: List[str], target_names: List[str],
                 sort_key: Optional[Callable] = None, **kwargs):
        self.dataset = dataset
        self.source_names = source_names
        self.target_names = target_names
        # sort by the first field if no sort key is given
        if sort_key is None:
            def sort_key(x):
                return getattr(x, self.source_names[0])
        device = None if cuda.is_available() else -1
        self.dl = BucketIterator(dataset, batch_size=batch_size, sort_key=sort_key, device=device, **kwargs)
        self.bs = batch_size
        self.iter = 0 
開發者ID:outcastofmusic,項目名稱:quick-nlp,代碼行數:15,代碼來源:torchtext_data_loaders.py

示例3: __init__

# 需要導入模塊: from torch import cuda [as 別名]
# 或者: from torch.cuda import is_available [as 別名]
def __init__(self, use_cuda_if_available=True):

        self.cuda = False
        self.fp16_mode = False
        if use_cuda_if_available and cuda.is_available():
            self.cuda = True
            cudnn.benchmark = True

        self.epoch_start_funcs = []
        self.batch_start_funcs = []
        self.epoch_end_funcs = []
        self.batch_end_funcs = []
        self.train_completed_funcs = [] 
開發者ID:johnolafenwa,項目名稱:TorchFusion,代碼行數:15,代碼來源:learners.py

示例4: gpu_available

# 需要導入模塊: from torch import cuda [as 別名]
# 或者: from torch.cuda import is_available [as 別名]
def gpu_available() -> bool:
        return False 
開發者ID:rigetti,項目名稱:quantumflow,代碼行數:4,代碼來源:torchbk.py

示例5: __init__

# 需要導入模塊: from torch import cuda [as 別名]
# 或者: from torch.cuda import is_available [as 別名]
def __init__(self, dataset, batch_size, sort_key, target_roles=None, max_context_size=130000, backwards=False,
                 **kwargs):
        self.target_roles = target_roles
        self.text_field = dataset.fields['text']
        self.max_context_size = max_context_size
        self.backwards = backwards
        device = None if cuda.is_available() else -1
        super().__init__(dataset=dataset, batch_size=batch_size, sort_key=sort_key, device=device, **kwargs) 
開發者ID:outcastofmusic,項目名稱:quick-nlp,代碼行數:10,代碼來源:iterators.py

示例6: check_cuda

# 需要導入模塊: from torch import cuda [as 別名]
# 或者: from torch.cuda import is_available [as 別名]
def check_cuda(torch_var, use_cuda=False):
    if use_cuda and cuda.is_available():
        return torch_var.cuda()
    else:
        return torch_var 
開發者ID:GBLin5566,項目名稱:toward-controlled-generation-of-text-pytorch,代碼行數:7,代碼來源:utils.py

示例7: get_info

# 需要導入模塊: from torch import cuda [as 別名]
# 或者: from torch.cuda import is_available [as 別名]
def get_info():
    """
    Get gpu info.

    :return: <dict> gpu info
    """
    return {
        "has_cuda": cuda.is_available(),
        "devices": [] if not cuda.is_available() else [cuda.get_device_name(i) for i in range(cuda.device_count())],
    } 
開發者ID:dreamnettech,項目名稱:dreampower,代碼行數:12,代碼來源:gpu_info.py

示例8: generate_images

# 需要導入模塊: from torch import cuda [as 別名]
# 或者: from torch.cuda import is_available [as 別名]
def generate_images(model, batch, mask_descriptors, num_samples=64, temp=1.,
                    verbose=False):
    """Generates image completions based on the images in batch masked by the
    masks in mask_descriptors. This will generate
    batch.size(0) * len(mask_descriptors) * num_samples completions, i.e.
    num_samples completions for every image and mask combination.

    Parameters
    ----------
    model : pixconcnn.models.pixel_constrained.PixelConstrained instance

    batch : torch.Tensor

    mask_descriptors : list of mask_descriptor
        See utils.masks.MaskGenerator for allowed mask_descriptors.

    num_samples : int
        Number of samples to generate for a given image-mask combination.

    temp : float
        Temperature for sampling.

    verbose : bool
        If True prints progress information while generating images
    """
    device = torch_device("cuda" if cuda_is_available() else "cpu")
    model.to(device)
    outputs = []
    for i in range(batch.size(0)):
        outputs_per_img = []
        for j in range(len(mask_descriptors)):
            if verbose:
                print("Generating samples for image {} using mask {}".format(i, mask_descriptors[j]))
            # Get image and mask combination
            img = batch[i:i+1]
            mask_generator = MaskGenerator(model.prior_net.img_size, mask_descriptors[j])
            mask = mask_generator.get_masks(1)
            # Create conditional pixels which will be used to sample completions
            cond_pixels = get_repeated_conditional_pixels(img, mask, model.prior_net.num_colors, num_samples)
            cond_pixels = cond_pixels.to(device)
            samples, log_probs = model.sample(cond_pixels, return_likelihood=True, temp=temp)
            outputs_per_img.append({
                "orig_img": img,
                "cond_pixels": cond_pixels,
                "mask": mask,
                "samples": samples,
                "log_probs": log_probs
            })
        outputs.append(outputs_per_img)
    return outputs 
開發者ID:Schlumberger,項目名稱:pixel-constrained-cnn-pytorch,代碼行數:52,代碼來源:generate.py


注:本文中的torch.cuda.is_available方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。