-
Notifications
You must be signed in to change notification settings - Fork 749
[Scheduler] Simplify scheduler for prefill instances #7944
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
Open
liyonghua0910
wants to merge
1
commit into
PaddlePaddle:develop
Choose a base branch
from
liyonghua0910:develop+20260527_prefill_schedule
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+31
−1
Open
Changes from all commits
Commits
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
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 |
|---|---|---|
|
|
@@ -1248,6 +1248,32 @@ def _allocate_decode_and_extend(): | |
|
|
||
| return batch_request, error_reqs | ||
|
|
||
| def prefill_schedule(self): | ||
| with self.lock: | ||
| # P instance has no decode — full budget for prefill | ||
| batch_request = BatchRequest() | ||
| token_budget = self.config.scheduler_config.max_num_batched_tokens | ||
|
|
||
| assert len(self.waiting) == 0, "Prefill scheduler should not have waiting requests" | ||
|
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. 🟡 建议 Python 以 建议改为显式异常或日志警告: if len(self.waiting) != 0:
llm_logger.warning(
f"prefill_schedule: unexpected {len(self.waiting)} waiting requests, skipping them."
)或如果这是不可恢复的状态: if len(self.waiting) != 0:
raise RuntimeError(
f"Prefill scheduler should not have waiting requests, got {len(self.waiting)}"
) |
||
|
|
||
| # Prepare prefill tasks for all running requests | ||
| for request in list(self.running): | ||
| if self._is_decoding(request): | ||
| continue | ||
|
|
||
| num_new_tokens = self._get_num_new_tokens(request, token_budget) | ||
| if num_new_tokens == 0: | ||
| continue | ||
|
|
||
| # Add requests into scheduled batch as blocks were preallocated | ||
| llm_logger.debug(f"schedule prefill tasks {request.request_id} with {num_new_tokens} tokens") | ||
| batch_request.add_request(self._prepare_prefill_task(request, num_new_tokens)) | ||
| token_budget -= num_new_tokens | ||
| request.num_computed_tokens += num_new_tokens | ||
|
|
||
| self.update_metrics() | ||
| return batch_request, [] | ||
|
|
||
| def waiting_async_process(self, request: Request) -> None: | ||
| """ | ||
| Check if async preprocessing is complete for a request. | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 建议
prefill_schedule()仅在resource_manager_v1中实现,其他实现调用时会抛AttributeErrorcommon_engine.py对所有splitwise_role == "prefill"的实例无条件调用self.resource_manager.prefill_schedule(),但该方法目前只在resource_manager_v1.py中新增。若项目存在其他 resource manager 实现(如 v2 或未来新增版本),以 prefill 角色启动时会在此处崩溃。注意到代码中已有类似的防御写法(
hasattr检查scheduler_unhandled_request_num)。建议同步到其他 resource manager 实现,或添加防御检查: