MCPcopy Create free account
hub / github.com/FreedomIntelligence/CMB / generate_batch

Method generate_batch

workers/base.py:171–192  ·  view source on GitHub ↗

r""" Args: batch (`List[dict]`): a list of raw data. Returns: outputs (`List[str]`): a list of generated output from the model. Usage: runner.generate(prompts)

(self, batch: list)

Source from the content-addressed store, hash-verified

169
170 @torch.no_grad()
171 def generate_batch(self, batch: list):
172 r"""
173 Args:
174 batch (`List[dict]`):
175 a list of raw data.
176 Returns:
177 outputs (`List[str]`):
178 a list of generated output from the model.
179 Usage:
180 runner.generate(prompts)
181 """
182
183 if self.use_qa:
184 batch, lines = self.prompt_wrapper.wrap_conv(batch)
185 else:
186 batch, lines = self.prompt_wrapper.wrap(batch)
187 inputs = self.tokenizer(batch, padding=True, truncation=True, return_tensors="pt").to(self.device)
188 self.prompt_wrapper.lengths = inputs.input_ids.shape[1]
189 outputs = self.unwrap_model().generate( **inputs, **self.generation_config)
190 outputs = self.prompt_wrapper.unwrap(outputs, self.generation_config.get('num_return_sequences', 1))
191
192 return outputs, lines
193
194
195 def get_single_query(self, datum, use_cot):

Callers 1

mainFunction · 0.80

Calls 4

unwrap_modelMethod · 0.95
wrap_convMethod · 0.80
wrapMethod · 0.80
unwrapMethod · 0.80

Tested by

no test coverage detected