Trim the answer to end it on an eos token.
(prompt_len, tokens)
| 288 | stats.end_phase(tokens=niter * bs) |
| 289 | |
| 290 | def trim_answer(prompt_len, tokens): |
| 291 | # print(prompt, tokens) |
| 292 | """Trim the answer to end it on an eos token.""" |
| 293 | tokens = tokens[: max_seq_length - prompt_len] |
| 294 | eos_id = self.tokenizer.eot_id |
| 295 | if eos_id in tokens: |
| 296 | return tokens[: tokens.index(eos_id) + 1] |
| 297 | else: |
| 298 | return tokens |
| 299 | |
| 300 | answers = [ |
| 301 | trim_answer(prompt_len, answer) |
nothing calls this directly
no outgoing calls
no test coverage detected