[MRV2][Spec Decode] Avoid rejection sampler OOM by chunking (#48630)
Signed-off-by: mgoin <mgoin64@gmail.com> Signed-off-by: Michael Goin <mgoin64@gmail.com> Co-authored-by: Nick Hill <nickhill123@gmail.com>
This commit is contained in:
co-authored by
Nick Hill
parent
521aa80f71
commit
ac36a7a1e7
@@ -2,6 +2,7 @@
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from collections.abc import Sequence
|
||||
from copy import copy
|
||||
from dataclasses import dataclass, field
|
||||
from typing import TYPE_CHECKING, NamedTuple, TypeAlias
|
||||
@@ -90,6 +91,32 @@ class LogprobsTensors(NamedTuple):
|
||||
self.selected_token_ranks[mask],
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def cat(
|
||||
tensors: Sequence["LogprobsTensors"],
|
||||
cu_num_generated_tokens: list[int] | None = None,
|
||||
) -> "LogprobsTensors":
|
||||
"""Concatenate flattened logprob tensors."""
|
||||
assert tensors
|
||||
assert cu_num_generated_tokens is not None or all(
|
||||
tensor.cu_num_generated_tokens is None for tensor in tensors
|
||||
)
|
||||
if len(tensors) == 1:
|
||||
tensor = tensors[0]
|
||||
if cu_num_generated_tokens is None:
|
||||
return tensor
|
||||
return tensor._replace(cu_num_generated_tokens=cu_num_generated_tokens)
|
||||
return LogprobsTensors(
|
||||
logprob_token_ids=torch.cat(
|
||||
[tensor.logprob_token_ids for tensor in tensors]
|
||||
),
|
||||
logprobs=torch.cat([tensor.logprobs for tensor in tensors]),
|
||||
selected_token_ranks=torch.cat(
|
||||
[tensor.selected_token_ranks for tensor in tensors]
|
||||
),
|
||||
cu_num_generated_tokens=cu_num_generated_tokens,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def empty_cpu(
|
||||
num_positions: int, num_tokens_per_position: int
|
||||
|
||||
Reference in New Issue
Block a user