def compute_cost_graph(self, devices=None):
    """Computes a CostGraphDef protobuf based on this graph.

    Defined in tensorflow/core/framework/cost_graph.proto.

    Args:
      devices: optional [string], the names of devices to consider. If
          specified, any tensor on a device not listed is given a size of zero.
          Any device-less tensor (e.g. Mesh TensorFlow tensor) is not affected.

    Returns:
      a CostGraphDef protobuf with a Node for every operation in the graph, each
      of which is populated with size/dtype information for its inputs and
      outputs (which match the input/output order of the operation).
    """
    cost_graph_def = cost_graph_pb2.CostGraphDef()

    for i, operation_name in enumerate(self.get_all_operation_names()):
      node = cost_graph_def.node.add(
          name=operation_name,
          device=self.get_operation_device(operation_name),
          id=i)
      for input_name in self.get_operation_input_names(operation_name):
        id1, id2 = self._tensor_name_to_ids[input_name]
        node.input_info.add(preceding_node=id1, preceding_port=id2)

      for output_name in self.get_operation_output_names(operation_name):
        tensor_device = self.get_tensor_device(output_name)
        # devices = [] is not the same as None, and tensor_device = '' is also
        # not the same as None.
        if devices is None or tensor_device is None or tensor_device in devices:
          node.output_info.add(
              size=self.get_tensor_num_entries(output_name),
              alias_input_port=-1,
              dtype=self.get_tensor_dtype(output_name).as_datatype_enum,
              shape=self.get_tensor_shape(output_name).as_proto(),
          )
        else:
          node.output_info.add(
              size=0,
              alias_input_port=-1,
              dtype=self.get_tensor_dtype(output_name).as_datatype_enum,
          )

        # NOTE(joshuawang): Unfortunately, the CostGraphDef protobuf has final
        # operations, not tensors. As a result, we have to declare any operation
        # that outputs a final tensor as final, which may expand the final set
        # of tensors to keep in memory. This issue also arises in the scheduler
        # code we will interface with.
        if self.is_tensor_final(output_name):
          node.is_final = True

    return cost_graph_def
Computes a CostGraphDef protobuf based on this graph.

    Defined in tensorflow/core/framework/cost_graph.proto.

    Args:
      devices: optional [string], the names of devices to consider. If
          specified, any tensor on a device not listed is given a size of zero.
          Any device-less tensor (e.g. Mesh TensorFlow tensor) is not affected.

    Returns:
      a CostGraphDef protobuf with a Node for every operation in the graph, each
      of which is populated with size/dtype information for its inputs and
      outputs (which match the input/output order of the operation).