Iāve noticed something puzzling about the head dimension calculation in Mistral Small 3.1 According to the transformers documentation, head_dim should be calculated as hidden_size // num_attention_heads, which for Mistral Small 3.1 would be:
head_dim = 5120 // 32 = 160
However, in the modelās config.json, head_dim is explicitly set to 128:
{
"architectures": [
"MistralForCausalLM"
],
"attention_dropout": 0.0,
"bos_token_id": 1,
"eos_token_id": 2,
"head_dim": 128,
"hidden_act": "silu",
"hidden_size": 5120,
"initializer_range": 0.02,
"intermediate_size": 32768,
"max_position_embeddings": 32768,
"model_type": "mistral",
"num_attention_heads": 32,
"num_hidden_layers": 40,
"num_key_value_heads": 8,
"rms_norm_eps": 1e-05,
"rope_theta": 100000000.0,
"sliding_window": null,
"tie_word_embeddings": false,
"torch_dtype": "bfloat16",
"transformers_version": "4.49.0.dev0",
"use_cache": true,
"vocab_size": 131072
}
This seems to conflict with the transformers documentation which states: head_dim (int, optional, defaults to hidden_size // num_attention_heads) ā The attention head dimension.source
Interestingly, if we calculate using num_hidden_layers instead:
head_dim = hidden_size // num_hidden_layers
head_dim = 5120 // 40 = 128
This matches the preset value in the config, but Iām not sure if this is coincidental or intentional.
Can someone explain:
-
Why is head_dim set to 128 instead of the calculated 160?
-
Is the correlation with num_hidden_layers meaningful or coincidental?