[PR #1954] fix(tinytorch): unguarded accuracy_retention division crashes on zero baseline #34678

Open
opened 2026-07-14 19:28:48 -05:00 by GiteaMirror · 0 comments
Owner

📋 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: devHead: fix/benchmarking-accuracy-retention-division


📝 Commits (1)

  • bfe35a1 fix(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 against opt_metrics[metric] <= 0 with a documented "fallback to 1.0" (matching the function's own docstring: "Handle division by zero with fallback to 1.0"), but accuracy_retention = opt_metrics['accuracy'] / base_metrics['accuracy'] had no such guard on the denominator.
  • A baseline model with 0.0 accuracy (a broken/failing baseline -- exactly the kind of input a benchmarking suite should handle gracefully) raises ZeroDivisionError and 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

  • Confirmed the old code raises ZeroDivisionError for base_metrics={'accuracy': 0.0}.
  • Confirmed the fixed code returns accuracy_retention=1.0 instead for that case.
  • Confirmed the normal (non-zero) case is unaffected: base={'accuracy': 0.5}, opt={'accuracy': 0.6} still returns accuracy_retention=1.2.
  • python -m py_compile passes on the edited file.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/harvard-edge/cs249r_book/pull/1954 **Author:** [@Shashank-Tripathi-07](https://github.com/Shashank-Tripathi-07) **Created:** 7/7/2026 **Status:** 🔄 Open **Base:** `dev` ← **Head:** `fix/benchmarking-accuracy-retention-division` --- ### 📝 Commits (1) - [`bfe35a1`](https://github.com/harvard-edge/cs249r_book/commit/bfe35a1f9965c16506f9051f64c557bcd23ed907) fix(tinytorch): unguarded accuracy_retention division crashes on zero baseline ### 📊 Changes **1 file changed** (+4 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `tinytorch/src/19_benchmarking/19_benchmarking.py` (+4 -1) </details> ### 📄 Description ## Summary - `_calculate_improvements()` guards the latency/memory/energy division against `opt_metrics[metric] <= 0` with a documented "fallback to 1.0" (matching the function's own docstring: "Handle division by zero with fallback to 1.0"), but `accuracy_retention = opt_metrics['accuracy'] / base_metrics['accuracy']` had no such guard on the denominator. - A baseline model with `0.0` accuracy (a broken/failing baseline -- exactly the kind of input a benchmarking suite should handle gracefully) raises `ZeroDivisionError` and 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 - [x] Confirmed the old code raises `ZeroDivisionError` for `base_metrics={'accuracy': 0.0}`. - [x] Confirmed the fixed code returns `accuracy_retention=1.0` instead for that case. - [x] Confirmed the normal (non-zero) case is unaffected: `base={'accuracy': 0.5}, opt={'accuracy': 0.6}` still returns `accuracy_retention=1.2`. - [x] `python -m py_compile` passes on the edited file. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-07-14 19:28:48 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/cs249r_book#34678