yujiepan commited on
Commit
1b8b8cd
·
verified ·
1 Parent(s): e85eedf

Upload tied tiny Mistral Large 4 checkpoint

Browse files
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tekken.json filter=lfs diff=lfs merge=lfs -text
37
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
.meta/create_model.py ADDED
@@ -0,0 +1,307 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def create_model(source_model_id: str, source_revision: str, save_folder: str):
2
+ import json
3
+ from pathlib import Path
4
+
5
+ import torch
6
+ from huggingface_hub import hf_hub_download
7
+ from safetensors import safe_open
8
+ from safetensors.torch import save_file
9
+ from transformers import AutoConfig, AutoModelForImageTextToText
10
+
11
+ folder = Path(save_folder)
12
+ folder.mkdir(parents=True, exist_ok=True)
13
+ torch.manual_seed(42)
14
+
15
+ def read_json(name: str):
16
+ return json.loads(
17
+ Path(hf_hub_download(source_model_id, name, revision=source_revision)).read_text(encoding="utf-8")
18
+ )
19
+
20
+ source_config, params = read_json("config.json"), read_json("params.json")
21
+ text = source_config["text_config"]
22
+ text.update(
23
+ architectures=["MistralLarge4ForCausalLM"],
24
+ tie_word_embeddings=True,
25
+ hidden_size=128,
26
+ intermediate_size=128,
27
+ moe_intermediate_size=128,
28
+ num_hidden_layers=12,
29
+ num_attention_heads=4,
30
+ num_key_value_heads=4,
31
+ head_dim=32,
32
+ qk_nope_head_dim=64,
33
+ qk_rope_head_dim=64,
34
+ v_head_dim=128,
35
+ kv_lora_rank=512,
36
+ index_head_dim=128,
37
+ index_n_heads=4,
38
+ index_topk=128,
39
+ n_routed_experts=32,
40
+ n_shared_experts=1,
41
+ num_experts_per_tok=4,
42
+ first_k_dense_replace=1,
43
+ layer_types=["indexed_attention"] * 12,
44
+ mlp_layer_types=["dense"] + ["sparse"] * 11,
45
+ no_rope_layers=[1, 1, 1, 0] * 3,
46
+ indexer_types=["full"] * 4 + ["full", "full", "shared", "shared"] * 2,
47
+ kv_source_layers=[0, 1, 2, 3, 4, 5, 6, 3, 8, 9, 10, 3],
48
+ )
49
+ source_config["tie_word_embeddings"] = True
50
+ source_config["vision_config"].update(
51
+ hidden_size=64,
52
+ intermediate_size=128,
53
+ num_hidden_layers=4,
54
+ num_attention_heads=2,
55
+ head_dim=32,
56
+ image_size=1540,
57
+ patch_size=14,
58
+ )
59
+ source_config["quantization_config"] = {
60
+ "quant_method": "fp8",
61
+ "activation_scheme": "dynamic",
62
+ "weight_block_size": [64, 64],
63
+ "scale_fmt": "ue8m0",
64
+ "modules_to_not_convert": [
65
+ "model.vision_tower",
66
+ "model.multi_modal_projector",
67
+ "lm_head",
68
+ "kv_b_proj",
69
+ "indexer.wk",
70
+ "indexer.weights_proj",
71
+ "kv_a_proj_with_mqa",
72
+ ],
73
+ }
74
+ source_config["transformers_weights"] = "consolidated.safetensors"
75
+ params.update(
76
+ dim=128,
77
+ tied_embeddings=True,
78
+ n_layers=12,
79
+ head_dim=32,
80
+ hidden_dim=128,
81
+ n_heads=4,
82
+ n_kv_heads=4,
83
+ kv_lora_rank=512,
84
+ qk_rope_head_dim=64,
85
+ qk_nope_head_dim=64,
86
+ v_head_dim=128,
87
+ nope="rope,rope,rope,nope",
88
+ kv_sharing={"source_layers_str": "0,1,2,3,4,5,6,3,8,9,10,3"},
89
+ dsa={
90
+ "topk": 128,
91
+ "n_heads": 4,
92
+ "head_dim": 128,
93
+ "rope_head_dim": 64,
94
+ "match_nope": True,
95
+ "ssmax_scaling": True,
96
+ "norm_eps": 1e-6,
97
+ "sharing": "full,full,full,full,full,full,shared,shared,full,full,shared,shared",
98
+ "fp8_indexer": True,
99
+ "fp8_kv_cache": True,
100
+ },
101
+ quantization={
102
+ "qscheme_act": "BLOCK",
103
+ "qformat_weight": "fp8_e4m3",
104
+ "qdynamic_act": True,
105
+ "qscheme_weight": "BLOCK",
106
+ "use_ue8m0_for_qscales": True,
107
+ "block_size_out": 64,
108
+ "block_size_in": 64,
109
+ "quantize_kv_a": False,
110
+ },
111
+ moe={
112
+ "expert_parallel": 1,
113
+ "expert_model_parallel": 1,
114
+ "route_every_n": 1,
115
+ "first_k_dense_replace": 1,
116
+ "num_experts": 32,
117
+ "num_experts_per_tok": 4,
118
+ "num_expert_groups": 1,
119
+ "num_expert_groups_per_tok": 1,
120
+ "routed_scale": 1.0,
121
+ "expert_hidden_dim": 128,
122
+ "num_shared_experts": 1,
123
+ },
124
+ vision_encoder={
125
+ **params["vision_encoder"],
126
+ "intermediate_size": 128,
127
+ "num_hidden_layers": 4,
128
+ "num_attention_heads": 2,
129
+ "hidden_size": 64,
130
+ "image_size": 1540,
131
+ "max_image_size": 1540,
132
+ "patch_size": 14,
133
+ },
134
+ mtp={
135
+ "n_layers": 3,
136
+ "depth": 3,
137
+ "ragged_attention": "32,32,32",
138
+ "target_activation_layers": "1,4,7,10,11",
139
+ "norm_strategy": "eagle",
140
+ "dspark": {"markov_rank": 4, "head_type": "rnn", "draft_input": "position_specific"},
141
+ },
142
+ )
143
+ # The public HF config is used by Transformers while vLLM also needs this
144
+ # native Mistral block to build and enable the in-checkpoint DSpark draft.
145
+ text["mtp_config"] = params["mtp"]
146
+ config_for_build = dict(source_config)
147
+ config_for_build.pop("quantization_config")
148
+ (folder / "config.json").write_text(json.dumps(config_for_build, indent=2) + "\n", encoding="utf-8")
149
+ model = AutoModelForImageTextToText.from_config(AutoConfig.from_pretrained(folder), dtype=torch.bfloat16)
150
+ with torch.no_grad():
151
+ for name, value in model.named_parameters():
152
+ if name.endswith("weight") and "norm" in name:
153
+ value.fill_(1)
154
+ elif name.endswith("bias"):
155
+ value.zero_()
156
+ else:
157
+ value.normal_(mean=0.0, std=0.02)
158
+ model.tie_weights()
159
+ model.save_pretrained(folder, safe_serialization=True)
160
+ state = {}
161
+ with safe_open(folder / "model.safetensors", framework="pt", device="cpu") as reader:
162
+ for name in reader.keys():
163
+ state[name] = reader.get_tensor(name).contiguous()
164
+ (folder / "model.safetensors").unlink()
165
+
166
+ def should_quantize(name: str, value: torch.Tensor) -> bool:
167
+ return (
168
+ name.endswith(".weight")
169
+ and value.ndim == 2
170
+ and value.shape[0] % 64 == 0
171
+ and value.shape[1] % 64 == 0
172
+ and not name.startswith(
173
+ (
174
+ "vision_encoder.",
175
+ "vision_language_adapter.",
176
+ "patch_merger.",
177
+ "pre_mm_projector_norm.",
178
+ "tok_embeddings.",
179
+ "output.",
180
+ )
181
+ )
182
+ and not any(
183
+ piece in name
184
+ for piece in (
185
+ ".wkv_a_with_mqa.",
186
+ ".wkv_b.",
187
+ ".indexer.wk.",
188
+ ".indexer.weights_proj.",
189
+ ".attention.wo.",
190
+ ".feed_forward.",
191
+ ".shared_experts.",
192
+ ".experts.",
193
+ )
194
+ )
195
+ and not name.endswith(".gate.weight")
196
+ )
197
+
198
+ def quantize(name: str, value: torch.Tensor) -> None:
199
+ rows, columns = value.shape
200
+ blocks = value.float().reshape(rows // 64, 64, columns // 64, 64)
201
+ maximum = blocks.abs().amax(dim=(1, 3)).clamp_min(torch.finfo(torch.float32).tiny)
202
+ inverse = torch.pow(2.0, torch.ceil(torch.log2(1.0 / maximum))).to(torch.float8_e8m0fnu)
203
+ state[name] = (
204
+ (blocks * inverse.float()[:, None, :, None])
205
+ .clamp(-448, 448)
206
+ .reshape(rows, columns)
207
+ .to(torch.float8_e4m3fn)
208
+ .contiguous()
209
+ )
210
+ state[name.removesuffix(".weight") + ".qscale_weight"] = (1.0 / inverse.float()).to(torch.float8_e8m0fnu)
211
+
212
+ for name, value in list(state.items()):
213
+ if should_quantize(name, value):
214
+ quantize(name, value)
215
+
216
+ for layer in range(3):
217
+ prefix = f"mtp_dspark.backbone.layers.{layer}"
218
+ shapes = {
219
+ "attention_norm.weight": (128,),
220
+ "attention.wq.weight": (512, 128),
221
+ "attention.wkv_a_with_mqa.weight": (576, 128),
222
+ "attention.kv_a_norm.weight": (512,),
223
+ "attention.wkv_b.weight": (768, 512),
224
+ "attention.wo.weight": (128, 512),
225
+ "ffn_norm.weight": (128,),
226
+ "feed_forward.w1.weight": (128, 128),
227
+ "feed_forward.w2.weight": (128, 128),
228
+ "feed_forward.w3.weight": (128, 128),
229
+ }
230
+ for name, shape in shapes.items():
231
+ state[f"{prefix}.{name}"] = (
232
+ torch.ones(shape, dtype=torch.bfloat16)
233
+ if name.endswith("norm.weight")
234
+ else torch.randn(shape, dtype=torch.bfloat16) * 0.02
235
+ )
236
+ state.update(
237
+ {
238
+ "mtp_dspark.backbone.target_projection.weight": torch.randn(128, 640, dtype=torch.bfloat16) * 0.02,
239
+ "mtp_dspark.backbone.target_norm.weight": torch.ones(128, dtype=torch.bfloat16),
240
+ "mtp_dspark.backbone.final_norm.weight": torch.ones(128, dtype=torch.bfloat16),
241
+ "mtp_dspark.backbone.mask_embedding": torch.randn(2, 128, dtype=torch.bfloat16) * 0.02,
242
+ "mtp_dspark.autoregressive_head.embedding.weight": torch.randn(204800, 4, dtype=torch.bfloat16) * 0.02,
243
+ "mtp_dspark.autoregressive_head.output.weight": torch.randn(204800, 4, dtype=torch.bfloat16) * 0.02,
244
+ "mtp_dspark.autoregressive_head.joint_proj.weight": torch.randn(12, 136, dtype=torch.bfloat16) * 0.02,
245
+ "mtp_dspark.autoregressive_head.joint_proj.bias": torch.zeros(12, dtype=torch.bfloat16),
246
+ "lerope.alpha": torch.zeros(32, dtype=torch.bfloat16),
247
+ }
248
+ )
249
+ save_file(state, folder / "consolidated.safetensors", metadata={"format": "pt"})
250
+ (folder / "config.json").write_text(json.dumps(source_config, indent=2) + "\n", encoding="utf-8")
251
+ (folder / "params.json").write_text(json.dumps(params, indent=2) + "\n", encoding="utf-8")
252
+ for name in (
253
+ "tekken.json",
254
+ "tokenizer.json",
255
+ "tokenizer_config.json",
256
+ "processor_config.json",
257
+ "chat_template.jinja",
258
+ "generation_config.json",
259
+ "LICENSE",
260
+ ):
261
+ (folder / name).write_bytes(Path(hf_hub_download(source_model_id, name, revision=source_revision)).read_bytes())
262
+ (folder / "vllm_mistral_large4_tied.py").write_text(
263
+ "from vllm.distributed import get_pp_group\n"
264
+ "from vllm.models.mistral_large4 import MistralLarge4ForCausalLM\n\n\n"
265
+ "class MistralLarge4TiedForCausalLM(MistralLarge4ForCausalLM):\n"
266
+ ' def __init__(self, *, vllm_config, prefix=""):\n'
267
+ " super().__init__(vllm_config=vllm_config, prefix=prefix)\n"
268
+ " if self.config.tie_word_embeddings and get_pp_group().is_last_rank:\n"
269
+ " self.lm_head = self.lm_head.tie_weights(self.model.embed_tokens)\n",
270
+ encoding="utf-8",
271
+ )
272
+ (folder / "vllm_plugin.py").write_text(
273
+ "def register():\n"
274
+ " from vllm import ModelRegistry\n\n"
275
+ " ModelRegistry.register_model(\n"
276
+ ' "MistralLarge4ForCausalLM",\n'
277
+ ' "vllm_mistral_large4_tied:MistralLarge4TiedForCausalLM",\n'
278
+ " )\n",
279
+ encoding="utf-8",
280
+ )
281
+ (folder / "pyproject.toml").write_text(
282
+ "[build-system]\n"
283
+ "requires = ['setuptools>=61']\n"
284
+ "build-backend = 'setuptools.build_meta'\n\n"
285
+ "[project]\n"
286
+ "name = 'mistral-large-4-tied-vllm'\n"
287
+ "version = '0.1.0'\n\n"
288
+ "[project.entry-points.'vllm.general_plugins']\n"
289
+ "mistral_large4_tied = 'vllm_plugin:register'\n\n"
290
+ "[tool.setuptools]\n"
291
+ "py-modules = ['vllm_mistral_large4_tied', 'vllm_plugin']\n",
292
+ encoding="utf-8",
293
+ )
294
+ model.add_module(
295
+ "mtp_dspark",
296
+ torch.nn.ModuleDict(
297
+ {"backbone": torch.nn.ModuleDict({"layers": torch.nn.ModuleList([torch.nn.Identity() for _ in range(3)])})}
298
+ ),
299
+ )
300
+ return str(model)
301
+
302
+
303
+ create_model(
304
+ source_model_id="mistralai/Mistral-Large-4-1T-A52B",
305
+ source_revision="f12dabdc0c1e99e7f7924461a6f308859b05af4d",
306
+ save_folder="/tmp/mistral-large-4",
307
+ )
.meta/env.json ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "source_model": {
3
+ "name": "mistralai/Mistral-Large-4-1T-A52B",
4
+ "commit_id": "f12dabdc0c1e99e7f7924461a6f308859b05af4d"
5
+ },
6
+ "environments": {
7
+ "creation": {
8
+ "python": "3.12.13",
9
+ "packages": {
10
+ "huggingface_hub": "2.3.0",
11
+ "safetensors": "0.8.0",
12
+ "tokenizers": "0.23.3",
13
+ "torch": "2.13.0+cu126",
14
+ "transformers": "5.22.0.dev0"
15
+ },
16
+ "cuda": "12.6"
17
+ },
18
+ "transformers": {
19
+ "python": "3.12.13",
20
+ "packages": {
21
+ "Pillow": "12.3.0",
22
+ "huggingface_hub": "2.3.0",
23
+ "mistral-large-4-tied-vllm": "0.1.0",
24
+ "safetensors": "0.8.0",
25
+ "tokenizers": "0.23.3",
26
+ "torch": "2.13.0+cu126",
27
+ "transformers": "5.22.0.dev0",
28
+ "vllm": "0.1.dev1+g5a3eba034.d20260730.cu126"
29
+ },
30
+ "cuda": "12.6",
31
+ "hardware": {
32
+ "gpu_model": "NVIDIA H20"
33
+ }
34
+ },
35
+ "vllm-offline": {
36
+ "python": "3.12.13",
37
+ "packages": {
38
+ "Pillow": "12.3.0",
39
+ "huggingface_hub": "2.3.0",
40
+ "mistral-large-4-tied-vllm": "0.1.0",
41
+ "safetensors": "0.8.0",
42
+ "tokenizers": "0.23.3",
43
+ "torch": "2.13.0+cu126",
44
+ "transformers": "5.22.0.dev0",
45
+ "vllm": "0.1.dev1+g5a3eba034.d20260730.cu126"
46
+ },
47
+ "cuda": "12.6",
48
+ "hardware": {
49
+ "gpu_model": "NVIDIA H20"
50
+ }
51
+ }
52
+ }
53
+ }
.meta/model.log ADDED
@@ -0,0 +1,299 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MistralLarge4ForConditionalGeneration(
2
+ (model): MistralLarge4Model(
3
+ (vision_tower): PixtralVisionModel(
4
+ (patch_conv): Conv2d(3, 64, kernel_size=(14, 14), stride=(14, 14), bias=False)
5
+ (ln_pre): PixtralRMSNorm((64,), eps=1e-05)
6
+ (transformer): PixtralTransformer(
7
+ (layers): ModuleList(
8
+ (0-3): 4 x PixtralAttentionLayer(
9
+ (attention_norm): PixtralRMSNorm((64,), eps=1e-05)
10
+ (feed_forward): PixtralMLP(
11
+ (gate_proj): Linear(in_features=64, out_features=128, bias=False)
12
+ (up_proj): Linear(in_features=64, out_features=128, bias=False)
13
+ (down_proj): Linear(in_features=128, out_features=64, bias=False)
14
+ (act_fn): SiLUActivation()
15
+ )
16
+ (attention): PixtralAttention(
17
+ (k_proj): Linear(in_features=64, out_features=64, bias=False)
18
+ (v_proj): Linear(in_features=64, out_features=64, bias=False)
19
+ (q_proj): Linear(in_features=64, out_features=64, bias=False)
20
+ (o_proj): Linear(in_features=64, out_features=64, bias=False)
21
+ )
22
+ (ffn_norm): PixtralRMSNorm((64,), eps=1e-05)
23
+ )
24
+ )
25
+ )
26
+ (patch_positional_embedding): PixtralVisionRotaryEmbedding()
27
+ )
28
+ (multi_modal_projector): MistralLarge4MultiModalProjector(
29
+ (norm): MistralLarge4RMSNorm((64,), eps=1e-05)
30
+ (patch_merger): MistralLarge4PatchMerger(
31
+ (merging_layer): Linear(in_features=256, out_features=64, bias=False)
32
+ )
33
+ (linear_1): Linear(in_features=64, out_features=128, bias=False)
34
+ (act): GELUActivation()
35
+ (linear_2): Linear(in_features=128, out_features=128, bias=False)
36
+ )
37
+ (language_model): MistralLarge4TextModel(
38
+ (embed_tokens): Embedding(204800, 128)
39
+ (layers): ModuleList(
40
+ (0): MistralLarge4TextDecoderLayer(
41
+ (self_attn): MistralLarge4TextAttention(
42
+ (kv_a_proj_with_mqa): Linear(in_features=128, out_features=576, bias=False)
43
+ (kv_a_layernorm): MistralLarge4RMSNorm((512,), eps=1e-05)
44
+ (kv_b_proj): Linear(in_features=512, out_features=768, bias=False)
45
+ (o_proj): Linear(in_features=512, out_features=128, bias=False)
46
+ (indexer): MistralLarge4TextIndexer(
47
+ (wq_b): Linear(in_features=128, out_features=512, bias=False)
48
+ (wk): Linear(in_features=128, out_features=128, bias=False)
49
+ (k_norm): LayerNorm((128,), eps=1e-06, elementwise_affine=True, bias=True)
50
+ (weights_proj): Linear(in_features=128, out_features=4, bias=False)
51
+ (q_input_norm): LayerNorm((128,), eps=1e-06, elementwise_affine=True, bias=True)
52
+ (softmax_scaling): MistralLarge4TextSoftmaxScaling()
53
+ )
54
+ (q_proj): Linear(in_features=128, out_features=512, bias=False)
55
+ (softmax_scaling): MistralLarge4TextSoftmaxScaling()
56
+ )
57
+ (mlp): MistralLarge4TextMLP(
58
+ (gate_proj): Linear(in_features=128, out_features=128, bias=False)
59
+ (up_proj): Linear(in_features=128, out_features=128, bias=False)
60
+ (down_proj): Linear(in_features=128, out_features=128, bias=False)
61
+ (act_fn): SiLUActivation()
62
+ )
63
+ (input_layernorm): MistralLarge4RMSNorm((128,), eps=1e-05)
64
+ (post_attention_layernorm): MistralLarge4RMSNorm((128,), eps=1e-05)
65
+ )
66
+ (1-2): 2 x MistralLarge4TextDecoderLayer(
67
+ (self_attn): MistralLarge4TextAttention(
68
+ (kv_a_proj_with_mqa): Linear(in_features=128, out_features=576, bias=False)
69
+ (kv_a_layernorm): MistralLarge4RMSNorm((512,), eps=1e-05)
70
+ (kv_b_proj): Linear(in_features=512, out_features=768, bias=False)
71
+ (o_proj): Linear(in_features=512, out_features=128, bias=False)
72
+ (indexer): MistralLarge4TextIndexer(
73
+ (wq_b): Linear(in_features=128, out_features=512, bias=False)
74
+ (wk): Linear(in_features=128, out_features=128, bias=False)
75
+ (k_norm): LayerNorm((128,), eps=1e-06, elementwise_affine=True, bias=True)
76
+ (weights_proj): Linear(in_features=128, out_features=4, bias=False)
77
+ (q_input_norm): LayerNorm((128,), eps=1e-06, elementwise_affine=True, bias=True)
78
+ (softmax_scaling): MistralLarge4TextSoftmaxScaling()
79
+ )
80
+ (q_proj): Linear(in_features=128, out_features=512, bias=False)
81
+ (softmax_scaling): MistralLarge4TextSoftmaxScaling()
82
+ )
83
+ (mlp): MistralLarge4TextMoE(
84
+ (experts): MistralLarge4TextExperts(
85
+ (act_fn): SiLUActivation()
86
+ )
87
+ (gate): MistralLarge4TextTopkRouter()
88
+ (shared_experts): MistralLarge4TextMLP(
89
+ (gate_proj): Linear(in_features=128, out_features=128, bias=False)
90
+ (up_proj): Linear(in_features=128, out_features=128, bias=False)
91
+ (down_proj): Linear(in_features=128, out_features=128, bias=False)
92
+ (act_fn): SiLUActivation()
93
+ )
94
+ )
95
+ (input_layernorm): MistralLarge4RMSNorm((128,), eps=1e-05)
96
+ (post_attention_layernorm): MistralLarge4RMSNorm((128,), eps=1e-05)
97
+ )
98
+ (3): MistralLarge4TextDecoderLayer(
99
+ (self_attn): MistralLarge4TextAttention(
100
+ (kv_a_proj_with_mqa): Linear(in_features=128, out_features=512, bias=False)
101
+ (kv_a_layernorm): MistralLarge4RMSNorm((512,), eps=1e-05)
102
+ (kv_b_proj): Linear(in_features=512, out_features=1024, bias=False)
103
+ (o_proj): Linear(in_features=512, out_features=128, bias=False)
104
+ (indexer): MistralLarge4TextIndexer(
105
+ (wq_b): Linear(in_features=128, out_features=512, bias=False)
106
+ (wk): Linear(in_features=128, out_features=128, bias=False)
107
+ (k_norm): LayerNorm((128,), eps=1e-06, elementwise_affine=True, bias=True)
108
+ (weights_proj): Linear(in_features=128, out_features=4, bias=False)
109
+ (q_input_norm): LayerNorm((128,), eps=1e-06, elementwise_affine=True, bias=True)
110
+ (softmax_scaling): MistralLarge4TextSoftmaxScaling()
111
+ )
112
+ (q_proj): Linear(in_features=128, out_features=512, bias=False)
113
+ (softmax_scaling): MistralLarge4TextSoftmaxScaling()
114
+ )
115
+ (mlp): MistralLarge4TextMoE(
116
+ (experts): MistralLarge4TextExperts(
117
+ (act_fn): SiLUActivation()
118
+ )
119
+ (gate): MistralLarge4TextTopkRouter()
120
+ (shared_experts): MistralLarge4TextMLP(
121
+ (gate_proj): Linear(in_features=128, out_features=128, bias=False)
122
+ (up_proj): Linear(in_features=128, out_features=128, bias=False)
123
+ (down_proj): Linear(in_features=128, out_features=128, bias=False)
124
+ (act_fn): SiLUActivation()
125
+ )
126
+ )
127
+ (input_layernorm): MistralLarge4RMSNorm((128,), eps=1e-05)
128
+ (post_attention_layernorm): MistralLarge4RMSNorm((128,), eps=1e-05)
129
+ )
130
+ (4-5): 2 x MistralLarge4TextDecoderLayer(
131
+ (self_attn): MistralLarge4TextAttention(
132
+ (kv_a_proj_with_mqa): Linear(in_features=128, out_features=576, bias=False)
133
+ (kv_a_layernorm): MistralLarge4RMSNorm((512,), eps=1e-05)
134
+ (kv_b_proj): Linear(in_features=512, out_features=768, bias=False)
135
+ (o_proj): Linear(in_features=512, out_features=128, bias=False)
136
+ (indexer): MistralLarge4TextIndexer(
137
+ (wq_b): Linear(in_features=128, out_features=512, bias=False)
138
+ (wk): Linear(in_features=128, out_features=128, bias=False)
139
+ (k_norm): LayerNorm((128,), eps=1e-06, elementwise_affine=True, bias=True)
140
+ (weights_proj): Linear(in_features=128, out_features=4, bias=False)
141
+ (q_input_norm): LayerNorm((128,), eps=1e-06, elementwise_affine=True, bias=True)
142
+ (softmax_scaling): MistralLarge4TextSoftmaxScaling()
143
+ )
144
+ (q_proj): Linear(in_features=128, out_features=512, bias=False)
145
+ (softmax_scaling): MistralLarge4TextSoftmaxScaling()
146
+ )
147
+ (mlp): MistralLarge4TextMoE(
148
+ (experts): MistralLarge4TextExperts(
149
+ (act_fn): SiLUActivation()
150
+ )
151
+ (gate): MistralLarge4TextTopkRouter()
152
+ (shared_experts): MistralLarge4TextMLP(
153
+ (gate_proj): Linear(in_features=128, out_features=128, bias=False)
154
+ (up_proj): Linear(in_features=128, out_features=128, bias=False)
155
+ (down_proj): Linear(in_features=128, out_features=128, bias=False)
156
+ (act_fn): SiLUActivation()
157
+ )
158
+ )
159
+ (input_layernorm): MistralLarge4RMSNorm((128,), eps=1e-05)
160
+ (post_attention_layernorm): MistralLarge4RMSNorm((128,), eps=1e-05)
161
+ )
162
+ (6): MistralLarge4TextDecoderLayer(
163
+ (self_attn): MistralLarge4TextAttention(
164
+ (kv_a_proj_with_mqa): Linear(in_features=128, out_features=576, bias=False)
165
+ (kv_a_layernorm): MistralLarge4RMSNorm((512,), eps=1e-05)
166
+ (kv_b_proj): Linear(in_features=512, out_features=768, bias=False)
167
+ (o_proj): Linear(in_features=512, out_features=128, bias=False)
168
+ (q_proj): Linear(in_features=128, out_features=512, bias=False)
169
+ (softmax_scaling): MistralLarge4TextSoftmaxScaling()
170
+ )
171
+ (mlp): MistralLarge4TextMoE(
172
+ (experts): MistralLarge4TextExperts(
173
+ (act_fn): SiLUActivation()
174
+ )
175
+ (gate): MistralLarge4TextTopkRouter()
176
+ (shared_experts): MistralLarge4TextMLP(
177
+ (gate_proj): Linear(in_features=128, out_features=128, bias=False)
178
+ (up_proj): Linear(in_features=128, out_features=128, bias=False)
179
+ (down_proj): Linear(in_features=128, out_features=128, bias=False)
180
+ (act_fn): SiLUActivation()
181
+ )
182
+ )
183
+ (input_layernorm): MistralLarge4RMSNorm((128,), eps=1e-05)
184
+ (post_attention_layernorm): MistralLarge4RMSNorm((128,), eps=1e-05)
185
+ )
186
+ (7): MistralLarge4TextDecoderLayer(
187
+ (self_attn): MistralLarge4TextAttention(
188
+ (kv_b_proj): Linear(in_features=512, out_features=1024, bias=False)
189
+ (o_proj): Linear(in_features=512, out_features=128, bias=False)
190
+ (q_proj): Linear(in_features=128, out_features=512, bias=False)
191
+ (softmax_scaling): MistralLarge4TextSoftmaxScaling()
192
+ )
193
+ (mlp): MistralLarge4TextMoE(
194
+ (experts): MistralLarge4TextExperts(
195
+ (act_fn): SiLUActivation()
196
+ )
197
+ (gate): MistralLarge4TextTopkRouter()
198
+ (shared_experts): MistralLarge4TextMLP(
199
+ (gate_proj): Linear(in_features=128, out_features=128, bias=False)
200
+ (up_proj): Linear(in_features=128, out_features=128, bias=False)
201
+ (down_proj): Linear(in_features=128, out_features=128, bias=False)
202
+ (act_fn): SiLUActivation()
203
+ )
204
+ )
205
+ (input_layernorm): MistralLarge4RMSNorm((128,), eps=1e-05)
206
+ (post_attention_layernorm): MistralLarge4RMSNorm((128,), eps=1e-05)
207
+ )
208
+ (8-9): 2 x MistralLarge4TextDecoderLayer(
209
+ (self_attn): MistralLarge4TextAttention(
210
+ (kv_a_proj_with_mqa): Linear(in_features=128, out_features=576, bias=False)
211
+ (kv_a_layernorm): MistralLarge4RMSNorm((512,), eps=1e-05)
212
+ (kv_b_proj): Linear(in_features=512, out_features=768, bias=False)
213
+ (o_proj): Linear(in_features=512, out_features=128, bias=False)
214
+ (indexer): MistralLarge4TextIndexer(
215
+ (wq_b): Linear(in_features=128, out_features=512, bias=False)
216
+ (wk): Linear(in_features=128, out_features=128, bias=False)
217
+ (k_norm): LayerNorm((128,), eps=1e-06, elementwise_affine=True, bias=True)
218
+ (weights_proj): Linear(in_features=128, out_features=4, bias=False)
219
+ (q_input_norm): LayerNorm((128,), eps=1e-06, elementwise_affine=True, bias=True)
220
+ (softmax_scaling): MistralLarge4TextSoftmaxScaling()
221
+ )
222
+ (q_proj): Linear(in_features=128, out_features=512, bias=False)
223
+ (softmax_scaling): MistralLarge4TextSoftmaxScaling()
224
+ )
225
+ (mlp): MistralLarge4TextMoE(
226
+ (experts): MistralLarge4TextExperts(
227
+ (act_fn): SiLUActivation()
228
+ )
229
+ (gate): MistralLarge4TextTopkRouter()
230
+ (shared_experts): MistralLarge4TextMLP(
231
+ (gate_proj): Linear(in_features=128, out_features=128, bias=False)
232
+ (up_proj): Linear(in_features=128, out_features=128, bias=False)
233
+ (down_proj): Linear(in_features=128, out_features=128, bias=False)
234
+ (act_fn): SiLUActivation()
235
+ )
236
+ )
237
+ (input_layernorm): MistralLarge4RMSNorm((128,), eps=1e-05)
238
+ (post_attention_layernorm): MistralLarge4RMSNorm((128,), eps=1e-05)
239
+ )
240
+ (10): MistralLarge4TextDecoderLayer(
241
+ (self_attn): MistralLarge4TextAttention(
242
+ (kv_a_proj_with_mqa): Linear(in_features=128, out_features=576, bias=False)
243
+ (kv_a_layernorm): MistralLarge4RMSNorm((512,), eps=1e-05)
244
+ (kv_b_proj): Linear(in_features=512, out_features=768, bias=False)
245
+ (o_proj): Linear(in_features=512, out_features=128, bias=False)
246
+ (q_proj): Linear(in_features=128, out_features=512, bias=False)
247
+ (softmax_scaling): MistralLarge4TextSoftmaxScaling()
248
+ )
249
+ (mlp): MistralLarge4TextMoE(
250
+ (experts): MistralLarge4TextExperts(
251
+ (act_fn): SiLUActivation()
252
+ )
253
+ (gate): MistralLarge4TextTopkRouter()
254
+ (shared_experts): MistralLarge4TextMLP(
255
+ (gate_proj): Linear(in_features=128, out_features=128, bias=False)
256
+ (up_proj): Linear(in_features=128, out_features=128, bias=False)
257
+ (down_proj): Linear(in_features=128, out_features=128, bias=False)
258
+ (act_fn): SiLUActivation()
259
+ )
260
+ )
261
+ (input_layernorm): MistralLarge4RMSNorm((128,), eps=1e-05)
262
+ (post_attention_layernorm): MistralLarge4RMSNorm((128,), eps=1e-05)
263
+ )
264
+ (11): MistralLarge4TextDecoderLayer(
265
+ (self_attn): MistralLarge4TextAttention(
266
+ (kv_b_proj): Linear(in_features=512, out_features=1024, bias=False)
267
+ (o_proj): Linear(in_features=512, out_features=128, bias=False)
268
+ (q_proj): Linear(in_features=128, out_features=512, bias=False)
269
+ (softmax_scaling): MistralLarge4TextSoftmaxScaling()
270
+ )
271
+ (mlp): MistralLarge4TextMoE(
272
+ (experts): MistralLarge4TextExperts(
273
+ (act_fn): SiLUActivation()
274
+ )
275
+ (gate): MistralLarge4TextTopkRouter()
276
+ (shared_experts): MistralLarge4TextMLP(
277
+ (gate_proj): Linear(in_features=128, out_features=128, bias=False)
278
+ (up_proj): Linear(in_features=128, out_features=128, bias=False)
279
+ (down_proj): Linear(in_features=128, out_features=128, bias=False)
280
+ (act_fn): SiLUActivation()
281
+ )
282
+ )
283
+ (input_layernorm): MistralLarge4RMSNorm((128,), eps=1e-05)
284
+ (post_attention_layernorm): MistralLarge4RMSNorm((128,), eps=1e-05)
285
+ )
286
+ )
287
+ (norm): MistralLarge4RMSNorm((128,), eps=1e-05)
288
+ (rotary_emb): MistralLarge4TextRotaryEmbedding()
289
+ )
290
+ )
291
+ (lm_head): Linear(in_features=128, out_features=204800, bias=False)
292
+ (mtp_dspark): ModuleDict(
293
+ (backbone): ModuleDict(
294
+ (layers): ModuleList(
295
+ (0-2): 3 x Identity()
296
+ )
297
+ )
298
+ )
299
+ )
LICENSE ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Mistral Ecosystem Open-Weight License
2
+
3
+ Mistral Ecosystem Open-Weight License. This license is a modified version of the MIT license.
4
+ Attribution notice: 2026 - Mistral
5
+
6
+ Permission is hereby granted, free of charge, to any person (the “Licensee”) obtaining a copy of this model and associated documentation files - including the model weights, parameters, configuration files, and associated documentation (the “Model”), to deal in the Model without restriction, including without limitation the rights to (a) use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Model; (b) run, deploy, further train or otherwise modify the Model and create derivative works from it; and (c) permit persons to whom the Model is furnished to do so, subject to the following conditions:
7
+
8
+ 1. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Model.
9
+
10
+ 2. If the Licensee or any of its affiliates operates a Model as a Service business, the Licensee must enter into a separate commercial license with Mistral before using the Model or its derivative works for any commercial purpose. The Licensee may contact Mistral, using this form: https://mistral.ai/contact/, to request a commercial license.
11
+
12
+ "Model as a Service" means giving a third party access to the Model or its derivative works for inference or post-training by any means (for instance via API or hosted endpoints), in a manner that allows such third party to exercise meaningful control over the inputs, parameters, or training data. This does not include (a) end-user products with model capabilities solely embedded within specific features or harnesses, or (b) mere relaying of requests to models hosted by others.
13
+
14
+ 3. The requirements set forth in Section 2 do not apply to: (a) internal use of the Model or its derivative works, defined as any use that does not make the Model or its derivative works available to third parties; or (b) any use of the Model accessed through Mistral’s official products.
15
+
16
+ THE MODEL AND ANY OUTPUT THEREFROM ARE PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL MISTRAL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MODEL OR THE USE OR OTHER DEALINGS IN THE MODEL.
17
+
18
+ For any questions regarding this license, please contact us using the form here: https://mistral.ai/contact/
README.md ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ pipeline_tag: image-text-to-text
4
+ base_model:
5
+ - mistralai/Mistral-Large-4-1T-A52B
6
+ ---
7
+
8
+ This is a randomly initialized tiny model based on [mistralai/Mistral-Large-4-1T-A52B](https://huggingface.co/mistralai/Mistral-Large-4-1T-A52B) for testing and debugging.
9
+
10
+ | Feature | Source | This repo |
11
+ |---|---|---|
12
+ | Checkpoint tensor elements | 7.13B BF16, 63.84M F32, 1.05T F8_E4M3 | 54.84M BF16, 1.31M F8_E4M3, 320 F8_E8M0 |
13
+ | Safetensors weight files | 1.06 TB (54 files) | 111.12 MB (consolidated.safetensors) |
14
+ | Architecture / input | Multimodal MoE; text and image | Same |
15
+ | Vocabulary rows / tied embeddings | 204,800 / false | 204,800 / true |
16
+ | Backbone layers | 72 | 12: three complete RoPE/RoPE/RoPE/NoPE cycles |
17
+ | Text hidden size / attention head dimension | 6,144 / 64 | 128 / 32 |
18
+ | Routed / selected / shared experts | 128 / 4 / 1 | 32 / 4 / 1 |
19
+ | DSA indexer | 32 heads; 128-wide; top-2,048 | 4 heads; 128-wide; top-128 |
20
+ | Cross-layer KV sharing | Source pattern | Two complete three-own/one-shared NoPE cycles |
21
+ | Vision tower | 30 layers; 2,048 width | 4 layers; 64 width |
22
+ | DSpark | 3 dense MLA stages; rank 512; depth 3 | 3 dense MLA stages; rank 8; depth 3 |
23
+ | Checkpoint precision | E4M3 block-FP8 + UE8M0 scales; BF16 exclusions | Same format; 64×64 blocks |
24
+
25
+ TP=2 vLLM uses a 64-wide FP8 activation group per rank, which fixes the residual width at 128. The checkpoint retains 64×64 FP8 blocks, a 512-wide MLA latent KV required by H20 sparse MLA, and four 32-wide attention heads. The input/output BF16 token table is tied, saving one 52.43 MB matrix; the optimized vLLM kernel constraints still place the checkpoint above the 30 MB soft target.
26
+
27
+ | File path | Size |
28
+ |------|------|
29
+ | consolidated.safetensors | 111.1MB |
30
+
31
+ ### Example usage
32
+
33
+ #### Transformers (✅ verified)
34
+
35
+ ```python
36
+ def run_transformers(model_id: str):
37
+ import torch
38
+ from PIL import Image
39
+ from transformers import AutoModelForImageTextToText, AutoProcessor
40
+ from transformers.utils.quantization_config import FineGrainedFP8Config
41
+
42
+ model = AutoModelForImageTextToText.from_pretrained(
43
+ str(model_id),
44
+ dtype=torch.bfloat16,
45
+ device_map="cuda",
46
+ attn_implementation="sdpa",
47
+ quantization_config=FineGrainedFP8Config(dequantize=True),
48
+ )
49
+ processor = AutoProcessor.from_pretrained(str(model_id))
50
+ messages = [
51
+ {
52
+ "role": "user",
53
+ "content": [
54
+ {"type": "image", "image": Image.new("RGB", (56, 56), (30, 120, 220))},
55
+ {"type": "text", "text": "Describe this image in one word."},
56
+ ],
57
+ }
58
+ ]
59
+ inputs = processor.apply_chat_template(
60
+ messages,
61
+ add_generation_prompt=True,
62
+ tokenize=True,
63
+ return_dict=True,
64
+ return_tensors="pt",
65
+ reasoning_effort="low",
66
+ ).to(model.device)
67
+ output = model.generate(**inputs, do_sample=False, max_new_tokens=10)
68
+ print(processor.decode(output[0, inputs["input_ids"].shape[1] :], skip_special_tokens=True))
69
+
70
+
71
+ if __name__ == "__main__":
72
+ run_transformers(model_id="tiny-random/mistral-large-4")
73
+ ```
74
+
75
+ #### vLLM offline (✅ verified)
76
+
77
+ Install the snapshot package with `pip install --no-deps <model directory>` before starting vLLM.
78
+
79
+ ```python
80
+ def run_vllm(model_id: str):
81
+ import os
82
+
83
+ os.environ.setdefault("VLLM_USE_FLASHINFER_SAMPLER", "0")
84
+ os.environ.setdefault("VLLM_ALLREDUCE_USE_FLASHINFER", "0")
85
+ os.environ.setdefault("VLLM_ALLREDUCE_USE_SYMM_MEM", "0")
86
+ from PIL import Image
87
+ from transformers import AutoProcessor
88
+ from vllm import LLM, SamplingParams
89
+
90
+ model_id = str(model_id)
91
+ processor = AutoProcessor.from_pretrained(model_id)
92
+ llm = LLM(
93
+ model=model_id,
94
+ trust_remote_code=True,
95
+ tensor_parallel_size=2,
96
+ speculative_config={"method": "dspark", "num_speculative_tokens": 3},
97
+ kv_cache_dtype="bfloat16",
98
+ max_model_len=512,
99
+ max_num_batched_tokens=1024,
100
+ max_num_seqs=2,
101
+ gpu_memory_utilization=0.1,
102
+ disable_custom_all_reduce=True,
103
+ kernel_config={"linear_backend": "triton"},
104
+ attention_config={"backend": "FLASHINFER_MLA_SPARSE_SM90"},
105
+ )
106
+ sampling = SamplingParams(temperature=0, max_tokens=10, ignore_eos=True)
107
+ try:
108
+ print(llm.generate(["Hello"], sampling)[0].outputs[0].text)
109
+ image = Image.new("RGB", (56, 56), "blue")
110
+ inputs = processor.apply_chat_template(
111
+ [
112
+ {
113
+ "role": "user",
114
+ "content": [
115
+ {"type": "image", "image": image},
116
+ {"type": "text", "text": "Describe this image in one word."},
117
+ ],
118
+ }
119
+ ],
120
+ add_generation_prompt=True,
121
+ tokenize=True,
122
+ return_dict=True,
123
+ return_tensors="pt",
124
+ reasoning_effort="low",
125
+ )
126
+ result = llm.generate(
127
+ {"prompt_token_ids": inputs["input_ids"][0].tolist(), "multi_modal_data": {"image": image}},
128
+ sampling,
129
+ )
130
+ print(result[0].outputs[0].text)
131
+ finally:
132
+ llm.llm_engine.engine_core.shutdown(timeout=30)
133
+
134
+
135
+ if __name__ == "__main__":
136
+ run_vllm(model_id="tiny-random/mistral-large-4")
137
+ ```
138
+
139
+ #### vLLM serving (unverified)
140
+
141
+ Use the official Mistral Large 4 vLLM image.
142
+
143
+ ```bash
144
+ docker run --rm --runtime nvidia --gpus all --ipc=host -p 8000:8000 --entrypoint bash \
145
+ -v "$(pwd)/mistral-large-4:/model:ro" vllm/vllm-openai:mistral-large-4 \
146
+ -lc 'pip install --no-deps /model && vllm serve /model \
147
+ --tensor-parallel-size 2 \
148
+ --speculative-config '{"method":"dspark","num_speculative_tokens":3}' \
149
+ --kv-cache-dtype bfloat16 --disable-custom-all-reduce \
150
+ --kernel-config '{"linear_backend":"triton"}' \
151
+ --attention-config '{"backend":"FLASHINFER_MLA_SPARSE_SM90"}' \
152
+ --limit-mm-per-prompt '{"image":1}' --max-model-len 2048 \
153
+ --max-num-batched-tokens 256 --max-num-seqs 4 --gpu-memory-utilization 0.2'
154
+ ```
155
+
156
+ ### Creating this repo
157
+
158
+ - Code: [.meta/create_model.py](.meta/create_model.py)
159
+ - Model structure: [.meta/model.log](.meta/model.log)
160
+ - Environment: [.meta/env.json](.meta/env.json)
161
+
162
+ *This repo is generated by GPT-6.1-Sol.*
chat_template.jinja ADDED
@@ -0,0 +1,258 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {#- Default system message if no system prompt is passed. #}
2
+ {%- set default_system_message = '' %}
3
+
4
+ {#- Begin of sequence token. #}
5
+ {{- bos_token }}
6
+
7
+
8
+ {#- Handle system prompt if it exists. #}
9
+ {%- set loop_messages = messages %}
10
+ {%- if messages[0]['role'] != 'system' and default_system_message != '' %}
11
+ {{- '[SYSTEM_PROMPT]' ~ default_system_message ~ '[/SYSTEM_PROMPT]' }}
12
+ {%- endif %}
13
+
14
+
15
+ {#- Tools and model settings definition #}
16
+ {%- set available_tools = '' %}
17
+ {%- set has_tools = false %}
18
+ {%- if tools is defined and tools is not none and tools|length > 0 %}
19
+ {%- set has_tools = true %}
20
+ {%- set available_tools = '[AVAILABLE_TOOLS]' ~ (tools| tojson) ~ '[/AVAILABLE_TOOLS]' %}
21
+ {%- endif %}
22
+ {%- set json_schema = none %}
23
+ {%- if response_format is defined and response_format is not none %}
24
+ {%- set response_format_type = response_format.get('type', 'text') %}
25
+ {%- set response_json_schema = response_format.get('json_schema') %}
26
+ {%- if response_format_type not in ['text', 'json_object', 'json_schema'] %}
27
+ {{- raise_exception('Response format type must be one of text, json_object or json_schema, got ' ~ response_format_type ~ '.') }}
28
+ {%- elif response_format_type == 'json_schema' %}
29
+ {%- if response_json_schema is none or response_json_schema.get('schema') is none %}
30
+ {{- raise_exception('Response format `json_schema` must define the schema') }}
31
+ {%- else %}
32
+ {%- set json_schema = response_json_schema['schema'] %}
33
+ {%- endif %}
34
+ {%- elif response_format_type == 'json_object' %}
35
+ {%- set json_schema = {'anyOf': [{'type': 'object'}, {'type': 'array'}]} %}
36
+ {%- endif %}
37
+ {%- endif %}
38
+ {%- if reasoning_effort is not defined or reasoning_effort is none %}
39
+ {%- set reasoning_effort = 'high' %}
40
+ {%- endif %}
41
+ {%- if reasoning_effort not in ['low', 'medium', 'high'] %}
42
+ {{- raise_exception('reasoning_effort must be one of "low", "medium", "high"') }}
43
+ {%- endif %}
44
+ {%- set model_settings_parts = [] %}
45
+ {%- if json_schema is not none %}
46
+ {%- set model_settings_parts = model_settings_parts + ['"json_schema": ' ~ (json_schema|tojson)] %}
47
+ {%- endif %}
48
+ {%- set model_settings_parts = model_settings_parts + ['"reasoning_effort": "' ~ reasoning_effort ~ '"'] %}
49
+ {%- set model_settings = '' %}
50
+ {%- if model_settings_parts %}
51
+ {%- set model_settings = '[MODEL_SETTINGS]{' ~ model_settings_parts|join(', ') ~ '}[/MODEL_SETTINGS]' %}
52
+ {%- endif %}
53
+
54
+ {#- Macros #}
55
+ {%- macro render_content(content, context_name, supported_types_desc, support_thinking, support_images) -%}
56
+ {%- if content is string -%}
57
+ {{- content -}}
58
+ {%- elif content -%}
59
+ {%- for block in content -%}
60
+ {%- if block['type'] == 'text' -%}
61
+ {{- block['text'] -}}
62
+ {%- elif support_thinking and block['type'] == 'thinking' -%}
63
+ {{- '[THINK]' ~ block['thinking'] -}}
64
+ {%- if block.get('closed', true) -%}{{- '[/THINK]' -}}{%- endif -%}
65
+ {%- elif support_images and block['type'] in ['image', 'image_url'] -%}
66
+ {{- '[IMG]' -}}
67
+ {%- else -%}
68
+ {{- raise_exception('Only ' ~ supported_types_desc ~ ' chunks are supported in ' ~ context_name ~ '.') -}}
69
+ {%- endif -%}
70
+ {%- endfor -%}
71
+ {%- else -%}
72
+ {{- raise_exception(context_name ~ ' must have non-empty content.') -}}
73
+ {%- endif -%}
74
+ {%- endmacro -%}
75
+
76
+ {#- Aggregate consecutive messages with the same role except system and tool. #}
77
+ {#- A sentinel message is appended so the last group gets flushed inside the loop. #}
78
+ {%- set ns_agg = namespace(messages=[], current_group=[], current_role=none) %}
79
+ {%- for message in loop_messages + [{'role': '__sentinel__'}] %}
80
+ {%- if message['role'] != ns_agg.current_role or message['role'] == 'system' or message['role'] == 'tool' %}
81
+ {%- if ns_agg.current_role == 'tool' %}
82
+ {%- set ns_agg.messages = ns_agg.messages + ns_agg.current_group %}
83
+ {%- elif ns_agg.current_role is not none %}
84
+ {%- set ns_c = namespace(text_parts=[], chunks=[], has_non_text=false, tool_calls=[]) %}
85
+ {%- for msg in ns_agg.current_group %}
86
+ {#- Convert reasoning / reasoning_content to a leading thinking chunk. #}
87
+ {%- set reasoning = msg.get('reasoning_content', msg.get('reasoning', none)) %}
88
+ {%- if reasoning is not none and reasoning != '' %}
89
+ {%- if msg['content'] is not none and msg['content'] is not string %}
90
+ {%- for block in msg['content'] %}
91
+ {%- if block['type'] == 'thinking' %}
92
+ {{- raise_exception('Message cannot have both thinking chunks in content and a top-level `reasoning` or `reasoning_content` field.') }}
93
+ {%- endif %}
94
+ {%- endfor %}
95
+ {%- endif %}
96
+ {%- set think_chunk = {'type': 'thinking', 'thinking': reasoning} %}
97
+ {%- if msg['content'] is string and msg['content'] != '' %}
98
+ {%- set new_content = [think_chunk, {'type': 'text', 'text': msg['content']}] %}
99
+ {%- elif msg['content'] is not none and msg['content'] is not string and msg['content'] | length > 0 %}
100
+ {%- set new_content = [think_chunk] + msg['content'] | list %}
101
+ {%- else %}
102
+ {%- set new_content = [think_chunk] %}
103
+ {%- endif %}
104
+ {%- if msg['tool_calls'] is defined and msg['tool_calls'] is not none %}
105
+ {%- set msg = {'role': msg['role'], 'content': new_content, 'tool_calls': msg['tool_calls']} %}
106
+ {%- else %}
107
+ {%- set msg = {'role': msg['role'], 'content': new_content} %}
108
+ {%- endif %}
109
+ {%- endif %}
110
+ {%- if msg['content'] is string %}
111
+ {%- set ns_c.text_parts = ns_c.text_parts + [msg['content']] %}
112
+ {%- elif msg['content'] is not none %}
113
+ {%- set ns_msg = namespace(msg_text_parts=[]) %}
114
+ {%- for block in msg['content'] %}
115
+ {%- if block['type'] == 'text' %}
116
+ {%- set ns_msg.msg_text_parts = ns_msg.msg_text_parts + [block['text']] %}
117
+ {%- else %}
118
+ {%- if ns_msg.msg_text_parts | length > 0 %}
119
+ {%- set ns_c.text_parts = ns_c.text_parts + [ns_msg.msg_text_parts | join('')] %}
120
+ {%- set ns_msg.msg_text_parts = [] %}
121
+ {%- endif %}
122
+ {%- if ns_c.text_parts | length > 0 %}
123
+ {%- set ns_c.chunks = ns_c.chunks + [{'type': 'text', 'text': ns_c.text_parts | join('\n\n')}] %}
124
+ {%- set ns_c.text_parts = [] %}
125
+ {%- endif %}
126
+ {%- set ns_c.chunks = ns_c.chunks + [block] %}
127
+ {%- set ns_c.has_non_text = true %}
128
+ {%- endif %}
129
+ {%- endfor %}
130
+ {%- if ns_msg.msg_text_parts | length > 0 %}
131
+ {%- set ns_c.text_parts = ns_c.text_parts + [ns_msg.msg_text_parts | join('')] %}
132
+ {%- endif %}
133
+ {%- endif %}
134
+ {%- if msg['tool_calls'] is defined and msg['tool_calls'] is not none %}
135
+ {%- set ns_c.tool_calls = ns_c.tool_calls + msg['tool_calls'] | list %}
136
+ {%- endif %}
137
+ {%- endfor %}
138
+ {%- if ns_c.has_non_text %}
139
+ {%- if ns_c.text_parts | length > 0 %}
140
+ {%- set ns_c.chunks = ns_c.chunks + [{'type': 'text', 'text': ns_c.text_parts | join('\n\n')}] %}
141
+ {%- endif %}
142
+ {%- set merged_content = ns_c.chunks %}
143
+ {%- else %}
144
+ {%- set merged_content = ns_c.text_parts | join('\n\n') %}
145
+ {%- endif %}
146
+ {%- if ns_c.tool_calls | length > 0 %}
147
+ {%- set ns_agg.messages = ns_agg.messages + [{'role': ns_agg.current_role, 'content': merged_content, 'tool_calls': ns_c.tool_calls}] %}
148
+ {%- else %}
149
+ {%- set ns_agg.messages = ns_agg.messages + [{'role': ns_agg.current_role, 'content': merged_content}] %}
150
+ {%- endif %}
151
+ {%- endif %}
152
+ {%- if message['role'] != '__sentinel__' %}
153
+ {%- set ns_agg.current_group = [message] %}
154
+ {%- set ns_agg.current_role = message['role'] %}
155
+ {%- endif %}
156
+ {%- else %}
157
+ {%- set ns_agg.current_group = ns_agg.current_group + [message] %}
158
+ {%- endif %}
159
+ {%- endfor %}
160
+ {%- set loop_messages = ns_agg.messages %}
161
+
162
+ {#- Validates message ordering. #}
163
+ {%- set ns = namespace(available_tools_and_settings_emitted=false) %}
164
+ {%- if loop_messages | length > 0 and loop_messages[0]['role'] not in ['user', 'system'] %}
165
+ {{- raise_exception('Conversation must start with a user or system message, got ' ~ loop_messages[0]['role'] ~ '.') }}
166
+ {%- endif %}
167
+ {%- set ns_order = namespace(previous_role=none) %}
168
+ {%- for message in loop_messages %}
169
+ {%- set current_role = message['role'] %}
170
+ {%- if ns_order.previous_role is not none %}
171
+ {%- if ns_order.previous_role == 'system' %}
172
+ {%- if current_role not in ['user', 'assistant', 'system'] %}
173
+ {{- raise_exception('Unexpected role \'' ~ current_role ~ '\' after role \'' ~ ns_order.previous_role ~ '\'') }}
174
+ {%- endif %}
175
+ {%- elif ns_order.previous_role == 'user' %}
176
+ {%- if current_role not in ['assistant', 'system', 'user'] %}
177
+ {{- raise_exception('Unexpected role \'' ~ current_role ~ '\' after role \'' ~ ns_order.previous_role ~ '\'') }}
178
+ {%- endif %}
179
+ {%- elif ns_order.previous_role == 'assistant' %}
180
+ {%- if current_role not in ['assistant', 'user', 'tool'] %}
181
+ {{- raise_exception('Unexpected role \'' ~ current_role ~ '\' after role \'' ~ ns_order.previous_role ~ '\'') }}
182
+ {%- endif %}
183
+ {%- elif ns_order.previous_role == 'tool' %}
184
+ {%- if current_role not in ['assistant', 'tool', 'user'] %}
185
+ {{- raise_exception('Unexpected role \'' ~ current_role ~ '\' after role \'' ~ ns_order.previous_role ~ '\'') }}
186
+ {%- endif %}
187
+ {%- endif %}
188
+ {%- endif %}
189
+ {%- set ns_order.previous_role = current_role %}
190
+ {%- endfor %}
191
+
192
+ {#- Handle conversation messages. #}
193
+ {%- for message in loop_messages %}
194
+ {#- User messages supports text, image and image_url content. #}
195
+ {%- if message['role'] == 'user' %}
196
+ {%- if not ns.available_tools_and_settings_emitted %}
197
+ {{- available_tools }}
198
+ {{- model_settings }}
199
+ {%- set ns.available_tools_and_settings_emitted = true %}
200
+ {%- endif %}
201
+ {%- if message['content'] is not string and message['content'] %}
202
+ {#- When content has exactly one image and one text block, put image first. #}
203
+ {%- if message['content'] | length == 2 and message['content'][0]['type'] == 'text' and message['content'][1]['type'] in ['image', 'image_url'] %}
204
+ {%- set blocks = [message['content'][1], message['content'][0]] %}
205
+ {%- else %}
206
+ {%- set blocks = message['content'] %}
207
+ {%- endif %}
208
+ {%- set user_content = blocks %}
209
+ {%- else %}
210
+ {%- set user_content = message['content'] %}
211
+ {%- endif %}
212
+ {{- '[INST]' -}}
213
+ {{- render_content(content=user_content, context_name='user message content', supported_types_desc='text, image and image_url', support_thinking=false, support_images=true) -}}
214
+ {{- '[/INST]' }}
215
+
216
+ {#- Assistant messages supports text and thinking content. #}
217
+ {%- elif message['role'] == 'assistant' %}
218
+ {%- if (message['content'] is none or message['content'] == '' or message['content']|length == 0) and (message['tool_calls'] is not defined or message['tool_calls'] is none or message['tool_calls']|length == 0) %}
219
+ {{- raise_exception('Assistant message must have a string or a list of chunks in content or a list of tool calls.') }}
220
+ {%- endif %}
221
+
222
+ {%- if message['content'] %}
223
+ {{- render_content(content=message['content'], context_name='assistant message contents', supported_types_desc='text and thinking', support_thinking=true, support_images=false) -}}
224
+ {%- endif %}
225
+
226
+ {%- if message['tool_calls'] is defined and message['tool_calls'] is not none and message['tool_calls']|length > 0 %}
227
+ {%- for tool in message['tool_calls'] %}
228
+ {{- '[TOOL_CALLS]' }}
229
+ {%- set name = tool['function']['name'] %}
230
+ {%- set arguments = tool['function']['arguments'] %}
231
+ {%- if arguments is not string %}
232
+ {%- set arguments = arguments|tojson|safe %}
233
+ {%- elif arguments == '' %}
234
+ {%- set arguments = '{}' %}
235
+ {%- endif %}
236
+ {{- name ~ '[ARGS]' ~ arguments }}
237
+ {%- endfor %}
238
+ {%- endif %}
239
+
240
+ {{- eos_token }}
241
+
242
+ {#- Tool messages (multimodal). #}
243
+ {%- elif message['role'] == 'tool' %}
244
+ {{- '[TOOL_RESULTS]' -}}
245
+ {{- render_content(content=message['content'], context_name='tool message contents', supported_types_desc='text and image', support_thinking=false, support_images=true) -}}
246
+ {{- '[/TOOL_RESULTS]' }}
247
+
248
+ {#- System messages. #}
249
+ {%- elif message['role'] == 'system' %}
250
+ {{- '[SYSTEM_PROMPT]' -}}
251
+ {{- render_content(content=message['content'], context_name='system message contents', supported_types_desc='text', support_thinking=false, support_images=false) -}}
252
+ {{- '[/SYSTEM_PROMPT]' -}}
253
+
254
+ {#- Raise exception for unsupported roles. #}
255
+ {%- else %}
256
+ {{- raise_exception('Only user, assistant, system and tool roles are supported, got ' ~ message['role'] ~ '.') }}
257
+ {%- endif %}
258
+ {%- endfor %}
config.json ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "MistralLarge4ForConditionalGeneration"
4
+ ],
5
+ "dtype": "bfloat16",
6
+ "image_token_index": 10,
7
+ "model_type": "mistral_large4",
8
+ "multimodal_projector_bias": false,
9
+ "projector_hidden_act": "gelu",
10
+ "quantization_config": {
11
+ "quant_method": "fp8",
12
+ "activation_scheme": "dynamic",
13
+ "weight_block_size": [
14
+ 64,
15
+ 64
16
+ ],
17
+ "scale_fmt": "ue8m0",
18
+ "modules_to_not_convert": [
19
+ "model.vision_tower",
20
+ "model.multi_modal_projector",
21
+ "lm_head",
22
+ "kv_b_proj",
23
+ "indexer.wk",
24
+ "indexer.weights_proj",
25
+ "kv_a_proj_with_mqa"
26
+ ]
27
+ },
28
+ "spatial_merge_size": 2,
29
+ "text_config": {
30
+ "attention_bias": false,
31
+ "attention_dropout": 0.0,
32
+ "bos_token_id": 1,
33
+ "eos_token_id": 2,
34
+ "final_logit_softcapping": 30.0,
35
+ "first_k_dense_replace": 1,
36
+ "head_dim": 32,
37
+ "hidden_act": "silu",
38
+ "hidden_size": 128,
39
+ "index_head_dim": 128,
40
+ "index_n_heads": 4,
41
+ "index_topk": 128,
42
+ "indexer_types": [
43
+ "full",
44
+ "full",
45
+ "full",
46
+ "full",
47
+ "full",
48
+ "full",
49
+ "shared",
50
+ "shared",
51
+ "full",
52
+ "full",
53
+ "shared",
54
+ "shared"
55
+ ],
56
+ "initializer_range": 0.02,
57
+ "intermediate_size": 128,
58
+ "kv_lora_rank": 512,
59
+ "kv_source_layers": [
60
+ 0,
61
+ 1,
62
+ 2,
63
+ 3,
64
+ 4,
65
+ 5,
66
+ 6,
67
+ 3,
68
+ 8,
69
+ 9,
70
+ 10,
71
+ 3
72
+ ],
73
+ "layer_types": [
74
+ "indexed_attention",
75
+ "indexed_attention",
76
+ "indexed_attention",
77
+ "indexed_attention",
78
+ "indexed_attention",
79
+ "indexed_attention",
80
+ "indexed_attention",
81
+ "indexed_attention",
82
+ "indexed_attention",
83
+ "indexed_attention",
84
+ "indexed_attention",
85
+ "indexed_attention"
86
+ ],
87
+ "max_position_embeddings": 1048576,
88
+ "mlp_layer_types": [
89
+ "dense",
90
+ "sparse",
91
+ "sparse",
92
+ "sparse",
93
+ "sparse",
94
+ "sparse",
95
+ "sparse",
96
+ "sparse",
97
+ "sparse",
98
+ "sparse",
99
+ "sparse",
100
+ "sparse"
101
+ ],
102
+ "model_type": "mistral_large4_text",
103
+ "moe_intermediate_size": 128,
104
+ "n_group": 1,
105
+ "n_routed_experts": 32,
106
+ "n_shared_experts": 1,
107
+ "no_rope_layer_interval": 4,
108
+ "no_rope_layers": [
109
+ 1,
110
+ 1,
111
+ 1,
112
+ 0,
113
+ 1,
114
+ 1,
115
+ 1,
116
+ 0,
117
+ 1,
118
+ 1,
119
+ 1,
120
+ 0
121
+ ],
122
+ "num_attention_heads": 4,
123
+ "num_experts_per_tok": 4,
124
+ "num_hidden_layers": 12,
125
+ "num_key_value_heads": 4,
126
+ "output_router_logits": false,
127
+ "pad_token_id": null,
128
+ "qk_head_dim": 128,
129
+ "qk_nope_head_dim": 64,
130
+ "qk_rope_head_dim": 64,
131
+ "rms_norm_eps": 1e-05,
132
+ "rope_parameters": {
133
+ "attention_factor": 1.0,
134
+ "beta_fast": 32,
135
+ "beta_slow": 1,
136
+ "factor": 2048,
137
+ "original_max_position_embeddings": 512,
138
+ "rope_theta": 10000.0,
139
+ "rope_type": "yarn"
140
+ },
141
+ "routed_scaling_factor": 1.0,
142
+ "tie_word_embeddings": true,
143
+ "topk_group": 1,
144
+ "use_cache": true,
145
+ "v_head_dim": 128,
146
+ "vocab_size": 204800,
147
+ "architectures": [
148
+ "MistralLarge4ForCausalLM"
149
+ ],
150
+ "mtp_config": {
151
+ "n_layers": 3,
152
+ "depth": 3,
153
+ "ragged_attention": "32,32,32",
154
+ "target_activation_layers": "1,4,7,10,11",
155
+ "norm_strategy": "eagle",
156
+ "dspark": {
157
+ "markov_rank": 4,
158
+ "head_type": "rnn",
159
+ "draft_input": "position_specific"
160
+ }
161
+ }
162
+ },
163
+ "tie_word_embeddings": true,
164
+ "transformers_version": "5.21.0.dev0",
165
+ "transformers_weights": "consolidated.safetensors",
166
+ "vision_config": {
167
+ "attention_dropout": 0.0,
168
+ "head_dim": 32,
169
+ "hidden_act": "silu",
170
+ "hidden_size": 64,
171
+ "image_size": 1540,
172
+ "initializer_range": 0.02,
173
+ "intermediate_size": 128,
174
+ "model_type": "pixtral",
175
+ "num_attention_heads": 2,
176
+ "num_channels": 3,
177
+ "num_hidden_layers": 4,
178
+ "patch_size": 14,
179
+ "rope_parameters": {
180
+ "rope_theta": 10000.0,
181
+ "rope_type": "axial"
182
+ }
183
+ },
184
+ "vision_feature_layer": -1
185
+ }
consolidated.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:233e1a76d998d19bf117cf6acc381c31eeb46a3313811543d60f7d42cfaada56
3
+ size 111124456
generation_config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 1,
3
+ "do_sample": true,
4
+ "eos_token_id": 2,
5
+ "max_length": 1048576,
6
+ "pad_token_id": 11,
7
+ "temperature": 1.0,
8
+ "top_p": 0.95,
9
+ "transformers_version": "5.21.0.dev0"
10
+ }
params.json ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "dim": 128,
3
+ "n_layers": 12,
4
+ "head_dim": 32,
5
+ "hidden_dim": 128,
6
+ "n_heads": 4,
7
+ "n_kv_heads": 4,
8
+ "rope_theta": 10000.0,
9
+ "norm_eps": 1e-05,
10
+ "vocab_size": 204800,
11
+ "tied_embeddings": true,
12
+ "max_position_embeddings": 1048576,
13
+ "ragged_attention": null,
14
+ "nope": "rope,rope,rope,nope",
15
+ "softmax_tanh_gating": 30.0,
16
+ "llama_4_scaling": null,
17
+ "q_lora_rank": null,
18
+ "qk_rope_head_dim": 64,
19
+ "qk_nope_head_dim": 64,
20
+ "kv_lora_rank": 512,
21
+ "v_head_dim": 128,
22
+ "ssmax_scaling": true,
23
+ "lerope": true,
24
+ "dsa": {
25
+ "topk": 128,
26
+ "n_heads": 4,
27
+ "head_dim": 128,
28
+ "rope_head_dim": 64,
29
+ "match_nope": true,
30
+ "ssmax_scaling": true,
31
+ "norm_eps": 1e-06,
32
+ "sharing": "full,full,full,full,full,full,shared,shared,full,full,shared,shared",
33
+ "fp8_indexer": true,
34
+ "fp8_kv_cache": true
35
+ },
36
+ "quantization": {
37
+ "qscheme_act": "BLOCK",
38
+ "qformat_weight": "fp8_e4m3",
39
+ "qdynamic_act": true,
40
+ "qscheme_weight": "BLOCK",
41
+ "use_ue8m0_for_qscales": true,
42
+ "block_size_out": 64,
43
+ "block_size_in": 64,
44
+ "quantize_kv_a": false
45
+ },
46
+ "yarn": {
47
+ "original_max_position_embeddings": 512,
48
+ "factor": 2048,
49
+ "apply_scale": false,
50
+ "beta": 32,
51
+ "alpha": 1
52
+ },
53
+ "kv_sharing": {
54
+ "source_layers_str": "0,1,2,3,4,5,6,3,8,9,10,3"
55
+ },
56
+ "moe": {
57
+ "expert_parallel": 1,
58
+ "expert_model_parallel": 1,
59
+ "route_every_n": 1,
60
+ "first_k_dense_replace": 1,
61
+ "num_experts": 32,
62
+ "num_experts_per_tok": 4,
63
+ "num_expert_groups": 1,
64
+ "num_expert_groups_per_tok": 1,
65
+ "routed_scale": 1.0,
66
+ "expert_hidden_dim": 128,
67
+ "num_shared_experts": 1
68
+ },
69
+ "vision_encoder": {
70
+ "image_token_id": 10,
71
+ "image_break_token_id": 12,
72
+ "image_end_token_id": 13,
73
+ "intermediate_size": 128,
74
+ "num_hidden_layers": 4,
75
+ "num_attention_heads": 2,
76
+ "mm_projector_id": "patch_merge",
77
+ "spatial_merge_size": 2,
78
+ "hidden_size": 64,
79
+ "num_channels": 3,
80
+ "image_size": 1540,
81
+ "max_image_size": 1540,
82
+ "patch_size": 14,
83
+ "rope_theta": 10000.0,
84
+ "add_pre_mm_projector_layer_norm": true,
85
+ "adapter_bias": false
86
+ },
87
+ "mtp": {
88
+ "n_layers": 3,
89
+ "depth": 3,
90
+ "ragged_attention": "32,32,32",
91
+ "target_activation_layers": "1,4,7,10,11",
92
+ "norm_strategy": "eagle",
93
+ "dspark": {
94
+ "markov_rank": 4,
95
+ "head_type": "rnn",
96
+ "draft_input": "position_specific"
97
+ }
98
+ }
99
+ }
processor_config.json ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "image_break_token": "[IMG_BREAK]",
3
+ "image_end_token": "[IMG_END]",
4
+ "image_processor": {
5
+ "do_convert_rgb": true,
6
+ "do_normalize": true,
7
+ "do_pad": true,
8
+ "do_rescale": true,
9
+ "do_resize": true,
10
+ "image_mean": [
11
+ 0.48145466,
12
+ 0.4578275,
13
+ 0.40821073
14
+ ],
15
+ "image_processor_type": "PixtralImageProcessor",
16
+ "image_std": [
17
+ 0.26862954,
18
+ 0.26130258,
19
+ 0.27577711
20
+ ],
21
+ "patch_size": 14,
22
+ "resample": 3,
23
+ "rescale_factor": 0.00392156862745098,
24
+ "size": {
25
+ "longest_edge": 1540
26
+ }
27
+ },
28
+ "image_token": "[IMG]",
29
+ "patch_size": 14,
30
+ "processor_class": "PixtralProcessor",
31
+ "spatial_merge_size": 2
32
+ }
pyproject.toml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [build-system]
2
+ requires = ['setuptools>=61']
3
+ build-backend = 'setuptools.build_meta'
4
+
5
+ [project]
6
+ name = 'mistral-large-4-tied-vllm'
7
+ version = '0.1.0'
8
+
9
+ [project.entry-points.'vllm.general_plugins']
10
+ mistral_large4_tied = 'vllm_plugin:register'
11
+
12
+ [tool.setuptools]
13
+ py-modules = ['vllm_mistral_large4_tied', 'vllm_plugin']
tekken.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cc05cc0f7d8ef11e61151df069ffa99499b040e29309006f7bac5a470b8ddb67
3
+ size 25813790
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:23a444357919e98375ac640bdd08723430ba5965da96c5f920ee2bad2390dc3e
3
+ size 27851075
tokenizer_config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "backend": "tokenizers",
3
+ "bos_token": "<s>",
4
+ "eos_token": "</s>",
5
+ "model_max_length": 1048576,
6
+ "pad_token": "<pad>",
7
+ "processor_class": "PixtralProcessor",
8
+ "tokenizer_class": "TokenizersBackend",
9
+ "unk_token": "<unk>"
10
+ }
vllm_mistral_large4_tied.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ from vllm.distributed import get_pp_group
2
+ from vllm.models.mistral_large4 import MistralLarge4ForCausalLM
3
+
4
+
5
+ class MistralLarge4TiedForCausalLM(MistralLarge4ForCausalLM):
6
+ def __init__(self, *, vllm_config, prefix=""):
7
+ super().__init__(vllm_config=vllm_config, prefix=prefix)
8
+ if self.config.tie_word_embeddings and get_pp_group().is_last_rank:
9
+ self.lm_head = self.lm_head.tie_weights(self.model.embed_tokens)
vllm_plugin.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ def register():
2
+ from vllm import ModelRegistry
3
+
4
+ ModelRegistry.register_model(
5
+ "MistralLarge4ForCausalLM",
6
+ "vllm_mistral_large4_tied:MistralLarge4TiedForCausalLM",
7
+ )