MCPcopy Create free account
hub / github.com/MLSysU/TD-Pipe / SequenceData

Class SequenceData

TD_Pipe/sequence.py:51–97  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

49
50
51class 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
100class Sequence:

Callers 2

profile_runMethod · 0.90
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected