prince-canuma
commited on
Upload folder using huggingface_hub
Browse files- .ipynb_checkpoints/model-00001-of-00015-checkpoint.safetensors +0 -0
- README.md +28 -0
- config.json +88 -0
- convert.py +278 -0
- model-00001-of-00015.safetensors +3 -0
- model-00002-of-00015.safetensors +3 -0
- model-00003-of-00015.safetensors +3 -0
- model-00004-of-00015.safetensors +3 -0
- model-00005-of-00015.safetensors +3 -0
- model-00006-of-00015.safetensors +3 -0
- model-00007-of-00015.safetensors +3 -0
- model-00008-of-00015.safetensors +3 -0
- model-00009-of-00015.safetensors +3 -0
- model-00010-of-00015.safetensors +3 -0
- model-00011-of-00015.safetensors +3 -0
- model-00012-of-00015.safetensors +3 -0
- model-00013-of-00015.safetensors +3 -0
- model-00014-of-00015.safetensors +3 -0
- model-00015-of-00015.safetensors +3 -0
- model.safetensors.index.json +0 -0
- special_tokens_map.json +23 -0
- tokenizer.json +0 -0
- tokenizer_config.json +42 -0
.ipynb_checkpoints/model-00001-of-00015-checkpoint.safetensors
ADDED
File without changes
|
README.md
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language:
|
3 |
+
- fr
|
4 |
+
- it
|
5 |
+
- de
|
6 |
+
- es
|
7 |
+
- en
|
8 |
+
license: apache-2.0
|
9 |
+
tags:
|
10 |
+
- moe
|
11 |
+
- mlx
|
12 |
+
---
|
13 |
+
|
14 |
+
# mlx-community/mixtral-8x22b-4bit
|
15 |
+
This model was converted to MLX format from [`v2ray/Mixtral-8x22B-v0.1`]() using mlx-lm version **0.4.0**.
|
16 |
+
Refer to the [original model card](https://huggingface.co/v2ray/Mixtral-8x22B-v0.1) for more details on the model.
|
17 |
+
## Use with mlx
|
18 |
+
|
19 |
+
```bash
|
20 |
+
pip install mlx-lm
|
21 |
+
```
|
22 |
+
|
23 |
+
```python
|
24 |
+
from mlx_lm import load, generate
|
25 |
+
|
26 |
+
model, tokenizer = load("mlx-community/mixtral-8x22b-4bit")
|
27 |
+
response = generate(model, tokenizer, prompt="hello", verbose=True)
|
28 |
+
```
|
config.json
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"add_cross_attention": false,
|
3 |
+
"architectures": [
|
4 |
+
"MixtralForCausalLM"
|
5 |
+
],
|
6 |
+
"attention_dropout": 0.0,
|
7 |
+
"bad_words_ids": null,
|
8 |
+
"begin_suppress_tokens": null,
|
9 |
+
"bos_token_id": 1,
|
10 |
+
"chunk_size_feed_forward": 0,
|
11 |
+
"cross_attention_hidden_size": null,
|
12 |
+
"decoder_start_token_id": null,
|
13 |
+
"diversity_penalty": 0.0,
|
14 |
+
"do_sample": false,
|
15 |
+
"early_stopping": false,
|
16 |
+
"encoder_no_repeat_ngram_size": 0,
|
17 |
+
"eos_token_id": 2,
|
18 |
+
"exponential_decay_length_penalty": null,
|
19 |
+
"finetuning_task": null,
|
20 |
+
"forced_bos_token_id": null,
|
21 |
+
"forced_eos_token_id": null,
|
22 |
+
"hidden_act": "silu",
|
23 |
+
"hidden_size": 6144,
|
24 |
+
"id2label": {
|
25 |
+
"0": "LABEL_0",
|
26 |
+
"1": "LABEL_1"
|
27 |
+
},
|
28 |
+
"initializer_range": 0.02,
|
29 |
+
"intermediate_size": 16384,
|
30 |
+
"is_decoder": false,
|
31 |
+
"is_encoder_decoder": false,
|
32 |
+
"label2id": {
|
33 |
+
"LABEL_0": 0,
|
34 |
+
"LABEL_1": 1
|
35 |
+
},
|
36 |
+
"length_penalty": 1.0,
|
37 |
+
"max_length": 20,
|
38 |
+
"max_position_embeddings": 65536,
|
39 |
+
"min_length": 0,
|
40 |
+
"model_type": "mixtral",
|
41 |
+
"no_repeat_ngram_size": 0,
|
42 |
+
"num_attention_heads": 48,
|
43 |
+
"num_beam_groups": 1,
|
44 |
+
"num_beams": 1,
|
45 |
+
"num_experts_per_tok": 2,
|
46 |
+
"num_hidden_layers": 56,
|
47 |
+
"num_key_value_heads": 8,
|
48 |
+
"num_local_experts": 8,
|
49 |
+
"num_return_sequences": 1,
|
50 |
+
"output_attentions": false,
|
51 |
+
"output_hidden_states": false,
|
52 |
+
"output_router_logits": false,
|
53 |
+
"output_scores": false,
|
54 |
+
"pad_token_id": null,
|
55 |
+
"prefix": null,
|
56 |
+
"problem_type": null,
|
57 |
+
"pruned_heads": {},
|
58 |
+
"quantization": {
|
59 |
+
"group_size": 64,
|
60 |
+
"bits": 4
|
61 |
+
},
|
62 |
+
"remove_invalid_values": false,
|
63 |
+
"repetition_penalty": 1.0,
|
64 |
+
"return_dict": true,
|
65 |
+
"return_dict_in_generate": false,
|
66 |
+
"rms_norm_eps": 1e-05,
|
67 |
+
"rope_theta": 1000000,
|
68 |
+
"router_aux_loss_coef": 0.001,
|
69 |
+
"router_jitter_noise": 0.0,
|
70 |
+
"sep_token_id": null,
|
71 |
+
"sliding_window": null,
|
72 |
+
"suppress_tokens": null,
|
73 |
+
"task_specific_params": null,
|
74 |
+
"temperature": 1.0,
|
75 |
+
"tf_legacy_loss": false,
|
76 |
+
"tie_encoder_decoder": false,
|
77 |
+
"tie_word_embeddings": false,
|
78 |
+
"tokenizer_class": null,
|
79 |
+
"top_k": 50,
|
80 |
+
"top_p": 1.0,
|
81 |
+
"torch_dtype": "bfloat16",
|
82 |
+
"torchscript": false,
|
83 |
+
"transformers_version": "4.39.3",
|
84 |
+
"typical_p": 1.0,
|
85 |
+
"use_bfloat16": false,
|
86 |
+
"use_cache": true,
|
87 |
+
"vocab_size": 32000
|
88 |
+
}
|
convert.py
ADDED
@@ -0,0 +1,278 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright 2023 Mistral AI and The HuggingFace Inc. team. All rights reserved.
|
2 |
+
#
|
3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
# you may not use this file except in compliance with the License.
|
5 |
+
# You may obtain a copy of the License at
|
6 |
+
#
|
7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
#
|
9 |
+
# Unless required by applicable law or agreed to in writing, software
|
10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
# See the License for the specific language governing permissions and
|
13 |
+
# limitations under the License.
|
14 |
+
import argparse
|
15 |
+
import json
|
16 |
+
import os
|
17 |
+
|
18 |
+
import torch
|
19 |
+
from safetensors.torch import load_file
|
20 |
+
|
21 |
+
from transformers import (
|
22 |
+
MixtralConfig,
|
23 |
+
MixtralForCausalLM,
|
24 |
+
)
|
25 |
+
|
26 |
+
"""
|
27 |
+
Sample usage:
|
28 |
+
|
29 |
+
```
|
30 |
+
python src/transformers/models/mixtral/convert_mixtral_weights_to_hf.py \
|
31 |
+
--input_dir /path/to/downloaded/mixtral/weights --model_size 7B --output_dir /output/path
|
32 |
+
```
|
33 |
+
|
34 |
+
Thereafter, models can be loaded via:
|
35 |
+
|
36 |
+
```py
|
37 |
+
from transformers import MixtralForCausalLM
|
38 |
+
|
39 |
+
model = MixtralForCausalLM.from_pretrained("/output/path")
|
40 |
+
```
|
41 |
+
|
42 |
+
Important note: you need to be able to host the whole model in RAM to execute this script (even if the biggest versions
|
43 |
+
come in several checkpoints they each contain a part of each weight of the model, so we need to load them all in RAM).
|
44 |
+
"""
|
45 |
+
|
46 |
+
def compute_intermediate_size(n, ffn_dim_multiplier=1, multiple_of=256):
|
47 |
+
return multiple_of * ((int(ffn_dim_multiplier * int(8 * n / 3)) + multiple_of - 1) // multiple_of)
|
48 |
+
|
49 |
+
def read_json(path):
|
50 |
+
with open(path, "r") as f:
|
51 |
+
return json.load(f)
|
52 |
+
|
53 |
+
def write_json(text, path):
|
54 |
+
with open(path, "w") as f:
|
55 |
+
json.dump(text, f)
|
56 |
+
|
57 |
+
def write_model(model_path, input_base_path, model_size, safe_serialization=True):
|
58 |
+
os.makedirs(model_path, exist_ok=True)
|
59 |
+
|
60 |
+
params = read_json(os.path.join(input_base_path, "params.json"))
|
61 |
+
num_shards = 1
|
62 |
+
|
63 |
+
# For some reason this is a string in the params.json
|
64 |
+
sliding_window = int(params["sliding_window"]) if "sliding_window" in params else None
|
65 |
+
base = params.get("rope_theta", 10000.0)
|
66 |
+
vocab_size = params["vocab_size"]
|
67 |
+
|
68 |
+
if model_size == "7B":
|
69 |
+
dim = params["hidden_size"]
|
70 |
+
max_position_embeddings = 4096 * 8
|
71 |
+
num_local_experts = params["num_local_experts"]
|
72 |
+
ffn_dim = params["intermediate_size"]
|
73 |
+
n_layers = params["num_hidden_layers"]
|
74 |
+
n_heads = params["num_attention_heads"]
|
75 |
+
n_heads_per_shard = n_heads // num_shards
|
76 |
+
dims_per_head = dim // n_heads
|
77 |
+
if "num_key_value_heads" in params:
|
78 |
+
num_key_value_heads = params["num_key_value_heads"] # for GQA / MQA
|
79 |
+
num_local_key_value_heads = num_key_value_heads // num_shards
|
80 |
+
key_value_dim = dims_per_head * num_local_key_value_heads
|
81 |
+
else: # compatibility with other checkpoints
|
82 |
+
num_key_value_heads = n_heads
|
83 |
+
num_local_key_value_heads = n_heads_per_shard
|
84 |
+
key_value_dim = dim
|
85 |
+
rms_norm_eps = params["rms_norm_eps"]
|
86 |
+
elif model_size == "22B":
|
87 |
+
dim = params["dim"]
|
88 |
+
max_position_embeddings = params["max_seq_len"]
|
89 |
+
num_local_experts = params["moe"]["num_experts"]
|
90 |
+
ffn_dim = params["hidden_dim"]
|
91 |
+
n_layers = params["n_layers"]
|
92 |
+
n_heads = params["n_heads"]
|
93 |
+
n_heads_per_shard = n_heads // num_shards
|
94 |
+
dims_per_head = dim // n_heads
|
95 |
+
if "n_kv_heads" in params:
|
96 |
+
num_key_value_heads = params["n_kv_heads"] # for GQA / MQA
|
97 |
+
num_local_key_value_heads = num_key_value_heads // num_shards
|
98 |
+
key_value_dim = dims_per_head * num_local_key_value_heads
|
99 |
+
else: # compatibility with other checkpoints
|
100 |
+
num_key_value_heads = n_heads
|
101 |
+
num_local_key_value_heads = n_heads_per_shard
|
102 |
+
key_value_dim = dim
|
103 |
+
rms_norm_eps = params["norm_eps"]
|
104 |
+
else:
|
105 |
+
raise Exception("Illegal model size:", model_size)
|
106 |
+
|
107 |
+
# permute for sliced rotary
|
108 |
+
def permute(w, n_heads=n_heads, dim1=dim, dim2=dim):
|
109 |
+
return w.view(n_heads, dim1 // n_heads // 2, 2, dim2).transpose(1, 2).reshape(dim1, dim2)
|
110 |
+
|
111 |
+
print(f"Fetching all parameters from the checkpoint at \"{input_base_path}\"...")
|
112 |
+
# Load weights
|
113 |
+
if model_size == "7B":
|
114 |
+
loaded = [
|
115 |
+
torch.load(os.path.join(input_base_path, f"consolidated.{i:02d}.pt"), map_location="cpu") for i in range(8)
|
116 |
+
]
|
117 |
+
merged_state_dict = {}
|
118 |
+
for state_dict in loaded:
|
119 |
+
merged_state_dict.update(state_dict)
|
120 |
+
elif model_size == "22B":
|
121 |
+
merged_state_dict = load_file(os.path.join(input_base_path, "consolidated.safetensors"))
|
122 |
+
print("Parameters load finished.")
|
123 |
+
|
124 |
+
state_dict = {}
|
125 |
+
for layer_i in range(n_layers):
|
126 |
+
print(f"At layer {layer_i}...")
|
127 |
+
# Sharded
|
128 |
+
# Note that attention.w{q,k,v,o}, feed_fordward.w[1,2,3], attention_norm.weight and ffn_norm.weight share
|
129 |
+
# the same storage object, saving attention_norm and ffn_norm will save other weights too, which is
|
130 |
+
# redundant as other weights will be stitched from multiple shards. To avoid that, they are cloned.
|
131 |
+
|
132 |
+
state_dict.update(
|
133 |
+
{
|
134 |
+
f"model.layers.{layer_i}.input_layernorm.weight": merged_state_dict[
|
135 |
+
f"layers.{layer_i}.attention_norm.weight"
|
136 |
+
].clone(),
|
137 |
+
f"model.layers.{layer_i}.post_attention_layernorm.weight": merged_state_dict[
|
138 |
+
f"layers.{layer_i}.ffn_norm.weight"
|
139 |
+
].clone(),
|
140 |
+
}
|
141 |
+
)
|
142 |
+
|
143 |
+
state_dict[f"model.layers.{layer_i}.self_attn.q_proj.weight"] = permute(
|
144 |
+
merged_state_dict[f"layers.{layer_i}.attention.wq.weight"]
|
145 |
+
.view(n_heads_per_shard, dims_per_head, dim)
|
146 |
+
.reshape(dim, dim)
|
147 |
+
)
|
148 |
+
state_dict[f"model.layers.{layer_i}.self_attn.k_proj.weight"] = permute(
|
149 |
+
merged_state_dict[f"layers.{layer_i}.attention.wk.weight"]
|
150 |
+
.view(num_local_key_value_heads, dims_per_head, dim)
|
151 |
+
.reshape(key_value_dim, dim),
|
152 |
+
num_key_value_heads,
|
153 |
+
key_value_dim,
|
154 |
+
dim,
|
155 |
+
)
|
156 |
+
state_dict[f"model.layers.{layer_i}.self_attn.v_proj.weight"] = (
|
157 |
+
merged_state_dict[f"layers.{layer_i}.attention.wv.weight"]
|
158 |
+
.view(num_local_key_value_heads, dims_per_head, dim)
|
159 |
+
.reshape(key_value_dim, dim)
|
160 |
+
)
|
161 |
+
|
162 |
+
state_dict[f"model.layers.{layer_i}.self_attn.o_proj.weight"] = merged_state_dict[
|
163 |
+
f"layers.{layer_i}.attention.wo.weight"
|
164 |
+
]
|
165 |
+
|
166 |
+
if model_size == "7B":
|
167 |
+
w1 = merged_state_dict[f"layers.{layer_i}.block_sparse_moe.w1"]
|
168 |
+
w2 = merged_state_dict[f"layers.{layer_i}.block_sparse_moe.w2"]
|
169 |
+
w3 = merged_state_dict[f"layers.{layer_i}.block_sparse_moe.w3"]
|
170 |
+
|
171 |
+
experts_w1 = [
|
172 |
+
w1[ffn_dim * expert_idx : ffn_dim * (expert_idx + 1), :].contiguous().clone()
|
173 |
+
for expert_idx in range(num_local_experts)
|
174 |
+
]
|
175 |
+
|
176 |
+
for idx, expert_block in enumerate(experts_w1):
|
177 |
+
expert_key = f"model.layers.{layer_i}.block_sparse_moe.experts.{idx}.w1"
|
178 |
+
state_dict[expert_key + ".weight"] = expert_block.clone()
|
179 |
+
|
180 |
+
experts_w2 = [
|
181 |
+
w2[ffn_dim * expert_idx : ffn_dim * (expert_idx + 1), :].contiguous().clone()
|
182 |
+
for expert_idx in range(num_local_experts)
|
183 |
+
]
|
184 |
+
|
185 |
+
for idx, expert_block in enumerate(experts_w2):
|
186 |
+
expert_key = f"model.layers.{layer_i}.block_sparse_moe.experts.{idx}.w2"
|
187 |
+
state_dict[expert_key + ".weight"] = expert_block.T.clone().contiguous()
|
188 |
+
|
189 |
+
experts_w3 = [
|
190 |
+
w3[ffn_dim * expert_idx : ffn_dim * (expert_idx + 1), :].contiguous().clone()
|
191 |
+
for expert_idx in range(num_local_experts)
|
192 |
+
]
|
193 |
+
|
194 |
+
for idx, expert_block in enumerate(experts_w3):
|
195 |
+
expert_key = f"model.layers.{layer_i}.block_sparse_moe.experts.{idx}.w3"
|
196 |
+
state_dict[expert_key + ".weight"] = expert_block.clone()
|
197 |
+
|
198 |
+
state_dict[f"model.layers.{layer_i}.block_sparse_moe.gate.weight"] = merged_state_dict[
|
199 |
+
f"layers.{layer_i}.block_sparse_moe.gate.weight"
|
200 |
+
]
|
201 |
+
elif model_size == "22B":
|
202 |
+
for expert_i in range(num_local_experts):
|
203 |
+
w1 = merged_state_dict[f"layers.{layer_i}.feed_forward.experts.{expert_i}.w1.weight"]
|
204 |
+
w2 = merged_state_dict[f"layers.{layer_i}.feed_forward.experts.{expert_i}.w2.weight"]
|
205 |
+
w3 = merged_state_dict[f"layers.{layer_i}.feed_forward.experts.{expert_i}.w3.weight"]
|
206 |
+
state_dict[f"model.layers.{layer_i}.block_sparse_moe.experts.{expert_i}.w1.weight"] = w1.contiguous().clone()
|
207 |
+
state_dict[f"model.layers.{layer_i}.block_sparse_moe.experts.{expert_i}.w2.weight"] = w2.contiguous().clone()
|
208 |
+
state_dict[f"model.layers.{layer_i}.block_sparse_moe.experts.{expert_i}.w3.weight"] = w3.contiguous().clone()
|
209 |
+
state_dict[f"model.layers.{layer_i}.block_sparse_moe.gate.weight"] = merged_state_dict[
|
210 |
+
f"layers.{layer_i}.feed_forward.gate.weight"
|
211 |
+
]
|
212 |
+
|
213 |
+
state_dict.update(
|
214 |
+
{
|
215 |
+
"model.norm.weight": merged_state_dict["norm.weight"],
|
216 |
+
"model.embed_tokens.weight": merged_state_dict["tok_embeddings.weight"],
|
217 |
+
"lm_head.weight": merged_state_dict["output.weight"],
|
218 |
+
}
|
219 |
+
)
|
220 |
+
|
221 |
+
config_additional_kwargs = {}
|
222 |
+
if model_size == "22B":
|
223 |
+
config_additional_kwargs["num_experts_per_tok"] = params["moe"]["num_experts_per_tok"]
|
224 |
+
config = MixtralConfig(
|
225 |
+
hidden_size=dim,
|
226 |
+
intermediate_size=ffn_dim,
|
227 |
+
num_attention_heads=n_heads,
|
228 |
+
num_hidden_layers=n_layers,
|
229 |
+
rms_norm_eps=rms_norm_eps,
|
230 |
+
num_key_value_heads=num_key_value_heads,
|
231 |
+
vocab_size=vocab_size,
|
232 |
+
rope_theta=base,
|
233 |
+
max_position_embeddings=max_position_embeddings,
|
234 |
+
sliding_window=sliding_window,
|
235 |
+
num_local_experts=num_local_experts,
|
236 |
+
**config_additional_kwargs
|
237 |
+
)
|
238 |
+
|
239 |
+
print("Loading the checkpoint in a Mixtral model.")
|
240 |
+
with torch.device("meta"):
|
241 |
+
model = MixtralForCausalLM(config)
|
242 |
+
# Avoid saving this as part of the config.
|
243 |
+
del model.config._name_or_path
|
244 |
+
model.config.torch_dtype = torch.bfloat16
|
245 |
+
print("Saving in the Transformers format.")
|
246 |
+
|
247 |
+
model.load_state_dict(state_dict, strict=True, assign=True)
|
248 |
+
|
249 |
+
for n, p in model.named_parameters():
|
250 |
+
assert p.device.type != "meta", f"{n} has not been loaded!"
|
251 |
+
|
252 |
+
model.save_pretrained(model_path, safe_serialization=safe_serialization)
|
253 |
+
|
254 |
+
def main():
|
255 |
+
parser = argparse.ArgumentParser()
|
256 |
+
parser.add_argument(
|
257 |
+
"--input-dir",
|
258 |
+
help="Location of Mixtral weights, which contains tokenizer.model and model folders",
|
259 |
+
required=True,
|
260 |
+
)
|
261 |
+
parser.add_argument(
|
262 |
+
"--model-size",
|
263 |
+
choices=["7B", "22B"],
|
264 |
+
help="'f' models correspond to the finetuned versions, and are specific to the Mixtral official release. For more details on Mixtral, checkout the original repo: https://huggingface.co/mistral-ai",
|
265 |
+
default="7B",
|
266 |
+
)
|
267 |
+
parser.add_argument("--output-dir", help="Location to write HF model", required=True)
|
268 |
+
parser.add_argument("--safe-serialization", type=bool, default=True, help="Whether or not to save using `safetensors`.")
|
269 |
+
args = parser.parse_args()
|
270 |
+
write_model(
|
271 |
+
model_path=args.output_dir,
|
272 |
+
input_base_path=args.input_dir,
|
273 |
+
model_size=args.model_size,
|
274 |
+
safe_serialization=args.safe_serialization,
|
275 |
+
)
|
276 |
+
|
277 |
+
if __name__ == "__main__":
|
278 |
+
main()
|
model-00001-of-00015.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:314b7c3ef0ac39ffa20bfc29fcc3ffb355fcb9a0dbc456b8d86f075bb03251ae
|
3 |
+
size 5348243527
|
model-00002-of-00015.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:387e2cd7fe5855521343788e960a2a0ec45b1f0a48fe0d0cf40f2920b2e184a1
|
3 |
+
size 5351416675
|
model-00003-of-00015.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:93256e72ed9577dd863619d12ab12b44d7f802964f993b742b4f83ea8c7edfd8
|
3 |
+
size 5351416739
|
model-00004-of-00015.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f2925dc99a4bb8a098f12190968d8dbfa6b2992f6c3b5d2ee92039925cf39c4c
|
3 |
+
size 5358370680
|
model-00005-of-00015.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:bdc080ecf96f9ecd22f3d723278a4d33a46c176f6a5b1dbe276929651701beb2
|
3 |
+
size 5351416988
|
model-00006-of-00015.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:51c96a3b9cea6c47e37736bc12809e1d36870ca137c907100b2c95244fe9c872
|
3 |
+
size 5351417004
|
model-00007-of-00015.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:11f578df7d003f4a32187d6ab3e3c50a2edf82eb9542ec37a233a0af8d614256
|
3 |
+
size 5351416986
|
model-00008-of-00015.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ecc9bc38ac8b2cdde50491c0982861a5ddcff5679816c43aa1e8fdb25c88c34d
|
3 |
+
size 5351416946
|
model-00009-of-00015.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9619c42f210da268126cb9aef2d529d7546005a18864f3b549650167061930c2
|
3 |
+
size 5358370676
|
model-00010-of-00015.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f809b7cac05afcd9050f26ab38e77eed2a6c9e56af0ef4dea9db8977f03e994c
|
3 |
+
size 5351417016
|
model-00011-of-00015.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e89876f56dc63477ddba26c708b0c100ab42c17c27de9abc6b9f8061283d25ff
|
3 |
+
size 5351417002
|
model-00012-of-00015.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:087f926e66d6ec285f4570c00d61507efd9db949e6738ce4eb755f90099a9415
|
3 |
+
size 5351416958
|
model-00013-of-00015.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f06e87f350b4da91fa163ac1429096a76b4808b0a7c46748fa5d14e957e090f0
|
3 |
+
size 5351416996
|
model-00014-of-00015.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:588f928d1787312f0f532e6825392d96fb5f2735aca3e3eb2cd8dafc7d3eaf08
|
3 |
+
size 5358370654
|
model-00015-of-00015.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d0032391c95d00dd74b464e9b66ab3deb489cac718d1db09e0481674d9f127a5
|
3 |
+
size 4449777275
|
model.safetensors.index.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
special_tokens_map.json
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bos_token": {
|
3 |
+
"content": "<s>",
|
4 |
+
"lstrip": false,
|
5 |
+
"normalized": false,
|
6 |
+
"rstrip": false,
|
7 |
+
"single_word": false
|
8 |
+
},
|
9 |
+
"eos_token": {
|
10 |
+
"content": "</s>",
|
11 |
+
"lstrip": false,
|
12 |
+
"normalized": false,
|
13 |
+
"rstrip": false,
|
14 |
+
"single_word": false
|
15 |
+
},
|
16 |
+
"unk_token": {
|
17 |
+
"content": "<unk>",
|
18 |
+
"lstrip": false,
|
19 |
+
"normalized": false,
|
20 |
+
"rstrip": false,
|
21 |
+
"single_word": false
|
22 |
+
}
|
23 |
+
}
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"add_bos_token": true,
|
3 |
+
"add_eos_token": false,
|
4 |
+
"added_tokens_decoder": {
|
5 |
+
"0": {
|
6 |
+
"content": "<unk>",
|
7 |
+
"lstrip": false,
|
8 |
+
"normalized": false,
|
9 |
+
"rstrip": false,
|
10 |
+
"single_word": false,
|
11 |
+
"special": true
|
12 |
+
},
|
13 |
+
"1": {
|
14 |
+
"content": "<s>",
|
15 |
+
"lstrip": false,
|
16 |
+
"normalized": false,
|
17 |
+
"rstrip": false,
|
18 |
+
"single_word": false,
|
19 |
+
"special": true
|
20 |
+
},
|
21 |
+
"2": {
|
22 |
+
"content": "</s>",
|
23 |
+
"lstrip": false,
|
24 |
+
"normalized": false,
|
25 |
+
"rstrip": false,
|
26 |
+
"single_word": false,
|
27 |
+
"special": true
|
28 |
+
}
|
29 |
+
},
|
30 |
+
"additional_special_tokens": [],
|
31 |
+
"bos_token": "<s>",
|
32 |
+
"clean_up_tokenization_spaces": false,
|
33 |
+
"eos_token": "</s>",
|
34 |
+
"legacy": true,
|
35 |
+
"model_max_length": 1000000000000000019884624838656,
|
36 |
+
"pad_token": null,
|
37 |
+
"sp_model_kwargs": {},
|
38 |
+
"spaces_between_special_tokens": false,
|
39 |
+
"tokenizer_class": "LlamaTokenizer",
|
40 |
+
"unk_token": "<unk>",
|
41 |
+
"use_default_system_prompt": false
|
42 |
+
}
|