code: def AddTrainingOperators(model, softmax, label):
      """Adds training operators to the model."""
      xent = model.LabelCrossEntropy([softmax, label], "xent")
      # compute the expected loss
      loss = model.AveragedLoss(xent, "loss")
      # track the accuracy of the model
      AddAccuracy(model, softmax, label)
      # use the average loss we just computed to add gradient operators to the
      # model
      model.AddGradientOperators([loss])
      # do a simple stochastic gradient descent
      ITER = brew.iter(model, "iter")
      # set the learning rate schedule
      LR = model.LearningRate(
          ITER,
          "LR",
          base_lr=-0.1,
          policy="step",
          stepsize=1,
          gamma=0.999,
      )
      # ONE is a constant value that is used in the gradient update. We only need
      # to create it once, so it is explicitly placed in param_init_net.
      ONE = model.param_init_net.ConstantFill(
          [], "ONE", shape=[1], value=1.0
      )
      # Now, for each parameter, we do the gradient updates.
      for param in model.params:
          # Note how we get the gradient of each parameter - ModelHelper keeps
          # track of that.
          param_grad = model.param_to_grad[param]
          # The update is a simple weighted sum: param = param + param_grad * LR
          model.WeightedSum([param, ONE, param_grad, LR], param)
  
file_path: tensorboardX/examples/demo_caffe2.py
imports: import numpy
  import os
  import shutil
  from caffe2.python import core, model_helper, workspace, brew
  from tensorboardX import TorchVis
label_desc: Use image node_id 5 for calling a global function with example usage: AddTrainingOperators(model, softmax, label) without return types