Skip to content

Commit

Permalink
Silence deprecation warning in TensorFlow 2.4 (#810)
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumekln authored Mar 12, 2021
1 parent a9f961e commit ef845dd
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion opennmt/training.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,15 @@ def _finalize_dataset(self, dataset):
# We prefer not to use experimental_distribute_dataset here because it
# sometimes fails to split the batches (noticed with tokens batch type).
dataset_fn = dataset if callable(dataset) else lambda _: dataset
return self._strategy.experimental_distribute_datasets_from_function(dataset_fn)
# TODO: clean this API usage when TensorFlow requirement is updated to >=2.4.
distribute_fn = getattr(
self._strategy, "distribute_datasets_from_function", None
)
if distribute_fn is None:
distribute_fn = (
self._strategy.experimental_distribute_datasets_from_function
)
return distribute_fn(dataset_fn)

def _forward(self, source, target, accum_steps=1, report_steps=None):
per_replica_loss = self._strategy.run(
Expand Down

0 comments on commit ef845dd

Please sign in to comment.