MCPcopy Create free account
hub / github.com/boyiwei/alignment-attribution-code / eval_ppl

Function eval_ppl

lib/eval.py:81–96  ·  view source on GitHub ↗
(args, model, tokenizer, device=torch.device("cuda:0"))

Source from the content-addressed store, hash-verified

79
80# Function to evaluate perplexity (ppl) on a specified model and tokenizer
81def eval_ppl(args, model, tokenizer, device=torch.device("cuda:0")):
82 # Set dataset
83 dataset = "wikitext"
84
85 # Print status
86 print(f"evaluating on {dataset}")
87
88 # Get the test loader
89 _, testloader = get_loaders(
90 dataset, seed=0, seqlen=model.seqlen, tokenizer=tokenizer
91 )
92
93 # Evaluate ppl in no grad context to avoid updating the model
94 with torch.no_grad():
95 ppl_test = eval_ppl_wikitext(model, testloader, 1, device)
96 return ppl_test
97
98
99# Function to evaluate perplexity (ppl) specifically on the wikitext dataset

Callers 4

mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90

Calls 2

get_loadersFunction · 0.85
eval_ppl_wikitextFunction · 0.85

Tested by

no test coverage detected