code: def assert_model_is_valid(
      program,
      inputs,
      backend="nn_proto",
      verbose=True,
      expected_output_shapes=None,
  ):
      """
      Assert Core ML model is valid.
  
      Inputs:
  
      - input: str -> shape tuple. All program input names need to appear in str.
        shape tuple can only contain positive integers.
      """
      input_dict = dict()
      for name, shape in inputs.items():
          input_dict[name] = np.random.rand(*shape)
      proto = _converter._convert(
          program, convert_from="mil", convert_to=backend
      )
      if verbose:
          from coremltools.models.neural_network.printer import (
              print_network_spec,
          )
  
          print_network_spec(proto, style="coding")
  
      model = coremltools.models.MLModel(proto)
      assert model is not None
      if _IS_MACOS:
          prediction = model.predict(input_dict, useCPUOnly=True)
          assert prediction is not None
          if expected_output_shapes is not None:
              for out_name, out_shape in expected_output_shapes.items():
                  assert out_name in prediction
                  assert out_shape == prediction[out_name].shape
  
imports: import logging
  import numpy
  import copy
  import coremltools
  from coremltools import converters
  from coremltools.converters.mil import converter
  from coremltools.converters.mil.mil import Program, Function
  from coremltools.converters.mil.mil.passes.pass_registry import PASS_REGISTRY
  from coremltools._deps import _IS_MACOS
label_desc: Use image node_id 2 for calling a global function with example usage: assert_model_is_valid(program, inputs, backend, verbose, expected_output_shapes) without return types