huggingface/transformers · error · ValueError
Calling `get_mtp_config` on a config containing `layer_types
Error message
Calling `get_mtp_config` on a config containing `layer_types` without `mtp_layer_types` is ambiguous
What it means
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.
Source
Thrown at src/transformers/configuration_utils.py:1402
the indexing of layers at 0).
"""
# Start from the text config
text_config = copy.deepcopy(self.get_text_config(decoder=True))
num_mtp_layers = getattr(text_config, "num_mtp_layers", None)
# In this case, raise
if num_mtp_layers is None:
raise ValueError("Calling `get_mtp_config` on a config without `num_mtp_layers`")
layer_types = getattr(text_config, "layer_types", None)
mtp_layer_types = getattr(text_config, "mtp_layer_types", None)
mlp_layer_types = getattr(text_config, "mlp_layer_types", None)
mtp_mlp_layer_types = getattr(text_config, "mtp_mlp_layer_types", None)
# Replace the index-based fields so that we can call `XXXDecoderLayer(config, layer_idx)` with the mtp config, and create
# the correct layers
if layer_types is not None:
if mtp_layer_types is None:
raise ValueError(
"Calling `get_mtp_config` on a config containing `layer_types` without `mtp_layer_types` is ambiguous"
)
text_config.layer_types = mtp_layer_types
if mlp_layer_types is not None:
if mtp_mlp_layer_types is None:
raise ValueError(
"Calling `get_mtp_config` on a config containing `mlp_layer_types` without `mtp_mlp_layer_types` is ambiguous"
)
text_config.mlp_layer_types = mtp_mlp_layer_types
# This is needed to be correct in several places, e.g. when creating the cache
text_config.num_hidden_layers = num_mtp_layers
return text_config
def get_configuration_file(configuration_files: list[str]) -> str:
"""View on GitHub (pinned to a597f97485)
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.
Example fix
// before config.layer_types = ["dense", "linear"] * 16 config.num_mtp_layers = 1 config.get_mtp_config() # ValueError // after config.mtp_layer_types = ["dense"] config.get_mtp_config()
Defensive patterns
Strategy: validation
Validate before calling
text_cfg = config.get_text_config(decoder=True)
if getattr(text_cfg, "num_mtp_layers", None) is not None:
if getattr(text_cfg, "layer_types", None) is not None and getattr(text_cfg, "mtp_layer_types", None) is None:
text_cfg.mtp_layer_types = ["dense"] * text_cfg.num_mtp_layers # or appropriate types Type guard
def mtp_layer_types_are_consistent(text_cfg) -> bool:
return getattr(text_cfg, "layer_types", None) is None or getattr(text_cfg, "mtp_layer_types", None) is not None Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- The `{layer_types}` entries must be in {allowed_types} but g
- `num_hidden_layers` ({self.num_hidden_layers}) must be equal
- Calling `get_mtp_config` on a config without `num_mtp_layers
- The `layer_types` entries must be in {ALLOWED_LAYER_TYPES}
- `num_hidden_layers` ({num_hidden_layers}) must be equal to t
AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14).
Data as JSON: /api/errors/a59d68dc62feef65.
Report an issue: GitHub.