Text Generation
PyTorch
Polish
English
polish
causal-lm
pretraining
continued-pretraining
Eval Results (legacy)
kacperwikiel's picture
Add self-contained base-model CPT, SFT, RL and checkpoint averaging notebook tutorials
5f92b4e verified
Raw History Blame Contribute Delete
632 Bytes
"""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<logits.shape[-1]})
if not seen:return logits
ids=torch.tensor(seen,device=logits.device,dtype=torch.long)
values=logits.index_select(-1,ids)
logits.index_copy_(-1,ids,torch.where(values<0,values*penalty,values/penalty))
return logits