MCPcopy Create free account
hub / github.com/AIS-SNU/Smart-Infinity / evaluate

Function evaluate

DeepSpeedExample/megatron/training.py:575–611  ·  view source on GitHub ↗

Evaluation.

(forward_step_func, data_iterator, model, verbose=False)

Source from the content-addressed store, hash-verified

573
574
575def evaluate(forward_step_func, data_iterator, model, verbose=False):
576 """Evaluation."""
577 args = get_args()
578
579 # Turn on evaluation mode which disables dropout.
580 model.eval()
581
582 total_loss_dict = {}
583
584 with torch.no_grad():
585 iteration = 0
586 while iteration < args.eval_iters:
587 iteration += 1
588 if verbose and iteration % args.log_interval == 0:
589 print_rank_0('Evaluating iter {}/{}'.format(iteration,
590 args.eval_iters))
591 # Forward evaluation.
592 _, loss_dict = forward_step_func(data_iterator, model)
593
594 # When contiguous memory optimizations are enabled, the buffers
595 # allocated by the optimizations are deallocated during backward pass
596 # in the absence of backward pass the buffers should be reset after each
597 # forward pass
598 if args.deepspeed and args.deepspeed_activation_checkpointing:
599 deepspeed.checkpointing.reset()
600
601 # Reduce across processes.
602 for key in loss_dict:
603 total_loss_dict[key] = total_loss_dict.get(key, 0.) + \
604 loss_dict[key]
605 # Move model back to the train mode.
606 model.train()
607
608 for key in total_loss_dict:
609 total_loss_dict[key] /= args.eval_iters
610
611 return total_loss_dict
612
613
614def evaluate_and_print_results(prefix, forward_step_func,

Callers 1

Calls 6

get_argsFunction · 0.90
print_rank_0Function · 0.90
evalMethod · 0.45
resetMethod · 0.45
getMethod · 0.45
trainMethod · 0.45

Tested by

no test coverage detected