MCPcopy Create free account
hub / github.com/ZinYY/TreeLoRA / perplexity_evaluation

Method perplexity_evaluation

model/base_model.py:40–60  ·  view source on GitHub ↗
(self, eval_dataloader, device)

Source from the content-addressed store, hash-verified

38
39
40 def perplexity_evaluation(self, eval_dataloader, device):
41 self.model.eval()
42 losses = 0
43 for step, batch in enumerate(eval_dataloader):
44 # implementation, batch = {k: v.to(device) for k, v in batch.items()}
45 del batch['sources']
46 batch = to_device(batch, device)
47 with torch.no_grad():
48 outputs = self.model(**batch, use_cache=False)
49 loss = outputs.loss
50 losses += loss.float()
51 losses = losses / (step + 1)
52 try:
53 perplexity = torch.exp(losses)
54 except OverflowError:
55 perplexity = float("inf")
56 try:
57 perplexity = get_all_reduce_mean(perplexity).item()
58 except:
59 pass
60 return perplexity
61
62
63 def train_one_task(self, task, i_task, epochs):

Callers

nothing calls this directly

Calls 3

to_deviceFunction · 0.90
get_all_reduce_meanFunction · 0.90
evalMethod · 0.80

Tested by

no test coverage detected