Spaces:
Runtime error
Runtime error
Commit
·
739e310
1
Parent(s):
5022ada
Llama 2 Changes
Browse files- README.md +2 -0
- app.py +44 -1
- converter.py +601 -0
- requirements.txt +11 -0
README.md
CHANGED
|
@@ -8,6 +8,8 @@ sdk_version: 5.12.0
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
short_description: Gradio Interface for LLaMa-2-7B model
|
|
|
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
short_description: Gradio Interface for LLaMa-2-7B model
|
| 11 |
+
models:
|
| 12 |
+
- meta-llama/Llama-2-7b
|
| 13 |
---
|
| 14 |
|
| 15 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
|
@@ -1,3 +1,46 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 3 |
+
from huggingface_hub import snapshot_download
|
| 4 |
+
import torch
|
| 5 |
|
| 6 |
+
import os
|
| 7 |
+
import subprocess
|
| 8 |
+
import gc
|
| 9 |
+
|
| 10 |
+
model_id = "meta-llama/Llama-2-7b"
|
| 11 |
+
|
| 12 |
+
print("\n\nSaving model to Local....\n\n")
|
| 13 |
+
|
| 14 |
+
snapshot_download(repo_id=model_id, local_dir="llama")
|
| 15 |
+
|
| 16 |
+
print("\n\nConverting to suitable type...\n\n")
|
| 17 |
+
subprocess.run("python converter.py --input_dir llama --model_size 7B --output_dir model".split(" "))
|
| 18 |
+
print("\n\nModel converted successfully!!\n\n")
|
| 19 |
+
print(os.listdir("model"))
|
| 20 |
+
|
| 21 |
+
gc.collect()
|
| 22 |
+
|
| 23 |
+
print("\n\nInitializing model...\n\n")
|
| 24 |
+
model_interface = pipeline(
|
| 25 |
+
"text-generation",
|
| 26 |
+
model="./model",
|
| 27 |
+
torch_dtype=torch.bfloat16,
|
| 28 |
+
device="cpu",
|
| 29 |
+
)
|
| 30 |
+
print("\n\nModel initialized successfully!!\n\n")
|
| 31 |
+
|
| 32 |
+
def generate_text(text: str) -> str:
|
| 33 |
+
response = model_interface(text, do_sample=False)
|
| 34 |
+
response_text = response[0]["generated_text"]
|
| 35 |
+
return response_text
|
| 36 |
+
|
| 37 |
+
# Create the Gradio interface
|
| 38 |
+
iface = gr.Interface(
|
| 39 |
+
fn=generate_text,
|
| 40 |
+
inputs=gr.Textbox(lines=3, placeholder="Enter your prompt here"),
|
| 41 |
+
outputs=gr.Textbox(lines=5),
|
| 42 |
+
title="Llama 2 Text Generator",
|
| 43 |
+
description="Generate text using the Llama 2 model.",
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
iface.launch()
|
converter.py
ADDED
|
@@ -0,0 +1,601 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2022 EleutherAI 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 gc
|
| 16 |
+
import json
|
| 17 |
+
import os
|
| 18 |
+
import tempfile
|
| 19 |
+
import warnings
|
| 20 |
+
from typing import List
|
| 21 |
+
|
| 22 |
+
import torch
|
| 23 |
+
from tokenizers import AddedToken, processors
|
| 24 |
+
|
| 25 |
+
from transformers import GenerationConfig, LlamaConfig, LlamaForCausalLM, LlamaTokenizer, PreTrainedTokenizerFast
|
| 26 |
+
from transformers.convert_slow_tokenizer import TikTokenConverter
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
try:
|
| 30 |
+
from transformers import LlamaTokenizerFast
|
| 31 |
+
except ImportError as e:
|
| 32 |
+
warnings.warn(e)
|
| 33 |
+
warnings.warn(
|
| 34 |
+
"The converted tokenizer will be the `slow` tokenizer. To use the fast, update your `tokenizers` library and re-run the tokenizer conversion"
|
| 35 |
+
)
|
| 36 |
+
LlamaTokenizerFast = None
|
| 37 |
+
|
| 38 |
+
"""
|
| 39 |
+
Sample usage:
|
| 40 |
+
|
| 41 |
+
```
|
| 42 |
+
python src/transformers/models/llama/convert_llama_weights_to_hf.py \
|
| 43 |
+
--input_dir /path/to/downloaded/llama/weights --model_size 1B --llama_version 3.2 --output_dir /output/path
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
Thereafter, models can be loaded via:
|
| 47 |
+
|
| 48 |
+
```py
|
| 49 |
+
from transformers import LlamaForCausalLM, LlamaTokenizer
|
| 50 |
+
|
| 51 |
+
model = LlamaForCausalLM.from_pretrained("/output/path")
|
| 52 |
+
tokenizer = LlamaTokenizer.from_pretrained("/output/path")
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
Important note: you need to be able to host the whole model in RAM to execute this script (even if the biggest versions
|
| 56 |
+
come in several checkpoints they each contain a part of each weight of the model, so we need to load them all in RAM).
|
| 57 |
+
|
| 58 |
+
If you want your tokenizer to add a bos automatically you should update the tokenizer._tokenizers.post_processor:
|
| 59 |
+
|
| 60 |
+
```py
|
| 61 |
+
from tokenizers import processors
|
| 62 |
+
bos = "<|begin_of_text|>"
|
| 63 |
+
tokenizer._tokenizers.post_processor = processors.Sequence(
|
| 64 |
+
[
|
| 65 |
+
processors.ByteLevel(trim_offsets=False),
|
| 66 |
+
processors.TemplateProcessing(
|
| 67 |
+
single=f"{bos}:0 $A:0",
|
| 68 |
+
pair=f"{bos}:0 $A:0 {bos}:1 $B:1",
|
| 69 |
+
special_tokens=[
|
| 70 |
+
(bos, tokenizer.encode(bos)),
|
| 71 |
+
],
|
| 72 |
+
),
|
| 73 |
+
]
|
| 74 |
+
)
|
| 75 |
+
```
|
| 76 |
+
"""
|
| 77 |
+
|
| 78 |
+
NUM_SHARDS = {
|
| 79 |
+
"1B": 1,
|
| 80 |
+
"3B": 1,
|
| 81 |
+
"7B": 1,
|
| 82 |
+
"8B": 1,
|
| 83 |
+
"8Bf": 1,
|
| 84 |
+
"7Bf": 1,
|
| 85 |
+
"13B": 2,
|
| 86 |
+
"13Bf": 2,
|
| 87 |
+
"34B": 4,
|
| 88 |
+
"30B": 4,
|
| 89 |
+
"65B": 8,
|
| 90 |
+
"70B": 8,
|
| 91 |
+
"70Bf": 8,
|
| 92 |
+
"405B": 8,
|
| 93 |
+
"405B-MP16": 16,
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
CONTEXT_LENGTH_FOR_VERSION = {"Guard-3": 131072, "3.2": 131072, "3.1": 131072, "3": 8192, "2": 4096, "1": 2048}
|
| 97 |
+
|
| 98 |
+
BOS_ADDED_TOKEN = AddedToken(
|
| 99 |
+
"<|begin_of_text|>", single_word=False, lstrip=False, rstrip=False, normalized=False, special=True
|
| 100 |
+
)
|
| 101 |
+
EOS_ADDED_TOKEN = AddedToken(
|
| 102 |
+
"<|end_of_text|>", single_word=False, lstrip=False, rstrip=False, normalized=False, special=True
|
| 103 |
+
)
|
| 104 |
+
EOT_ADDED_TOKEN = AddedToken(
|
| 105 |
+
"<|eot_id|>", single_word=False, lstrip=False, rstrip=False, normalized=False, special=True
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
DEFAULT_LLAMA_SPECIAL_TOKENS = {
|
| 109 |
+
"3": [
|
| 110 |
+
"<|begin_of_text|>",
|
| 111 |
+
"<|end_of_text|>",
|
| 112 |
+
"<|reserved_special_token_0|>",
|
| 113 |
+
"<|reserved_special_token_1|>",
|
| 114 |
+
"<|reserved_special_token_2|>",
|
| 115 |
+
"<|reserved_special_token_3|>",
|
| 116 |
+
"<|start_header_id|>",
|
| 117 |
+
"<|end_header_id|>",
|
| 118 |
+
"<|reserved_special_token_4|>",
|
| 119 |
+
"<|eot_id|>", # end of turn
|
| 120 |
+
]
|
| 121 |
+
+ [f"<|reserved_special_token_{i}|>" for i in range(5, 256 - 5)],
|
| 122 |
+
"3.1": [
|
| 123 |
+
"<|begin_of_text|>",
|
| 124 |
+
"<|end_of_text|>",
|
| 125 |
+
"<|reserved_special_token_0|>",
|
| 126 |
+
"<|reserved_special_token_1|>",
|
| 127 |
+
"<|finetune_right_pad_id|>",
|
| 128 |
+
"<|reserved_special_token_2|>",
|
| 129 |
+
"<|start_header_id|>",
|
| 130 |
+
"<|end_header_id|>",
|
| 131 |
+
"<|eom_id|>", # end of message
|
| 132 |
+
"<|eot_id|>", # end of turn
|
| 133 |
+
"<|python_tag|>",
|
| 134 |
+
]
|
| 135 |
+
+ [f"<|reserved_special_token_{i}|>" for i in range(3, 256 - 8)],
|
| 136 |
+
"3.2": [
|
| 137 |
+
"<|begin_of_text|>",
|
| 138 |
+
"<|end_of_text|>",
|
| 139 |
+
"<|reserved_special_token_0|>",
|
| 140 |
+
"<|reserved_special_token_1|>",
|
| 141 |
+
"<|finetune_right_pad_id|>",
|
| 142 |
+
"<|reserved_special_token_2|>",
|
| 143 |
+
"<|start_header_id|>",
|
| 144 |
+
"<|end_header_id|>",
|
| 145 |
+
"<|eom_id|>", # end of message
|
| 146 |
+
"<|eot_id|>", # end of turn
|
| 147 |
+
"<|python_tag|>",
|
| 148 |
+
]
|
| 149 |
+
+ [f"<|reserved_special_token_{i}|>" for i in range(3, 256 - 8)],
|
| 150 |
+
"Guard-3": [
|
| 151 |
+
"<|begin_of_text|>",
|
| 152 |
+
"<|end_of_text|>",
|
| 153 |
+
"<|reserved_special_token_0|>",
|
| 154 |
+
"<|reserved_special_token_1|>",
|
| 155 |
+
"<|finetune_right_pad_id|>",
|
| 156 |
+
"<|reserved_special_token_2|>",
|
| 157 |
+
"<|start_header_id|>",
|
| 158 |
+
"<|end_header_id|>",
|
| 159 |
+
"<|eom_id|>", # end of message
|
| 160 |
+
"<|eot_id|>", # end of turn
|
| 161 |
+
"<|python_tag|>",
|
| 162 |
+
]
|
| 163 |
+
+ [f"<|reserved_special_token_{i}|>" for i in range(3, 256 - 8)],
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def is_llama_3(version):
|
| 168 |
+
return version in ["3", "3.1", "3.2", "Guard-3"]
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
def compute_intermediate_size(n, ffn_dim_multiplier=1, multiple_of=256):
|
| 172 |
+
return multiple_of * ((int(ffn_dim_multiplier * int(8 * n / 3)) + multiple_of - 1) // multiple_of)
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
def read_json(path):
|
| 176 |
+
with open(path, "r") as f:
|
| 177 |
+
return json.load(f)
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
def write_json(text, path):
|
| 181 |
+
with open(path, "w") as f:
|
| 182 |
+
json.dump(text, f)
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
def write_model(
|
| 186 |
+
model_path,
|
| 187 |
+
input_base_path,
|
| 188 |
+
model_size=None,
|
| 189 |
+
safe_serialization=True,
|
| 190 |
+
llama_version="1",
|
| 191 |
+
vocab_size=None,
|
| 192 |
+
num_shards=None,
|
| 193 |
+
instruct=False,
|
| 194 |
+
push_to_hub=False,
|
| 195 |
+
):
|
| 196 |
+
print("Converting the model.")
|
| 197 |
+
params = read_json(os.path.join(input_base_path, "params.json"))
|
| 198 |
+
num_shards = NUM_SHARDS[model_size] if num_shards is None else num_shards
|
| 199 |
+
params = params.get("model", params)
|
| 200 |
+
n_layers = params["n_layers"]
|
| 201 |
+
n_heads = params["n_heads"]
|
| 202 |
+
n_heads_per_shard = n_heads // num_shards
|
| 203 |
+
dim = params["dim"]
|
| 204 |
+
dims_per_head = dim // n_heads
|
| 205 |
+
base = params.get("rope_theta", 10000.0)
|
| 206 |
+
inv_freq = 1.0 / (base ** (torch.arange(0, dims_per_head, 2).float() / dims_per_head))
|
| 207 |
+
if base > 10000.0 and not is_llama_3(llama_version):
|
| 208 |
+
max_position_embeddings = 16384
|
| 209 |
+
else:
|
| 210 |
+
max_position_embeddings = CONTEXT_LENGTH_FOR_VERSION[llama_version]
|
| 211 |
+
|
| 212 |
+
if params.get("n_kv_heads", None) is not None:
|
| 213 |
+
num_key_value_heads = params["n_kv_heads"] # for GQA / MQA
|
| 214 |
+
num_key_value_heads_per_shard = num_key_value_heads // num_shards
|
| 215 |
+
key_value_dim = dims_per_head * num_key_value_heads
|
| 216 |
+
else: # compatibility with other checkpoints
|
| 217 |
+
num_key_value_heads = n_heads
|
| 218 |
+
num_key_value_heads_per_shard = n_heads_per_shard
|
| 219 |
+
key_value_dim = dim
|
| 220 |
+
|
| 221 |
+
# permute for sliced rotary
|
| 222 |
+
def permute(w, n_heads, dim1=dim, dim2=dim):
|
| 223 |
+
return w.view(n_heads, dim1 // n_heads // 2, 2, dim2).transpose(1, 2).reshape(dim1, dim2)
|
| 224 |
+
|
| 225 |
+
with tempfile.TemporaryDirectory() as tmp_model_path:
|
| 226 |
+
print(f"Fetching all parameters from the checkpoint at {input_base_path}.")
|
| 227 |
+
# Load weights
|
| 228 |
+
if num_shards == 1:
|
| 229 |
+
# Not sharded
|
| 230 |
+
# (The sharded implementation would also work, but this is simpler.)
|
| 231 |
+
loaded = torch.load(os.path.join(input_base_path, "consolidated.00.pth"), map_location="cpu")
|
| 232 |
+
else:
|
| 233 |
+
# Sharded
|
| 234 |
+
checkpoint_list = sorted([file for file in os.listdir(input_base_path) if file.endswith(".pth")])
|
| 235 |
+
print("Loading in order:", checkpoint_list)
|
| 236 |
+
loaded = [torch.load(os.path.join(input_base_path, file), map_location="cpu") for file in checkpoint_list]
|
| 237 |
+
param_count = 0
|
| 238 |
+
index_dict = {"weight_map": {}}
|
| 239 |
+
for layer_i in range(n_layers):
|
| 240 |
+
filename = f"pytorch_model-{layer_i + 1}-of-{n_layers + 1}.bin"
|
| 241 |
+
if num_shards == 1:
|
| 242 |
+
# Unsharded
|
| 243 |
+
state_dict = {
|
| 244 |
+
f"model.layers.{layer_i}.self_attn.q_proj.weight": permute(
|
| 245 |
+
loaded[f"layers.{layer_i}.attention.wq.weight"], n_heads=n_heads
|
| 246 |
+
),
|
| 247 |
+
f"model.layers.{layer_i}.self_attn.k_proj.weight": permute(
|
| 248 |
+
loaded[f"layers.{layer_i}.attention.wk.weight"],
|
| 249 |
+
n_heads=num_key_value_heads,
|
| 250 |
+
dim1=key_value_dim,
|
| 251 |
+
),
|
| 252 |
+
f"model.layers.{layer_i}.self_attn.v_proj.weight": loaded[f"layers.{layer_i}.attention.wv.weight"],
|
| 253 |
+
f"model.layers.{layer_i}.self_attn.o_proj.weight": loaded[f"layers.{layer_i}.attention.wo.weight"],
|
| 254 |
+
f"model.layers.{layer_i}.mlp.gate_proj.weight": loaded[f"layers.{layer_i}.feed_forward.w1.weight"],
|
| 255 |
+
f"model.layers.{layer_i}.mlp.down_proj.weight": loaded[f"layers.{layer_i}.feed_forward.w2.weight"],
|
| 256 |
+
f"model.layers.{layer_i}.mlp.up_proj.weight": loaded[f"layers.{layer_i}.feed_forward.w3.weight"],
|
| 257 |
+
f"model.layers.{layer_i}.input_layernorm.weight": loaded[
|
| 258 |
+
f"layers.{layer_i}.attention_norm.weight"
|
| 259 |
+
],
|
| 260 |
+
f"model.layers.{layer_i}.post_attention_layernorm.weight": loaded[
|
| 261 |
+
f"layers.{layer_i}.ffn_norm.weight"
|
| 262 |
+
],
|
| 263 |
+
}
|
| 264 |
+
else:
|
| 265 |
+
# Sharded
|
| 266 |
+
# Note that attention.w{q,k,v,o}, feed_fordward.w[1,2,3], attention_norm.weight and ffn_norm.weight share
|
| 267 |
+
# the same storage object, saving attention_norm and ffn_norm will save other weights too, which is
|
| 268 |
+
# redundant as other weights will be stitched from multiple shards. To avoid that, they are cloned.
|
| 269 |
+
|
| 270 |
+
state_dict = {
|
| 271 |
+
f"model.layers.{layer_i}.input_layernorm.weight": loaded[0][
|
| 272 |
+
f"layers.{layer_i}.attention_norm.weight"
|
| 273 |
+
].clone(),
|
| 274 |
+
f"model.layers.{layer_i}.post_attention_layernorm.weight": loaded[0][
|
| 275 |
+
f"layers.{layer_i}.ffn_norm.weight"
|
| 276 |
+
].clone(),
|
| 277 |
+
}
|
| 278 |
+
state_dict[f"model.layers.{layer_i}.self_attn.q_proj.weight"] = permute(
|
| 279 |
+
torch.cat(
|
| 280 |
+
[
|
| 281 |
+
loaded[i][f"layers.{layer_i}.attention.wq.weight"].view(
|
| 282 |
+
n_heads_per_shard, dims_per_head, dim
|
| 283 |
+
)
|
| 284 |
+
for i in range(len(loaded))
|
| 285 |
+
],
|
| 286 |
+
dim=0,
|
| 287 |
+
).reshape(dim, dim),
|
| 288 |
+
n_heads=n_heads,
|
| 289 |
+
)
|
| 290 |
+
state_dict[f"model.layers.{layer_i}.self_attn.k_proj.weight"] = permute(
|
| 291 |
+
torch.cat(
|
| 292 |
+
[
|
| 293 |
+
loaded[i][f"layers.{layer_i}.attention.wk.weight"].view(
|
| 294 |
+
num_key_value_heads_per_shard, dims_per_head, dim
|
| 295 |
+
)
|
| 296 |
+
for i in range(len(loaded))
|
| 297 |
+
],
|
| 298 |
+
dim=0,
|
| 299 |
+
).reshape(key_value_dim, dim),
|
| 300 |
+
num_key_value_heads,
|
| 301 |
+
key_value_dim,
|
| 302 |
+
dim,
|
| 303 |
+
)
|
| 304 |
+
state_dict[f"model.layers.{layer_i}.self_attn.v_proj.weight"] = torch.cat(
|
| 305 |
+
[
|
| 306 |
+
loaded[i][f"layers.{layer_i}.attention.wv.weight"].view(
|
| 307 |
+
num_key_value_heads_per_shard, dims_per_head, dim
|
| 308 |
+
)
|
| 309 |
+
for i in range(len(loaded))
|
| 310 |
+
],
|
| 311 |
+
dim=0,
|
| 312 |
+
).reshape(key_value_dim, dim)
|
| 313 |
+
|
| 314 |
+
state_dict[f"model.layers.{layer_i}.self_attn.o_proj.weight"] = torch.cat(
|
| 315 |
+
[loaded[i][f"layers.{layer_i}.attention.wo.weight"] for i in range(len(loaded))], dim=1
|
| 316 |
+
)
|
| 317 |
+
state_dict[f"model.layers.{layer_i}.mlp.gate_proj.weight"] = torch.cat(
|
| 318 |
+
[loaded[i][f"layers.{layer_i}.feed_forward.w1.weight"] for i in range(len(loaded))], dim=0
|
| 319 |
+
)
|
| 320 |
+
state_dict[f"model.layers.{layer_i}.mlp.down_proj.weight"] = torch.cat(
|
| 321 |
+
[loaded[i][f"layers.{layer_i}.feed_forward.w2.weight"] for i in range(len(loaded))], dim=1
|
| 322 |
+
)
|
| 323 |
+
state_dict[f"model.layers.{layer_i}.mlp.up_proj.weight"] = torch.cat(
|
| 324 |
+
[loaded[i][f"layers.{layer_i}.feed_forward.w3.weight"] for i in range(len(loaded))], dim=0
|
| 325 |
+
)
|
| 326 |
+
|
| 327 |
+
state_dict[f"model.layers.{layer_i}.self_attn.rotary_emb.inv_freq"] = inv_freq
|
| 328 |
+
for k, v in state_dict.items():
|
| 329 |
+
index_dict["weight_map"][k] = filename
|
| 330 |
+
param_count += v.numel()
|
| 331 |
+
torch.save(state_dict, os.path.join(tmp_model_path, filename))
|
| 332 |
+
|
| 333 |
+
filename = f"pytorch_model-{n_layers + 1}-of-{n_layers + 1}.bin"
|
| 334 |
+
if num_shards == 1:
|
| 335 |
+
# Unsharded
|
| 336 |
+
state_dict = {
|
| 337 |
+
"model.embed_tokens.weight": loaded["tok_embeddings.weight"],
|
| 338 |
+
"model.norm.weight": loaded["norm.weight"],
|
| 339 |
+
"lm_head.weight": loaded["output.weight"],
|
| 340 |
+
}
|
| 341 |
+
else:
|
| 342 |
+
concat_dim = 0 if is_llama_3(llama_version) else 1
|
| 343 |
+
state_dict = {
|
| 344 |
+
"model.norm.weight": loaded[0]["norm.weight"],
|
| 345 |
+
"model.embed_tokens.weight": torch.cat(
|
| 346 |
+
[loaded[i]["tok_embeddings.weight"] for i in range(len(loaded))], dim=concat_dim
|
| 347 |
+
),
|
| 348 |
+
"lm_head.weight": torch.cat([loaded[i]["output.weight"] for i in range(len(loaded))], dim=0),
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
for k, v in state_dict.items():
|
| 352 |
+
index_dict["weight_map"][k] = filename
|
| 353 |
+
param_count += v.numel()
|
| 354 |
+
torch.save(state_dict, os.path.join(tmp_model_path, filename))
|
| 355 |
+
|
| 356 |
+
# Write configs
|
| 357 |
+
index_dict["metadata"] = {"total_size": param_count * 2}
|
| 358 |
+
write_json(index_dict, os.path.join(tmp_model_path, "pytorch_model.bin.index.json"))
|
| 359 |
+
ffn_dim_multiplier = params["ffn_dim_multiplier"] if "ffn_dim_multiplier" in params else 1
|
| 360 |
+
multiple_of = params["multiple_of"] if "multiple_of" in params else 256
|
| 361 |
+
|
| 362 |
+
if is_llama_3(llama_version):
|
| 363 |
+
bos_token_id = 128000
|
| 364 |
+
|
| 365 |
+
if instruct:
|
| 366 |
+
eos_token_id = [128001, 128008, 128009]
|
| 367 |
+
else:
|
| 368 |
+
eos_token_id = 128001
|
| 369 |
+
else:
|
| 370 |
+
bos_token_id = 1
|
| 371 |
+
eos_token_id = 2
|
| 372 |
+
|
| 373 |
+
if llama_version in ["3.1", "3.2", "Guard-3"]:
|
| 374 |
+
rope_scaling = {
|
| 375 |
+
"factor": 32.0 if llama_version == "3.2" else 8.0,
|
| 376 |
+
"low_freq_factor": 1.0,
|
| 377 |
+
"high_freq_factor": 4.0,
|
| 378 |
+
"original_max_position_embeddings": 8192,
|
| 379 |
+
"rope_type": "llama3",
|
| 380 |
+
}
|
| 381 |
+
else:
|
| 382 |
+
rope_scaling = None
|
| 383 |
+
|
| 384 |
+
config = LlamaConfig(
|
| 385 |
+
hidden_size=dim,
|
| 386 |
+
intermediate_size=compute_intermediate_size(dim, ffn_dim_multiplier, multiple_of),
|
| 387 |
+
num_attention_heads=params["n_heads"],
|
| 388 |
+
num_hidden_layers=params["n_layers"],
|
| 389 |
+
rms_norm_eps=params["norm_eps"],
|
| 390 |
+
num_key_value_heads=num_key_value_heads,
|
| 391 |
+
vocab_size=vocab_size,
|
| 392 |
+
rope_theta=base,
|
| 393 |
+
rope_scaling=rope_scaling,
|
| 394 |
+
max_position_embeddings=max_position_embeddings,
|
| 395 |
+
bos_token_id=bos_token_id,
|
| 396 |
+
eos_token_id=eos_token_id,
|
| 397 |
+
tie_word_embeddings=True if llama_version in ["3.2"] else False,
|
| 398 |
+
)
|
| 399 |
+
|
| 400 |
+
config.save_pretrained(tmp_model_path)
|
| 401 |
+
|
| 402 |
+
generation_config = GenerationConfig(
|
| 403 |
+
do_sample=True,
|
| 404 |
+
temperature=0.6,
|
| 405 |
+
top_p=0.9,
|
| 406 |
+
bos_token_id=bos_token_id,
|
| 407 |
+
eos_token_id=eos_token_id,
|
| 408 |
+
)
|
| 409 |
+
generation_config.save_pretrained(tmp_model_path)
|
| 410 |
+
|
| 411 |
+
# Make space so we can load the model properly now.
|
| 412 |
+
del state_dict
|
| 413 |
+
del loaded
|
| 414 |
+
gc.collect()
|
| 415 |
+
|
| 416 |
+
print("Loading the checkpoint in a Llama model.")
|
| 417 |
+
model = LlamaForCausalLM.from_pretrained(tmp_model_path, torch_dtype=torch.bfloat16, low_cpu_mem_usage=True)
|
| 418 |
+
|
| 419 |
+
# Avoid saving this as part of the config.
|
| 420 |
+
del model.config._name_or_path
|
| 421 |
+
model.config.torch_dtype = torch.float16
|
| 422 |
+
|
| 423 |
+
print("Saving in the Transformers format.")
|
| 424 |
+
if push_to_hub:
|
| 425 |
+
print("Pushing to the hub.")
|
| 426 |
+
model.push_to_hub(model_path, safe_serialization=safe_serialization, private=True, use_temp_dir=True)
|
| 427 |
+
else:
|
| 428 |
+
print("Saving to disk.")
|
| 429 |
+
model.save_pretrained(model_path, safe_serialization=safe_serialization)
|
| 430 |
+
|
| 431 |
+
|
| 432 |
+
class Llama3Converter(TikTokenConverter):
|
| 433 |
+
def __init__(self, vocab_file, special_tokens=None, instruct=False, llama_version="3.2", **kwargs):
|
| 434 |
+
super().__init__(vocab_file, additional_special_tokens=special_tokens, **kwargs)
|
| 435 |
+
tokenizer = self.converted()
|
| 436 |
+
|
| 437 |
+
# References for chat templates in instruct models
|
| 438 |
+
templates_for_version = {
|
| 439 |
+
"2": ("meta-llama/Llama-2-7b-chat-hf", "f5db02db724555f92da89c216ac04704f23d4590"),
|
| 440 |
+
"3": ("meta-llama/Meta-Llama-3-8B-Instruct", "5f0b02c75b57c5855da9ae460ce51323ea669d8a"),
|
| 441 |
+
"3.1": ("meta-llama/Llama-3.1-8B-Instruct", "0e9e39f249a16976918f6564b8830bc894c89659"),
|
| 442 |
+
"3.2": ("meta-llama/Llama-3.2-1B-Instruct", "e9f8effbab1cbdc515c11ee6e098e3d5a9f51e14"),
|
| 443 |
+
"Guard-3": ("meta-llama/Llama-Guard-3-1B", "acf7aafa60f0410f8f42b1fa35e077d705892029"),
|
| 444 |
+
}
|
| 445 |
+
|
| 446 |
+
# Add chat_template only if instruct is True.
|
| 447 |
+
# Prevents a null chat_template, which triggers
|
| 448 |
+
# a parsing warning in the Hub.
|
| 449 |
+
additional_kwargs = {}
|
| 450 |
+
if instruct or llama_version in ["Guard-3"]:
|
| 451 |
+
model_id, revision = templates_for_version.get(llama_version, (None, None))
|
| 452 |
+
if model_id is not None:
|
| 453 |
+
from transformers import AutoTokenizer
|
| 454 |
+
|
| 455 |
+
t = AutoTokenizer.from_pretrained(model_id, revision=revision)
|
| 456 |
+
additional_kwargs["chat_template"] = t.chat_template
|
| 457 |
+
|
| 458 |
+
self.converted_tokenizer = PreTrainedTokenizerFast(
|
| 459 |
+
tokenizer_object=tokenizer,
|
| 460 |
+
bos_token="<|begin_of_text|>",
|
| 461 |
+
eos_token="<|end_of_text|>" if not instruct else "<|eot_id|>",
|
| 462 |
+
model_input_names=["input_ids", "attention_mask"],
|
| 463 |
+
model_max_length=CONTEXT_LENGTH_FOR_VERSION[llama_version],
|
| 464 |
+
clean_up_tokenization_spaces=True,
|
| 465 |
+
**additional_kwargs,
|
| 466 |
+
)
|
| 467 |
+
self.update_post_processor(self.converted_tokenizer)
|
| 468 |
+
# finer special_tokens_map.json
|
| 469 |
+
self.converted_tokenizer._bos_token = BOS_ADDED_TOKEN
|
| 470 |
+
self.converted_tokenizer._eos_token = EOT_ADDED_TOKEN if instruct else EOS_ADDED_TOKEN
|
| 471 |
+
|
| 472 |
+
# We can't do this while building the tokenizer because we have no easy access to the bos token id
|
| 473 |
+
def update_post_processor(self, tokenizer):
|
| 474 |
+
tokenizer._tokenizer.post_processor = processors.Sequence(
|
| 475 |
+
[
|
| 476 |
+
processors.ByteLevel(trim_offsets=False),
|
| 477 |
+
processors.TemplateProcessing(
|
| 478 |
+
single="<|begin_of_text|> $A",
|
| 479 |
+
pair="<|begin_of_text|>:0 $A:0 <|begin_of_text|>:1 $B:1",
|
| 480 |
+
special_tokens=[
|
| 481 |
+
("<|begin_of_text|>", tokenizer.convert_tokens_to_ids("<|begin_of_text|>")),
|
| 482 |
+
],
|
| 483 |
+
),
|
| 484 |
+
]
|
| 485 |
+
)
|
| 486 |
+
|
| 487 |
+
|
| 488 |
+
def write_tokenizer(
|
| 489 |
+
tokenizer_path, input_tokenizer_path, llama_version="2", special_tokens=None, instruct=False, push_to_hub=False
|
| 490 |
+
):
|
| 491 |
+
print("Converting the tokenizer.")
|
| 492 |
+
tokenizer_class = LlamaTokenizer if LlamaTokenizerFast is None else LlamaTokenizerFast
|
| 493 |
+
if is_llama_3(llama_version):
|
| 494 |
+
tokenizer = Llama3Converter(
|
| 495 |
+
input_tokenizer_path,
|
| 496 |
+
special_tokens,
|
| 497 |
+
instruct,
|
| 498 |
+
llama_version,
|
| 499 |
+
).converted_tokenizer
|
| 500 |
+
else:
|
| 501 |
+
try:
|
| 502 |
+
tokenizer = tokenizer_class(input_tokenizer_path)
|
| 503 |
+
except Exception:
|
| 504 |
+
raise ValueError(
|
| 505 |
+
"Failed to instantiate tokenizer. Please, make sure you have sentencepiece and protobuf installed."
|
| 506 |
+
)
|
| 507 |
+
|
| 508 |
+
if push_to_hub:
|
| 509 |
+
print(f"Pushing a {tokenizer_class.__name__} to the Hub repo - {tokenizer_path}.")
|
| 510 |
+
tokenizer.push_to_hub(tokenizer_path, private=True, use_temp_dir=True)
|
| 511 |
+
else:
|
| 512 |
+
print(f"Saving a {tokenizer_class.__name__} to {tokenizer_path}.")
|
| 513 |
+
tokenizer.save_pretrained(tokenizer_path)
|
| 514 |
+
return tokenizer
|
| 515 |
+
|
| 516 |
+
|
| 517 |
+
def main():
|
| 518 |
+
parser = argparse.ArgumentParser()
|
| 519 |
+
parser.add_argument(
|
| 520 |
+
"--input_dir",
|
| 521 |
+
help="Location of Llama weights, which contains tokenizer.model and model folders",
|
| 522 |
+
)
|
| 523 |
+
parser.add_argument(
|
| 524 |
+
"--model_size",
|
| 525 |
+
default=None,
|
| 526 |
+
help="'f' Deprecated in favor of `num_shards`: models correspond to the finetuned versions, and are specific to the Llama2 official release. For more details on Llama2, checkout the original repo: https://huggingface.co/meta-llama",
|
| 527 |
+
)
|
| 528 |
+
parser.add_argument(
|
| 529 |
+
"--output_dir",
|
| 530 |
+
help="Location to write HF model and tokenizer",
|
| 531 |
+
)
|
| 532 |
+
parser.add_argument(
|
| 533 |
+
"--push_to_hub",
|
| 534 |
+
help="Whether or not to push the model to the hub at `output_dir` instead of saving it locally.",
|
| 535 |
+
action="store_true",
|
| 536 |
+
default=False,
|
| 537 |
+
)
|
| 538 |
+
parser.add_argument(
|
| 539 |
+
"--safe_serialization", action="store_true", default=True, help="Whether or not to save using `safetensors`."
|
| 540 |
+
)
|
| 541 |
+
# Different Llama versions used different default values for max_position_embeddings, hence the need to be able to specify which version is being used.
|
| 542 |
+
parser.add_argument(
|
| 543 |
+
"--llama_version",
|
| 544 |
+
choices=["1", "2", "3", "3.1", "3.2", "Guard-3"],
|
| 545 |
+
default="1",
|
| 546 |
+
type=str,
|
| 547 |
+
help="Version of the Llama model to convert. Currently supports Llama1 and Llama2. Controls the context size",
|
| 548 |
+
)
|
| 549 |
+
parser.add_argument(
|
| 550 |
+
"--num_shards",
|
| 551 |
+
default=None,
|
| 552 |
+
type=int,
|
| 553 |
+
help="The number of individual shards used for the model. Does not have to be the same as the number of consolidated_xx.pth",
|
| 554 |
+
)
|
| 555 |
+
parser.add_argument(
|
| 556 |
+
"--special_tokens",
|
| 557 |
+
default=None,
|
| 558 |
+
type=List[str],
|
| 559 |
+
help="The list of special tokens that should be added to the model.",
|
| 560 |
+
)
|
| 561 |
+
parser.add_argument(
|
| 562 |
+
"--instruct",
|
| 563 |
+
action="store_true",
|
| 564 |
+
default=False,
|
| 565 |
+
help="Whether the model is an instruct model or not. Will affect special tokens and chat template.",
|
| 566 |
+
)
|
| 567 |
+
args = parser.parse_args()
|
| 568 |
+
if args.model_size is None and args.num_shards is None:
|
| 569 |
+
raise ValueError("You have to set at least `num_shards` if you are not giving the `model_size`")
|
| 570 |
+
if args.special_tokens is None:
|
| 571 |
+
# no special tokens by default
|
| 572 |
+
args.special_tokens = DEFAULT_LLAMA_SPECIAL_TOKENS.get(str(args.llama_version), [])
|
| 573 |
+
|
| 574 |
+
spm_path = os.path.join(args.input_dir, "tokenizer.model")
|
| 575 |
+
vocab_size = len(
|
| 576 |
+
write_tokenizer(
|
| 577 |
+
args.output_dir,
|
| 578 |
+
spm_path,
|
| 579 |
+
llama_version=args.llama_version,
|
| 580 |
+
special_tokens=args.special_tokens,
|
| 581 |
+
instruct=args.instruct,
|
| 582 |
+
push_to_hub=args.push_to_hub,
|
| 583 |
+
)
|
| 584 |
+
)
|
| 585 |
+
|
| 586 |
+
if args.model_size != "tokenizer_only":
|
| 587 |
+
write_model(
|
| 588 |
+
model_path=args.output_dir,
|
| 589 |
+
input_base_path=args.input_dir,
|
| 590 |
+
model_size=args.model_size,
|
| 591 |
+
safe_serialization=args.safe_serialization,
|
| 592 |
+
llama_version=args.llama_version,
|
| 593 |
+
vocab_size=vocab_size,
|
| 594 |
+
num_shards=args.num_shards,
|
| 595 |
+
instruct=args.instruct,
|
| 596 |
+
push_to_hub=args.push_to_hub,
|
| 597 |
+
)
|
| 598 |
+
|
| 599 |
+
|
| 600 |
+
if __name__ == "__main__":
|
| 601 |
+
main()
|
requirements.txt
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
transformers
|
| 3 |
+
torch
|
| 4 |
+
|
| 5 |
+
tiktoken
|
| 6 |
+
blobfile
|
| 7 |
+
sentencepiece
|
| 8 |
+
einops
|
| 9 |
+
accelerate
|
| 10 |
+
fastapi
|
| 11 |
+
uvicorn
|