当使用tf.keras.mixed_precision.experimental时,如何使Tensorflow检查点在次要版本之间兼容?

2024-06-01 00:05:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我是Tensorflow的新手,所以我正在学习模型保存/加载方案。我正在使用一个库,它提供了一个保存在Tensorflow 2.2中的模型检查点(.index和.data文件)。我想使用相同的库加载这个检查点,但是使用Tensorflow 2.6,这样它就可以在Google Colab中运行。当我在Tensorflow 2.2(以及相关的CUDA版本)中加载检查点时,模型运行良好。但是,如果我在Tensorflow 2.6(最新CUDA版本)中加载相同的检查点,模型运行时不会抛出任何错误,但输出完全不同

需要注意的是,该库确实使用了一些实验性API,这些API可能会导致版本兼容性问题(如官方指南here中所述)。特别是,它广泛使用了tensorflow.keras.mixed_precision.experimental,以及tf.config.experimental.set_memory_growthtf.data.experimental.copy_to_devicetf.data.experimental.AUTOTUNE。直观地说,混合精度。实验性似乎会显著影响小型版本的重量节省/装载

我确实收到了以下警告。如果我切换到使用tf.keras.mixed_precision(无实验),它们将消失,但是模型输出仍然完全错误

WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/keras/mixed_precision/loss_scale.py:52: DynamicLossScale.init (from tensorflow.python.training.experimental.loss_scale) is deprecated and will be removed in a future version.

Instructions for updating: Use tf.keras.mixed_precision.LossScaleOptimizer instead. LossScaleOptimizer now has all the functionality of DynamicLossScale

WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/tensorflow/python/training/tracking/util.py:1361: NameBasedSaverStatus.init (from tensorflow.python.training.tracking.util) is deprecated and will be removed in a future version.

Instructions for updating: Restoring a name-based tf.train.Saver checkpoint using the object-based restore API. This mode uses global names to match variables, and so is somewhat fragile. It also adds new restore ops to the graph each time it is called when graph building. Prefer re-encoding training checkpoints in the object-based format: run save() on the object-based saver (the same one this message is coming from) and use that checkpoint in the future.

有没有关于保存混合精度模型检查点的建议,以使其在次要版本之间兼容?或者处理一般的实验性Tensorflow API


Tags: andthe模型版本apiistftensorflow