mirror of
https://github.com/NVIDIA/TensorRT-LLM.git
synced 2026-01-13 22:18:36 +08:00
* Update TensorRT-LLM --------- Co-authored-by: wangruohui <12756472+wangruohui@users.noreply.github.com>
8 lines
216 B
Python
8 lines
216 B
Python
def ppl(logits, output_ids):
|
|
"""
|
|
Calculate per-token perplexity.
|
|
"""
|
|
nlls = -logits.log_softmax(dim=-1)
|
|
ppls = nlls.gather(-1, output_ids.long().unsqueeze(-1))
|
|
return ppls.mean().exp().item()
|