PyTorch
PyTorch查看CUDA和CUDNN版本
>>> import torch
>>> print(torch)
<module 'torch' from '/home/torch/code_pytorch/pytorch.master/torch/__init__.py'>
>>> torch.__version__
'2.0.0a0+gitb8151d2'
>>>
>>> torch.cuda.is_available()
True
>>> torch.version.cuda
'11.7'
>>>
>>> torch.backends.cudnn.is_available()
False
>>> torch.backends.cudnn.version()
>>>
>>>
查看PyTorch版本的对应的git commit id
python -c 'import torch; print(torch.version.git_version)'
求 Minimum 的梯度
# $ cat test_minimum_grad.py
#!/usr/bin/env python
import torch
x = torch.tensor([1.0, 5.0, 3.0], dtype=torch.float, requires_grad=True)
y = torch.tensor([4.0, 2.0, 6.0], dtype=torch.float, requires_grad=True)
z = torch.minimum(x, y)
print(z.detach().numpy())
d = torch.tensor([1.0, 2.0, 3.0], dtype=torch.float, requires_grad=True)
z.backward(gradient=d)
print('grad of x is ', x.grad)
# $ ./test_minimum_grad.py
# [1. 2. 3.]
# grad of x is tensor([1., 0., 3.])
参考:

浙公网安备 33010602011771号