code: def train_all_models(
      self,
      Ymat,
      val_len=24,
      start_date="2016-1-1",
      freq="H",
      covariates=None,
      dti=None,
      period=None,
      init_epochs=100,
      alt_iters=10,
      y_iters=200,
      tenacity=7,
      mod=5,
      max_FX_epoch=300,
      max_TCN_epoch=300,
      num_workers=1,
  ):
      self.end_index = Ymat.shape[1]
      self.start_date = start_date
      self.freq = freq
      self.period = period
      self.covariates = covariates
      self.dti = dti
  
      if self.normalize:
          self.s = np.std(Ymat[:, 0 : self.end_index], axis=1)
          # self.s[self.s == 0] = 1.0
          self.s += 1.0
          self.m = np.mean(Ymat[:, 0 : self.end_index], axis=1)
          self.Ymat = (Ymat - self.m[:, None]) / self.s[:, None]
          self.mini = np.abs(np.min(self.Ymat))
          self.Ymat = self.Ymat + self.mini
      else:
          self.Ymat = Ymat
  
      n, T = self.Ymat.shape
      t0 = self.end_index + 1
      if t0 > T:
          self.Ymat = np.hstack(
              [self.Ymat, self.Ymat[:, -1].reshape(-1, 1)]
          )
      if self.svd:
          indices = np.random.choice(
              self.Ymat.shape[0], self.rank, replace=False
          )
          X = self.Ymat[indices, 0:t0]
          mX = np.std(X, axis=1)
          mX[mX == 0] = 1.0
          X = X / mX[:, None]
          Ft = get_model(
              X.transpose(), self.Ymat[:, 0:t0].transpose(), lamb=0.1
          )
          F = Ft[0].transpose()
          self.X = torch.from_numpy(X).float()
          self.F = torch.from_numpy(F).float()
      else:
          R = torch.zeros(self.rank, t0).float()
          X = torch.normal(R, 0.1)
          C = torch.zeros(n, self.rank).float()
          F = torch.normal(C, 0.1)
          self.X = X.float()
          self.F = F.float()
  
      self.D = TCMFDataLoader(
          Ymat=self.Ymat,
          vbsize=self.vbsize,
          hbsize=self.hbsize,
          end_index=self.end_index,
          val_len=val_len,
          shuffle=False,
      )
      # print("-"*50+"Initializing Factors.....")
      logger.info("Initializing Factors")
      self.num_epochs = init_epochs
      self.train_factors(val_len=val_len)
  
      if alt_iters % 2 == 1:
          alt_iters += 1
  
      # print("Starting Alternate Training.....")
      logger.info("Starting Alternate Training.....")
  
      for i in range(1, alt_iters):
          if i % 2 == 0:
              logger.info("Training Factors. Iter#:{}".format(i))
              self.num_epochs = max_FX_epoch
              self.train_factors(
                  seed=False,
                  val_len=val_len,
                  early_stop=True,
                  tenacity=tenacity,
                  mod=mod,
              )
          else:
              # logger.info(
              #     "--------------------------------------------Training Xseq Model. Iter#:{}"
              #     .format(i)
              #     + "-------------------------------------------------------"
              # )
              logger.info("Training Xseq Model. Iter#:{}".format(i))
  
              self.num_epochs = max_TCN_epoch
              T = np.array(self.X.detach())
              self.train_Xseq(
                  Ymat=T,
                  num_epochs=self.num_epochs,
                  val_len=val_len,
                  early_stop=True,
                  tenacity=tenacity,
              )
  
      logger.info("Start training Yseq.....")
      val_loss = self.train_Yseq(
          num_epochs=y_iters,
          covariates=covariates,
          dti=dti,
          val_len=val_len,
          num_workers=num_workers,
      )
      return val_loss
  
imports: from __future__ import print_function
  import torch
  import numpy
  import pandas
  import torch.nn
  import torch.optim
  from torch.autograd import Variable
  from zoo.chronos.model.tcmf.data_loader import TCMFDataLoader
  from zoo.chronos.model.tcmf.local_model import TemporalConvNet, LocalModel
  from zoo.chronos.model.tcmf.time import TimeCovariates
  import copy
  import pickle
  import logging
label_desc: Use image node_id 16 for calling the DeepGLO obj's underlying member method code with example usage: obj.train_all_models(Ymat, val_len, start_date, freq, covariates, dti, period, init_epochs, alt_iters, y_iters, tenacity, mod, max_FX_epoch, max_TCN_epoch, num_workers) and returns: val_loss