code: def ensure_graph_is_valid(graph_def: graph_pb2.GraphDef) -> None:
      """Makes sure that the graph is internally consistent.
  
      Checks basic properties of the graph def and raises an exception if there are
      input references to missing nodes, duplicated names, or other logic errors.
  
      Args:
        graph_def: Definition of a graph to be checked.
  
      Raises:
        ValueError: If the graph is incorrectly constructed.
      """
      node_map = {}
      for node in graph_def.node:
          if node.name not in node_map:
              node_map[node.name] = node
          else:
              raise ValueError(
                  "Duplicate node names detected for ", node.name
              )
      for node in graph_def.node:
          for input_name in node.input:
              input_node_name = node_name_from_input(input_name)
              if input_node_name not in node_map:
                  raise ValueError(
                      "Input for ",
                      node.name,
                      " not found: ",
                      input_name,
                  )
  
imports: import collections
  import math
  import re
  from typing import Mapping, Sequence
  import numpy
  from tensorflow.core.framework import attr_value_pb2
  from tensorflow.core.framework import graph_pb2
  from tensorflow.core.framework import node_def_pb2
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import graph_util
  from tensorflow.python.framework import tensor_util
  from tensorflow.python.platform import flags
  from tensorflow.python.platform import tf_logging
  from tensorflow.python.tools import strip_unused_lib
label_desc: Use image node_id 5 for calling a global function with example usage: ensure_graph_is_valid(graph_def) without return types