Skip to content

Pipelined decode: the last layer's finish goes in token order - #13

Merged
srcterm merged 1 commit into
mainfrom
fix/finish-order
Nov 15, 2026
Merged

srcterm merged 1 commit into
mainfrom
fix/finish-order

Conversation

@srcterm

@srcterm srcterm commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

A stream could finish the last layer before the stream ahead of it had, and Inkling 2's pipelined decode then produced wrong tokens.

Cause

The scheduler lets a stream begin a layer only after the stream before it has begun it, which also puts the finishes of every layer but the last in token order. For the last layer there was a waiver: a stream that had begun it could finish as soon as its own reads were in. Inkling 2's adapter stores a layer's fourth convolution state in finish(), and the next token's finish() reads it, so its finishes have to go in token order at every layer.

Before the overlapped step (#11) the earlier stream's reads always had a routing round trip of head start, and it never lost. With the overlapped step its reads start after the later stream's begin has been handed over, and a later stream without misses can overtake it. This has been on main since #11 and #12 were both merged. Only Inkling's adapter writes cache state in finish(); Qwen3.8, DeepSeek-V4.1 and the generic adapter are not affected, and Inkling pipelined is opt-in (--draft-head).

Fix

The predecessor rule now holds for the last finish too: a stream finishes the last layer once the stream before it is through the stack. One condition in PipelinedDecoder._ready.

Evidence

Tiny random Inkling with a random draft head (every step rolls streams back), 8 slots a layer, pipelined decode against stock mlx-lm, 40 decodes each:

main this branch
as it is 2 of 40 differ 0 of 40
a stream's routing evaluated at once (widens the window) 40 of 40 differ 0 of 40

The full Inkling pipeline toy failed 8 of 40 runs on main and 0 of 54 on the Inkling branch before the overlapped step; with the fix 0 of 40. The other toys and the Qwen3.6 gate (validate, generate, serve: the recorded hashes) pass.

Other models

Main's scheduler and this one alternating in blocks inside one pipelined decode, compared per step at equal step size and misses:

Text Cost of the fix
Qwen3.8-Flash-Next, 16 GiB, up to 3 tokens in flight, 320 tokens first 128 and 160 tokens are main's +0.9% ± 1.5% a step
DeepSeek-V4.1-Flash, 12.2 GiB, up to 6 tokens in flight, 256 tokens equal to the 256-token reference +0.9% ± 0.8% a step

So no measurable cost on either, and both keep their text. The stricter rule only delays a stream's last finish while the stream ahead is still waiting on reads for the last layer.

…re it (Inkling 2 stores a convolution state in finish that the next token's finish reads; since the overlapped step a stream whose reads came first could overtake: wrong tokens in 8 of 40 runs of the Inkling toy)
@srcterm
srcterm requested a balanced review from Copilot and removed request for Copilot November 15, 2026 17:00

Copilot AI 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.

🟢 Approval recommended

No active review issues are recorded for the scheduler’s token-ordering change to protect shared convolution state.

No open issues 🎉

What changed in this PR

This PR fixes an Inkling 2 pipelined-decoding race by requiring final-layer finishes to follow token order, protecting shared convolution state used by successive tokens.

Changes:

  • Removes the final-layer exception from the scheduler’s predecessor check, so each stream waits until its predecessor is through the stack.
  • Updates scheduler documentation to explain ordering requirements for both begin and finish.
File Description
streamlx/​pipeline.py Enforces token-ordered final-layer finishes and documents the shared-cache dependency.

Review effort: Balanced

@srcterm
srcterm merged commit 9ab2cca into main Nov 15, 2026
1 of 2 checks passed
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