[GH-ISSUE #1128] With tinytorch 0.1.3, 06_autograd.py test_unit_function_classes should be moved after enable_autograd #16225

Closed
opened 2026-05-24 10:20:29 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @avikde on GitHub (Jan 21, 2026).
Original GitHub issue: https://github.com/harvard-edge/cs249r_book/issues/1128

Originally assigned to: @profvjreddi on GitHub.

The test_unit_function_classes() function fails if called (currently first in line 1276) before enable_autograd(quiet=True) (currently in line 2288). It appears that test_unit_function_classes() is also called from test_module(), so maybe it just does not need to be called in line 1276.

Originally created by @avikde on GitHub (Jan 21, 2026). Original GitHub issue: https://github.com/harvard-edge/cs249r_book/issues/1128 Originally assigned to: @profvjreddi on GitHub. The `test_unit_function_classes()` function fails if called (currently first in line 1276) before `enable_autograd(quiet=True)` (currently in line 2288). It appears that `test_unit_function_classes()` is also called from `test_module()`, so maybe it just does not need to be called in line 1276.
Author
Owner

@profvjreddi commented on GitHub (Jan 21, 2026):

👍 Will look at fixing it!

<!-- gh-comment-id:3781675644 --> @profvjreddi commented on GitHub (Jan 21, 2026): 👍 Will look at fixing it!
Author
Owner

@profvjreddi commented on GitHub (Jan 22, 2026):

Status: Fixed

You were correct. The test_unit_function_classes() function at line 1276 was being called in an if __name__ == "__main__" block, but enable_autograd() isn't called until line 2288. Since the test creates Tensors with requires_grad=True, and that parameter is only added to the Tensor class by enable_autograd(), running the file directly would fail.

Fix: Removed the premature test call. The test is already called from test_module() which runs after enable_autograd() is invoked.

Thanks for catching this!

<!-- gh-comment-id:3784231464 --> @profvjreddi commented on GitHub (Jan 22, 2026): **Status: Fixed** ✅ You were correct. The `test_unit_function_classes()` function at line 1276 was being called in an `if __name__ == "__main__"` block, but `enable_autograd()` isn't called until line 2288. Since the test creates Tensors with `requires_grad=True`, and that parameter is only added to the Tensor class by `enable_autograd()`, running the file directly would fail. **Fix:** Removed the premature test call. The test is already called from `test_module()` which runs after `enable_autograd()` is invoked. Thanks for catching this!
Author
Owner

@avikde commented on GitHub (Jan 22, 2026):

Thanks @profvjreddi! As I mentioned in the other issue, feel free to close the issue whenever is best for your workflow.

<!-- gh-comment-id:3784606529 --> @avikde commented on GitHub (Jan 22, 2026): Thanks @profvjreddi! As I mentioned in the other issue, feel free to close the issue whenever is best for your workflow.
Author
Owner

@profvjreddi commented on GitHub (Jan 22, 2026):

Also fixed in v0.1.4! Removed the premature test_unit_function_classes() call - as you noted, it's already called from test_module() after enable_autograd() runs.

(See #1127 for update instructions and contributor details!)

<!-- gh-comment-id:3787428524 --> @profvjreddi commented on GitHub (Jan 22, 2026): Also fixed in v0.1.4! Removed the premature `test_unit_function_classes()` call - as you noted, it's already called from `test_module()` after `enable_autograd()` runs. (See #1127 for update instructions and contributor details!)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/cs249r_book#16225