mirror of
https://github.com/harvard-edge/cs249r_book.git
synced 2026-05-07 02:03:55 -05:00
[PR #1343] [MERGED] fix(tinytorch): wire Tanh into enable_autograd() #8132
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/harvard-edge/cs249r_book/pull/1343
Author: @profvjreddi
Created: 4/16/2026
Status: ✅ Merged
Merged: 4/16/2026
Merged by: @profvjreddi
Base:
dev← Head:fix/tanh-autograd-wiring📝 Commits (1)
242093efix(tinytorch): wire Tanh into enable_autograd()📊 Changes
2 files changed (+94 additions, -1 deletions)
View changed files
📝
tinytorch/src/06_autograd/06_autograd.py(+73 -1)📝
tinytorch/tests/06_autograd/test_06_autograd_progressive.py(+21 -0)📄 Description
closes #1341
what
Tanh was the only activation not patched by
enable_autograd(). callingTanh()(x).backward()silently leftx.gradas None because the forward never attached a computation graph.changes
follows the existing
tracked_sigmoid_forwardpattern precisely (same "save output for backward" shape sinced/dx tanh(x) = 1 - tanh(x)^2can be derived from the forward result):TanhBackward(Function)classsrc/06_autograd/06_autograd.py(between SigmoidBackward and SoftmaxBackward)tracked_tanh_forwardwrapperenable_autograd()enable_autograd()tests/06_autograd/test_06_autograd_progressive.pytest
the new
test_tanh_activation_gradientasserts:x.grad is not Noneafter callingtanh(x).sum().backward()context
came out of #1336 where @Shashank-Tripathi-07's finite-diff tests exposed the bypass. see #1341 for the diagnosis and #1342 for the followup backward-math audit across other ops.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.