def evaluate(data_source):
    model.eval()
    with torch.no_grad():
        total_loss = 0
        hidden = model.init_hidden(eval_batch_size)
        eff_history_mode = ((args.seq_len > args.horizon) and (not args.repack))
        if eff_history_mode:
            validseqlen = (args.seq_len - args.horizon)
            seq_len = args.seq_len
        else:
            validseqlen = args.horizon
            seq_len = args.horizon
        processed_data_size = 0
        for i in range(0, (data_source.size(0) - 1), validseqlen):
            eff_history = (args.horizon if eff_history_mode else 0)
            if ((i + eff_history) >= (data_source.size(0) - 1)):
                continue
            (data, targets) = get_batch(data_source, i, seq_len, evaluation=True)
            if args.repack:
                hidden = repackage_hidden(hidden)
            else:
                hidden = model.init_hidden(eval_batch_size)
            data = data.t()
            net = (nn.DataParallel(model) if (data.size(0) > 10) else model)
            ((_, _, decoded), hidden, all_decoded) = net(data, hidden)
            decoded = decoded.transpose(0, 1)
            targets = targets[eff_history:].contiguous().view((- 1))
            final_decoded = decoded[eff_history:].contiguous().view((- 1), ntokens)
            loss = criterion(final_decoded, targets)
            loss = loss.data
            total_loss += ((data.size(1) - eff_history) * loss)
            processed_data_size += (data.size(1) - eff_history)
        decoded = None
        final_decoded = None
        targets = None
        all_decoded = None
        return (total_loss.item() / processed_data_size)
def evaluate(data_source):
    model.eval()
    with torch.no_grad():
        total_loss = 0
        hidden = model.init_hidden(eval_batch_size)
        eff_history_mode = ((args.seq_len > args.horizon) and (not args.repack))
        if eff_history_mode:
            validseqlen = (args.seq_len - args.horizon)
            seq_len = args.seq_len
        else:
            validseqlen = args.horizon
            seq_len = args.horizon
        processed_data_size = 0
        for i in range(0, (data_source.size(0) - 1), validseqlen):
            eff_history = (args.horizon if eff_history_mode else 0)
            if ((i + eff_history) >= (data_source.size(0) - 1)):
                continue
            (data, targets) = get_batch(data_source, i, seq_len, evaluation=True)
            if args.repack:
                hidden = repackage_hidden(hidden)
            else:
                hidden = model.init_hidden(eval_batch_size)
            data = data.t()
            net = (nn.DataParallel(model) if (data.size(0) > 10) else model)
            ((_, _, decoded), hidden, all_decoded) = net(data, hidden)
            decoded = decoded.transpose(0, 1)
            targets = targets[eff_history:].contiguous().view((- 1))
            final_decoded = decoded[eff_history:].contiguous().view((- 1), ntokens)
            loss = criterion(final_decoded, targets)
            loss = loss.data
            total_loss += ((data.size(1) - eff_history) * loss)
            processed_data_size += (data.size(1) - eff_history)
        decoded = None
        final_decoded = None
        targets = None
        all_decoded = None
        return (total_loss.item() / processed_data_size)