[Observability] Add pending token count to prefill log and get_load#22480
Merged
[Observability] Add pending token count to prefill log and get_load#22480
Conversation
Add a `#pending-token` metric to the prefill batch log and a `num_pending_tokens` field to the `GetLoadReqOutput` returned by `/get_load`. This shows the total number of tokens still waiting to be prefilled, including remaining tokens from the currently chunked request. This is particularly useful for load balancing long-context requests across engines. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
Collaborator
Author
|
/tag-and-rerun-ci |
Removed outdated comments regarding prefix_indices and chunk_deduct.
Fridge003
pushed a commit
that referenced
this pull request
Apr 11, 2026
…22480) Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
pyc96
pushed a commit
to pyc96/sglang
that referenced
this pull request
Apr 14, 2026
…gl-project#22480) Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
yhyang201
pushed a commit
to yhyang201/sglang
that referenced
this pull request
Apr 22, 2026
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.
Motivation
For prefill requests, the engine log only shows
#queue-reqand#running-req, which is insufficient for understanding load — especially for long-context requests where a single request can have hundreds of thousands of tokens pending prefill across multiple chunks.This PR adds a
#pending-tokenmetric that shows the total number of tokens still waiting to be prefilled. This is useful for:/get_loadModifications
PrefillStats(scheduler_metrics_mixin.py): Addednum_pending_tokensfield, snapshotted at batch-scheduling time for correct reporting under the overlap scheduler._get_num_pending_tokens()(scheduler_metrics_mixin.py): New shared helper that computes pending tokens from the waiting queue plus remaining tokens of the currently chunked request. Accepts achunk_deductparameter to handle the timing difference between scheduling time (whereprefix_indiceshas not yet been updated) and query time (get_load, where it has).scheduler_metrics_mixin.py): Added#pending-token: {N}to the log line.GetLoadReqOutput(io_struct.py): Addednum_pending_tokensfield returned by/get_load.get_load()(scheduler_metrics_mixin.py): Populatesnum_pending_tokensusing the shared helper.get_new_batch_prefill()(scheduler.py): Snapshotsnum_pending_tokensintoPrefillStatsat scheduling time.Example log output with a 30K-token chunked prefill (chunk size 8192):
Accuracy Tests
N/A — observability-only change, no model output affected.
Speed Tests and Profiling
N/A — adds a lightweight sum over the waiting queue during logging and load queries.
Checklist