MCPcopy Create free account
hub / github.com/OpenMOSS/MOSS / StopWordsCriteria

Class StopWordsCriteria

utils.py:5–15  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3
4
5class 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

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected