mirror of
https://github.com/harvard-edge/cs249r_book.git
synced 2026-07-15 21:28:33 -05:00
[PR #1955] [MERGED] fix(tinytorch): capstone latency divisions crash on coarse timer resolution #34679
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/1955
Author: @Shashank-Tripathi-07
Created: 7/7/2026
Status: ✅ Merged
Merged: 7/10/2026
Merged by: @profvjreddi
Base:
dev← Head:fix/capstone-latency-zero-division📝 Commits (1)
49033c7fix(tinytorch): capstone latency divisions crash on coarse timer resolution📊 Changes
1 file changed (+8 additions, -2 deletions)
View changed files
📝
tinytorch/src/20_capstone/20_capstone.py(+8 -2)📄 Description
Summary
benchmark_model()'sthroughput_samples_per_sec(float(1000 / avg_latency)) andgenerate_submission()'sspeedup(float(baseline_latency / optimized_latency)) both divide by a latency measured withtime.time()around a single tiny forward pass, with no zero-guard.time.time()has coarse resolution on Windows (commonly ~15.6ms). For a small model, a fast forward pass can legitimately measure0.0elapsed time across all runs, makingavg_latency(and thereforeoptimized_latencydownstream in a submission comparison) exactly0.0and raisingZeroDivisionError.Fix
An existing test asserts
throughput_samples_per_sec > 0, and another assertsspeedup > 0, so the fix floors each denominator at a small epsilon (1e-6) rather than returning0.0orNone-- both of which would fail those assertions and would also misrepresent an immeasurably-fast result as zero throughput.Test plan
ZeroDivisionErrorfor bothavg_latency=0.0andoptimized_latency=0.0with the old expressions.avg_latency=2.0ms -> 500.0samples/sec, unchanged from before).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.