{"record":{"id":"4bd2ba65be4ccf55","repo":"huggingface/transformers","slug":"model-cls-name-has-no-config-class-or-model-4bd2ba","errorCode":null,"errorMessage":"Model {cls.__name__} has no config_class or model_type.","messagePattern":"Model (.+?) has no config_class or model_type\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/integrations/hub_kernels.py","lineNumber":857,"sourceCode":"        original_init(self, *args, **kwargs)\n        children = [getattr(self, name) for name in child_names]\n        kernel_instance = kernel_cls(*children)\n        setattr(self, child_names[0], kernel_instance)\n        for name in child_names[1:]:\n            setattr(self, name, nn.Identity())\n\n    patched_cls = type(f\"Fused{parent_cls.__name__}\", (parent_cls,), {\"__init__\": patched_init})\n    patched_cls.__qualname__ = f\"Fused{parent_cls.__qualname__}\"\n    return patched_cls\n\n\ndef register_kernel_replacements_and_fusions(\n    cls: \"type[PreTrainedModel]\",\n    config: \"PretrainedConfig\",\n    kernel_config: \"KernelConfig\",\n) -> None:\n    if not hasattr(cls, \"config_class\") or not hasattr(cls.config_class, \"model_type\"):\n        raise ValueError(f\"Model {cls.__name__} has no config_class or model_type.\")\n    model_type = cls.config_class.model_type\n\n    patch_mapping: dict[str, type] = {}\n    new_mapping: dict = {}\n\n    # We might need to instantiate the model on meta device.\n    # We do it lazily, only if we encounter a fused kernel.\n    meta_model = None\n\n    for layer_name, hub_repo in kernel_config.kernel_mapping.items():\n        if isinstance(hub_repo, (str, tuple)):\n            hub_repo = {None: hub_repo}\n\n        if isinstance(hub_repo, dict):\n            if len(hub_repo.values()) != 1:\n                raise ValueError(\n                    f\"Expected exactly one kernel repo regardless of device/mode specificity, got {hub_repo}\"\n                )","sourceCodeStart":839,"sourceCodeEnd":875,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/integrations/hub_kernels.py#L839-L875","documentation":"Before wiring hub-kernel replacements/fusions into a model class, `register_kernel_replacements_and_fusions` needs `cls.config_class.model_type` to build the correct patch mapping. If the model class has no `config_class` attribute, or the config class lacks `model_type`, this ValueError fires — it indicates the object passed as a model class is not a standard `PreTrainedModel` subclass.","triggerScenarios":"Calling `register_kernel_replacements_and_fusions(cls, config, kernel_config)` with a custom layer/class that never set `config_class`, or a dynamically created model class where `config_class` points at a bare `PretrainedConfig` without a `model_type`; also reachable when the class-level `config_class` was shadowed or deleted.","commonSituations":"Kernelizing custom or experimental model implementations that skip the `config_class` annotation; wrapping a modeling class with `type(...)` dynamically (fused-class generation) without re-attaching `config_class`; passing a layer class instead of the top-level model class.","solutions":["Ensure the class is a proper PreTrainedModel subclass with `config_class = MyConfig` and `MyConfig.model_type = \"my_model\"` set.","Pass the top-level model class (the one registered with AutoModel), not an individual layer class.","If you generated the class dynamically, copy `config_class` from the parent: `patched_cls.config_class = parent_cls.config_class`."],"exampleFix":"# before\nclass MyModel(nn.Module):  # no config_class\n    ...\nregister_kernel_replacements_and_fusions(MyModel, config, kernel_config)  # ValueError\n\n# after\nfrom transformers import PreTrainedModel, PretrainedConfig\n\nclass MyConfig(PretrainedConfig):\n    model_type = \"my_model\"\n\nclass MyModel(PreTrainedModel):\n    config_class = MyConfig\n\nregister_kernel_replacements_and_fusions(MyModel, config, kernel_config)","handlingStrategy":"validation","validationCode":"assert hasattr(cls, \"config_class\") and hasattr(getattr(cls, \"config_class\", None), \"model_type\"), (\n    f\"{cls.__name__} must be a PreTrainedModel subclass with config_class.model_type\"\n)","typeGuard":"def is_kernelizable_model_class(cls) -> bool:\n    return hasattr(cls, \"config_class\") and hasattr(cls.config_class, \"model_type\")","tryCatchPattern":"try:\n    register_kernel_replacements_and_fusions(cls, config, kernel_config)\nexcept ValueError as e:\n    if \"no config_class or model_type\" in str(e):\n        cls.config_class = type(config)  # attach a proper config class, then retry\n        if not hasattr(cls.config_class, \"model_type\"):\n            cls.config_class.model_type = config.model_type\n        register_kernel_replacements_and_fusions(cls, config, kernel_config)\n    else:\n        raise","preventionTips":["Always define config_class and model_type on custom PreTrainedModel subclasses.","When creating classes dynamically, copy config_class from the parent class.","Unit-test that is_kernelizable_model_class(model_cls) passes before kernelizing."],"tags":["kernels","model-registration","config-class","custom-model"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}