metadata.py 963 Bytes
Newer Older
1
2
# SPDX-License-Identifier: Apache-2.0

3
from dataclasses import dataclass
4
from typing import Dict, List, Optional, Set, Tuple
5
6
7
8
9
10
11
12
13
14
15

import torch


@dataclass
class SamplingMetadata:

    temperature: torch.Tensor
    all_greedy: bool
    all_random: bool

16
17
18
19
20
21
    # None when there are no speculated tokens.
    spec_token_ids: Optional[List[List[int]]]

    top_p: Optional[torch.Tensor]
    top_k: Optional[torch.Tensor]
    min_p: Optional[torch.Tensor]
22

23
    generators: Dict[int, torch.Generator]
24

25
26
    # None means no logprobs, 0 means sampled token logprobs only
    max_num_logprobs: Optional[int]
27
28
29
30
31
32
33
34

    no_penalties: bool
    prompt_token_ids: Optional[torch.Tensor]
    frequency_penalties: torch.Tensor
    presence_penalties: torch.Tensor
    repetition_penalties: torch.Tensor

    output_token_ids: List[List[int]]
35
36
37

    # req_index -> (min_tokens, stop_token_ids)
    min_tokens: Dict[int, Tuple[int, Set[int]]]
38
39

    logit_bias: List[Optional[Dict[int, float]]]