# Perplexity Calculation in run\_clm.py

**URL:** <https://discuss.huggingface.co/t/perplexity-calculation-in-run-clm-py/88163>\
**Category:** 🤗Transformers\
**Created:** [May 23, 2024, 11:32pm UTC](https://discuss.huggingface.co/t/perplexity-calculation-in-run-clm-py/88163 "2024-05-23T23:32:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nghosh](https://avatars.discourse-cdn.com/v4/letter/n/d07c76/32.png) [@nghosh](https://discuss.huggingface.co/u/nghosh)\
**Post date:** [May 23, 2024, 11:32pm UTC](https://discuss.huggingface.co/t/perplexity-calculation-in-run-clm-py/88163/1 "2024-05-23T23:32:40Z")

</div>

I am trying to evaluate the perplexity of a model on WikiText-2.

The three code sources I am using are:

1. [GitHub - yxli2123/LoftQ](https://github.com/yxli2123/LoftQ)
2. [GitHub - horseee/LLM-Pruner: [NeurIPS 2023] LLM-Pruner: On the Structural Pruning of Large Language Models. Support LLaMA, Llama-2, BLOOM, Vicuna, Baichuan, etc.](https://github.com/horseee/LLM-Pruner)
3. [GitHub - locuslab/wanda: A simple and effective LLM pruning approach.](https://github.com/locuslab/wanda)

2 and 3 agree, but 1 which is based on the run\_clm.py script from [transformers/examples/pytorch/language-modeling/run\_clm.py at main · huggingface/transformers · GitHub](https://github.com/huggingface/transformers/blob/main/examples/pytorch/language-modeling/run_clm.py) seems to be significantly different.

For example, when evaluation Llama-2 13b I get the following respective perplexities (using seq\_length 1024)

1. 12.02
2. 5.43
3. 5.43

Does anyone know why the value obtained from 1. is significantly different from the other values?
