Skip to content

Fix JSONLogger examples/sec rate and crash on zero write time - #798

Draft
rootkiller6788 wants to merge 1 commit into
google:mainfrom
rootkiller6788:fix-jsonlogger-examples-per-sec
Draft

rootkiller6788 wants to merge 1 commit into
google:mainfrom
rootkiller6788:fix-jsonlogger-examples-per-sec

Conversation

@rootkiller6788

Copy link
Copy Markdown

What

JSONLogger reported a bogus write-throughput figure and could crash on fast writes.

Problems

  1. 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 logged 2.00 examples/sec instead of 3.00.
  2. When write_time rounded to 0.0 (common for small result sets), the eager division raised ZeroDivisionError, which propagated out of JSONLogger.__call__ into evaluation and aborted the run after results were already written.
  3. %02f is 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

  • Track the number of examples actually written inside the write loop.
  • Compute the rate from that count and guard against a zero write_time (log an infinite rate rather than raising).
  • Use %.2f so the log rounds to 2 decimals.

Tests

  • test_no_crash_when_write_time_is_zero: forces write_time == 0 (by pinning time.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 reports 3.00 examples/sec (the example count), not 2.00.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant