mirror of
https://github.com/harvard-edge/cs249r_book.git
synced 2026-07-16 14:42:29 -05:00
[PR #1866] [MERGED] fix(conv2d): Conv2dBackward return tuple must match saved_tensors length #29144
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/1866
Author: @Shashank-Tripathi-07
Created: 6/16/2026
Status: ✅ Merged
Merged: 6/16/2026
Merged by: @profvjreddi
Base:
main← Head:fix/conv2d-backward-tuple-mismatch📝 Commits (1)
12e5280fix Conv2dBackward return tuple to match saved_tensors length📊 Changes
1 file changed (+3 additions, -2 deletions)
View changed files
📝
tinytorch/src/09_convolutions/09_convolutions.py(+3 -2)📄 Description
What breaks
Conv2dBackward.__init__registers either 2 or 3 tensors insaved_tensorsdepending on whether bias exists:But
apply()always returned a 3-tuple(grad_input, grad_weight, grad_bias).The backward walk zips
saved_tensorswith the return tuple. Whenbias=None, zip silently truncates at 2 pairs, sograd_biasis produced but never consumed. This is fragile -- any reordering ofsaved_tensorsorapply()output would silently corrupt weight updates.Fix
Return only
(grad_input, grad_weight)whenbias is None, so tuple length always equalslen(saved_tensors).Test plan
pytest tinytorch/tests/09_convolutions/-- all conv tests pass🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.