tensorflow/models · error · ValueError

Inside a program, we should not bind the config with a…

Error message

Inside a program, we should not bind the config with a class twice.

What it means

Double-registration guard inside bind's decorator: the same Config class is being bound to a BUILDER a second time within one process, which would silently overwrite the first binding (tracked via the module-level _BOUND set).

Solutions

  1. Bind each Config class only once per program
  2. Consolidate duplicate bind decorators on the same config class
  3. Restructure imports so the binding module is not executed twice under different names
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at official/modeling/hyperparams/base_config.py:43 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/a64decc66f6c4093. Report an issue: GitHub.

Appendix: source

Thrown at official/modeling/hyperparams/base_config.py:43

from absl import logging
import tensorflow as tf, tf_keras
import yaml

from official.modeling.hyperparams import params_dict


_BOUND = set()


def bind(config_cls):
  """Bind a class to config cls."""
  if not inspect.isclass(config_cls):
    raise ValueError('The bind decorator is supposed to apply on the class '
                     f'attribute. Received {config_cls}, not a class.')

  def decorator(builder):
    if config_cls in _BOUND:
      raise ValueError('Inside a program, we should not bind the config with a'
                       ' class twice.')
    if inspect.isclass(builder):
      config_cls._BUILDER = builder  # pylint: disable=protected-access
    elif inspect.isfunction(builder):

      def _wrapper(self, *args, **kwargs):  # pylint: disable=unused-argument
        return builder(*args, **kwargs)

      config_cls._BUILDER = _wrapper  # pylint: disable=protected-access
    else:
      raise ValueError(f'The `BUILDER` type is not supported: {builder}')
    _BOUND.add(config_cls)
    return builder

  return decorator


def _is_optional(field):

View on GitHub (pinned to e006f5f0d5)