tensorflow/models · error · ValueError
Optimizer has to be instance ofoptimization.ExponentialMovin
Error message
Optimizer has to be instance ofoptimization.ExponentialMovingAverage forEMACheckpointing action
What it means
Error "Optimizer has to be instance ofoptimization.ExponentialMovingAverage forEMACheckpointing action" thrown in tensorflow/models.
Source
Thrown at official/core/actions.py:101
"""
def __init__(self,
export_dir: str,
optimizer: tf_keras.optimizers.Optimizer,
checkpoint: tf.train.Checkpoint,
max_to_keep: int = 1):
"""Initializes the instance.
Args:
export_dir: `str` for the export directory of the EMA average weights.
optimizer: `tf_keras.optimizers.Optimizer` optimizer instance used for
training. This will be used to swap the model weights with the average
weigths.
checkpoint: `tf.train.Checkpoint` instance.
max_to_keep: `int` for max checkpoints to keep in ema_checkpoints subdir.
"""
if not isinstance(optimizer, optimization.ExponentialMovingAverage):
raise ValueError('Optimizer has to be instance of'
'optimization.ExponentialMovingAverage for'
'EMACheckpointing action')
export_dir = os.path.join(export_dir, 'ema_checkpoints')
tf.io.gfile.makedirs(os.path.dirname(export_dir))
self._optimizer = optimizer
self._checkpoint = checkpoint
self._checkpoint_manager = tf.train.CheckpointManager(
checkpoint,
directory=export_dir,
max_to_keep=max_to_keep,
checkpoint_name='average_weights')
def __call__(self, output: orbit.runner.Output):
"""Swaps model weights, and saves the checkpoint.
Args:
output: The train or eval output.View on GitHub (pinned to e006f5f0d5)
When it happens
Trigger: Thrown at official/core/actions.py:101 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of tensorflow/models@e006f5f0d5 (2026-08-24).
Data as JSON: /api/errors/07def8679e73a52f.
Report an issue: GitHub.