{"record":{"id":"30384339820b3a69","repo":"huggingface/transformers","slug":"the-layer-types-entries-must-be-in-allowed-ty","errorCode":null,"errorMessage":"The `{layer_types}` entries must be in {allowed_types} but got {layers}","messagePattern":"The `(.+?)` entries must be in (.+?) but got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/configuration_utils.py","lineNumber":539,"sourceCode":"                        f\"and {vocab_size - 1}), got {value}. This may result in unexpected behavior.\"\n                    )\n\n    def validate_layer_type(self):\n        \"\"\"Check that `mlp_layer_types` and `layer_types` is correctly defined.\"\"\"\n        for allowed_types, layer_types in zip(\n            [ALLOWED_ATTN_LAYER_TYPES, ALLOWED_MLP_LAYER_TYPES], [\"layer_types\", \"mlp_layer_types\"]\n        ):\n            layers = getattr(self, layer_types, None)\n            if not (layers is not None and hasattr(self, \"num_hidden_layers\")):\n                return\n            if self.is_custom_code():\n                # Custom code may have legacy layer types that need to be remapped\n                if (remapped := remap_legacy_layer_types(layers)) != layers:\n                    # Only try setattr if layers changed in case layer_types is a read-only property\n                    setattr(self, layer_types, remapped)\n                layers = remapped\n            if not all(layer_type in allowed_types for layer_type in layers):\n                raise ValueError(f\"The `{layer_types}` entries must be in {allowed_types} but got {layers}\")\n            elif self.num_hidden_layers is not None and self.num_hidden_layers != len(layers):\n                raise ValueError(\n                    f\"`num_hidden_layers` ({self.num_hidden_layers}) must be equal to the number of `{layer_types}` \"\n                    f\"({len(layers)})\"\n                )\n\n    @property\n    def rope_scaling(self):\n        return self.rope_parameters\n\n    @rope_scaling.setter\n    def rope_scaling(self, value):\n        self.rope_parameters = value\n\n    def save_pretrained(self, save_directory: str | os.PathLike, push_to_hub: bool = False, **kwargs):\n        \"\"\"\n        Save a configuration object to the directory `save_directory`, so that it can be re-loaded using the\n        [`~PreTrainedConfig.from_pretrained`] class method.","sourceCodeStart":521,"sourceCodeEnd":557,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/configuration_utils.py#L521-L557","documentation":"ValueError from layer-type validation when any entry of layer_types or mlp_layer_types is not in the corresponding allowed set (ALLOWED_ATTN_LAYER_TYPES / ALLOWED_MLP_LAYER_TYPES). Custom-code configs first get legacy names remapped; anything still unknown after remapping is rejected. It guards against silently building layers the modeling code cannot instantiate.","triggerScenarios":"MyConfig(layer_types=['self_attn', 'banana_attn']) where 'banana_attn' is not an allowed attention layer type; passing vendor-specific layer names to a stock transformers build; stale names in a remoted config that remap_legacy_layer_types does not cover.","commonSituations":"Configs authored against forks that extended the layer-type vocabulary; version skew where allowed types were renamed; hand-edited config.json layer lists.","solutions":["Replace each invalid entry (the message lists the offending list and the allowed set) with a valid type such as 'self_attn', 'cross_attn', or the documented MLP types","Print ALLOWED_ATTN_LAYER_TYPES / ALLOWED_MLP_LAYER_TYPES from your transformers version for the exact vocabulary","For custom-code models, ensure is_custom_code() is true so legacy remapping applies, or update the names"],"exampleFix":"# before\ncfg.layer_types = ['self_attn', 'banana_attn']\n# after\ncfg.layer_types = ['self_attn', 'cross_attn']","handlingStrategy":"validation","validationCode":"from transformers.configuration_utils import ALLOWED_ATTN_LAYER_TYPES, ALLOWED_MLP_LAYER_TYPES\nassert all(t in ALLOWED_ATTN_LAYER_TYPES for t in layer_types), f'bad types: {set(layer_types) - set(ALLOWED_ATTN_LAYER_TYPES)}'","typeGuard":"def layer_types_valid(layer_types: list[str], allowed: set[str]) -> bool:\n    return all(t in allowed for t in layer_types)","tryCatchPattern":"try:\n    cfg.validate_layer_types()\nexcept ValueError as e:\n    if 'must be in' in str(e):\n        raise ValueError(f'unknown layer type; allowed: {ALLOWED_ATTN_LAYER_TYPES}') from e\n    raise","preventionTips":["Source layer-type vocabularies from the installed transformers version, not docs","Run config validation before save_pretrained on hand-edited configs"],"tags":["config","architecture","layer-types","validation"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}