MCPcopy
hub / github.com/NVIDIA/TensorRT-LLM / ppl

Function ppl

tensorrt_llm/tools/ppl.py:1–7  ·  view source on GitHub ↗

Calculate per-token perplexity.

(logits, output_ids)

Source from the content-addressed store, hash-verified

1def ppl(logits, output_ids):
2 """
3 Calculate per-token perplexity.
4 """
5 nlls = -logits.log_softmax(dim=-1)
6 ppls = nlls.gather(-1, output_ids.long().unsqueeze(-1))
7 return ppls.mean().exp().item()

Callers 2

eval_trt_llmFunction · 0.90
eval_hfFunction · 0.90

Calls 2

unsqueezeMethod · 0.80
meanMethod · 0.80

Tested by

no test coverage detected