
Posted by Goldie Gadde and Douglas Yarrington for the TensorFlow team
. Finally, we’re releasing new experimental APIs for tf.function retracing and Keras Optimizers. Let's take a look at these new and improved features.
Improved CPU performance: oneDNN by default
We have worked with Intel to integrate the for oneDNN, which could provide up to a 4x and newer CPUs.
Users running TensorFlow with oneDNN optimizations enabled might observe slightly different numerical results from when the optimizations are off. This is because floating-point round-off approaches and order differ, and can create slight errors. If this causes issues for you, turn the optimizations off by setting TF_ENABLE_ONEDNN_OPTS=0 before running your TensorFlow programs. To enable or re-enable them, set TF_ENABLE_ONEDNN_OPTS=1 before running your TensorFlow program. To verify that the optimizations are on, look for a message beginning with "oneDNN custom operations are on" in your program log. We welcome feedback on .
DTensor is designed with the following principles at its core:
- A device-agnostic API: This allows the same model code to be used on CPU, GPU, or TPU, including models partitioned across device types.
- Multi-client execution: Removes the coordinator and leaves each task to drive its locally attached devices, allowing scaling a model with no impact to startup time.
- A global perspective vs. per-replica: Traditionally with TensorFlow, distributed model code is written around replicas, but with DTensor, model code is written from the global perspective and per replica code is generated and run by the DTensor runtime. Among other things, this means no uncertainty about whether batch normalization is happening at the global level or the per replica level.
We have developed several introductory tutorials on DTensor, from DTensor concepts to training DTensor ML models with Keras:
- rules indicate what type of arguments can be used with particular function traces. Subtyping also explains how different specific shapes are joined into a generic shape that is their supertype, to reduce the number of traces for a function.
To learn more, see the new APIs for
, and thereduce_retracingparameter oftf.function.Support for WSL2
The to make ops deterministic, and TensorFlow 2.9 improved determinism performance in
tf.datain some cases. If you want your TensorFlow models to run deterministically, just add the following to the start of your program:```
tf.keras.utils.set_random_seed(1)
tf.config.experimental.enable_op_determinism()
```
The first line sets the random seed for Python, NumPy, and TensorFlow, which is necessary for determinism. The second line makes each TensorFlow op deterministic. Note that determinism in general comes at the expense of lower performance and so your model may run slower when op determinism is enabled.
Optimized Training with Keras
In TensorFlow 2.9, we are releasing a new experimental version of the Keras Optimizer API, If for any reason you decide to stay with the old optimizer (we discourage it), then you can change your optimizer to
tf.keras.optimizers.legacy.Optimizerto avoid being automatically switched to the new optimizer in a later TensorFlow version.Use Case 2: Your work depends on third-party Keras-based optimizers (such as tensorflow_addons)
Your work should run successfully as long as the library continues to support the specific optimizer. However, if the library maintainers fail to take actions to accommodate the Keras optimizer change, your work would error out. So please stay tuned with the third-party library’s announcement, and. It is worth it, and may be easier than you think! If for any reason migration is not going to happen soon, then please replace your
tf.keras.optimizers.XXXtotf.keras.optimizers.legacy.XXXto avoid being automatically switched to the new optimizer.Use Case 4: Your work has customized gradient aggregation logic
Usually this means you are doing gradients aggregation outside the optimizer, and calling
apply_gradients()withexperimental_aggregate_gradients=False. We changed the argument name, so please change your optimizer totf.keras.optimizers.experimental.Optimizerand setskip_gradients_aggregation=True. If it errors out after making this change, please . change your optimizer totf.keras.optimizers.experimental.Optimizer. If for any reason you want to keep using the old optimizer, change your optimizer totf.keras.optimizers.legacy.Optimizer.Next steps
Check out the , follow . If you’ve built something you’d like to share, please submit it for our Community Spotlight at or post to the TensorFlow Forum. Thank you!
↗ Original-Artikel auf blog.tensorflow.org lesenVollständiger Original-BerichtAusführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf blog.tensorflow.org.
SOCIAL SHARE CARD GENERATOR