Skip to content

Backward operation of torch.eig for real eigenvalues#33090

Closed
mfkasim1 wants to merge 3 commits intopytorch:masterfrom
mfkasim1:deriveig2
Closed

Backward operation of torch.eig for real eigenvalues#33090
mfkasim1 wants to merge 3 commits intopytorch:masterfrom
mfkasim1:deriveig2

Conversation

@mfkasim1
Copy link
Contributor

@mfkasim1 mfkasim1 commented Feb 7, 2020

Another pull request to follow up issue #32531.
Here I implemented the backward operation for torch.eig with a condition that all the eigenvalues are real.

This pull request is independent of my another pull request #32932, which means that there is no dependency between this PR and my another PR.

@dr-ci
Copy link

dr-ci bot commented Feb 7, 2020

💊 CircleCI build failures summary and remediations

As of commit 5d676ee:

Commit 5d676ee was recently pushed. Waiting for builds...


This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions on the GitHub issue tracker.

This comment has been revised 2 times.

Copy link
Collaborator

@albanD albanD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks quite good!
Small details about test and perf but this is almost ready to go.

Will this need an update when the batch eig lands? Or are these formulas going to work for both?

@mfkasim1
Copy link
Contributor Author

mfkasim1 commented Feb 7, 2020

Thanks for the review, @albanD. The computation in this PR should not be changed when my another PR lands. The way I wrote it is by following closely symeig_backward which should be fine with batched calculation.
The only thing to change when eig is batched is the test case which should include tensor > 2D.

Copy link
Collaborator

@albanD albanD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks !

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@albanD has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@albanD albanD added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Feb 10, 2020
iotamudelta added a commit to ROCm/pytorch that referenced this pull request Feb 10, 2020
IFU 20200210 #2: Backward operation of torch.eig for real eigenvalues (pytorch#33090)
@facebook-github-bot
Copy link
Contributor

@albanD merged this pull request in 9d94f56.

@facebook-github-bot
Copy link
Contributor

@albanD merged this pull request in 9d94f56.

ttumiel pushed a commit to ttumiel/pytorch that referenced this pull request Mar 4, 2020
Summary:
Another pull request to follow up issue pytorch#32531.
Here I implemented the backward operation for `torch.eig` with a condition that all the eigenvalues are real.

This pull request is independent of my another pull request pytorch#32932, which means that there is no dependency between this PR and my another PR.
Pull Request resolved: pytorch#33090

Differential Revision: D19814347

Pulled By: albanD

fbshipit-source-id: 2fae30964e97987abb690544df8240aedeae56e8
facebook-github-bot pushed a commit that referenced this pull request Nov 9, 2020
Summary:
Related: #33090
I just realized that I haven't updated the docs of `torch.eig` when implementing the backward.
Here's the PR updating the docs about the grad of `torch.eig`.

cc albanD

Pull Request resolved: #47598

Reviewed By: heitorschueroff

Differential Revision: D24829373

Pulled By: albanD

fbshipit-source-id: 89963ce66b2933e6c34e2efc93ad0f2c3dd28c68
Comment on lines +1820 to +1822

auto gvortho = gv - at::sum(gv * v, /*dim=*/-2, /*keepdim=*/true) * v;
auto B = hm * at::matmul(vt, gvortho);
Copy link
Collaborator

@nikitaved nikitaved Feb 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mfkasim1 , could you please explain this line where you subtract contributions of v from gv? It does not seem to agree with the reference you mentioned above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually derived the expression myself, but I didn't have the time to write it down, so I just put the closest available literature in the code.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The derivations are different, so I do not know which method to trust, but I do not immediately see any issues in the reference. So, then, how did you get that gvortho?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if they are actually different or actually the same with just different expressions.
I have put my expression into gradcheck and gradgradcheck and it passes.
I will write the derivation down if I got time.

Copy link
Collaborator

@nikitaved nikitaved Feb 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They seem to different, in your derivation you subtract from the gv the projection of gv into v, and they do not do it in the reference. The parts with the eigenvalue contribution seem to match.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, if I remember it correctly, I subtract it because of the constraint of the eigenvectors to have norm = 1.
I probably did the similar trick from this paper (eq. 3.23-3.25)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All right, now I see. I did check the output of torch.eig it indeed produces normalized eigenvectors. Awesome, thank you!

@kimjw0623
Copy link

Is this feature updated to pytorch 1.7.1?

@mfkasim1
Copy link
Contributor Author

@kimjw0623 yes, it should be. You can check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged open source triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants