# NotFoundError: Key optimizer/slot_variable not found in checkpoint

- **ID:** `tensorflow/checkpoint-optimizer-slot-variable-mismatch`
- **Domain:** tensorflow
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 88%

## Root Cause

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.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| tensorflow 2.6 | active | — | — |
| tensorflow 2.7 | active | — | — |
| tensorflow 2.8 | active | — | — |

## Workarounds

1. **Restore only the model weights using tf.train.Checkpoint(model=model).restore(path) and skip optimizer slot variables by not including optimizer in the checkpoint object. Then reinitialize the optimizer.** (90% success)
   ```
   Restore only the model weights using tf.train.Checkpoint(model=model).restore(path) and skip optimizer slot variables by not including optimizer in the checkpoint object. Then reinitialize the optimizer.
   ```
2. **Switch to the original optimizer that was used during checkpoint saving. For example, if the checkpoint was saved with Adam, use tf.keras.optimizers.Adam() during restoration.** (95% success)
   ```
   Switch to the original optimizer that was used during checkpoint saving. For example, if the checkpoint was saved with Adam, use tf.keras.optimizers.Adam() during restoration.
   ```

## Dead Ends

- **** — While it resolves the mismatch, it discards all previously trained weights. (70% fail)
- **** — Checkpoint files are protocol buffers; manual edits corrupt the file and cause DataLossError. (95% fail)
