class_docstr: Tests the Grappler memory optimizer.
class_docstr_tok: ["Tests","the","Grappler","memory","optimizer","."]
docstr: Check that the swap annotations are followed.
docstr_tok: ["Check","that","the","swap","annotations","are","followed","."]
code: def testSimpleSwap(self):
      """Check that the swap annotations are followed."""
      with ops.device("/gpu:0"):
          a = variable_v1.VariableV1(10, name="a")
          b = variable_v1.VariableV1(20, name="b")
          c = math_ops.add_n([a, b], name="c")
          d = math_ops.add_n([b, c], name="d")
          train_op = ops.get_collection_ref(ops.GraphKeys.TRAIN_OP)
          train_op.append(d)
  
          d.op._set_attr("_swap_to_host", attr_value_pb2.AttrValue(i=0))
  
          mg = meta_graph.create_meta_graph_def(
              graph=ops.get_default_graph()
          )
          graph_size = len(mg.graph_def.node)
  
          config = config_pb2.ConfigProto()
          config.graph_options.rewrite_options.CopyFrom(
              rewriter_config_pb2.RewriterConfig(
                  disable_model_pruning=True,
                  meta_optimizer_iterations=rewriter_config_pb2.RewriterConfig.ONE,
                  constant_folding=rewriter_config_pb2.RewriterConfig.OFF,
                  memory_optimization=rewriter_config_pb2.RewriterConfig.MANUAL,
                  min_graph_nodes=-1,
              )
          )
          graph = tf_optimizer.OptimizeGraph(config, mg)
  
          self.assertEqual(len(graph.node), graph_size + 2)
          self.assertTrue(
              set(node.name for node in graph.node)
              > set(["a", "b", "c", "d", "swap_in_d_0", "swap_out_d_0"])
          )
          for node in graph.node:
              if node.name == "swap_in_d_0":
                  self.assertEqual("swap_out_d_0", node.input[0])
                  self.assertEqual("^b/read", node.input[1])
              elif node.name == "swap_out_d_0":
                  self.assertEqual("b/read", node.input[0])
              elif node.name == "d":
                  self.assertEqual("swap_in_d_0", node.input[0])
                  self.assertEqual("c", node.input[1])
  
imports: from tensorflow.core.framework import attr_value_pb2
  from tensorflow.core.protobuf import config_pb2
  from tensorflow.core.protobuf import rewriter_config_pb2
  from tensorflow.python.client import session
  from tensorflow.python.framework import meta_graph
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import random_seed
  from tensorflow.python.framework import test_util
  from tensorflow.python.grappler import tf_optimizer
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import nn
  from tensorflow.python.ops import variable_scope
  from tensorflow.python.ops import variable_v1
  from tensorflow.python.ops import variables
  from tensorflow.python.platform import test
  from tensorflow.python.training import training
label_desc: Use image node_id 2 for calling the MemoryOptimizerSwapTest obj's underlying member method code with example usage: obj.testSimpleSwap() without return types