Skip to content

Add an optional standalone decode benchmark - #93

Open
ronaldmannak wants to merge 17 commits into
claude/a4-batch-token-iteratorfrom
codex/standalone-decode-benchmarks
Open

ronaldmannak wants to merge 17 commits into
claude/a4-batch-token-iteratorfrom
codex/standalone-decode-benchmarks

Conversation

@ronaldmannak

@ronaldmannak ronaldmannak commented Nov 5, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #91. The functional batching stack can be merged independently of this tooling.

What changed

Add only Benchmarks/DecodeBench/Package.swift and Sources/decodebench/main.swift as a separate Swift package. Time TokenIterator and BatchTokenIterator decode at every batch size asked for (1,4,8 by default), report time to first token, alternate run order, and check repeatability. Support greedy, top-p and categorical sampling, MLX_SWIFT_LM_PATH for another checkout, and SINGLE_ONLY for main.

decodebench <model directory> [decode tokens: 128] [rounds: 5] [prompt tokens: 145]
            [sampler: greedy|topp|categorical] [batch sizes: 1,4,8] [prompt lengths: equal|mixed]

With mixed prompt lengths the rows of a batch get prompts that shrink evenly from the full length to a sixth of it, so every row but the first is left-padded and the per-row positions and padding mask from #87 and #88 are on the timed path. Every batch row is compared with an untimed single-sequence run of its own prompt; the agreement is reported per row, not asserted. This replaces the earlier two fixed comparisons (single against batch(1), batch(1) against row 0 of batch(4)).

The root package and library targets are unchanged.

Restack (2026-11-06): both commits (d4fa4f5, b28ce06, kept on the fork as backup/2026-11-06/codex/standalone-decode-benchmarks and …-b28ce06) are rebased unchanged onto #91's new head (bf09f16).

Measurements

These were taken on b28ce06, before the restack, and were not re-run. The restack changes #91's admission checks, which run once per joining row, not per decode step.

Llama 3.2 3B Instruct 4-bit, release build, 145 prompt tokens, 128 decode tokens, 5 rounds, greedy, medians:

Path Equal lengths Mixed lengths (145 down to 24)
single 226.18 tok/s, ttft 41 ms 224.57 tok/s, ttft 41 ms
batch(1) 222.75 tok/s, ttft 42 ms 222.29 tok/s, ttft 42 ms
batch(4) 170.46 per row, 681.84 total, ttft 156 ms 170.30 per row, 681.21 total, ttft 125 ms
batch(8) 106.50 per row, 852.01 total, ttft 317 ms 106.16 per row, 849.29 total, ttft 243 ms

Equal lengths: every row of batch(1), batch(4) and batch(8) agrees with its single run on all 129 tokens. Mixed lengths: batch(4) rows agree on [129, 129, 47, 7] tokens, batch(8) rows on [129, 129, 129, 129, 129, 129, 129, 1]. Every path repeats its tokens in every round.

The early mixed-length divergences are near ties, not padding errors. A separate teacher-forced check (each prompt prefilled alone, caches merged as the iterator merges them, every row fed its single run's greedy tokens) gives the same logit difference against the single run for padded and unpadded rows: median 0.014–0.020 for padding 0 to 121, against 0.016–0.018 for an unpadded batch. The batch(8) row that parts ways after its first token does so where its single run's top two logits are 0.008 apart, and the same prompt flips at the same step in an unpadded batch of eight 24-token prompts.

Evidence

At this head (4e4c889), the package builds in release against this checkout and prints its usage with no arguments:

cd Benchmarks/DecodeBench
DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer swift build -c release --scratch-path <scratch>
Build complete! (57.31 sec)
<scratch>/release/decodebench
usage: decodebench <model directory> [decode tokens] [rounds] [prompt tokens] [sampler] [batch sizes] [prompt lengths]

Before the restack, on b28ce06:

  • Release build against this branch with Xcode's toolchain; no warnings in the benchmark.
  • Both runs above, plus a 32-token SINGLE_ONLY run built against this branch and one built with MLX_SWIFT_LM_PATH pointing at fork main (it builds and runs there).
  • CI-pinned swift-format 603: format leaves the file unchanged and lint --strict passes.

GitHub Actions jobs in this origin fork are skipped by the workflow's repository-owner condition; the results above are local.

Restack (2026-11-06c)

cd Benchmarks/DecodeBench && swift build -c release --scratch-path <scratch>
Build complete! (89.66 sec)

Rebased onto main 4ab2679 (2026-11-07)

Rebased from c8dabc6 onto main 4ab2679, which adds seven commits (22bdf2c..4ab2679): surrogate-pair escapes, weight-loading progress, LFM2.5, chat-session steering, VLM image prompts out of float32, LFM3, and Qwen 3.5 VLM YaRN. Git applied every commit of the stack without conflicts. git range-diff shows this PR's commits unchanged.

Release build of the benchmark at this head (d80c2ac):

cd Benchmarks/DecodeBench && swift build -c release
[51 / 51] decodebench-product
Build complete! (48.47 sec)

At this head (d80c2ac):

The whole MLXLMTests bundle at this head:

-only-testing:MLXLMTests
Executed 975 tests, with 8 tests skipped and 0 failures (0 unexpected) in 119.730 (119.903) seconds
Test "Test MiniCPM5 Format via ToolCallProcessor keeps a function close tag inside CDATA" recorded a known issue at ToolTests.swift:2212:13: Expectation failed: processor.toolCalls.count == 1
r􀢄 Test "G7: a left-padded batch matches the texts run one at a time" failed after 4.179 seconds with 2 issues.
Test rotatingHybridCacheMatchesGreedyAcrossWindow(promptLength:useMoE:) with 10 test cases failed after 5.479 seconds with 2 issues.
Test run with 1611 tests in 133 suites failed after 26.149 seconds with 6 issues (including 2 known issues).

The failures are main's. EmbeddingGemmaMaskTests G7 fails as before. LFM2DSparkMetalTests.rotatingHybridCacheMatchesGreedyAcrossWindow (prompt length 3, with and without MoE) is new on main: it fails the same way on main 4ab2679 alone, in three of three runs, and at every stack head through #91 (-only-testing:MLXLMTests/LFM2DSparkMetalTests). The two MiniCPM5 CDATA issues are withKnownIssue. Main's whole bundle on this machine: 1449 Swift Testing tests and 974 XCTest cases, with these same failures.

Batch row operations move to BatchableKVCache (2026-11-07b)

Rebased onto #91's 51d71ef (the BatchableKVCache change in #88-#91; see #88). This PR's two commits are unchanged (git range-diff); the benchmark uses no row operation.

Release build of the benchmark at this head:

cd Benchmarks/DecodeBench && DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer swift build -c release
[296 / 296] decodebench-product
Build complete! (68.71 sec)

At this head (4f1a7d6, was d80c2ac):

The whole MLXLMTests bundle at this head:

-only-testing:MLXLMTests
Executed 975 tests, with 8 tests skipped and 0 failures (0 unexpected) in 115.282 (115.427) seconds
Test "Test MiniCPM5 Format via ToolCallProcessor keeps a function close tag inside CDATA" recorded a known issue at ToolTests.swift:2212:13: Expectation failed: processor.toolCalls.count == 1
Test "G7: a left-padded batch matches the texts run one at a time" failed after 4.379 seconds with 2 issues.
Test rotatingHybridCacheMatchesGreedyAcrossWindow(promptLength:useMoE:) with 10 test cases failed after 5.701 seconds with 2 issues.
Test run with 1615 tests in 133 suites failed after 26.635 seconds with 6 issues (including 2 known issues).

The failures are main's, as at the previous head: EmbeddingGemmaMaskTests G7 and LFM2DSparkMetalTests.rotatingHybridCacheMatchesGreedyAcrossWindow fail on main 4ab2679 alone; the two MiniCPM5 CDATA issues are withKnownIssue.

Merge validation and padding-only extraction (2026-11-07c)

Rebased onto #91's 95844b3 (the round 8 changes in #88-#90). This PR's other commits are unchanged (git range-diff); the only new commits in the stack are #88's 1c399b0, #89's 081b109, #90's a35cbe2 and #94's 13957b4. This PR's decodebench measured the round 8 change, before and after; see #88 for the numbers.

At this head (3a18939, was 4f1a7d6):

The whole MLXLMTests bundle at this head:

-only-testing:MLXLMTests
Executed 975 tests, with 8 tests skipped and 0 failures (0 unexpected) in 118.149 (118.304) seconds
Test "Test MiniCPM5 Format via ToolCallProcessor keeps a function close tag inside CDATA" recorded a known issue at ToolTests.swift:2212:13: Expectation failed: processor.toolCalls.count == 1
Test "G7: a left-padded batch matches the texts run one at a time" failed after 4.025 seconds with 2 issues.
Test rotatingHybridCacheMatchesGreedyAcrossWindow(promptLength:useMoE:) with 10 test cases failed after 5.753 seconds with 2 issues.
Test run with 1621 tests in 133 suites failed after 26.273 seconds with 6 issues (including 2 known issues).

The failures are main's, as at the previous heads: EmbeddingGemmaMaskTests G7 and LFM2DSparkMetalTests.rotatingHybridCacheMatchesGreedyAcrossWindow fail on main 4ab2679 alone; the two MiniCPM5 CDATA issues are withKnownIssue.

Review fixes merged forward (2026-11-07d)

Merged #91 into this branch (head 5482f7c, was 3a18939; no rebase). It brings in #90's e222aa2 (the typed recurrent merge refuses subclasses and mixed classes, with three new tests). Nothing else in this PR changes.

At 5482f7c:

DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer xcodebuild test -skipPackagePluginValidation \
  -scheme mlx-swift-lm-Package -destination 'platform=macOS' \
  -only-testing:MLXLMTests/BatchTokenIteratorTests -only-testing:MLXLMTests/BatchedRecurrentParityTests -only-testing:MLXLMTests/QwenVLBatchedPositionTests

Suite QwenVLBatchedPositionTests passed after 0.310 seconds.
Suite BatchedRecurrentParityTests passed after 0.608 seconds.
Suite BatchTokenIteratorTests passed after 1.726 seconds.
Test run with 45 tests in 3 suites passed after 1.726 seconds.
** TEST SUCCEEDED **

BatchTokenIterator events merged in (2026-11-07e)

Merged #91 (head 99a47ff, was 5482f7c; no rebase). DecodeBench now reads the iterator's BatchEvent.token events instead of Response values. Its timing is unchanged: the time-to-first-token and decode-split fixes wait for stage 2 (resumable prefill). DecodeBench builds against this head (swift build -c release: Build complete!).

At 99a47ff:

DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer xcodebuild test -skipPackagePluginValidation \
  -scheme mlx-swift-lm-Package -destination 'platform=macOS' \
  -only-testing:MLXLMTests/BatchTokenIteratorTests -only-testing:MLXLMTests/BatchedRecurrentParityTests -only-testing:MLXLMTests/QwenVLBatchedPositionTests

Suite QwenVLBatchedPositionTests passed after 0.351 seconds.
Suite BatchedRecurrentParityTests passed after 0.670 seconds.
Suite BatchTokenIteratorTests passed after 1.896 seconds.
Test run with 49 tests in 3 suites passed after 1.896 seconds.
** TEST SUCCEEDED **

That is 49 tests here; 45 at 5482f7c. The 4 additions are #91's new iterator tests.

Follow-up 5c3e71e, for the Codex finding on that port: DecodeBench rethrows a .failed event's error, so a row that cannot join ends the run instead of leaving a partial batch that still reports a rate. This is how it behaved before, when admission threw. It builds against 5c3e71e (Build complete!). DecodeBench is not part of the test scheme.

Then merged #91's follow-up ca604a2 (head efb92249): 50 tests, all passing.

GenerateParameters initializer merged in (2026-11-07g)

Merged #91's acebd0b (e048b1a) and 1e95cae (5821f85), one push each, each given a thumbs up by Codex. No changes in this PR. Head 5821f85: 54 tests, all passing.

DecodeBench timing for resumable prefill (2026-11-07h)

Pushed one commit at a time; Codex gave each a thumbs up before the next went out.

  • Merged Add continuous batched token generation with checked admission #91's resumable prefill (4bf5ff0). Codex then noted that DecodeBench's timing no longer held: with Llama prefilling resumably, the first step is a prefill, not every row's first token.
  • b2269b2: the time to first token now ends at the first .token event.
    • The decode rate counts only the steady steps: every row decodes, none of them its first token, and no prefill chunk runs.
    • Steps that decode while also feeding a prefill chunk are reported apart, as overlap steps with their mean time.
    • For a model that prefills whole prompts the numbers mean what they meant before.
  • c02bbbc, for a Codex finding on b2269b2: a run with no steady step, such as 4 decode tokens at batch size 8, now stops with an explanation instead of reporting NaN. Checked on Llama 3.2 3B.

Head c02bbbc: 57 tests, all passing. DecodeBench builds (swift build -c release).

DecodeBench (#93 at c02bbbc, release) on the local Llama-3.2-3B-Instruct-4bit, 128 5 4096 greedy 4 mixed (prompt lengths 4096/2958/1820/682). Before is #98 at dc023a7, without this commit; after is #98 at f309640. Runs alternated before, after, after, before.

batch(4) steady decode, total batch(4) time to first token single
before 395.45, 389.00 tok/s 1361, 1359 ms 158.85, 157.45 tok/s
after 395.62, 394.11 tok/s 681, 679 ms 157.36, 157.93 tok/s
  • Steady decode is unchanged.
  • The first token arrives once the first row is prefilled, not after all four.
  • After the change, the three later rows' prefill chunks run alongside decoding: 15 overlap steps at about 67 ms each (one 512-token chunk plus a decode step), where before the decoding waited for the whole admission.
  • Every row matched its single run on all 129 tokens and repeated them in every round.

Two-chunk prefill merged in (2026-11-07j)

Merged #91 at 6dd7f3c (d43364d); Codex gave #91 a thumbs up. 15 more model families opt into resumable prefill, the family test seeds its weights, and two prefill chunks stay in flight (6dd7f3c): a batch of one now reaches its first token as fast as a single run. #91's paired TTFT benchmark ran this PR's DecodeBench. The merge was clean.

BatchTokenIteratorTests + QwenVLBatchedPositionTests + BatchedRecurrentParityTests at d43364d:

** TEST SUCCEEDED **
Test run with 59 tests in 3 suites passed after 4.157 seconds.

Merged #91 again (96d0458). #91's fix ab5075e followed: the prefill wait now uses chunk markers instead of the cache's own arrays, which an in-place cache write had rebound to the chunk just submitted. At 128-token chunks a batch of one's first token came 125 ms sooner. The merge was clean. Focused suites at 96d0458:

** TEST SUCCEEDED **
Test run with 59 tests in 3 suites passed after 2.996 seconds.

Prefill step and arrival mode (2026-11-08)

8a05215 lets developers tune the prefill chunk size on their own hardware:

  • Prefill step: an eighth argument sets PrefillParameters.stepSize for both the single-sequence and the batch paths.
  • Arrival mode: prompt lengths arrival[:tokens].
    • Each batch size is a number of active rows decoding prompts of the prompt length. After 16 steps in which every row decoded, a prompt of tokens arrives (default 4096).
    • Per width, it reports the newcomer's time to first token, the active rows' p50/p95/max gaps between tokens while the newcomer is admitted, and the tokens each active row emitted while it waited.
    • Rounds replay it, alternating the order of the widths.
  • README: a new Benchmarks/DecodeBench/README.md covers both options and notes that the balance depends on the GPU and the model.

Arrival runs

  • Setup: Apple M5 Max, Llama-3.2-3B-Instruct-4bit (local copy), library at Add continuous batched token generation with checked admission #91 ab5075e.
  • Command: decodebench <model> 128 3 145 greedy 1,3 arrival:4096 <step>.
  • Order: four processes, in the step order 512, 256, 256, 512.
  • Timing: TTFT is from the newcomer's insertion. Gaps are pooled over the three rounds of a process.
prefill step active rows newcomer TTFT active p50 gap active p95 gap active max gap tokens per active row while it waited
512 1 621, 621 ms 71.0, 70.5 ms 79.3, 79.0 ms 80.9, 79.2 ms 10
512 3 649, 644 ms 71.5, 70.3 ms 79.2, 78.5 ms 79.6, 79.9 ms 10
256 1 864, 856 ms 51.1, 50.1 ms 56.5, 56.7 ms 59.1, 58.3 ms 18
256 3 887, 878 ms 50.8, 50.8 ms 57.3, 56.8 ms 59.4, 57.6 ms 18
  • 256-token chunks cut the active rows' p95 gap by about 22 ms and give each active row 18 tokens during admission instead of 10.
  • But the newcomer waits about 235 ms longer.
  • This reproduces Codex's earlier measurement of the same scenario: p95 78.5 → 58.0 ms, TTFT 624 → 862 ms.
  • Every width repeated its tokens in every round.
  • -DSINGLE_ONLY still builds.

Merged #91 once more (7c434f8) for 31b3e7d, a documentation note on choosing PrefillParameters.stepSize that points to the arrival mode above. The merge was clean. Focused suites at 7c434f8:

** TEST SUCCEEDED **
Test run with 59 tests in 3 suites passed after 2.981 seconds.

#91's marker and layer-count fixes merged in (2026-11-08)

Merged #91 (a0b4216). It brings #91 at 3ac324a:

  • 6c28e8c: each prefill chunk now has one marker that owns its memory. Before, its markers were views of the cache buffers, which forced every in-place chunk to copy its buffer.
  • 3ac324a: a first row whose supplied cache has fewer layers than the model now fails with KVCacheError instead of trapping in the model.

The merge was clean. Focused suites at a0b4216:

** TEST SUCCEEDED **
Test run with 61 tests in 3 suites passed after 2.800 seconds.

Merged #91 again (922a95c) for c9145a2. The prefill chunk marker is now a single element: one element of the last cache array instead of every array's. That removes the ~10 ms that 6c28e8c added to a batch of four's first-row TTFT on 2048-token prompts, and the marker still owns its memory. The merge was clean. Focused suites at 922a95c:

** TEST SUCCEEDED **
Test run with 61 tests in 3 suites passed after 2.787 seconds.

Not done on purpose

Test changes

  • 2026-11-08 (merge 922a95c): no test changes.
  • 2026-11-08 (merge a0b4216): no test changes.
  • 2026-11-08 (merge 7c434f8): no test changes.
  • 2026-11-08 (8a05215): no test changes; DecodeBench is not part of the test targets.
  • 2026-11-07j (merge 96d0458): no test changes.
  • 2026-11-07j (merge d43364d): no test changes.
  • 2026-11-07e: none.
  • None. This PR has no tests.

AI assistance: the benchmark was developed with Claude Code. Codex extracted it into this optional PR and restacked and validated it at the maintainer's request for this origin fork. Claude Code added the batch sizes and mixed lengths, and restacked it onto the rewritten #91.

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T05:04:19.343246Z 922a95c Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 10f50ff193

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ronaldmannak

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: c043d848f8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ronaldmannak
ronaldmannak force-pushed the codex/standalone-decode-benchmarks branch from 253564b to e0dc0cf Compare November 6, 2026 03:54
@ronaldmannak
ronaldmannak force-pushed the claude/a4-batch-token-iterator branch from e36259c to cc49616 Compare November 6, 2026 03:54
@ronaldmannak
ronaldmannak force-pushed the codex/standalone-decode-benchmarks branch from e0dc0cf to d4fa4f5 Compare November 6, 2026 04:23
@ronaldmannak
ronaldmannak force-pushed the claude/a4-batch-token-iterator branch from cc49616 to 6821d03 Compare November 6, 2026 04:23
@ronaldmannak
ronaldmannak force-pushed the claude/a4-batch-token-iterator branch from 6821d03 to bf09f16 Compare November 6, 2026 20:41
@ronaldmannak
ronaldmannak force-pushed the codex/standalone-decode-benchmarks branch 2 times, most recently from 4e4c889 to 4b4d11f Compare November 6, 2026 21:07
@ronaldmannak
ronaldmannak force-pushed the claude/a4-batch-token-iterator branch from bf09f16 to b166406 Compare November 6, 2026 21:07
@ronaldmannak
ronaldmannak force-pushed the codex/standalone-decode-benchmarks branch 2 times, most recently from 097fa0c to 7a4cc19 Compare November 6, 2026 22:22
@ronaldmannak
ronaldmannak force-pushed the claude/a4-batch-token-iterator branch from 3122507 to 1793cc5 Compare November 6, 2026 22:22
@ronaldmannak
ronaldmannak force-pushed the codex/standalone-decode-benchmarks branch from 7a4cc19 to d80c2ac Compare November 7, 2026 05:11
@ronaldmannak
ronaldmannak force-pushed the claude/a4-batch-token-iterator branch 2 times, most recently from dbce3a0 to 51d71ef Compare November 7, 2026 06:25
@ronaldmannak
ronaldmannak force-pushed the codex/standalone-decode-benchmarks branch from d80c2ac to 4f1a7d6 Compare November 7, 2026 06:25
ronaldmannak and others added 2 commits November 6, 2026 23:50
Batch sizes are now a comma-separated argument, 1,4,8 by default, each
timed and reported per row and in total. A mixed-lengths option gives
the rows of a batch prompts that shrink evenly to a sixth of the full
length, so all rows but the first are left-padded.

Every batch row is compared with an untimed single-sequence run of its
own prompt. This replaces the two fixed comparisons (single against
batch of one, batch of one against row 0 of the batch of four) with one
per row for every size. Agreement stays reported, not asserted. The
alternating order now puts every batch size before or after the single
run. The SINGLE_ONLY build is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ronaldmannak

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 5821f85623

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

ronaldmannak and others added 2 commits November 7, 2026 13:08
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With resumable prefill (PR 91), a BatchTokenIterator step can feed a
prefill chunk instead of yielding tokens, and rows join one step apart.
DecodeBench timed the first next() as the prefill and every later step
as decode, which no longer holds.

The time to first token now ends at the first .token event. The decode
rate counts only the steady steps: every row decodes, none of them its
first token, and no prefill chunk runs. Steps that decode while also
feeding a prefill chunk are reported apart, as overlap steps with their
mean time. For a model that prefills whole prompts the numbers mean what
they meant before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4bf5ff07d1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +146 to +148
try record(try iterator.next())
let firstToken = seconds(since: start)
let decodeStart = ContinuousClock.now

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Establish the timing boundary from actual token events

For Llama models, which already conform to ResumablePrefillModel at this commit, the first BatchTokenIterator.next() returns only a .prefill event, not the first token of every row. resumableStep() admits at most one row per call and delivers its first token on a later call. Consequently, this boundary reports TTFT before any token is delivered and includes subsequent rows' prefill and staggered admission in the purported decode-only throughput measurement, even with the default 145-token prompts. Establish the boundary using actual token events and account for staggered row admission so the reported batch decode rate remains comparable to the single-sequence rate.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b2269b2. The time to first token now ends at the first .token event, and the decode rate counts only steady steps: every row decodes, none of them its first token, and no prefill chunk runs. Steps that decode while also feeding a prefill chunk are reported apart as overlap steps. For a model that prefills whole prompts the numbers mean what they meant before.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b2269b2919

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}
}
return Run(
tokensPerSecond: Double(steadySteps) / steadySeconds,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Handle runs with no steady-state decode samples

For a resumable-prefill model such as Llama, a short run can finish its earliest rows before all requested rows begin decoding. For example, requesting 4 decode tokens with the default batch sizes leaves batch(8) with no steps satisfying the steady-state predicate, so both counters remain zero and this division reports NaN throughput. Long prompts requiring multiple prefill chunks can cause the same problem even with larger token limits. Detect the absence of steady-state samples and report the measurement as unavailable with an actionable explanation, or extend the run until a measurable steady-state interval exists.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the next commit on this branch: with no steady decode step, DecodeBench now stops with an explanation (ask for more decode tokens than the rows and their prefill chunks take to join) instead of reporting NaN. Checked with 4 decode tokens at batch size 8 on Llama 3.2 3B.

With resumable prefill the rows join one step apart, so a short run (for
example 4 decode tokens at batch size 8) can end its first rows before the
last one decodes. No step then decodes every row without a prefill chunk,
and the steady decode rate divided zero by zero. DecodeBench now stops with
an explanation instead of reporting NaN. Found by Codex.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ronaldmannak

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c02bbbc68a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

var state = seed &* 6_364_136_223_846_793_005 &+ 1_442_695_040_888_963_407
return (0 ..< length).map { _ in
state = state &* 6_364_136_223_846_793_005 &+ 1_442_695_040_888_963_407
return Int32(1000 + (state >> 33) % 20000)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Bound synthetic token IDs by the loaded model's vocabulary

For a local model with a vocabulary smaller than 21,000 entries, this generator can produce token IDs outside its embedding table; with fewer than 1,001 entries, every generated token is invalid. Small-vocabulary configurations are supported—for example, Tests/MLXLMTests/Qwen3PrefillLogitsTests.swift uses a Qwen3 configuration with vocab_size: 256. Such models receive out-of-range embedding indices during the initial warm-up rather than a valid benchmark workload. Derive the sampling range from the loaded model's vocabulary size while retaining the deterministic seed.

Useful? React with 👍 / 👎.

Comment on lines +148 to +150
let stepStart = ContinuousClock.now
guard let events = try iterator.next() else { break }
let stepSeconds = seconds(since: stepStart)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include between-step GPU execution in steady decode timing

For fast models or large batches, summing only the durations of iterator.next() overstates decode throughput. BatchTokenIterator.step() enqueues the successor with asyncEval before returning the current tokens, so GPU execution continues during the untimed event-processing loop, including the per-token ids.firstIndex searches and token appends. The next timed call therefore waits for only the remaining work, while steadySeconds omits execution that already happened between calls. This also biases comparisons against runSingle, which uses a continuous elapsed interval. Measure the steady-state interval continuously across consecutive qualifying steps, including the gaps between calls, rather than summing isolated call durations.

Useful? React with 👍 / 👎.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ronaldmannak

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: d43364d7ee

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ronaldmannak

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 96d04582a4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ronaldmannak

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 96d04582a4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

ronaldmannak and others added 2 commits November 7, 2026 19:36
So developers can tune the prefill chunk size on their own hardware:

- An eighth argument sets PrefillParameters.stepSize for both the
  single-sequence and the batch paths.
- Prompt lengths `arrival[:tokens]`: each batch size is a number of
  active rows decoding prompts of the prompt length; after 16 steps in
  which every row decoded, a prompt of `tokens` (default 4096) arrives.
  Per width it reports the newcomer's time to first token, the active
  rows' p50/p95/max gaps between tokens while the newcomer is admitted,
  and the tokens each active row emitted while it waited. Rounds replay
  it, alternating the order of the widths.
- A README describes the options and notes that the balance depends on
  the GPU and the model.

On an Apple M5 Max with Llama 3.2 3B 4-bit (1 and 3 active rows, 145-token
prompts, a 4096-token arrival), step 512 gives a p95 gap of 78.5-79.3 ms
and a 621-649 ms newcomer TTFT; step 256 gives 56.5-57.3 ms and 856-887 ms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ronaldmannak

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 8a05215813

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ronaldmannak

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 7c434f88c6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ronaldmannak

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: a0b4216d9f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ronaldmannak

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 922a95c1ad

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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