-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
[Speculative decoding] Add periodic log with time spent in proposal/scoring/verification #6963
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
894ea25
spec timers
cadedaniel f1f993c
lint
cadedaniel a0fd134
PR feedback
cadedaniel 09878a6
comment
cadedaniel 7469d02
disable log stats
cadedaniel e691674
fix
cadedaniel d81b8e6
Merge remote-tracking branch 'origin/main' into spec-timers
cadedaniel 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 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import time | ||
from collections import defaultdict | ||
from functools import cached_property | ||
from typing import Any, Dict, List, Optional, Set, Tuple | ||
|
@@ -522,28 +523,37 @@ def _run_speculative_decoding_step( | |
execute_model_req.previous_hidden_states = self.previous_hidden_states | ||
self.previous_hidden_states = None | ||
|
||
# Generate proposals using draft worker. | ||
proposals = self.proposer_worker.get_spec_proposals( | ||
execute_model_req, self._seq_with_bonus_token_in_last_step) | ||
with Timer() as proposal_timer: | ||
# Generate proposals using draft worker. | ||
proposals = self.proposer_worker.get_spec_proposals( | ||
execute_model_req, self._seq_with_bonus_token_in_last_step) | ||
|
||
if not self._allow_zero_draft_token_step and proposals.no_proposals: | ||
#TODO: Fix it #5814 | ||
raise RuntimeError("Cannot handle cases where distributed draft " | ||
"workers generate no tokens") | ||
|
||
proposal_scores = self.scorer.score_proposals( | ||
execute_model_req, | ||
proposals, | ||
) | ||
accepted_token_ids, target_logprobs = self._verify_tokens( | ||
execute_model_req.seq_group_metadata_list, proposal_scores, | ||
proposals, execute_model_req.num_lookahead_slots) | ||
with Timer() as scoring_timer: | ||
proposal_scores = self.scorer.score_proposals( | ||
execute_model_req, | ||
proposals, | ||
) | ||
|
||
with Timer() as verification_timer: | ||
accepted_token_ids, target_logprobs = self._verify_tokens( | ||
execute_model_req.seq_group_metadata_list, proposal_scores, | ||
proposals, execute_model_req.num_lookahead_slots) | ||
|
||
stage_times = (proposal_timer.elapsed_time_ms / num_lookahead_slots, | ||
scoring_timer.elapsed_time_ms, | ||
verification_timer.elapsed_time_ms) | ||
|
||
return self._create_output_sampler_list( | ||
execute_model_req.seq_group_metadata_list, | ||
accepted_token_ids, | ||
target_logprobs=target_logprobs, | ||
k=execute_model_req.num_lookahead_slots) | ||
k=execute_model_req.num_lookahead_slots, | ||
stage_times=stage_times) | ||
|
||
@nvtx_range("spec_decode_worker._verify_tokens") | ||
def _verify_tokens( | ||
|
@@ -648,6 +658,7 @@ def _create_output_sampler_list( | |
accepted_token_ids: torch.Tensor, # shape: [batch_size, k+1] | ||
target_logprobs: torch.Tensor, # shape: [batch_size, k+1, vocab_size] | ||
k: int, | ||
stage_times: Tuple[float, float, float], | ||
) -> List[SamplerOutput]: | ||
"""Given the accepted token ids, create a list of SamplerOutput. | ||
|
||
|
@@ -725,6 +736,15 @@ def _create_output_sampler_list( | |
if maybe_rejsample_metrics is not None: | ||
sampler_output_list[ | ||
0].spec_decode_worker_metrics = maybe_rejsample_metrics | ||
|
||
(average_time_per_proposal_tok_ms, scoring_time_ms, | ||
verification_time_ms) = stage_times | ||
logger.info( | ||
"SpecDecodeWorker stage times: " | ||
"average_time_per_proposal_tok_ms=%.02f " | ||
"scoring_time_ms=%.02f verification_time_ms=%.02f", | ||
average_time_per_proposal_tok_ms, scoring_time_ms, | ||
verification_time_ms) | ||
return sampler_output_list | ||
|
||
def _create_dummy_logprob_lists( | ||
|
@@ -912,3 +932,15 @@ def split_num_cache_blocks_evenly(scorer_cache_block_size_bytes: int, | |
(proposer_cache_block_size_bytes + scorer_cache_block_size_bytes)) | ||
|
||
return new_num_gpu_blocks | ||
|
||
|
||
class Timer: | ||
|
||
def __enter__(self): | ||
self.start_time = time.time() | ||
return self | ||
|
||
def __exit__(self, exc_type, exc_value, traceback): | ||
self.end_time = time.time() | ||
self.elapsed_time_s = self.end_time - self.start_time | ||
self.elapsed_time_ms = self.elapsed_time_s * 1000 | ||
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. Put it in a more common space like utils? 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. ack |
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.
It looks like we will print this log every step? Did I miss something?
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.
only when rejection sampler emits metrics, which is every 5s
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.
I'll add comment