class_docstr: A distribution strategy for running on a single device.
  
  Using this strategy will place any variables created in its scope on the
  specified device. Input distributed through this strategy will be
  prefetched to the specified device. Moreover, any functions called via
  `strategy.run` will also be placed on the specified device
  as well.
  
  Typical usage of this strategy could be testing your code with the
  tf.distribute.Strategy API before switching to other strategies which
  actually distribute to multiple devices/machines.
  
  For example:
  ```
  strategy = tf.distribute.OneDeviceStrategy(device="/gpu:0")
  
  with strategy.scope():
    v = tf.Variable(1.0)
    print(v.device)  # /job:localhost/replica:0/task:0/device:GPU:0
  
  def step_fn(x):
    return x * 2
  
  result = 0
  for i in range(10):
    result += strategy.run(step_fn, args=(i,))
  print(result)  # 90
  ```
class_docstr_tok: ["A","distribution","strategy","for","running","on","a","single","device",".","Using","this","strategy","will","place","any","variables","created","in","its","scope","on","the","specified","device",".","Input","distributed","through","this","strategy","will","be","prefetched","to","the","specified","device",".","Moreover",",","any","functions","called","via","`","strategy.run","`","will","also","be","placed","on","the","specified","device","as","well",".","Typical","usage","of","this","strategy","could","be","testing","your","code","with","the","tf.distribute.Strategy","API","before","switching","to","other","strategies","which","actually","distribute","to","multiple","devices\/machines",".","For","example",":","``","`","strategy","=","tf.distribute.OneDeviceStrategy","(","device=","''","\/gpu:0","''",")","with","strategy.scope","(",")",":","v","=","tf.Variable","(","1.0",")","print","(","v.device",")","#","\/job",":","localhost\/replica:0\/task:0\/device",":","GPU:0","def","step_fn","(","x",")",":","return","x","*","2","result","=","0","for","i","in","range","(","10",")",":","result","+=","strategy.run","(","step_fn",",","args=","(","i",",",")",")","print","(","result",")","#","90","``","`"]
docstr: Distributes `tf.data.Dataset` instances created by calls to `dataset_fn`.
  
  `dataset_fn` will be called once for each worker in the strategy. In this
  case, we only have one worker and one device so `dataset_fn` is called
  once.
  
  The `dataset_fn` should take an `tf.distribute.InputContext` instance where
  information about batching and input replication can be accessed:
  
  ```
  def dataset_fn(input_context):
    batch_size = input_context.get_per_replica_batch_size(global_batch_size)
    d = tf.data.Dataset.from_tensors([[1.]]).repeat().batch(batch_size)
    return d.shard(
        input_context.num_input_pipelines, input_context.input_pipeline_id)
  
  inputs = strategy.distribute_datasets_from_function(dataset_fn)
  
  for batch in inputs:
    replica_results = strategy.run(replica_fn, args=(batch,))
  ```
  
  IMPORTANT: The `tf.data.Dataset` returned by `dataset_fn` should have a
  per-replica batch size, unlike `experimental_distribute_dataset`, which uses
  the global batch size.  This may be computed using
  `input_context.get_per_replica_batch_size`.
  
  Args:
    dataset_fn: A function taking a `tf.distribute.InputContext` instance and
      returning a `tf.data.Dataset`.
    options: `tf.distribute.InputOptions` used to control options on how this
      dataset is distributed.
  
  Returns:
    A "distributed `Dataset`", which the caller can iterate over like regular
    datasets.
docstr_tok: ["Distributes","`","tf.data.Dataset","`","instances","created","by","calls","to","`","dataset_fn","`",".","`","dataset_fn","`","will","be","called","once","for","each","worker","in","the","strategy",".","In","this","case",",","we","only","have","one","worker","and","one","device","so","`","dataset_fn","`","is","called","once",".","The","`","dataset_fn","`","should","take","an","`","tf.distribute.InputContext","`","instance","where","information","about","batching","and","input","replication","can","be","accessed",":","``","`","def","dataset_fn","(","input_context",")",":","batch_size","=","input_context.get_per_replica_batch_size","(","global_batch_size",")","d","=","tf.data.Dataset.from_tensors","(","[","[","1",".","]","]",")",".repeat","(",")",".batch","(","batch_size",")","return","d.shard","(","input_context.num_input_pipelines",",","input_context.input_pipeline_id",")","inputs","=","strategy.distribute_datasets_from_function","(","dataset_fn",")","for","batch","in","inputs",":","replica_results","=","strategy.run","(","replica_fn",",","args=","(","batch",",",")",")","``","`","IMPORTANT",":","The","`","tf.data.Dataset","`","returned","by","`","dataset_fn","`","should","have","a","per-replica","batch","size",",","unlike","`","experimental_distribute_dataset","`",",","which","uses","the","global","batch","size",".","This","may","be","computed","using","`","input_context.get_per_replica_batch_size","`",".","Args",":","dataset_fn",":","A","function","taking","a","`","tf.distribute.InputContext","`","instance","and","returning","a","`","tf.data.Dataset","`",".","options",":","`","tf.distribute.InputOptions","`","used","to","control","options","on","how","this","dataset","is","distributed",".","Returns",":","A","``","distributed","`","Dataset","`","``",",","which","the","caller","can","iterate","over","like","regular","datasets","."]
code: def distribute_datasets_from_function(
      self,
      dataset_fn,  # pylint: disable=useless-super-delegation
      options=None,
  ):
      """Distributes `tf.data.Dataset` instances created by calls to `dataset_fn`.
  
      `dataset_fn` will be called once for each worker in the strategy. In this
      case, we only have one worker and one device so `dataset_fn` is called
      once.
  
      The `dataset_fn` should take an `tf.distribute.InputContext` instance where
      information about batching and input replication can be accessed:
  
      ```
      def dataset_fn(input_context):
        batch_size = input_context.get_per_replica_batch_size(global_batch_size)
        d = tf.data.Dataset.from_tensors([[1.]]).repeat().batch(batch_size)
        return d.shard(
            input_context.num_input_pipelines, input_context.input_pipeline_id)
  
      inputs = strategy.distribute_datasets_from_function(dataset_fn)
  
      for batch in inputs:
        replica_results = strategy.run(replica_fn, args=(batch,))
      ```
  
      IMPORTANT: The `tf.data.Dataset` returned by `dataset_fn` should have a
      per-replica batch size, unlike `experimental_distribute_dataset`, which uses
      the global batch size.  This may be computed using
      `input_context.get_per_replica_batch_size`.
  
      Args:
        dataset_fn: A function taking a `tf.distribute.InputContext` instance and
          returning a `tf.data.Dataset`.
        options: `tf.distribute.InputOptions` used to control options on how this
          dataset is distributed.
  
      Returns:
        A "distributed `Dataset`", which the caller can iterate over like regular
        datasets.
      """
      return super(
          OneDeviceStrategy, self
      ).distribute_datasets_from_function(dataset_fn, options)
  
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 3 for calling the OneDeviceStrategy obj's underlying member method code with example usage: obj.distribute_datasets_from_function(dataset_fn, options) and returns: super