Data associated with a sequence. Args: prompt_token_ids: The token IDs of the prompt. Attributes: prompt_token_ids: The token IDs of the prompt. output_token_ids: The token IDs of the output. cumulative_logprob: The cumulative log probability of the output.
| 49 | |
| 50 | |
| 51 | class SequenceData: |
| 52 | """Data associated with a sequence. |
| 53 | |
| 54 | |
| 55 | Args: |
| 56 | prompt_token_ids: The token IDs of the prompt. |
| 57 | |
| 58 | Attributes: |
| 59 | prompt_token_ids: The token IDs of the prompt. |
| 60 | output_token_ids: The token IDs of the output. |
| 61 | cumulative_logprob: The cumulative log probability of the output. |
| 62 | """ |
| 63 | |
| 64 | def __init__( |
| 65 | self, |
| 66 | prompt_token_ids: List[int], |
| 67 | ) -> None: |
| 68 | self.prompt_token_ids = prompt_token_ids |
| 69 | self.output_token_ids: List[int] = [] |
| 70 | self.cumulative_logprob = 0.0 |
| 71 | |
| 72 | def append_token_id(self, token_id: int, logprob: float) -> None: |
| 73 | self.output_token_ids.append(token_id) |
| 74 | self.cumulative_logprob += logprob |
| 75 | |
| 76 | def get_len(self) -> int: |
| 77 | return len(self.output_token_ids) + len(self.prompt_token_ids) |
| 78 | |
| 79 | def get_prompt_len(self) -> int: |
| 80 | return len(self.prompt_token_ids) |
| 81 | |
| 82 | def get_output_len(self) -> int: |
| 83 | return len(self.output_token_ids) |
| 84 | |
| 85 | def get_token_ids(self) -> List[int]: |
| 86 | return self.prompt_token_ids + self.output_token_ids |
| 87 | |
| 88 | def get_last_token_id(self) -> int: |
| 89 | if not self.output_token_ids: |
| 90 | return self.prompt_token_ids[-1] |
| 91 | return self.output_token_ids[-1] |
| 92 | |
| 93 | def __repr__(self) -> str: |
| 94 | return (f"SequenceData(" |
| 95 | f"prompt_token_ids={self.prompt_token_ids}, " |
| 96 | f"output_token_ids={self.output_token_ids}, " |
| 97 | f"cumulative_logprob={self.cumulative_logprob})") |
| 98 | |
| 99 | |
| 100 | class Sequence: |
no outgoing calls
no test coverage detected