(args, model, tokenizer, device=torch.device("cuda:0"))
| 79 | |
| 80 | # Function to evaluate perplexity (ppl) on a specified model and tokenizer |
| 81 | def 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 |
no test coverage detected