spec: add spec metrics mean acceptance length and acceptance rate per position#24536
Conversation
|
cc @ggerganov |
| size_t n_gen_tokens = 0; // number of tokens generated by this implementation. | ||
| size_t n_acc_tokens = 0; // number of tokens accepted by the target model. | ||
|
|
||
| size_t n_draft_verif_steps = 0; // number of draft token verification steps by the target model. |
There was a problem hiding this comment.
This is the same as n_call_accept - no need for new member.
There was a problem hiding this comment.
fixed. Thanks for pointing out.
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
|
Thanks for the review! @ggerganov I fixed all the issues, and checked the results again. It looks good to me. |
| std::string str_stats; | ||
| if (impl->n_call_accept > 0) { | ||
| const double mean = | ||
| 1.0 + (double) impl->n_acc_tokens / (double) impl->n_call_accept; |
There was a problem hiding this comment.
Is it correct to have 1.0 + here?
For example, if I see in the logs mean acc len = 3.0, should I use --spec-draft-n-max 3 or --spec-draft-n-max 2. I think it is the latter, which is a bit confusing.
There was a problem hiding this comment.
Yes, the 1.0 + is intentional. It follows the conventional definition from vLLM: mean acceptance length = tokens committed per target forward pass, including the bonus token that's always produced even when no draft is accepted — so the range is [1, n_max+1], not [0, n_max]. see https://github.com/vllm-project/vllm/blob/b997071ec493765abbed990c65843ed05e4708a8/vllm/v1/spec_decode/metrics.py#L114
mean acc len = 3.0 corresponds to about 2 accepted draft tokens on average, and a total advancement of 3 tokens per target pass.
It is basically the speedup over normal decoding, which only produces 1 token per pass. The bonus token is included because the target always emits one even if every draft gets rejected, so AL = 1 means "no speedup".
That said, it's only a convention. If you think it reads better without the bonus token, I can report it without +1 instead.
There was a problem hiding this comment.
More specifically, the +1 represents the one additional token produced by the target model: a recovered token if some draft token is rejected, or a bonus token if all draft tokens are accepted. So this metric is closer to "tokens advanced per speculative verification step".
For choosing n_max, the per-position acceptance rates are more preferred.
… position (ggml-org#24536) * spec: add spec metrics mean acceptance length and acceptance per pos * fix as suggestion Co-authored-by: Georgi Gerganov <ggerganov@gmail.com> * fix as suggestion Co-authored-by: Georgi Gerganov <ggerganov@gmail.com> * fix as suggestion Co-authored-by: Georgi Gerganov <ggerganov@gmail.com> * fix as suggestions --------- Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
… position (ggml-org#24536) * spec: add spec metrics mean acceptance length and acceptance per pos * fix as suggestion Co-authored-by: Georgi Gerganov <ggerganov@gmail.com> * fix as suggestion Co-authored-by: Georgi Gerganov <ggerganov@gmail.com> * fix as suggestion Co-authored-by: Georgi Gerganov <ggerganov@gmail.com> * fix as suggestions --------- Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
Overview
This PR adds
mean_acceptance_lengthandacceptance_rate_per_positionmetrics for speculative decoding.These metrics make it easier to understand how well a speculative decoding method is performing and help tune speculative decoding parameters such as
--spec-draft-n-maxand--spec-draft-p-min.The implementation follows the same metric definitions used by vLLM's spec metrics:
mean_acceptance_length = 1 + accepted_tokens / draft_verification_stepsacceptance_rate_per_position[i] = accepted_tokens_at_position_i / draft_verification_stepsThis PR reports the metrics in two places:
The per-request metrics show speculative decoding behavior for an individual completion, while the aggregated metrics accumulate results across requests for each speculative decoding implementation, making them useful for long-running performance monitoring and parameter tuning.
Example output from EAGLE3 speculative decoding:
Additional information
Requirements