Repository navigation
Conversation
gplume
force-pushed
the
codex/chat-input-tokens
branch
from
December 4, 2026 19:15
a0c5c92 to
d8255c0
Compare
This branch has not been deployed
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.
What and why
Closes #108.
Add
POST /v1/chat/completions/input_tokens. Send a Chat Completions body to get{"input_tokens": N}for the loaded model. Counting uses the same file preparation, template options, tokenizer and media expansion as generation. The generation path checks the encoder output against the planned number of rows before caching it. The Anthropic counter uses the same path after request translation.Ordinary prompts can be counted past the context limit. Counting returns an explicit error when a speech transcript is needed, an OCR workflow has no single admissible page, or Chat would switch to another model.
Where it applies
Server-side prompt preparation for Chat Completions, including API-only mode. The change is independent of GPU kind, weight type, slot count and drafting mode.
Accuracy
Tested on Linux with one Arc Pro B70, driver 26.35.39758.21, Qwen3.8-27B-Q5_K_M and its Qwen3-VL projector. Both HTTP modes returned the same counts as
usage.prompt_tokensfor a plain message (58), declared tools (364), a tool call and result (524), thinking disabled (13), low reasoning effort (45), one image (313) and two images (580). A text prompt of 500,052 tokens was counted exactly at context 2,048.The generation statistics, saved session contents and reuse of a different live KV prefix were unchanged across counting. Both count endpoints rejected an inactive model with HTTP 409. A transcript-dependent request returned HTTP 400. With OCR mode selected by alias, one fitting PDF page matched generation (298). The counter rejected the multi-page request and an oversized single page.
Upstream
06cb3be1and this branch returned the same ordinary greedy answer,Blue sky, with 25 prompt tokens. The CPU chat golden tests and API compatibility tests passed. All fourrunz --dump-logitsoutputs had SHA-256f4f2edf8d8768f498112f33c34f04980660f18ff27ddf1d0e840807da1b2711b.Speed
Same command in A B B A order (A =
06cb3be1, B =a0c5c925):Start lines included
GPU: Intel(R) Arc(TM) Pro B70 Graphics, driver 26.35.39758.21, 256 EUs, 2800 MHz, 30.3 GiB of its own, XMX yes, 16-lane sub-groupsandinferzero: H8 rotates the activations from f32. The HTTP checks used--ctx 2048 --chunk 128and ran with and without--no-webui.Not tested
Windows PowerShell 5.1/7, native audio projector inference, OCR-specific weights, other GPU families, multi-GPU, multiple slots and speculative decoding.