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)
| 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): |
no test coverage detected