mirror of
https://git.datalinker.icu/vllm-project/vllm.git
synced 2025-12-25 20:15:19 +08:00
- **Add SPDX license headers to python source files**
- **Check for SPDX headers using pre-commit**
commit 9d7ef44c3cfb72ca4c32e1c677d99259d10d4745
Author: Russell Bryant <rbryant@redhat.com>
Date: Fri Jan 31 14:18:24 2025 -0500
Add SPDX license headers to python source files
This commit adds SPDX license headers to python source files as
recommended to
the project by the Linux Foundation. These headers provide a concise way
that is
both human and machine readable for communicating license information
for each
source file. It helps avoid any ambiguity about the license of the code
and can
also be easily used by tools to help manage license compliance.
The Linux Foundation runs license scans against the codebase to help
ensure
we are in compliance with the licenses of the code we use, including
dependencies. Having these headers in place helps that tool do its job.
More information can be found on the SPDX site:
- https://spdx.dev/learn/handling-license-info/
Signed-off-by: Russell Bryant <rbryant@redhat.com>
commit 5a1cf1cb3b80759131c73f6a9dddebccac039dea
Author: Russell Bryant <rbryant@redhat.com>
Date: Fri Jan 31 14:36:32 2025 -0500
Check for SPDX headers using pre-commit
Signed-off-by: Russell Bryant <rbryant@redhat.com>
---------
Signed-off-by: Russell Bryant <rbryant@redhat.com>
99 lines
3.0 KiB
Python
99 lines
3.0 KiB
Python
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
from abc import ABC, abstractmethod
|
|
from dataclasses import dataclass
|
|
from typing import List, Optional, Set, Union
|
|
|
|
import torch
|
|
|
|
from vllm.sequence import ExecuteModelRequest, PromptLogprobs
|
|
from vllm.worker.worker_base import WorkerBase
|
|
|
|
|
|
@dataclass
|
|
class SpeculativeProposals:
|
|
"""Datastructure used to represent proposal tokens from some proposer. It
|
|
also tracks how many speculative tokens each sequence has.
|
|
"""
|
|
|
|
# Speculative proposal tokens.
|
|
proposal_token_ids: torch.Tensor
|
|
|
|
# Probabilities of the proposal tokens according to the proposer.
|
|
proposal_probs: torch.Tensor
|
|
|
|
# The valid length of each proposal; can be zero.
|
|
proposal_lens: torch.Tensor
|
|
|
|
# A flag to mark that there's no available proposals
|
|
no_proposals: bool = False
|
|
|
|
def __repr__(self):
|
|
return (f"SpeculativeProposals("
|
|
f"proposal_token_ids={self.proposal_token_ids}, "
|
|
f"proposal_probs={self.proposal_probs.shape}, "
|
|
f"proposal_lens={self.proposal_lens})")
|
|
|
|
|
|
@dataclass
|
|
class SpeculativeScores:
|
|
"""Datastructure used to represent the scores of speculative tokens
|
|
according to the scoring model.
|
|
"""
|
|
|
|
# Probabilities of the speculative tokens according to the scoring model.
|
|
probs: torch.Tensor
|
|
|
|
# Log-probabilities of the speculative tokens according to the scoring
|
|
# model. These values can be used to generate Logprob objects that are
|
|
# returned to the user.
|
|
logprobs: torch.Tensor
|
|
|
|
# Token ids sampled from the scoring model. Used for speculative bonus
|
|
# tokens and also non-speculative normal decoding.
|
|
token_ids: torch.Tensor
|
|
|
|
# Optional last hidden states from the scoring model.
|
|
hidden_states: Optional[torch.Tensor] = None
|
|
|
|
# Scoring model may also return logprobs for prompt tokens
|
|
# for each request, when chunked prefill is enabled.
|
|
prompt_logprobs: Optional[List[PromptLogprobs]] = None
|
|
|
|
def __repr__(self):
|
|
return (f"SpeculativeScores("
|
|
f"probs={self.probs.shape}, "
|
|
f"token_ids={self.token_ids.shape})")
|
|
|
|
|
|
class SpeculativeProposer(ABC):
|
|
|
|
@abstractmethod
|
|
def get_spec_proposals(
|
|
self,
|
|
execute_model_req: ExecuteModelRequest,
|
|
# If set, this contains all sequence IDs that were assigned
|
|
# bonus tokens in their last forward pass.
|
|
seq_ids_with_bonus_token_in_last_step: Set[int],
|
|
) -> SpeculativeProposals:
|
|
raise NotImplementedError
|
|
|
|
|
|
class SpeculativeScorer(ABC):
|
|
|
|
def __init__(self, scorer_worker: WorkerBase,
|
|
device: Union[torch.device, str], vocab_size: int):
|
|
self._scorer_worker = scorer_worker
|
|
if isinstance(device, torch.device):
|
|
device = device.type
|
|
self._device = device
|
|
self._vocab_size = vocab_size
|
|
|
|
@abstractmethod
|
|
def score_proposals(
|
|
self,
|
|
execute_model_req: ExecuteModelRequest,
|
|
proposals: SpeculativeProposals,
|
|
) -> SpeculativeScores:
|
|
raise NotImplementedError
|