5 examples of 'pytorch cuda 11.4' in Python

Every line of 'pytorch cuda 11.4' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
221def cuda(xs, gpu_id):
222 if torch.cuda.is_available():
223 if not isinstance(xs, (list, tuple)):
224 return xs.cuda(int(gpu_id[0]))
225 else:
226 return [x.cuda(int(gpu_id[0])) for x in xs]
227 return xs
124def to_cuda(list_modules):
125 for m in list_modules:
126 m.cuda()
50def _tensor_to_cuda(x):
51 if x.is_cuda:
52 return x
53 else:
54 return x.cuda()
30@pytest.mark.skipif(not torch.cuda.is_available(), reason="Require cuda")
31def test_to_device_cuda():
32 obj = {"a": [torch.tensor([0, 1])]}
33 obj2 = to_device(obj, "cuda")
34 assert obj2["a"][0].device == torch.device("cuda:0")
770def cuda(self, device_id=None):
771 """
772 This method operates identically to :func:`torch.nn.Module.cuda`.
773
774 Args:
775 device_id (:obj:`str`, optional):
776 Device ID of GPU to use.
777 Returns:
778 :obj:`~gpytorch.lazy.LazyTensor`:
779 a new LazyTensor identical to ``self``, but on the GPU.
780 """
781 new_args = []
782 new_kwargs = {}
783 for arg in self._args:
784 if hasattr(arg, "cuda"):
785 new_args.append(arg.cuda(device_id))
786 else:
787 new_args.append(arg)
788 for name, val in self._kwargs.items():
789 if hasattr(val, "cuda"):
790 new_kwargs[name] = val.cuda(device_id)
791 else:
792 new_kwargs[name] = val
793 return self.__class__(*new_args, **new_kwargs)

Related snippets