主要功能改进
tf.distribution 通过
tf.distribution.experimental.ParameterServerStrategy API 引入了对 Keras 模型异步训练实验性支持。更多细节请参见下文。
MultiWorkerMirroredStrategy 不再是一个实验性 API,现在已进入稳定版本。针对命令执行失败和其他错误进行了修复。请查看具体教程,了解如何
使用 Keras 进行多任务并行训练。
tf.experimental.numpy 的新模块进行了实验性支持,此 API 不仅与 NumPy 兼容,更便于编写 TF 程序,可参阅
详细指南了解更多信息,更多细节请参见下文。
针对 Ampere 架构的 GPU 添加了 TensorFlow-32(简称TF32) 的支持,这是一种基于 Nvidia Ampere 的GPU模式,默认情况下将启用。
tf.keras.mixed_precision 已稳定,不再为实验性支持。这允许在训练过程中使用 16 位浮点数格式,在 GPU 上的性能提升高达 3 倍,在 TPU 的提升也高达 60 %。
TensorFlow pip 安装包现已使用 CUDA11 和 cuDNN 8.0.2构建。
重大改进
tensorflow::tstring/TF_TString 的连续数组。
TF_StringDecode、
TF_StringEncode 和
TF_StringEncodedSize 不再被使用,现已移除;关于 C 语言中的字符串访问/修改,请参见
core/platform/ctstring.h。
tensorflow.python、
tensorflow.core和
tensorflow.compiler 模块现在被隐藏。这些模块不再是 TensorFlow 可访问 API 的一部分。
tf.raw_ops.Max 和
tf.raw_ops.Min 不再接受类型为
tf.complex64 或
tf.complex128 的输入,因为这些操作对于复杂类型的行为没有被明确定义。
config.experimental.enable_tensor_float_32_execution(False) 来禁用 TensorFloat-32 。
默认情况下,XLA:CPU 和 XLA:GPU 设备不再注册。如果你真的需要它们,请使用 TF_XLA_FLAGS=--tf_xla_enable_xla_devices,但该标志位也将在后续版本中删除。
compile() 中的
steps_per_execution 参数已稳定,不再为实验性支持,如果您传递的是
experimental_steps_per_execution,请在你的代码中重新命名为
steps_per_execution 。这个参数控制了在调用
fit() 时,每次调用
tf.function 时要运行的批次数量。在单次
tf.function 调用中运行多个批次可以极大地提高在 TPU 中或带有大量 Python 计算的小型模型的性能。
isinstance(x, tf.Tensor) 而不是
tf.is_tensor的代码,应该改用
tf.is_tensor。
tensor.ref() 等)。
get_concrete_function 直接跟踪 Keras 符号输入的代码,应该改成直接构建匹配的
tf.TensorSpecs 并跟踪
TensorSpec对象。
tf.map_fn/
tf.cond/
tf.while_loop/control flow 作为操作层的代码,且碰巧能在 TF 2.4 之前的版本工作的代码。现在将明确地不支持这些功能。在 TF 2.4 之前,将这些操作转换为 Functional API 操作层是不可靠的,而且容易出现难以理解或无法定位的错误。
tf.rank 这样可根据输入是静态值或符号值而返回对应的类型的操作,现在这些操作将统一返回符号值。
tf.keras.Model 的代码。它假设层中只有一个位置参数。单这个假设在 TF 2.4 之前也不成立,新版本中更容易引起问题。
keras.backend.get_graph() 的代码,现在已经不需要这么做了。
在调用 Functional API Keras 模型一开始便强制进行输入形状假释的代码。这可能对一些用户造成影响,如 在 Functional 模型中创建 Input 对象时使用的形状与传递给该模型的数据的形状不匹配时。您可以通过使用正确形状的数据调用模型,或者通过放宽 Input 形状假设来解决不匹配的问题(您可以将 shape 属性设为 None ,将此作为轴(axis)以表示这是动态的),您也可以通过设置 model.input_spec = None 来完全禁止输入检查。
tf.data.experimental.service.DispatchServer 现在采用配置元组而不是单个参数。用法更新为
tf.data.experimental.service.DispatchServer(dispatcher_config)。
tf.data.experimental.service.WorkerServer 现在采用配置元组,而不是单个参数。用法更新为 tf.data.experimental.service.WorkerServer(worker_config)。
tf.distribution.Strategy.experimental_make_numpy_dataset。请使用
tf.data.Dataset.from_tensor_slices 来代替。
tf.distribut.StrategyExtended.reduce_to、
tf.distribut.StrategyExtended.batch_reduce_to、
tf.distribut.ReplicaContext.all_reduce 中的
experimental_hints 重命名为
options。
tf.distribution.experimental.CollectiveHints 重命名为
tf.distribution.experimental.CommunicationOptions。
tf.distribution.experimental.CollectiveCommunication 重命名为
tf.distribution.experimental.CommunicationImplementation。
tf.distribut.Strategy.experimental_distribute_datasets_from_function 重命名为
distribute_datasets_from_function,因为它不仅支持实验环境。
删除了 tf.distribut.Strategy.experimental_run_v2 方法,该方法在 TF 2.2 中已被废弃。
引入了 tf.quantization.quantize_and_dequantize_v2,它更新了超过范围的量化的梯度定义。要模拟 tf.quantization.quantize_and_dequantize(...)的 V1 行为,使用tf.grad_pass_through(tf.quantization.quantize_and_dequantize_v2)(...)。
如果您想详细了解 本文提及 的相关内容,请参阅以下文档。这些文档深入探讨了这篇文章中提及的许多主题:
使用 Keras 进行多任务并行训练
https://tensorflow.google.cn/tutorials/distribute/multi_worker_with_keras
tf.experimental.numpy
https://tensorflow.google.cn/api_docs/python/tf/experimental/numpy
详细指南
https://tensorflow.google.cn/guide/tf_numpy
tf.keras.mixed_precision
https://tensorflow.google.cn/api_docs/python/tf/keras/mixed_precision?version=nightly
采样模式 API
https://tensorflow.google.cn/guide/profiler#profiling_apis
指南
https://tensorflow.google.cn/lite/performance/measurement#trace_tensorflow_lite_internals_in_android
TensorFloat-32
https://blogs.nvidia.com/blog/2020/05/14/tensorfloat-32-precision-format/
了解更多请点击 “阅读原文” 访问 GitHub。