Question: model = nn . Linear ( 5 , 1 ) # linear model with input dim = 5 , and a single output model.weight.grad =

model = nn.Linear(5,1) # linear model with input dim =5, and a single output
model.weight.grad = torch.Tensor([[1,2,3,4,5.]])
model.bias.grad = torch.Tensor([1.])
max_grad_norm =0.5
torch.nn.utils.clip_grad_norm_(model.parameters(), max_grad_norm)
print(model.weight.grad, model.bias.grad)
tensor([[0.0668,0.1336,0.2004,0.2673,0.3341]]) tensor([0.0668])
Explain why if we set max_grad_norm >=7.49 above, the gradient will be unchanged. Your explanation should demonstrate the calculation of where the number 7.49 comes from.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!