Add metrics for speculative decoding (acceptance rate, average acceptance length)#11441
Merged
zhyncs merged 17 commits intosgl-project:mainfrom Oct 13, 2025
Merged
Add metrics for speculative decoding (acceptance rate, average acceptance length)#11441zhyncs merged 17 commits intosgl-project:mainfrom
zhyncs merged 17 commits intosgl-project:mainfrom
Conversation
…nto sjl/1001-spec-metrics
…nto sjl/1001-spec-metrics
4 tasks
scottjlee
commented
Oct 10, 2025
Comment on lines
+380
to
+382
| req.spec_accepted_tokens += ( | ||
| sum(1 for idx in accept_index_row if idx != -1) - 1 | ||
| ) |
Collaborator
There was a problem hiding this comment.
LGTM, this change seems pretty lightweight.
7 tasks
zhyncs
approved these changes
Oct 12, 2025
Collaborator
merrymercy
reviewed
Oct 13, 2025
lpc0220
pushed a commit
to lpc0220/sglang
that referenced
this pull request
Oct 29, 2025
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.
Re-attempt of #11144, which introduced an additional device sync per verify pass (see discussion here). This PR updates the implementation to instead iterate over an existing list on CPU, avoiding the device sync (see here for the change).
Motivation
To better understand results when using speculative decoding, it would be helpful to have request-level information on the acceptance rate and average acceptance length.
Modifications
Add the following metrics tracked at the request level:
spec_accept_rate: Speculative decoding acceptance rate for this request(# accepted tokens / # draft tokens).spec_accept_length: Number of accepted tokens for each verification pass, averaged across all passes for this request.These metrics are collected at a per-request level, and reported in the final log output (example below):
In addition, we also expose the average acceptance rate of a batch (calculated as
total accepted tokens / total draft tokensfor a batch) as a Prometheus metricsglang:spec_accept_rate. Example output below:Accuracy Tests
Should not affect model outputs or accuracy.
Benchmarking and Profiling
Checklist