code: def test_trainer_lr_sched():
      x = gluon.Parameter("x", shape=(10,))
      x.initialize(ctx=[mx.cpu(0), mx.cpu(1)], init="zeros")
      freq = 2
      factor = 0.1
      lr = 1
      lr_sched = mx.lr_scheduler.FactorScheduler(
          freq, factor=factor, base_lr=lr
      )
      trainer = gluon.Trainer(
          [x], "sgd", {"learning_rate": lr, "lr_scheduler": lr_sched}
      )
      for i in range(10):
          with mx.autograd.record():
              for w in x.list_data():
                  y = w + 1
                  y.backward()
          trainer.step(1)
          if i % freq == 0:
              assert trainer.learning_rate == lr, (
                  lr,
                  trainer.learning_rate,
                  i,
              )
              lr *= factor
      mx.nd.waitall()
  
      # Update on kvstore = False
      x = gluon.Parameter("x", shape=(10,))
      x.initialize(ctx=[mx.cpu(0), mx.cpu(1)], init="zeros")
      freq = 2
      factor = 0.1
      lr = 1
      lr_sched = mx.lr_scheduler.FactorScheduler(
          freq, factor=factor, base_lr=lr
      )
      trainer = gluon.Trainer(
          [x],
          "sgd",
          {"learning_rate": lr, "lr_scheduler": lr_sched},
          update_on_kvstore=False,
      )
      for i in range(10):
          with mx.autograd.record():
              for w in x.list_data():
                  y = w + 1
                  y.backward()
          trainer.step(1)
          if i % freq == 0:
              assert trainer.learning_rate == lr, (
                  lr,
                  trainer.learning_rate,
                  i,
              )
              lr *= factor
      mx.nd.waitall()
  
imports: import mxnet
  import unittest
  import os
  import numpy
  from mxnet import gluon
  from mxnet.gluon import nn
  from mxnet.test_utils import assert_almost_equal
  from common import assertRaises, xfail_when_nonstandard_decimal_separator
  from copy import deepcopy
  import pytest
label_desc: Use image node_id 10 for calling a global function with example usage: test_trainer_lr_sched() without return types