Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the bug in autograd example that sends wrong gradient backwards when computation graph doesn't resemble a tree #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lhlich
Copy link

@lhlich lhlich commented Jun 29, 2023

see https://leetcode.com/playground/UPrmL2r9. In this example e = 24a+3 and the gradient should be 24 instead of 28.

The issue is that when a NumberWithGrad object serves as the parent node of multiple operations, we just want to send the incoming gradient backward_grad recursively. The gradient of b is 1 from path b->c->e, and it's 5 from path b->d->e. We send gradient 1 to a for the first time and send gradient 1+5=6 for the second time, and that's why we see 28

@lhlich lhlich changed the title Fix the bug in autograd example Fix the bug in autograd example that sends wrong gradient backwards when computation graph doesn't resemble a tree Jun 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant