(model, epoch, output_predictions=False)
| 42 | dataloaders.append((dataset.dataset_name, dataloader)) |
| 43 | |
| 44 | def metrics_func(model, epoch, output_predictions=False): |
| 45 | print_rank_0('calculating metrics ...') |
| 46 | correct = 0 |
| 47 | total = 0 |
| 48 | if output_predictions: |
| 49 | assert mpu.get_data_parallel_world_size() == 1 |
| 50 | named_predictions = [] |
| 51 | names = 'predictions' |
| 52 | for name, dataloader in dataloaders: |
| 53 | output = calculate_correct_answers(name, model, dataloader, |
| 54 | epoch, output_predictions) |
| 55 | if not output_predictions: |
| 56 | correct_ans, total_count = output |
| 57 | else: |
| 58 | correct_ans, total_count, predictions = output |
| 59 | named_predictions.append((name, predictions)) |
| 60 | names += '_' + name |
| 61 | correct += correct_ans |
| 62 | total += total_count |
| 63 | percent = float(correct) * 100.0 / float(total) |
| 64 | print_rank_0(' >> |epoch: {}| overall: correct / total = {} / {} = ' |
| 65 | '{:.4f} %'.format(epoch, correct, total, percent)) |
| 66 | |
| 67 | if output_predictions and torch.distributed.get_rank() == 0: |
| 68 | assert args.load is not None |
| 69 | filename = os.path.join(args.load, names + '.pt') |
| 70 | torch.save(named_predictions, filename) |
| 71 | |
| 72 | return metrics_func |
| 73 |
nothing calls this directly
no test coverage detected