tensorflow/models · error · ValueError
The bind decorator is supposed to apply on the class…
Error message
The bind decorator is supposed to apply on the class attribute. Received {config_cls}, not a class. What it means
Decorator misuse guard in base_config.bind: the function was applied to something that is not a class (e.g. a method or instance), but bind requires the config_cls argument to be a Config subclass to attach the builder to it.
Solutions
- Apply @bind(MyConfigClass) to a builder function/class, passing the Config subclass itself
- Fix call sites that pass an instance or module instead of the class
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at official/modeling/hyperparams/base_config.py:38 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/a1898e7ac233925b.
Report an issue: GitHub.
Appendix: source
Thrown at official/modeling/hyperparams/base_config.py:38
import inspect
import types
import typing
from typing import Any, List, Mapping, Optional, Type, Union
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 builderView on GitHub (pinned to e006f5f0d5)