Variable isn’t a thing anymore.
The mistake in your code is that you do the .cuda() after requiring the gradient. .cuda is calculation for autograd purposes.
I’d probably subclass nn.Module and self.A = nn.Parameter(A) (requires grad is automatic for nn.Parameter).
You don’t want to include your optimizer in the module itself, if only so you can do the following in the right order: a) instantiate your class b) .cuda() your instance c) set up the optimizer.
Best regards
Thomas