Upload folder using huggingface_hub
Browse files- .gitattributes +1 -0
- added_tokens.json +24 -0
- attention_mask.py +81 -0
- chat_template.json +3 -0
- config.json +52 -0
- configuration_vora.py +35 -0
- generation_config.json +14 -0
- lora.py +91 -0
- merges.txt +0 -0
- model-00001-of-00007.safetensors +3 -0
- model-00002-of-00007.safetensors +3 -0
- model-00003-of-00007.safetensors +3 -0
- model-00004-of-00007.safetensors +3 -0
- model-00005-of-00007.safetensors +3 -0
- model-00006-of-00007.safetensors +3 -0
- model-00007-of-00007.safetensors +3 -0
- model.safetensors.index.json +447 -0
- modeling_vora.py +219 -0
- preprocessor_config.json +23 -0
- processing_vora.py +139 -0
- processor_config.json +6 -0
- special_tokens_map.json +31 -0
- tokenizer.json +3 -0
- tokenizer_config.json +209 -0
- vision_embedding.py +134 -0
- vocab.json +0 -0
- vora_generation_utils.py +101 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ 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 |
+
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
added_tokens.json
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"</tool_call>": 151658,
|
3 |
+
"<tool_call>": 151657,
|
4 |
+
"<|box_end|>": 151649,
|
5 |
+
"<|box_start|>": 151648,
|
6 |
+
"<|endoftext|>": 151643,
|
7 |
+
"<|file_sep|>": 151664,
|
8 |
+
"<|fim_middle|>": 151660,
|
9 |
+
"<|fim_pad|>": 151662,
|
10 |
+
"<|fim_prefix|>": 151659,
|
11 |
+
"<|fim_suffix|>": 151661,
|
12 |
+
"<|im_end|>": 151645,
|
13 |
+
"<|im_start|>": 151644,
|
14 |
+
"<|image_pad|>": 151655,
|
15 |
+
"<|object_ref_end|>": 151647,
|
16 |
+
"<|object_ref_start|>": 151646,
|
17 |
+
"<|quad_end|>": 151651,
|
18 |
+
"<|quad_start|>": 151650,
|
19 |
+
"<|repo_name|>": 151663,
|
20 |
+
"<|video_pad|>": 151656,
|
21 |
+
"<|vision_end|>": 151653,
|
22 |
+
"<|vision_pad|>": 151654,
|
23 |
+
"<|vision_start|>": 151652
|
24 |
+
}
|
attention_mask.py
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Optional
|
2 |
+
|
3 |
+
import torch
|
4 |
+
|
5 |
+
|
6 |
+
def _make_causal_mask(
|
7 |
+
attention_mask: torch.Tensor, dtype: torch.dtype, device: torch.device
|
8 |
+
):
|
9 |
+
"""
|
10 |
+
Make causal mask used for bi-directional self-attention.
|
11 |
+
"""
|
12 |
+
bsz, tgt_len = attention_mask.shape
|
13 |
+
mask = torch.full((tgt_len, tgt_len), torch.tensor(torch.finfo(dtype).min, device=device), device=device)
|
14 |
+
mask_cond = torch.arange(mask.size(-1), device=device)
|
15 |
+
mask.masked_fill_(mask_cond < (mask_cond + 1).view(mask.size(-1), 1), 0)
|
16 |
+
mask = mask.to(dtype)
|
17 |
+
|
18 |
+
return mask[None, None, :, :].expand(bsz, 1, tgt_len, tgt_len)
|
19 |
+
|
20 |
+
|
21 |
+
def _make_2dvison_mask(column_mask, dtype: torch.dtype, device: torch.device):
|
22 |
+
"""
|
23 |
+
"""
|
24 |
+
bsz, seq_length = column_mask.shape
|
25 |
+
cross_mask = torch.zeros((bsz, 1, seq_length, seq_length), dtype=dtype, device=device)
|
26 |
+
|
27 |
+
# 找到连续的 1 的区间
|
28 |
+
start = None
|
29 |
+
for bsz_idx in range(bsz):
|
30 |
+
for i in range(seq_length):
|
31 |
+
if column_mask[bsz_idx, i] == 1:
|
32 |
+
if start is None:
|
33 |
+
start = i
|
34 |
+
else:
|
35 |
+
if start is not None:
|
36 |
+
# 填充区间
|
37 |
+
cross_mask[bsz_idx, 0, start:i, start:i] = 1
|
38 |
+
start = None
|
39 |
+
|
40 |
+
# 处理最后一个区间
|
41 |
+
if start is not None:
|
42 |
+
cross_mask[bsz_idx, 0, start:seq_length, start:seq_length] = 1
|
43 |
+
|
44 |
+
return cross_mask
|
45 |
+
|
46 |
+
|
47 |
+
def _expand_mask(mask: torch.Tensor, dtype: torch.dtype, tgt_len: Optional[int] = None):
|
48 |
+
"""
|
49 |
+
Expands attention_mask from `[bsz, seq_len]` to `[bsz, 1, tgt_seq_len, src_seq_len]`.
|
50 |
+
"""
|
51 |
+
bsz, src_len = mask.size()
|
52 |
+
tgt_len = tgt_len if tgt_len is not None else src_len
|
53 |
+
|
54 |
+
expanded_mask = mask[:, None, None, :].expand(bsz, 1, tgt_len, src_len).to(dtype)
|
55 |
+
|
56 |
+
inverted_mask = 1.0 - expanded_mask
|
57 |
+
|
58 |
+
return inverted_mask.masked_fill_(inverted_mask.to(torch.bool), torch.finfo(dtype).min)
|
59 |
+
|
60 |
+
|
61 |
+
def make_mask(attention_mask: torch.Tensor, dtype: torch.dtype=None, device: torch.device=None, mode: str="default", vision_mask: torch.Tensor=None, ):
|
62 |
+
if dtype is None:
|
63 |
+
dtype = attention_mask.dtype
|
64 |
+
if device is None:
|
65 |
+
device = attention_mask.device
|
66 |
+
expanded_attn_mask = _expand_mask(attention_mask, dtype).to(device)
|
67 |
+
causal_mask = _make_causal_mask(attention_mask, dtype, device).to(device)
|
68 |
+
if mode == "default":
|
69 |
+
return attention_mask
|
70 |
+
else:
|
71 |
+
assert vision_mask is not None, "vision_mask is None"
|
72 |
+
vision_mask = vision_mask.to(device)
|
73 |
+
bsz, seq_length = attention_mask.shape
|
74 |
+
vision_mask_bg = vision_mask[:, None, :, None]
|
75 |
+
vision_mask_2d = _make_2dvison_mask(vision_mask, dtype, device)
|
76 |
+
if mode == "bidirectional":
|
77 |
+
mask = expanded_attn_mask + causal_mask
|
78 |
+
mask = mask.clone().masked_fill_(vision_mask_2d.to(torch.bool), 0)
|
79 |
+
return mask
|
80 |
+
else:
|
81 |
+
raise NotImplementedError(f"mode {mode} is not implemented")
|
chat_template.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"chat_template": "{% set image_count = namespace(value=0) %}{% set video_count = namespace(value=0) %}{% for message in messages %}{% if loop.first and message['role'] != 'system' %}<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n{% endif %}<|im_start|>{{ message['role'] }}\n{% if message['content'] is string %}{{ message['content'] }}<|im_end|>\n{% else %}{% for content in message['content'] %}{% if content['type'] == 'image' or 'image' in content or 'image_url' in content %}{% set image_count.value = image_count.value + 1 %}{% if add_vision_id %}Picture {{ image_count.value }}: {% endif %}<|vision_start|><|image_pad|><|vision_end|>{% elif content['type'] == 'video' or 'video' in content %}{% set video_count.value = video_count.value + 1 %}{% if add_vision_id %}Video {{ video_count.value }}: {% endif %}<|vision_start|><|video_pad|><|vision_end|>{% elif 'text' in content %}{{ content['text'] }}{% endif %}{% endfor %}<|im_end|>\n{% endif %}{% endfor %}{% if add_generation_prompt %}<|im_start|>assistant\n{% endif %}"
|
3 |
+
}
|
config.json
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architectures": [
|
3 |
+
"VoRAForCausalLM"
|
4 |
+
],
|
5 |
+
"attention_dropout": 0.0,
|
6 |
+
"auto_map": {
|
7 |
+
"AutoConfig": "configuration_vora.VoRAConfig",
|
8 |
+
"AutoModelForCausalLM": "modeling_vora.VoRAForCausalLM"
|
9 |
+
},
|
10 |
+
"aux_vision": "",
|
11 |
+
"bos_token_id": 151643,
|
12 |
+
"eos_token_id": 151645,
|
13 |
+
"hidden_act": "silu",
|
14 |
+
"hidden_size": 3584,
|
15 |
+
"image_size": 448,
|
16 |
+
"initializer_range": 0.02,
|
17 |
+
"intermediate_size": 18944,
|
18 |
+
"llm": "/mnt/bn/wh-data/data/models/Qwen2.5-7B-Instruct",
|
19 |
+
"lora": {
|
20 |
+
"layers": 24,
|
21 |
+
"r": -1,
|
22 |
+
"target_modules": [
|
23 |
+
"self_attn.q_proj",
|
24 |
+
"self_attn.k_proj",
|
25 |
+
"self_attn.v_proj",
|
26 |
+
"self_attn.o_proj",
|
27 |
+
"mlp.up_proj",
|
28 |
+
"mlp.gate_proj",
|
29 |
+
"mlp.down_proj"
|
30 |
+
]
|
31 |
+
},
|
32 |
+
"max_position_embeddings": 32768,
|
33 |
+
"max_window_layers": 28,
|
34 |
+
"model_type": "vora",
|
35 |
+
"num_attention_heads": 28,
|
36 |
+
"num_hidden_layers": 28,
|
37 |
+
"num_key_value_heads": 4,
|
38 |
+
"patch_size": 14,
|
39 |
+
"rms_norm_eps": 1e-06,
|
40 |
+
"rope_scaling": null,
|
41 |
+
"rope_theta": 1000000.0,
|
42 |
+
"sliding_window": 131072,
|
43 |
+
"tie_word_embeddings": false,
|
44 |
+
"torch_dtype": "float32",
|
45 |
+
"transformers_version": "4.50.3",
|
46 |
+
"use_cache": true,
|
47 |
+
"use_sliding_window": false,
|
48 |
+
"vision_attention_mask": "bidirectional",
|
49 |
+
"vision_embedding_intermediate_size": 1536,
|
50 |
+
"vision_embedding_type": "AIMv2",
|
51 |
+
"vocab_size": 152064
|
52 |
+
}
|
configuration_vora.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Any
|
2 |
+
|
3 |
+
from transformers.configuration_utils import PretrainedConfig
|
4 |
+
|
5 |
+
__all__ = ["VoRAConfig"]
|
6 |
+
|
7 |
+
|
8 |
+
class VoRAConfig(PretrainedConfig):
|
9 |
+
model_type = "vora"
|
10 |
+
_auto_class = "AutoConfig"
|
11 |
+
|
12 |
+
def __init__(
|
13 |
+
self,
|
14 |
+
llm: str = "",
|
15 |
+
aux_vision: str = "",
|
16 |
+
lora: dict = {},
|
17 |
+
image_size: int = 448,
|
18 |
+
vision_embedding_type: str = "",
|
19 |
+
vision_embedding_intermediate_size: int = 1536,
|
20 |
+
patch_size: int = 14,
|
21 |
+
vision_attention_mask: str = "bidirectional",
|
22 |
+
rms_norm_eps: float = 1e-5,
|
23 |
+
**kwargs: Any,
|
24 |
+
):
|
25 |
+
super().__init__(**kwargs)
|
26 |
+
self.llm = llm
|
27 |
+
self.aux_vision = aux_vision
|
28 |
+
self.lora = lora
|
29 |
+
self.image_size = image_size
|
30 |
+
self.vision_embedding_type = vision_embedding_type
|
31 |
+
self.vision_embedding_intermediate_size = vision_embedding_intermediate_size
|
32 |
+
self.patch_size = patch_size
|
33 |
+
self.vision_attention_mask = vision_attention_mask
|
34 |
+
self.rms_norm_eps = rms_norm_eps
|
35 |
+
|
generation_config.json
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bos_token_id": 151643,
|
3 |
+
"pad_token_id": 151643,
|
4 |
+
"do_sample": true,
|
5 |
+
"eos_token_id": [
|
6 |
+
151645,
|
7 |
+
151643
|
8 |
+
],
|
9 |
+
"repetition_penalty": 1.05,
|
10 |
+
"temperature": 0.7,
|
11 |
+
"top_p": 0.8,
|
12 |
+
"top_k": 20,
|
13 |
+
"transformers_version": "4.37.0"
|
14 |
+
}
|
lora.py
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import types
|
3 |
+
import math
|
4 |
+
from torch import nn
|
5 |
+
import torch.nn.functional as F
|
6 |
+
|
7 |
+
|
8 |
+
QWEN2_TARGET_MODULES = [
|
9 |
+
"self_attn.q_proj",
|
10 |
+
"self_attn.k_proj",
|
11 |
+
"self_attn.v_proj",
|
12 |
+
"self_attn.o_proj",
|
13 |
+
"mlp.up_proj",
|
14 |
+
"mlp.gate_proj",
|
15 |
+
"mlp.down_proj",
|
16 |
+
]
|
17 |
+
|
18 |
+
|
19 |
+
class LoRALayer(nn.Linear):
|
20 |
+
def __init__(
|
21 |
+
self,
|
22 |
+
in_features: int,
|
23 |
+
out_features: int,
|
24 |
+
r: int = 1024,
|
25 |
+
**kwargs
|
26 |
+
):
|
27 |
+
nn.Linear.__init__(self, in_features, out_features)
|
28 |
+
if r < 0:
|
29 |
+
self.forward = self.naive_forward
|
30 |
+
else:
|
31 |
+
# we elimate lora_alpha here bc we find it unnecessary in VoRA
|
32 |
+
self.lora_A = nn.Linear(in_features, r, bias=False)
|
33 |
+
self.lora_B = nn.Linear(r, out_features, bias=False)
|
34 |
+
nn.init.kaiming_uniform_(self.lora_A.weight, a=math.sqrt(5))
|
35 |
+
nn.init.zeros_(self.lora_B.weight)
|
36 |
+
|
37 |
+
def forward(self, x: torch.Tensor):
|
38 |
+
intermediate = F.linear(x, self.weight, bias=self.bias)
|
39 |
+
result = intermediate + self.lora_B(self.lora_A(x))
|
40 |
+
return result
|
41 |
+
|
42 |
+
def naive_forward(self, x: torch.Tensor):
|
43 |
+
return F.linear(x, self.weight, bias=self.bias)
|
44 |
+
|
45 |
+
def _get_submodules(self, key):
|
46 |
+
parent = self.get_submodule(".".join(key.split(".")[:-1]))
|
47 |
+
target_name = key.split(".")[-1]
|
48 |
+
target = self.get_submodule(key)
|
49 |
+
return parent, target, target_name
|
50 |
+
|
51 |
+
def _find_and_replace(self, lora_params):
|
52 |
+
target_modules = lora_params["target_modules"]
|
53 |
+
|
54 |
+
for llm_module_name in target_modules:
|
55 |
+
parent, target, target_name = self._get_submodules(llm_module_name)
|
56 |
+
vora_layer = LoRALayer(
|
57 |
+
target.in_features,
|
58 |
+
target.out_features,
|
59 |
+
**lora_params
|
60 |
+
)
|
61 |
+
self._replace_module(parent, target_name, vora_layer, target)
|
62 |
+
|
63 |
+
def _replace_module(self, parent_module, child_name, new_module, old_module):
|
64 |
+
setattr(parent_module, child_name, new_module)
|
65 |
+
new_module.weight = old_module.weight
|
66 |
+
if old_module.bias is not None:
|
67 |
+
new_module.bias = old_module.bias
|
68 |
+
if getattr(old_module, "state", None) is not None:
|
69 |
+
new_module.state = old_module.state
|
70 |
+
new_module.to(old_module.weight.device)
|
71 |
+
|
72 |
+
def apply_lora(llm, lora_params={"layers": "all", "r": 1024, "target_modules": QWEN2_TARGET_MODULES}):
|
73 |
+
llm_num_layers = llm.config.num_hidden_layers
|
74 |
+
total_layers = lora_params.get("layers", "all")
|
75 |
+
|
76 |
+
# -------------------- validation check ---------------------
|
77 |
+
if isinstance(total_layers, str):
|
78 |
+
if total_layers.lower() == "all":
|
79 |
+
total_layers = list(range(llm_num_layers))
|
80 |
+
else:
|
81 |
+
assert isinstance(total_layers, int), "total_layers must be an integer or 'all'"
|
82 |
+
total_layers = list(range(total_layers))
|
83 |
+
# -------------------- validation check ---------------------
|
84 |
+
|
85 |
+
# -------------------- replace llm layers ---------------------
|
86 |
+
for i in total_layers:
|
87 |
+
llm_layer = llm.model.layers[i]
|
88 |
+
llm_layer._get_submodules = types.MethodType(_get_submodules, llm_layer)
|
89 |
+
llm_layer._find_and_replace = types.MethodType(_find_and_replace, llm_layer)
|
90 |
+
llm_layer._replace_module = types.MethodType(_replace_module, llm_layer)
|
91 |
+
llm_layer._find_and_replace(lora_params)
|
merges.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
model-00001-of-00007.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3a2164771a66a6d1bded7a320400a72dd2d6754c6c52a70a9299db0d1f319a59
|
3 |
+
size 4977229368
|
model-00002-of-00007.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3624d28b4695a26768fe361090f3f126d5e10ec5c44a006d33886cf7e1d6ffff
|
3 |
+
size 4779540384
|
model-00003-of-00007.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3f739dc6bba6a644182f3972e28841e12d375a72d34a3bb6e5d9e4b43b4c01fa
|
3 |
+
size 4933723424
|
model-00004-of-00007.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3fa7e59c2059f06ba171f40c09f3ea8375c551ecfb490e35d165342795ab1ac7
|
3 |
+
size 4933723464
|
model-00005-of-00007.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a6a9ed61468f6c7a9064b3a516ef5dac9b28ad282cee9ddf044ec511ef1dc60b
|
3 |
+
size 4999770352
|
model-00006-of-00007.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:29fe7750560a75fe7348499eec2cf79d275b00b904c363e5ea300e9ec0b94871
|
3 |
+
size 3662865360
|
model-00007-of-00007.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9bc90d888b4d1fb1e1d10b58f7bc64df1dfb9dfd8d9bda05b06166b1b65fd0e9
|
3 |
+
size 2211926704
|
model.safetensors.index.json
ADDED
@@ -0,0 +1,447 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"metadata": {
|
3 |
+
"total_size": 30498727936
|
4 |
+
},
|
5 |
+
"weight_map": {
|
6 |
+
"llm.lm_head.weight": "model-00007-of-00007.safetensors",
|
7 |
+
"llm.model.embed_tokens.weight": "model-00001-of-00007.safetensors",
|
8 |
+
"llm.model.layers.0.input_layernorm.weight": "model-00001-of-00007.safetensors",
|
9 |
+
"llm.model.layers.0.mlp.down_proj.bias": "model-00001-of-00007.safetensors",
|
10 |
+
"llm.model.layers.0.mlp.down_proj.weight": "model-00001-of-00007.safetensors",
|
11 |
+
"llm.model.layers.0.mlp.gate_proj.bias": "model-00001-of-00007.safetensors",
|
12 |
+
"llm.model.layers.0.mlp.gate_proj.weight": "model-00001-of-00007.safetensors",
|
13 |
+
"llm.model.layers.0.mlp.up_proj.bias": "model-00001-of-00007.safetensors",
|
14 |
+
"llm.model.layers.0.mlp.up_proj.weight": "model-00001-of-00007.safetensors",
|
15 |
+
"llm.model.layers.0.post_attention_layernorm.weight": "model-00001-of-00007.safetensors",
|
16 |
+
"llm.model.layers.0.self_attn.k_proj.bias": "model-00001-of-00007.safetensors",
|
17 |
+
"llm.model.layers.0.self_attn.k_proj.weight": "model-00001-of-00007.safetensors",
|
18 |
+
"llm.model.layers.0.self_attn.o_proj.bias": "model-00001-of-00007.safetensors",
|
19 |
+
"llm.model.layers.0.self_attn.o_proj.weight": "model-00001-of-00007.safetensors",
|
20 |
+
"llm.model.layers.0.self_attn.q_proj.bias": "model-00001-of-00007.safetensors",
|
21 |
+
"llm.model.layers.0.self_attn.q_proj.weight": "model-00001-of-00007.safetensors",
|
22 |
+
"llm.model.layers.0.self_attn.v_proj.bias": "model-00001-of-00007.safetensors",
|
23 |
+
"llm.model.layers.0.self_attn.v_proj.weight": "model-00001-of-00007.safetensors",
|
24 |
+
"llm.model.layers.1.input_layernorm.weight": "model-00001-of-00007.safetensors",
|
25 |
+
"llm.model.layers.1.mlp.down_proj.bias": "model-00001-of-00007.safetensors",
|
26 |
+
"llm.model.layers.1.mlp.down_proj.weight": "model-00001-of-00007.safetensors",
|
27 |
+
"llm.model.layers.1.mlp.gate_proj.bias": "model-00001-of-00007.safetensors",
|
28 |
+
"llm.model.layers.1.mlp.gate_proj.weight": "model-00001-of-00007.safetensors",
|
29 |
+
"llm.model.layers.1.mlp.up_proj.bias": "model-00001-of-00007.safetensors",
|
30 |
+
"llm.model.layers.1.mlp.up_proj.weight": "model-00001-of-00007.safetensors",
|
31 |
+
"llm.model.layers.1.post_attention_layernorm.weight": "model-00001-of-00007.safetensors",
|
32 |
+
"llm.model.layers.1.self_attn.k_proj.bias": "model-00001-of-00007.safetensors",
|
33 |
+
"llm.model.layers.1.self_attn.k_proj.weight": "model-00001-of-00007.safetensors",
|
34 |
+
"llm.model.layers.1.self_attn.o_proj.bias": "model-00001-of-00007.safetensors",
|
35 |
+
"llm.model.layers.1.self_attn.o_proj.weight": "model-00001-of-00007.safetensors",
|
36 |
+
"llm.model.layers.1.self_attn.q_proj.bias": "model-00001-of-00007.safetensors",
|
37 |
+
"llm.model.layers.1.self_attn.q_proj.weight": "model-00001-of-00007.safetensors",
|
38 |
+
"llm.model.layers.1.self_attn.v_proj.bias": "model-00001-of-00007.safetensors",
|
39 |
+
"llm.model.layers.1.self_attn.v_proj.weight": "model-00001-of-00007.safetensors",
|
40 |
+
"llm.model.layers.10.input_layernorm.weight": "model-00003-of-00007.safetensors",
|
41 |
+
"llm.model.layers.10.mlp.down_proj.bias": "model-00003-of-00007.safetensors",
|
42 |
+
"llm.model.layers.10.mlp.down_proj.weight": "model-00003-of-00007.safetensors",
|
43 |
+
"llm.model.layers.10.mlp.gate_proj.bias": "model-00003-of-00007.safetensors",
|
44 |
+
"llm.model.layers.10.mlp.gate_proj.weight": "model-00003-of-00007.safetensors",
|
45 |
+
"llm.model.layers.10.mlp.up_proj.bias": "model-00003-of-00007.safetensors",
|
46 |
+
"llm.model.layers.10.mlp.up_proj.weight": "model-00003-of-00007.safetensors",
|
47 |
+
"llm.model.layers.10.post_attention_layernorm.weight": "model-00003-of-00007.safetensors",
|
48 |
+
"llm.model.layers.10.self_attn.k_proj.bias": "model-00003-of-00007.safetensors",
|
49 |
+
"llm.model.layers.10.self_attn.k_proj.weight": "model-00003-of-00007.safetensors",
|
50 |
+
"llm.model.layers.10.self_attn.o_proj.bias": "model-00003-of-00007.safetensors",
|
51 |
+
"llm.model.layers.10.self_attn.o_proj.weight": "model-00003-of-00007.safetensors",
|
52 |
+
"llm.model.layers.10.self_attn.q_proj.bias": "model-00003-of-00007.safetensors",
|
53 |
+
"llm.model.layers.10.self_attn.q_proj.weight": "model-00003-of-00007.safetensors",
|
54 |
+
"llm.model.layers.10.self_attn.v_proj.bias": "model-00003-of-00007.safetensors",
|
55 |
+
"llm.model.layers.10.self_attn.v_proj.weight": "model-00003-of-00007.safetensors",
|
56 |
+
"llm.model.layers.11.input_layernorm.weight": "model-00003-of-00007.safetensors",
|
57 |
+
"llm.model.layers.11.mlp.down_proj.bias": "model-00003-of-00007.safetensors",
|
58 |
+
"llm.model.layers.11.mlp.down_proj.weight": "model-00003-of-00007.safetensors",
|
59 |
+
"llm.model.layers.11.mlp.gate_proj.bias": "model-00003-of-00007.safetensors",
|
60 |
+
"llm.model.layers.11.mlp.gate_proj.weight": "model-00003-of-00007.safetensors",
|
61 |
+
"llm.model.layers.11.mlp.up_proj.bias": "model-00003-of-00007.safetensors",
|
62 |
+
"llm.model.layers.11.mlp.up_proj.weight": "model-00003-of-00007.safetensors",
|
63 |
+
"llm.model.layers.11.post_attention_layernorm.weight": "model-00003-of-00007.safetensors",
|
64 |
+
"llm.model.layers.11.self_attn.k_proj.bias": "model-00003-of-00007.safetensors",
|
65 |
+
"llm.model.layers.11.self_attn.k_proj.weight": "model-00003-of-00007.safetensors",
|
66 |
+
"llm.model.layers.11.self_attn.o_proj.bias": "model-00003-of-00007.safetensors",
|
67 |
+
"llm.model.layers.11.self_attn.o_proj.weight": "model-00003-of-00007.safetensors",
|
68 |
+
"llm.model.layers.11.self_attn.q_proj.bias": "model-00003-of-00007.safetensors",
|
69 |
+
"llm.model.layers.11.self_attn.q_proj.weight": "model-00003-of-00007.safetensors",
|
70 |
+
"llm.model.layers.11.self_attn.v_proj.bias": "model-00003-of-00007.safetensors",
|
71 |
+
"llm.model.layers.11.self_attn.v_proj.weight": "model-00003-of-00007.safetensors",
|
72 |
+
"llm.model.layers.12.input_layernorm.weight": "model-00003-of-00007.safetensors",
|
73 |
+
"llm.model.layers.12.mlp.down_proj.bias": "model-00003-of-00007.safetensors",
|
74 |
+
"llm.model.layers.12.mlp.down_proj.weight": "model-00003-of-00007.safetensors",
|
75 |
+
"llm.model.layers.12.mlp.gate_proj.bias": "model-00003-of-00007.safetensors",
|
76 |
+
"llm.model.layers.12.mlp.gate_proj.weight": "model-00003-of-00007.safetensors",
|
77 |
+
"llm.model.layers.12.mlp.up_proj.bias": "model-00003-of-00007.safetensors",
|
78 |
+
"llm.model.layers.12.mlp.up_proj.weight": "model-00003-of-00007.safetensors",
|
79 |
+
"llm.model.layers.12.post_attention_layernorm.weight": "model-00003-of-00007.safetensors",
|
80 |
+
"llm.model.layers.12.self_attn.k_proj.bias": "model-00003-of-00007.safetensors",
|
81 |
+
"llm.model.layers.12.self_attn.k_proj.weight": "model-00003-of-00007.safetensors",
|
82 |
+
"llm.model.layers.12.self_attn.o_proj.bias": "model-00003-of-00007.safetensors",
|
83 |
+
"llm.model.layers.12.self_attn.o_proj.weight": "model-00003-of-00007.safetensors",
|
84 |
+
"llm.model.layers.12.self_attn.q_proj.bias": "model-00003-of-00007.safetensors",
|
85 |
+
"llm.model.layers.12.self_attn.q_proj.weight": "model-00003-of-00007.safetensors",
|
86 |
+
"llm.model.layers.12.self_attn.v_proj.bias": "model-00003-of-00007.safetensors",
|
87 |
+
"llm.model.layers.12.self_attn.v_proj.weight": "model-00003-of-00007.safetensors",
|
88 |
+
"llm.model.layers.13.input_layernorm.weight": "model-00004-of-00007.safetensors",
|
89 |
+
"llm.model.layers.13.mlp.down_proj.bias": "model-00004-of-00007.safetensors",
|
90 |
+
"llm.model.layers.13.mlp.down_proj.weight": "model-00004-of-00007.safetensors",
|
91 |
+
"llm.model.layers.13.mlp.gate_proj.bias": "model-00003-of-00007.safetensors",
|
92 |
+
"llm.model.layers.13.mlp.gate_proj.weight": "model-00003-of-00007.safetensors",
|
93 |
+
"llm.model.layers.13.mlp.up_proj.bias": "model-00004-of-00007.safetensors",
|
94 |
+
"llm.model.layers.13.mlp.up_proj.weight": "model-00004-of-00007.safetensors",
|
95 |
+
"llm.model.layers.13.post_attention_layernorm.weight": "model-00004-of-00007.safetensors",
|
96 |
+
"llm.model.layers.13.self_attn.k_proj.bias": "model-00003-of-00007.safetensors",
|
97 |
+
"llm.model.layers.13.self_attn.k_proj.weight": "model-00003-of-00007.safetensors",
|
98 |
+
"llm.model.layers.13.self_attn.o_proj.bias": "model-00003-of-00007.safetensors",
|
99 |
+
"llm.model.layers.13.self_attn.o_proj.weight": "model-00003-of-00007.safetensors",
|
100 |
+
"llm.model.layers.13.self_attn.q_proj.bias": "model-00003-of-00007.safetensors",
|
101 |
+
"llm.model.layers.13.self_attn.q_proj.weight": "model-00003-of-00007.safetensors",
|
102 |
+
"llm.model.layers.13.self_attn.v_proj.bias": "model-00003-of-00007.safetensors",
|
103 |
+
"llm.model.layers.13.self_attn.v_proj.weight": "model-00003-of-00007.safetensors",
|
104 |
+
"llm.model.layers.14.input_layernorm.weight": "model-00004-of-00007.safetensors",
|
105 |
+
"llm.model.layers.14.mlp.down_proj.bias": "model-00004-of-00007.safetensors",
|
106 |
+
"llm.model.layers.14.mlp.down_proj.weight": "model-00004-of-00007.safetensors",
|
107 |
+
"llm.model.layers.14.mlp.gate_proj.bias": "model-00004-of-00007.safetensors",
|
108 |
+
"llm.model.layers.14.mlp.gate_proj.weight": "model-00004-of-00007.safetensors",
|
109 |
+
"llm.model.layers.14.mlp.up_proj.bias": "model-00004-of-00007.safetensors",
|
110 |
+
"llm.model.layers.14.mlp.up_proj.weight": "model-00004-of-00007.safetensors",
|
111 |
+
"llm.model.layers.14.post_attention_layernorm.weight": "model-00004-of-00007.safetensors",
|
112 |
+
"llm.model.layers.14.self_attn.k_proj.bias": "model-00004-of-00007.safetensors",
|
113 |
+
"llm.model.layers.14.self_attn.k_proj.weight": "model-00004-of-00007.safetensors",
|
114 |
+
"llm.model.layers.14.self_attn.o_proj.bias": "model-00004-of-00007.safetensors",
|
115 |
+
"llm.model.layers.14.self_attn.o_proj.weight": "model-00004-of-00007.safetensors",
|
116 |
+
"llm.model.layers.14.self_attn.q_proj.bias": "model-00004-of-00007.safetensors",
|
117 |
+
"llm.model.layers.14.self_attn.q_proj.weight": "model-00004-of-00007.safetensors",
|
118 |
+
"llm.model.layers.14.self_attn.v_proj.bias": "model-00004-of-00007.safetensors",
|
119 |
+
"llm.model.layers.14.self_attn.v_proj.weight": "model-00004-of-00007.safetensors",
|
120 |
+
"llm.model.layers.15.input_layernorm.weight": "model-00004-of-00007.safetensors",
|
121 |
+
"llm.model.layers.15.mlp.down_proj.bias": "model-00004-of-00007.safetensors",
|
122 |
+
"llm.model.layers.15.mlp.down_proj.weight": "model-00004-of-00007.safetensors",
|
123 |
+
"llm.model.layers.15.mlp.gate_proj.bias": "model-00004-of-00007.safetensors",
|
124 |
+
"llm.model.layers.15.mlp.gate_proj.weight": "model-00004-of-00007.safetensors",
|
125 |
+
"llm.model.layers.15.mlp.up_proj.bias": "model-00004-of-00007.safetensors",
|
126 |
+
"llm.model.layers.15.mlp.up_proj.weight": "model-00004-of-00007.safetensors",
|
127 |
+
"llm.model.layers.15.post_attention_layernorm.weight": "model-00004-of-00007.safetensors",
|
128 |
+
"llm.model.layers.15.self_attn.k_proj.bias": "model-00004-of-00007.safetensors",
|
129 |
+
"llm.model.layers.15.self_attn.k_proj.weight": "model-00004-of-00007.safetensors",
|
130 |
+
"llm.model.layers.15.self_attn.o_proj.bias": "model-00004-of-00007.safetensors",
|
131 |
+
"llm.model.layers.15.self_attn.o_proj.weight": "model-00004-of-00007.safetensors",
|
132 |
+
"llm.model.layers.15.self_attn.q_proj.bias": "model-00004-of-00007.safetensors",
|
133 |
+
"llm.model.layers.15.self_attn.q_proj.weight": "model-00004-of-00007.safetensors",
|
134 |
+
"llm.model.layers.15.self_attn.v_proj.bias": "model-00004-of-00007.safetensors",
|
135 |
+
"llm.model.layers.15.self_attn.v_proj.weight": "model-00004-of-00007.safetensors",
|
136 |
+
"llm.model.layers.16.input_layernorm.weight": "model-00004-of-00007.safetensors",
|
137 |
+
"llm.model.layers.16.mlp.down_proj.bias": "model-00004-of-00007.safetensors",
|
138 |
+
"llm.model.layers.16.mlp.down_proj.weight": "model-00004-of-00007.safetensors",
|
139 |
+
"llm.model.layers.16.mlp.gate_proj.bias": "model-00004-of-00007.safetensors",
|
140 |
+
"llm.model.layers.16.mlp.gate_proj.weight": "model-00004-of-00007.safetensors",
|
141 |
+
"llm.model.layers.16.mlp.up_proj.bias": "model-00004-of-00007.safetensors",
|
142 |
+
"llm.model.layers.16.mlp.up_proj.weight": "model-00004-of-00007.safetensors",
|
143 |
+
"llm.model.layers.16.post_attention_layernorm.weight": "model-00004-of-00007.safetensors",
|
144 |
+
"llm.model.layers.16.self_attn.k_proj.bias": "model-00004-of-00007.safetensors",
|
145 |
+
"llm.model.layers.16.self_attn.k_proj.weight": "model-00004-of-00007.safetensors",
|
146 |
+
"llm.model.layers.16.self_attn.o_proj.bias": "model-00004-of-00007.safetensors",
|
147 |
+
"llm.model.layers.16.self_attn.o_proj.weight": "model-00004-of-00007.safetensors",
|
148 |
+
"llm.model.layers.16.self_attn.q_proj.bias": "model-00004-of-00007.safetensors",
|
149 |
+
"llm.model.layers.16.self_attn.q_proj.weight": "model-00004-of-00007.safetensors",
|
150 |
+
"llm.model.layers.16.self_attn.v_proj.bias": "model-00004-of-00007.safetensors",
|
151 |
+
"llm.model.layers.16.self_attn.v_proj.weight": "model-00004-of-00007.safetensors",
|
152 |
+
"llm.model.layers.17.input_layernorm.weight": "model-00004-of-00007.safetensors",
|
153 |
+
"llm.model.layers.17.mlp.down_proj.bias": "model-00004-of-00007.safetensors",
|
154 |
+
"llm.model.layers.17.mlp.down_proj.weight": "model-00004-of-00007.safetensors",
|
155 |
+
"llm.model.layers.17.mlp.gate_proj.bias": "model-00004-of-00007.safetensors",
|
156 |
+
"llm.model.layers.17.mlp.gate_proj.weight": "model-00004-of-00007.safetensors",
|
157 |
+
"llm.model.layers.17.mlp.up_proj.bias": "model-00004-of-00007.safetensors",
|
158 |
+
"llm.model.layers.17.mlp.up_proj.weight": "model-00004-of-00007.safetensors",
|
159 |
+
"llm.model.layers.17.post_attention_layernorm.weight": "model-00004-of-00007.safetensors",
|
160 |
+
"llm.model.layers.17.self_attn.k_proj.bias": "model-00004-of-00007.safetensors",
|
161 |
+
"llm.model.layers.17.self_attn.k_proj.weight": "model-00004-of-00007.safetensors",
|
162 |
+
"llm.model.layers.17.self_attn.o_proj.bias": "model-00004-of-00007.safetensors",
|
163 |
+
"llm.model.layers.17.self_attn.o_proj.weight": "model-00004-of-00007.safetensors",
|
164 |
+
"llm.model.layers.17.self_attn.q_proj.bias": "model-00004-of-00007.safetensors",
|
165 |
+
"llm.model.layers.17.self_attn.q_proj.weight": "model-00004-of-00007.safetensors",
|
166 |
+
"llm.model.layers.17.self_attn.v_proj.bias": "model-00004-of-00007.safetensors",
|
167 |
+
"llm.model.layers.17.self_attn.v_proj.weight": "model-00004-of-00007.safetensors",
|
168 |
+
"llm.model.layers.18.input_layernorm.weight": "model-00005-of-00007.safetensors",
|
169 |
+
"llm.model.layers.18.mlp.down_proj.bias": "model-00005-of-00007.safetensors",
|
170 |
+
"llm.model.layers.18.mlp.down_proj.weight": "model-00005-of-00007.safetensors",
|
171 |
+
"llm.model.layers.18.mlp.gate_proj.bias": "model-00004-of-00007.safetensors",
|
172 |
+
"llm.model.layers.18.mlp.gate_proj.weight": "model-00004-of-00007.safetensors",
|
173 |
+
"llm.model.layers.18.mlp.up_proj.bias": "model-00004-of-00007.safetensors",
|
174 |
+
"llm.model.layers.18.mlp.up_proj.weight": "model-00004-of-00007.safetensors",
|
175 |
+
"llm.model.layers.18.post_attention_layernorm.weight": "model-00005-of-00007.safetensors",
|
176 |
+
"llm.model.layers.18.self_attn.k_proj.bias": "model-00004-of-00007.safetensors",
|
177 |
+
"llm.model.layers.18.self_attn.k_proj.weight": "model-00004-of-00007.safetensors",
|
178 |
+
"llm.model.layers.18.self_attn.o_proj.bias": "model-00004-of-00007.safetensors",
|
179 |
+
"llm.model.layers.18.self_attn.o_proj.weight": "model-00004-of-00007.safetensors",
|
180 |
+
"llm.model.layers.18.self_attn.q_proj.bias": "model-00004-of-00007.safetensors",
|
181 |
+
"llm.model.layers.18.self_attn.q_proj.weight": "model-00004-of-00007.safetensors",
|
182 |
+
"llm.model.layers.18.self_attn.v_proj.bias": "model-00004-of-00007.safetensors",
|
183 |
+
"llm.model.layers.18.self_attn.v_proj.weight": "model-00004-of-00007.safetensors",
|
184 |
+
"llm.model.layers.19.input_layernorm.weight": "model-00005-of-00007.safetensors",
|
185 |
+
"llm.model.layers.19.mlp.down_proj.bias": "model-00005-of-00007.safetensors",
|
186 |
+
"llm.model.layers.19.mlp.down_proj.weight": "model-00005-of-00007.safetensors",
|
187 |
+
"llm.model.layers.19.mlp.gate_proj.bias": "model-00005-of-00007.safetensors",
|
188 |
+
"llm.model.layers.19.mlp.gate_proj.weight": "model-00005-of-00007.safetensors",
|
189 |
+
"llm.model.layers.19.mlp.up_proj.bias": "model-00005-of-00007.safetensors",
|
190 |
+
"llm.model.layers.19.mlp.up_proj.weight": "model-00005-of-00007.safetensors",
|
191 |
+
"llm.model.layers.19.post_attention_layernorm.weight": "model-00005-of-00007.safetensors",
|
192 |
+
"llm.model.layers.19.self_attn.k_proj.bias": "model-00005-of-00007.safetensors",
|
193 |
+
"llm.model.layers.19.self_attn.k_proj.weight": "model-00005-of-00007.safetensors",
|
194 |
+
"llm.model.layers.19.self_attn.o_proj.bias": "model-00005-of-00007.safetensors",
|
195 |
+
"llm.model.layers.19.self_attn.o_proj.weight": "model-00005-of-00007.safetensors",
|
196 |
+
"llm.model.layers.19.self_attn.q_proj.bias": "model-00005-of-00007.safetensors",
|
197 |
+
"llm.model.layers.19.self_attn.q_proj.weight": "model-00005-of-00007.safetensors",
|
198 |
+
"llm.model.layers.19.self_attn.v_proj.bias": "model-00005-of-00007.safetensors",
|
199 |
+
"llm.model.layers.19.self_attn.v_proj.weight": "model-00005-of-00007.safetensors",
|
200 |
+
"llm.model.layers.2.input_layernorm.weight": "model-00001-of-00007.safetensors",
|
201 |
+
"llm.model.layers.2.mlp.down_proj.bias": "model-00001-of-00007.safetensors",
|
202 |
+
"llm.model.layers.2.mlp.down_proj.weight": "model-00001-of-00007.safetensors",
|
203 |
+
"llm.model.layers.2.mlp.gate_proj.bias": "model-00001-of-00007.safetensors",
|
204 |
+
"llm.model.layers.2.mlp.gate_proj.weight": "model-00001-of-00007.safetensors",
|
205 |
+
"llm.model.layers.2.mlp.up_proj.bias": "model-00001-of-00007.safetensors",
|
206 |
+
"llm.model.layers.2.mlp.up_proj.weight": "model-00001-of-00007.safetensors",
|
207 |
+
"llm.model.layers.2.post_attention_layernorm.weight": "model-00001-of-00007.safetensors",
|
208 |
+
"llm.model.layers.2.self_attn.k_proj.bias": "model-00001-of-00007.safetensors",
|
209 |
+
"llm.model.layers.2.self_attn.k_proj.weight": "model-00001-of-00007.safetensors",
|
210 |
+
"llm.model.layers.2.self_attn.o_proj.bias": "model-00001-of-00007.safetensors",
|
211 |
+
"llm.model.layers.2.self_attn.o_proj.weight": "model-00001-of-00007.safetensors",
|
212 |
+
"llm.model.layers.2.self_attn.q_proj.bias": "model-00001-of-00007.safetensors",
|
213 |
+
"llm.model.layers.2.self_attn.q_proj.weight": "model-00001-of-00007.safetensors",
|
214 |
+
"llm.model.layers.2.self_attn.v_proj.bias": "model-00001-of-00007.safetensors",
|
215 |
+
"llm.model.layers.2.self_attn.v_proj.weight": "model-00001-of-00007.safetensors",
|
216 |
+
"llm.model.layers.20.input_layernorm.weight": "model-00005-of-00007.safetensors",
|
217 |
+
"llm.model.layers.20.mlp.down_proj.bias": "model-00005-of-00007.safetensors",
|
218 |
+
"llm.model.layers.20.mlp.down_proj.weight": "model-00005-of-00007.safetensors",
|
219 |
+
"llm.model.layers.20.mlp.gate_proj.bias": "model-00005-of-00007.safetensors",
|
220 |
+
"llm.model.layers.20.mlp.gate_proj.weight": "model-00005-of-00007.safetensors",
|
221 |
+
"llm.model.layers.20.mlp.up_proj.bias": "model-00005-of-00007.safetensors",
|
222 |
+
"llm.model.layers.20.mlp.up_proj.weight": "model-00005-of-00007.safetensors",
|
223 |
+
"llm.model.layers.20.post_attention_layernorm.weight": "model-00005-of-00007.safetensors",
|
224 |
+
"llm.model.layers.20.self_attn.k_proj.bias": "model-00005-of-00007.safetensors",
|
225 |
+
"llm.model.layers.20.self_attn.k_proj.weight": "model-00005-of-00007.safetensors",
|
226 |
+
"llm.model.layers.20.self_attn.o_proj.bias": "model-00005-of-00007.safetensors",
|
227 |
+
"llm.model.layers.20.self_attn.o_proj.weight": "model-00005-of-00007.safetensors",
|
228 |
+
"llm.model.layers.20.self_attn.q_proj.bias": "model-00005-of-00007.safetensors",
|
229 |
+
"llm.model.layers.20.self_attn.q_proj.weight": "model-00005-of-00007.safetensors",
|
230 |
+
"llm.model.layers.20.self_attn.v_proj.bias": "model-00005-of-00007.safetensors",
|
231 |
+
"llm.model.layers.20.self_attn.v_proj.weight": "model-00005-of-00007.safetensors",
|
232 |
+
"llm.model.layers.21.input_layernorm.weight": "model-00005-of-00007.safetensors",
|
233 |
+
"llm.model.layers.21.mlp.down_proj.bias": "model-00005-of-00007.safetensors",
|
234 |
+
"llm.model.layers.21.mlp.down_proj.weight": "model-00005-of-00007.safetensors",
|
235 |
+
"llm.model.layers.21.mlp.gate_proj.bias": "model-00005-of-00007.safetensors",
|
236 |
+
"llm.model.layers.21.mlp.gate_proj.weight": "model-00005-of-00007.safetensors",
|
237 |
+
"llm.model.layers.21.mlp.up_proj.bias": "model-00005-of-00007.safetensors",
|
238 |
+
"llm.model.layers.21.mlp.up_proj.weight": "model-00005-of-00007.safetensors",
|
239 |
+
"llm.model.layers.21.post_attention_layernorm.weight": "model-00005-of-00007.safetensors",
|
240 |
+
"llm.model.layers.21.self_attn.k_proj.bias": "model-00005-of-00007.safetensors",
|
241 |
+
"llm.model.layers.21.self_attn.k_proj.weight": "model-00005-of-00007.safetensors",
|
242 |
+
"llm.model.layers.21.self_attn.o_proj.bias": "model-00005-of-00007.safetensors",
|
243 |
+
"llm.model.layers.21.self_attn.o_proj.weight": "model-00005-of-00007.safetensors",
|
244 |
+
"llm.model.layers.21.self_attn.q_proj.bias": "model-00005-of-00007.safetensors",
|
245 |
+
"llm.model.layers.21.self_attn.q_proj.weight": "model-00005-of-00007.safetensors",
|
246 |
+
"llm.model.layers.21.self_attn.v_proj.bias": "model-00005-of-00007.safetensors",
|
247 |
+
"llm.model.layers.21.self_attn.v_proj.weight": "model-00005-of-00007.safetensors",
|
248 |
+
"llm.model.layers.22.input_layernorm.weight": "model-00005-of-00007.safetensors",
|
249 |
+
"llm.model.layers.22.mlp.down_proj.bias": "model-00005-of-00007.safetensors",
|
250 |
+
"llm.model.layers.22.mlp.down_proj.weight": "model-00005-of-00007.safetensors",
|
251 |
+
"llm.model.layers.22.mlp.gate_proj.bias": "model-00005-of-00007.safetensors",
|
252 |
+
"llm.model.layers.22.mlp.gate_proj.weight": "model-00005-of-00007.safetensors",
|
253 |
+
"llm.model.layers.22.mlp.up_proj.bias": "model-00005-of-00007.safetensors",
|
254 |
+
"llm.model.layers.22.mlp.up_proj.weight": "model-00005-of-00007.safetensors",
|
255 |
+
"llm.model.layers.22.post_attention_layernorm.weight": "model-00005-of-00007.safetensors",
|
256 |
+
"llm.model.layers.22.self_attn.k_proj.bias": "model-00005-of-00007.safetensors",
|
257 |
+
"llm.model.layers.22.self_attn.k_proj.weight": "model-00005-of-00007.safetensors",
|
258 |
+
"llm.model.layers.22.self_attn.o_proj.bias": "model-00005-of-00007.safetensors",
|
259 |
+
"llm.model.layers.22.self_attn.o_proj.weight": "model-00005-of-00007.safetensors",
|
260 |
+
"llm.model.layers.22.self_attn.q_proj.bias": "model-00005-of-00007.safetensors",
|
261 |
+
"llm.model.layers.22.self_attn.q_proj.weight": "model-00005-of-00007.safetensors",
|
262 |
+
"llm.model.layers.22.self_attn.v_proj.bias": "model-00005-of-00007.safetensors",
|
263 |
+
"llm.model.layers.22.self_attn.v_proj.weight": "model-00005-of-00007.safetensors",
|
264 |
+
"llm.model.layers.23.input_layernorm.weight": "model-00005-of-00007.safetensors",
|
265 |
+
"llm.model.layers.23.mlp.down_proj.bias": "model-00005-of-00007.safetensors",
|
266 |
+
"llm.model.layers.23.mlp.down_proj.weight": "model-00005-of-00007.safetensors",
|
267 |
+
"llm.model.layers.23.mlp.gate_proj.bias": "model-00005-of-00007.safetensors",
|
268 |
+
"llm.model.layers.23.mlp.gate_proj.weight": "model-00005-of-00007.safetensors",
|
269 |
+
"llm.model.layers.23.mlp.up_proj.bias": "model-00005-of-00007.safetensors",
|
270 |
+
"llm.model.layers.23.mlp.up_proj.weight": "model-00005-of-00007.safetensors",
|
271 |
+
"llm.model.layers.23.post_attention_layernorm.weight": "model-00005-of-00007.safetensors",
|
272 |
+
"llm.model.layers.23.self_attn.k_proj.bias": "model-00005-of-00007.safetensors",
|
273 |
+
"llm.model.layers.23.self_attn.k_proj.weight": "model-00005-of-00007.safetensors",
|
274 |
+
"llm.model.layers.23.self_attn.o_proj.bias": "model-00005-of-00007.safetensors",
|
275 |
+
"llm.model.layers.23.self_attn.o_proj.weight": "model-00005-of-00007.safetensors",
|
276 |
+
"llm.model.layers.23.self_attn.q_proj.bias": "model-00005-of-00007.safetensors",
|
277 |
+
"llm.model.layers.23.self_attn.q_proj.weight": "model-00005-of-00007.safetensors",
|
278 |
+
"llm.model.layers.23.self_attn.v_proj.bias": "model-00005-of-00007.safetensors",
|
279 |
+
"llm.model.layers.23.self_attn.v_proj.weight": "model-00005-of-00007.safetensors",
|
280 |
+
"llm.model.layers.24.input_layernorm.weight": "model-00006-of-00007.safetensors",
|
281 |
+
"llm.model.layers.24.mlp.down_proj.weight": "model-00006-of-00007.safetensors",
|
282 |
+
"llm.model.layers.24.mlp.gate_proj.weight": "model-00006-of-00007.safetensors",
|
283 |
+
"llm.model.layers.24.mlp.up_proj.weight": "model-00006-of-00007.safetensors",
|
284 |
+
"llm.model.layers.24.post_attention_layernorm.weight": "model-00006-of-00007.safetensors",
|
285 |
+
"llm.model.layers.24.self_attn.k_proj.bias": "model-00005-of-00007.safetensors",
|
286 |
+
"llm.model.layers.24.self_attn.k_proj.weight": "model-00005-of-00007.safetensors",
|
287 |
+
"llm.model.layers.24.self_attn.o_proj.weight": "model-00006-of-00007.safetensors",
|
288 |
+
"llm.model.layers.24.self_attn.q_proj.bias": "model-00005-of-00007.safetensors",
|
289 |
+
"llm.model.layers.24.self_attn.q_proj.weight": "model-00005-of-00007.safetensors",
|
290 |
+
"llm.model.layers.24.self_attn.v_proj.bias": "model-00005-of-00007.safetensors",
|
291 |
+
"llm.model.layers.24.self_attn.v_proj.weight": "model-00005-of-00007.safetensors",
|
292 |
+
"llm.model.layers.25.input_layernorm.weight": "model-00006-of-00007.safetensors",
|
293 |
+
"llm.model.layers.25.mlp.down_proj.weight": "model-00006-of-00007.safetensors",
|
294 |
+
"llm.model.layers.25.mlp.gate_proj.weight": "model-00006-of-00007.safetensors",
|
295 |
+
"llm.model.layers.25.mlp.up_proj.weight": "model-00006-of-00007.safetensors",
|
296 |
+
"llm.model.layers.25.post_attention_layernorm.weight": "model-00006-of-00007.safetensors",
|
297 |
+
"llm.model.layers.25.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
|
298 |
+
"llm.model.layers.25.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
|
299 |
+
"llm.model.layers.25.self_attn.o_proj.weight": "model-00006-of-00007.safetensors",
|
300 |
+
"llm.model.layers.25.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
|
301 |
+
"llm.model.layers.25.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
|
302 |
+
"llm.model.layers.25.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
|
303 |
+
"llm.model.layers.25.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
|
304 |
+
"llm.model.layers.26.input_layernorm.weight": "model-00006-of-00007.safetensors",
|
305 |
+
"llm.model.layers.26.mlp.down_proj.weight": "model-00006-of-00007.safetensors",
|
306 |
+
"llm.model.layers.26.mlp.gate_proj.weight": "model-00006-of-00007.safetensors",
|
307 |
+
"llm.model.layers.26.mlp.up_proj.weight": "model-00006-of-00007.safetensors",
|
308 |
+
"llm.model.layers.26.post_attention_layernorm.weight": "model-00006-of-00007.safetensors",
|
309 |
+
"llm.model.layers.26.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
|
310 |
+
"llm.model.layers.26.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
|
311 |
+
"llm.model.layers.26.self_attn.o_proj.weight": "model-00006-of-00007.safetensors",
|
312 |
+
"llm.model.layers.26.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
|
313 |
+
"llm.model.layers.26.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
|
314 |
+
"llm.model.layers.26.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
|
315 |
+
"llm.model.layers.26.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
|
316 |
+
"llm.model.layers.27.input_layernorm.weight": "model-00006-of-00007.safetensors",
|
317 |
+
"llm.model.layers.27.mlp.down_proj.weight": "model-00006-of-00007.safetensors",
|
318 |
+
"llm.model.layers.27.mlp.gate_proj.weight": "model-00006-of-00007.safetensors",
|
319 |
+
"llm.model.layers.27.mlp.up_proj.weight": "model-00006-of-00007.safetensors",
|
320 |
+
"llm.model.layers.27.post_attention_layernorm.weight": "model-00006-of-00007.safetensors",
|
321 |
+
"llm.model.layers.27.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
|
322 |
+
"llm.model.layers.27.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
|
323 |
+
"llm.model.layers.27.self_attn.o_proj.weight": "model-00006-of-00007.safetensors",
|
324 |
+
"llm.model.layers.27.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
|
325 |
+
"llm.model.layers.27.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
|
326 |
+
"llm.model.layers.27.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
|
327 |
+
"llm.model.layers.27.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
|
328 |
+
"llm.model.layers.3.input_layernorm.weight": "model-00002-of-00007.safetensors",
|
329 |
+
"llm.model.layers.3.mlp.down_proj.bias": "model-00002-of-00007.safetensors",
|
330 |
+
"llm.model.layers.3.mlp.down_proj.weight": "model-00002-of-00007.safetensors",
|
331 |
+
"llm.model.layers.3.mlp.gate_proj.bias": "model-00002-of-00007.safetensors",
|
332 |
+
"llm.model.layers.3.mlp.gate_proj.weight": "model-00002-of-00007.safetensors",
|
333 |
+
"llm.model.layers.3.mlp.up_proj.bias": "model-00002-of-00007.safetensors",
|
334 |
+
"llm.model.layers.3.mlp.up_proj.weight": "model-00002-of-00007.safetensors",
|
335 |
+
"llm.model.layers.3.post_attention_layernorm.weight": "model-00002-of-00007.safetensors",
|
336 |
+
"llm.model.layers.3.self_attn.k_proj.bias": "model-00002-of-00007.safetensors",
|
337 |
+
"llm.model.layers.3.self_attn.k_proj.weight": "model-00002-of-00007.safetensors",
|
338 |
+
"llm.model.layers.3.self_attn.o_proj.bias": "model-00002-of-00007.safetensors",
|
339 |
+
"llm.model.layers.3.self_attn.o_proj.weight": "model-00002-of-00007.safetensors",
|
340 |
+
"llm.model.layers.3.self_attn.q_proj.bias": "model-00002-of-00007.safetensors",
|
341 |
+
"llm.model.layers.3.self_attn.q_proj.weight": "model-00002-of-00007.safetensors",
|
342 |
+
"llm.model.layers.3.self_attn.v_proj.bias": "model-00002-of-00007.safetensors",
|
343 |
+
"llm.model.layers.3.self_attn.v_proj.weight": "model-00002-of-00007.safetensors",
|
344 |
+
"llm.model.layers.4.input_layernorm.weight": "model-00002-of-00007.safetensors",
|
345 |
+
"llm.model.layers.4.mlp.down_proj.bias": "model-00002-of-00007.safetensors",
|
346 |
+
"llm.model.layers.4.mlp.down_proj.weight": "model-00002-of-00007.safetensors",
|
347 |
+
"llm.model.layers.4.mlp.gate_proj.bias": "model-00002-of-00007.safetensors",
|
348 |
+
"llm.model.layers.4.mlp.gate_proj.weight": "model-00002-of-00007.safetensors",
|
349 |
+
"llm.model.layers.4.mlp.up_proj.bias": "model-00002-of-00007.safetensors",
|
350 |
+
"llm.model.layers.4.mlp.up_proj.weight": "model-00002-of-00007.safetensors",
|
351 |
+
"llm.model.layers.4.post_attention_layernorm.weight": "model-00002-of-00007.safetensors",
|
352 |
+
"llm.model.layers.4.self_attn.k_proj.bias": "model-00002-of-00007.safetensors",
|
353 |
+
"llm.model.layers.4.self_attn.k_proj.weight": "model-00002-of-00007.safetensors",
|
354 |
+
"llm.model.layers.4.self_attn.o_proj.bias": "model-00002-of-00007.safetensors",
|
355 |
+
"llm.model.layers.4.self_attn.o_proj.weight": "model-00002-of-00007.safetensors",
|
356 |
+
"llm.model.layers.4.self_attn.q_proj.bias": "model-00002-of-00007.safetensors",
|
357 |
+
"llm.model.layers.4.self_attn.q_proj.weight": "model-00002-of-00007.safetensors",
|
358 |
+
"llm.model.layers.4.self_attn.v_proj.bias": "model-00002-of-00007.safetensors",
|
359 |
+
"llm.model.layers.4.self_attn.v_proj.weight": "model-00002-of-00007.safetensors",
|
360 |
+
"llm.model.layers.5.input_layernorm.weight": "model-00002-of-00007.safetensors",
|
361 |
+
"llm.model.layers.5.mlp.down_proj.bias": "model-00002-of-00007.safetensors",
|
362 |
+
"llm.model.layers.5.mlp.down_proj.weight": "model-00002-of-00007.safetensors",
|
363 |
+
"llm.model.layers.5.mlp.gate_proj.bias": "model-00002-of-00007.safetensors",
|
364 |
+
"llm.model.layers.5.mlp.gate_proj.weight": "model-00002-of-00007.safetensors",
|
365 |
+
"llm.model.layers.5.mlp.up_proj.bias": "model-00002-of-00007.safetensors",
|
366 |
+
"llm.model.layers.5.mlp.up_proj.weight": "model-00002-of-00007.safetensors",
|
367 |
+
"llm.model.layers.5.post_attention_layernorm.weight": "model-00002-of-00007.safetensors",
|
368 |
+
"llm.model.layers.5.self_attn.k_proj.bias": "model-00002-of-00007.safetensors",
|
369 |
+
"llm.model.layers.5.self_attn.k_proj.weight": "model-00002-of-00007.safetensors",
|
370 |
+
"llm.model.layers.5.self_attn.o_proj.bias": "model-00002-of-00007.safetensors",
|
371 |
+
"llm.model.layers.5.self_attn.o_proj.weight": "model-00002-of-00007.safetensors",
|
372 |
+
"llm.model.layers.5.self_attn.q_proj.bias": "model-00002-of-00007.safetensors",
|
373 |
+
"llm.model.layers.5.self_attn.q_proj.weight": "model-00002-of-00007.safetensors",
|
374 |
+
"llm.model.layers.5.self_attn.v_proj.bias": "model-00002-of-00007.safetensors",
|
375 |
+
"llm.model.layers.5.self_attn.v_proj.weight": "model-00002-of-00007.safetensors",
|
376 |
+
"llm.model.layers.6.input_layernorm.weight": "model-00002-of-00007.safetensors",
|
377 |
+
"llm.model.layers.6.mlp.down_proj.bias": "model-00002-of-00007.safetensors",
|
378 |
+
"llm.model.layers.6.mlp.down_proj.weight": "model-00002-of-00007.safetensors",
|
379 |
+
"llm.model.layers.6.mlp.gate_proj.bias": "model-00002-of-00007.safetensors",
|
380 |
+
"llm.model.layers.6.mlp.gate_proj.weight": "model-00002-of-00007.safetensors",
|
381 |
+
"llm.model.layers.6.mlp.up_proj.bias": "model-00002-of-00007.safetensors",
|
382 |
+
"llm.model.layers.6.mlp.up_proj.weight": "model-00002-of-00007.safetensors",
|
383 |
+
"llm.model.layers.6.post_attention_layernorm.weight": "model-00002-of-00007.safetensors",
|
384 |
+
"llm.model.layers.6.self_attn.k_proj.bias": "model-00002-of-00007.safetensors",
|
385 |
+
"llm.model.layers.6.self_attn.k_proj.weight": "model-00002-of-00007.safetensors",
|
386 |
+
"llm.model.layers.6.self_attn.o_proj.bias": "model-00002-of-00007.safetensors",
|
387 |
+
"llm.model.layers.6.self_attn.o_proj.weight": "model-00002-of-00007.safetensors",
|
388 |
+
"llm.model.layers.6.self_attn.q_proj.bias": "model-00002-of-00007.safetensors",
|
389 |
+
"llm.model.layers.6.self_attn.q_proj.weight": "model-00002-of-00007.safetensors",
|
390 |
+
"llm.model.layers.6.self_attn.v_proj.bias": "model-00002-of-00007.safetensors",
|
391 |
+
"llm.model.layers.6.self_attn.v_proj.weight": "model-00002-of-00007.safetensors",
|
392 |
+
"llm.model.layers.7.input_layernorm.weight": "model-00002-of-00007.safetensors",
|
393 |
+
"llm.model.layers.7.mlp.down_proj.bias": "model-00002-of-00007.safetensors",
|
394 |
+
"llm.model.layers.7.mlp.down_proj.weight": "model-00002-of-00007.safetensors",
|
395 |
+
"llm.model.layers.7.mlp.gate_proj.bias": "model-00002-of-00007.safetensors",
|
396 |
+
"llm.model.layers.7.mlp.gate_proj.weight": "model-00002-of-00007.safetensors",
|
397 |
+
"llm.model.layers.7.mlp.up_proj.bias": "model-00002-of-00007.safetensors",
|
398 |
+
"llm.model.layers.7.mlp.up_proj.weight": "model-00002-of-00007.safetensors",
|
399 |
+
"llm.model.layers.7.post_attention_layernorm.weight": "model-00002-of-00007.safetensors",
|
400 |
+
"llm.model.layers.7.self_attn.k_proj.bias": "model-00002-of-00007.safetensors",
|
401 |
+
"llm.model.layers.7.self_attn.k_proj.weight": "model-00002-of-00007.safetensors",
|
402 |
+
"llm.model.layers.7.self_attn.o_proj.bias": "model-00002-of-00007.safetensors",
|
403 |
+
"llm.model.layers.7.self_attn.o_proj.weight": "model-00002-of-00007.safetensors",
|
404 |
+
"llm.model.layers.7.self_attn.q_proj.bias": "model-00002-of-00007.safetensors",
|
405 |
+
"llm.model.layers.7.self_attn.q_proj.weight": "model-00002-of-00007.safetensors",
|
406 |
+
"llm.model.layers.7.self_attn.v_proj.bias": "model-00002-of-00007.safetensors",
|
407 |
+
"llm.model.layers.7.self_attn.v_proj.weight": "model-00002-of-00007.safetensors",
|
408 |
+
"llm.model.layers.8.input_layernorm.weight": "model-00003-of-00007.safetensors",
|
409 |
+
"llm.model.layers.8.mlp.down_proj.bias": "model-00003-of-00007.safetensors",
|
410 |
+
"llm.model.layers.8.mlp.down_proj.weight": "model-00003-of-00007.safetensors",
|
411 |
+
"llm.model.layers.8.mlp.gate_proj.bias": "model-00003-of-00007.safetensors",
|
412 |
+
"llm.model.layers.8.mlp.gate_proj.weight": "model-00003-of-00007.safetensors",
|
413 |
+
"llm.model.layers.8.mlp.up_proj.bias": "model-00003-of-00007.safetensors",
|
414 |
+
"llm.model.layers.8.mlp.up_proj.weight": "model-00003-of-00007.safetensors",
|
415 |
+
"llm.model.layers.8.post_attention_layernorm.weight": "model-00003-of-00007.safetensors",
|
416 |
+
"llm.model.layers.8.self_attn.k_proj.bias": "model-00002-of-00007.safetensors",
|
417 |
+
"llm.model.layers.8.self_attn.k_proj.weight": "model-00002-of-00007.safetensors",
|
418 |
+
"llm.model.layers.8.self_attn.o_proj.bias": "model-00002-of-00007.safetensors",
|
419 |
+
"llm.model.layers.8.self_attn.o_proj.weight": "model-00002-of-00007.safetensors",
|
420 |
+
"llm.model.layers.8.self_attn.q_proj.bias": "model-00002-of-00007.safetensors",
|
421 |
+
"llm.model.layers.8.self_attn.q_proj.weight": "model-00002-of-00007.safetensors",
|
422 |
+
"llm.model.layers.8.self_attn.v_proj.bias": "model-00002-of-00007.safetensors",
|
423 |
+
"llm.model.layers.8.self_attn.v_proj.weight": "model-00002-of-00007.safetensors",
|
424 |
+
"llm.model.layers.9.input_layernorm.weight": "model-00003-of-00007.safetensors",
|
425 |
+
"llm.model.layers.9.mlp.down_proj.bias": "model-00003-of-00007.safetensors",
|
426 |
+
"llm.model.layers.9.mlp.down_proj.weight": "model-00003-of-00007.safetensors",
|
427 |
+
"llm.model.layers.9.mlp.gate_proj.bias": "model-00003-of-00007.safetensors",
|
428 |
+
"llm.model.layers.9.mlp.gate_proj.weight": "model-00003-of-00007.safetensors",
|
429 |
+
"llm.model.layers.9.mlp.up_proj.bias": "model-00003-of-00007.safetensors",
|
430 |
+
"llm.model.layers.9.mlp.up_proj.weight": "model-00003-of-00007.safetensors",
|
431 |
+
"llm.model.layers.9.post_attention_layernorm.weight": "model-00003-of-00007.safetensors",
|
432 |
+
"llm.model.layers.9.self_attn.k_proj.bias": "model-00003-of-00007.safetensors",
|
433 |
+
"llm.model.layers.9.self_attn.k_proj.weight": "model-00003-of-00007.safetensors",
|
434 |
+
"llm.model.layers.9.self_attn.o_proj.bias": "model-00003-of-00007.safetensors",
|
435 |
+
"llm.model.layers.9.self_attn.o_proj.weight": "model-00003-of-00007.safetensors",
|
436 |
+
"llm.model.layers.9.self_attn.q_proj.bias": "model-00003-of-00007.safetensors",
|
437 |
+
"llm.model.layers.9.self_attn.q_proj.weight": "model-00003-of-00007.safetensors",
|
438 |
+
"llm.model.layers.9.self_attn.v_proj.bias": "model-00003-of-00007.safetensors",
|
439 |
+
"llm.model.layers.9.self_attn.v_proj.weight": "model-00003-of-00007.safetensors",
|
440 |
+
"llm.model.norm.weight": "model-00006-of-00007.safetensors",
|
441 |
+
"vision_embedding.out_proj.weight": "model-00007-of-00007.safetensors",
|
442 |
+
"vision_embedding.patchifier.norm.weight": "model-00007-of-00007.safetensors",
|
443 |
+
"vision_embedding.patchifier.proj.bias": "model-00007-of-00007.safetensors",
|
444 |
+
"vision_embedding.patchifier.proj.weight": "model-00007-of-00007.safetensors",
|
445 |
+
"vision_embedding.pos_embed": "model-00007-of-00007.safetensors"
|
446 |
+
}
|
447 |
+
}
|
modeling_vora.py
ADDED
@@ -0,0 +1,219 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os.path as osp
|
2 |
+
|
3 |
+
import torch
|
4 |
+
import torch.distributed as dist
|
5 |
+
from transformers import (
|
6 |
+
AutoModelForCausalLM,
|
7 |
+
AutoTokenizer,
|
8 |
+
AutoConfig,
|
9 |
+
PreTrainedModel,
|
10 |
+
PretrainedConfig,
|
11 |
+
Qwen2ForCausalLM,
|
12 |
+
)
|
13 |
+
|
14 |
+
from .attention_mask import make_mask
|
15 |
+
from .configuration_vora import VoRAConfig
|
16 |
+
from .lora import apply_lora
|
17 |
+
from .vision_embedding import build_vision_embedding
|
18 |
+
from .vora_generation_utils import (
|
19 |
+
VoraGenerationMixin,
|
20 |
+
custom_prepare_4d_causal_attention_mask_with_cache_position,
|
21 |
+
)
|
22 |
+
|
23 |
+
|
24 |
+
class VoRAForCausalLM(PreTrainedModel):
|
25 |
+
config_class = VoRAConfig
|
26 |
+
_auto_class = 'AutoModelForCausalLM'
|
27 |
+
supports_gradient_checkpointing = True
|
28 |
+
|
29 |
+
def __init__(self, config: PretrainedConfig = VoRAConfig()):
|
30 |
+
super().__init__(config)
|
31 |
+
self.config = config
|
32 |
+
# -------------- Setup LLM ---------------------
|
33 |
+
self.llm = Qwen2ForCausalLM(config)
|
34 |
+
|
35 |
+
# monkey patch for generation
|
36 |
+
self.llm.__class__ = type(self.llm.__class__.__name__, (self.llm.__class__, VoraGenerationMixin), {})
|
37 |
+
self.llm.model._prepare_4d_causal_attention_mask_with_cache_position = staticmethod(custom_prepare_4d_causal_attention_mask_with_cache_position)
|
38 |
+
dtype = self.llm.dtype
|
39 |
+
|
40 |
+
# hacking for multi-processor infer
|
41 |
+
self._tp_plan = self.llm._tp_plan
|
42 |
+
|
43 |
+
self.config.update(self.llm.config.to_dict())
|
44 |
+
# ----------------------------------------------
|
45 |
+
|
46 |
+
|
47 |
+
# -------------- Setup LoRA -------------------
|
48 |
+
if config.lora:
|
49 |
+
for _, param in self.llm.named_parameters():
|
50 |
+
param.requires_grad = False
|
51 |
+
apply_lora(self.llm, config.lora)
|
52 |
+
self.llm.to(dtype)
|
53 |
+
# ----------------------------------------------
|
54 |
+
|
55 |
+
# ------------ Setup Vision Embedding ----------
|
56 |
+
self.vision_embedding = build_vision_embedding(config, self.llm.config.hidden_size)
|
57 |
+
# ----------------------------------------------
|
58 |
+
|
59 |
+
def _encode_vision(self, images, n_frames):
|
60 |
+
# TODO: we need a more elegant way here to deal with mixed image and pure text training
|
61 |
+
if images.size(0) > 0:
|
62 |
+
vision_embeds = self.vision_embedding(images)
|
63 |
+
else:
|
64 |
+
# FIXME: hacking for deepspeed training
|
65 |
+
# we feed a dummy image tensor (1, 3, H, W) into vision_encoder when training a pure-text batch
|
66 |
+
images = images.new_zeros((1, *images.shape[1:]))
|
67 |
+
vision_embeds = self.vision_embedding(images)[0:0]
|
68 |
+
vision_embeds = vision_embeds.split(n_frames, dim=0)
|
69 |
+
attention_mask = [torch.ones(feature.size()[:-1], dtype=torch.long).to(feature.device) for feature in vision_embeds]
|
70 |
+
vision_targets = [torch.ones(feature.size(), dtype=torch.long).to(feature.device).fill_(-100) for feature in attention_mask]
|
71 |
+
|
72 |
+
image_shapes = images.shape[-2:]
|
73 |
+
|
74 |
+
return vision_embeds, attention_mask, vision_targets, image_shapes
|
75 |
+
|
76 |
+
def _concat_embedding(self, vision_encode_out, batch, vision_placeholder_index, left_padding=False, pad_token_id=0):
|
77 |
+
""" concat vision and text
|
78 |
+
"""
|
79 |
+
|
80 |
+
vision_embeds, vision_atts, vision_targets, _ = vision_encode_out
|
81 |
+
|
82 |
+
input_embeds = []
|
83 |
+
attention_mask = []
|
84 |
+
targets = []
|
85 |
+
vision_mask = [] # only set vision embeds as 1, text as 0, for aux loss
|
86 |
+
|
87 |
+
for cur_batch_idx, cur_input_ids in enumerate(batch["input_ids"]):
|
88 |
+
cur_vision_embeds = vision_embeds[cur_batch_idx]
|
89 |
+
cur_vision_attn = vision_atts[cur_batch_idx]
|
90 |
+
cur_vision_targets = vision_targets[cur_batch_idx]
|
91 |
+
cur_attn_masks = batch["attention_mask"][cur_batch_idx]
|
92 |
+
|
93 |
+
image_token_indices = torch.where(cur_input_ids == vision_placeholder_index)[0]
|
94 |
+
cur_image_num = len(image_token_indices)
|
95 |
+
image_token_indices = list(image_token_indices) + [cur_input_ids.shape[0]]
|
96 |
+
|
97 |
+
cur_input_embeds = []
|
98 |
+
cur_attention_mask = []
|
99 |
+
cur_target = []
|
100 |
+
cur_vision_mask = []
|
101 |
+
|
102 |
+
# convert text before 1st <image> to embedding
|
103 |
+
image_token_index = image_token_indices[0]
|
104 |
+
|
105 |
+
cur_input_embeds.append(
|
106 |
+
self.llm.get_input_embeddings()(cur_input_ids[:image_token_index]),
|
107 |
+
)
|
108 |
+
cur_attention_mask.append(
|
109 |
+
cur_attn_masks[:image_token_index],
|
110 |
+
)
|
111 |
+
cur_vision_mask.append(
|
112 |
+
torch.zeros_like(cur_attn_masks[:image_token_index]).to(cur_attn_masks.device),
|
113 |
+
)
|
114 |
+
if "labels" in batch:
|
115 |
+
cur_target.append(
|
116 |
+
batch["labels"][cur_batch_idx, :image_token_index],
|
117 |
+
)
|
118 |
+
|
119 |
+
if batch.get("vison_placeholder_mode", 0) == 1:
|
120 |
+
assert cur_image_num <= 1, "multiple video input is not supported"
|
121 |
+
cur_vision_embeds = cur_vision_embeds.unsqueeze(0)
|
122 |
+
cur_vision_attn = cur_vision_attn.unsqueeze(0)
|
123 |
+
cur_vision_targets = cur_vision_targets.unsqueeze(0)
|
124 |
+
assert cur_image_num == len(cur_vision_embeds), \
|
125 |
+
f"Size mismatch! cur_image_num: {cur_image_num}, len(cur_vision_embeds): {len(cur_vision_embeds)} {len(cur_vision_embeds)} \
|
126 |
+
in {batch['prompt'][cur_batch_idx]} & {batch['gt'][cur_batch_idx]} & {batch['input_ids'][cur_batch_idx]}"
|
127 |
+
# convert each <image> xxx group into embedding
|
128 |
+
text_embedding = self.llm.get_input_embeddings()(cur_input_ids.relu())
|
129 |
+
for i in range(0, cur_image_num):
|
130 |
+
image_token_index = image_token_indices[i]
|
131 |
+
cur_input_embeds.extend([
|
132 |
+
cur_vision_embeds[i],
|
133 |
+
text_embedding[image_token_index+1:image_token_indices[i+1]]
|
134 |
+
])
|
135 |
+
cur_attention_mask.extend([
|
136 |
+
cur_vision_attn[i],
|
137 |
+
cur_attn_masks[image_token_index+1:image_token_indices[i+1]]
|
138 |
+
])
|
139 |
+
cur_vision_mask.extend([
|
140 |
+
torch.ones_like(cur_vision_attn[i]).to(cur_vision_attn[i].device),
|
141 |
+
torch.zeros_like(cur_attn_masks[image_token_index+1:image_token_indices[i+1]]).to(cur_vision_attn[i].device),
|
142 |
+
])
|
143 |
+
if "labels" in batch:
|
144 |
+
cur_target.extend([
|
145 |
+
cur_vision_targets[i],
|
146 |
+
batch["labels"][cur_batch_idx, image_token_index+1:image_token_indices[i+1]],
|
147 |
+
])
|
148 |
+
|
149 |
+
input_embeds.append(torch.cat(cur_input_embeds))
|
150 |
+
attention_mask.append(torch.cat(cur_attention_mask))
|
151 |
+
vision_mask.append(torch.cat(cur_vision_mask))
|
152 |
+
if "labels" in batch:
|
153 |
+
targets.append(torch.cat(cur_target))
|
154 |
+
|
155 |
+
# padding
|
156 |
+
n_tokens = [embed.shape[0] for embed in input_embeds]
|
157 |
+
|
158 |
+
max_token = max(n_tokens)
|
159 |
+
|
160 |
+
for i in range(len(input_embeds)):
|
161 |
+
if max_token > n_tokens[i]:
|
162 |
+
pad_token = torch.tensor([pad_token_id] * (max_token - n_tokens[i]))
|
163 |
+
pad_embedding = self.llm.get_input_embeddings()(pad_token.to(batch["attention_mask"][i].device))
|
164 |
+
pad_attention = torch.zeros(pad_embedding.shape[0], dtype=torch.long).to(batch["attention_mask"][i].device)
|
165 |
+
pad_targets = torch.ones(pad_attention.size(), dtype=torch.long).to(batch["attention_mask"][i].device).fill_(-100)
|
166 |
+
|
167 |
+
if left_padding:
|
168 |
+
input_embeds[i] = torch.cat([pad_embedding, input_embeds[i]])
|
169 |
+
attention_mask[i] = torch.cat([pad_attention, attention_mask[i]])
|
170 |
+
vision_mask[i] = torch.cat([pad_attention, vision_mask[i]])
|
171 |
+
if "labels" in batch:
|
172 |
+
targets[i] = torch.cat([pad_targets, targets[i]])
|
173 |
+
else:
|
174 |
+
input_embeds[i] = torch.cat([input_embeds[i], pad_embedding])
|
175 |
+
attention_mask[i] = torch.cat([attention_mask[i], pad_attention])
|
176 |
+
vision_mask[i] = torch.cat([vision_mask[i], pad_attention])
|
177 |
+
if "labels" in batch:
|
178 |
+
targets[i] = torch.cat([targets[i], pad_targets])
|
179 |
+
|
180 |
+
inputs_embeds = torch.stack(input_embeds, dim=0).type(self.llm.dtype)
|
181 |
+
attention_mask = torch.stack(attention_mask, dim=0)
|
182 |
+
vision_mask = torch.stack(vision_mask, dim=0).to(attention_mask.device)
|
183 |
+
|
184 |
+
if len(targets) > 0:
|
185 |
+
targets = torch.stack(targets, dim=0)
|
186 |
+
|
187 |
+
attention_mask = make_mask(
|
188 |
+
attention_mask,
|
189 |
+
mode=self.config.vision_attention_mask,
|
190 |
+
vision_mask=vision_mask,
|
191 |
+
dtype=inputs_embeds.dtype
|
192 |
+
)
|
193 |
+
|
194 |
+
return inputs_embeds, attention_mask, targets, vision_mask
|
195 |
+
|
196 |
+
def generate(self, batch, **generate_params):
|
197 |
+
|
198 |
+
with torch.amp.autocast(
|
199 |
+
device_type="cuda",
|
200 |
+
enabled=(self.device != torch.device("cpu"))
|
201 |
+
):
|
202 |
+
# get vision token
|
203 |
+
vision_placeholder_index = batch.pop("vision_placeholder_index")
|
204 |
+
|
205 |
+
# get vision features
|
206 |
+
images, n_frames = batch["frames"], batch["n_frames"]
|
207 |
+
vision_encode_out = self._encode_vision(images, n_frames)
|
208 |
+
|
209 |
+
inputs_embeds, attention_mask, _, _ = self._concat_embedding(
|
210 |
+
vision_encode_out, batch, vision_placeholder_index, left_padding=False, pad_token_id=generate_params["eos_token_id"])
|
211 |
+
|
212 |
+
outputs = self.llm.generate(
|
213 |
+
inputs_embeds=inputs_embeds,
|
214 |
+
attention_mask=attention_mask,
|
215 |
+
output_attentions=True,
|
216 |
+
**generate_params
|
217 |
+
)
|
218 |
+
|
219 |
+
return outputs
|
preprocessor_config.json
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"do_center_crop": false,
|
3 |
+
"do_convert_rgb": true,
|
4 |
+
"do_normalize": true,
|
5 |
+
"do_rescale": true,
|
6 |
+
"do_resize": false,
|
7 |
+
"image_mean": [
|
8 |
+
0.48145466,
|
9 |
+
0.4578275,
|
10 |
+
0.40821073
|
11 |
+
],
|
12 |
+
"image_processor_type": "CLIPImageProcessor",
|
13 |
+
"image_std": [
|
14 |
+
0.26862954,
|
15 |
+
0.26130258,
|
16 |
+
0.27577711
|
17 |
+
],
|
18 |
+
"resample": 3,
|
19 |
+
"rescale_factor": 0.00392156862745098,
|
20 |
+
"size": {
|
21 |
+
"shortest_edge": 224
|
22 |
+
}
|
23 |
+
}
|
processing_vora.py
ADDED
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import math
|
3 |
+
|
4 |
+
from typing import List, Union
|
5 |
+
from PIL import Image
|
6 |
+
|
7 |
+
from transformers.feature_extraction_utils import BatchFeature
|
8 |
+
from transformers.image_utils import ImageInput
|
9 |
+
from transformers.processing_utils import ProcessingKwargs, ProcessorMixin, Unpack, _validate_images_text_input_order
|
10 |
+
from transformers.tokenization_utils_base import PreTokenizedInput, TextInput
|
11 |
+
|
12 |
+
from .modeling_vora import VoRAForCausalLM
|
13 |
+
|
14 |
+
|
15 |
+
def smart_resize(
|
16 |
+
height: int, width: int, factor: int = 14, min_pixels: int = 14 * 14, max_pixels: int = 14 * 14 * 160 * 160
|
17 |
+
):
|
18 |
+
"""Rescales the image so that the following conditions are met:
|
19 |
+
|
20 |
+
1. Both dimensions (height and width) are divisible by 'factor'.
|
21 |
+
|
22 |
+
2. The total number of pixels is within the range ['min_pixels', 'max_pixels'].
|
23 |
+
|
24 |
+
3. The aspect ratio of the image is maintained as closely as possible.
|
25 |
+
|
26 |
+
"""
|
27 |
+
if height < factor or width < factor:
|
28 |
+
raise ValueError(f"height:{height} or width:{width} must be larger than factor:{factor}")
|
29 |
+
elif max(height, width) / min(height, width) > 200:
|
30 |
+
raise ValueError(
|
31 |
+
f"absolute aspect ratio must be smaller than 200, got {max(height, width) / min(height, width)}"
|
32 |
+
)
|
33 |
+
h_bar = round(height / factor) * factor
|
34 |
+
w_bar = round(width / factor) * factor
|
35 |
+
if h_bar * w_bar > max_pixels:
|
36 |
+
beta = math.sqrt((height * width) / max_pixels)
|
37 |
+
h_bar = math.floor(height / beta / factor) * factor
|
38 |
+
w_bar = math.floor(width / beta / factor) * factor
|
39 |
+
elif h_bar * w_bar < min_pixels:
|
40 |
+
beta = math.sqrt(min_pixels / (height * width))
|
41 |
+
h_bar = math.ceil(height * beta / factor) * factor
|
42 |
+
w_bar = math.ceil(width * beta / factor) * factor
|
43 |
+
return h_bar, w_bar
|
44 |
+
|
45 |
+
|
46 |
+
class VoRAProcessorKwargs(ProcessingKwargs, total=False):
|
47 |
+
_defaults = {
|
48 |
+
"text_kwargs": {
|
49 |
+
"padding": False,
|
50 |
+
},
|
51 |
+
"images_kwargs": {},
|
52 |
+
}
|
53 |
+
|
54 |
+
|
55 |
+
class VoRAProcesser(ProcessorMixin):
|
56 |
+
attributes = ["image_processor", "tokenizer"]
|
57 |
+
valid_kwargs = [
|
58 |
+
"chat_template",
|
59 |
+
"image_token",
|
60 |
+
]
|
61 |
+
image_processor_class = "AutoImageProcessor"
|
62 |
+
tokenizer_class = "AutoTokenizer"
|
63 |
+
|
64 |
+
def __init__(
|
65 |
+
self,
|
66 |
+
image_processor=None,
|
67 |
+
tokenizer=None,
|
68 |
+
chat_template=None,
|
69 |
+
image_token="<image>", # set the default and let users change if they have peculiar special tokens in rare cases
|
70 |
+
image_token_index = -200,
|
71 |
+
**kwargs,
|
72 |
+
):
|
73 |
+
self.image_token = image_token
|
74 |
+
self.image_token_index = image_token_index
|
75 |
+
super().__init__(image_processor, tokenizer, chat_template=chat_template)
|
76 |
+
|
77 |
+
def __call__(
|
78 |
+
self,
|
79 |
+
images: ImageInput = None,
|
80 |
+
text: Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None,
|
81 |
+
**kwargs: Unpack[VoRAProcessorKwargs],
|
82 |
+
):
|
83 |
+
if images is None and text is None:
|
84 |
+
raise ValueError("You have to specify at least one of `images` or `text`.")
|
85 |
+
|
86 |
+
images, text = _validate_images_text_input_order(images, text)
|
87 |
+
output_kwargs = self._merge_kwargs(
|
88 |
+
VoRAProcessorKwargs,
|
89 |
+
tokenizer_init_kwargs=self.tokenizer.init_kwargs,
|
90 |
+
**kwargs,
|
91 |
+
)
|
92 |
+
|
93 |
+
if images is not None:
|
94 |
+
images = [[self.anyres_resize(image[0])] for image in images]
|
95 |
+
image_inputs = self.image_processor(images, **output_kwargs["images_kwargs"])
|
96 |
+
else:
|
97 |
+
image_inputs = {}
|
98 |
+
|
99 |
+
if isinstance(text, str):
|
100 |
+
text = [text]
|
101 |
+
elif not isinstance(text, list) and not isinstance(text[0], str):
|
102 |
+
raise ValueError("Invalid input text. Please provide a string, or a list of strings")
|
103 |
+
|
104 |
+
input_ids = [self.tokenizer_vision_placeholder(t) for t in text]
|
105 |
+
attention_mask = [
|
106 |
+
[1] * len(input_ids[i]) for i in range(len(input_ids))
|
107 |
+
]
|
108 |
+
text_inputs = dict(
|
109 |
+
input_ids=torch.as_tensor(input_ids, dtype=torch.int64),
|
110 |
+
attention_mask=torch.as_tensor(attention_mask, dtype=torch.int64),
|
111 |
+
)
|
112 |
+
image_inputs['frames'] = image_inputs.pop('pixel_values')
|
113 |
+
image_inputs['n_frames'] = [len(_images) for _images in images]
|
114 |
+
image_inputs['vision_placeholder_index'] = self.image_token_index
|
115 |
+
return BatchFeature(data={**text_inputs, **image_inputs})
|
116 |
+
|
117 |
+
def anyres_resize(self, pil_img: Image.Image):
|
118 |
+
h, w = pil_img.size
|
119 |
+
h, w = smart_resize(h, w)
|
120 |
+
image = pil_img.resize((w, h))
|
121 |
+
return image
|
122 |
+
|
123 |
+
def tokenizer_vision_placeholder(self, prompt, add_bos=False):
|
124 |
+
def join_lists(*lists, sep):
|
125 |
+
result = []
|
126 |
+
for i, lst in enumerate(lists):
|
127 |
+
if i > 0 and sep:
|
128 |
+
result.extend([sep])
|
129 |
+
result.extend(lst)
|
130 |
+
return result
|
131 |
+
|
132 |
+
prompt_chunks = [self.tokenizer.encode(
|
133 |
+
chunk) for chunk in prompt.split(self.image_token)]
|
134 |
+
input_ids = join_lists(*prompt_chunks, sep=self.image_token_index)
|
135 |
+
if add_bos:
|
136 |
+
input_ids = [self.tokenizer.bos_token_id] + input_ids
|
137 |
+
|
138 |
+
return input_ids
|
139 |
+
|
processor_config.json
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"image_token": "<image>",
|
3 |
+
"image_token_index": -200,
|
4 |
+
"processor_class": "VoRAProcessing",
|
5 |
+
"auto_map": {"AutoProcessor": "processing_vora.VoRAProcesser"}
|
6 |
+
}
|
special_tokens_map.json
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"additional_special_tokens": [
|
3 |
+
"<|im_start|>",
|
4 |
+
"<|im_end|>",
|
5 |
+
"<|object_ref_start|>",
|
6 |
+
"<|object_ref_end|>",
|
7 |
+
"<|box_start|>",
|
8 |
+
"<|box_end|>",
|
9 |
+
"<|quad_start|>",
|
10 |
+
"<|quad_end|>",
|
11 |
+
"<|vision_start|>",
|
12 |
+
"<|vision_end|>",
|
13 |
+
"<|vision_pad|>",
|
14 |
+
"<|image_pad|>",
|
15 |
+
"<|video_pad|>"
|
16 |
+
],
|
17 |
+
"eos_token": {
|
18 |
+
"content": "<|im_end|>",
|
19 |
+
"lstrip": false,
|
20 |
+
"normalized": false,
|
21 |
+
"rstrip": false,
|
22 |
+
"single_word": false
|
23 |
+
},
|
24 |
+
"pad_token": {
|
25 |
+
"content": "<|endoftext|>",
|
26 |
+
"lstrip": false,
|
27 |
+
"normalized": false,
|
28 |
+
"rstrip": false,
|
29 |
+
"single_word": false
|
30 |
+
}
|
31 |
+
}
|
tokenizer.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9c5ae00e602b8860cbd784ba82a8aa14e8feecec692e7076590d014d7b7fdafa
|
3 |
+
size 11421896
|
tokenizer_config.json
ADDED
@@ -0,0 +1,209 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"add_bos_token": false,
|
3 |
+
"add_prefix_space": false,
|
4 |
+
"added_tokens_decoder": {
|
5 |
+
"151643": {
|
6 |
+
"content": "<|endoftext|>",
|
7 |
+
"lstrip": false,
|
8 |
+
"normalized": false,
|
9 |
+
"rstrip": false,
|
10 |
+
"single_word": false,
|
11 |
+
"special": true
|
12 |
+
},
|
13 |
+
"151644": {
|
14 |
+
"content": "<|im_start|>",
|
15 |
+
"lstrip": false,
|
16 |
+
"normalized": false,
|
17 |
+
"rstrip": false,
|
18 |
+
"single_word": false,
|
19 |
+
"special": true
|
20 |
+
},
|
21 |
+
"151645": {
|
22 |
+
"content": "<|im_end|>",
|
23 |
+
"lstrip": false,
|
24 |
+
"normalized": false,
|
25 |
+
"rstrip": false,
|
26 |
+
"single_word": false,
|
27 |
+
"special": true
|
28 |
+
},
|
29 |
+
"151646": {
|
30 |
+
"content": "<|object_ref_start|>",
|
31 |
+
"lstrip": false,
|
32 |
+
"normalized": false,
|
33 |
+
"rstrip": false,
|
34 |
+
"single_word": false,
|
35 |
+
"special": true
|
36 |
+
},
|
37 |
+
"151647": {
|
38 |
+
"content": "<|object_ref_end|>",
|
39 |
+
"lstrip": false,
|
40 |
+
"normalized": false,
|
41 |
+
"rstrip": false,
|
42 |
+
"single_word": false,
|
43 |
+
"special": true
|
44 |
+
},
|
45 |
+
"151648": {
|
46 |
+
"content": "<|box_start|>",
|
47 |
+
"lstrip": false,
|
48 |
+
"normalized": false,
|
49 |
+
"rstrip": false,
|
50 |
+
"single_word": false,
|
51 |
+
"special": true
|
52 |
+
},
|
53 |
+
"151649": {
|
54 |
+
"content": "<|box_end|>",
|
55 |
+
"lstrip": false,
|
56 |
+
"normalized": false,
|
57 |
+
"rstrip": false,
|
58 |
+
"single_word": false,
|
59 |
+
"special": true
|
60 |
+
},
|
61 |
+
"151650": {
|
62 |
+
"content": "<|quad_start|>",
|
63 |
+
"lstrip": false,
|
64 |
+
"normalized": false,
|
65 |
+
"rstrip": false,
|
66 |
+
"single_word": false,
|
67 |
+
"special": true
|
68 |
+
},
|
69 |
+
"151651": {
|
70 |
+
"content": "<|quad_end|>",
|
71 |
+
"lstrip": false,
|
72 |
+
"normalized": false,
|
73 |
+
"rstrip": false,
|
74 |
+
"single_word": false,
|
75 |
+
"special": true
|
76 |
+
},
|
77 |
+
"151652": {
|
78 |
+
"content": "<|vision_start|>",
|
79 |
+
"lstrip": false,
|
80 |
+
"normalized": false,
|
81 |
+
"rstrip": false,
|
82 |
+
"single_word": false,
|
83 |
+
"special": true
|
84 |
+
},
|
85 |
+
"151653": {
|
86 |
+
"content": "<|vision_end|>",
|
87 |
+
"lstrip": false,
|
88 |
+
"normalized": false,
|
89 |
+
"rstrip": false,
|
90 |
+
"single_word": false,
|
91 |
+
"special": true
|
92 |
+
},
|
93 |
+
"151654": {
|
94 |
+
"content": "<|vision_pad|>",
|
95 |
+
"lstrip": false,
|
96 |
+
"normalized": false,
|
97 |
+
"rstrip": false,
|
98 |
+
"single_word": false,
|
99 |
+
"special": true
|
100 |
+
},
|
101 |
+
"151655": {
|
102 |
+
"content": "<|image_pad|>",
|
103 |
+
"lstrip": false,
|
104 |
+
"normalized": false,
|
105 |
+
"rstrip": false,
|
106 |
+
"single_word": false,
|
107 |
+
"special": true
|
108 |
+
},
|
109 |
+
"151656": {
|
110 |
+
"content": "<|video_pad|>",
|
111 |
+
"lstrip": false,
|
112 |
+
"normalized": false,
|
113 |
+
"rstrip": false,
|
114 |
+
"single_word": false,
|
115 |
+
"special": true
|
116 |
+
},
|
117 |
+
"151657": {
|
118 |
+
"content": "<tool_call>",
|
119 |
+
"lstrip": false,
|
120 |
+
"normalized": false,
|
121 |
+
"rstrip": false,
|
122 |
+
"single_word": false,
|
123 |
+
"special": false
|
124 |
+
},
|
125 |
+
"151658": {
|
126 |
+
"content": "</tool_call>",
|
127 |
+
"lstrip": false,
|
128 |
+
"normalized": false,
|
129 |
+
"rstrip": false,
|
130 |
+
"single_word": false,
|
131 |
+
"special": false
|
132 |
+
},
|
133 |
+
"151659": {
|
134 |
+
"content": "<|fim_prefix|>",
|
135 |
+
"lstrip": false,
|
136 |
+
"normalized": false,
|
137 |
+
"rstrip": false,
|
138 |
+
"single_word": false,
|
139 |
+
"special": false
|
140 |
+
},
|
141 |
+
"151660": {
|
142 |
+
"content": "<|fim_middle|>",
|
143 |
+
"lstrip": false,
|
144 |
+
"normalized": false,
|
145 |
+
"rstrip": false,
|
146 |
+
"single_word": false,
|
147 |
+
"special": false
|
148 |
+
},
|
149 |
+
"151661": {
|
150 |
+
"content": "<|fim_suffix|>",
|
151 |
+
"lstrip": false,
|
152 |
+
"normalized": false,
|
153 |
+
"rstrip": false,
|
154 |
+
"single_word": false,
|
155 |
+
"special": false
|
156 |
+
},
|
157 |
+
"151662": {
|
158 |
+
"content": "<|fim_pad|>",
|
159 |
+
"lstrip": false,
|
160 |
+
"normalized": false,
|
161 |
+
"rstrip": false,
|
162 |
+
"single_word": false,
|
163 |
+
"special": false
|
164 |
+
},
|
165 |
+
"151663": {
|
166 |
+
"content": "<|repo_name|>",
|
167 |
+
"lstrip": false,
|
168 |
+
"normalized": false,
|
169 |
+
"rstrip": false,
|
170 |
+
"single_word": false,
|
171 |
+
"special": false
|
172 |
+
},
|
173 |
+
"151664": {
|
174 |
+
"content": "<|file_sep|>",
|
175 |
+
"lstrip": false,
|
176 |
+
"normalized": false,
|
177 |
+
"rstrip": false,
|
178 |
+
"single_word": false,
|
179 |
+
"special": false
|
180 |
+
}
|
181 |
+
},
|
182 |
+
"additional_special_tokens": [
|
183 |
+
"<|im_start|>",
|
184 |
+
"<|im_end|>",
|
185 |
+
"<|object_ref_start|>",
|
186 |
+
"<|object_ref_end|>",
|
187 |
+
"<|box_start|>",
|
188 |
+
"<|box_end|>",
|
189 |
+
"<|quad_start|>",
|
190 |
+
"<|quad_end|>",
|
191 |
+
"<|vision_start|>",
|
192 |
+
"<|vision_end|>",
|
193 |
+
"<|vision_pad|>",
|
194 |
+
"<|image_pad|>",
|
195 |
+
"<|video_pad|>"
|
196 |
+
],
|
197 |
+
"bos_token": null,
|
198 |
+
"chat_template": "{%- if tools %}\n {{- '<|im_start|>system\\n' }}\n {%- if messages[0]['role'] == 'system' %}\n {{- messages[0]['content'] }}\n {%- else %}\n {{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}\n {%- endif %}\n {{- \"\\n\\n# Tools\\n\\nYou may call one or more functions to assist with the user query.\\n\\nYou are provided with function signatures within <tools></tools> XML tags:\\n<tools>\" }}\n {%- for tool in tools %}\n {{- \"\\n\" }}\n {{- tool | tojson }}\n {%- endfor %}\n {{- \"\\n</tools>\\n\\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\\n<tool_call>\\n{\\\"name\\\": <function-name>, \\\"arguments\\\": <args-json-object>}\\n</tool_call><|im_end|>\\n\" }}\n{%- else %}\n {%- if messages[0]['role'] == 'system' %}\n {{- '<|im_start|>system\\n' + messages[0]['content'] + '<|im_end|>\\n' }}\n {%- else %}\n {{- '<|im_start|>system\\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n{%- for message in messages %}\n {%- if (message.role == \"user\") or (message.role == \"system\" and not loop.first) or (message.role == \"assistant\" and not message.tool_calls) %}\n {{- '<|im_start|>' + message.role + '\\n' + message.content + '<|im_end|>' + '\\n' }}\n {%- elif message.role == \"assistant\" %}\n {{- '<|im_start|>' + message.role }}\n {%- if message.content %}\n {{- '\\n' + message.content }}\n {%- endif %}\n {%- for tool_call in message.tool_calls %}\n {%- if tool_call.function is defined %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {{- '\\n<tool_call>\\n{\"name\": \"' }}\n {{- tool_call.name }}\n {{- '\", \"arguments\": ' }}\n {{- tool_call.arguments | tojson }}\n {{- '}\\n</tool_call>' }}\n {%- endfor %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != \"tool\") %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- message.content }}\n {{- '\\n</tool_response>' }}\n {%- if loop.last or (messages[loop.index0 + 1].role != \"tool\") %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n{%- endif %}\n",
|
199 |
+
"clean_up_tokenization_spaces": false,
|
200 |
+
"eos_token": "<|im_end|>",
|
201 |
+
"errors": "replace",
|
202 |
+
"extra_special_tokens": {},
|
203 |
+
"model_max_length": 131072,
|
204 |
+
"pad_token": "<|endoftext|>",
|
205 |
+
"processor_class": "VoRAProcessing",
|
206 |
+
"split_special_tokens": false,
|
207 |
+
"tokenizer_class": "Qwen2Tokenizer",
|
208 |
+
"unk_token": null
|
209 |
+
}
|
vision_embedding.py
ADDED
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import torch.nn as nn
|
3 |
+
|
4 |
+
from .configuration_vora import VoRAConfig
|
5 |
+
|
6 |
+
|
7 |
+
def _get_1d_sincos_pos_embed_from_grid(
|
8 |
+
embed_dim: int, pos: torch.Tensor, device: torch.device
|
9 |
+
) -> torch.Tensor:
|
10 |
+
omega = torch.arange(embed_dim // 2).float().to(device)
|
11 |
+
omega /= embed_dim / 2.0
|
12 |
+
omega = 1.0 / 10000**omega # (D / 2,)
|
13 |
+
pos = pos.reshape(-1) # (M,)
|
14 |
+
out = pos[:, None] * omega[None, :] # (M, D / 2), outer product
|
15 |
+
emb_sin, emb_cos = torch.sin(out).to(device), torch.cos(out).to(device) # (M, D / 2)
|
16 |
+
emb = torch.cat([emb_sin, emb_cos], dim=1) # (M, D)
|
17 |
+
return emb
|
18 |
+
|
19 |
+
|
20 |
+
def get_sincos_pos_embed(h: int, w: int, embed_dim: int, device: torch.device) -> torch.Tensor:
|
21 |
+
assert embed_dim % 2 == 0, embed_dim
|
22 |
+
grid_h = torch.arange(h).float().to(device)
|
23 |
+
grid_w = torch.arange(w).float().to(device)
|
24 |
+
grid = torch.meshgrid(grid_w, grid_h, indexing="xy")
|
25 |
+
grid = torch.stack(grid, dim=0).to(device)
|
26 |
+
grid = grid.reshape([2, 1, h, w])
|
27 |
+
emb_h = _get_1d_sincos_pos_embed_from_grid(embed_dim // 2, grid[0], device)
|
28 |
+
emb_w = _get_1d_sincos_pos_embed_from_grid(embed_dim // 2, grid[1], device)
|
29 |
+
pos_embed = torch.cat([emb_h, emb_w], dim=1) # (H * W, D)
|
30 |
+
return pos_embed
|
31 |
+
|
32 |
+
|
33 |
+
class RMSNorm(nn.Module):
|
34 |
+
def __init__(self, dim: int, eps: float = 1e-6):
|
35 |
+
super().__init__()
|
36 |
+
self.weight = nn.Parameter(torch.ones(dim))
|
37 |
+
self.eps = eps
|
38 |
+
|
39 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
40 |
+
output = self._norm(x.float()).type_as(x)
|
41 |
+
return output * self.weight
|
42 |
+
|
43 |
+
def extra_repr(self) -> str:
|
44 |
+
return f"{tuple(self.weight.shape)}, eps={self.eps}"
|
45 |
+
|
46 |
+
def _norm(self, x: torch.Tensor) -> torch.Tensor:
|
47 |
+
return x * torch.rsqrt(x.pow(2).mean(-1, keepdim=True) + self.eps)
|
48 |
+
|
49 |
+
|
50 |
+
class VisionEmbedding(nn.Module):
|
51 |
+
def __init__(self,
|
52 |
+
config: VoRAConfig = None,
|
53 |
+
hidden_size: int = 4096,
|
54 |
+
):
|
55 |
+
super().__init__()
|
56 |
+
self.patch_size = config.patch_size
|
57 |
+
self.proj = nn.Conv2d(
|
58 |
+
3,
|
59 |
+
hidden_size,
|
60 |
+
kernel_size=(self.patch_size, self.patch_size),
|
61 |
+
stride=(self.patch_size, self.patch_size),
|
62 |
+
bias=True,
|
63 |
+
)
|
64 |
+
self.norm = RMSNorm(hidden_size, eps=1e-05)
|
65 |
+
self.embed_dim = hidden_size
|
66 |
+
|
67 |
+
def forward(self, pixel_values: torch.Tensor):
|
68 |
+
_, _, H, W = pixel_values.shape
|
69 |
+
tokens = self.norm(self.proj(pixel_values).flatten(2).transpose(1, 2))
|
70 |
+
pos_embed = get_sincos_pos_embed(
|
71 |
+
H // self.patch_size, W // self.patch_size, embed_dim=self.embed_dim, device=tokens.device
|
72 |
+
)
|
73 |
+
tokens = tokens + pos_embed.to(tokens.device)
|
74 |
+
return tokens
|
75 |
+
|
76 |
+
|
77 |
+
class AIMv2PatchEmbed(nn.Module):
|
78 |
+
def __init__(self, config: VoRAConfig):
|
79 |
+
super().__init__()
|
80 |
+
self.proj = nn.Conv2d(
|
81 |
+
3,
|
82 |
+
config.vision_embedding_intermediate_size,
|
83 |
+
kernel_size=(config.patch_size, config.patch_size),
|
84 |
+
stride=(config.patch_size, config.patch_size),
|
85 |
+
)
|
86 |
+
self.norm = RMSNorm(config.vision_embedding_intermediate_size, eps=config.rms_norm_eps)
|
87 |
+
|
88 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
89 |
+
x = self.proj(x).flatten(2).transpose(1, 2)
|
90 |
+
x = self.norm(x)
|
91 |
+
return x
|
92 |
+
|
93 |
+
|
94 |
+
class AIMv2ViTPreprocessor(nn.Module):
|
95 |
+
def __init__(self,
|
96 |
+
config: VoRAConfig = None,
|
97 |
+
hidden_size: int = 4096,
|
98 |
+
):
|
99 |
+
super().__init__()
|
100 |
+
num_patches = (config.image_size // config.patch_size) ** 2
|
101 |
+
self.config = config
|
102 |
+
|
103 |
+
self.patchifier = AIMv2PatchEmbed(config)
|
104 |
+
self.pos_embed = nn.Parameter(torch.zeros((1, num_patches, config.vision_embedding_intermediate_size)))
|
105 |
+
self.out_proj = nn.Linear(config.vision_embedding_intermediate_size, hidden_size, bias=False)
|
106 |
+
|
107 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
108 |
+
B, C, H, W = x.shape
|
109 |
+
h_token = H // self.config.patch_size
|
110 |
+
w_token = W // self.config.patch_size
|
111 |
+
tokens = self.patchifier(x)
|
112 |
+
_, N, _ = tokens.shape
|
113 |
+
pos_embed = self.pos_embed.to(tokens.device)
|
114 |
+
|
115 |
+
if N <= pos_embed.size(1):
|
116 |
+
# 如果 N 小于或等于 num_patches,直接相加
|
117 |
+
tokens = tokens + pos_embed[:, :N]
|
118 |
+
else:
|
119 |
+
# 如果 N 大于 num_patches,使用双线性插值
|
120 |
+
# 将 pos_embed 调整为 (1, num_patches, hidden_size) 的形状
|
121 |
+
pos_embed = pos_embed.view(1, int(pos_embed.size(1)**0.5), int(pos_embed.size(1)**0.5), -1).permute(0, 3, 1, 2)
|
122 |
+
# 使用双线性插值调整大小
|
123 |
+
pos_embed = F.interpolate(pos_embed, size=(h_token, w_token), mode='bilinear', align_corners=False).permute(0, 2, 3, 1)
|
124 |
+
# 重塑为 (1, N, hidden_size) 形状
|
125 |
+
pos_embed = pos_embed.view(1, N, pos_embed.size(-1))
|
126 |
+
tokens = tokens + pos_embed
|
127 |
+
|
128 |
+
return self.out_proj(tokens)
|
129 |
+
|
130 |
+
|
131 |
+
def build_vision_embedding(config: VoRAConfig, hidden_size):
|
132 |
+
if config.vision_embedding_type == "AIMv2":
|
133 |
+
return AIMv2ViTPreprocessor(config, hidden_size)
|
134 |
+
return VisionEmbedding(config, hidden_size)
|
vocab.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
vora_generation_utils.py
ADDED
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Any, Dict, Optional
|
2 |
+
|
3 |
+
import torch
|
4 |
+
from transformers import GenerationMixin
|
5 |
+
from transformers.cache_utils import Cache
|
6 |
+
from transformers.utils import ModelOutput
|
7 |
+
|
8 |
+
|
9 |
+
class VoraGenerationMixin(GenerationMixin):
|
10 |
+
|
11 |
+
def prepare_inputs_for_generation(
|
12 |
+
self,
|
13 |
+
input_ids: torch.LongTensor,
|
14 |
+
past_key_values: Optional[Cache] = None,
|
15 |
+
attention_mask: Optional[torch.LongTensor] = None,
|
16 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
17 |
+
cache_position: Optional[torch.LongTensor] = None,
|
18 |
+
**kwargs,
|
19 |
+
):
|
20 |
+
if attention_mask is not None and attention_mask.ndim == 4:
|
21 |
+
attention_mask_2d = (attention_mask[:, 0, :, :] == 0).any(dim=1).long().to(attention_mask.device)
|
22 |
+
model_input = super().prepare_inputs_for_generation(
|
23 |
+
input_ids,
|
24 |
+
past_key_values=past_key_values,
|
25 |
+
attention_mask=attention_mask_2d,
|
26 |
+
inputs_embeds=inputs_embeds,
|
27 |
+
cache_position=cache_position,
|
28 |
+
**kwargs,
|
29 |
+
)
|
30 |
+
model_input['attention_mask'] = attention_mask
|
31 |
+
return model_input
|
32 |
+
else:
|
33 |
+
return super().prepare_inputs_for_generation(
|
34 |
+
input_ids,
|
35 |
+
past_key_values=past_key_values,
|
36 |
+
attention_mask=attention_mask,
|
37 |
+
inputs_embeds=inputs_embeds,
|
38 |
+
cache_position=cache_position,
|
39 |
+
**kwargs,
|
40 |
+
)
|
41 |
+
|
42 |
+
def _update_model_kwargs_for_generation(
|
43 |
+
self,
|
44 |
+
outputs: ModelOutput,
|
45 |
+
model_kwargs: Dict[str, Any],
|
46 |
+
is_encoder_decoder: bool = False,
|
47 |
+
num_new_tokens: int = 1,
|
48 |
+
) -> Dict[str, Any]:
|
49 |
+
if "attention_mask" in model_kwargs and model_kwargs["attention_mask"].ndim == 4:
|
50 |
+
attention_mask = model_kwargs.pop("attention_mask")
|
51 |
+
model_kwargs = super()._update_model_kwargs_for_generation(
|
52 |
+
outputs, model_kwargs, is_encoder_decoder=is_encoder_decoder, num_new_tokens=num_new_tokens
|
53 |
+
)
|
54 |
+
bs, _, seq_len, tgt_len = attention_mask.shape
|
55 |
+
dtype = attention_mask.dtype
|
56 |
+
min_dtype = torch.finfo(dtype).min
|
57 |
+
new_col = attention_mask.new_zeros((bs, 1, seq_len, 1)).fill_(min_dtype)
|
58 |
+
new_row = attention_mask.new_zeros((bs, 1, 1, tgt_len + 1))
|
59 |
+
model_kwargs["attention_mask"] = torch.cat([
|
60 |
+
torch.cat([attention_mask, new_col], dim=-1),
|
61 |
+
new_row
|
62 |
+
], dim=2)
|
63 |
+
return model_kwargs
|
64 |
+
else:
|
65 |
+
return super()._update_model_kwargs_for_generation(
|
66 |
+
outputs, model_kwargs, is_encoder_decoder=is_encoder_decoder, num_new_tokens=num_new_tokens
|
67 |
+
)
|
68 |
+
|
69 |
+
|
70 |
+
def custom_prepare_4d_causal_attention_mask_with_cache_position(
|
71 |
+
attention_mask: torch.Tensor,
|
72 |
+
sequence_length: int,
|
73 |
+
target_length: int,
|
74 |
+
dtype: torch.dtype,
|
75 |
+
device: torch.device,
|
76 |
+
cache_position: torch.Tensor,
|
77 |
+
batch_size: int,
|
78 |
+
**kwargs,
|
79 |
+
):
|
80 |
+
if attention_mask is not None and attention_mask.dim() == 4:
|
81 |
+
# In this case we assume that the mask comes already in inverted form and requires no inversion or slicing.
|
82 |
+
causal_mask = attention_mask[:, :, -sequence_length:, -target_length:]
|
83 |
+
else:
|
84 |
+
min_dtype = torch.finfo(dtype).min
|
85 |
+
causal_mask = torch.full(
|
86 |
+
(sequence_length, target_length), fill_value=min_dtype, dtype=dtype, device=device
|
87 |
+
)
|
88 |
+
if sequence_length != 1:
|
89 |
+
causal_mask = torch.triu(causal_mask, diagonal=1)
|
90 |
+
causal_mask *= torch.arange(target_length, device=device) > cache_position.reshape(-1, 1)
|
91 |
+
causal_mask = causal_mask[None, None, :, :].expand(batch_size, 1, -1, -1)
|
92 |
+
if attention_mask is not None:
|
93 |
+
causal_mask = causal_mask.clone() # copy to contiguous memory for in-place edit
|
94 |
+
mask_length = attention_mask.shape[-1]
|
95 |
+
padding_mask = causal_mask[:, :, :, :mask_length] + attention_mask[:, None, None, :]
|
96 |
+
padding_mask = padding_mask == 0
|
97 |
+
causal_mask[:, :, :, :mask_length] = causal_mask[:, :, :, :mask_length].masked_fill(
|
98 |
+
padding_mask, min_dtype
|
99 |
+
)
|
100 |
+
|
101 |
+
return causal_mask
|