Skip to content

server: /v1/completions takes echo, the prompt's text and legacy logprobs ahead of an unchanged reply - #3526

Merged
ashhart merged 4 commits into
mainfrom
lead/completions-echo
Nov 24, 2026
Merged

ashhart merged 4 commits into
mainfrom
lead/completions-echo

Conversation

@ashhart

@ashhart ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Evaluation harnesses such as lm-evaluation-harness score loglikelihood tasks through OpenAI's legacy completions echo: they send a prompt with max_tokens 0 or 1, logprobs: K and echo: true, and read the prompt tokens' logprobs back. TensorFold ignored echo, so those tasks couldn't be run against it. This serves echo on the existing prompt-row path.

What this changes

  • echo: true on /v1/completions: the prompt's text comes ahead of text.

  • With logprobs: K: the legacy arrays (tokens, token_logprobs, top_logprobs, text_offset) list every prompt token before the reply's. The first prompt token has null in token_logprobs and top_logprobs, and text_offset counts from 0.

  • The reply's own entries: tokens, token_logprobs and top_logprobs are byte-identical to the same request without echo (tested); only their text_offset moves past the prompt.

  • max_tokens: 0 with echo: returns the prompt alone, with finish_reason: "length" and completion_tokens: 0. The engine draws one token, which the reply drops.

  • Refused with a 400 naming echo: engines without prompt logprobs, streamed requests, bodies with messages, and non-boolean values. Chat routes still ignore the field.

  • prompt_logprobs: its output is unchanged. Its value is now built in the route from the engine's raw rows, so echo and prompt_logprobs can share one engine read with different counts.

  • The echoed text: the prompt's token ids decoded, so text, tokens and text_offset agree.

  • Issue: n/a. This came from the 16 Nov check of competitor gap docs against main (echo and lm-eval are listed for vLLM-class servers and Hyperflare); no issue or PR covered it.

  • Stacked on: main. The draft code-infill PR, suffix, stacks on this one.

  • atc overlap --json: to run after review. server: a raw completions prompt list gets one choice a prompt, each the reply that prompt gets alone #3194 (prompt lists) and server: n of 1 through 16 choices on chat and completions, each its own request on the one prompt #3148 (n > 1) also touch openai.zig, which is at 599 lines here, so whichever lands later may need a split.

  • Field shapes: OpenAI's legacy completions reference (developers.openai.com/api/reference/resources/completions/methods/create). No other engine's or harness's source was read.

Checks on this head

  • Head commit: 01b7063 on main e7e2424.
  • Lean checker: 337 on base and head, 0 new (tools/pr_check.py: 0 errors, 1 advisory warning).
  • Tests:
    • zig build test-logprob-offers-host: 44/44. Against main's sources, 4 of the 5 new tests fail; the fifth checks unchanged output.
    • zig build test-golden: 325/338 equal, 0 unexpected (the 13 are the existing known list), plus three new cases (echo-false, echo-unsupported, echo-stream). Security goldens 55/55.
    • The server module's tests: 1483 passed, 9 skipped, 0 failed.
    • zig fmt --check, git diff --check: clean.
  • CI: pending.
  • Not run: a real model on a GPU, so prompt rows come from the scripted test engine.

Receipt

n/a for speed: the reply's tokens are unchanged by construction and by test. It reaches inference only to read prompt rows, which engines with prompt_logprobs already return. A device run with lm-eval against a served model is the follow-up.

Checklist

  • The title and description match the head commit.

  • New tests fail before the change, pass after it, and skip cleanly without their dependency.

  • Comments and docstrings are one line. No measurements or history in the source.

  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

  • Every token still goes through the lane rounds; generated tokens equal the request without echo.

  • Synthena (Ash's Agent)

…robs ahead of an unchanged reply

echo: true puts the prompt's decoded ids in front of text and, with logprobs, each prompt
token's entry (null for the first) ahead of the reply's, whose entries stay as without echo.
max_tokens 0 with echo returns the prompt alone. Engines without prompt_logprobs, streams,
messages bodies and non-boolean values are refused by name; prompt_logprobs keeps its own count.
@ashhart
ashhart force-pushed the lead/completions-echo branch from 28ae653 to 9e3d511 Compare November 24, 2026 15:50
@ashhart
ashhart merged commit 7ab4e93 into main Nov 24, 2026
@ashhart
ashhart deleted the lead/completions-echo branch November 24, 2026 15:50
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