code: def load(prog, **kwargs):
      if "main" not in prog.functions:
          msg = "main function not found in program {}"
          raise ValueError(msg.format(prog))
      if len(prog.functions) != 1:
          msg = (
              "Program must have exactly one `main` function to "
              "convert to NN. Program: {}"
          )
          raise ValueError(msg.format(prog))
  
      nn_backend_passes(prog)
      input_types = prog.main_input_types
  
      v1_inputs = []
      symbolic_inputs = {}
      for name, var in prog.functions["main"].inputs.items():
          if types.is_tensor(var.sym_type):
              sym_shape = var.sym_type.get_shape()
              if any_variadic(sym_shape):
                  # TODO: rdar://59559656
                  raise NotImplementedError(
                      "Variadic rank is not supported"
                  )
              if any_symbolic(sym_shape):
                  user_specified = False
                  for input_type in input_types:
                      if name == input_type.name:
                          sym_shape = input_type.shape.default
                          user_specified = True
                          break
                  # Use dummy static shape, and will set it later.
                  shape = [
                      1 if is_symbolic(d) else d for d in sym_shape
                  ]
                  if not user_specified:
                      symbolic_inputs[name] = sym_shape
              else:
                  shape = sym_shape
              v1_inputs.append((name, datatypes.Array(*shape)))
          elif types.is_scalar(var.sym_type):
              v1_inputs.append((name, datatypes.Array(1)))
          else:
              raise NotImplementedError()
  
      v1_outputs = []
      for var in prog.functions["main"].outputs:
          if types.is_tensor(var.sym_type) or types.is_primitive(
              var.sym_type
          ):
              # Disregard the output types
              v1_outputs.append((var.name, None))
          else:
              raise NotImplementedError()
  
      # create neural network builder
      builder = neural_network.NeuralNetworkBuilder(
          v1_inputs,
          v1_outputs,
          disable_rank5_shape_mapping=True,
          use_float_arraytype=True,
      )
  
      # const in V2 are added lazily to V1 by each op whenever needed.
      # `const_context` stores the const names we've added so far and avoid
      # adding a const more than once.
      # const_context: list[set of str] (const name for v1 & v2
      # (the same)). Note that in NN in outer layer is visible from the inner
      # layer, so the const_context is simply a stack of set.
      const_context = []
      # Iterate through ops and add to builder
      convert_ops(
          const_context,
          builder,
          prog.functions["main"].operations,
          prog.functions["main"].outputs,
      )
  
      # Replace model outputs's name with v1_outputs
      output_names = [x[0] for x in v1_outputs]
      for i, spec_layer in enumerate(builder.nn_spec.layers):
          for j, name in enumerate(spec_layer.output):
              for output_name in output_names:
                  if output_name.split(":")[0] == name:
                      spec_layer.output[j] = output_name
  
      proto = builder.spec
      # image input
      has_image_input = any(
          [isinstance(s, ImageType) for s in input_types]
      )
      if has_image_input:
          proto = _convert_to_image_input(proto, input_types)
  
      # classifier flag
      classifier_config = kwargs.get("classifier_config", None)
      if classifier_config is not None:
          proto = _convert_to_classifier(proto, classifier_config)
  
      _set_user_inputs(proto, input_types)
      _set_symbolic_inputs(proto, symbolic_inputs)
      _set_optional_inputs(proto, input_types)
  
      return proto
  
imports: from __future__ import print_function
  from __future__ import division
  from __future__ import absolute_import
  import logging
  from collections import defaultdict
  from coremltools.converters.mil.input_types import ClassifierConfig, ImageType, EnumeratedShapes, Shape, RangeDim
  from coremltools.models import MLModel
  from coremltools.models import neural_network
  import coremltools.models.datatypes
  from coremltools.converters.mil.mil import types
  from coremltools.converters.mil.mil.types.symbolic import any_symbolic, any_variadic, is_symbolic
  from .op_mapping import convert_ops
  from coremltools.models.neural_network import flexible_shape_utils
  from coremltools.models.neural_network.flexible_shape_utils import update_image_size_range, add_enumerated_image_sizes, set_multiarray_ndshape_range, add_multiarray_ndshape_enumeration
  from .passes.nn_passes import nn_backend_passes
  from coremltools.converters._profile_utils import _profile
label_desc: Use image node_id 6 for calling a global function with example usage: load(prog) and returns: proto