-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Fix oom error for large page size #4913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2834035
fix oom error for large page size
xiezhq-hermann ec9125a
Merge branch 'main' into xiezhq-page-fix
xiezhq-hermann d0365d5
roll back to a more conservative checking
xiezhq-hermann 719ca16
Update schedule_batch.py
xiezhq-hermann 037f884
Merge branch 'main' into xiezhq-page-fix
xiezhq-hermann 42370ab
Merge branch 'main' into xiezhq-page-fix
xiezhq-hermann f20913a
Fix lint
merrymercy c674f64
Merge branch 'main' into xiezhq-page-fix
xiezhq-hermann ffaf35b
Fix flaky tests
merrymercy e99bacb
Merge branch 'main' into xiezhq-page-fix
merrymercy c37d307
Merge branch 'main' into xiezhq-page-fix
xiezhq-hermann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -793,16 +793,23 @@ def alloc_paged_token_slots_extend( | |
| raise RuntimeError(error_msg) | ||
| return out_cache_loc | ||
|
|
||
| @property | ||
| def new_page_count_next_decode(self): | ||
| page_size = self.token_to_kv_pool_allocator.page_size | ||
| if page_size == 1: | ||
| return len(self.reqs) | ||
| return sum(1 for req in self.reqs if req.seqlen % page_size == 0) | ||
|
|
||
| def alloc_paged_token_slots_decode( | ||
| self, | ||
| seq_lens: torch.Tensor, | ||
| last_loc: torch.Tensor, | ||
| ): | ||
| if ( | ||
| self.token_to_kv_pool_allocator.available_size() | ||
| < len(seq_lens) * self.token_to_kv_pool_allocator.page_size | ||
| ): | ||
| if self.tree_cache is not None: | ||
| if self.tree_cache is not None: | ||
| if ( | ||
| self.token_to_kv_pool_allocator.available_size() | ||
| < len(seq_lens) * self.token_to_kv_pool_allocator.page_size | ||
| ): | ||
| self.tree_cache.evict( | ||
| len(seq_lens) * self.token_to_kv_pool_allocator.page_size, | ||
| ) | ||
|
|
@@ -1096,16 +1103,18 @@ def mix_with_running(self, running_batch: "ScheduleBatch"): | |
| self.extend_logprob_start_lens.extend([0] * running_bs) | ||
|
|
||
| def check_decode_mem(self, buf_multiplier=1): | ||
| bs = len(self.reqs) * buf_multiplier | ||
| if self.token_to_kv_pool_allocator.available_size() >= bs: | ||
| return True | ||
|
|
||
| self.tree_cache.evict(bs) | ||
| tokens_required = ( | ||
| self.new_page_count_next_decode | ||
| * buf_multiplier | ||
| * self.token_to_kv_pool_allocator.page_size | ||
| ) | ||
|
|
||
| if self.token_to_kv_pool_allocator.available_size() >= bs: | ||
| if self.token_to_kv_pool_allocator.available_size() >= tokens_required: | ||
| return True | ||
|
|
||
| return False | ||
| self.tree_cache.evict(tokens_required) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be |
||
|
|
||
| return self.token_to_kv_pool_allocator.available_size() >= tokens_required | ||
|
|
||
| def retract_decode(self, server_args: ServerArgs): | ||
| """Retract the decoding requests when there is not enough memory.""" | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.