Skip to content

Correct served KL calculation for truncated logprobs - #140

Merged
WestWaters merged 1 commit into
WestWaters:mainfrom
SloptimistPrime:contrib/served-kl
Oct 6, 2026
Merged

WestWaters merged 1 commit into
WestWaters:mainfrom
SloptimistPrime:contrib/served-kl

Conversation

@SloptimistPrime

Copy link
Copy Markdown
Contributor

The old calculation summed only shared top-logprob entries and divided by their count. It could report a negative KL score.

Use shared tokens plus the remaining probability mass, then average per position. The output labels this as coarsened KL, a lower bound rather than full-vocabulary KL. Also reject invalid probabilities and nonpositive strides.

13 tests pass, including known cases, an HTTP comparison and 200 randomized truncations. This fixes the evaluator; it does not establish that one quantization recipe beats another.

I used AI assistance and reviewed and tested the changes.

@WestWaters
WestWaters merged commit c73bb23 into WestWaters:main Oct 6, 2026
1 check passed
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.

2 participants