You have to be logged in to leave a comment.
Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#%%
import torch
print(torch.__version__)
#%%
tensor = torch.Tensor([[3, 4], [7, 5]])
tensor
#%%
tensor.requires_grad # False by default, computations for this tensor won't be tracked
#%%
tensor.requires_grad_() # implicit enable of tracking computations for this tensor to calculate gradients on the backward pass
tensor.requires_grad
#%%
print(tensor.grad) # accumulates the gradient of the computations w.r.t. this tensor after the backward pass which was used to caluclate the gradients
#%%
print(tensor.grad_fn) # no backward pass performed yet
#%%
out = tensor * tensor
#%%
out.requires_grad # derived from the original tensor
#%%
print(out.grad) # still no gradients
#%%
print(out.grad_fn) # exists because it holds the result of a computation (the mulitiplication) which required gradients, it therefore has a gradient function associated with it
#%%
print(tensor.grad_fn) # no grad_fn because this tensor is NOT the result of any computation
#%%
out = (tensor * tensor).mean()
print(out.grad_fn)
#%%
print(tensor.grad) # still no gradients associated with the original tensor
#%%
out.backward() # compute the gradients w.r.t. the "out" tensor
#%%
print(tensor.grad) # now it exists!
#%%
new_tensor = tensor * tensor
print(new_tensor.requires_grad) # if the tensors in the computation have requires_grad=True the computed output will as well
#%%
with torch.no_grad():
# stop autograd from tracking history on newly created tensors
# we require gradient calculation in training phase
# we turn off calculating gradients when predicting
new_tensor = tensor * tensor
print('new_tensor = ', new_tensor)
print('requires_grad for tensor', tensor.requires_grad) # True; required gradient calculation
print('requires_grad for new_tensor', new_tensor.requires_grad) # False; does not require gradient calculation because of the torch.no_grad() block we are in
Press p or to see the previous file or,
n or to see the next file
Comments
Integrate Google Cloud Storage
Use Google Storage
Select bucket
Upload key
Finish
Use Google Cloud Storage!
Browsing data directories saved to Google Cloud Storage is possible with DAGsHub. Let's configure
your repository to easily display your data in the context of any commit!
Specify your Google Storage bucket
Congratulations!
pytorch-tensors is now integrated with Google Cloud Storage!
Delete Storage Key
Are you sure you want to delete this access key?
No
Yes
Integrate AWS S3
Use S3 remote
Select bucket
Access key
Finish
Use AWS S3 as storage!
Browsing data directories saved to S3 is possible with DAGsHub. Let's configure
your repository to easily display your data in the context of any commit!
Specify your S3 bucket
Select Region
af-south-1 - Africa (Cape Town)
ap-northeast-1 - Asia Pacific (Tokyo)
ap-northeast-2 - Asia Pacific (Seoul)
ap-south-1 - Asia Pacific (Mumbai)
ap-southeast-1 - Asia Pacific (Singapore)
ap-southeast-2 - Asia Pacific (Sydney)
ca-central-1 - Canada (Central)
eu-central-1 - EU (Frankfurt)
eu-north-1 - EU (Stockholm)
eu-west-1 - EU (Ireland)
eu-west-2 - EU (London)
eu-west-3 - EU (Paris)
sa-east-1 - South America (São Paulo)
us-east-1 - US East (N. Virginia)
us-east-2 - US East (Ohio)
us-gov-east-1 - US Gov East 1
us-gov-west-1 - US Gov West 1
us-west-1 - US West (N. California)
us-west-2 - US West (Oregon)
Congratulations!
pytorch-tensors is now integrated with AWS S3!
Delete Storage Key
Are you sure you want to delete this access key?
No
Yes
Integrate S3 compatible storage
Use S3 like remote
Select bucket
Access key
Finish
Use any S3 compatible storage!
Browsing data directories saved to S3 compatible storage is possible with DAGsHub. Let's configure
your repository to easily display your data in the context of any commit!
Specify your S3 bucket
Congratulations!
pytorch-tensors is now integrated with your S3 compatible storage!
Delete Storage Key
Are you sure you want to delete this access key?
No
Yes
Integrate Azure Cloud Storage
Use Azure Storage
Select bucket
Set key
Finish
Use Azure Cloud Storage!
Browsing data directories saved to Azure Cloud Storage is possible with DAGsHub. Let's configure
your repository to easily display your data in the context of any commit!
Specify your Azure Storage bucket
Congratulations!
pytorch-tensors is now integrated with Azure Cloud Storage!