I am unable to use grad funcation

Gradients for weights

indent preformatted text by 4 spaces

print(w)

print(w.grad)

tensor([[ 2.4848, 0.1907, -0.5383],
[-0.2645, 0.1914, 1.1861]], requires_grad=True)
None

grad is not a function to be honest.

I don’t see anything that would involve such weights, which could in turn create some gradients. You have to use the variable, because the grads are calculated w.r.t. something.

1 Like