Hi Jack!



 Jack_Rolph:

I would be happy using scipy, but how would I ensure the gradients are calculated correctly?


If you use scipy (or numpy, etc.)  you would have to write your own
custom backward() for your operation in order to get autograd to
work.  For this kind of eigenvalue computation, writing backward()
would involve some significant analysis and numerical programming.
(It should, be doable – just a lot more than a one-liner.)
Now that you’ve gotten rid of the  with torch.no_grad():
block I think that the version you posted above should give you
legitimate gradients.  (I’m not really clear on how autograd works
with loops like this, but I don’t see any reason it shouldn’t.)
If the loop conflicts with autograd (or if you think the loop is hurting
performance), you could unwrap the loop.  (Although now that
you’ve increased the default value of n_power_iterations
to 400 from 5, fully unwrapping the loop might be unattractive.)
Best.
K. Frank