# WARNING:tensorflow:最近 5 次对 <function train_step> 的调用中有 5 次触发了 tf.function 重追踪

- **ID:** `tensorflow/graph-mode-retracing-warning`
- **领域:** tensorflow
- **类别:** runtime_error
- **错误码:** `RETRACE`
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

tf.function 被反复重追踪，因为输入张量的形状或数据类型在调用之间发生变化，导致性能下降。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| tensorflow 2.11.0 | active | — | — |
| tensorflow 2.12.0 | active | — | — |
| tensorflow 2.13.0 | active | — | — |

## 解决方案

1. ```
   Ensure all input tensors have consistent shapes and dtypes across batches. Pad variable-length inputs to a fixed shape using `tf.keras.preprocessing.sequence.pad_sequences`.
   ```

## 无效尝试

- **** — This loses the performance benefits of graph execution and may cause other errors. (90% 失败率)
- **** — This can mask the issue but may lead to incorrect gradients or memory errors. (85% 失败率)
