code: def train_command(args):
      if args.ooc_gpu_memory_size is not None:
          ooc_gpu_memory_size = str_to_num(args.ooc_gpu_memory_size)
          if ooc_gpu_memory_size < 0:
              logger.log(
                  99,
                  f"Fatal error. invalid ooc_gpu_memory_size [{args.ooc_gpu_memory_size}].",
              )
              return False
          args.ooc_gpu_memory_size = ooc_gpu_memory_size
      if args.ooc_window_length is not None:
          ooc_window_length = str_to_num(args.ooc_window_length)
          if ooc_window_length < 0:
              logger.log(
                  99,
                  f"Fatal error. invalid ooc_window_length [{args.ooc_window_length}].",
              )
              return False
          args.ooc_window_length = ooc_window_length
  
      callback.update_status(args)
  
      if single_or_rankzero():
          configure_progress(os.path.join(args.outdir, "progress.txt"))
  
      info = load.load(
          [args.config],
          prepare_data_iterator=None,
          exclude_parameter=True,
          context=args.context,
      )
  
      # Check dataset uri is empty.
      dataset_error = False
      for dataset in info.datasets.values():
          if dataset.uri.strip() == "":
              dataset_error = True
      if dataset_error:
          logger.log(99, "Fatal error. Dataset URI is empty.")
          return False
  
      class TrainConfig:
          pass
  
      config = TrainConfig()
      config.timelimit = -1
      if args.param:
          # If this parameter file contains optimizer information
          # we need to info to recovery.
          # load.load([args.param], parameter_only=True)
          load_train_state(args.param, info)
  
      config.timelimit = callback.get_timelimit(args)
  
      config.global_config = info.global_config
      config.training_config = info.training_config
  
      if single_or_rankzero():
          logger.log(
              99, "Train with contexts {}".format(available_contexts)
          )
  
      class OptConfig:
          pass
  
      config.optimizers = OrderedDict()
      for name, opt in info.optimizers.items():
          o = OptConfig()
          o.optimizer = opt
          o.data_iterators = []
          config.optimizers[name] = o
  
      class MonConfig:
          pass
  
      config.monitors = OrderedDict()
      for name, mon in info.monitors.items():
          m = MonConfig()
          m.monitor = mon
          m.data_iterators = []
          config.monitors[name] = m
  
      # Training
      comm = current_communicator()
      config.training_config.iter_per_epoch //= comm.size if comm else 1
      max_iteration = (
          config.training_config.max_epoch
          * config.training_config.iter_per_epoch
      )
  
      global _save_parameter_info
      _save_parameter_info = {}
      _, config_ext = os.path.splitext(args.config)
      if config_ext == ".prototxt" or config_ext == ".nntxt":
          _save_parameter_info["config"] = args.config
      elif config_ext == ".nnp":
          with zipfile.ZipFile(args.config, "r") as nnp:
              for name in nnp.namelist():
                  _, ext = os.path.splitext(name)
                  if ext == ".nntxt" or ext == ".prototxt":
                      nnp.extract(name, args.outdir)
                      _save_parameter_info["config"] = os.path.join(
                          args.outdir, name
                      )
  
      result = False
      restart = False
      if max_iteration > 0:
          rng = np.random.RandomState(comm.rank if comm else 0)
          with ExitStack() as stack:
              # Create data_iterator instance only once for each dataset in optimizers
              optimizer_data_iterators = {}
              for name, o in config.optimizers.items():
                  for di in o.optimizer.data_iterators.values():
                      if di not in optimizer_data_iterators:
                          di_instance = stack.enter_context(di())
                          if comm and comm.size > 1:
                              di_instance = di_instance.slice(
                                  rng, comm.size, comm.rank
                              )
                          optimizer_data_iterators[di] = di_instance
                      else:
                          di_instance = optimizer_data_iterators[di]
                      o.data_iterators.append(di_instance)
  
              # Create data_iterator instance only once for each dataset in monitors
              monitor_data_iterators = {}
              for name, m in config.monitors.items():
                  for di in m.monitor.data_iterators.values():
                      if di not in monitor_data_iterators:
                          di_instance = stack.enter_context(di())
                          if comm and comm.size > 1:
                              di_instance = di_instance.slice(
                                  rng, comm.size, comm.rank
                              )
                          monitor_data_iterators[di] = di_instance
                      else:
                          di_instance = monitor_data_iterators[di]
                      m.data_iterators.append(di_instance)
              monitor_data_iterators.update(optimizer_data_iterators)
  
              result, restart = _train(args, config)
      else:
          # save parameters without training (0 epoch learning)
          logger.log(99, "0 epoch learning. (Just save parameter.)")
          if single_or_rankzero():
              _save_parameters(args, None, 0, config, True)
          result = True
  
      if single_or_rankzero() and not restart:
          if result:
              logger.log(99, "Training Completed.")
              callback.update_status("finished")
          else:
              logger.log(99, "Training Incompleted.")
              callback.update_status("failed")
      if single_or_rankzero():
          progress(None)
      return True
  
imports: import glob
  import os
  import time
  import zipfile
  from collections import OrderedDict
  import nnabla
  import nnabla.utils.callback
  import nnabla.utils.load
  import numpy
  from contextlib2 import ExitStack
  from nnabla import available_contexts
  from nnabla.config import nnabla_config
  from nnabla.logger import logger
  from nnabla.parameter import save_parameters
  from nnabla.utils.cli.utility import NodeTimeInfoCollector
  from nnabla.utils.cli.utility import get_cpu_gpu_average_load
  from nnabla.utils.cli.utility import let_data_to_variable
  from nnabla.utils.cli.utility import lms_scheduler
  from nnabla.utils.cli.utility import load_train_state
  from nnabla.utils.cli.utility import measure_cpu_gpu_instant_load
  from nnabla.utils.cli.utility import save_optimizer_states
  from nnabla.utils.cli.utility import str_to_num
  from nnabla.utils.communicator_util import current_communicator, single_or_rankzero
  from nnabla.utils.nnp_format import nnp_version
  from nnabla.utils.progress import configure_progress, progress
  from six.moves import range
label_desc: Use image node_id 10 for calling a global function with example usage: train_command(args) and returns: True, False, False, False