docstr: Checks that ps placement is based on var name.
docstr_tok: ["Checks","that","ps","placement","is","based","on","var","name","."]
code: def test_monkey_patch_default_variable_placement_strategy(
      self, num_tasks, op_names, before_want_ps, after_want_ps
  ):
      """Checks that ps placement is based on var name."""
  
      with context.graph_mode():
          var_ops = [
              tf.Variable(0.0, name=op_name).op for op_name in op_names
          ]
          before_device_fn = tf.compat.v1.train.replica_device_setter(
              ps_tasks=num_tasks
          )
          self.assertEqual(
              before_want_ps, [before_device_fn(op) for op in var_ops]
          )
  
          with monkey_patch_default_variable_placement_strategy():
              after_device_fn = (
                  tf.compat.v1.train.replica_device_setter(
                      ps_tasks=num_tasks
                  )
              )
          self.assertEqual(
              after_want_ps, [after_device_fn(op) for op in var_ops]
          )
  
          # Check that monkey-patch is only for the context.
          before_device_fn = tf.compat.v1.train.replica_device_setter(
              ps_tasks=num_tasks
          )
          self.assertEqual(
              before_want_ps, [before_device_fn(op) for op in var_ops]
          )
  
file_path: adanet/adanet/distributed/devices_test.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from absl.testing import parameterized
  from adanet.distributed.devices import monkey_patch_default_variable_placement_strategy
  import tensorflow.compat.v2
  from tensorflow.python.eager import context
  from tensorflow.python.framework import test_util
label_desc: Use image node_id 2 for calling the DevicesTest obj's underlying member method code with example usage: obj.test_monkey_patch_default_variable_placement_strategy(num_tasks, op_names, before_want_ps, after_want_ps) without return types