code: def test_epoch(self, data_set, return_pred=False):
      self.model.eval()
      self.tra.eval()
      data_set.eval()
  
      preds = []
      metrics = []
      for batch in tqdm(data_set):
          data, label, index = (
              batch["data"],
              batch["label"],
              batch["index"],
          )
  
          feature = data[:, :, : -self.tra.num_states]
          hist_loss = data[
              :, : -data_set.horizon, -self.tra.num_states :
          ]
  
          with torch.no_grad():
              hidden = self.model(feature)
              pred, all_preds, prob = self.tra(hidden, hist_loss)
  
          L = (all_preds - label[:, None]).pow(2)
  
          L -= L.min(
              dim=-1, keepdim=True
          ).values  # normalize & ensure positive input
  
          data_set.assign_data(index, L)  # save loss to memory
  
          X = np.c_[
              pred.cpu().numpy(),
              label.cpu().numpy(),
          ]
          columns = ["score", "label"]
          if prob is not None:
              X = np.c_[X, all_preds.cpu().numpy(), prob.cpu().numpy()]
              columns += [
                  "score_%d" % d for d in range(all_preds.shape[1])
              ] + ["prob_%d" % d for d in range(all_preds.shape[1])]
  
          pred = pd.DataFrame(
              X, index=index.cpu().numpy(), columns=columns
          )
  
          metrics.append(evaluate(pred))
  
          if return_pred:
              preds.append(pred)
  
      metrics = pd.DataFrame(metrics)
      metrics = {
          "MSE": metrics.MSE.mean(),
          "MAE": metrics.MAE.mean(),
          "IC": metrics.IC.mean(),
          "ICIR": metrics.IC.mean() / metrics.IC.std(),
      }
  
      if return_pred:
          preds = pd.concat(preds, axis=0)
          preds.index = data_set.restore_index(preds.index)
          preds.index = preds.index.swaplevel()
          preds.sort_index(inplace=True)
  
      return metrics, preds
  
imports: import os
  import copy
  import math
  import json
  import collections
  import numpy
  import pandas
  import torch
  import torch.nn
  import torch.optim
  import torch.nn.functional
  from tqdm import tqdm
  from qlib.utils import get_or_create_path
  from qlib.log import get_module_logger
  from qlib.model.base import Model
label_desc: Use image node_id 3 for calling the TRAModel obj's underlying member method code with example usage: obj.test_epoch(data_set, return_pred) and returns: metrics,  preds