Repository navigation
Fix JSONLogger examples/sec rate and crash on zero write time - #798
Draft
rootkiller6788 wants to merge 1 commit into
Draft
rootkiller6788 wants to merge 1 commit into
rootkiller6788 wants to merge 1 commit into
Conversation
The "examples/sec" figure used len(inferences), which counts inference types (e.g. prediction, score) rather than the number of examples written. A zero-duration write also raised ZeroDivisionError, and the %02f format spec never rounded to 2 decimals as intended. Track the number of examples written, guard against a zero write time, and use %.2f.
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.
What
JSONLoggerreported a bogus write-throughput figure and could crash on fast writes.Problems
len(inferences) / write_time--len(inferences)is the number of inference types (prediction,score, ...), not the number of examples written. For a task with 3 examples and 2 inference types it logged2.00 examples/secinstead of3.00.write_timerounded to0.0(common for small result sets), the eager division raisedZeroDivisionError, which propagated out ofJSONLogger.__call__into evaluation and aborted the run after results were already written.%02fis parsed as a zero-padding flag with min-width 2 and prints 6 decimals by default -- it never gave the intended 2-decimal rounding.Fix
write_time(log an infinite rate rather than raising).%.2fso the log rounds to 2 decimals.Tests
test_no_crash_when_write_time_is_zero: forceswrite_time == 0(by pinningtime.time) and asserts the logger still writes the inference file without raising.test_logs_examples_per_second: with 3 examples and 2 inference types, asserts the log reports3.00 examples/sec(the example count), not2.00.