tensorflow/models · error · ValueError

The Config has been locked. No change is allowed.

Error message

The Config has been locked. No change is allowed.

What it means

Lock guard in Config.__setattr__/lock path: the Config instance has been locked (via lock()) and is treated as immutable, so any subsequent attribute mutation is rejected. This fires when code tries to modify a frozen/shared config after validation.

Solutions

  1. Call override() on an unlocked copy (e.g. copy_and_override) instead of mutating a locked config
  2. Perform modifications before lock()/validate is invoked
  3. Re-create the config from params if changes are needed
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

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

        logging.warning(
            "The list/tuple don't match the value dictionaries provided. Thus, "
            'the list/tuple is determined by the type annotation and '
            'values provided. This is error-prone.')
        self.__dict__[k] = self._import_config(v, subconfig_type)
      else:
        self.__dict__[k] = self._import_config(v, subconfig_type)
    else:
      self.__dict__[k] = self._import_config(v, subconfig_type)

  def __setattr__(self, k, v):
    if k == 'BUILDER' or k == '_BUILDER':
      raise AttributeError('`BUILDER` is a property and `_BUILDER` is the '
                           'reserved class attribute. We should only assign '
                           '`_BUILDER` at the class level.')

    if k not in self.RESERVED_ATTR:
      if getattr(self, '_locked', False):
        raise ValueError('The Config has been locked. ' 'No change is allowed.')
    self._set(k, v)

  def _override(self, override_dict, is_strict=True):
    """Overrides same method in ParamsDict.

    Also called by ParamsDict methods.

    Args:
      override_dict: dictionary to write to .
      is_strict: If True, not allows to add new keys.

    Raises:
      KeyError: overriding reserved keys or keys not exist (is_strict=True).
    """
    for k, v in sorted(override_dict.items()):
      if k in self.RESERVED_ATTR:
        raise KeyError('The key {!r} is internally reserved. '
                       'Can not be overridden.'.format(k))

View on GitHub (pinned to e006f5f0d5)