Remove numpy_datasets from V2 strategies
PiperOrigin-RevId: 336741829 Change-Id: Ifa8f9869e2ced3383bf1d7cd5d115d137eeadea9
This commit is contained in:
parent
e5a3292a48
commit
1782a45957
@ -52,6 +52,8 @@
|
||||
to be 0. To simulate the V1 the behavior of
|
||||
tf.quantization.quantize_and_dequantize(...) use
|
||||
tf.grad_pass_through(tf.quantization.quantize_and_dequantize_v2)(...).
|
||||
* `tf.distribute.Strategy.experimental_make_numpy_dataset` is removed. Please
|
||||
use `tf.data.Dataset.from_tensor_slices` instead.
|
||||
|
||||
## Known Caveats
|
||||
|
||||
|
@ -206,7 +206,6 @@ py_test(
|
||||
"//tensorflow/python/autograph/core:test_lib",
|
||||
"//tensorflow/python/data/ops:dataset_ops",
|
||||
"//tensorflow/python/distribute/cluster_resolver:cluster_resolver_lib",
|
||||
"//third_party/py/numpy",
|
||||
],
|
||||
)
|
||||
|
||||
|
@ -681,9 +681,7 @@ class StrategyBase(object):
|
||||
[see the
|
||||
guide](https://www.tensorflow.org/guide/distributed_training#using_tfdistributestrategy_with_custom_training_loops):
|
||||
|
||||
* Start by either creating a `tf.data.Dataset` normally or using
|
||||
`tf.distribute.experimental_make_numpy_dataset` to make a dataset out of
|
||||
a `numpy` array.
|
||||
* Start by creating a `tf.data.Dataset` normally.
|
||||
* Use `tf.distribute.Strategy.experimental_distribute_dataset` to convert
|
||||
a `tf.data.Dataset` to something that produces "per-replica" values.
|
||||
If you want to manually specify how the dataset should be partitioned
|
||||
@ -908,39 +906,6 @@ class StrategyBase(object):
|
||||
return self.extended._make_input_fn_iterator( # pylint: disable=protected-access
|
||||
input_fn, replication_mode=replication_mode)
|
||||
|
||||
@deprecation.deprecated(
|
||||
"2020-09-30", "Please use tf.data.Dataset.from_tensor_slices instead")
|
||||
def experimental_make_numpy_dataset(self, numpy_input):
|
||||
"""Makes a `tf.data.Dataset` from a numpy array.
|
||||
|
||||
This avoids adding `numpy_input` as a large constant in the graph,
|
||||
and copies the data to the machine or machines that will be processing
|
||||
the input.
|
||||
|
||||
Note that you will likely need to use `experimental_distribute_dataset`
|
||||
with the returned dataset to further distribute it with the strategy.
|
||||
|
||||
Example:
|
||||
|
||||
>>> strategy = tf.distribute.MirroredStrategy()
|
||||
>>> numpy_input = np.ones([10], dtype=np.float32)
|
||||
>>> dataset = strategy.experimental_make_numpy_dataset(numpy_input)
|
||||
>>> dataset
|
||||
<TensorSliceDataset shapes: (), types: tf.float32>
|
||||
>>> dataset = dataset.batch(2)
|
||||
>>> dist_dataset = strategy.experimental_distribute_dataset(dataset)
|
||||
|
||||
Args:
|
||||
numpy_input: a nest of NumPy input arrays that will be converted into a
|
||||
dataset. Note that the NumPy arrays are stacked, as that is normal
|
||||
`tf.data.Dataset` behavior.
|
||||
|
||||
Returns:
|
||||
A `tf.data.Dataset` representing `numpy_input`.
|
||||
"""
|
||||
return self.extended.experimental_make_numpy_dataset(
|
||||
numpy_input, session=None)
|
||||
|
||||
@doc_controls.do_not_generate_docs # DEPRECATED: TF 1.x only
|
||||
def experimental_run(self, fn, input_iterator=None):
|
||||
"""DEPRECATED TF 1.x ONLY."""
|
||||
|
@ -19,7 +19,6 @@ from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
from absl.testing import parameterized
|
||||
import numpy as np
|
||||
|
||||
from tensorflow.python.autograph.core import converter_testing
|
||||
from tensorflow.python.data.ops import dataset_ops
|
||||
@ -99,10 +98,6 @@ class _TestExtended(distribute_lib.StrategyExtendedV1):
|
||||
del reduce_op, destinations, experimental_hints
|
||||
return value
|
||||
|
||||
def _experimental_make_numpy_dataset(self, numpy_input, session):
|
||||
del session
|
||||
return dataset_ops.DatasetV2.from_tensor_slices(numpy_input)
|
||||
|
||||
def _experimental_run_steps_on_iterator(self, fn, iterator, iterations,
|
||||
initial_loop_values=None):
|
||||
# TODO(tomhennigan) This is missing many things (e.g. ctx.run_op).
|
||||
@ -346,13 +341,6 @@ class TestStrategyTest(test.TestCase):
|
||||
self.assertEqual(self.evaluate(x), self.evaluate(x_r))
|
||||
self.assertEqual(self.evaluate(y), self.evaluate(y_r))
|
||||
|
||||
@_run_in_and_out_of_scope
|
||||
def testExperimentalMakeNumpyDataset(self, dist):
|
||||
numpy_input = np.ones([10], dtype=np.float32)
|
||||
dataset = dist.experimental_make_numpy_dataset(numpy_input)
|
||||
self.assertEqual(
|
||||
self.evaluate(dataset.reduce(0., lambda a, b: a + b)), 10.)
|
||||
|
||||
@_run_in_and_out_of_scope
|
||||
def testExperimentalRunStepsOnIterator(self, dist):
|
||||
all_inputs = []
|
||||
|
@ -28,6 +28,7 @@ from tensorflow.core.protobuf import config_pb2
|
||||
from tensorflow.core.util import event_pb2
|
||||
from tensorflow.python.client import session as session_lib
|
||||
from tensorflow.python.data.ops import dataset_ops
|
||||
from tensorflow.python.distribute import distribute_lib
|
||||
from tensorflow.python.distribute import distribute_utils
|
||||
from tensorflow.python.distribute import distribution_strategy_context as ds_context
|
||||
from tensorflow.python.distribute import reduce_util
|
||||
@ -429,6 +430,8 @@ class DistributionTestBase(test.TestCase):
|
||||
self.assertEqual((1,) * len(global_step_tensors), global_step_values)
|
||||
|
||||
def _test_numpy_dataset(self, strategy, session=None, run_in_function=False):
|
||||
if not isinstance(strategy, distribute_lib.StrategyV1):
|
||||
self.skipTest("n/a: V1 only")
|
||||
cached_session = session or self.cached_session()
|
||||
with strategy.scope(), cached_session as sess:
|
||||
x = np.asarray([[1, 2], [6, 12], [2, 4], [5, 10], [3, 6], [4, 8]])
|
||||
|
@ -48,10 +48,6 @@ tf_class {
|
||||
name: "experimental_local_results"
|
||||
argspec: "args=[\'self\', \'value\'], varargs=None, keywords=None, defaults=None"
|
||||
}
|
||||
member_method {
|
||||
name: "experimental_make_numpy_dataset"
|
||||
argspec: "args=[\'self\', \'numpy_input\'], varargs=None, keywords=None, defaults=None"
|
||||
}
|
||||
member_method {
|
||||
name: "experimental_run"
|
||||
argspec: "args=[\'self\', \'fn\', \'input_iterator\'], varargs=None, keywords=None, defaults=[\'None\'], "
|
||||
|
@ -48,10 +48,6 @@ tf_class {
|
||||
name: "experimental_local_results"
|
||||
argspec: "args=[\'self\', \'value\'], varargs=None, keywords=None, defaults=None"
|
||||
}
|
||||
member_method {
|
||||
name: "experimental_make_numpy_dataset"
|
||||
argspec: "args=[\'self\', \'numpy_input\'], varargs=None, keywords=None, defaults=None"
|
||||
}
|
||||
member_method {
|
||||
name: "experimental_run"
|
||||
argspec: "args=[\'self\', \'fn\', \'input_iterator\'], varargs=None, keywords=None, defaults=[\'None\'], "
|
||||
|
@ -47,10 +47,6 @@ tf_class {
|
||||
name: "experimental_local_results"
|
||||
argspec: "args=[\'self\', \'value\'], varargs=None, keywords=None, defaults=None"
|
||||
}
|
||||
member_method {
|
||||
name: "experimental_make_numpy_dataset"
|
||||
argspec: "args=[\'self\', \'numpy_input\'], varargs=None, keywords=None, defaults=None"
|
||||
}
|
||||
member_method {
|
||||
name: "experimental_run"
|
||||
argspec: "args=[\'self\', \'fn\', \'input_iterator\'], varargs=None, keywords=None, defaults=[\'None\'], "
|
||||
|
@ -52,10 +52,6 @@ tf_class {
|
||||
name: "experimental_local_results"
|
||||
argspec: "args=[\'self\', \'value\'], varargs=None, keywords=None, defaults=None"
|
||||
}
|
||||
member_method {
|
||||
name: "experimental_make_numpy_dataset"
|
||||
argspec: "args=[\'self\', \'numpy_input\'], varargs=None, keywords=None, defaults=None"
|
||||
}
|
||||
member_method {
|
||||
name: "experimental_replicate_to_logical_devices"
|
||||
argspec: "args=[\'self\', \'tensor\'], varargs=None, keywords=None, defaults=None"
|
||||
|
@ -48,10 +48,6 @@ tf_class {
|
||||
name: "experimental_local_results"
|
||||
argspec: "args=[\'self\', \'value\'], varargs=None, keywords=None, defaults=None"
|
||||
}
|
||||
member_method {
|
||||
name: "experimental_make_numpy_dataset"
|
||||
argspec: "args=[\'self\', \'numpy_input\'], varargs=None, keywords=None, defaults=None"
|
||||
}
|
||||
member_method {
|
||||
name: "experimental_run"
|
||||
argspec: "args=[\'self\', \'fn\', \'input_iterator\'], varargs=None, keywords=None, defaults=[\'None\'], "
|
||||
|
@ -48,10 +48,6 @@ tf_class {
|
||||
name: "experimental_local_results"
|
||||
argspec: "args=[\'self\', \'value\'], varargs=None, keywords=None, defaults=None"
|
||||
}
|
||||
member_method {
|
||||
name: "experimental_make_numpy_dataset"
|
||||
argspec: "args=[\'self\', \'numpy_input\'], varargs=None, keywords=None, defaults=None"
|
||||
}
|
||||
member_method {
|
||||
name: "experimental_run"
|
||||
argspec: "args=[\'self\', \'fn\', \'input_iterator\'], varargs=None, keywords=None, defaults=[\'None\'], "
|
||||
|
@ -48,10 +48,6 @@ tf_class {
|
||||
name: "experimental_local_results"
|
||||
argspec: "args=[\'self\', \'value\'], varargs=None, keywords=None, defaults=None"
|
||||
}
|
||||
member_method {
|
||||
name: "experimental_make_numpy_dataset"
|
||||
argspec: "args=[\'self\', \'numpy_input\'], varargs=None, keywords=None, defaults=None"
|
||||
}
|
||||
member_method {
|
||||
name: "experimental_run"
|
||||
argspec: "args=[\'self\', \'fn\', \'input_iterator\'], varargs=None, keywords=None, defaults=[\'None\'], "
|
||||
|
@ -48,10 +48,6 @@ tf_class {
|
||||
name: "experimental_local_results"
|
||||
argspec: "args=[\'self\', \'value\'], varargs=None, keywords=None, defaults=None"
|
||||
}
|
||||
member_method {
|
||||
name: "experimental_make_numpy_dataset"
|
||||
argspec: "args=[\'self\', \'numpy_input\'], varargs=None, keywords=None, defaults=None"
|
||||
}
|
||||
member_method {
|
||||
name: "experimental_run"
|
||||
argspec: "args=[\'self\', \'fn\', \'input_iterator\'], varargs=None, keywords=None, defaults=[\'None\'], "
|
||||
|
Loading…
Reference in New Issue
Block a user