(model, eval_dataloader)
| 491 | |
| 492 | |
| 493 | def evaluation(model, eval_dataloader): |
| 494 | model.eval() |
| 495 | losses = 0 |
| 496 | for step, batch in enumerate(eval_dataloader): |
| 497 | # implementation, batch = {k: v.to(device) for k, v in batch.items()} |
| 498 | del batch['sources'] |
| 499 | batch = to_device(batch, device) |
| 500 | with torch.no_grad(): |
| 501 | # check output |
| 502 | outputs = model(**batch) |
| 503 | |
| 504 | loss = outputs.loss |
| 505 | losses += loss.float() |
| 506 | losses = losses / (step + 1) |
| 507 | try: |
| 508 | perplexity = torch.exp(losses) |
| 509 | except OverflowError: |
| 510 | perplexity = float("inf") |
| 511 | try: |
| 512 | perplexity = get_all_reduce_mean(perplexity).item() |
| 513 | except: |
| 514 | pass |
| 515 | return perplexity |
| 516 | |
| 517 | def get_optimizer(model): |
| 518 | # Split weights in two groups, one with weight decay and the other not. |
nothing calls this directly
no test coverage detected