MCPcopy
hub / github.com/zai-org/CogView / evaluate

Function evaluate

pretrain_gpt2.py:569–607  ·  view source on GitHub ↗

Evaluation.

(data_iterator, model, args, timers, verbose=False)

Source from the content-addressed store, hash-verified

567
568
569def evaluate(data_iterator, model, args, timers, verbose=False):
570 """Evaluation."""
571
572 # Turn on evaluation mode which disables dropout.
573 model.eval()
574 is_sparse_raw = args.is_sparse
575 args.is_sparse = 0
576
577 total_lm_loss = 0
578 mems = []
579 with torch.no_grad():
580 iteration = 0
581 while iteration < args.eval_iters:
582 iteration += 1
583 if verbose and iteration % args.log_interval == 0:
584 print_rank_0('Evaluating iter {}/{}'.format(iteration, args.eval_iters))
585 # Forward evaluation.
586 lm_loss, mems, img_loss, txt_loss = forward_step(data_iterator, model, args, timers, mems=mems)
587
588 ''&#x27;when contiguous memory optimizations are enabled, the buffers
589 allocated by the optimizations are deallocated during backward pass
590 in the absence of backward pass the buffers should be reset after each
591 forward pass''&#x27;
592 if args.deepspeed and args.deepspeed_activation_checkpointing:
593 deepspeed.checkpointing.reset()
594
595 # Reduce across processes.
596 if isinstance(model, DDP):
597 torch.distributed.all_reduce(lm_loss.data)
598 lm_loss.data = lm_loss.data / args.world_size
599
600 total_lm_loss += lm_loss.data.detach().float().item()
601
602 # Move model back to the train mode.
603 model.train()
604 args.is_sparse = is_sparse_raw
605
606 total_lm_loss /= args.eval_iters
607 return total_lm_loss
608
609
610def evaluate_and_print_results(prefix, data_iterator, model,

Callers 1

Calls 3

print_rank_0Function · 0.90
forward_stepFunction · 0.85
resetMethod · 0.45

Tested by

no test coverage detected