Repository navigation
Pipelined decode: the last layer's finish goes in token order - #13
Merged
Merged
Conversation
…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
requested
a balanced review from Copilot
and removed request for
Copilot
November 15, 2026 17:00
Copilot stopped reviewing on behalf of
srcterm due to an error
November 15, 2026 17:01
There was a problem hiding this comment.
🟢 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
beginandfinish.
| File | Description |
|---|---|
streamlx/pipeline.py |
Enforces token-ordered final-layer finishes and documents the shared-cache dependency. |
Review effort: Balanced
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.
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'sfinish()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:
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:
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.