implement stream generating

This commit is contained in:
hiyouga
2023-06-05 16:43:44 +08:00
parent 44298c1235
commit fe1d930816
3 changed files with 32 additions and 22 deletions

View File

@@ -52,13 +52,12 @@ class AverageMeter:
# Avoid runtime error in model.generate(do_sample=True).
# Borrowed from: https://huggingface.co/THUDM/chatglm-6b/blob/658202d88ac4bb782b99e99ac3adff58b4d0b813/modeling_chatglm.py#L54
class InvalidScoreLogitsProcessor(LogitsProcessor):
def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor) -> torch.FloatTensor:
if torch.isnan(scores).any() or torch.isinf(scores).any():
scores.zero_()
scores[..., 5] = 5e4
scores[:, 0] = 1.0
return scores