MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _select_training_loop

Method _select_training_loop

tensorflow/python/keras/engine/training.py:482–532  ·  view source on GitHub ↗

Select training loop for fit/eval/predict based on the inputs.

(self, inputs)

Source from the content-addressed store, hash-verified

480 self._run_eagerly = value
481
482 def _select_training_loop(self, inputs):
483 """Select training loop for fit/eval/predict based on the inputs."""
484 # TODO(kaftan) or TODO(scottzhu): This check should eventually be nicely
485 # integrated into the data adapters in the v2 loop. We can't do this yet
486 # because we currently have to fall back for unhandled data types.
487 if isinstance(inputs, (iterator_ops.Iterator,
488 iterator_ops.IteratorV2)):
489 raise ValueError('For performance reasons Keras `fit`, `evaluate` and'
490 '`predict` accept tf.data `Datasets` as input but not '
491 'iterators that have been manually generated from '
492 'Datasets by users. Please directly pass in the '
493 'original `Dataset` object instead of passing in '
494 '`iter(dataset)`.')
495
496 # Experiment training loop with default DS path.
497 if context.executing_eagerly() and self._experimental_run_tf_function:
498 try:
499 valid_adapter = data_adapter.select_data_adapter(inputs, None)
500 except ValueError as data_failure_exception:
501 valid_adapter = None
502 logging.warning('Falling back from v2 loop because of error: '
503 '%s' % data_failure_exception)
504 if valid_adapter:
505 if self._in_multi_worker_mode():
506 return training_distributed.DistributionMultiWorkerTrainingLoop(
507 training_v2.Loop())
508 else:
509 return training_v2.Loop()
510
511 # Case 1: distribution strategy.
512 if self._distribution_strategy:
513 if self._in_multi_worker_mode():
514 return training_distributed.DistributionMultiWorkerTrainingLoop(
515 training_distributed.DistributionSingleWorkerTrainingLoop())
516 else:
517 return training_distributed.DistributionSingleWorkerTrainingLoop()
518
519 # Case 2: generator-like. Input is Python generator, or Sequence object,
520 # or a non-distributed Dataset or iterator in eager execution.
521 if data_utils.is_generator_or_sequence(inputs):
522 return training_generator.GeneratorOrSequenceTrainingLoop()
523 if training_utils.is_eager_dataset_or_iterator(inputs):
524 return training_generator.EagerDatasetOrIteratorTrainingLoop()
525
526 # Case 3: Symbolic tensors or Numpy array-like.
527 # This includes Datasets and iterators in graph mode (since they
528 # generate symbolic tensors).
529 if self.run_eagerly:
530 return training_generator.GeneratorLikeTrainingLoop()
531 else:
532 return training_arrays.ArrayLikeTrainingLoop()
533
534 def fit(self,
535 x=None,

Callers 3

fitMethod · 0.95
evaluateMethod · 0.95
predictMethod · 0.95

Calls 3

_in_multi_worker_modeMethod · 0.95
executing_eagerlyMethod · 0.80
LoopMethod · 0.80

Tested by

no test coverage detected