Generate results given a list of inputs. Args: inputs (List[str]): A list of strings. max_out_len (int): The maximum length of the output. Returns: List[str]: A list of generated strings.
(self,
inputs: List[str],
max_out_len: int,
min_out_len: Optional[int] = None,
stopping_criteria: List[str] = [])
| 318 | return len(tokens) |
| 319 | |
| 320 | def generate(self, |
| 321 | inputs: List[str], |
| 322 | max_out_len: int, |
| 323 | min_out_len: Optional[int] = None, |
| 324 | stopping_criteria: List[str] = []) -> List[str]: |
| 325 | """Generate results given a list of inputs. |
| 326 | |
| 327 | Args: |
| 328 | inputs (List[str]): A list of strings. |
| 329 | max_out_len (int): The maximum length of the output. |
| 330 | |
| 331 | Returns: |
| 332 | List[str]: A list of generated strings. |
| 333 | """ |
| 334 | if min_out_len is None: |
| 335 | # keep same with InternTrain's default value |
| 336 | min_out_len = 1 |
| 337 | |
| 338 | if self.mode == 'none': |
| 339 | tokens = self.batch_encode(inputs, |
| 340 | self.max_seq_len, |
| 341 | left_padding=True) |
| 342 | else: |
| 343 | tokens = self.batch_encode(inputs, |
| 344 | self.max_seq_len - max_out_len, |
| 345 | left_padding=True) |
| 346 | |
| 347 | # random seed for pass@k |
| 348 | seed = torch.tensor(time.time(), dtype=torch.int64).cuda() |
| 349 | |
| 350 | dist.broadcast(seed, src=0) |
| 351 | torch.cuda.manual_seed(seed.item()) |
| 352 | dist.barrier() |
| 353 | outputs = self.generator.generate( |
| 354 | tokens, |
| 355 | max_length=tokens.shape[1] + max_out_len, |
| 356 | **self.generation_kwargs) # bsz, num_return_sequences, max_length |
| 357 | outputs = outputs[:, 0, tokens.shape[1]:] |
| 358 | output_text = self.batch_decode( |
| 359 | outputs, |
| 360 | eos_token_ids=self.generator.eos_token_id, |
| 361 | stopping_criteria=stopping_criteria) # gitleaks:allow |
| 362 | |
| 363 | return output_text |
| 364 | |
| 365 | def get_ppl(self, |
| 366 | input_texts: List[str], |
nothing calls this directly
no test coverage detected