I think it’s just a matter of taste and apparently I like the Module class, since it looks “clean” to me. All parameters are defined in the __init__ while the forward method just applies the desired behavior. Using a function would work as well of course, since my Module is stateless.
If you would like to maximize the entropy, you could just remove the multiplication with -1.
Assuming your model has a layer called linear1, you can check the gradients with: model.linear1.weight.grad.