message: Compress constants in graph at the end of meta-optimizer.
diff: @@ -17,6 +17,7 @@ limitations under the License.
  #include "absl/strings/substitute.h"
  #include "tensorflow/core/common_runtime/function.h"
  #include "tensorflow/core/framework/function.pb.h"
  +#include "tensorflow/core/framework/tensor_util.h"
  #include "tensorflow/core/framework/versions.pb.h"
  #include "tensorflow/core/graph/graph_constructor.h"
  #include "tensorflow/core/grappler/clusters/virtual_cluster.h"
  @@ -102,6 +103,18 @@ uint64 DeadlineMicroSeconds(const RewriterConfig& cfg) {
  }
  }
  +Status CompressConstants(GraphDef* graph) {
  + for (int i = 0; i < graph->node_size(); ++i) {
  + NodeDef* node = graph->mutable_node(i);
  + if ((IsConstant(*node) || IsHostConstant(*node)) &&
  + HasNodeAttr(*node, "value")) {
  + AttrValue& attr_val = (*node->mutable_attr())["value"];
  + tensor::CompressTensorProtoInPlace(attr_val.mutable_tensor());
  + }
  + }
  + return Status::OK();
  +}
  +
  } // namespace
  #define MK_OPT(NAME, VALUE) \
  @@ -432,6 +445,9 @@ Status MetaOptimizer::OptimizeGraph(Cluster* cluster, const GrapplerItem& item,
  RUN_OPTIMIZER_OR_RETURN_IF_ERROR(sa_optimizer);
  }
  + // Compress the constants in the final graph.
  + TF_RETURN_IF_ERROR(CompressConstants(optimized_graph));
  +
  // Record graph optimization result.
  optimization_results_.push_back(optimization_result);
  