huggingface/transformers · error · ValueError
Calling `get_mtp_config` on a config without `num_mtp_layers
Error message
Calling `get_mtp_config` on a config without `num_mtp_layers`
What it means
ValueError from PreTrainedConfig.get_mtp_config: it deep-copies the decoder text config and builds the MTP (multi-token prediction) config, which requires num_mtp_layers to be defined. If the text config has no num_mtp_layers attribute (getattr returns None), MTP layers were never configured and building an MTP model is meaningless.
Source
Thrown at src/transformers/configuration_utils.py:1391
value = getattr(config_to_return, key)
delattr(config_to_return, key)
setattr(config_to_return, new_key, value)
return config_to_return
def get_mtp_config(self) -> "PreTrainedConfig":
"""
Returns the mtp text config to be used to create the MTP model. Since the MTP layers are created by instantiating
the same classes as the main model, we need to overwrite index-specific properties of the config such as `layer_types`
or `mtp_layer_types` to create the correct mtp layers and avoid indexing issues in the layers (because MTP layers restart
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"View on GitHub (pinned to a597f97485)
Solutions
- Guard the call: only invoke get_mtp_config() when getattr(config, 'num_mtp_layers', None) is not None.
- If MTP is intended, set num_mtp_layers (and the corresponding mtp layer-type fields) on the config.
- Use the non-MTP model class for checkpoints without MTP weights.
Example fix
// before mtp_cfg = config.get_mtp_config() # ValueError on non-MTP checkpoint // after mtp_cfg = config.get_mtp_config() if getattr(config, "num_mtp_layers", None) else None
Defensive patterns
Strategy: type-guard
Validate before calling
if getattr(config.get_text_config(decoder=True), "num_mtp_layers", None) is None:
skip_mtp = True # do not call get_mtp_config / build MTP model Type guard
def has_mtp_layers(config) -> bool:
return getattr(config.get_text_config(decoder=True), "num_mtp_layers", None) is not None Try / catch
try:
mtp_config = config.get_mtp_config()
except ValueError as e:
if "without `num_mtp_layers`" in str(e):
mtp_config = None # checkpoint has no MTP Prevention
- Treat MTP as opt-in: branch on num_mtp_layers before constructing MTP modules.
- Validate configs with a schema check at load time for MTP-capable pipelines.
When it happens
Trigger: Calling config.get_mtp_config() (directly or via MTP model construction) on a model whose config lacks num_mtp_layers, e.g. a checkpoint not trained with MTP (most standard LLMs).
Common situations: Generic code paths that unconditionally build MTP heads for models like DeepSeek-MTP/GLM-style architectures; loading a non-MTP checkpoint into MTP-aware code.
Related errors
- The embed_dim ({self.embed_dim}) is not a multiple of the nu
- 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 containing `layer_types
- File not found: {audio}
AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14).
Data as JSON: /api/errors/ca879b6582ad9f71.
Report an issue: GitHub.