huggingface/transformers · error · ValueError

{auto_class} is not a valid auto class.

Error message

{auto_class} is not a valid auto class.

What it means

FeatureExtractionMixin.register_auto_class refuses an auto_class string that does not name an attribute of transformers.models.auto. Only real auto classes (e.g. 'AutoFeatureExtractor') can be attached so AutoFeatureExtractor can discover the custom feature extractor at runtime.

Source

Thrown at src/transformers/feature_extraction_utils.py:663

    @classmethod
    def register_for_auto_class(cls, auto_class="AutoFeatureExtractor"):
        """
        Register this class with a given auto class. This should only be used for custom feature extractors as the ones
        in the library are already mapped with `AutoFeatureExtractor`.



        Args:
            auto_class (`str` or `type`, *optional*, defaults to `"AutoFeatureExtractor"`):
                The auto class to register this new feature extractor with.
        """
        if not isinstance(auto_class, str):
            auto_class = auto_class.__name__

        import transformers.models.auto as auto_module

        if not hasattr(auto_module, auto_class):
            raise ValueError(f"{auto_class} is not a valid auto class.")

        cls._auto_class = auto_class


FeatureExtractionMixin.push_to_hub = copy_func(FeatureExtractionMixin.push_to_hub)
if FeatureExtractionMixin.push_to_hub.__doc__ is not None:
    FeatureExtractionMixin.push_to_hub.__doc__ = FeatureExtractionMixin.push_to_hub.__doc__.format(
        object="feature extractor", object_class="AutoFeatureExtractor", object_files="feature extractor file"
    )

View on GitHub (pinned to a597f97485)

Solutions

  1. Use exactly 'AutoFeatureExtractor' (the only supported auto class for feature extractors)
  2. Check hasattr(transformers.models.auto, name) before registering if the name comes from user input
  3. Update/downgrade transformers if the example you follow targets a different auto-class set

Example fix

# before
fe.register_auto_class("AutoFeatureExctrator")  # typo
# after
fe.register_auto_class("AutoFeatureExtractor")
Defensive patterns

Strategy: validation

Validate before calling

import transformers.models.auto as auto_module

def is_valid_auto_class(name: str) -> bool:
    return hasattr(auto_module, name)

Try / catch

try:
    fe.register_auto_class(auto_class)
except ValueError:
    logging.warning("unsupported auto class %r; defaulting to AutoFeatureExtractor", auto_class)
    fe.register_auto_class("AutoFeatureExtractor")

Prevention

When it happens

Trigger: Calling my_feature_extractor.register_auto_class('AutoFeatureExctrator') (typo), passing a custom class name not defined in transformers.models.auto, or passing a class object whose __name__ does not exist in the auto module.

Common situations: Typos in the class name, copy-pasting old examples that reference removed auto classes, or assuming any user-defined auto class works without it being exported from transformers.models.auto.

Related errors


AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14). Data as JSON: /api/errors/b213d14e92135baf. Report an issue: GitHub.