code: def GenerateMemoryReport(
      metagraph, detailed_report=True, cluster=None
  ):
      """Analyze the peak memory usage for the provided metagraph.
  
      Args:
        metagraph: A TensorFlow MetaGraphDef.
        detailed_report: print the live tensors in addition to the peak memory
          usage.
        cluster: Analyze the memory using the specified cluster, or the local
          machine if no cluster was specified.
  
      Returns:
        A string with the formatted memory usage.
      """
      if cluster is None:
          cluster = gcluster.Cluster(
              disable_detailed_stats=True, disable_timeline=True
          )
  
      item = gitem.Item(metagraph)
      peak_usage = cluster.DeterminePeakMemoryUsage(item)
      report = ""
      for device, snapshot in peak_usage.items():
          peak_usage = snapshot[0]
          report += (
              "Peak usage for device "
              + device
              + ": "
              + str(peak_usage)
              + " bytes\n"
          )
          if detailed_report:
              live_tensors = snapshot[1]
              for tensor in live_tensors:
                  op_name = tensor[0]
                  output_id = tensor[1]
                  mem_used = tensor[2]
                  report += (
                      "  "
                      + str(op_name)
                      + ":"
                      + str(output_id)
                      + " uses "
                      + str(mem_used)
                      + " bytes\n"
                  )
  
      return report
  
imports: from tensorflow.python.grappler import _pywrap_cost_analyzer
  from tensorflow.python.grappler import cluster
  from tensorflow.python.grappler import item
label_desc: Use image node_id 2 for calling a global function with example usage: GenerateMemoryReport(metagraph, detailed_report, cluster) and returns: report