Fix operator-precedence bug in sparse L0 tracking condition#94
Merged
Conversation
`i % tracking_n / 2 == 0` parsed as `(i % tracking_n) / 2 == 0`, which is equivalent to `i % tracking_n == 0` because any non-zero remainder divided by 2 is non-zero. The intended 2x logging density (the sparse loop runs 2x as many epochs as the dense loop) was silently lost, halving the fidelity of the sparse performance DataFrame that feeds the dashboard. Compute the stride explicitly as `max(1, tracking_n // 2)` and use `i % sparse_tracking_n == 0`, with a comment explaining the intent and the original parse mistake so it does not regress. Adds tests/test_sparse_tracking.py verifying the sparse DataFrame now has ~4x the dense DataFrame's row count at 100 dense epochs (2x density * 2x epochs), consistent with the design. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
MaxGhenis
commented
Apr 17, 2026
Contributor
Author
MaxGhenis
left a comment
There was a problem hiding this comment.
LGTM (cannot self-approve; posting as comment).
sparse_tracking_n = max(1, tracking_n // 2)gives the intended 2x log density for the sparse loop (which runs 2x as many epochs). The inline comment explains the parse mistake ((i % tracking_n) / 2==i % tracking_n == 0) so the intent is obvious on future reads.max(1, ...)guardstracking_n == 1(whenepochs <= 10), preventing a divide-by-zero oni % 0.- Test exercises the L0 path via
csv_pathand reads the sparse CSV back, counting rows to verify the ~4x ratio (2x density × 2x sparse epochs). Tight regression.
Docstring / code comment explains what the tracking density should be (match the 2x epoch ratio). Intent is now self-documenting.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Finding #4 (HIGH).
i % tracking_n / 2 == 0parsed as(i % tracking_n) / 2 == 0, which is equivalent toi % tracking_n == 0because any non-zero remainder divided by 2 is non-zero. The intended 2x logging density (the sparse loop runs 2x as many epochs as the dense loop) was silently lost, halving the fidelity of the sparse performance DataFrame that feeds the dashboard.Stride is now
max(1, tracking_n // 2)with a comment explaining both the intent and the original parse mistake.Test plan
tests/test_sparse_tracking.pyverifying the sparse DataFrame has ~4x the dense DataFrame row count at 100 dense epochs (2x density × 2x epoch count).uv run pytest tests -x -q-> 16 passed).🤖 Generated with Claude Code