tensorflow
data_error
ai_generated
true
NotFoundError: 检查点中未找到键 optimizer/slot_variable
NotFoundError: Key optimizer/slot_variable not found in checkpoint
ID: tensorflow/checkpoint-optimizer-slot-variable-mismatch
88%修复率
87%置信度
1证据数
2023-04-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| tensorflow 2.6 | active | — | — | — |
| tensorflow 2.7 | active | — | — | — |
| tensorflow 2.8 | active | — | — | — |
根因分析
检查点使用不同的优化器(例如 Adam)保存,但恢复时模型使用了不同的优化器(例如 SGD),因此插槽变量(如 m、v)缺失。
English
The checkpoint was saved with a different optimizer (e.g., Adam) but is being restored with a model that uses a different optimizer (e.g., SGD), so the slot variables (e.g., m, v) are missing.
官方文档
https://www.tensorflow.org/guide/checkpoint#loading_checkpoints解决方案
-
使用 tf.train.Checkpoint(model=model).restore(path) 仅恢复模型权重,并跳过优化器插槽变量(不在检查点对象中包含优化器)。然后重新初始化优化器。
-
切换到保存检查点时使用的原始优化器。例如,如果检查点使用 Adam 保存,则在恢复时使用 tf.keras.optimizers.Adam()。
无效尝试
常见但无效的做法:
-
70% 失败
While it resolves the mismatch, it discards all previously trained weights.
-
95% 失败
Checkpoint files are protocol buffers; manual edits corrupt the file and cause DataLossError.