Prevented fully cached sequences from being processed in prefill phase #117
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.
Thank you for this amazing open-source project!
Problem
Fixes the crash reported in #114 where the system crashes when prompt length exactly equals
kvcache_block_size(256 tokens). Additionally, optimizes scheduler performance by preventing fully cached sequences from entering prefill computation.Root Cause Analysis
seq.num_cached_tokens == len(seq), all tokens are cached, resulting intokens_to_compute = 0Solution
1. Scheduler Optimization (
scheduler.py)Before: All sequences were added to
scheduled_seqsregardless of cache statusAfter: Only sequences with
tokens_to_compute > 0are scheduled for computationBenefits:
2. Block Manager (
block_manager.py)Before: Assertion failure when
last_block.hash == -1in certain edge casesAfter: Conditional check to handle edge cases gracefully
Purpose: This change ensures compatibility with fully cached sequences where the previous hash value is already correct and doesn't need recalculation.
Closes #114
I look forward to your review and would appreciate any feedback.