mirror of
https://github.com/harvard-edge/cs249r_book.git
synced 2026-07-17 08:28:07 -05:00
[PR #1871] [MERGED] fix(autograd): tracked_mul passes raw scalar to MulBackward, causing .data crash on backward #36490
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/1871
Author: @Shashank-Tripathi-07
Created: 6/16/2026
Status: ✅ Merged
Merged: 6/16/2026
Merged by: @profvjreddi
Base:
main← Head:fix/tracked-mul-scalar-tensor📝 Commits (1)
47baaeafix tracked_mul passing raw scalar to MulBackward instead of a Tensor📊 Changes
1 file changed (+2 additions, -4 deletions)
View changed files
📝
tinytorch/src/06_autograd/06_autograd.py(+2 -4)📄 Description
What breaks
tracked_mul()wraps a scalar operand intoother_tensor = Tensor(other)correctly, but then builds the grad function with the original scalar:MulBackward.apply()doesa, b = self.saved_tensorsand thenb.datato compute the gradient. Calling.dataon a PythonintorfloatraisesAttributeError. Any scalar multiplication inside arequires_grad=Truecomputation graph crashes duringbackward().Fix
other_tensoris already constructed and initialized with_ensure_grad_attrs. The forward value is unaffected --_original_mulstill receives the originalother.Test plan
pytest tinytorch/tests/06_autograd/passesx = Tensor([2.0], requires_grad=True); (x * 3.0).backward()--x.gradshould be[3.0]🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.