tensorflow/models · error · ValueError

The ParamsDict has been locked. No change is allowed.

Error message

The ParamsDict has been locked. No change is allowed.

What it means

Lock guard in ParamsDict.__setattr__: the instance was locked (lock()) making it immutable, so the attribute set is refused. Fires when mutating a validated or shared ParamsDict.

Solutions

  1. Mutate a copy created before locking, or override the config before lock()
  2. Use replace_params_dict/copy patterns instead of mutating locked instances
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at official/modeling/hyperparams/params_dict.py:119 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/d8f7ba97960ee20c. Report an issue: GitHub.

Appendix: source

Thrown at official/modeling/hyperparams/params_dict.py:119

    """Sets the value of the existing key.

    Note that this does not allow directly defining a new key. Use the
    `override` method with `is_strict=False` instead.

    Args:
      k: the key string.
      v: the value to be used to set the key `k`.

    Raises:
      KeyError: if k is not defined in the ParamsDict.
    """
    if k not in ParamsDict.RESERVED_ATTR:
      if k not in self.__dict__.keys():
        raise KeyError('The key `%{}` does not exist. '
                       'To extend the existing keys, use '
                       '`override` with `is_strict` = True.'.format(k))
      if self._locked:
        raise ValueError('The ParamsDict has been locked. '
                         'No change is allowed.')
    self._set(k, v)

  def __getattr__(self, k):
    """Gets the value of the existing key.

    Args:
      k: the key string.

    Returns:
      the value of the key.

    Raises:
      AttributeError: if k is not defined in the ParamsDict.
    """
    if k not in self.__dict__.keys():
      raise AttributeError('The key `{}` does not exist. '.format(k))
    return self.__dict__[k]

View on GitHub (pinned to e006f5f0d5)