[Feature] Support EAGLE 3 (#4247)
This commit is contained in:
@@ -223,16 +223,18 @@ class LogitsProcessor(nn.Module):
|
||||
hidden_states,
|
||||
lm_head: VocabParallelEmbedding,
|
||||
logits_metadata: Union[LogitsMetadata, ForwardBatch],
|
||||
aux_hidden_states: Optional[torch.Tensor] = None,
|
||||
) -> LogitsProcessorOutput:
|
||||
if isinstance(logits_metadata, ForwardBatch):
|
||||
logits_metadata = LogitsMetadata.from_forward_batch(logits_metadata)
|
||||
|
||||
# Get the last hidden states and last logits for the next token prediction
|
||||
if (
|
||||
logits_metadata.forward_mode.is_decode_or_idle()
|
||||
or logits_metadata.forward_mode.is_target_verify()
|
||||
):
|
||||
pruned_states = hidden_states
|
||||
if aux_hidden_states is not None:
|
||||
aux_pruned_states = [hidden for hidden in aux_hidden_states]
|
||||
sample_indices = None
|
||||
input_logprob_indices = None
|
||||
elif (
|
||||
@@ -256,6 +258,8 @@ class LogitsProcessor(nn.Module):
|
||||
- 1
|
||||
)
|
||||
pruned_states = hidden_states[last_index]
|
||||
if aux_hidden_states is not None:
|
||||
aux_pruned_states = [hidden[last_index] for hidden in aux_hidden_states]
|
||||
sample_indices = None
|
||||
input_logprob_indices = None
|
||||
else:
|
||||
@@ -319,13 +323,27 @@ class LogitsProcessor(nn.Module):
|
||||
hidden_states_to_store: Optional[torch.Tensor] = None
|
||||
if logits_metadata.capture_hidden_mode.need_capture():
|
||||
if logits_metadata.capture_hidden_mode.is_full():
|
||||
hidden_states_to_store = hidden_states
|
||||
if aux_hidden_states is not None:
|
||||
aux_hidden_states = torch.cat(aux_hidden_states, dim=-1)
|
||||
hidden_states_to_store = aux_hidden_states
|
||||
else:
|
||||
hidden_states_to_store = hidden_states
|
||||
elif logits_metadata.capture_hidden_mode.is_last():
|
||||
# Get the last token hidden states. If sample_indices is None,
|
||||
# pruned states only contain the last tokens already.
|
||||
hidden_states_to_store = (
|
||||
pruned_states[sample_indices] if sample_indices else pruned_states
|
||||
)
|
||||
if aux_hidden_states is not None:
|
||||
aux_pruned_states = torch.cat(aux_pruned_states, dim=-1)
|
||||
hidden_states_to_store = (
|
||||
aux_pruned_states[sample_indices]
|
||||
if sample_indices
|
||||
else aux_pruned_states
|
||||
)
|
||||
else:
|
||||
hidden_states_to_store = (
|
||||
pruned_states[sample_indices]
|
||||
if sample_indices
|
||||
else pruned_states
|
||||
)
|
||||
else:
|
||||
assert False, "Should never reach"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user