"""Sign-aware token repetition penalty, excluding document-control token IDs.""" import math import torch def penalize_repetition(logits,token_ids,penalty=1.1,first_text_id=6): if not math.isfinite(penalty) or penalty<1:raise ValueError('repetition penalty must be finite and >= 1') if penalty==1:return logits seen=sorted({n for n in token_ids if first_text_id<=n