Skip to content

Native server: prefill time included in decode seconds, so long prompts read as collapsed decodes - #588

Closed
eleqtrizit wants to merge 1 commit into
ashhart:mainfrom
eleqtrizit:native-seconds-decode
Closed

eleqtrizit wants to merge 1 commit into
ashhart:mainfrom
eleqtrizit:native-seconds-decode

Conversation

@eleqtrizit

Copy link
Copy Markdown
Contributor

What this changes

A side-by-side of the native and Python engines on the same long-context bench was comparing two different measurements. The native server streamed its tensorfold block carrying seconds as the whole request's wall time, prompt included, and the bench read gen_tok / seconds as the decode rate — so a 128k prompt put its 8.6-second prefill inside the decode cell and printed a decode rate that fell toward zero as the prompt grew, an apparent collapse that was never the engine's.

This changes the native server's chat runtime block to carry seconds as the reply's decode time — the same seconds tokens_per_second already divides — so a consumer reading seconds as decode seconds (llm-bench's tensorfold branch does) no longer counts the prompt in a long-context reply's decode rate, and both columns of that comparison become decode-only.

This PR

     ctx task      prompt_tok    gen_tok    prefill tok/s        tok/s
----------------------------------------------------------------------
      2k code            1640       1265         21364.27       731.20  draft=68%
      8k code            6448       1173         20919.60       720.25  draft=66%
     32k code           25683       1253         18420.47       649.92  draft=67%
     64k code           51327       1288         15584.44       569.17  draft=67%
    128k code          102615       1208         12018.87       421.50  draft=65%

zig main (prefill time included in decode time)

     ctx task      prompt_tok    gen_tok    prefill tok/s        tok/s
----------------------------------------------------------------------
      2k code            1641       1277         21343.42       688.18  draft=67%
      8k code            6449       1191         20876.42       600.23  draft=64%
     32k code           25682       1248         18391.94       375.10  draft=67%
     64k code           51327       1233         15556.38       225.17  draft=67%
    128k code          102615       1244         11986.14       108.04  draft=66%

Receipt

  • Environment, with the TensorFold commit, MLX or PyTorch version, machine and GPU, checkpoint and revision:

    Linux x86_64, zig 0.17.0, no MLX or PyTorch in the loop; commit 77fdb75 atop 0d83398 (main). The native CUDA server against checkpoint TensorFold/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bit, revision d9d758fb83953437f7263256b0d96157e2a348b8, served with --no-thinking --context 131000; the consumer is llm-bench, which reads gen_tok / seconds from the streamed tensorfold block.

  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false:

    Not needed for tokens: this changes a reply's reported seconds alone; no
    weight, kernel, round or sampling path is touched, and the streamed reply's
    bytes are identical. The block stays self-consistent, before and after:
    tokens_per_second is decode_tokens / seconds on both sides of the
    change — only which seconds those are moves, from the request's whole wall
    to its decode span.

  • Decode speed before and after, from tools/bench_openai.py:

    Not from bench_openai; one streamed chat request at each of 2k, 8k, 32k, 64k and 128k contexts, 512 tokens, greedy, read through llm-bench. Before, the same bench counted an 8.6-second 128k prefill inside the 128k decode cell; after, it does not, so the before and after tables are the same engine measured by a moving ruler — the after column, not the before, is the one comparable against the Python engine's:

  • Prompt speed before and after, from tools/prefill_cold.py:

    Not from prefill_cold; the same requests' prompt_tok / prefill_seconds is unchanged by this (a prompt's timing fields are untouched), so there is nothing to measure here.

  • Tests run, with pass, fail and skip counts:

    zig build test exit 0, including the server framing goldens (their seconds field matches through the <t> timing placeholders, so no golden changed); zig build test-cuda-host exit 0. The suites print no pass/fail counts of their own; the exit codes are the record.

  • Not run, and why:

    Metal on the Mac build — the block builder is the same chat.zig on either platform, and the goldens cover the framing on the host suite; no Mac was at hand to serve on one. tools/bench_concurrent.py's concurrent and reuse cells — the block's shape, not its consumer behavior under load, is what changed, and the client's own decode spans (measured beside the block's seconds, at 2k through 128k) are the record instead.

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.

  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Untouched: no engine change.)

  • No precision traded for speed. If the bits change, the description says which sums change and why. (No model sums are in this change; seconds and tokens_per_second stay divisors of the same quantities on either side of it.)

  • Prompt processing is no slower than the last release. (Untouched.)

  • The description says which platforms I ran, Metal M1 to M5 and CUDA, and which I could not. (Ran the Linux CUDA native server; could not run Metal on a Mac.)

  • New tests fail before the change, pass after it, and skip cleanly without their dependency. (No new test: the framing goldens already assert the block's shape through their <t> placeholders, and pass unchanged, which is the point — only the field's value semantics move, and no golden pinned them.)

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

  • No personal data, machine names, internal hosts or local paths. No AI attribution lines.

…decode time, as tokens_per_second divides them: a consumer reading seconds as decode no longer counts the prompt in it

(cherry picked from commit 10d2f1a)
@ashhart ashhart mentioned this pull request Oct 10, 2026
@ashhart

ashhart commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Thank you, @eleqtrizit. Decode-time seconds is in main as a21d951, under your name. Like #576, the commit came with a personal address, so we re-authored it to your noreply address and GitHub shows this as closed rather than merged. We left out the "cherry picked from" line, since that commit isn't public.

We checked it on an M3 Ultra with an 8,478-token prompt and a 256-token reply. Before, seconds was 39.19 against a 39.20 s request, 33.45 s of it prefill. After, seconds is 5.65, exactly 255 tokens over the reported 45.1 tokens a second, with prefill_seconds at 33.54 and time_to_first_token at 33.63.

seconds now means something different from the Python 0.6 server's field of the same name, which is the whole request, so 30e4dc8 writes down what each timing field measures in docs/api.md, and the release notes will say it changed. It ships in the next release. Thanks again!

@ashhart ashhart closed this Oct 10, 2026
BobClawblaw pushed a commit to BobClawblaw/TensorFold that referenced this pull request Oct 10, 2026
…_seconds and time_to_first_token measure

After ashhart#588 seconds is the reply's decode time; the Python 0.6 server's seconds stays the whole request.
BobClawblaw pushed a commit to BobClawblaw/TensorFold that referenced this pull request Oct 10, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…_seconds and time_to_first_token measure

After ashhart#588 seconds is the reply's decode time; the Python 0.6 server's seconds stays the whole request.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
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