mirror of
https://github.com/harvard-edge/cs249r_book.git
synced 2026-05-06 09:38:33 -05:00
Pruning Code Mistake #446
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 @Tess314 on GitHub (Oct 28, 2025).
Originally assigned to: @profvjreddi on GitHub.
In the Model Optimizations chapter, in the Pruning section, there is a mistake in Listing 1:
The results section states that 4 out of 9 weights should remain. This is not the case, due to the mask.
torch.abs(weights) takes the absolute value of each weight, so negative numbers like -0.9 become 0.9.
'>=threshold' then keeps any value whose magnitude is greater than or equal to 0.1, regardless of sign, meaning both the positive and negative large numbers stay. In short, the code leaves 6 out of 9 weights remaining, not 4.
Here is a correction:
The corrected code ensures negative weights are removed. This leaves the user with 3 out of 9 weights remaining (33% sparsity instead of 44%). I am aware the listing states this code example should use magnitude-based pruning, but as the results were incorrect I am providing this correction in which negative signs are accounted for.
Hope this helps!
-Tess
@profvjreddi commented on GitHub (Oct 28, 2025):
Hi @Tess314 --
Thank you so much for catching this and taking the time to explain it so clearly. I love it when the community helps find these kinds of issues. I write these sections over time, and sometimes little mistakes sneak through, so your note is incredibly helpful. 🙏
I’ll take a closer look at your explanation about the mask behavior later this evening and put in a fix today. When I do, I’ll make sure to list you as a co-author on the change so you get credit. I love recognizing people for their help.
And of course, you’re also welcome to open a PR if you’d like to make the fix directly.
Appreciate the sharp eye and contribution!
Cheerios,
VJ
@Tess314 commented on GitHub (Oct 29, 2025):
Hi @profvjreddi, have you had a chance to check this yet?
I appreciate the recognition :)
Tess
@profvjreddi commented on GitHub (Oct 29, 2025):
Hey @Tess314, I pushed a fix. Could you review it here - dev? This is the dev version. I do a release once every few weeks and push that to the main branch. I might do that later this weekend.
By the way, look who is on the acknowledgments page on the dev branch :)
Your picture doesn't show up because I don't have your GitHub email.
Unless I associate your GitHub account email with your GitHub ID, it won't officially recognize your account. If you want to share your GitHub email, I can update it. You can also email me at vj@eecs.harvard.edu
@Tess314 commented on GitHub (Oct 29, 2025):
Hi @profvjreddi,
The fix looks great! Glad I was able to help.
I appreciated you adding me to the acknowledgements page :)
My GitHub email is tesswattelders@gmail.com
Kind regards,
Tess
@profvjreddi commented on GitHub (Oct 30, 2025):
Closing, fixed in
c9eaffc9a7