{"record":{"id":"aa5df2a719904b55","repo":"huggingface/transformers","slug":"the-layer-types-entries-must-be-in-allowed-laye","errorCode":null,"errorMessage":"The `layer_types` entries must be in {ALLOWED_LAYER_TYPES}","messagePattern":"The `layer_types` entries must be in (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/configuration_utils.py","lineNumber":1489,"sourceCode":"PreTrainedConfig.push_to_hub = copy_func(PreTrainedConfig.push_to_hub)\nif PreTrainedConfig.push_to_hub.__doc__ is not None:\n    PreTrainedConfig.push_to_hub.__doc__ = PreTrainedConfig.push_to_hub.__doc__.format(\n        object=\"config\", object_class=\"AutoConfig\", object_files=\"configuration file\"\n    )\n\n\n# The alias is only here for BC - we did not have the correct CamelCasing before\nPretrainedConfig = PreTrainedConfig\n\n\ndef layer_type_validation(layer_types: list[str], num_hidden_layers: int | None = None, attention: bool = True):\n    logger.warning(\n        \"`layer_type_validation` is deprecated and will be removed in v5.20. \"\n        \"Use `PreTrainedConfig.validate_layer_type` instead\"\n    )\n\n    if not all(layer_type in ALLOWED_LAYER_TYPES for layer_type in layer_types):\n        raise ValueError(f\"The `layer_types` entries must be in {ALLOWED_LAYER_TYPES}\")\n    if num_hidden_layers is not None and num_hidden_layers != len(layer_types):\n        raise ValueError(\n            f\"`num_hidden_layers` ({num_hidden_layers}) must be equal to the number of layer types \"\n            f\"({len(layer_types)})\"\n        )\n","sourceCodeStart":1471,"sourceCodeEnd":1495,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/configuration_utils.py#L1471-L1495","documentation":"ValueError from the deprecated free function layer_type_validation (warned for removal in v5.20; use PreTrainedConfig.validate_layer_type instead): a value in layer_types is not a member of ALLOWED_LAYER_TYPES (e.g. 'dense'/'linear' attention variants).","triggerScenarios":"Calling layer_type_validation([\"dense\", \"sliding\", \"full\"], ...) where 'sliding'/'full' are not in ALLOWED_LAYER_TYPES, or configs carrying a custom layer type string not yet supported by the installed version.","commonSituations":"New architectures adding a layer type before the installed Transformers version knows it (version skew); typos like 'Dense' with wrong casing.","solutions":["Use only strings from transformers.configuration_utils.ALLOWED_LAYER_TYPES (check the constant in your version).","Upgrade Transformers if the layer type is valid in a newer release.","Migrate to the instance API: config.validate_layer_type(layer_types, num_hidden_layers)."],"exampleFix":"// before\nlayer_type_validation([\"dense\", \"full\"], num_hidden_layers=2)  # ValueError\n\n// after\nlayer_type_validation([\"dense\", \"linear\"], num_hidden_layers=2)","handlingStrategy":"validation","validationCode":"from transformers.configuration_utils import ALLOWED_LAYER_TYPES\nbad = [t for t in layer_types if t not in ALLOWED_LAYER_TYPES]\nif bad:\n    raise ValueError(f\"unsupported layer types {bad}; allowed: {ALLOWED_LAYER_TYPES}\")","typeGuard":"def layer_types_are_valid(layer_types: list[str]) -> bool:\n    from transformers.configuration_utils import ALLOWED_LAYER_TYPES\n    return all(t in ALLOWED_LAYER_TYPES for t in layer_types)","tryCatchPattern":null,"preventionTips":["Import ALLOWED_LAYER_TYPES from your installed version rather than hardcoding the list.","Migrate off the deprecated layer_type_validation to config.validate_layer_type."],"tags":["config","layer-types","validation","deprecated"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}