grad_norm_clip_type=args.grad_norm_clip_type, annotate=args.annotate, device_idxs=device_idx, gpu_memory_limit=args.gpu_memory_limit) if len(args.retrain_model) != 0: trainer.retrain_model(retrain_model=args.retrain_model, processed_steps=args.processed_steps) try: trainer.run() print('Logging stats to file ... ') stats.log_to_file('*' * 80) except KeyboardInterrupt: print('Keyboard interrupted. Logging stats to file ... ') finally: stats.train_stats_to_file() stats.valid_stats_to_file() if args.eval_type == 'acc': sorted_values = sorted(stats.valid_acc.items(), key=lambda d: d[1], reverse=True) elif args.eval_type == 'xent': sorted_values = sorted(stats.valid_loss.items(), key=lambda d: d[1]) else: sorted_values = sorted(stats.valid_bleu.items(), key=lambda d: d[1], reverse=True) stats.log_to_file('Model performances (%s): ' % args.eval_type) print('Model performances (%s): ' % args.eval_type)