mirror of
https://github.com/harvard-edge/cs249r_book.git
synced 2026-07-16 23:24:55 -05:00
[Module 03: Layers] Inconsistency between code examples #497
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?
Originally created by @minhdang26403 on GitHub (Feb 6, 2026).
In the Module 03 - Layers, there are some inconsistencies between code examples. Specifically, in the Linear layer implementation, the book mentions
requires_gradparameter, but it's not set in the code.However, in the forward pass of
Dropout, the code creates Tensor and setsrequires_gradparameter. This can cause some confusion while reading the book.Therefore, I raise this issue to have a discussion about whether we should explicitly set
requires_gradparameters here. Once we have an agreement on this, I can create PR to fix this issue.@profvjreddi commented on GitHub (Feb 6, 2026):
Hi @minhdang26403! 👋 Thank you for the careful review of Module 03! You have a great eye for consistency issues.
The good news is that this was already fixed on in commit a363406 ("fix(layers): remove requires_grad from Linear layer Tensor calls").
The code examples you're seeing with requires_grad=x.requires_grad and requires_grad=False are from an older version. The current implementation in main has neither Linear nor Dropout using requires_grad:
Current Linear layer:
self.weight = Tensor(weight_data) # No requires_grad
self.bias = Tensor(bias_data) # No requires_grad
Current Dropout layer:
mask_tensor = Tensor(mask.astype(np.float32)) # No requires_grad
scale = Tensor(np.array(1.0 / keep_prob)) # No requires_grad
This was a bug and has been fixed, and now it is intentional, as TinyTorch follows progressive disclosure—Module 03 teaches layers, but requires_grad isn't introduced until Module 06 (Autograd). This prevents students from encountering concepts before they've been explained. Since you're looking at an older cached or forked version, I'll close this issue as already resolved. But thank you again for the thorough review 🙏