TensorFlow 2.10.0
Release 2.10.0
Breaking Changes
- Causal attention in
keras.layers.Attentionandkeras.layers.AdditiveAttentionis now specified in thecall()method via theuse_causal_maskargument (rather than in the constructor), for consistency with other layers. - Some files in
tensorflow/python/traininghave been moved totensorflow/python/trackingandtensorflow/python/checkpoint. Please update your imports accordingly, the old files will be removed in Release 2.11. tf.keras.optimizers.experimental.Optimizerwill graduate in Release 2.11, which meanstf.keras.optimizers.Optimizerwill be an alias oftf.keras.optimizers.experimental.Optimizer. The currenttf.keras.optimizers.Optimizerwill continue to be supported astf.keras.optimizers.legacy.Optimizer, e.g.,tf.keras.optimizers.legacy.Adam. Most users won't be affected by this change, but please check the API doc if any API used in your workflow is changed or deprecated, and make adaptions. If you decide to keep using the old optimizer, please explicitly change your optimizer totf.keras.optimizers.legacy.Optimizer.- RNG behavior change for
tf.keras.initializers. Keras initializers will now use stateless random ops to generate random numbers.- Both seeded and unseeded initializers will always generate the same values every time they are called (for a given variable shape). For unseeded initializers (
seed=None), a random seed will be created and assigned at initializer creation (different initializer instances get different seeds). - An unseeded initializer will raise a warning if it is reused (called) multiple times. This is because it would produce the same values each time, which may not be intended.
- Both seeded and unseeded initializers will always generate the same values every time they are called (for a given variable shape). For unseeded initializers (
Deprecations
- The C++
tensorflow::Codeandtensorflow::Statuswill become aliases of respectivelyabsl::StatusCodeandabsl::Statusin some future release.- Use
tensorflow::OkStatus()instead oftensorflow::Status::OK(). - Stop constructing
Statusobjects fromtensorflow::error::Code. - One MUST NOT access
tensorflow::errors::Codefields. Accessingtensorflow::error::Codefields is fine.- Use the constructors such as
tensorflow::errors:InvalidArgumentto create status using an error code without accessing it. - Use the free functions such as
tensorflow::errors::IsInvalidArgumentif needed. - In the last resort, use e.g.
static_cast<tensorflow::errors::Code>(error::Code::INVALID_ARGUMENT)orstatic_cast<int>(code)for comparisons.
- Use the constructors such as
- Use
tensorflow::StatusOrwill also become in the future alias toabsl::StatusOr, so useStatusOr::valueinstead ofStatusOr::ConsumeValueOrDie.
Major Features and Improvements
-
tf.lite:- New operations supported:
- tflite SelectV2 now supports 5D.
- tf.einsum is supported with multiple unknown shapes.
- tf.unsortedsegmentprod op is supported.
- tf.unsortedsegmentmax op is supported.
- tf.unsortedsegmentsum op is supported.
- Updates to existing operations:
- tfl.scatter_nd now supports I1 for update arg.
- Upgrade Flatbuffers v2.0.5 from v1.12.0
- New operations supported:
-
tf.keras:EinsumDenselayer is moved from experimental to core. Its import path is moved fromtf.keras.layers.experimental.EinsumDensetotf.keras.layers.EinsumDense.- Added
tf.keras.utils.audio_dataset_from_directoryutility to easily generate audio classification datasets from directories of.wavfiles. - Added
subset="both"support intf.keras.utils.image_dataset_from_directory,tf.keras.utils.text_dataset_from_directory, andaudio_dataset_from_directory, to be used with thevalidation_splitargument, for returning both dataset splits at once, as a tuple. - Added
tf.keras.utils.split_datasetutility to split aDatasetobject or a list/tuple of arrays into twoDatasetobjects (e.g. train/test). - Added step granularity to
BackupAndRestorecallback for handling distributed training failures & restarts. The training state can now be restored at the exact epoch and step at which it was previously saved before failing. - Added
tf.keras.dtensor.experimental.optimizers.AdamW. This optimizer is similar as the existingkeras.optimizers.experimental.AdamW, and works in the DTensor training use case. - Improved masking support for
tf.keras.layers.MultiHeadAttention.- Implicit masks for
query,keyandvalueinputs will automatically be used to compute a correct attention mask for the layer. These padding masks will be combined with anyattention_maskpassed in directly when calling the layer. This can be used withtf.keras.layers.Embeddingwithmask_zero=Trueto automatically infer a correct padding mask. - Added a
use_causal_maskcall time arugment to the layer. Passinguse_causal_mask=Truewill compute a causal attention mask, and optionally combine it with anyattention_maskpassed in directly when calling the layer.
- Implicit masks for
- Added
ignore_classargument in the lossSparseCategoricalCrossentropyand metricsIoUandMeanIoU, to specify a class index to be ignored during loss/metric computation (e.g. a background/void class). - Added
tf.keras.models.experimental.SharpnessAwareMinimization. This class implements the sharpness-aware minimization technique, which boosts model performance on various tasks, e.g., ResNet on image classification.
-
tf.data:- Added support for cross-trainer data caching in tf.data service. This saves computation resources when concurrent training jobs train from the same dataset. See (https://www.tensorflow.org/api_docs/python/tf/data/experimental/service#sharing_tfdata_service_with_concurrent_trainers) for more details.
- Added
dataset_idtotf.data.experimental.service.register_dataset. If provided,tf.dataservice will use the provided ID for the dataset. If the dataset ID already exists, no new dataset will be registered. This is useful if multiple training jobs need to use the same dataset for training. In this case, users should callregister_datasetwith the samedataset_id. - Added a new field,
inject_prefetch, totf.data.experimental.OptimizationOptions. If it is set toTrue,tf.datawill now automatically add aprefetchtransformation to datasets that end in synchronous transformations. This enables data generation to be overlapped with data consumption. This may cause a small increase in memory usage due to buffering. To enable this behavior, setinject_prefetch=Trueintf.data.experimental.OptimizationOptions. - Added a new value to
tf.data.Options.autotune.autotune_algorithm: STAGE_BASED. If the autotune algorithm is set to STAGE_BASED, then it runs a new algorithm that can get the same performance with lower CPU/memory usage. - Added
tf.data.experimental.from_list, a new API for creatingDatasets from lists of elements.
-
tf.distribute:- Added
tf.distribute.experimental.PreemptionCheckpointHandlerto handle worker preemption/maintenance and cluster-wise consistent error reporting fortf.distribute.MultiWorkerMirroredStrategy. Specifically, for the type of interruption with advance notice, it automatically saves a checkpoint, exits the program without raising an unrecoverable error, and restores the progress when training restarts.
- Added
-
tf.math:- Added
tf.math.approx_max_kandtf.math.approx_min_kwhich are the optimized alternatives totf.math.top_kon TPU. The performance difference range from 8 to 100 times depending on the size of k. When running on CPU and GPU, a non-optimized XLA kernel is used.
- Added
-
tf.train:- Added
tf.train.TrackableViewwhich allows users to inspect the TensorFlow Trackable object (e.g.tf.Module, Keras Layers and models).
- Added
-
tf.vectorized_map:- Added an optional parameter:
warn. This parameter controls whether or not warnings will be printed when operations in the providedfnfall back to a while loop.
- Added an optional parameter:
-
XLA:
- MWMS is now compilable with XLA.
- Compute Library for the Arm® Architecture (ACL) is supported for aarch64 CPU XLA runtime
-
CPU performance optimizations:
- x86 CPUs: oneDNN bfloat16 auto-mixed precision grappler graph optimization pass has been renamed from
auto_mixed_precision_mkltoauto_mixed_precision_onednn_bfloat16. See example usage here. - aarch64 CPUs: Experimental performance optimizations from Compute Library for the Arm® Architecture (ACL) are available through oneDNN in the default Linux aarch64 package (
pip install tensorflow).- The optimizations are disabled by default.
- Set the environment variable
TF_ENABLE_ONEDNN_OPTS=1to enable the optimizations. Setting the variable to 0 or unsetting it will disable the optimizations. - These optimizations can yield slightly different numerical results from when they are off due to floating-point round-off errors from different computation approaches and orders.
- To verify that the optimizations are on, look for a message with "oneDNN custom operations are on" in the log. If the exact phrase is not there, it means they are off.
- x86 CPUs: oneDNN bfloat16 auto-mixed precision grappler graph optimization pass has been renamed from
Bug Fixes and Other Changes
-
New argument
experimental_device_ordinalinLogicalDeviceConfigurationto control the order of logical devices. (GPU only) -
tf.keras:- Changed the TensorBoard tag names produced by the
tf.keras.callbacks.TensorBoardcallback, so that summaries logged automatically for model weights now include either a/histogramor/imagesuffix in their tag names, in order to prevent tag name collisions across summary types.
- Changed the TensorBoard tag names produced by the
-
When running on GPU (with cuDNN version 7.6.3 or later),
tf.nn.depthwise_conv2dbackprop tofilter(and therefore alsotf.keras.layers.DepthwiseConv2D) now operate deterministically (andtf.errors.UnimplementedErroris no longer thrown) when op-determinism has been enabled viatf.config.experimental.enable_op_determinism. This closes issue 47174. -
tf.random- Added
tf.random.experimental.stateless_shuffle, a stateless version oftf.random.shuffle.
- Added
Security
- Fixes a
CHECKfailure in tf.reshape caused by overflows (CVE-2022-35934) - Fixes a
CHECKfailure inSobolSamplecaused by missing validation (CVE-2022-35935) - Fixes an OOB read in
Gather_ndop in TF Lite (CVE-2022-35937) - Fixes a
CHECKfailure inTensorListReservecaused by missing validation (CVE-2022-35960) - Fixes an OOB write in
Scatter_ndop in TF Lite (CVE-2022-35939) - Fixes an integer overflow in
RaggedRangeOp(CVE-2022-35940) - Fixes a
CHECKfailure inAvgPoolOp(CVE-2022-35941) - Fixes a
CHECKfailures inUnbatchGradOp(CVE-2022-35952) - Fixes a segfault TFLite converter on per-channel quantized transposed convolutions (CVE-2022-36027)
- Fixes a
CHECKfailures inAvgPool3DGrad(CVE-2022-35959) - Fixes a
CHECKfailures inFractionalAvgPoolGrad(CVE-2022-35963) - Fixes a segfault in
BlockLSTMGradV2(CVE-2022-35964) - Fixes a segfault in
LowerBoundandUpperBound(CVE-2022-35965) - Fixes a segfault in
QuantizedAvgPool(CVE-2022-35966) - Fixes a segfault in
QuantizedAdd(CVE-2022-35967) - Fixes a
CHECKfail inAvgPoolGrad(CVE-2022-35968) - Fixes a
CHECKfail inConv2DBackpropInput(CVE-2022-35969) - Fixes a segfault in
QuantizedInstanceNorm(CVE-2022-35970) - Fixes a
CHECKfail inFakeQuantWithMinMaxVars(CVE-2022-35971) - Fixes a segfault in
Requantize(CVE-2022-36017) - Fixes a segfault in
QuantizedBiasAdd(CVE-2022-35972) - Fixes a
CHECKfail inFakeQuantWithMinMaxVarsPerChannel(CVE-2022-36019) - Fixes a segfault in
QuantizedMatMul(CVE-2022-35973) - Fixes a segfault in
QuantizeDownAndShrinkRange(CVE-2022-35974) - Fixes segfaults in
QuantizedReluandQuantizedRelu6(CVE-2022-35979) - Fixes a
CHECKfail inFractionalMaxPoolGrad(CVE-2022-35981) - Fixes a
CHECKfail inRaggedTensorToVariant(CVE-2022-36018) - Fixes a
CHECKfail inQuantizeAndDequantizeV3(CVE-2022-36026) - Fixes a segfault in
SparseBincount(CVE-2022-35982) - Fixes a
CHECKfail inSaveandSaveSlices(CVE-2022-35983) - Fixes a
CHECKfail inParameterizedTruncatedNormal(CVE-2022-35984) - Fixes a
CHECKfail inLRNGrad(CVE-2022-35985) - Fixes a segfault in
RaggedBincount(CVE-2022-35986) - Fixes a
CHECKfail inDenseBincount(CVE-2022-35987) - Fixes a
CHECKfail intf.linalg.matrix_rank(CVE-2022-35988) - Fixes a
CHECKfail inMaxPool(CVE-2022-35989) - Fixes a
CHECKfail inConv2DBackpropInput(CVE-2022-35999) - Fixes a
CHECKfail inEmptyTensorList(CVE-2022-35998) - Fixes a
CHECKfail intf.sparse.cross(CVE-2022-35997) - Fixes a floating point exception in
Conv2D(CVE-2022-35996) - Fixes a
CHECKfail inAudioSummaryV2(CVE-2022-35995) - Fixes a
CHECKfail inCollectiveGather(CVE-2022-35994) - Fixes a
CHECKfail inSetSize(CVE-2022-35993) - Fixes a
CHECKfail inTensorListFromTensor(CVE-2022-35992) - Fixes a
CHECKfail inTensorListScatterandTensorListScatterV2(CVE-2022-35991) - Fixes a
CHECKfail inFakeQuantWithMinMaxVarsPerChannelGradient(CVE-2022-35990) - Fixes a
CHECKfail inFakeQuantWithMinMaxVarsGradient(CVE-2022-36005) - Fixes a
CHECKfail intf.random.gamma(CVE-2022-36004) - Fixes a
CHECKfail inRandomPoissonV2(CVE-2022-36003) - Fixes a
CHECKfail inUnbatch(CVE-2022-36002) - Fixes a
CHECKfail inDrawBoundingBoxes(CVE-2022-36001) - Fixes a
CHECKfail inEig(CVE-2022-36000) - Fixes a null dereference on MLIR on empty function attributes (CVE-2022-36011)
- Fixes an assertion failure on MLIR empty edge names (CVE-2022-36012)
- Fixes a null-dereference in
mlir::tfg::GraphDefImporter::ConvertNodeDef(CVE-2022-36013) - Fixes a null-dereference in
mlir::tfg::TFOp::nameAttr(CVE-2022-36014) - Fixes an integer overflow in math ops (CVE-2022-36015)
- Fixes a
CHECK-fail intensorflow::full_type::SubstituteFromAttrs(CVE-2022-36016) - Fixes an OOB read in
Gather_ndop in TF Lite Micro (CVE-2022-35938)
Thanks to our Contributors
This release contains contributions from many people at Google, as well as:
Abolfazl Shahbazi, Adam Lanicek, Amin Benarieb, andreii, Andrew Fitzgibbon, Andrew Goodbody, angerson, Ashiq Imran, Aurélien Geron, Banikumar Maiti (Intel Aipg), Ben Barsdell, Ben Mares, bhack, Bhavani Subramanian, Bill Schnurr, Byungsoo Oh, Chandra Sr Potula, Chengji Yao, Chris Carpita, Christopher Bate, chunduriv, Cliff Woolley, Cliffs Dover, Cloud Han, Code-Review-Doctor, DEKHTIARJonathan, Deven Desai, Djacon, Duncan Riach, fedotoff, fo40225, Frederic Bastien, gadagashwini, Gauri1 Deshpande, guozhong.zhuang, Hui Peng, James Gerity, Jason Furmanek, Jonathan Dekhtiar, Jueon Park, Kaixi Hou, Kanvi Khanna, Keith Smiley, Koan-Sin Tan, Kulin Seth, kushanam, Learning-To-Play, Li-Wen Chang, lipracer, liuyuanqiang, Louis Sugy, Lucas David, Lukas Geiger, Mahmoud Abuzaina, Marius Brehler, Maxiwell S. Garcia, mdfaijul, Meenakshi Venkataraman, Michal Szutenberg, Michele Di Giorgio, Mickaël Salamin, Nathan John Sircombe, Nathan Luehr, Neil Girdhar, Nils Reichardt, Nishidha Panpaliya, Nobuo Tsukamoto, Om Thakkar, Patrice Vignola, Philipp Hack, Pooya Jannaty, Prianka Liz Kariat, pshiko, Rajeshwar Reddy T, rdl4199, Rohit Santhanam, Rsanthanam-Amd, Sachin Muradi, Saoirse Stewart, Serge Panev, Shu Wang, Srinivasan Narayanamoorthy, Stella Stamenova, Stephan Hartmann, Sunita Nadampalli, synandi, Tamas Bela Feher, Tao Xu, Thibaut Goetghebuer-Planchon, Trevor Morris, Xiaoming (Jason) Cui, Yimei Sun, Yong Tang, Yuanqiang Liu, Yulv-Git, Zhoulong Jiang, ZihengJiang