Repository navigation
Conversation
…up#179) The chunked-vs-full prefill decision in `prefill_sequence` keys off the *full* prompt length, but `start_chunked_prefill` only processes the suffix `[prefill_start_offset..]`. On a prompt-cache hit the adopted prefix can cover all but a short suffix, so when the full prompt clears the 512-token chunk threshold the suffix still fits entirely in chunk 0. In that case chunk 0 already reaches the end of the prompt, yet `start_chunked_prefill` unconditionally stored the sequence for continuation (unlike `continue_chunked_prefill`, which guards on `end < total`). On the next tick `continue_chunked_prefill` ran with `offset == total`, slicing an empty `[total..total]` chunk and feeding a `[1, 0]` input to the model. The resulting `[1, 0, vocab]` logits then crashed in `slice_last_logits`: std::invalid_argument: [squeeze] Cannot squeeze axis 1 with size 0 This reproduced on multi-turn chat (Qwen3-Coder-30B-A3B-Instruct, prompt cache on) on turn 3, where the prompt first crosses the chunk threshold — exactly matching the report. Disabling the cache forces `start_offset=0`, so chunk 0 never reaches the end and the bug is masked. Fix: after processing chunk 0, if `end >= prompt_tokens.len()` finish the prefill and sample the first token (mirroring the final-chunk path in `continue_chunked_prefill`) instead of queuing an empty continuation. This guarantees `chunked_prefill_seq` is only ever stored with `prefill_offset < total`, so `continue_chunked_prefill` can never receive an empty chunk. Adds two regression tests covering the first-chunk-terminal boundary for both the long-cache-hit case (terminal) and the cold long-prompt case (non-terminal). Fixes lablup#179 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Member
Hardening Review UpdateTarget PR reviewed: #183 SummaryI reviewed the implementation against the issue's cache-enabled turn-3 crash scenario and pushed follow-up hardening commit Findings and fixes
Security reviewNo authentication, authorization, file, network, shell, secret-handling, or user-input parsing surface is changed. I did not find a security issue in this PR's scope. Performance / reliability reviewThe valid hot path adds only small integer range calculation before the existing forward pass. It avoids no-progress scheduler states and prevents the zero-length input shape from reaching MLX. Validation
I did not rerun the large Qwen3-Coder real-checkpoint repro locally; the original PR body records that E2E validation on this branch. |
Contributor
Author
|
Thank you for your prompt attention to this! |
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.
Summary
Fixes #179 — a
std::invalid_argument: [squeeze] Cannot squeeze axis 1 with size 0crash on the third turn of a multi-turn chat when the prompt-prefix cache is enabled (Qwen3-Coder-30B-A3B-Instruct, but model-agnostic).Root cause
The chunked-vs-full prefill decision in
prefill_sequencekeys off the full prompt length, butstart_chunked_prefillonly processes the suffix[prefill_start_offset..]. On a prompt-cache hit the adopted prefix can cover all but a short suffix, so when the full prompt clears the 512-token chunk threshold the suffix still fits entirely in chunk 0.In that case chunk 0 already reaches the end of the prompt, yet
start_chunked_prefillunconditionally stored the sequence for continuation — unlikecontinue_chunked_prefill, which guards onend < total. On the next tickcontinue_chunked_prefillran withoffset == total, sliced an empty[total..total]chunk, and fed a[1, 0]input to the model. The resulting[1, 0, vocab]logits then crashed inslice_last_logits, which slices the last position and squeezes axis 1 (size 0).This is why the crash is cache-only (a cold prefill has
prefill_start_offset == 0, so chunk 0 never reaches the end) and turn-3-specific (turn 3 is where the prompt first crosses the chunk threshold; turn 2's 455-token prompt stays under 512 and takes the full-prefill path).Fix
After processing chunk 0, if
end >= prompt_tokens.len()finish the prefill and sample the first token (mirroring the final-chunk path incontinue_chunked_prefill) instead of queuing an empty continuation. This guaranteeschunked_prefill_seqis only ever stored withprefill_offset < total, socontinue_chunked_prefillcan never receive an empty chunk.Adds two regression tests covering the first-chunk-terminal boundary: the long-cache-hit case (terminal → finish) and the cold long-prompt case (non-terminal → continue).
Verification
cargo test --features metal,accelerate scheduler— all scheduler tests pass, including the two new ones.repro.mjsfrom the issue (Qwen3-Coder-30B-A3B-Instruct-MLX-8bit, prompt cache on):[squeeze]abort.