Files
b2txt25/model_training_nnn_tpu/ISSUES.md
2025-10-17 00:51:53 +08:00

37 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ISSUES
## 双重梯度裁剪
优化器级别global_clipnorm=self.args.get('grad_norm_clip_value', 0.0)第283行
手动级别tf.clip_by_global_norm第447-449行
这导致梯度被裁剪两次并且在TPU的分布式训练中可能引发内部状态冲突。
修复总结
问题根源双重梯度裁剪导致AdamW内部状态冲突 修复内容:
移除了优化器级别的梯度裁剪:删除了 global_clipnorm 参数
保留手动梯度裁剪:在 _train_step 中继续使用 tf.clip_by_global_norm
为什么会出错:
```python
# 之前:双重裁剪
optimizer = tf.keras.optimizers.AdamW(
global_clipnorm=clip_value # 第一次裁剪
)
```
```python
# 在 _train_step 中:
tf.clip_by_global_norm(gradients, clip_value) # 第二次裁剪
optimizer.apply_gradients(...) # 内部再次处理,导致冲突
现在的修复
```
```python
# 现在:只有一次裁剪
optimizer = tf.keras.optimizers.AdamW(
# 没有 global_clipnorm
)
```
```python
# 在 _train_step 中:
tf.clip_by_global_norm(gradients, clip_value) # 唯一的裁剪
optimizer.apply_gradients(...) # 正常工作
```