code: def _context(proto):
      comm = current_communicator()
      if not proto.backends:
          logger.warning("Old-style context. Updating to new format.")
          # Update from old Context
          backends = [x.strip() for x in proto.backend.split("|")]
          compute_backends = [
              x.strip() for x in proto.compute_backend.split("|")
          ]
          if "cuda" in backends:
              device_id = str(proto.device_id)
              if comm:
                  device_id = str(comm.local_rank)
  
              if "cudnn" in compute_backends:
                  try:
                      import nnabla_ext.cudnn
  
                      ctx = nnabla_ext.cudnn.context(
                          device_id=device_id
                      )
                  except ImportError:
                      logger.warning("Fallback to CPU context.")
                      import nnabla_ext.cpu
  
                      ctx = nnabla_ext.cpu.context()
              elif "default" in compute_backends:
                  try:
                      import nnabla_ext.cuda
  
                      ctx = nnabla_ext.cuda.context(device_id=device_id)
                  except ImportError:
                      logger.warning("Fallback to CPU context.")
                      import nnabla_ext.cpu
  
                      ctx = nnabla_ext.cpu.context()
              else:
                  raise ValueError(
                      "Invalid compute_backend {}".format(
                          proto.compute_backend
                      )
                  )
          elif "cpu" in backends:
              import nnabla_ext.cpu
  
              ctx = nnabla_ext.cpu.context()
          else:
              raise ValueError("Invalid context {}".format(proto))
          ctx.array_class = str(proto.array_class)
          return ctx
      ctx = nn.Context()
      ctx.backend = proto.backends
      ctx.array_class = str(proto.array_class)
  
      if comm:
          ctx.device_id = str(comm.local_rank)
      else:
          ctx.device_id = str(proto.device_id)
  
      return ctx
  
imports: import itertools
  import os
  import re
  from collections import OrderedDict
  import nnabla
  import nnabla.functions
  import nnabla.solver
  import numpy
  from nnabla.core.graph_optimizer import IdentityRemover
  from nnabla.initializer import NormalInitializer, UniformInitializer, ConstantInitializer, RangeInitializer
  from nnabla.logger import logger
  from nnabla.utils import nnabla_pb2
  from nnabla.utils.communicator_util import current_communicator, single_or_rankzero
  from nnabla.utils.create_cache import CreateCache
  from nnabla.utils.data_iterator import data_iterator_csv_dataset, data_iterator_cache
  from nnabla.utils.get_file_handle import get_initial_file_loader, load_files
  from nnabla.utils.learning_rate_scheduler import PolynomialScheduler, CosineScheduler, ExponentialScheduler, StepScheduler, LinearWarmupScheduler
label_desc: Use image node_id 6 for calling a global function with example usage: _context(proto) and returns: ctx, ctx