code: def train(
      network,
      train_data,
      test_data,
      epochs,
      learning_rate=0.01,
      optimizer="sgd",
      ctx=mx.gpu(0),
      num_epoch_lr=5,
      factor=0.2,
  ):
      np.random.seed(123)  # Fix random seed for consistent demos
      mx.np.random.seed(123)  # Fix random seed for consistent demos
      random.seed(123)  # Fix random seed for consistent demos
  
      schedule = mx.lr_scheduler.FactorScheduler(
          step=len(train_data) * len(ctx) * num_epoch_lr, factor=factor
      )
  
      trainer = gluon.Trainer(
          network.collect_params(),
          optimizer,
          {
              "learning_rate": learning_rate,
              "wd": 0.0001,
              "lr_scheduler": schedule,
          },
      )
      # update_on_kvstore=False)
  
      l2 = gluon.loss.L2Loss()
  
      network.hybridize()
  
      losses_output = []
      for e in range(epochs):
          loss_acc = 0.0
          for idx, (users, items, scores) in enumerate(train_data):
              users_ = gluon.utils.split_and_load(users, ctx)
              items_ = gluon.utils.split_and_load(items, ctx)
              scores_ = gluon.utils.split_and_load(scores, ctx)
  
              with autograd.record():
                  preds = [
                      network(u, i) for u, i in zip(users_, items_)
                  ]
                  losses = [l2(p, s) for p, s in zip(preds, scores_)]
  
              [l.backward() for l in losses]
              loss_acc += sum(
                  [l.asnumpy() for l in losses]
              ).mean() / len(ctx)
              trainer.update(users.shape[0])
  
          test_loss = evaluate_network(network, test_data, ctx)
          train_loss = loss_acc / (idx + 1)
          print(
              "Epoch [{}], Training RMSE {:.4f}, Test RMSE {:.4f}".format(
                  e, train_loss, test_loss
              )
          )
          losses_output.append((train_loss, test_loss))
      return losses_output
  
imports: import logging
  import math
  import random
  import mxnet
  from mxnet import gluon, autograd, nd
  import numpy
label_desc: Use image node_id 2 for calling a global function with example usage: train(network, train_data, test_data, epochs, learning_rate, optimizer, ctx, num_epoch_lr, factor) and returns: losses_output