Skip to content

fix(inference): align log probabilities with generated tokens - #360

Open
VedanthB wants to merge 1 commit into
algorithmicsuperintelligence:mainfrom
VedanthB:fix/local-token-logprobs
Open

VedanthB wants to merge 1 commit into
algorithmicsuperintelligence:mainfrom
VedanthB:fix/local-token-logprobs

Conversation

@VedanthB

@VedanthB VedanthB commented Dec 4, 2026

Copy link
Copy Markdown

Summary

For local PyTorch chat completions, logprobs.content drops the first generated token and repeats the last one with a null score. A one-token completion returns one entry with no score. I found this while checking the example in #359.

Each causal logit row scores the following token. Keep the unscored entry at the first position of the full sequence, so trimming the prompt leaves exactly one scored entry per generated token. The response shape stays the same.

Verification

  • The regression fails on upstream for one- and two-token completions. It checks token order and the scores of both the generated token and a known alternative against the corresponding logit row.
  • python -m unittest tests.test_max_completion_tokens tests.test_completions_endpoint -v passed all 19 tests.
  • Posted to the real local Flask route on macOS using cached SmolLM2-135M-Instruct at revision 12fd25f. Both one-token and 16-token responses returned HTTP 200, with one finite score and three alternatives per generated token. The returned tokens reconstructed the response text in both cases.
  • git diff --check passed.

Codex assisted with the patch and verification.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

1 similar comment
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

This branch has not been deployed

No deployments
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