Include spec stats in metrics#4625
Open
RunningLeon wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds Prometheus metrics for speculative decoding (spec decode) so that spec decode statistics can be scraped from the service /metrics endpoint.
Changes:
- Add spec decode Prometheus counters and gauges to
PrometheusStatLogger. - Implement
record_specdecode()to export spec decode totals and derived acceptance metrics. - Add a unit test validating that spec decode metrics are emitted as expected.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lmdeploy/metrics/loggers.py | Adds Prometheus metric definitions and record_specdecode() implementation to export spec decode stats. |
| tests/test_lmdeploy/test_metrics_loggers.py | Adds a pytest test covering the newly exported spec decode metrics. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+206
to
+210
| # Speculative decoding counters. Acceptance rate and mean acceptance | ||
| # length are derived in PromQL from these raw counters. | ||
| # rate(accepted_tokens) / rate(draft_tokens) | ||
| # 1 + rate(accepted_tokens) / rate(drafts) | ||
| self.counter_spec_decode_num_drafts = prometheus_client.Counter( |
Comment on lines
+389
to
+406
| @staticmethod | ||
| def _get_counter_value(counter) -> float: | ||
| """Get the current value from a prometheus counter child.""" | ||
| return counter._value.get() | ||
|
|
||
| def record_specdecode(self, stats: SpeculativeDecodingStats) -> None: | ||
| pass | ||
| """Report speculative decoding metrics to prometheus.""" | ||
| if stats.num_drafts <= 0: | ||
| return | ||
|
|
||
| self.counter_spec_decode_num_drafts.inc(stats.num_drafts) | ||
| self.counter_spec_decode_num_draft_tokens.inc(stats.num_draft_tokens) | ||
| self.counter_spec_decode_num_accepted_tokens.inc(stats.num_accepted_tokens) | ||
|
|
||
| num_drafts = self._get_counter_value(self.counter_spec_decode_num_drafts) | ||
| num_draft_tokens = self._get_counter_value(self.counter_spec_decode_num_draft_tokens) | ||
| num_accepted_tokens = self._get_counter_value(self.counter_spec_decode_num_accepted_tokens) | ||
| mean_accept_rate = num_accepted_tokens / num_draft_tokens if num_draft_tokens > 0 else 0.0 |
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
Include spec stats in metrics
get spec stats info from service
Modification
Please briefly describe what modification is made in this PR.
BC-breaking (Optional)
Does the modification introduce changes that break the backward-compatibility of the downstream repositories?
If so, please describe how it breaks the compatibility and how the downstream projects should modify their code to keep compatibility with this PR.
Use cases (Optional)
If this PR introduces a new feature, it is better to list some use cases here, and update the documentation.
Checklist