mirror of
https://github.com/harvard-edge/cs249r_book.git
synced 2026-07-16 06:07:17 -05:00
[GH-ISSUE #1258] tinytorch - module 02 - sonarqube consistency issue #21520
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 @asgalon on GitHub (Mar 20, 2026).
Original GitHub issue: https://github.com/harvard-edge/cs249r_book/issues/1258
Originally assigned to: @profvjreddi on GitHub.
Running SonarQube precommit checks, I got the following Maintainability / Consistency issue python:S6711 (Medium impact) in 02_activation.py, line 1048:
test_data = Tensor(np.random.randn(size).astype(np.float32))Now, this is with the "SonarQube for IDE" local rules, it could be that the project does not use Sonar or uses different rules or that this rule should be suppressed for some reason, so this may be just a question of the right setup that I have not found yet. In general it is a good idea to take care of things that show up as Medium or higher issues in a project to improve the overall code quality. Maybe I am overthinking this again, but I am used to a very thorough pre-release QA management from my client projects, so I feel obliged to open alt least one ticket about this class of issue for someone to review it.
@profvjreddi commented on GitHub (Mar 28, 2026):
Good catch, @asgalon, and thanks for the detailed write-up; your write-ups are always very thoughtful, so I am grateful for that. It is really helpful for me to understand where you are coming from. We don't currently run SonarQube in our CI pipeline (I actually just learned about it when you first mentioned it—learned something new!), but the underlying issue is valid.
The legacy
np.randomAPI (randn,rand,randint,seed) does, in fact, rely on global state, which hurts reproducibility, and I have to agree that this is especially relevant for an educational codebase where students need deterministic results.That said, this pattern is currently codebase-wide 😓 so I will have to run a major refactor rather than do a single-file fix. The migration pattern would look like:
Give me a few days, and I will work through this one. It is a good one. I will do it on the flight back from my trip. Sitting in the middle of the Caribbean right now 🏖️😄
@asgalon commented on GitHub (Mar 28, 2026):
Well, then enjoy the rest of your trip ☀️🏝️😎 issues can wait a little
@profvjreddi commented on GitHub (Apr 3, 2026):
Hey @asgalon I migrated all 878 legacy
np.randomcalls across 106 files to the modernGeneratorAPI. Everynp.random.randn,np.random.seed,np.random.randint, etc. now usesnp.random.default_rng(7)with explicit Generator instances. No more global state.All 805 tests pass. Thanks for catching this one, it was long overdue. Closing this out 💪
@all-contributors please add @asgalon as a contributor for 🪲 Bug in TinyTorch
@github-actions[bot] commented on GitHub (Apr 3, 2026):
I've added @asgalon as a contributor to tinytorch! 🎉
Recognized for: doc
Project(s): tinytorch (explicitly mentioned in comment)
Based on: @all-contributors please add @asgalon as a contributor for 🪲 Bug in TinyTorch
The contributor list has been updated in:
tinytorch/.all-contributorsrc,tinytorch/README.mdREADME.mdWe love recognizing our contributors! ❤️