Repository navigation
fix(eval): leave turns with no reported usage out of the token_usage_v1 average - #7735
Closed
Fruiterer333 wants to merge 1 commit into
Closed
Fruiterer333 wants to merge 1 commit into
Fruiterer333 wants to merge 1 commit into
Conversation
copybara-service Bot
pushed a commit
that referenced
this pull request
Oct 27, 2026
Merge #7735 The overall `token_usage_v1` value, and each averaged count under it, now divides by the turns that reported input or output tokens. A turn that reported neither already read n/a, including one that reported only cached tokens; it no longer lowers the overall value as a zero. Per-turn values are unchanged, and a count missing from a turn that did report usage still averages as zero. Fixes #7734 PiperOrigin-RevId: 1007857232
Collaborator
|
Thank you @Fruiterer333 for your contribution! 🎉 Your changes have been successfully imported and merged via Copybara in commit 5e52b21. Closing this PR as the changes are now in the main branch. |
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.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
token_usage_v1reportsn/afor a turn whose model calls returned no usage metadata, but_TokenUsageV1Evaluator._averagestill counts that turn in the denominator as 0 tokens. With one turn that used 1,000 tokens and one turn with no reported usage, the overall is 500. The efficiency metrics README says "n/anever means zero", andinference_call_count_v1andinvocation_duration_v1already leave n/a turns out of their averages.Solution:
_averagenow builds its shared denominator from the invocations that reported at least one count. Within those invocations, a missing count still averages as zero (unchanged behavior, covered bytest_token_usage_averages_an_unreported_count_as_zero_for_that_turn), andtotal == input + outputstill holds after averaging. If no invocation reported usage, every count staysNone, as before.Testing Plan
Unit Tests:
Added
test_token_usage_average_leaves_out_a_turn_that_reported_no_usage. It fails onmain(assert 520.0 == 1040.0) and passes with this change.pyink --check,isort --check-only,codespellandmypypass on the changed files.Manual End-to-End (E2E) Tests:
Ran the reproduction script from #7734, which gets the evaluators through
DEFAULT_METRIC_EVALUATOR_REGISTRY(no model call needed):Checklist
Additional context
I used Claude Code to help find the issue and draft the change. I reproduced the bug, reviewed every line, and ran the tests above myself.