class_docstr: An iterator over `tf.distribute.DistributedDataset`.
  
  `tf.distribute.DistributedIterator` is the primary mechanism for enumerating
  elements of a `tf.distribute.DistributedDataset`. It supports the Python
  Iterator protocol, which means it can be iterated over using a for-loop or by
  fetching individual elements explicitly via `get_next()`.
  
  You can create a `tf.distribute.DistributedIterator` by calling `iter` on
  a `tf.distribute.DistributedDataset` or creating a python loop over a
  `tf.distribute.DistributedDataset`.
  
  Visit the [tutorial](https://www.tensorflow.org/tutorials/distribute/input)
  on distributed input for more examples and caveats.
class_docstr_tok: ["An","iterator","over","`","tf.distribute.DistributedDataset","`",".","`","tf.distribute.DistributedIterator","`","is","the","primary","mechanism","for","enumerating","elements","of","a","`","tf.distribute.DistributedDataset","`",".","It","supports","the","Python","Iterator","protocol",",","which","means","it","can","be","iterated","over","using","a","for-loop","or","by","fetching","individual","elements","explicitly","via","`","get_next","(",")","`",".","You","can","create","a","`","tf.distribute.DistributedIterator","`","by","calling","`","iter","`","on","a","`","tf.distribute.DistributedDataset","`","or","creating","a","python","loop","over","a","`","tf.distribute.DistributedDataset","`",".","Visit","the","[","tutorial","]","(","https",":","\/\/www.tensorflow.org\/tutorials\/distribute\/input",")","on","distributed","input","for","more","examples","and","caveats","."]
docstr: Returns a `tf.experimental.Optional` that contains the next value for all replicas.
  
  If the `tf.distribute.DistributedIterator` has reached the end of the
  sequence, the returned `tf.experimental.Optional` will have no value.
  
  Example usage:
  
  >>> strategy = tf.distribute.MirroredStrategy(["GPU:0", "GPU:1"])
  >>> global_batch_size = 2
  >>> steps_per_loop = 2
  >>> dataset = tf.data.Dataset.range(10).batch(global_batch_size)
  >>> distributed_iterator = iter(
  ...     strategy.experimental_distribute_dataset(dataset))
  >>> def step_fn(x):
  ...   # train the model with inputs
  ...   return x
  >>> @tf.function
  ... def train_fn(distributed_iterator):
  ...   for _ in tf.range(steps_per_loop):
  ...     optional_data = distributed_iterator.get_next_as_optional()
  ...     if not optional_data.has_value():
  ...       break
  ...     per_replica_results = strategy.run(step_fn, args=(optional_data.get_value(),))
  ...     tf.print(strategy.experimental_local_results(per_replica_results))
  >>> train_fn(distributed_iterator)
  ... # ([0 1], [2 3])
  ... # ([4], [])
  
  Returns:
    An `tf.experimental.Optional` object representing the next value from the
    `tf.distribute.DistributedIterator` (if it has one) or no value.
docstr_tok: ["Returns","a","`","tf.experimental.Optional","`","that","contains","the","next","value","for","all","replicas",".","If","the","`","tf.distribute.DistributedIterator","`","has","reached","the","end","of","the","sequence",",","the","returned","`","tf.experimental.Optional","`","will","have","no","value",".","Example","usage",":",">",">",">","strategy","=","tf.distribute.MirroredStrategy","(","[","``","GPU:0","''",",","``","GPU:1","''","]",")",">",">",">","global_batch_size","=","2",">",">",">","steps_per_loop","=","2",">",">",">","dataset","=","tf.data.Dataset.range","(","10",")",".batch","(","global_batch_size",")",">",">",">","distributed_iterator","=","iter","(","...","strategy.experimental_distribute_dataset","(","dataset",")",")",">",">",">","def","step_fn","(","x",")",":","...","#","train","the","model","with","inputs","...","return","x",">",">",">","@","tf.function","...","def","train_fn","(","distributed_iterator",")",":","...","for","_","in","tf.range","(","steps_per_loop",")",":","...","optional_data","=","distributed_iterator.get_next_as_optional","(",")","...","if","not","optional_data.has_value","(",")",":","...","break","...","per_replica_results","=","strategy.run","(","step_fn",",","args=","(","optional_data.get_value","(",")",",",")",")","...","tf.print","(","strategy.experimental_local_results","(","per_replica_results",")",")",">",">",">","train_fn","(","distributed_iterator",")","...","#","(","[","0","1","]",",","[","2","3","]",")","...","#","(","[","4","]",",","[","]",")","Returns",":","An","`","tf.experimental.Optional","`","object","representing","the","next","value","from","the","`","tf.distribute.DistributedIterator","`","(","if","it","has","one",")","or","no","value","."]
code: def get_next_as_optional(self):
      # pylint: disable=line-too-long
      """Returns a `tf.experimental.Optional` that contains the next value for all replicas.
  
      If the `tf.distribute.DistributedIterator` has reached the end of the
      sequence, the returned `tf.experimental.Optional` will have no value.
  
      Example usage:
  
      >>> strategy = tf.distribute.MirroredStrategy(["GPU:0", "GPU:1"])
      >>> global_batch_size = 2
      >>> steps_per_loop = 2
      >>> dataset = tf.data.Dataset.range(10).batch(global_batch_size)
      >>> distributed_iterator = iter(
      ...     strategy.experimental_distribute_dataset(dataset))
      >>> def step_fn(x):
      ...   # train the model with inputs
      ...   return x
      >>> @tf.function
      ... def train_fn(distributed_iterator):
      ...   for _ in tf.range(steps_per_loop):
      ...     optional_data = distributed_iterator.get_next_as_optional()
      ...     if not optional_data.has_value():
      ...       break
      ...     per_replica_results = strategy.run(step_fn, args=(optional_data.get_value(),))
      ...     tf.print(strategy.experimental_local_results(per_replica_results))
      >>> train_fn(distributed_iterator)
      ... # ([0 1], [2 3])
      ... # ([4], [])
  
      Returns:
        An `tf.experimental.Optional` object representing the next value from the
        `tf.distribute.DistributedIterator` (if it has one) or no value.
      """
      # pylint: enable=line-too-long
      raise NotImplementedError(
          "get_next_as_optional() not implemented in descendants"
      )
  
imports: from tensorflow.python.util.tf_export import tf_export
  from tensorflow.tools.docs import doc_controls
label_desc: Use image node_id 3 for calling the DistributedIteratorInterface obj's underlying member method code with example usage: obj.get_next_as_optional() without return types