{"record":{"id":"a59d68dc62feef65","repo":"huggingface/transformers","slug":"calling-get-mtp-config-on-a-config-containing-l","errorCode":null,"errorMessage":"Calling `get_mtp_config` on a config containing `layer_types` without `mtp_layer_types` is ambiguous","messagePattern":"Calling `get_mtp_config` on a config containing `layer_types` without `mtp_layer_types` is ambiguous","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/configuration_utils.py","lineNumber":1402,"sourceCode":"        the indexing of layers at 0).\n        \"\"\"\n        # Start from the text config\n        text_config = copy.deepcopy(self.get_text_config(decoder=True))\n        num_mtp_layers = getattr(text_config, \"num_mtp_layers\", None)\n        # In this case, raise\n        if num_mtp_layers is None:\n            raise ValueError(\"Calling `get_mtp_config` on a config without `num_mtp_layers`\")\n\n        layer_types = getattr(text_config, \"layer_types\", None)\n        mtp_layer_types = getattr(text_config, \"mtp_layer_types\", None)\n        mlp_layer_types = getattr(text_config, \"mlp_layer_types\", None)\n        mtp_mlp_layer_types = getattr(text_config, \"mtp_mlp_layer_types\", None)\n\n        # Replace the index-based fields so that we can call `XXXDecoderLayer(config, layer_idx)` with the mtp config, and create\n        # the correct layers\n        if layer_types is not None:\n            if mtp_layer_types is None:\n                raise ValueError(\n                    \"Calling `get_mtp_config` on a config containing `layer_types` without `mtp_layer_types` is ambiguous\"\n                )\n            text_config.layer_types = mtp_layer_types\n        if mlp_layer_types is not None:\n            if mtp_mlp_layer_types is None:\n                raise ValueError(\n                    \"Calling `get_mtp_config` on a config containing `mlp_layer_types` without `mtp_mlp_layer_types` is ambiguous\"\n                )\n            text_config.mlp_layer_types = mtp_mlp_layer_types\n\n        # This is needed to be correct in several places, e.g. when creating the cache\n        text_config.num_hidden_layers = num_mtp_layers\n\n        return text_config\n\n\ndef get_configuration_file(configuration_files: list[str]) -> str:\n    \"\"\"","sourceCodeStart":1384,"sourceCodeEnd":1420,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/configuration_utils.py#L1384-L1420","documentation":"ValueError from get_mtp_config: the text config defines layer_types (per-layer attention type list) but not mtp_layer_types. MTP layers restart layer indexing at 0, so the code must replace layer_types with an MTP-specific list; without mtp_layer_types it cannot know which layer types the MTP layers use.","triggerScenarios":"A config with layer_types=[\"dense\",...] and num_mtp_layers>0 but no mtp_layer_types attribute, then get_mtp_config() is called (typically during DeepSeek-V3/MTP-style model construction).","commonSituations":"Hand-written configs for hybrid-attention models that add MTP layers without filling in the MTP fields; older converted checkpoints predating the mtp_layer_types field.","solutions":["Set text_config.mtp_layer_types to a list whose length equals num_mtp_layers, e.g. [\"dense\"] * num_mtp_layers.","Copy an official MTP-capable checkpoint's config (e.g. DeepSeek-V3) as the template for these fields.","If the model genuinely has no MTP layers, remove num_mtp_layers instead of leaving it set without mtp fields."],"exampleFix":"// before\nconfig.layer_types = [\"dense\", \"linear\"] * 16\nconfig.num_mtp_layers = 1\nconfig.get_mtp_config()  # ValueError\n\n// after\nconfig.mtp_layer_types = [\"dense\"]\nconfig.get_mtp_config()","handlingStrategy":"validation","validationCode":"text_cfg = config.get_text_config(decoder=True)\nif getattr(text_cfg, \"num_mtp_layers\", None) is not None:\n    if getattr(text_cfg, \"layer_types\", None) is not None and getattr(text_cfg, \"mtp_layer_types\", None) is None:\n        text_cfg.mtp_layer_types = [\"dense\"] * text_cfg.num_mtp_layers  # or appropriate types","typeGuard":"def mtp_layer_types_are_consistent(text_cfg) -> bool:\n    return getattr(text_cfg, \"layer_types\", None) is None or getattr(text_cfg, \"mtp_layer_types\", None) is not None","tryCatchPattern":null,"preventionTips":["Whenever you set layer_types and num_mtp_layers together, always set mtp_layer_types in the same place.","Use official MTP-capable configs as templates for the full field set."],"tags":["config","mtp","layer-types"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}