TensorFlow
machine learning
model saving
limitations
deep learning

TensorFlow Saver has 5 models limit

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

Introduction

TensorFlow's old saver behavior is often misunderstood as having a hard limit of five models. In reality, the usual default was simply to keep five recent checkpoints unless you changed the retention setting, so the "limit" is a configurable cleanup policy rather than a fundamental TensorFlow restriction.

What the old Saver default actually meant

In TensorFlow 1 style code, tf.train.Saver used a max_to_keep parameter. If you did not specify it, older examples often defaulted to keeping five recent checkpoints.

That means:

  • TensorFlow could save more than five times
  • it just removed older checkpoints according to the retention policy

A basic TensorFlow 1 style example:

python
1import tensorflow as tf
2
3tf.compat.v1.disable_eager_execution()
4
5v = tf.Variable(0.0, name="weight")
6saver = tf.compat.v1.train.Saver(max_to_keep=10)
7
8with tf.compat.v1.Session() as sess:
9    sess.run(tf.compat.v1.global_variables_initializer())
10    for step in range(12):
11        sess.run(v.assign(float(step)))
12        saver.save(sess, "ckpts/model", global_step=step)

This saves repeatedly while retaining up to ten recent checkpoints instead of five.

There is no hard five-checkpoint ceiling

If you want more retained checkpoints, set a larger value:

python
saver = tf.compat.v1.train.Saver(max_to_keep=20)

If you want to keep all checkpoints, some older workflows used:

python
saver = tf.compat.v1.train.Saver(max_to_keep=None)

That can work, but keeping everything forever is usually a storage management problem waiting to happen.

Modern TensorFlow uses checkpoint managers

In TensorFlow 2 style workflows, CheckpointManager is the more modern equivalent:

python
1import tensorflow as tf
2
3model = tf.keras.Sequential([
4    tf.keras.layers.Dense(1, input_shape=(3,))
5])
6
7optimizer = tf.keras.optimizers.Adam()
8ckpt = tf.train.Checkpoint(model=model, optimizer=optimizer)
9manager = tf.train.CheckpointManager(
10    ckpt,
11    directory="tf2_ckpts",
12    max_to_keep=7
13)
14
15path = manager.save()
16print(path)

Again, max_to_keep is a retention policy, not a model-count law of nature.

Decide retention based on recovery needs

How many checkpoints to keep should depend on your workflow:

  • short experiments may only need a few
  • long-running training may need more rollback points
  • regulated or audited workflows may need named milestone checkpoints

A common practical pattern is:

  • keep a small rolling window of recent checkpoints
  • separately export milestone or best-model artifacts

That avoids keeping every transient training state forever.

Best checkpoint versus every checkpoint

Many teams do not actually need every recent state. They need one or both of:

  • the latest checkpoint for resume
  • the best checkpoint by validation metric

That should affect your retention policy. Storing many nearly identical checkpoints is often unnecessary if the restore strategy is well defined.

Storage and cleanup tradeoffs

Checkpoint files can be large. Aggressive retention settings may create:

  • disk pressure
  • slower artifact sync
  • harder cleanup
  • confusion about which checkpoint should be deployed

So the default of five was not arbitrary nonsense. It was a conservative operational default for keeping recent progress without uncontrolled storage growth.

Common Pitfalls

The most common mistake is interpreting "only five checkpoints remain on disk" as a hard TensorFlow limitation. Another is increasing retention without thinking about disk usage, especially in long-running jobs with frequent save intervals. Developers also often keep many checkpoints but fail to distinguish latest, best, and deployable artifacts. Mixing TensorFlow 1 saver examples with TensorFlow 2 checkpoint managers is another source of confusion. Finally, some training scripts save too frequently, so even a moderate retention count creates unnecessary I O overhead and clutter.

Summary

  • The old five-checkpoint behavior was usually just the default max_to_keep policy.
  • It was not a hard TensorFlow limit on the number of saves.
  • In TensorFlow 1, configure retention through tf.train.Saver(max_to_keep=...).
  • In TensorFlow 2, use tf.train.CheckpointManager(max_to_keep=...).
  • Choose retention based on resume, rollback, and best-model needs.
  • Treat checkpoint count as an operational storage policy, not a framework restriction.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

All Rights Reserved.