code: def test_distributed_training_accuracy(
      tmpdir, device_id, mode, config
  ):
      ref_trainer = SimpleTrainer(None, None)
  
      # test if mode is available
      if not ref_trainer.create_distributed_learner(mode, config):
          pytest.skip("unsupported distributed learner mode")
  
      # run distributed training and check if all workers get the same model
      launch_args = ["--outputdir", str(tmpdir), "--mode", mode]
  
      if config:
          config_filename = os.path.join(str(tmpdir), "config.pkl")
          with open(config_filename, "wb") as pkl:
              pickle.dump(config, pkl)
          launch_args += ["--config", config_filename]
  
      if device_id >= 0:
          launch_args += ["--gpu"]
  
      mpiexec_execute(__file__, ["-n", str(NUM_WORKERS)], launch_args)
  
      p0 = np.load(os.path.join(str(tmpdir), mode + "0.npy"))
      for rank in range(NUM_WORKERS):
          p = np.load(
              os.path.join(str(tmpdir), mode + str(rank) + ".npy")
          )
          assert np.allclose(p0, p)
  
      # only compares with single worker with default config
      if config is not None:
          return
  
      # reference training on single worker, by concatenating data on all workers
      for batch in range(NUM_BATCHES):
          indices = None
          for rank in range(NUM_WORKERS):
              set_np_random_seed(rank, batch)
              rank_indices = (
                  np.random.random((BATCH_SIZE_PER_WORKER,))
                  * (ref_trainer.input_dim - 1)
              ).astype(np.int)
              indices = (
                  np.concatenate([indices, rank_indices])
                  if indices is not None
                  else rank_indices
              )
          ref_trainer.train_minibatch(indices)
  
      assert np.allclose(p0, ref_trainer.p.value)
  
imports: import argparse
  import collections
  import os
  import pickle
  import pytest
  import re
  import signal
  import subprocess
  import sys
  import time
  import numpy
  import cntk
label_desc: Use image node_id 4 for calling a global function with example usage: test_distributed_training_accuracy(tmpdir, device_id, mode, config) without return types