code: def test_trainer_reset_kv():
      def check_trainer_reset_kv(kv):
          x = gluon.Parameter("x", shape=(10,), lr_mult=1.0)
          params = {"x": x}
          x.initialize(ctx=[mx.cpu(0), mx.cpu(1)], init="zeros")
          trainer = gluon.Trainer(
              params, "sgd", {"learning_rate": 0.1}, kvstore=kv
          )
          mx.nd.save(
              "test_trainer_reset_kv.params",
              {k: v._reduce() for k, v in params.items()},
          )
          with mx.autograd.record():
              for w in x.list_data():
                  y = w + 1
                  y.backward()
          trainer.step(1)
          assert trainer._kvstore.type == kv
          # load would reset kvstore
          mx.nd.waitall()
          params = mx.nd.load("test_trainer_reset_kv.params")
          x._load_init(params["x"], None)
          if trainer._update_on_kvstore:
              # drop kvstore state if new parameters are loaded
              assert trainer._kvstore is None
              assert trainer._kv_initialized is False
          with mx.autograd.record():
              for w in x.list_data():
                  y = w + 1
                  y.backward()
          trainer.step(1)
          # the updated parameter should be based on the loaded checkpoint
          assert (x.data(mx.cpu()) == -0.2).asnumpy().all()
  
      kvs = ["local", "device"]
      for kv in kvs:
          check_trainer_reset_kv(kv)
  
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 8 for calling a global function with example usage: test_trainer_reset_kv() without return types