# WARNING:tensorflow:5 out of the last 5 calls to <function train_step> triggered tf.function retracing

- **ID:** `tensorflow/graph-mode-retracing-warning`
- **Domain:** tensorflow
- **Category:** runtime_error
- **Error Code:** `RETRACE`
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The tf.function is being retraced repeatedly because the input tensor shapes or dtypes change between calls, which degrades performance.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| tensorflow 2.11.0 | active | — | — |
| tensorflow 2.12.0 | active | — | — |
| tensorflow 2.13.0 | active | — | — |

## Workarounds

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`.** (85% success)
   ```
   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`.
   ```

## Dead Ends

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