[GH-ISSUE #1893] [Bug] Jupyternotebook: Tensor.__init__() Does Not Accept requires_grad Used by Autograd Tests #29768

Open
opened 2026-06-21 19:31:30 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @Chufeng-Jiang on GitHub (Jun 21, 2026).
Original GitHub issue: https://github.com/harvard-edge/cs249r_book/issues/1893

Area

TinyTorch

Location

Module 06 and forward in the jupyternotebook

Description

The autograd broadcasting tests construct tensors using the following syntax:

x = Tensor(data, requires_grad=True)

However, the currently exported Tensor class only defines:

Tensor(data)

As a result, the tests in the Jupyternotebook fail before reaching the broadcasting-gradient implementation.

TypeError Traceback (most recent call last) Cell In[43], line 111 108 print("✅ Broadcasting gradient tests pass!") 110 if __name__ == "__main__": --> 111 test_unit_broadcast_gradients() Cell In[43], line 7, in test_unit_broadcast_gradients() 3 print("🔬 Unit Test: Broadcasting in Gradients...") 5 # Scenario 1: Bias-like broadcasting (most common case) 6 # Shape: (batch, features) + (features,) → (batch, features) ----> 7 x = Tensor(rng.standard_normal((4, 3)), requires_grad=True) 8 bias = Tensor(np.ones(3), requires_grad=True) 10 add_func = AddBackward(x, bias) TypeError: Tensor.__init__() got an unexpected keyword argument 'requires_grad'
Image

However, it doesn't affect the unit test when call "tito module complete 06", everything passed successfully.

Image

Expected Behavior

I think all related - codes in the notebook cell needs to revised to, making the requires_grad separately :

x = Tensor(rng.standard_normal((4, 3)))
x.requires_grad = True
bias = Tensor(np.ones(3))
bias.requires_grad = True

The same change may need to be applied to the other occurrences of Tensor(..., requires_grad=True) in the cell.

I would be happy to submit a pull request with the modifications in the cell. However, before doing so, I wanted to confirm whether this is the intended fix or whether the Tensor constructor is instead supposed to be updated to support the requires_grad argument.

Environment (TinyTorch bugs only)

No response

Originally created by @Chufeng-Jiang on GitHub (Jun 21, 2026). Original GitHub issue: https://github.com/harvard-edge/cs249r_book/issues/1893 ### Area TinyTorch ### Location Module 06 and forward in the jupyternotebook ### Description The autograd broadcasting tests construct tensors using the following syntax: x = Tensor(data, requires_grad=True) However, the currently exported Tensor class only defines: Tensor(data) As a result, the tests in the Jupyternotebook fail before reaching the broadcasting-gradient implementation. ``` TypeError Traceback (most recent call last) Cell In[43], line 111 108 print("✅ Broadcasting gradient tests pass!") 110 if __name__ == "__main__": --> 111 test_unit_broadcast_gradients() Cell In[43], line 7, in test_unit_broadcast_gradients() 3 print("🔬 Unit Test: Broadcasting in Gradients...") 5 # Scenario 1: Bias-like broadcasting (most common case) 6 # Shape: (batch, features) + (features,) → (batch, features) ----> 7 x = Tensor(rng.standard_normal((4, 3)), requires_grad=True) 8 bias = Tensor(np.ones(3), requires_grad=True) 10 add_func = AddBackward(x, bias) TypeError: Tensor.__init__() got an unexpected keyword argument 'requires_grad' ``` <img width="682" height="329" alt="Image" src="https://github.com/user-attachments/assets/5c800466-12f1-491d-9d79-03cef819b0de" /> However, it doesn't affect the unit test when call "tito module complete 06", everything passed successfully. <img width="740" height="690" alt="Image" src="https://github.com/user-attachments/assets/181e29d9-2e99-4872-85b6-92011ca422eb" /> ### Expected Behavior I think all related - codes in the notebook cell needs to revised to, making the requires_grad separately : ``` x = Tensor(rng.standard_normal((4, 3))) x.requires_grad = True bias = Tensor(np.ones(3)) bias.requires_grad = True ``` The same change may need to be applied to the other occurrences of Tensor(..., requires_grad=True) in the cell. I would be happy to submit a pull request with the modifications in the cell. However, before doing so, I wanted to confirm whether this is the intended fix or whether the Tensor constructor is instead supposed to be updated to support the requires_grad argument. ### Environment (TinyTorch bugs only) _No response_
GiteaMirror added the area: tinytorchtype: bug labels 2026-06-21 19:31:31 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/cs249r_book#29768