Export NaNs in logits to scheduler_stats if output is corrupted (#18777)
Signed-off-by: Vlad Mihailescu <vtmihailescu@gmail.com>
This commit is contained in:
@@ -1431,6 +1431,10 @@ class GPUModelRunner(LoRAModelRunnerMixin):
|
||||
)
|
||||
sampler_output.sampled_token_ids = output_token_ids
|
||||
|
||||
num_nans_in_logits = {}
|
||||
if envs.VLLM_COMPUTE_NANS_IN_LOGITS:
|
||||
num_nans_in_logits = self._get_nans_in_logits(logits)
|
||||
|
||||
# TODO(woosuk): The following loop can be slow since it iterates over
|
||||
# the requests one by one. Optimize.
|
||||
discard_sampled_tokens_req_indices = []
|
||||
@@ -1601,6 +1605,7 @@ class GPUModelRunner(LoRAModelRunnerMixin):
|
||||
pooler_output=[],
|
||||
finished_sending=finished_sending,
|
||||
finished_recving=finished_recving,
|
||||
num_nans_in_logits=num_nans_in_logits,
|
||||
)
|
||||
|
||||
def kv_connector_no_forward(
|
||||
@@ -1826,6 +1831,26 @@ class GPUModelRunner(LoRAModelRunnerMixin):
|
||||
|
||||
return prompt_logprobs_dict
|
||||
|
||||
def _get_nans_in_logits(
|
||||
self,
|
||||
logits: Optional[torch.Tensor],
|
||||
) -> dict[str, int]:
|
||||
try:
|
||||
if logits is None:
|
||||
return {req_id: 0 for req_id in self.input_batch.req_ids}
|
||||
|
||||
num_nans_in_logits = {}
|
||||
num_nans_for_index = logits.isnan().sum(dim=-1).cpu().numpy()
|
||||
for req_id in self.input_batch.req_ids:
|
||||
req_index = self.input_batch.req_id_to_index[req_id]
|
||||
num_nans_in_logits[req_id] = (
|
||||
int(num_nans_for_index[req_index])
|
||||
if num_nans_for_index is not None
|
||||
and req_index < logits.shape[0] else 0)
|
||||
return num_nans_in_logits
|
||||
except IndexError:
|
||||
return {}
|
||||
|
||||
@contextmanager
|
||||
def maybe_randomize_inputs(self, input_ids: torch.Tensor):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user