Problem
Loading the Mistral Small 4 checkpoint mlx-community/Mistral-Small-4-119B-2603-4bit (a Mistral3ForConditionalGeneration VLM whose text_config.model_type is mistral4, i.e. an MLA + MoE text backbone with weights self_attn.q_a_proj / kv_a_proj_with_mqa / kv_b_proj) fails at load with: Failed to load text model: Weight not found: model.layers.0.self_attn.q_proj.weight.
Root cause
build_pixtral_family_context (src/loading/vlm_pixtral.rs:104-109) unconditionally parses the text config as models::llama3::ModelArgs and loads the text backbone via models::Llama3Model::from_weights (which expects standard attention q_proj). It never checks text_config.model_type == "mistral4", so an MLA text backbone (q_a_proj / kv_a_proj_with_mqa / kv_b_proj, no q_proj) cannot be found and the load fails. The non-VLM text-only path already handles this: load_llama_family_from_weights (src/loading/mod.rs:210-220) branches on is_mistral4_config(config) and routes to models::Mistral4Model::from_weights (after models::mistral4::sanitize_weights(weights, &args, "")). The VLM context builder is missing the equivalent branch. Note build_pixtral_family_context already strips the language_model. prefix via strip_language_model_prefix (line 100), so the weights are at the bare model.layers... namespace for both loaders.
Proposed fix
In build_pixtral_family_context, branch on is_mistral4_config(&full_config) (or text_config.model_type == "mistral4"). When true, parse the text config as models::mistral4::Mistral4Config, run models::mistral4::sanitize_weights(&mut weights, &args, ""), and build models::Mistral4Model::from_weights(&weights, &args) wrapped as LoadedModel::Mistral4, mirroring load_llama_family_from_weights. Keep the Llama path for non-mistral4 Mistral3 VLMs (Pixtral / standard Mistral text). Be careful that the Llama-specific config massaging in build_mistral_text_config (infer_llama_config_from_weights, apply_mistral_attention_head_override, which key off q_proj) does not corrupt the mistral4 config; for the mistral4 branch prefer the raw text_config with quantization inherited rather than the Llama-massaged value.
Impact
Mistral Small 4 (the only public mistral4 checkpoint) is a VLM, so this blocks loading it at all on the server/CLI. It also blocks real-model validation of the #421 dense-prefill-mask fix for mistral4 (the mask fix is in the mistral4 text backbone, which cannot currently load). Pre-existing (reproduces on main), independent of #421.
Acceptance criteria
References
Problem
Loading the Mistral Small 4 checkpoint
mlx-community/Mistral-Small-4-119B-2603-4bit(aMistral3ForConditionalGenerationVLM whosetext_config.model_typeismistral4, i.e. an MLA + MoE text backbone with weightsself_attn.q_a_proj/kv_a_proj_with_mqa/kv_b_proj) fails at load with:Failed to load text model: Weight not found: model.layers.0.self_attn.q_proj.weight.Root cause
build_pixtral_family_context(src/loading/vlm_pixtral.rs:104-109) unconditionally parses the text config asmodels::llama3::ModelArgsand loads the text backbone viamodels::Llama3Model::from_weights(which expects standard attentionq_proj). It never checkstext_config.model_type == "mistral4", so an MLA text backbone (q_a_proj/kv_a_proj_with_mqa/kv_b_proj, noq_proj) cannot be found and the load fails. The non-VLM text-only path already handles this:load_llama_family_from_weights(src/loading/mod.rs:210-220) branches onis_mistral4_config(config)and routes tomodels::Mistral4Model::from_weights(aftermodels::mistral4::sanitize_weights(weights, &args, "")). The VLM context builder is missing the equivalent branch. Notebuild_pixtral_family_contextalready strips thelanguage_model.prefix viastrip_language_model_prefix(line 100), so the weights are at the baremodel.layers...namespace for both loaders.Proposed fix
In
build_pixtral_family_context, branch onis_mistral4_config(&full_config)(ortext_config.model_type == "mistral4"). When true, parse the text config asmodels::mistral4::Mistral4Config, runmodels::mistral4::sanitize_weights(&mut weights, &args, ""), and buildmodels::Mistral4Model::from_weights(&weights, &args)wrapped asLoadedModel::Mistral4, mirroringload_llama_family_from_weights. Keep the Llama path for non-mistral4 Mistral3 VLMs (Pixtral / standard Mistral text). Be careful that the Llama-specific config massaging inbuild_mistral_text_config(infer_llama_config_from_weights,apply_mistral_attention_head_override, which key offq_proj) does not corrupt the mistral4 config; for the mistral4 branch prefer the rawtext_configwith quantization inherited rather than the Llama-massaged value.Impact
Mistral Small 4 (the only public
mistral4checkpoint) is a VLM, so this blocks loading it at all on the server/CLI. It also blocks real-model validation of the #421 dense-prefill-mask fix for mistral4 (the mask fix is in the mistral4 text backbone, which cannot currently load). Pre-existing (reproduces onmain), independent of #421.Acceptance criteria
mlxcel-server -m <Mistral-Small-4-119B-2603-4bit>loads without theq_projweight-not-found error and serves text generation.References