tensorflow/models · error · ValueError

%s already registered in NEW_OPTIMIZERS_CLS.

Error message

%s already registered in NEW_OPTIMIZERS_CLS.

What it means

Error "%s already registered in NEW_OPTIMIZERS_CLS." thrown in tensorflow/models.

Source

Thrown at official/modeling/optimization/optimizer_factory.py:100

                           ],
                           use_legacy_optimizer: bool = True):
  """Register customize optimizer cls.

  The user will still need to subclass data classes in
  configs.optimization_config to be used with OptimizerFactory.

  Args:
    key: A string to that the optimizer_config_cls is registered with.
    optimizer_config_cls: A class which inherits tf_keras.optimizers.Optimizer.
    use_legacy_optimizer: A boolean that indicates if using legacy optimizers.
  """
  if use_legacy_optimizer:
    if key in LEGACY_OPTIMIZERS_CLS:
      raise ValueError('%s already registered in LEGACY_OPTIMIZERS_CLS.' % key)
    LEGACY_OPTIMIZERS_CLS[key] = optimizer_config_cls
  else:
    if key in NEW_OPTIMIZERS_CLS:
      raise ValueError('%s already registered in NEW_OPTIMIZERS_CLS.' % key)
    NEW_OPTIMIZERS_CLS[key] = optimizer_config_cls


class OptimizerFactory:
  """Optimizer factory class.

  This class builds learning rate and optimizer based on an optimization config.
  To use this class, you need to do the following:
  (1) Define optimization config, this includes optimizer, and learning rate
      schedule.
  (2) Initialize the class using the optimization config.
  (3) Build learning rate.
  (4) Build optimizer.

  This is a typical example for using this class:

  ```
  params = {

View on GitHub (pinned to e006f5f0d5)

When it happens

Trigger: Thrown at official/modeling/optimization/optimizer_factory.py:100 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/99cccd69bfff7329. Report an issue: GitHub.