2023-02-23 03:01:20 +08:00
|
|
|
from typing import List
|
|
|
|
|
|
|
|
|
|
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class InputMetadata:
|
|
|
|
|
|
|
|
|
|
def __init__(
|
|
|
|
|
self,
|
2023-02-23 17:25:01 +08:00
|
|
|
seq_ids: List[int],
|
2023-02-23 03:01:20 +08:00
|
|
|
prompt_lens: List[int],
|
|
|
|
|
slot_mapping: torch.Tensor,
|
|
|
|
|
context_lens: torch.Tensor,
|
|
|
|
|
max_context_len: int,
|
|
|
|
|
block_tables: torch.Tensor,
|
|
|
|
|
) -> None:
|
2023-02-23 17:25:01 +08:00
|
|
|
self.seq_ids = seq_ids
|
2023-02-23 03:01:20 +08:00
|
|
|
self.prompt_lens = prompt_lens
|
2023-02-23 08:10:07 +08:00
|
|
|
self.slot_mapping = slot_mapping
|
2023-02-23 03:01:20 +08:00
|
|
|
self.context_lens = context_lens
|
|
|
|
|
self.max_context_len = max_context_len
|
|
|
|
|
self.block_tables = block_tables
|
|
|
|
|
|
|
|
|
|
self.num_prompts = len(prompt_lens)
|
|
|
|
|
self.num_generation_tokens = context_lens.shape[0]
|
2023-02-24 04:20:33 +08:00
|
|
|
if block_tables.numel() > 0:
|
|
|
|
|
self.max_num_blocks_per_seq = block_tables.shape[1]
|
|
|
|
|
else:
|
|
|
|
|
self.max_num_blocks_per_seq = 0
|
2023-02-23 03:01:20 +08:00
|
|
|
assert self.num_generation_tokens == block_tables.shape[0]
|
2023-02-23 17:25:01 +08:00
|
|
|
assert self.num_prompts + self.num_generation_tokens == len(seq_ids)
|