It seems you are trying to initialize self.params as the trainable parameters in the model, which is not the case at the moment, since you are not registering the tensor and would need to use nn.Parameter(torch.ones(...)) instead. This will make sure this parameter will be properly registered and e.g. passed to the optimizer via model.parameters().



 4158ndfkvBHJ1:

I would expect self.params.grad_fn to be different from None, for example MulBackward after every torch.mul in the forward function, but this is not the case. Why is that ?


Assuming you would have properly registered self.params it wouldn’t show any grad_fn, since it’s a leaf tensor and was not created by an operation. In case you want to check the grad_fns, you could check the forward activations e.g. print(potential.grad_fn).