Registering the a and b tensors as nn.Parameters should work (alternatively you could also use self.register_parameter). In your current code you are assigning tensors as model attributes, which won’t be registered as parameters internally.