MCPcopy Create free account
hub / github.com/InternScience/SciReason / batch_decode

Method batch_decode

opencompass/models/interntrain.py:480–500  ·  view source on GitHub ↗
(self,
                     outputs,
                     eos_token_ids: List[int],
                     stopping_criteria: List[str] = [])

Source from the content-addressed store, hash-verified

478 return torch.LongTensor(tokens).cuda()
479
480 def batch_decode(self,
481 outputs,
482 eos_token_ids: List[int],
483 stopping_criteria: List[str] = []):
484 # outputs: bsz, seq_len
485 output_text = []
486 outputs = outputs.tolist()
487 for output in outputs:
488 # cut off by eos_token_ids
489 eos_idx = len(output)
490 for eos_id in eos_token_ids:
491 if eos_id in output:
492 eos_idx = min(output.index(eos_id), eos_idx)
493 text = self.tokenizer.decode(output[:eos_idx])
494 if self.end_str is not None:
495 text = text.split(self.end_str)[0]
496 for stop_word in stopping_criteria:
497 text = text.split(stop_word)[0]
498 output_text.append(text)
499
500 return output_text

Callers 8

generateMethod · 0.95
forwardMethod · 0.80
__call__Method · 0.80
generateMethod · 0.80
generateMethod · 0.80
__call__Method · 0.80
_batch_generateMethod · 0.80
_single_generateMethod · 0.80

Calls 1

decodeMethod · 0.80

Tested by

no test coverage detected