mirror of
https://github.com/harvard-edge/cs249r_book.git
synced 2026-07-16 06:07:17 -05:00
[PR #1954] fix(tinytorch): unguarded accuracy_retention division crashes on zero baseline #34678
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?
📋 Pull Request Information
Original PR: https://github.com/harvard-edge/cs249r_book/pull/1954
Author: @Shashank-Tripathi-07
Created: 7/7/2026
Status: 🔄 Open
Base:
dev← Head:fix/benchmarking-accuracy-retention-division📝 Commits (1)
bfe35a1fix(tinytorch): unguarded accuracy_retention division crashes on zero baseline📊 Changes
1 file changed (+4 additions, -1 deletions)
View changed files
📝
tinytorch/src/19_benchmarking/19_benchmarking.py(+4 -1)📄 Description
Summary
_calculate_improvements()guards the latency/memory/energy division againstopt_metrics[metric] <= 0with a documented "fallback to 1.0" (matching the function's own docstring: "Handle division by zero with fallback to 1.0"), butaccuracy_retention = opt_metrics['accuracy'] / base_metrics['accuracy']had no such guard on the denominator.0.0accuracy (a broken/failing baseline -- exactly the kind of input a benchmarking suite should handle gracefully) raisesZeroDivisionErrorand crashes the whole comparison, while the sibling metrics computed two lines above degrade gracefully.Fix
Added the same guard pattern already used for the other three metrics.
Test plan
ZeroDivisionErrorforbase_metrics={'accuracy': 0.0}.accuracy_retention=1.0instead for that case.base={'accuracy': 0.5}, opt={'accuracy': 0.6}still returnsaccuracy_retention=1.2.python -m py_compilepasses on the edited file.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.