| 3 | |
| 4 | |
| 5 | class StopWordsCriteria(StoppingCriteria): |
| 6 | |
| 7 | def __init__(self, stop_indices: list): |
| 8 | self.stop_indices = stop_indices |
| 9 | |
| 10 | def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor, **kwargs) -> bool: |
| 11 | # do not support batch inference |
| 12 | for i in range(len(self.stop_indices)): |
| 13 | if self.stop_indices[-1-i] != input_ids[0][-1-i]: |
| 14 | return False |
| 15 | return True |
no outgoing calls
no test coverage detected