nb_candidates=opt_.hits_at_nb_cands)
        valid_data = env.build_valid_dataloader(True)
        test_data = env.build_valid_dataloader(True, test=True)
        with torch.no_grad():
            logging.info("Validating on the valid set -shuffle")
            validate(0,
                     net,
                     valid_data,
                     is_test=False,
                     nb_candidates=opt_.hits_at_nb_cands)
            logging.info("Validating on the hidden test set -shuffle")
            validate(0,
                     net,
                     test_data,
                     is_test=True,
                     nb_candidates=opt_.hits_at_nb_cands)
    else:
        train_model(opt_)


if __name__ == "__main__":
    opt = get_opt()
    # Set random state
    torch.manual_seed(opt.random_seed)
    opt.cuda = opt.cuda and torch.cuda.is_available()
    if opt.cuda:
        torch.cuda.manual_seed(opt.random_seed)
    # Set logging
    logger = get_logger(opt)
    main(opt)
Exemplo n.º 2
0
    "--task",
    type=str,
    choices=["dailydialog", "empchat", "reddit"],
    default="empchat",
    help="Dataset for context/target-response pairs",
)
args = parser.parse_args()
args.cuda = not args.no_cuda and torch.cuda.is_available()
if args.cuda:
    torch.cuda.set_device(args.gpu)
    logger.info(f"CUDA enabled (GPU {args.gpu:d})")
else:
    logger.info("Running on CPU only.")
if args.fasttext is not None:
    args.max_cand_length += args.fasttext
net, net_dictionary = load_model(args.model, get_opt(existing_opt=args))
if "bert_tokenizer" in net_dictionary:
    if args.task == "dailydialog":
        raise NotImplementedError(
            "BERT model currently incompatible with DailyDialog!")
if args.bleu_dict is not None:
    _, bleu_dictionary = load_model(args.bleu_dict, get_opt(existing_opt=args))
else:
    bleu_dictionary = net_dictionary
paramnum = 0
trainable = 0
for parameter in net.parameters():
    if parameter.requires_grad:
        trainable += parameter.numel()
    paramnum += parameter.numel()
print(paramnum, trainable)