Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
64153ca
Add initial implementation of mistral4 model
Goekdeniz-Guelmez Mar 16, 2026
dfad789
Implement Mistral-4 model architecture with attention and MoE layers
Goekdeniz-Guelmez Mar 16, 2026
775547e
Add Mistral AI's Mistral4 to acknowledgments in ACKNOWLEDGMENTS.md
Goekdeniz-Guelmez Mar 16, 2026
5008bc0
Refactor Mistral4 model arguments and attention scaling; optimize exp…
Goekdeniz-Guelmez Mar 16, 2026
8344088
Merge branch 'ml-explore:main' into add-mistral4
Goekdeniz-Guelmez Mar 17, 2026
1a3dac8
Rename scaling_args to scaling_config in Mistral4Attention for clarity
Goekdeniz-Guelmez Mar 17, 2026
d621dc0
Integrate PipelineMixin into Mistral4Model and update attention call …
Goekdeniz-Guelmez Mar 17, 2026
b477579
Sanitize model weights by filtering and renaming keys in the sanitize…
Goekdeniz-Guelmez Mar 17, 2026
55b0f20
format
Goekdeniz-Guelmez Mar 17, 2026
352fbf5
Fix attention scaling in Mistral4Attention and add unit test for Mist…
Goekdeniz-Guelmez Mar 17, 2026
79082fa
Refactor Mistral4Attention by removing commented-out code and unneces…
Goekdeniz-Guelmez Mar 17, 2026
443a1bc
Add Mistral4 model implementation and integrate with existing archite…
Goekdeniz-Guelmez Mar 18, 2026
ec42929
Update Mistral4 model references in utils and remove unused function …
Goekdeniz-Guelmez Mar 18, 2026
8d27511
Enhance Mistral4 attention mechanism by integrating attention scaling…
Goekdeniz-Guelmez Mar 18, 2026
80bd713
Refactor ModelArgs to simplify rope_parameters handling and update de…
Goekdeniz-Guelmez Mar 18, 2026
85d7b7a
Refactor sanitize method to improve weight handling and remove unused…
Goekdeniz-Guelmez Mar 19, 2026
88e98c5
nits + format
Goekdeniz-Guelmez Mar 19, 2026
5a5bcd5
Merge remote-tracking branch 'upstream/main' into mistral4-v2
michalk8 Sep 15, 2026
9599647
Merge branch 'main' into add-mistral4
Goekdeniz-Guelmez Sep 16, 2026
9ec6bea
Fix yarn for Mistral v4
michalk8 Sep 16, 2026
fa201e8
Fix Mistral4 sanitize
michalk8 Sep 17, 2026
8931ba6
Fix Mistral4 test
michalk8 Sep 17, 2026
1a940af
Fix dequantize, yarn + update test
michalk8 Sep 17, 2026
7f684f0
Use a linear layer for gate
michalk8 Sep 17, 2026
b59538d
Fix Mistral4 pipelining
michalk8 Sep 17, 2026
ff4cb66
Fix sharding
michalk8 Sep 17, 2026
ba5b03c
Don't materialize the mask
michalk8 Sep 17, 2026
27a8e01
Rename mistral4_text to mistral4
michalk8 Sep 17, 2026
3ac79ee
Use MultiLinear
michalk8 Sep 17, 2026
7bd8aa3
Simplify sanitize
michalk8 Sep 17, 2026
c6b4035
Use h.shape[1]
michalk8 Sep 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ACKNOWLEDGMENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ MLX LM was developed with contributions from the following individuals:
OpenBMB's `MiniCPM` and `MiniCPM3`, Kyutai's `Helium`, State-Space's `Mamba v1` and
`Mamba v2`, Z.ai & THUKEG's `GLM`, `GLM4`, `GLM5 (GLM MoE DSA)`, Rednote `dots.llm1`, Baidu's `Ernie4.5 MoE`,
inclusionAI's `Bailing MoE e.g. Ling-family`, `Bailing MoE Linear e.g. Ling-Linear-family`,
Klear team - Kuaishou Technology's `Klear`, AI21 Lab's `Jamba` IBM's `Granite MoE`,
Klear team - Kuaishou Technology's `Klear`, AI21 Lab's `Jamba` IBM's `Granite MoE`, Mistral AI's `Mistral4`,
Meituan's `LongCat`, Nvidia's `Nemotron H`, Swiss-AI's `Apertus`, Nikity's `Lille130m`,
Alibaba Qwen's `Qwen3Next`, Tele-AI's `TeleChat3`, and Allenai's `OLMoE` and `Olmo 3`;
Helped add support for the following model architectures:
Expand Down
27 changes: 18 additions & 9 deletions mlx_lm/models/mistral3.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# Copyright © 2025 Apple Inc.
# Copyright © 2026 Apple Inc.

from dataclasses import dataclass
from typing import Optional

import mlx.core as mx
import mlx.nn as nn
from mlx.utils import tree_flatten, tree_unflatten

from . import llama, ministral3
from . import llama, ministral3, mistral4
from .base import BaseModelArgs


Expand All @@ -30,6 +29,10 @@ def __init__(self, args: ModelArgs):
self.language_model = ministral3.Model(
ministral3.ModelArgs.from_dict(args.text_config)
)
elif args.text_config.get("model_type") == "mistral4":
self.language_model = mistral4.Model(
mistral4.ModelArgs.from_dict(args.text_config)
)
else:
self.language_model = llama.Model(
llama.ModelArgs.from_dict(args.text_config)
Expand All @@ -46,12 +49,18 @@ def __call__(
)

def sanitize(self, weights):
weights = tree_unflatten(list(weights.items()))
weights.pop("vision_tower", None)
weights.pop("multi_modal_projector", None)
lm_weights = dict(tree_flatten(weights["language_model"]))
weights["language_model"] = self.language_model.sanitize(lm_weights)
return dict(tree_flatten(weights))
lm_weights = {}
for key, value in weights.items():
if "vision_tower" in key or "multi_modal_projector" in key:
continue
if key.startswith("model.language_model."):
key = "model." + key.removeprefix("model.language_model.")
else:
key = key.removeprefix("language_model.")
lm_weights[key] = value

sanitized_lm = self.language_model.sanitize(lm_weights)
return {"language_model." + k: v for k, v in sanitized_lm.items()}

@property
def layers(self):
Expand Down
Loading
Loading