MCPcopy Create free account
hub / github.com/OpenBitSys/BitDistiller / BaseLM

Class BaseLM

test/general/lm_eval/base.py:121–467  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119
120
121class BaseLM(LM):
122 def __init__(self):
123 super().__init__()
124 self.batch_schedule = 1
125 self.batch_sizes = {}
126 self.max_batch_size = 512
127
128 @property
129 @abstractmethod
130 def eot_token_id(self):
131 pass
132
133 @property
134 @abstractmethod
135 def max_length(self):
136 pass
137
138 @property
139 @abstractmethod
140 def max_gen_toks(self):
141 pass
142
143 @property
144 @abstractmethod
145 def batch_size(self):
146 pass
147
148 @property
149 @abstractmethod
150 def device(self):
151 pass
152
153 @abstractmethod
154 def tok_encode(self, string: str):
155 pass
156
157 @abstractmethod
158 def tok_decode(self, tokens: Iterable[int]):
159 pass
160
161 @abstractmethod
162 def _model_generate(self, context, max_length, eos_token_id):
163 pass
164
165 @abstractmethod
166 def _model_call(self, inps):
167 """
168 inps: a torch tensor of shape [batch, sequence]
169 the size of sequence may vary from call to call
170
171 returns: a torch tensor of shape [batch, sequence, vocab] with the
172 logits returned from the model
173 """
174 pass
175
176 def _detect_batch_size(self, requests=None, pos=0):
177 if requests:
178 _, context_enc, continuation_enc = requests[pos]

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected