torch starting

Solutions on MaxInterview for torch starting by the best coders in the world

showing results for - "torch starting"
Robin
25 May 2017
1import torch
2# requires_grad = True -> tracks all operations on the tensor. 
3x = torch.randn(3, requires_grad=True)
4y = x + 2
5
6# y was created as a result of an operation, so it has a grad_fn attribute.
7# grad_fn: references a Function that has created the Tensor
8print(x) # created by the user -> grad_fn is None
9print(y)
10print(y.grad_fn)
11
12# Do more operations on y
13z = y * y * 3
14print(z)
15z = z.mean()
16print(z)
17
similar questions
queries leading to this page
torch starting