Repository navigation
Fix prefill LMOutput.State being dropped on TokenIterator's .logits path - #419
Merged
davidkoski merged 1 commit intoJul 13, 2026
Merged
Conversation
Qwen2.5-VL seeds its MROPE positionIds/ropeDeltas into the per-call LMOutput.State during prefill, but prepare()'s .logits branch never carried result.state into self.state, so the first decode step ran without them — position drift after an image-token block, degenerate empty output on dense frames. The .tokens branch already gets the carry via step(previous:) and the speculative iterator sets mainState = result.state; this makes the standard path consistent.
4 tasks done
davidkoski
approved these changes
Jul 13, 2026
davidkoski
left a comment
Member
There was a problem hiding this comment.
Change looks good. will be useful for #399 as well. Just waiting on CI
spokvulcan
added a commit
to spokvulcan/mlx-swift-lm
that referenced
this pull request
Jul 14, 2026
Review rework for ml-explore#399: no new protocol — LanguageModel.prepare gains state: LMOutput.State? instead, and prepareContinuation becomes a private detail of Qwen35. This also fixes a live cross-turn bug (the sibling of ml-explore#419's prefill-to-decode drop): ChatSession keeps the KV cache warm across turns, but the per-call M-RoPE state died with each turn's TokenIterator, so Qwen3.5 recomputed positions from zero on every warm continuation. On a tiny random-weight model, warm turn-2 logits diverge from a cold full prefill by 0.43 max-abs against a 8.3e-07 decode-path noise floor; with state threaded, all continuation shapes match the one-shot reference. - Qwen35: windowSize ?? 512 chunked prefill (Gemma3 parity); warm single-sequence continuations always route through the anchored windowed forward (anchor = cache offset + carried rope delta) - TokenIterator: optional seed state, post-prefill state readable - ChatSession: state persists across turns and tool-call restarts, stored alongside the KV cache - All other conformers take the parameter mechanically and ignore it; speculative/MTP iterators unchanged - Qwen35ContinuationTests: five tiny-model equivalence tests (warm text/image continuation, three-turn image resume state, windowed vs single-shot with an image straddling a window boundary) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
3 tasks
dkgv
pushed a commit
to dkgv/mlx-swift-lm
that referenced
this pull request
Jul 30, 2026
…ath (ml-explore#419) Qwen2.5-VL seeds its MROPE positionIds/ropeDeltas into the per-call LMOutput.State during prefill, but prepare()'s .logits branch never carried result.state into self.state, so the first decode step ran without them — position drift after an image-token block, degenerate empty output on dense frames. The .tokens branch already gets the carry via step(previous:) and the speculative iterator sets mainState = result.state; this makes the standard path consistent.
4 tasks
div0-space
pushed a commit
to LibraxisAI/mlx-swift-lm
that referenced
this pull request
Nov 29, 2026
* ci: queue Swift LM workloads on native runners * CI: stage disabled native CodeQL scanning and isolated uploads Preserve the existing Actions, C/C++ and Python default suites and categories. Keep activation behind CODEQL_NATIVE until the operator verifies advanced setup and the upload path. Prepared with OpenAI Codex assistance. * docs: describe native queue and qualification limits
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.
Proposed changes
Qwen2.5-VL seeds its MROPE
positionIds/ropeDeltasinto the per-callLMOutput.Stateduring prefill (the #283 pattern), butTokenIterator.prepare(...)'s.logitsbranch never carriesresult.stateintoself.state, so the first decode step runs without them — positions drift by the image-token count and greedy decode emits an empty```fence instead of the JSON body.Reproducible with
mlx-community/Qwen2.5-VL-7B-Instruct-4biton any dense full-page screenshot (e.g. a 1280×900 capture of a Wikipedia article) with a standardbbox_2dgrounding prompt at temperature 0:mainreturns a lone fence; with the state carried, the same input grounds correctly.The
.tokensbranch already gets the carry viastep(previous:), and the speculative iterator's.logitsbranch doesmainState = result.state; this makes the standard path consistent with both. +2 lines, one function.Follows the Qwen2.5-VL fixes in #238 / #239 / #242 / #243 — #239 moved the MROPE state onto per-call
LMOutput.State; this restores its prefill→decode handoff on the.logitspath.Checklist
pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes