code: def _update_metrics(self,
                          metric_train: mx.metric.EvalMetric,
                          metric_val: mx.metric.EvalMetric):
          
          checkpoint_metrics = {"epoch": self.state.epoch,
                                "learning-rate": self.model.optimizer.learning_rate,
                                "gradient-norm": self.state.gradient_norm,
                                "time-elapsed": time.time() - self.state.start_tic}
          gpu_memory_usage = utils.get_gpu_memory_usage(self.model.context)
          checkpoint_metrics['used-gpu-memory'] = sum(v[0] for v in gpu_memory_usage.values())
          checkpoint_metrics['converged'] = self.state.converged
          checkpoint_metrics['diverged'] = self.state.diverged
  
          for name, value in metric_train.get_name_value():
              checkpoint_metrics["%s-train" % name] = value
          for name, value in metric_val.get_name_value():
              checkpoint_metrics["%s-val" % name] = value
  
          self.state.metrics.append(checkpoint_metrics)
          utils.write_metrics_file(self.state.metrics, self.metrics_fname)
  
          tf_metrics = checkpoint_metrics.copy()
          tf_metrics.update({"%s_grad" % n: v for n, v in self.state.gradients.items()})
          tf_metrics.update(self.model.params)
          self.tflogger.log_metrics(metrics=tf_metrics, checkpoint=self.state.checkpoint)
docs: Updates metrics for current checkpoint. If a process manager is given, also collects previous decoding results
          and spawns a new decoding process.
          Writes all metrics to the metrics file and optionally logs to tensorboard.