提交 f28b07dc 编写于 作者: J Jay Shi 提交者: TensorFlower Gardener

[tf.data] Add `OptimizeDatasetOp` to most input pipelines. Enable graph...

[tf.data] Add `OptimizeDatasetOp` to most input pipelines. Enable graph rewrites only when there are optimizations to be applied to the pipelines.

PiperOrigin-RevId: 326312484
Change-Id: Ifdf1274db7fd8f07bb6c1815152f6f5938797de2
上级 05dd0d32
......@@ -106,6 +106,13 @@ void OptimizeDatasetOp::MakeDataset(OpKernelContext* ctx, DatasetBase* input,
}
}
// If there are no optimizations to be applied, directly return the input.
if (optimizations.empty()) {
*output = input;
input->Ref();
return;
}
auto config_factory = [this, &optimizations]() {
return CreateConfig(optimizations, optimization_configs_);
};
......
......@@ -377,19 +377,20 @@ class DatasetV2(collections_abc.Iterable, tracking_base.Trackable,
graph_rewrites = options._graph_rewrites()
graph_rewrite_configs = options._graph_rewrite_configs()
# pylint: enable=protected-access
if graph_rewrites.enabled or graph_rewrites.default:
if self._has_captured_ref():
if self._has_captured_ref():
if graph_rewrites.enabled or graph_rewrites.default:
warnings.warn(
"tf.data graph rewrites are not compatible with tf.Variable. "
"The following rewrites will be disabled: %s. To enable "
"rewrites, use resource variables instead by calling "
"`tf.enable_resource_variables()` at the start of the program." %
", ".join(graph_rewrites.enabled + graph_rewrites.default))
else:
dataset = _OptimizeDataset(dataset, graph_rewrites.enabled,
graph_rewrites.disabled,
graph_rewrites.default,
graph_rewrite_configs)
elif (graph_rewrites.enabled or graph_rewrites.default or
(options.experimental_optimization.apply_default_optimizations # pylint: disable=g-bool-id-comparison
is not False)):
dataset = _OptimizeDataset(dataset, graph_rewrites.enabled,
graph_rewrites.disabled,
graph_rewrites.default, graph_rewrite_configs)
# (3) Apply autotune options
autotune, algorithm, cpu_budget = options._autotune_settings() # pylint: disable=protected-access
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册