class_docstr: Implementation of OneDeviceStrategy.
class_docstr_tok: ["Implementation","of","OneDeviceStrategy","."]
code: def _experimental_run_steps_on_iterator(
      self, fn, iterator, iterations, initial_loop_values=None
  ):
      if initial_loop_values is None:
          initial_loop_values = {}
      initial_loop_values = nest.flatten(initial_loop_values)
  
      ctx = input_lib.MultiStepContext()
  
      def body(i, *args):
          """A wrapper around `fn` to create the while loop body."""
          del args
          fn_result = fn(ctx, iterator.get_next())
          flat_last_step_outputs = nest.flatten(ctx.last_step_outputs)
          with ops.control_dependencies([fn_result]):
              return [i + 1] + flat_last_step_outputs
  
      # We capture the control_flow_context at this point, before we run `fn`
      # inside a while_loop. This is useful in cases where we might need to exit
      # these contexts and get back to the outer context to do some things, for
      # e.g. create an op which should be evaluated only once at the end of the
      # loop on the host. One such usage is in creating metrics' value op.
      self._outer_control_flow_context = (
          ops.get_default_graph()._get_control_flow_context()
      )  # pylint: disable=protected-access
  
      # TODO(priyag): Use max_iterations instead of an explicit counter.
      cond = lambda i, *args: i < iterations
      i = constant_op.constant(0)
      loop_result = while_loop.while_loop(
          cond,
          body,
          [i] + initial_loop_values,
          name="",
          parallel_iterations=1,
          back_prop=False,
          swap_memory=False,
          return_same_structure=True,
      )
      del self._outer_control_flow_context
  
      ctx.run_op = control_flow_ops.group(loop_result)
  
      # Convert the last_step_outputs from a list to the original dict structure
      # of last_step_outputs.
      last_step_tensor_outputs = loop_result[1:]
      last_step_tensor_outputs_dict = nest.pack_sequence_as(
          ctx.last_step_outputs, last_step_tensor_outputs
      )
  
      ctx._set_last_step_outputs(
          last_step_tensor_outputs_dict
      )  # pylint: disable=protected-access
      return ctx
  
imports: from tensorflow.python.distribute import device_util
  from tensorflow.python.distribute import distribute_lib
  from tensorflow.python.distribute import distribute_utils
  from tensorflow.python.distribute import input_lib
  from tensorflow.python.distribute import input_util
  from tensorflow.python.distribute import numpy_dataset
  from tensorflow.python.distribute.v1 import input_lib
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import ops
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import control_flow_ops
  from tensorflow.python.ops import while_loop
  from tensorflow.python.util import nest
  from tensorflow.python.util.tf_export import tf_export
label_desc: Use image node_id 13 for calling the OneDeviceExtended obj's underlying member method code with example usage: obj._experimental_run_steps_on_iterator(fn, iterator, iterations, initial_loop_values) and returns: ctx, unknown