docstr: This test shows a very simple line model with test_loss in eager mode.
  
  The template is used to share parameters between a training and test model.
  
  This test also shows that it can pick up explicitly set variable stores
  even if they are only set before the first template usage.
docstr_tok: ["This","test","shows","a","very","simple","line","model","with","test_loss","in","eager","mode",".","The","template","is","used","to","share","parameters","between","a","training","and","test","model",".","This","test","also","shows","that","it","can","pick","up","explicitly","set","variable","stores","even","if","they","are","only","set","before","the","first","template","usage","."]
code: def test_eager_delayed_store_pickup(self):
      """This test shows a very simple line model with test_loss in eager mode.
  
      The template is used to share parameters between a training and test model.
  
      This test also shows that it can pick up explicitly set variable stores
      even if they are only set before the first template usage.
      """
      with context.eager_mode():
          training_input, training_output = (
              [1.0, 2.0, 3.0, 4.0],
              [2.8, 5.1, 7.2, 8.7],
          )
          test_input, test_output = (
              [5.0, 6.0, 7.0, 8.0],
              [11, 13, 15, 17],
          )
  
          random_seed.set_random_seed(1234)
  
          def test_line(x):
              m = variable_scope.get_variable(
                  "w",
                  shape=[],
                  initializer=init_ops.truncated_normal_initializer(),
              )
              b = variable_scope.get_variable(
                  "b",
                  shape=[],
                  initializer=init_ops.truncated_normal_initializer(),
              )
              return x * m + b
  
          line_template = template.make_template("line", test_line)
  
          def train_loss():
              train_prediction = line_template(training_input)
              return math_ops.reduce_mean(
                  math_ops.square(train_prediction - training_output)
              )
  
          def test_loss():
              test_prediction = line_template(test_input)
              return math_ops.reduce_mean(
                  math_ops.square(test_prediction - test_output)
              )
  
          store = variable_scope._VariableStore()
          store._store_eager_variables = True
  
          with variable_scope.with_variable_store(store):
              optimizer = gradient_descent.GradientDescentOptimizer(0.1)
              initial_test_loss = test_loss()
              optimizer.minimize(train_loss)
              final_test_loss = test_loss()
  
              # Parameters are tied, so the loss should have gone down after training.
              self.assertLess(
                  final_test_loss.numpy(), initial_test_loss.numpy()
              )
  
          # Verify that the explicitly set store is not empty
          # and the make_template picked it up
          self.assertEqual(
              set(store._vars.keys()), {"line/w", "line/b"}
          )
  
          # But the store should only get picked up once, so a second
          # store will go unused:
          second_store = variable_scope._VariableStore()
          second_store._store_eager_variables = True
  
          with variable_scope.with_variable_store(second_store):
              optimizer = gradient_descent.GradientDescentOptimizer(0.1)
              test_loss()
              optimizer.minimize(train_loss)
              test_loss()
          self.assertEmpty(second_store._vars)
  
imports: import functools
  import traceback
  from tensorflow.python.client import session
  from tensorflow.python.eager import context
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import random_seed
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import init_ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import template
  from tensorflow.python.ops import variable_scope
  from tensorflow.python.ops import variables
  import tensorflow.python.ops.nn_grad
  from tensorflow.python.platform import test
  from tensorflow.python.training import gradient_descent
label_desc: Use image node_id 3 for calling the TemplateTest obj's underlying member method code with example usage: obj.test_eager_delayed_store_pickup() and returns: unknown, math_ops, math_ops