Apply options, such as optimization configuration, to the dataset.
(self)
| 276 | return options |
| 277 | |
| 278 | def _apply_options(self): |
| 279 | """Apply options, such as optimization configuration, to the dataset.""" |
| 280 | |
| 281 | dataset = self |
| 282 | options = self.options() |
| 283 | if options.experimental_threading is not None: |
| 284 | t_options = options.experimental_threading |
| 285 | if t_options.max_intra_op_parallelism is not None: |
| 286 | dataset = _MaxIntraOpParallelismDataset( |
| 287 | dataset, t_options.max_intra_op_parallelism) |
| 288 | if t_options.private_threadpool_size is not None: |
| 289 | dataset = _PrivateThreadPoolDataset(dataset, |
| 290 | t_options.private_threadpool_size) |
| 291 | # pylint: disable=protected-access |
| 292 | static_optimizations = options._static_optimizations() |
| 293 | static_optimization_configs = options._static_optimization_configs() |
| 294 | # pylint: enable=protected-access |
| 295 | if static_optimizations: |
| 296 | if self._has_captured_ref(): |
| 297 | warnings.warn( |
| 298 | "tf.data static optimizations are not compatible with tf.Variable. " |
| 299 | "The following optimizations will be disabled: %s. To enable " |
| 300 | "optimizations, use resource variables instead by calling " |
| 301 | "`tf.enable_resource_variables()` at the start of the program." % |
| 302 | ", ".join(static_optimizations)) |
| 303 | else: |
| 304 | dataset = _OptimizeDataset(dataset, static_optimizations, |
| 305 | static_optimization_configs) |
| 306 | |
| 307 | autotune = True |
| 308 | algorithm = AutotuneAlgorithm.HILL_CLIMB |
| 309 | cpu_budget = 0 # Indicates that all CPU cores should be used. |
| 310 | if options.experimental_optimization is not None: |
| 311 | if options.experimental_optimization.autotune is False: # pylint: disable=g-bool-id-comparison |
| 312 | autotune = False |
| 313 | if options.experimental_optimization.autotune_algorithm is not None: |
| 314 | algorithm = options.experimental_optimization.autotune_algorithm |
| 315 | if options.experimental_optimization.autotune_cpu_budget is not None: |
| 316 | cpu_budget = options.experimental_optimization.autotune_cpu_budget |
| 317 | |
| 318 | if autotune: |
| 319 | dataset = _ModelDataset(dataset, algorithm, cpu_budget) |
| 320 | |
| 321 | if options.experimental_stats and options.experimental_stats.aggregator: # pylint: disable=line-too-long |
| 322 | dataset = _SetStatsAggregatorDataset( # pylint: disable=protected-access |
| 323 | dataset, options.experimental_stats.aggregator, |
| 324 | options.experimental_stats.prefix, |
| 325 | options.experimental_stats.counter_prefix) |
| 326 | |
| 327 | # TODO: DEKHTIARJonathan - Re-enable once stable. |
| 328 | # if os.environ.get("TF_ENABLE_AUTOMATIC_GPU_PREFETCHING", "0") == "1": |
| 329 | # from tensorflow.python.distribute import distribution_strategy_context |
| 330 | # if not distribution_strategy_context.has_strategy(): |
| 331 | # if (options.experimental_optimization.prefetch_to_device is not None and |
| 332 | # os.environ.get("TF_DISABLE_AUTOMATIC_GPU_PREFETCHING", "0") == "0"): |
| 333 | # from tensorflow.python.data.experimental.ops import prefetching_ops |
| 334 | # prefetch_device = options.experimental_optimization.prefetch_to_device |
| 335 | # |
no test coverage detected