tensorflow warning - Found untraced functions such as lstm_cell_6_layer_call_and_return_conditional_losses
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
The warning Found untraced functions such as lstm_cell_6_layer_call_and_return_conditional_losses appears when saving a TensorFlow/Keras model that contains LSTM layers (or other RNN layers). It means TensorFlow's tracing mechanism could not capture certain internal functions of the LSTM cell during the tf.saved_model.save() or model.save() process. These untraced functions are typically internal loss-computation and call methods. The warning is usually harmless for inference but can affect model serving if those code paths are needed.
The Warning
This appears during:
model.save("model_path")with SavedModel formattf.saved_model.save(model, "model_path")model.save("model.keras")in some TensorFlow versions
Why This Happens
When TensorFlow saves a model in SavedModel format, it traces all functions to convert them to a computation graph. LSTM cells have multiple internal methods (call, return conditional losses, etc.) that TensorFlow's tracer may not visit during normal forward-pass tracing:
The LSTM cell internally has methods like layer_call_and_return_conditional_losses that handle regularization losses. If the model does not use regularization, these paths are never executed during tracing and remain untraced.
Fix 1: Call the Model Before Saving
Ensure the model has been called with sample input before saving so TensorFlow traces all execution paths:
Fix 2: Save in Keras Format Instead
The .keras format (or legacy .h5) saves model weights and config without graph tracing, avoiding the warning entirely:
Use the Keras format when you plan to load the model in Python/Keras. Use SavedModel format when you need to serve with TensorFlow Serving or convert to TFLite.
Fix 3: Suppress the Warning
If the warning does not affect your use case (inference-only deployment), suppress it:
This does not fix the underlying issue — it hides the message. Only do this after confirming your saved model loads and produces correct predictions.
Fix 4: Use input_signature for Custom Models
For custom models or subclassed models, providing an explicit input_signature helps TensorFlow trace all paths:
The input_signature decorator tells TensorFlow the exact shape and type, enabling complete tracing.
Verifying the Saved Model Works
If predictions match, the untraced functions were not needed for inference.
Which Layers Trigger This Warning
| Layer | Triggers Warning | Reason |
| LSTM | Yes | Multiple internal cell methods |
| GRU | Yes | Similar RNN cell structure |
| SimpleRNN | Sometimes | Simpler cell, fewer untraced paths |
| Bidirectional(LSTM) | Yes | Wraps LSTM, doubles untraced functions |
| Dense | No | Simple layer, fully traced |
| Conv2D | No | No conditional internal paths |
Common Pitfalls
- Ignoring the warning for TF Serving: If you deploy with TensorFlow Serving and your serving signature calls one of the untraced functions (e.g., for loss computation during fine-tuning), loading will fail. Always test the saved model in your deployment environment.
- Saving before training: Saving an untrained model may produce more untraced functions because some code paths are only exercised during training. Train (or at least call
model.fitfor one step) before saving. - Version-specific behavior: The warning message and which functions are untraced change between TensorFlow versions. Upgrading TensorFlow (especially to 2.13+) reduces the number of untraced functions as Keras tracing has improved.
- Confusing warning with error: This is a warning, not an error. The model is still saved and typically works correctly for inference. Do not restructure your model architecture solely to eliminate this warning.
- Multiple LSTM layers amplify the warning: Each LSTM layer generates its own set of untraced functions (
lstm_cell_0,lstm_cell_1, etc.). The warning lists them all, which looks alarming but follows the same pattern for each layer.
Summary
- The warning occurs when saving models with LSTM/GRU layers in SavedModel format
- TensorFlow cannot trace internal cell methods that are not exercised during the save process
- The warning is usually harmless for inference — verify by loading and testing predictions
- Save in
.kerasformat instead of SavedModel to avoid the warning entirely - Call the model with sample input before saving to maximize traced function coverage
- For production deployment with TF Serving, test the saved model end-to-end

