Skip to content

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