Upload folder using huggingface_hub
Browse files- README.md +112 -3
- adapters.py +61 -0
- added_tokens.json +24 -0
- config.json +114 -0
- configuration.json +1 -0
- configuration_FlashVLDynamic.py +26 -0
- configuration_aimv2.py +62 -0
- generation_config.json +7 -0
- merges.txt +0 -0
- mm_constants.py +7 -0
- model-00001-of-00002.safetensors +3 -0
- model-00002-of-00002.safetensors +3 -0
- model.safetensors.index.json +527 -0
- modeling_FlashVLDynamic.py +392 -0
- modeling_aimv2.py +192 -0
- preprocessor_config.json +27 -0
- processing_FlashVL.py +19 -0
- special_tokens_map.json +31 -0
- tokenizer.json +0 -0
- tokenizer_config.json +207 -0
- utils_data.py +185 -0
- vocab.json +0 -0
README.md
CHANGED
@@ -1,3 +1,112 @@
|
|
1 |
-
---
|
2 |
-
license: apache-2.0
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
datasets:
|
4 |
+
- lmms-lab/LLaVA-OneVision-Data
|
5 |
+
- BAAI/Infinity-MM
|
6 |
+
language:
|
7 |
+
- en
|
8 |
+
- zh
|
9 |
+
base_model:
|
10 |
+
- apple/aimv2-huge-patch14-448
|
11 |
+
- Qwen/Qwen2-1.5B-Instruct
|
12 |
+
pipeline_tag: image-text-to-text
|
13 |
+
library_name: transformers
|
14 |
+
---
|
15 |
+
|
16 |
+
# FlashVL-2B-Dynamic
|
17 |
+
[\[📜 FlashVL\]](https://www.arxiv.org/abs/2505.09498)
|
18 |
+
|
19 |
+

|
20 |
+
|
21 |
+
## Introduction
|
22 |
+
|
23 |
+
We are excited to introduce **FlashVL**, a novel approach to optimizing Vision-Language Models (VLMs) for real-time applications, targeting ultra-low latency and high throughput without sacrificing accuracy. Leveraging advanced architectural enhancements and efficient computational strategies, Flash-VL 2B is designed to maximize throughput by reducing processing time while maintaining competitive performance across multiple vision-language benchmarks. Our approach includes tailored architectural choices, token compression mechanisms, data curation, training schemes, and a novel image processing technique called implicit semantic stitching that effectively balances computational load and model performance. Through extensive evaluations on 11 standard VLM benchmarks, we demonstrate that Flash-VL 2B achieves state-of-the-art results in both speed and accuracy, making it a promising solution for deployment in resource-constrained environments and large-scale real-time applications.
|
24 |
+
|
25 |
+
|
26 |
+
### Environment Setup
|
27 |
+
|
28 |
+
```bash
|
29 |
+
pip install torch==2.1.2
|
30 |
+
pip install transformers==4.50.0.dev0
|
31 |
+
```
|
32 |
+
|
33 |
+
|
34 |
+
### How to use it?
|
35 |
+
|
36 |
+
```python
|
37 |
+
import torch
|
38 |
+
from PIL import Image
|
39 |
+
import requests
|
40 |
+
from io import BytesIO
|
41 |
+
from transformers import AutoModel, AutoTokenizer, CLIPImageProcessor
|
42 |
+
|
43 |
+
model_path = "FlashVL/FlashVL-2B-Dynamic"
|
44 |
+
model = AutoModel.from_pretrained(model_path, torch_dtype=torch.bfloat16,trust_remote_code=True,device_map='cuda')
|
45 |
+
model.tokenizer = AutoTokenizer.from_pretrained(model_path,device_map='cuda')
|
46 |
+
model.im_trans = CLIPImageProcessor.from_pretrained(model_path)
|
47 |
+
|
48 |
+
# single-image single-round conversation (单图单轮对话)
|
49 |
+
image_url ="https://s3plus.meituan.net/automl-datasets/mlm/0516.png"
|
50 |
+
response = requests.get(image_url)
|
51 |
+
image_data = BytesIO(response.content)
|
52 |
+
pil_image = Image.open(image_data).convert('RGB')
|
53 |
+
messages = [{'role': 'user', 'content': "生成图中菜品的菜谱"}] # answer: EXTRA
|
54 |
+
answer = model.chat(pil_image, messages, do_sample=False, max_new_tokens=256)
|
55 |
+
print(answer)
|
56 |
+
|
57 |
+
# single-image multi-round conversation (单图多轮对话)
|
58 |
+
messages = [
|
59 |
+
{'role': 'user', 'content': '这是什么'},
|
60 |
+
{"role": "assistant", "content": '这是一道看起来像是银耳莲子汤的甜品。\
|
61 |
+
银耳是一种常见的食材,通常用于制作甜品和汤品,具有软糯的口感和清润的口感。莲 \
|
62 |
+
子是莲子的干燥部分,常用于中医和食疗中,具有补脾止泻的功效。图片中还可以看到 \
|
63 |
+
一些枸杞和核桃,枸杞富含维生素和抗氧化物质,核桃则提供丰富的蛋白质和健康脂肪。 \
|
64 |
+
整体来看,这道甜品不仅美味,还具有一定的营养价值。'},
|
65 |
+
{'role': 'user', 'content': '对图中菜品卡路里分析'}
|
66 |
+
]
|
67 |
+
answer = model.chat(pil_image, messages, do_sample=False, max_new_tokens=512)
|
68 |
+
print(answer)
|
69 |
+
|
70 |
+
# pure-text single-round conversation (纯文本对话)
|
71 |
+
messages = [{'role': 'user', 'content': "who are you"}]
|
72 |
+
answer = model.chat(None, messages, do_sample=False, max_new_tokens=256)
|
73 |
+
print(answer)
|
74 |
+
|
75 |
+
```
|
76 |
+
|
77 |
+
### Evaluation
|
78 |
+
|
79 |
+
| Benchmark | Qwen2-VL-2B | Aquila-VL-2B | InternVL2.5-2B | Flash-VL-2B<sub>s<sub> | Flash-VL-2B<sub>d<sub> | Flash-VL-2B<sub>d-ISS<sub> |
|
80 |
+
| :-------------: | :-------------: | :-------------: | :-------------: |:-------------: |:-------------: |:-------------: |
|
81 |
+
| MMMU<sub>val<sub> | 41.9 | 44.4 | 41.8 | 43.6 | 42.9 | 42.9 |
|
82 |
+
| MMBench<sup>en<sup> | 74.9 | 78.6 | 74.7 | 78.4 | 78.4 | 79.1 |
|
83 |
+
| MMBench<sup>cn<sup> | 73.5 | 76.3 | 71.6 | 74.7 | 74.9 | 76.7 |
|
84 |
+
| MMStar | 48.0 | 54.9 | 54.1 | 53.8 | 54.4 | 54.1 |
|
85 |
+
| MathVista<sub>testmini<sub> | 43.0 | 59.4 | 50.9 | 59.3 | 58.1 | 61.5 |
|
86 |
+
| AI2D<sub>test<sub> | 74.1 | 75.0 | 75.1 | 74.2 | 74.1 | 74.4 |
|
87 |
+
| MMVet | 49.5 | 40.9 | 61.7 | 47.3 | 52.7 | 50.7 |
|
88 |
+
| HallusionBench | 39.2 | 38.5 | 42.7 | 43.5 | 45.5 | 49.0 |
|
89 |
+
| OCRBench | 794 | 773 | 800 | 764 | 831 | 843 |
|
90 |
+
| MME | 1872 | 1813 | 2091 | 1715 | 1866 | 1850 |
|
91 |
+
| SEEDBench | 71.5 | 78.9 | 73.2 | 73.6 | 73.6 | 74.5 |
|
92 |
+
| Average | 60.2 | 62.6 | 63.6 | 62.4 | 64.0 | 64.8 |
|
93 |
+
|
94 |
+
|
95 |
+
We use [VLMEvalKit](https://github.com/open-compass/VLMEvalKit) to evaluate FlashVL-2B-Static.
|
96 |
+
|
97 |
+
|
98 |
+
|
99 |
+
## Citation
|
100 |
+
If you find this project useful in your research, please consider citing:
|
101 |
+
|
102 |
+
```BibTeX
|
103 |
+
@misc{zhang2025flashvl2boptimizingvisionlanguage,
|
104 |
+
title={Flash-VL 2B: Optimizing Vision-Language Model Performance for Ultra-Low Latency and High Throughput},
|
105 |
+
author={Bo Zhang and Shuo Li and Runhe Tian and Yang Yang and Jixin Tang and Jinhao Zhou and Lin Ma},
|
106 |
+
year={2025},
|
107 |
+
eprint={2505.09498},
|
108 |
+
archivePrefix={arXiv},
|
109 |
+
primaryClass={cs.CV},
|
110 |
+
url={https://arxiv.org/abs/2505.09498},
|
111 |
+
}
|
112 |
+
```
|
adapters.py
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import math
|
3 |
+
import torch
|
4 |
+
from torch import nn
|
5 |
+
from functools import partial
|
6 |
+
import torch.nn.functional as F
|
7 |
+
|
8 |
+
|
9 |
+
class Adapter_Template(nn.Module):
|
10 |
+
def __init__(self, config):
|
11 |
+
super().__init__()
|
12 |
+
self.gradient_checkpointing = False
|
13 |
+
|
14 |
+
def freeze_module(self, module):
|
15 |
+
for p in module.parameters():
|
16 |
+
p.requires_grad = False
|
17 |
+
|
18 |
+
def forward(self, inputs, add_start_end=True):
|
19 |
+
input_ids, hidden_states, targets, attn_mask, loss_mask = inputs
|
20 |
+
image_features = self.forward_adapter_modules(hidden_states)
|
21 |
+
return (input_ids, image_features, targets, attn_mask, loss_mask)
|
22 |
+
|
23 |
+
|
24 |
+
class Adapter_AIM(Adapter_Template):
|
25 |
+
|
26 |
+
def __init__(self, config):
|
27 |
+
super().__init__(config)
|
28 |
+
|
29 |
+
self.p0 = nn.Sequential(
|
30 |
+
nn.LayerNorm(config.vision_config.hidden_size*4),
|
31 |
+
nn.Linear(config.vision_config.hidden_size*4, config.intermediate_size),
|
32 |
+
nn.GELU(),
|
33 |
+
nn.Linear(config.intermediate_size, config.intermediate_size),
|
34 |
+
nn.GELU(),
|
35 |
+
)
|
36 |
+
self.proj = nn.Linear(config.intermediate_size, config.vision_config.proj_output_dim)
|
37 |
+
|
38 |
+
def freeze(self):
|
39 |
+
self.freeze_module(self.p0)
|
40 |
+
self.freeze_module(self.proj)
|
41 |
+
|
42 |
+
def pixel_shuffle(self, x, scale_factor=0.5):
|
43 |
+
n, w, h, c = x.size()
|
44 |
+
# N, W, H, C --> N, W, H * scale, C // scale
|
45 |
+
x = x.reshape(n, w, int(h * scale_factor), int(c / scale_factor))
|
46 |
+
# N, W, H * scale, C // scale --> N, H * scale, W, C // scale
|
47 |
+
x = x.permute(0, 2, 1, 3).contiguous()
|
48 |
+
# N, H * scale, W, C // scale --> N, H * scale, W * scale, C // (scale ** 2)
|
49 |
+
x = x.view(n, int(h * scale_factor), int(w * scale_factor),
|
50 |
+
int(c / (scale_factor * scale_factor)))
|
51 |
+
return x
|
52 |
+
|
53 |
+
def forward_adapter_modules(self, hidden_states):
|
54 |
+
h = w = int(hidden_states.shape[1] ** 0.5)
|
55 |
+
hidden_states = hidden_states.reshape(hidden_states.shape[0], h, w, -1)
|
56 |
+
hidden_states = self.pixel_shuffle(hidden_states, scale_factor=0.5)
|
57 |
+
hidden_states = hidden_states.reshape(hidden_states.shape[0], -1, hidden_states.shape[-1])
|
58 |
+
|
59 |
+
hidden_states = self.proj(self.p0(hidden_states))
|
60 |
+
|
61 |
+
return hidden_states
|
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 |
+
}
|
config.json
ADDED
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "/mnt/dolphinfs/ssd_pool/docker/user/hadoop-mlm/lishuo/repo/fine_tuning_package/model/",
|
3 |
+
"architectures": [
|
4 |
+
"FlashVLDynamic"
|
5 |
+
],
|
6 |
+
"auto_map": {
|
7 |
+
"AutoConfig": "configuration_FlashVLDynamic.FlashVLDynamicConfig",
|
8 |
+
"AutoModel": "modeling_FlashVLDynamic.FlashVLDynamic"
|
9 |
+
},
|
10 |
+
"intermediate_size": 7168,
|
11 |
+
"image_token_num": 256,
|
12 |
+
"image_split": 4,
|
13 |
+
"llm_config":{
|
14 |
+
"attention_dropout": 0.0,
|
15 |
+
"bos_token_id": 151643,
|
16 |
+
"eos_token_id": 151645,
|
17 |
+
"hidden_act": "silu",
|
18 |
+
"hidden_size": 1536,
|
19 |
+
"initializer_range": 0.02,
|
20 |
+
"intermediate_size": 8960,
|
21 |
+
"max_position_embeddings": 32768,
|
22 |
+
"max_window_layers": 21,
|
23 |
+
"model_type": "qwen2",
|
24 |
+
"num_attention_heads": 12,
|
25 |
+
"num_hidden_layers": 28,
|
26 |
+
"num_key_value_heads": 2,
|
27 |
+
"rms_norm_eps": 1e-06,
|
28 |
+
"rope_scaling": null,
|
29 |
+
"rope_theta": 1000000.0,
|
30 |
+
"sliding_window": null,
|
31 |
+
"tie_word_embeddings": true,
|
32 |
+
"torch_dtype": "bfloat16",
|
33 |
+
"transformers_version": "4.45.0.dev0",
|
34 |
+
"use_cache": true,
|
35 |
+
"use_sliding_window": false,
|
36 |
+
"vocab_size": 151936
|
37 |
+
},
|
38 |
+
"vision_config": {
|
39 |
+
"_name_or_path": "",
|
40 |
+
"add_cross_attention": false,
|
41 |
+
"architectures": null,
|
42 |
+
"attention_dropout": 0.0,
|
43 |
+
"bad_words_ids": null,
|
44 |
+
"begin_suppress_tokens": null,
|
45 |
+
"bos_token_id": null,
|
46 |
+
"chunk_size_feed_forward": 0,
|
47 |
+
"cross_attention_hidden_size": null,
|
48 |
+
"decoder_start_token_id": null,
|
49 |
+
"diversity_penalty": 0.0,
|
50 |
+
"do_sample": false,
|
51 |
+
"early_stopping": false,
|
52 |
+
"encoder_no_repeat_ngram_size": 0,
|
53 |
+
"eos_token_id": null,
|
54 |
+
"exponential_decay_length_penalty": null,
|
55 |
+
"finetuning_task": null,
|
56 |
+
"forced_bos_token_id": null,
|
57 |
+
"forced_eos_token_id": null,
|
58 |
+
"hidden_size": 1536,
|
59 |
+
"id2label": {
|
60 |
+
"0": "LABEL_0",
|
61 |
+
"1": "LABEL_1"
|
62 |
+
},
|
63 |
+
"image_size": 448,
|
64 |
+
"intermediate_size": 4096,
|
65 |
+
"is_decoder": false,
|
66 |
+
"is_encoder_decoder": false,
|
67 |
+
"label2id": {
|
68 |
+
"LABEL_0": 0,
|
69 |
+
"LABEL_1": 1
|
70 |
+
},
|
71 |
+
"length_penalty": 1.0,
|
72 |
+
"max_length": 20,
|
73 |
+
"min_length": 0,
|
74 |
+
"model_type": "aimv2",
|
75 |
+
"no_repeat_ngram_size": 0,
|
76 |
+
"num_attention_heads": 12,
|
77 |
+
"num_beam_groups": 1,
|
78 |
+
"num_beams": 1,
|
79 |
+
"num_channels": 3,
|
80 |
+
"num_hidden_layers": 24,
|
81 |
+
"num_return_sequences": 1,
|
82 |
+
"output_attentions": false,
|
83 |
+
"output_hidden_states": false,
|
84 |
+
"output_scores": false,
|
85 |
+
"pad_token_id": null,
|
86 |
+
"patch_size": 14,
|
87 |
+
"prefix": null,
|
88 |
+
"problem_type": null,
|
89 |
+
"proj_output_dim": 1536,
|
90 |
+
"projection_dropout": 0.0,
|
91 |
+
"pruned_heads": {},
|
92 |
+
"qkv_bias": false,
|
93 |
+
"remove_invalid_values": false,
|
94 |
+
"repetition_penalty": 1.0,
|
95 |
+
"return_dict": true,
|
96 |
+
"return_dict_in_generate": false,
|
97 |
+
"rms_norm_eps": 1e-05,
|
98 |
+
"sep_token_id": null,
|
99 |
+
"suppress_tokens": null,
|
100 |
+
"task_specific_params": null,
|
101 |
+
"temperature": 1.0,
|
102 |
+
"tf_legacy_loss": false,
|
103 |
+
"tie_encoder_decoder": false,
|
104 |
+
"tie_word_embeddings": true,
|
105 |
+
"tokenizer_class": null,
|
106 |
+
"top_k": 50,
|
107 |
+
"top_p": 1.0,
|
108 |
+
"torch_dtype": null,
|
109 |
+
"torchscript": false,
|
110 |
+
"typical_p": 1.0,
|
111 |
+
"use_bfloat16": false,
|
112 |
+
"use_bias": false
|
113 |
+
}
|
114 |
+
}
|
configuration.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{}
|
configuration_FlashVLDynamic.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import copy
|
2 |
+
import transformers
|
3 |
+
from transformers import PretrainedConfig, Qwen2Config
|
4 |
+
from .configuration_aimv2 import AIMv2Config
|
5 |
+
|
6 |
+
class FlashVLDynamicConfig(PretrainedConfig):
|
7 |
+
model_type = 'FlashVLDynamicConfig'
|
8 |
+
is_composition = True
|
9 |
+
|
10 |
+
def __init__(
|
11 |
+
self,
|
12 |
+
vision_config,
|
13 |
+
llm_config,
|
14 |
+
**kwargs
|
15 |
+
):
|
16 |
+
super().__init__(**kwargs)
|
17 |
+
self.vision_config = AIMv2Config(**vision_config)
|
18 |
+
self.llm_config = Qwen2Config(**llm_config)
|
19 |
+
|
20 |
+
def to_dict(self):
|
21 |
+
|
22 |
+
output = copy.deepcopy(self.__dict__)
|
23 |
+
output['vision_config'] = self.vision_config.to_dict()
|
24 |
+
output['llm_config'] = self.llm_config.to_dict()
|
25 |
+
|
26 |
+
return output
|
configuration_aimv2.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Any
|
2 |
+
|
3 |
+
from transformers.configuration_utils import PretrainedConfig
|
4 |
+
|
5 |
+
__all__ = ["AIMv2Config"]
|
6 |
+
|
7 |
+
|
8 |
+
class AIMv2Config(PretrainedConfig):
|
9 |
+
"""This is the configuration class to store the configuration of an [`AIMv2Model`].
|
10 |
+
|
11 |
+
Instantiating a configuration with the defaults will yield a similar configuration
|
12 |
+
to that of the [apple/aimv2-large-patch14-224](https://huggingface.co/apple/aimv2-large-patch14-224).
|
13 |
+
|
14 |
+
Args:
|
15 |
+
hidden_size: Dimension of the hidden representations.
|
16 |
+
intermediate_size: Dimension of the SwiGLU representations.
|
17 |
+
num_hidden_layers: Number of hidden layers in the Transformer.
|
18 |
+
num_attention_heads: Number of attention heads for each attention layer
|
19 |
+
in the Transformer.
|
20 |
+
num_channels: Number of input channels.
|
21 |
+
image_size: Image size.
|
22 |
+
patch_size: Patch size.
|
23 |
+
rms_norm_eps: Epsilon value used for the RMS normalization layer.
|
24 |
+
attention_dropout: Dropout ratio for attention probabilities.
|
25 |
+
projection_dropout: Dropout ratio for the projection layer after the attention.
|
26 |
+
qkv_bias: Whether to add a bias to the queries, keys and values.
|
27 |
+
use_bias: Whether to add a bias in the feed-forward and projection layers.
|
28 |
+
kwargs: Keyword arguments for the [`PretrainedConfig`].
|
29 |
+
"""
|
30 |
+
|
31 |
+
model_type: str = "aimv2"
|
32 |
+
|
33 |
+
def __init__(
|
34 |
+
self,
|
35 |
+
hidden_size: int = 1024,
|
36 |
+
intermediate_size: int = 2816,
|
37 |
+
num_hidden_layers: int = 24,
|
38 |
+
num_attention_heads: int = 8,
|
39 |
+
num_channels: int = 3,
|
40 |
+
image_size: int = 224,
|
41 |
+
patch_size: int = 14,
|
42 |
+
rms_norm_eps: float = 1e-5,
|
43 |
+
attention_dropout: float = 0.0,
|
44 |
+
projection_dropout: float = 0.0,
|
45 |
+
qkv_bias: bool = False,
|
46 |
+
use_bias: bool = False,
|
47 |
+
**kwargs: Any,
|
48 |
+
):
|
49 |
+
super().__init__(**kwargs)
|
50 |
+
self.hidden_size = hidden_size
|
51 |
+
self.intermediate_size = intermediate_size
|
52 |
+
self.num_hidden_layers = num_hidden_layers
|
53 |
+
self.num_attention_heads = num_attention_heads
|
54 |
+
self.num_channels = num_channels
|
55 |
+
self.patch_size = patch_size
|
56 |
+
self.image_size = image_size
|
57 |
+
self.attention_dropout = attention_dropout
|
58 |
+
self.rms_norm_eps = rms_norm_eps
|
59 |
+
|
60 |
+
self.projection_dropout = projection_dropout
|
61 |
+
self.qkv_bias = qkv_bias
|
62 |
+
self.use_bias = use_bias
|
generation_config.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bos_token_id": 151643,
|
3 |
+
"eos_token_id": 151645,
|
4 |
+
"max_new_tokens": 2048,
|
5 |
+
"pad_token_id": 151643,
|
6 |
+
"transformers_version": "4.45.0.dev0"
|
7 |
+
}
|
merges.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
mm_constants.py
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Model Constants
|
2 |
+
IGNORE_INDEX = -100
|
3 |
+
IMAGE_TOKEN_INDEX = -200
|
4 |
+
IMAGE_PAD_TOKEN_INDEX = -201
|
5 |
+
|
6 |
+
DEFAULT_SLICE_START_TOKEN = "[PLACEHOLDER_0]"
|
7 |
+
DEFAULT_SLICE_END_TOKEN = "[PLACEHOLDER_1]"
|
model-00001-of-00002.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9f9d37145fe62c36bb43d02b3e1fba703465d4241f3c9545ded3c96291873893
|
3 |
+
size 4918323328
|
model-00002-of-00002.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ec806b72857f9a0db631fe56bddcbb7b6493d9cd616e25428af426533a4aa240
|
3 |
+
size 212893224
|
model.safetensors.index.json
ADDED
@@ -0,0 +1,527 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"metadata": {
|
3 |
+
"total_size": 5131156480
|
4 |
+
},
|
5 |
+
"weight_map": {
|
6 |
+
"adp.p0.0.bias": "model-00001-of-00002.safetensors",
|
7 |
+
"adp.p0.0.weight": "model-00001-of-00002.safetensors",
|
8 |
+
"adp.p0.1.bias": "model-00002-of-00002.safetensors",
|
9 |
+
"adp.p0.1.weight": "model-00002-of-00002.safetensors",
|
10 |
+
"adp.p0.3.bias": "model-00002-of-00002.safetensors",
|
11 |
+
"adp.p0.3.weight": "model-00002-of-00002.safetensors",
|
12 |
+
"adp.proj.bias": "model-00002-of-00002.safetensors",
|
13 |
+
"adp.proj.weight": "model-00002-of-00002.safetensors",
|
14 |
+
"llm.lm_head.weight": "model-00001-of-00002.safetensors",
|
15 |
+
"llm.model.embed_tokens.weight": "model-00001-of-00002.safetensors",
|
16 |
+
"llm.model.layers.0.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
17 |
+
"llm.model.layers.0.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
18 |
+
"llm.model.layers.0.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
19 |
+
"llm.model.layers.0.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
20 |
+
"llm.model.layers.0.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
21 |
+
"llm.model.layers.0.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
22 |
+
"llm.model.layers.0.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
23 |
+
"llm.model.layers.0.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
24 |
+
"llm.model.layers.0.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
25 |
+
"llm.model.layers.0.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
26 |
+
"llm.model.layers.0.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
27 |
+
"llm.model.layers.0.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
28 |
+
"llm.model.layers.1.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
29 |
+
"llm.model.layers.1.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
30 |
+
"llm.model.layers.1.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
31 |
+
"llm.model.layers.1.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
32 |
+
"llm.model.layers.1.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
33 |
+
"llm.model.layers.1.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
34 |
+
"llm.model.layers.1.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
35 |
+
"llm.model.layers.1.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
36 |
+
"llm.model.layers.1.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
37 |
+
"llm.model.layers.1.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
38 |
+
"llm.model.layers.1.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
39 |
+
"llm.model.layers.1.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
40 |
+
"llm.model.layers.10.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
41 |
+
"llm.model.layers.10.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
42 |
+
"llm.model.layers.10.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
43 |
+
"llm.model.layers.10.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
44 |
+
"llm.model.layers.10.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
45 |
+
"llm.model.layers.10.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
46 |
+
"llm.model.layers.10.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
47 |
+
"llm.model.layers.10.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
48 |
+
"llm.model.layers.10.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
49 |
+
"llm.model.layers.10.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
50 |
+
"llm.model.layers.10.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
51 |
+
"llm.model.layers.10.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
52 |
+
"llm.model.layers.11.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
53 |
+
"llm.model.layers.11.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
54 |
+
"llm.model.layers.11.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
55 |
+
"llm.model.layers.11.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
56 |
+
"llm.model.layers.11.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
57 |
+
"llm.model.layers.11.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
58 |
+
"llm.model.layers.11.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
59 |
+
"llm.model.layers.11.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
60 |
+
"llm.model.layers.11.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
61 |
+
"llm.model.layers.11.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
62 |
+
"llm.model.layers.11.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
63 |
+
"llm.model.layers.11.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
64 |
+
"llm.model.layers.12.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
65 |
+
"llm.model.layers.12.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
66 |
+
"llm.model.layers.12.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
67 |
+
"llm.model.layers.12.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
68 |
+
"llm.model.layers.12.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
69 |
+
"llm.model.layers.12.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
70 |
+
"llm.model.layers.12.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
71 |
+
"llm.model.layers.12.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
72 |
+
"llm.model.layers.12.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
73 |
+
"llm.model.layers.12.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
74 |
+
"llm.model.layers.12.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
75 |
+
"llm.model.layers.12.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
76 |
+
"llm.model.layers.13.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
77 |
+
"llm.model.layers.13.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
78 |
+
"llm.model.layers.13.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
79 |
+
"llm.model.layers.13.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
80 |
+
"llm.model.layers.13.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
81 |
+
"llm.model.layers.13.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
82 |
+
"llm.model.layers.13.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
83 |
+
"llm.model.layers.13.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
84 |
+
"llm.model.layers.13.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
85 |
+
"llm.model.layers.13.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
86 |
+
"llm.model.layers.13.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
87 |
+
"llm.model.layers.13.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
88 |
+
"llm.model.layers.14.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
89 |
+
"llm.model.layers.14.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
90 |
+
"llm.model.layers.14.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
91 |
+
"llm.model.layers.14.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
92 |
+
"llm.model.layers.14.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
93 |
+
"llm.model.layers.14.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
94 |
+
"llm.model.layers.14.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
95 |
+
"llm.model.layers.14.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
96 |
+
"llm.model.layers.14.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
97 |
+
"llm.model.layers.14.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
98 |
+
"llm.model.layers.14.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
99 |
+
"llm.model.layers.14.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
100 |
+
"llm.model.layers.15.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
101 |
+
"llm.model.layers.15.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
102 |
+
"llm.model.layers.15.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
103 |
+
"llm.model.layers.15.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
104 |
+
"llm.model.layers.15.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
105 |
+
"llm.model.layers.15.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
106 |
+
"llm.model.layers.15.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
107 |
+
"llm.model.layers.15.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
108 |
+
"llm.model.layers.15.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
109 |
+
"llm.model.layers.15.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
110 |
+
"llm.model.layers.15.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
111 |
+
"llm.model.layers.15.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
112 |
+
"llm.model.layers.16.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
113 |
+
"llm.model.layers.16.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
114 |
+
"llm.model.layers.16.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
115 |
+
"llm.model.layers.16.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
116 |
+
"llm.model.layers.16.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
117 |
+
"llm.model.layers.16.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
118 |
+
"llm.model.layers.16.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
119 |
+
"llm.model.layers.16.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
120 |
+
"llm.model.layers.16.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
121 |
+
"llm.model.layers.16.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
122 |
+
"llm.model.layers.16.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
123 |
+
"llm.model.layers.16.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
124 |
+
"llm.model.layers.17.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
125 |
+
"llm.model.layers.17.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
126 |
+
"llm.model.layers.17.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
127 |
+
"llm.model.layers.17.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
128 |
+
"llm.model.layers.17.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
129 |
+
"llm.model.layers.17.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
130 |
+
"llm.model.layers.17.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
131 |
+
"llm.model.layers.17.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
132 |
+
"llm.model.layers.17.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
133 |
+
"llm.model.layers.17.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
134 |
+
"llm.model.layers.17.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
135 |
+
"llm.model.layers.17.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
136 |
+
"llm.model.layers.18.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
137 |
+
"llm.model.layers.18.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
138 |
+
"llm.model.layers.18.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
139 |
+
"llm.model.layers.18.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
140 |
+
"llm.model.layers.18.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
141 |
+
"llm.model.layers.18.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
142 |
+
"llm.model.layers.18.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
143 |
+
"llm.model.layers.18.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
144 |
+
"llm.model.layers.18.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
145 |
+
"llm.model.layers.18.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
146 |
+
"llm.model.layers.18.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
147 |
+
"llm.model.layers.18.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
148 |
+
"llm.model.layers.19.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
149 |
+
"llm.model.layers.19.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
150 |
+
"llm.model.layers.19.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
151 |
+
"llm.model.layers.19.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
152 |
+
"llm.model.layers.19.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
153 |
+
"llm.model.layers.19.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
154 |
+
"llm.model.layers.19.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
155 |
+
"llm.model.layers.19.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
156 |
+
"llm.model.layers.19.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
157 |
+
"llm.model.layers.19.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
158 |
+
"llm.model.layers.19.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
159 |
+
"llm.model.layers.19.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
160 |
+
"llm.model.layers.2.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
161 |
+
"llm.model.layers.2.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
162 |
+
"llm.model.layers.2.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
163 |
+
"llm.model.layers.2.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
164 |
+
"llm.model.layers.2.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
165 |
+
"llm.model.layers.2.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
166 |
+
"llm.model.layers.2.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
167 |
+
"llm.model.layers.2.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
168 |
+
"llm.model.layers.2.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
169 |
+
"llm.model.layers.2.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
170 |
+
"llm.model.layers.2.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
171 |
+
"llm.model.layers.2.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
172 |
+
"llm.model.layers.20.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
173 |
+
"llm.model.layers.20.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
174 |
+
"llm.model.layers.20.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
175 |
+
"llm.model.layers.20.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
176 |
+
"llm.model.layers.20.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
177 |
+
"llm.model.layers.20.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
178 |
+
"llm.model.layers.20.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
179 |
+
"llm.model.layers.20.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
180 |
+
"llm.model.layers.20.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
181 |
+
"llm.model.layers.20.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
182 |
+
"llm.model.layers.20.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
183 |
+
"llm.model.layers.20.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
184 |
+
"llm.model.layers.21.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
185 |
+
"llm.model.layers.21.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
186 |
+
"llm.model.layers.21.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
187 |
+
"llm.model.layers.21.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
188 |
+
"llm.model.layers.21.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
189 |
+
"llm.model.layers.21.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
190 |
+
"llm.model.layers.21.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
191 |
+
"llm.model.layers.21.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
192 |
+
"llm.model.layers.21.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
193 |
+
"llm.model.layers.21.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
194 |
+
"llm.model.layers.21.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
195 |
+
"llm.model.layers.21.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
196 |
+
"llm.model.layers.22.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
197 |
+
"llm.model.layers.22.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
198 |
+
"llm.model.layers.22.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
199 |
+
"llm.model.layers.22.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
200 |
+
"llm.model.layers.22.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
201 |
+
"llm.model.layers.22.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
202 |
+
"llm.model.layers.22.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
203 |
+
"llm.model.layers.22.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
204 |
+
"llm.model.layers.22.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
205 |
+
"llm.model.layers.22.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
206 |
+
"llm.model.layers.22.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
207 |
+
"llm.model.layers.22.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
208 |
+
"llm.model.layers.23.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
209 |
+
"llm.model.layers.23.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
210 |
+
"llm.model.layers.23.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
211 |
+
"llm.model.layers.23.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
212 |
+
"llm.model.layers.23.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
213 |
+
"llm.model.layers.23.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
214 |
+
"llm.model.layers.23.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
215 |
+
"llm.model.layers.23.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
216 |
+
"llm.model.layers.23.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
217 |
+
"llm.model.layers.23.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
218 |
+
"llm.model.layers.23.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
219 |
+
"llm.model.layers.23.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
220 |
+
"llm.model.layers.24.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
221 |
+
"llm.model.layers.24.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
222 |
+
"llm.model.layers.24.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
223 |
+
"llm.model.layers.24.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
224 |
+
"llm.model.layers.24.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
225 |
+
"llm.model.layers.24.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
226 |
+
"llm.model.layers.24.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
227 |
+
"llm.model.layers.24.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
228 |
+
"llm.model.layers.24.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
229 |
+
"llm.model.layers.24.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
230 |
+
"llm.model.layers.24.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
231 |
+
"llm.model.layers.24.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
232 |
+
"llm.model.layers.25.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
233 |
+
"llm.model.layers.25.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
234 |
+
"llm.model.layers.25.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
235 |
+
"llm.model.layers.25.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
236 |
+
"llm.model.layers.25.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
237 |
+
"llm.model.layers.25.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
238 |
+
"llm.model.layers.25.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
239 |
+
"llm.model.layers.25.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
240 |
+
"llm.model.layers.25.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
241 |
+
"llm.model.layers.25.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
242 |
+
"llm.model.layers.25.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
243 |
+
"llm.model.layers.25.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
244 |
+
"llm.model.layers.26.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
245 |
+
"llm.model.layers.26.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
246 |
+
"llm.model.layers.26.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
247 |
+
"llm.model.layers.26.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
248 |
+
"llm.model.layers.26.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
249 |
+
"llm.model.layers.26.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
250 |
+
"llm.model.layers.26.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
251 |
+
"llm.model.layers.26.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
252 |
+
"llm.model.layers.26.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
253 |
+
"llm.model.layers.26.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
254 |
+
"llm.model.layers.26.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
255 |
+
"llm.model.layers.26.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
256 |
+
"llm.model.layers.27.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
257 |
+
"llm.model.layers.27.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
258 |
+
"llm.model.layers.27.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
259 |
+
"llm.model.layers.27.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
260 |
+
"llm.model.layers.27.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
261 |
+
"llm.model.layers.27.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
262 |
+
"llm.model.layers.27.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
263 |
+
"llm.model.layers.27.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
264 |
+
"llm.model.layers.27.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
265 |
+
"llm.model.layers.27.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
266 |
+
"llm.model.layers.27.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
267 |
+
"llm.model.layers.27.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
268 |
+
"llm.model.layers.3.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
269 |
+
"llm.model.layers.3.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
270 |
+
"llm.model.layers.3.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
271 |
+
"llm.model.layers.3.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
272 |
+
"llm.model.layers.3.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
273 |
+
"llm.model.layers.3.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
274 |
+
"llm.model.layers.3.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
275 |
+
"llm.model.layers.3.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
276 |
+
"llm.model.layers.3.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
277 |
+
"llm.model.layers.3.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
278 |
+
"llm.model.layers.3.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
279 |
+
"llm.model.layers.3.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
280 |
+
"llm.model.layers.4.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
281 |
+
"llm.model.layers.4.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
282 |
+
"llm.model.layers.4.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
283 |
+
"llm.model.layers.4.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
284 |
+
"llm.model.layers.4.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
285 |
+
"llm.model.layers.4.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
286 |
+
"llm.model.layers.4.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
287 |
+
"llm.model.layers.4.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
288 |
+
"llm.model.layers.4.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
289 |
+
"llm.model.layers.4.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
290 |
+
"llm.model.layers.4.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
291 |
+
"llm.model.layers.4.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
292 |
+
"llm.model.layers.5.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
293 |
+
"llm.model.layers.5.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
294 |
+
"llm.model.layers.5.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
295 |
+
"llm.model.layers.5.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
296 |
+
"llm.model.layers.5.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
297 |
+
"llm.model.layers.5.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
298 |
+
"llm.model.layers.5.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
299 |
+
"llm.model.layers.5.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
300 |
+
"llm.model.layers.5.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
301 |
+
"llm.model.layers.5.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
302 |
+
"llm.model.layers.5.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
303 |
+
"llm.model.layers.5.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
304 |
+
"llm.model.layers.6.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
305 |
+
"llm.model.layers.6.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
306 |
+
"llm.model.layers.6.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
307 |
+
"llm.model.layers.6.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
308 |
+
"llm.model.layers.6.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
309 |
+
"llm.model.layers.6.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
310 |
+
"llm.model.layers.6.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
311 |
+
"llm.model.layers.6.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
312 |
+
"llm.model.layers.6.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
313 |
+
"llm.model.layers.6.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
314 |
+
"llm.model.layers.6.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
315 |
+
"llm.model.layers.6.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
316 |
+
"llm.model.layers.7.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
317 |
+
"llm.model.layers.7.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
318 |
+
"llm.model.layers.7.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
319 |
+
"llm.model.layers.7.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
320 |
+
"llm.model.layers.7.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
321 |
+
"llm.model.layers.7.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
322 |
+
"llm.model.layers.7.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
323 |
+
"llm.model.layers.7.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
324 |
+
"llm.model.layers.7.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
325 |
+
"llm.model.layers.7.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
326 |
+
"llm.model.layers.7.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
327 |
+
"llm.model.layers.7.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
328 |
+
"llm.model.layers.8.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
329 |
+
"llm.model.layers.8.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
330 |
+
"llm.model.layers.8.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
331 |
+
"llm.model.layers.8.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
332 |
+
"llm.model.layers.8.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
333 |
+
"llm.model.layers.8.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
334 |
+
"llm.model.layers.8.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
335 |
+
"llm.model.layers.8.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
336 |
+
"llm.model.layers.8.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
337 |
+
"llm.model.layers.8.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
338 |
+
"llm.model.layers.8.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
339 |
+
"llm.model.layers.8.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
340 |
+
"llm.model.layers.9.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
341 |
+
"llm.model.layers.9.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
342 |
+
"llm.model.layers.9.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
343 |
+
"llm.model.layers.9.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
344 |
+
"llm.model.layers.9.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
345 |
+
"llm.model.layers.9.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
346 |
+
"llm.model.layers.9.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
347 |
+
"llm.model.layers.9.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
348 |
+
"llm.model.layers.9.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
349 |
+
"llm.model.layers.9.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
350 |
+
"llm.model.layers.9.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
351 |
+
"llm.model.layers.9.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
352 |
+
"llm.model.norm.weight": "model-00001-of-00002.safetensors",
|
353 |
+
"vit.preprocessor.patchifier.norm.weight": "model-00001-of-00002.safetensors",
|
354 |
+
"vit.preprocessor.patchifier.proj.bias": "model-00001-of-00002.safetensors",
|
355 |
+
"vit.preprocessor.patchifier.proj.weight": "model-00001-of-00002.safetensors",
|
356 |
+
"vit.preprocessor.pos_embed": "model-00001-of-00002.safetensors",
|
357 |
+
"vit.trunk.blocks.0.attn.proj.weight": "model-00001-of-00002.safetensors",
|
358 |
+
"vit.trunk.blocks.0.attn.qkv.weight": "model-00001-of-00002.safetensors",
|
359 |
+
"vit.trunk.blocks.0.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
360 |
+
"vit.trunk.blocks.0.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
361 |
+
"vit.trunk.blocks.0.mlp.fc3.weight": "model-00001-of-00002.safetensors",
|
362 |
+
"vit.trunk.blocks.0.norm_1.weight": "model-00001-of-00002.safetensors",
|
363 |
+
"vit.trunk.blocks.0.norm_2.weight": "model-00001-of-00002.safetensors",
|
364 |
+
"vit.trunk.blocks.1.attn.proj.weight": "model-00001-of-00002.safetensors",
|
365 |
+
"vit.trunk.blocks.1.attn.qkv.weight": "model-00001-of-00002.safetensors",
|
366 |
+
"vit.trunk.blocks.1.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
367 |
+
"vit.trunk.blocks.1.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
368 |
+
"vit.trunk.blocks.1.mlp.fc3.weight": "model-00001-of-00002.safetensors",
|
369 |
+
"vit.trunk.blocks.1.norm_1.weight": "model-00001-of-00002.safetensors",
|
370 |
+
"vit.trunk.blocks.1.norm_2.weight": "model-00001-of-00002.safetensors",
|
371 |
+
"vit.trunk.blocks.10.attn.proj.weight": "model-00001-of-00002.safetensors",
|
372 |
+
"vit.trunk.blocks.10.attn.qkv.weight": "model-00001-of-00002.safetensors",
|
373 |
+
"vit.trunk.blocks.10.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
374 |
+
"vit.trunk.blocks.10.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
375 |
+
"vit.trunk.blocks.10.mlp.fc3.weight": "model-00001-of-00002.safetensors",
|
376 |
+
"vit.trunk.blocks.10.norm_1.weight": "model-00001-of-00002.safetensors",
|
377 |
+
"vit.trunk.blocks.10.norm_2.weight": "model-00001-of-00002.safetensors",
|
378 |
+
"vit.trunk.blocks.11.attn.proj.weight": "model-00001-of-00002.safetensors",
|
379 |
+
"vit.trunk.blocks.11.attn.qkv.weight": "model-00001-of-00002.safetensors",
|
380 |
+
"vit.trunk.blocks.11.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
381 |
+
"vit.trunk.blocks.11.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
382 |
+
"vit.trunk.blocks.11.mlp.fc3.weight": "model-00001-of-00002.safetensors",
|
383 |
+
"vit.trunk.blocks.11.norm_1.weight": "model-00001-of-00002.safetensors",
|
384 |
+
"vit.trunk.blocks.11.norm_2.weight": "model-00001-of-00002.safetensors",
|
385 |
+
"vit.trunk.blocks.12.attn.proj.weight": "model-00001-of-00002.safetensors",
|
386 |
+
"vit.trunk.blocks.12.attn.qkv.weight": "model-00001-of-00002.safetensors",
|
387 |
+
"vit.trunk.blocks.12.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
388 |
+
"vit.trunk.blocks.12.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
389 |
+
"vit.trunk.blocks.12.mlp.fc3.weight": "model-00001-of-00002.safetensors",
|
390 |
+
"vit.trunk.blocks.12.norm_1.weight": "model-00001-of-00002.safetensors",
|
391 |
+
"vit.trunk.blocks.12.norm_2.weight": "model-00001-of-00002.safetensors",
|
392 |
+
"vit.trunk.blocks.13.attn.proj.weight": "model-00001-of-00002.safetensors",
|
393 |
+
"vit.trunk.blocks.13.attn.qkv.weight": "model-00001-of-00002.safetensors",
|
394 |
+
"vit.trunk.blocks.13.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
395 |
+
"vit.trunk.blocks.13.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
396 |
+
"vit.trunk.blocks.13.mlp.fc3.weight": "model-00001-of-00002.safetensors",
|
397 |
+
"vit.trunk.blocks.13.norm_1.weight": "model-00001-of-00002.safetensors",
|
398 |
+
"vit.trunk.blocks.13.norm_2.weight": "model-00001-of-00002.safetensors",
|
399 |
+
"vit.trunk.blocks.14.attn.proj.weight": "model-00001-of-00002.safetensors",
|
400 |
+
"vit.trunk.blocks.14.attn.qkv.weight": "model-00001-of-00002.safetensors",
|
401 |
+
"vit.trunk.blocks.14.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
402 |
+
"vit.trunk.blocks.14.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
403 |
+
"vit.trunk.blocks.14.mlp.fc3.weight": "model-00001-of-00002.safetensors",
|
404 |
+
"vit.trunk.blocks.14.norm_1.weight": "model-00001-of-00002.safetensors",
|
405 |
+
"vit.trunk.blocks.14.norm_2.weight": "model-00001-of-00002.safetensors",
|
406 |
+
"vit.trunk.blocks.15.attn.proj.weight": "model-00001-of-00002.safetensors",
|
407 |
+
"vit.trunk.blocks.15.attn.qkv.weight": "model-00001-of-00002.safetensors",
|
408 |
+
"vit.trunk.blocks.15.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
409 |
+
"vit.trunk.blocks.15.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
410 |
+
"vit.trunk.blocks.15.mlp.fc3.weight": "model-00001-of-00002.safetensors",
|
411 |
+
"vit.trunk.blocks.15.norm_1.weight": "model-00001-of-00002.safetensors",
|
412 |
+
"vit.trunk.blocks.15.norm_2.weight": "model-00001-of-00002.safetensors",
|
413 |
+
"vit.trunk.blocks.16.attn.proj.weight": "model-00001-of-00002.safetensors",
|
414 |
+
"vit.trunk.blocks.16.attn.qkv.weight": "model-00001-of-00002.safetensors",
|
415 |
+
"vit.trunk.blocks.16.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
416 |
+
"vit.trunk.blocks.16.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
417 |
+
"vit.trunk.blocks.16.mlp.fc3.weight": "model-00001-of-00002.safetensors",
|
418 |
+
"vit.trunk.blocks.16.norm_1.weight": "model-00001-of-00002.safetensors",
|
419 |
+
"vit.trunk.blocks.16.norm_2.weight": "model-00001-of-00002.safetensors",
|
420 |
+
"vit.trunk.blocks.17.attn.proj.weight": "model-00001-of-00002.safetensors",
|
421 |
+
"vit.trunk.blocks.17.attn.qkv.weight": "model-00001-of-00002.safetensors",
|
422 |
+
"vit.trunk.blocks.17.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
423 |
+
"vit.trunk.blocks.17.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
424 |
+
"vit.trunk.blocks.17.mlp.fc3.weight": "model-00001-of-00002.safetensors",
|
425 |
+
"vit.trunk.blocks.17.norm_1.weight": "model-00001-of-00002.safetensors",
|
426 |
+
"vit.trunk.blocks.17.norm_2.weight": "model-00001-of-00002.safetensors",
|
427 |
+
"vit.trunk.blocks.18.attn.proj.weight": "model-00001-of-00002.safetensors",
|
428 |
+
"vit.trunk.blocks.18.attn.qkv.weight": "model-00001-of-00002.safetensors",
|
429 |
+
"vit.trunk.blocks.18.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
430 |
+
"vit.trunk.blocks.18.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
431 |
+
"vit.trunk.blocks.18.mlp.fc3.weight": "model-00001-of-00002.safetensors",
|
432 |
+
"vit.trunk.blocks.18.norm_1.weight": "model-00001-of-00002.safetensors",
|
433 |
+
"vit.trunk.blocks.18.norm_2.weight": "model-00001-of-00002.safetensors",
|
434 |
+
"vit.trunk.blocks.19.attn.proj.weight": "model-00001-of-00002.safetensors",
|
435 |
+
"vit.trunk.blocks.19.attn.qkv.weight": "model-00001-of-00002.safetensors",
|
436 |
+
"vit.trunk.blocks.19.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
437 |
+
"vit.trunk.blocks.19.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
438 |
+
"vit.trunk.blocks.19.mlp.fc3.weight": "model-00001-of-00002.safetensors",
|
439 |
+
"vit.trunk.blocks.19.norm_1.weight": "model-00001-of-00002.safetensors",
|
440 |
+
"vit.trunk.blocks.19.norm_2.weight": "model-00001-of-00002.safetensors",
|
441 |
+
"vit.trunk.blocks.2.attn.proj.weight": "model-00001-of-00002.safetensors",
|
442 |
+
"vit.trunk.blocks.2.attn.qkv.weight": "model-00001-of-00002.safetensors",
|
443 |
+
"vit.trunk.blocks.2.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
444 |
+
"vit.trunk.blocks.2.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
445 |
+
"vit.trunk.blocks.2.mlp.fc3.weight": "model-00001-of-00002.safetensors",
|
446 |
+
"vit.trunk.blocks.2.norm_1.weight": "model-00001-of-00002.safetensors",
|
447 |
+
"vit.trunk.blocks.2.norm_2.weight": "model-00001-of-00002.safetensors",
|
448 |
+
"vit.trunk.blocks.20.attn.proj.weight": "model-00001-of-00002.safetensors",
|
449 |
+
"vit.trunk.blocks.20.attn.qkv.weight": "model-00001-of-00002.safetensors",
|
450 |
+
"vit.trunk.blocks.20.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
451 |
+
"vit.trunk.blocks.20.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
452 |
+
"vit.trunk.blocks.20.mlp.fc3.weight": "model-00001-of-00002.safetensors",
|
453 |
+
"vit.trunk.blocks.20.norm_1.weight": "model-00001-of-00002.safetensors",
|
454 |
+
"vit.trunk.blocks.20.norm_2.weight": "model-00001-of-00002.safetensors",
|
455 |
+
"vit.trunk.blocks.21.attn.proj.weight": "model-00001-of-00002.safetensors",
|
456 |
+
"vit.trunk.blocks.21.attn.qkv.weight": "model-00001-of-00002.safetensors",
|
457 |
+
"vit.trunk.blocks.21.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
458 |
+
"vit.trunk.blocks.21.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
459 |
+
"vit.trunk.blocks.21.mlp.fc3.weight": "model-00001-of-00002.safetensors",
|
460 |
+
"vit.trunk.blocks.21.norm_1.weight": "model-00001-of-00002.safetensors",
|
461 |
+
"vit.trunk.blocks.21.norm_2.weight": "model-00001-of-00002.safetensors",
|
462 |
+
"vit.trunk.blocks.22.attn.proj.weight": "model-00001-of-00002.safetensors",
|
463 |
+
"vit.trunk.blocks.22.attn.qkv.weight": "model-00001-of-00002.safetensors",
|
464 |
+
"vit.trunk.blocks.22.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
465 |
+
"vit.trunk.blocks.22.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
466 |
+
"vit.trunk.blocks.22.mlp.fc3.weight": "model-00001-of-00002.safetensors",
|
467 |
+
"vit.trunk.blocks.22.norm_1.weight": "model-00001-of-00002.safetensors",
|
468 |
+
"vit.trunk.blocks.22.norm_2.weight": "model-00001-of-00002.safetensors",
|
469 |
+
"vit.trunk.blocks.23.attn.proj.weight": "model-00001-of-00002.safetensors",
|
470 |
+
"vit.trunk.blocks.23.attn.qkv.weight": "model-00001-of-00002.safetensors",
|
471 |
+
"vit.trunk.blocks.23.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
472 |
+
"vit.trunk.blocks.23.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
473 |
+
"vit.trunk.blocks.23.mlp.fc3.weight": "model-00001-of-00002.safetensors",
|
474 |
+
"vit.trunk.blocks.23.norm_1.weight": "model-00001-of-00002.safetensors",
|
475 |
+
"vit.trunk.blocks.23.norm_2.weight": "model-00001-of-00002.safetensors",
|
476 |
+
"vit.trunk.blocks.3.attn.proj.weight": "model-00001-of-00002.safetensors",
|
477 |
+
"vit.trunk.blocks.3.attn.qkv.weight": "model-00001-of-00002.safetensors",
|
478 |
+
"vit.trunk.blocks.3.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
479 |
+
"vit.trunk.blocks.3.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
480 |
+
"vit.trunk.blocks.3.mlp.fc3.weight": "model-00001-of-00002.safetensors",
|
481 |
+
"vit.trunk.blocks.3.norm_1.weight": "model-00001-of-00002.safetensors",
|
482 |
+
"vit.trunk.blocks.3.norm_2.weight": "model-00001-of-00002.safetensors",
|
483 |
+
"vit.trunk.blocks.4.attn.proj.weight": "model-00001-of-00002.safetensors",
|
484 |
+
"vit.trunk.blocks.4.attn.qkv.weight": "model-00001-of-00002.safetensors",
|
485 |
+
"vit.trunk.blocks.4.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
486 |
+
"vit.trunk.blocks.4.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
487 |
+
"vit.trunk.blocks.4.mlp.fc3.weight": "model-00001-of-00002.safetensors",
|
488 |
+
"vit.trunk.blocks.4.norm_1.weight": "model-00001-of-00002.safetensors",
|
489 |
+
"vit.trunk.blocks.4.norm_2.weight": "model-00001-of-00002.safetensors",
|
490 |
+
"vit.trunk.blocks.5.attn.proj.weight": "model-00001-of-00002.safetensors",
|
491 |
+
"vit.trunk.blocks.5.attn.qkv.weight": "model-00001-of-00002.safetensors",
|
492 |
+
"vit.trunk.blocks.5.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
493 |
+
"vit.trunk.blocks.5.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
494 |
+
"vit.trunk.blocks.5.mlp.fc3.weight": "model-00001-of-00002.safetensors",
|
495 |
+
"vit.trunk.blocks.5.norm_1.weight": "model-00001-of-00002.safetensors",
|
496 |
+
"vit.trunk.blocks.5.norm_2.weight": "model-00001-of-00002.safetensors",
|
497 |
+
"vit.trunk.blocks.6.attn.proj.weight": "model-00001-of-00002.safetensors",
|
498 |
+
"vit.trunk.blocks.6.attn.qkv.weight": "model-00001-of-00002.safetensors",
|
499 |
+
"vit.trunk.blocks.6.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
500 |
+
"vit.trunk.blocks.6.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
501 |
+
"vit.trunk.blocks.6.mlp.fc3.weight": "model-00001-of-00002.safetensors",
|
502 |
+
"vit.trunk.blocks.6.norm_1.weight": "model-00001-of-00002.safetensors",
|
503 |
+
"vit.trunk.blocks.6.norm_2.weight": "model-00001-of-00002.safetensors",
|
504 |
+
"vit.trunk.blocks.7.attn.proj.weight": "model-00001-of-00002.safetensors",
|
505 |
+
"vit.trunk.blocks.7.attn.qkv.weight": "model-00001-of-00002.safetensors",
|
506 |
+
"vit.trunk.blocks.7.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
507 |
+
"vit.trunk.blocks.7.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
508 |
+
"vit.trunk.blocks.7.mlp.fc3.weight": "model-00001-of-00002.safetensors",
|
509 |
+
"vit.trunk.blocks.7.norm_1.weight": "model-00001-of-00002.safetensors",
|
510 |
+
"vit.trunk.blocks.7.norm_2.weight": "model-00001-of-00002.safetensors",
|
511 |
+
"vit.trunk.blocks.8.attn.proj.weight": "model-00001-of-00002.safetensors",
|
512 |
+
"vit.trunk.blocks.8.attn.qkv.weight": "model-00001-of-00002.safetensors",
|
513 |
+
"vit.trunk.blocks.8.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
514 |
+
"vit.trunk.blocks.8.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
515 |
+
"vit.trunk.blocks.8.mlp.fc3.weight": "model-00001-of-00002.safetensors",
|
516 |
+
"vit.trunk.blocks.8.norm_1.weight": "model-00001-of-00002.safetensors",
|
517 |
+
"vit.trunk.blocks.8.norm_2.weight": "model-00001-of-00002.safetensors",
|
518 |
+
"vit.trunk.blocks.9.attn.proj.weight": "model-00001-of-00002.safetensors",
|
519 |
+
"vit.trunk.blocks.9.attn.qkv.weight": "model-00001-of-00002.safetensors",
|
520 |
+
"vit.trunk.blocks.9.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
521 |
+
"vit.trunk.blocks.9.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
522 |
+
"vit.trunk.blocks.9.mlp.fc3.weight": "model-00001-of-00002.safetensors",
|
523 |
+
"vit.trunk.blocks.9.norm_1.weight": "model-00001-of-00002.safetensors",
|
524 |
+
"vit.trunk.blocks.9.norm_2.weight": "model-00001-of-00002.safetensors",
|
525 |
+
"vit.trunk.post_trunk_norm.weight": "model-00001-of-00002.safetensors"
|
526 |
+
}
|
527 |
+
}
|
modeling_FlashVLDynamic.py
ADDED
@@ -0,0 +1,392 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import math
|
3 |
+
import copy
|
4 |
+
|
5 |
+
import torch
|
6 |
+
import torch.nn.functional as F
|
7 |
+
from torch.nn import CrossEntropyLoss
|
8 |
+
|
9 |
+
from PIL import Image
|
10 |
+
from functools import partial
|
11 |
+
from typing import List, Optional, Tuple, Union, Dict
|
12 |
+
from dataclasses import dataclass
|
13 |
+
|
14 |
+
import transformers
|
15 |
+
from transformers.modeling_outputs import ModelOutput
|
16 |
+
from transformers.modeling_utils import PreTrainedModel
|
17 |
+
from transformers import AutoModelForCausalLM
|
18 |
+
|
19 |
+
from .processing_FlashVL import tokenizer_image_token_qwen
|
20 |
+
from .adapters import Adapter_AIM
|
21 |
+
from .mm_constants import IGNORE_INDEX, IMAGE_TOKEN_INDEX, DEFAULT_SLICE_START_TOKEN, DEFAULT_SLICE_END_TOKEN
|
22 |
+
from .utils_data import split_image_ur
|
23 |
+
from .configuration_FlashVLDynamic import FlashVLDynamicConfig
|
24 |
+
from .modeling_aimv2 import AIMv2Model
|
25 |
+
|
26 |
+
@dataclass
|
27 |
+
class FlashVLDynamicOutputWithPast(ModelOutput):
|
28 |
+
loss: Optional[torch.FloatTensor] = None
|
29 |
+
logits: torch.FloatTensor = None
|
30 |
+
|
31 |
+
|
32 |
+
class FlashVLDynamic(PreTrainedModel):
|
33 |
+
config_class = FlashVLDynamicConfig
|
34 |
+
|
35 |
+
def __init__(self, config):
|
36 |
+
super().__init__(config)
|
37 |
+
self.llm = AutoModelForCausalLM.from_config(config.llm_config, trust_remote_code=True)
|
38 |
+
self.vit = AIMv2Model(config.vision_config)
|
39 |
+
self.adp = Adapter_AIM(config)
|
40 |
+
|
41 |
+
self.image_token_num = config.image_token_num
|
42 |
+
self.image_size = config.vision_config.image_size
|
43 |
+
self.image_split = config.image_split
|
44 |
+
|
45 |
+
def merge_text_image_tokens(self, inputs, add_start_end=False):
|
46 |
+
input_ids, image_features, targets, attn_mask, loss_mask = inputs
|
47 |
+
micro_batch_size, tokens_len = input_ids.shape
|
48 |
+
device = input_ids.device
|
49 |
+
|
50 |
+
img_rows, img_cols = torch.where(input_ids == IMAGE_TOKEN_INDEX)
|
51 |
+
image_idxs = {i: [] for i in range(micro_batch_size)}
|
52 |
+
for row, col in zip(img_rows.tolist(), img_cols.tolist()):
|
53 |
+
image_idxs[row].append(col)
|
54 |
+
for row in range(micro_batch_size):
|
55 |
+
image_idxs[row] = sorted(image_idxs[row])
|
56 |
+
|
57 |
+
split_sizes = []
|
58 |
+
for row in range(micro_batch_size):
|
59 |
+
image_num = len(image_idxs[row])
|
60 |
+
if image_num == 0:
|
61 |
+
split_sizes.append(tokens_len)
|
62 |
+
continue
|
63 |
+
|
64 |
+
if image_idxs[row][0] != 0:
|
65 |
+
split_sizes.append(image_idxs[row][0])
|
66 |
+
|
67 |
+
for idx in range(image_num - 1):
|
68 |
+
split_sizes.append(self.image_token_num)
|
69 |
+
if image_idxs[row][idx + 1] > image_idxs[row][idx] + self.image_token_num:
|
70 |
+
split_sizes.append(image_idxs[row][idx + 1] - (image_idxs[row][idx] + self.image_token_num))
|
71 |
+
|
72 |
+
if image_idxs[row][image_num - 1] + self.image_token_num >= tokens_len:
|
73 |
+
split_sizes.append(tokens_len - image_idxs[row][image_num - 1])
|
74 |
+
else:
|
75 |
+
split_sizes.append(self.image_token_num)
|
76 |
+
split_sizes.append(tokens_len - (image_idxs[row][image_num - 1] + self.image_token_num))
|
77 |
+
|
78 |
+
input_ids_noim = torch.where(input_ids < 0, 151643, input_ids)
|
79 |
+
input_ids_noim = input_ids_noim.view(-1)
|
80 |
+
input_embeds = self.llm.model.embed_tokens(input_ids_noim)
|
81 |
+
input_embeds_split = torch.split(input_embeds, split_sizes, dim=0)
|
82 |
+
|
83 |
+
vl_embeds_list = []
|
84 |
+
cur_language_idx = 0
|
85 |
+
cur_image_idx = 0
|
86 |
+
for row in range(micro_batch_size):
|
87 |
+
image_num = len(image_idxs[row])
|
88 |
+
if image_num == 0:
|
89 |
+
vl_embeds_list.append(input_embeds_split[cur_language_idx])
|
90 |
+
cur_language_idx += 1
|
91 |
+
vl_embeds_list.append(image_features[cur_image_idx][0:0])
|
92 |
+
cur_image_idx += 1
|
93 |
+
continue
|
94 |
+
|
95 |
+
if image_idxs[row][0] != 0:
|
96 |
+
vl_embeds_list.append(input_embeds_split[cur_language_idx])
|
97 |
+
cur_language_idx += 1
|
98 |
+
|
99 |
+
for idx in range(image_num - 1):
|
100 |
+
vl_embeds_list.append(image_features[cur_image_idx])
|
101 |
+
cur_language_idx += 1
|
102 |
+
cur_image_idx += 1
|
103 |
+
|
104 |
+
if image_idxs[row][idx + 1] > image_idxs[row][idx] + self.image_token_num:
|
105 |
+
vl_embeds_list.append(input_embeds_split[cur_language_idx])
|
106 |
+
cur_language_idx += 1
|
107 |
+
|
108 |
+
if image_idxs[row][image_num - 1] + self.image_token_num >= tokens_len:
|
109 |
+
vl_embeds_list.append(image_features[cur_image_idx][0 : tokens_len - image_idxs[row][image_num - 1]])
|
110 |
+
cur_language_idx += 1
|
111 |
+
cur_image_idx += 1
|
112 |
+
else:
|
113 |
+
vl_embeds_list.append(image_features[cur_image_idx])
|
114 |
+
cur_language_idx += 1
|
115 |
+
cur_image_idx += 1
|
116 |
+
vl_embeds_list.append(input_embeds_split[cur_language_idx])
|
117 |
+
cur_language_idx += 1
|
118 |
+
|
119 |
+
vl_embeds = torch.cat(vl_embeds_list)
|
120 |
+
vl_embeds = vl_embeds.view(micro_batch_size, tokens_len, vl_embeds.shape[-1])
|
121 |
+
return (input_ids, vl_embeds, targets, attn_mask, loss_mask)
|
122 |
+
|
123 |
+
def forward(
|
124 |
+
self,
|
125 |
+
input_ids: torch.LongTensor = None,
|
126 |
+
pixel_values: torch.FloatTensor = None,
|
127 |
+
attention_mask: Optional[torch.Tensor] = None,
|
128 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
129 |
+
labels: Optional[torch.LongTensor] = None,
|
130 |
+
output_attentions: Optional[bool] = None,
|
131 |
+
output_hidden_states: Optional[bool] = None,
|
132 |
+
return_dict: Optional[bool] = None,
|
133 |
+
local_pos_batch: Optional[torch.LongTensor] = None,
|
134 |
+
image_idx_batch: Optional[torch.Tensor] = None,
|
135 |
+
loss_mask_batch: Optional[torch.Tensor] = None,
|
136 |
+
use_cache: Optional[bool] = None,
|
137 |
+
):
|
138 |
+
inputs = [input_ids, pixel_values, labels, attention_mask, loss_mask_batch]
|
139 |
+
|
140 |
+
if isinstance(inputs[1], list):
|
141 |
+
pixel_values = [p.bfloat16() for p in inputs[1]]
|
142 |
+
else:
|
143 |
+
pixel_values = inputs[1].bfloat16()
|
144 |
+
img_token = self.vit.forward(pixel_values)
|
145 |
+
|
146 |
+
if hasattr(img_token, 'last_hidden_state'):
|
147 |
+
img_token = img_token.last_hidden_state
|
148 |
+
|
149 |
+
inputs = self.adp(inputs[:1]+[img_token]+inputs[2:])
|
150 |
+
|
151 |
+
inputs = self.merge_text_image_tokens(inputs)
|
152 |
+
tokens, hidden_states, targets, attn_mask, loss_mask = inputs
|
153 |
+
|
154 |
+
outputs = self.llm.forward(
|
155 |
+
inputs_embeds=hidden_states,
|
156 |
+
attention_mask=attn_mask,
|
157 |
+
use_cache=use_cache)
|
158 |
+
|
159 |
+
lm_logits = outputs.logits
|
160 |
+
|
161 |
+
loss = None
|
162 |
+
if targets is not None:
|
163 |
+
labels = targets.to(lm_logits.device)
|
164 |
+
shift_logits = lm_logits[..., :-1, :].contiguous()
|
165 |
+
shift_labels = labels[..., 1:].contiguous()
|
166 |
+
|
167 |
+
loss_fct = CrossEntropyLoss(reduction='none')
|
168 |
+
loss = loss_fct(
|
169 |
+
shift_logits.view(-1, shift_logits.size(-1)), shift_labels.view(-1)
|
170 |
+
)
|
171 |
+
|
172 |
+
batch_size = labels.size(0)
|
173 |
+
loss_mask = loss_mask[:, 1:].to(loss.dtype)
|
174 |
+
loss = (loss.view(batch_size, -1) * loss_mask).sum() / loss_mask.sum()
|
175 |
+
|
176 |
+
return FlashVLDynamicOutputWithPast(
|
177 |
+
loss=loss,
|
178 |
+
logits=lm_logits,
|
179 |
+
)
|
180 |
+
|
181 |
+
def get_input_embeddings(self):
|
182 |
+
return self.llm.get_input_embeddings()
|
183 |
+
|
184 |
+
def split_image_minicpm(self, image):
|
185 |
+
|
186 |
+
splits, grid_shapes = split_image_ur(image, self.image_split, self.image_size, force_min_size=True)
|
187 |
+
|
188 |
+
prefix = ''
|
189 |
+
flatten_splits = [splits[0]] # global image
|
190 |
+
prefix += '<image>\n'
|
191 |
+
if len(splits) > 1:
|
192 |
+
prefix += DEFAULT_SLICE_START_TOKEN # slice starts
|
193 |
+
for i in range(1, len(splits)):
|
194 |
+
prefix += '<image>'
|
195 |
+
prefix += '\n'
|
196 |
+
flatten_splits += [splits[i]]
|
197 |
+
prefix += DEFAULT_SLICE_END_TOKEN # slice ends
|
198 |
+
|
199 |
+
return flatten_splits, prefix
|
200 |
+
|
201 |
+
def to_llava_format(self, data):
|
202 |
+
img_pil = data['img']
|
203 |
+
messages = data['messages']
|
204 |
+
text_only = data['text_only']
|
205 |
+
is_video=False
|
206 |
+
if 'is_video' in data:
|
207 |
+
is_video=data['is_video']
|
208 |
+
messages.append({'role': 'assistant', 'content': ''})
|
209 |
+
conversations = []
|
210 |
+
for i,m in enumerate(messages):
|
211 |
+
if m['role'] == 'user':
|
212 |
+
value = str(m['content']).replace('<image>', '')
|
213 |
+
|
214 |
+
if i == 0 and not text_only:
|
215 |
+
assert not isinstance(img_pil, list)
|
216 |
+
img_pil, prefix = self.split_image_minicpm(img_pil)
|
217 |
+
value = prefix + value
|
218 |
+
|
219 |
+
conversations.append({'from': 'human', 'value': value})
|
220 |
+
elif m['role'] == 'assistant':
|
221 |
+
conversations.append({'from': 'gpt', 'value': str(m['content']).replace('<image>', '')})
|
222 |
+
else:
|
223 |
+
raise ValueError(f"Wrong role in conversation. {m['role']}")
|
224 |
+
return {'image': img_pil,
|
225 |
+
'text_only': text_only,
|
226 |
+
'is_video':is_video,
|
227 |
+
'conversations': conversations}
|
228 |
+
|
229 |
+
def generate(
|
230 |
+
self,
|
231 |
+
input_ids=None,
|
232 |
+
pixel_values=None,
|
233 |
+
attention_mask=None,
|
234 |
+
streamer=None,
|
235 |
+
**kwargs
|
236 |
+
):
|
237 |
+
image = kwargs.get('image')
|
238 |
+
img_token = self.vit.forward(image.bfloat16())
|
239 |
+
if hasattr(img_token, 'last_hidden_state'):
|
240 |
+
img_token = img_token.last_hidden_state
|
241 |
+
inputs = self.adp((
|
242 |
+
input_ids.to(self.device),
|
243 |
+
img_token,
|
244 |
+
None, None, None))
|
245 |
+
inputs = self.merge_text_image_tokens(inputs)
|
246 |
+
tokens, hidden_states, targets, attn_mask, loss_mask = inputs
|
247 |
+
|
248 |
+
keys_to_pop = ['loss_mask', 'paddings','targets','attn_mask','image']
|
249 |
+
kwargs = {k: v for k, v in kwargs.items() if k not in keys_to_pop}
|
250 |
+
outputs = self.llm.generate(
|
251 |
+
inputs_embeds=hidden_states.bfloat16(),
|
252 |
+
max_new_tokens=2048,
|
253 |
+
do_sample=False,
|
254 |
+
**kwargs
|
255 |
+
)
|
256 |
+
|
257 |
+
return outputs
|
258 |
+
|
259 |
+
def chat(self, pil_image, messages, answer_prompt=None, do_sample=True, max_new_tokens=256):
|
260 |
+
|
261 |
+
data={}
|
262 |
+
data['img'] = pil_image
|
263 |
+
data['text_only'] = (pil_image is None)
|
264 |
+
data['messages'] = messages
|
265 |
+
|
266 |
+
sources = self.to_llava_format(data)
|
267 |
+
sources = [sources]
|
268 |
+
has_image = not sources[0]['text_only']
|
269 |
+
|
270 |
+
if has_image:
|
271 |
+
img_list = sources[0]['image']
|
272 |
+
if not isinstance(img_list, list):
|
273 |
+
img_list = [img_list]
|
274 |
+
image = torch.stack([torch.from_numpy(self.im_trans(i)['pixel_values'][0]) for i in img_list], dim=0)
|
275 |
+
|
276 |
+
sources = copy.deepcopy([e["conversations"] for e in sources])
|
277 |
+
|
278 |
+
data_dict = self.preprocess_qwen(
|
279 |
+
sources,
|
280 |
+
self.tokenizer,
|
281 |
+
has_image=has_image,
|
282 |
+
)
|
283 |
+
|
284 |
+
input_ids_data = data_dict["input_ids"][0]
|
285 |
+
data_dict["input_ids"] = [ input_ids_data, ]
|
286 |
+
|
287 |
+
if not has_image:
|
288 |
+
image = torch.zeros(1, 3, self.image_size, self.image_size)
|
289 |
+
data_dict = dict(tokens=data_dict["input_ids"][0],)
|
290 |
+
|
291 |
+
img_token = self.vit.forward(image.cuda().bfloat16())
|
292 |
+
|
293 |
+
if hasattr(img_token, 'last_hidden_state'):
|
294 |
+
img_token = img_token.last_hidden_state
|
295 |
+
|
296 |
+
inputs = self.adp((
|
297 |
+
data_dict['tokens'].unsqueeze(0).to(self.device),
|
298 |
+
img_token,
|
299 |
+
None, None, None))
|
300 |
+
|
301 |
+
inputs = self.merge_text_image_tokens(inputs)
|
302 |
+
tokens, hidden_states, targets, attn_mask, loss_mask = inputs
|
303 |
+
|
304 |
+
outputs = self.llm.generate(
|
305 |
+
inputs_embeds=hidden_states.bfloat16(),
|
306 |
+
return_dict_in_generate=False,
|
307 |
+
max_new_tokens=max_new_tokens,
|
308 |
+
do_sample=do_sample,
|
309 |
+
pad_token_id=False,
|
310 |
+
)
|
311 |
+
decoded = self.tokenizer.decode(outputs[0])
|
312 |
+
|
313 |
+
stop_words_ids = [self.llm.generation_config.bos_token_id,
|
314 |
+
self.llm.generation_config.eos_token_id,
|
315 |
+
self.tokenizer.convert_tokens_to_ids('<|im_start|>')]
|
316 |
+
stop_words = [self.tokenizer.decode(w) for w in stop_words_ids]
|
317 |
+
|
318 |
+
for stop_word in stop_words:
|
319 |
+
decoded = decoded.replace(stop_word, "").strip()
|
320 |
+
|
321 |
+
return decoded
|
322 |
+
|
323 |
+
def preprocess_qwen(
|
324 |
+
self,
|
325 |
+
sources,
|
326 |
+
tokenizer: transformers.PreTrainedTokenizer,
|
327 |
+
has_image: bool = False,
|
328 |
+
max_len=2048,
|
329 |
+
system_message: str = "You are a helpful assistant.",) -> Dict:
|
330 |
+
|
331 |
+
roles = {"human": "user", "gpt": "assistant"}
|
332 |
+
tokenizer = copy.deepcopy(tokenizer)
|
333 |
+
|
334 |
+
tokenizer.add_tokens(["<image>"], special_tokens=True)
|
335 |
+
image_token_index = tokenizer.convert_tokens_to_ids("<image>")
|
336 |
+
im_start, im_end = tokenizer.additional_special_tokens_ids[:2]
|
337 |
+
# unmask_tokens = ["<|im_start|>", "<|im_start|>", "\n"]
|
338 |
+
unmask_tokens_idx = [198, im_start, im_end]
|
339 |
+
nl_tokens = tokenizer("\n").input_ids
|
340 |
+
|
341 |
+
chat_template = "{% for message in messages %}{{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\n' }}{% endif %}"
|
342 |
+
tokenizer.chat_template = chat_template
|
343 |
+
|
344 |
+
input_ids, targets = [], []
|
345 |
+
for i, source in enumerate(sources):
|
346 |
+
if roles[source[0]["from"]] != roles["human"]:
|
347 |
+
source = source[1:]
|
348 |
+
input_id, target = [], []
|
349 |
+
|
350 |
+
input_id += tokenizer.apply_chat_template([{"role" : "system", "content" : system_message}])
|
351 |
+
target += [IGNORE_INDEX] * len(input_id)
|
352 |
+
i=0
|
353 |
+
for conv in source:
|
354 |
+
try:
|
355 |
+
role = conv["role"]
|
356 |
+
content = conv["content"]
|
357 |
+
except:
|
358 |
+
role = conv["from"]
|
359 |
+
content = conv["value"]
|
360 |
+
role = roles.get(role, role)
|
361 |
+
|
362 |
+
if i==len(source)-1:
|
363 |
+
conv = [{"role" : role, "content" : content}]
|
364 |
+
encode_id = tokenizer.apply_chat_template(conv,add_generation_prompt=True)
|
365 |
+
else:
|
366 |
+
conv = [{"role" : role, "content" : content}]
|
367 |
+
encode_id = tokenizer.apply_chat_template(conv)
|
368 |
+
i=i+1
|
369 |
+
if image_token_index in encode_id:
|
370 |
+
encode_id = tokenizer_image_token_qwen(encode_id, tokenizer, image_token_index,image_token_num=self.image_token_num)
|
371 |
+
|
372 |
+
input_id += encode_id
|
373 |
+
if role in ["user", "system"]:
|
374 |
+
target += [IGNORE_INDEX] * len(encode_id)
|
375 |
+
else:
|
376 |
+
target += encode_id
|
377 |
+
|
378 |
+
|
379 |
+
assert len(input_id) == len(target), f"{len(input_id)} != {len(target)}"
|
380 |
+
for idx, encode_id in enumerate(input_id):
|
381 |
+
if encode_id in unmask_tokens_idx:
|
382 |
+
target[idx] = encode_id
|
383 |
+
if encode_id == image_token_index:
|
384 |
+
input_id[idx] = IMAGE_TOKEN_INDEX
|
385 |
+
input_ids.append(input_id)
|
386 |
+
targets.append(target)
|
387 |
+
input_ids = torch.tensor(input_ids, dtype=torch.long)
|
388 |
+
targets = torch.tensor(targets, dtype=torch.long)
|
389 |
+
return dict(
|
390 |
+
input_ids=input_ids,
|
391 |
+
labels=targets,
|
392 |
+
)
|
modeling_aimv2.py
ADDED
@@ -0,0 +1,192 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Optional, Tuple, Union
|
2 |
+
|
3 |
+
import torch
|
4 |
+
from .configuration_aimv2 import AIMv2Config
|
5 |
+
from torch import nn
|
6 |
+
from torch.nn import functional as F
|
7 |
+
from transformers.modeling_outputs import BaseModelOutputWithNoAttention
|
8 |
+
from transformers.modeling_utils import PreTrainedModel
|
9 |
+
|
10 |
+
__all__ = ["AIMv2Model"]
|
11 |
+
|
12 |
+
|
13 |
+
class RMSNorm(nn.Module):
|
14 |
+
def __init__(self, dim: int, eps: float = 1e-6):
|
15 |
+
super().__init__()
|
16 |
+
self.weight = nn.Parameter(torch.ones(dim))
|
17 |
+
self.eps = eps
|
18 |
+
|
19 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
20 |
+
output = self._norm(x.float()).type_as(x)
|
21 |
+
return output * self.weight
|
22 |
+
|
23 |
+
def extra_repr(self) -> str:
|
24 |
+
return f"{tuple(self.weight.shape)}, eps={self.eps}"
|
25 |
+
|
26 |
+
def _norm(self, x: torch.Tensor) -> torch.Tensor:
|
27 |
+
return x * torch.rsqrt(x.pow(2).mean(-1, keepdim=True) + self.eps)
|
28 |
+
|
29 |
+
|
30 |
+
class AIMv2SwiGLUFFN(nn.Module):
|
31 |
+
def __init__(self, config: AIMv2Config):
|
32 |
+
super().__init__()
|
33 |
+
hidden_features = config.intermediate_size
|
34 |
+
in_features = config.hidden_size
|
35 |
+
bias = config.use_bias
|
36 |
+
|
37 |
+
self.fc1 = nn.Linear(in_features, hidden_features, bias=bias)
|
38 |
+
self.fc2 = nn.Linear(hidden_features, in_features, bias=bias)
|
39 |
+
self.fc3 = nn.Linear(in_features, hidden_features, bias=bias)
|
40 |
+
|
41 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
42 |
+
x = F.silu(self.fc1(x)) * self.fc3(x)
|
43 |
+
x = self.fc2(x)
|
44 |
+
return x
|
45 |
+
|
46 |
+
|
47 |
+
class AIMv2PatchEmbed(nn.Module):
|
48 |
+
def __init__(self, config: AIMv2Config):
|
49 |
+
super().__init__()
|
50 |
+
self.proj = nn.Conv2d(
|
51 |
+
config.num_channels,
|
52 |
+
config.hidden_size,
|
53 |
+
kernel_size=(config.patch_size, config.patch_size),
|
54 |
+
stride=(config.patch_size, config.patch_size),
|
55 |
+
)
|
56 |
+
self.norm = RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
57 |
+
|
58 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
59 |
+
x = self.proj(x).flatten(2).transpose(1, 2)
|
60 |
+
x = self.norm(x)
|
61 |
+
return x
|
62 |
+
|
63 |
+
|
64 |
+
class AIMv2ViTPreprocessor(nn.Module):
|
65 |
+
def __init__(self, config: AIMv2Config):
|
66 |
+
super().__init__()
|
67 |
+
num_patches = (config.image_size // config.patch_size) ** 2
|
68 |
+
|
69 |
+
self.patchifier = AIMv2PatchEmbed(config)
|
70 |
+
self.pos_embed = nn.Parameter(torch.zeros((1, num_patches, config.hidden_size)))
|
71 |
+
|
72 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
73 |
+
tokens = self.patchifier(x)
|
74 |
+
_, N, _ = tokens.shape
|
75 |
+
pos_embed = self.pos_embed.to(tokens.device)
|
76 |
+
tokens = tokens + pos_embed[:, :N]
|
77 |
+
return tokens
|
78 |
+
|
79 |
+
|
80 |
+
class AIMv2Attention(nn.Module):
|
81 |
+
def __init__(self, config: AIMv2Config):
|
82 |
+
super().__init__()
|
83 |
+
dim = config.hidden_size
|
84 |
+
|
85 |
+
self.num_heads = config.num_attention_heads
|
86 |
+
self.qkv = nn.Linear(dim, dim * 3, bias=config.qkv_bias)
|
87 |
+
self.attn_drop = nn.Dropout(config.attention_dropout)
|
88 |
+
self.proj = nn.Linear(dim, dim, bias=config.use_bias)
|
89 |
+
self.proj_drop = nn.Dropout(config.projection_dropout)
|
90 |
+
|
91 |
+
def forward(
|
92 |
+
self, x: torch.Tensor, mask: Optional[torch.Tensor] = None
|
93 |
+
) -> torch.Tensor:
|
94 |
+
B, N, C = x.shape
|
95 |
+
qkv = (
|
96 |
+
self.qkv(x)
|
97 |
+
.reshape(B, N, 3, self.num_heads, C // self.num_heads)
|
98 |
+
.permute(2, 0, 3, 1, 4)
|
99 |
+
)
|
100 |
+
q, k, v = qkv.unbind(0)
|
101 |
+
|
102 |
+
x = F.scaled_dot_product_attention(q, k, v, attn_mask=mask)
|
103 |
+
x = x.transpose(1, 2).contiguous().reshape(B, N, C)
|
104 |
+
x = self.proj(x)
|
105 |
+
x = self.proj_drop(x)
|
106 |
+
return x
|
107 |
+
|
108 |
+
|
109 |
+
class AIMv2Block(nn.Module):
|
110 |
+
def __init__(self, config: AIMv2Config):
|
111 |
+
super().__init__()
|
112 |
+
self.attn = AIMv2Attention(config)
|
113 |
+
self.norm_1 = RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
114 |
+
self.mlp = AIMv2SwiGLUFFN(config)
|
115 |
+
self.norm_2 = RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
116 |
+
|
117 |
+
def forward(
|
118 |
+
self, x: torch.Tensor, mask: Optional[torch.Tensor] = None
|
119 |
+
) -> torch.Tensor:
|
120 |
+
x = x + self.attn(self.norm_1(x), mask)
|
121 |
+
x = x + self.mlp(self.norm_2(x))
|
122 |
+
return x
|
123 |
+
|
124 |
+
|
125 |
+
class AIMv2Transformer(nn.Module):
|
126 |
+
def __init__(self, config: AIMv2Config):
|
127 |
+
super().__init__()
|
128 |
+
self.blocks = nn.ModuleList(
|
129 |
+
[AIMv2Block(config) for _ in range(config.num_hidden_layers)]
|
130 |
+
)
|
131 |
+
self.post_trunk_norm = RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
132 |
+
|
133 |
+
def forward(
|
134 |
+
self,
|
135 |
+
tokens: torch.Tensor,
|
136 |
+
mask: Optional[torch.Tensor] = None,
|
137 |
+
output_hidden_states: bool = False,
|
138 |
+
) -> Tuple[torch.Tensor, Optional[Tuple[torch.Tensor, ...]]]:
|
139 |
+
hidden_states = () if output_hidden_states else None
|
140 |
+
for block in self.blocks:
|
141 |
+
tokens = block(tokens, mask)
|
142 |
+
if output_hidden_states:
|
143 |
+
hidden_states += (tokens,)
|
144 |
+
tokens = self.post_trunk_norm(tokens)
|
145 |
+
return tokens, hidden_states
|
146 |
+
|
147 |
+
|
148 |
+
class AIMv2PretrainedModel(PreTrainedModel):
|
149 |
+
config_class = AIMv2Config
|
150 |
+
base_model_prefix = "aimv2"
|
151 |
+
main_input_name = "pixel_values"
|
152 |
+
_no_split_modules = ["AIMv2ViTPreprocessor", "AIMv2Block"]
|
153 |
+
_supports_sdpa = True
|
154 |
+
|
155 |
+
|
156 |
+
class AIMv2Model(AIMv2PretrainedModel):
|
157 |
+
def __init__(self, config: AIMv2Config):
|
158 |
+
super().__init__(config)
|
159 |
+
self.preprocessor = AIMv2ViTPreprocessor(config)
|
160 |
+
self.trunk = AIMv2Transformer(config)
|
161 |
+
|
162 |
+
def forward(
|
163 |
+
self,
|
164 |
+
pixel_values: torch.Tensor,
|
165 |
+
mask: Optional[torch.Tensor] = None,
|
166 |
+
output_hidden_states: Optional[bool] = None,
|
167 |
+
return_dict: Optional[bool] = None,
|
168 |
+
) -> Union[
|
169 |
+
Tuple[torch.Tensor],
|
170 |
+
Tuple[torch.Tensor, Tuple[torch.Tensor, ...]],
|
171 |
+
BaseModelOutputWithNoAttention,
|
172 |
+
]:
|
173 |
+
if output_hidden_states is None:
|
174 |
+
output_hidden_states = self.config.output_hidden_states
|
175 |
+
if return_dict is None:
|
176 |
+
return_dict = self.config.use_return_dict
|
177 |
+
|
178 |
+
x = self.preprocessor(pixel_values)
|
179 |
+
x, hidden_states = self.trunk(
|
180 |
+
x, mask, output_hidden_states=output_hidden_states
|
181 |
+
)
|
182 |
+
|
183 |
+
if not return_dict:
|
184 |
+
res = (x,)
|
185 |
+
res += (hidden_states,) if output_hidden_states else ()
|
186 |
+
return res
|
187 |
+
|
188 |
+
return BaseModelOutputWithNoAttention(
|
189 |
+
last_hidden_state=x,
|
190 |
+
hidden_states=hidden_states,
|
191 |
+
)
|
192 |
+
|
preprocessor_config.json
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"crop_size": {
|
3 |
+
"height": 448,
|
4 |
+
"width": 448
|
5 |
+
},
|
6 |
+
"do_center_crop": true,
|
7 |
+
"do_convert_rgb": true,
|
8 |
+
"do_normalize": true,
|
9 |
+
"do_rescale": true,
|
10 |
+
"do_resize": true,
|
11 |
+
"image_mean": [
|
12 |
+
0.48145466,
|
13 |
+
0.4578275,
|
14 |
+
0.40821073
|
15 |
+
],
|
16 |
+
"image_processor_type": "CLIPImageProcessor",
|
17 |
+
"image_std": [
|
18 |
+
0.26862954,
|
19 |
+
0.26130258,
|
20 |
+
0.27577711
|
21 |
+
],
|
22 |
+
"resample": 3,
|
23 |
+
"rescale_factor": 0.00392156862745098,
|
24 |
+
"size": {
|
25 |
+
"shortest_edge": 448
|
26 |
+
}
|
27 |
+
}
|
processing_FlashVL.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from .mm_constants import IMAGE_TOKEN_INDEX, IMAGE_PAD_TOKEN_INDEX
|
2 |
+
|
3 |
+
def tokenizer_image_token_qwen(prompt, tokenizer, image_token_index, image_token_num=256):
|
4 |
+
prompt_chunks, tmp = [], []
|
5 |
+
for n in prompt:
|
6 |
+
if n == image_token_index:
|
7 |
+
prompt_chunks.append(tmp)
|
8 |
+
tmp = []
|
9 |
+
else:
|
10 |
+
tmp.append(n)
|
11 |
+
if tmp: prompt_chunks.append(tmp)
|
12 |
+
|
13 |
+
input_ids = []
|
14 |
+
for i, chunk in enumerate(prompt_chunks):
|
15 |
+
if i > 0:
|
16 |
+
input_ids.extend([IMAGE_TOKEN_INDEX] + [IMAGE_PAD_TOKEN_INDEX] * (image_token_num - 1))
|
17 |
+
input_ids.extend(chunk)
|
18 |
+
|
19 |
+
return input_ids
|
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
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
ADDED
@@ -0,0 +1,207 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
"model_max_length": 131072,
|
203 |
+
"pad_token": "<|endoftext|>",
|
204 |
+
"split_special_tokens": false,
|
205 |
+
"tokenizer_class": "Qwen2Tokenizer",
|
206 |
+
"unk_token": null
|
207 |
+
}
|
utils_data.py
ADDED
@@ -0,0 +1,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import os
|
3 |
+
from PIL import Image
|
4 |
+
import numpy as np
|
5 |
+
import math
|
6 |
+
import torchvision.transforms.functional as F
|
7 |
+
from torchvision.transforms import InterpolationMode
|
8 |
+
|
9 |
+
|
10 |
+
def split_image_ur(img, max_slice_num, image_size, force_min_size=False):
|
11 |
+
if force_min_size:
|
12 |
+
img = resize_by_patch_size_ur(img, min_size= image_size, max_size= image_size * max_slice_num, patch_size=14)
|
13 |
+
slice_config = {
|
14 |
+
"max_slice_nums": max_slice_num,
|
15 |
+
"scale_resolution": image_size,
|
16 |
+
"patch_size": 14
|
17 |
+
}
|
18 |
+
source_image, sub_images, _ = do_slice_by_minicpmv_strategy_ur(
|
19 |
+
img, max_slice_nums=slice_config["max_slice_nums"], scale_resolution=slice_config["scale_resolution"], patch_size=slice_config["patch_size"])
|
20 |
+
splits = []
|
21 |
+
splits.append(source_image)
|
22 |
+
for i in range(len(sub_images)):
|
23 |
+
for j in range(len(sub_images[0])):
|
24 |
+
splits.append(sub_images[i][j])
|
25 |
+
sliced_images, sliced_shapes = [], []
|
26 |
+
for slice_image in splits:
|
27 |
+
sliced_images.append(slice_image)
|
28 |
+
sliced_shapes.append(np.array((slice_image.size[0] // slice_config["patch_size"], slice_image.size[1] // slice_config["patch_size"])))
|
29 |
+
|
30 |
+
return sliced_images, sliced_shapes
|
31 |
+
|
32 |
+
# Strategy: MiniCPM-V
|
33 |
+
def do_slice_by_minicpmv_strategy_ur(image, max_slice_nums=9, scale_resolution=1120, patch_size=14, never_split=False):
|
34 |
+
|
35 |
+
original_size = image.size
|
36 |
+
original_width, original_height = original_size
|
37 |
+
log_ratio = math.log(original_width / original_height)
|
38 |
+
ratio = original_width * original_height / (scale_resolution * scale_resolution)
|
39 |
+
multiple = min(math.ceil(ratio), max_slice_nums)
|
40 |
+
|
41 |
+
source_image = None
|
42 |
+
best_grid = None
|
43 |
+
patches = []
|
44 |
+
|
45 |
+
if multiple <= 1 or never_split:
|
46 |
+
# dont need to slice, upsample
|
47 |
+
# best_size = find_best_resize(
|
48 |
+
# original_size, scale_resolution, patch_size, allow_upscale=True
|
49 |
+
# )
|
50 |
+
best_size = (scale_resolution, scale_resolution)
|
51 |
+
source_image = image.resize(best_size, Image.BICUBIC)
|
52 |
+
else:
|
53 |
+
candidate_split_grids_nums = []
|
54 |
+
for i in [multiple - 1, multiple, multiple + 1]:
|
55 |
+
if i == 1 or i > max_slice_nums:
|
56 |
+
continue
|
57 |
+
candidate_split_grids_nums.append(i)
|
58 |
+
|
59 |
+
# source image, down-sampling and ensure divided by patch_size
|
60 |
+
# best_resize = find_best_resize(original_size, scale_resolution, patch_size)
|
61 |
+
# source_image = image.copy().resize(best_resize, Image.BICUBIC)
|
62 |
+
source_image = image.copy().resize((scale_resolution,scale_resolution), Image.BICUBIC)
|
63 |
+
candidate_grids = []
|
64 |
+
|
65 |
+
# find best grid
|
66 |
+
for split_grids_nums in candidate_split_grids_nums:
|
67 |
+
m = 1
|
68 |
+
while m <= split_grids_nums:
|
69 |
+
if split_grids_nums % m == 0:
|
70 |
+
candidate_grids.append([m, split_grids_nums // m])
|
71 |
+
m += 1
|
72 |
+
# print("candidate_grids: ", candidate_grids)
|
73 |
+
|
74 |
+
best_grid = [1, 1]
|
75 |
+
min_error = float("inf")
|
76 |
+
for grid in candidate_grids:
|
77 |
+
error = abs(log_ratio - math.log(grid[0] / grid[1]))
|
78 |
+
if error < min_error:
|
79 |
+
best_grid = grid
|
80 |
+
min_error = error
|
81 |
+
|
82 |
+
refine_size = get_refine_size(
|
83 |
+
original_size, best_grid, scale_resolution, patch_size, allow_upscale=True
|
84 |
+
)
|
85 |
+
|
86 |
+
refine_image = image.resize(refine_size, Image.BICUBIC)
|
87 |
+
patches = split_to_patches(refine_image, best_grid)
|
88 |
+
|
89 |
+
return source_image, patches, best_grid
|
90 |
+
|
91 |
+
|
92 |
+
def ensure_divide(length, patch_size):
|
93 |
+
return max(round(length / patch_size) * patch_size, patch_size)
|
94 |
+
|
95 |
+
|
96 |
+
def find_best_resize(original_size, scale_resolution, patch_size, allow_upscale=False):
|
97 |
+
width, height = original_size
|
98 |
+
if (width * height > scale_resolution * scale_resolution) or allow_upscale:
|
99 |
+
r = width / height
|
100 |
+
height = int(scale_resolution / math.sqrt(r))
|
101 |
+
width = int(height * r)
|
102 |
+
best_width = ensure_divide(width, patch_size)
|
103 |
+
best_height = ensure_divide(height, patch_size)
|
104 |
+
|
105 |
+
# print(best_width, best_height, scale_resolution)
|
106 |
+
while best_width * best_height > scale_resolution ** 2:
|
107 |
+
# print(best_width)
|
108 |
+
best_width -= patch_size
|
109 |
+
|
110 |
+
return (best_width, best_height)
|
111 |
+
|
112 |
+
|
113 |
+
def get_refine_size(original_size, grid, scale_resolution, patch_size, allow_upscale=False):
|
114 |
+
width, height = original_size
|
115 |
+
grid_x, grid_y = grid
|
116 |
+
|
117 |
+
# refine_width = ensure_divide(width, grid_x)
|
118 |
+
# refine_height = ensure_divide(height, grid_y)
|
119 |
+
|
120 |
+
# grid_width = refine_width / grid_x
|
121 |
+
# grid_height = refine_height / grid_y
|
122 |
+
|
123 |
+
# best_grid_size = find_best_resize(
|
124 |
+
# (grid_width, grid_height),
|
125 |
+
# scale_resolution,
|
126 |
+
# patch_size,
|
127 |
+
# allow_upscale=allow_upscale,
|
128 |
+
# )
|
129 |
+
|
130 |
+
refine_size = (scale_resolution * grid_x, scale_resolution * grid_y)
|
131 |
+
|
132 |
+
return refine_size
|
133 |
+
|
134 |
+
|
135 |
+
def split_to_patches(image, grid):
|
136 |
+
patches = []
|
137 |
+
width, height = image.size
|
138 |
+
grid_x = int(width / grid[0])
|
139 |
+
grid_y = int(height / grid[1])
|
140 |
+
|
141 |
+
for i in range(0, height, grid_y):
|
142 |
+
images = []
|
143 |
+
for j in range(0, width, grid_x):
|
144 |
+
box = (j, i, j + grid_x, i + grid_y)
|
145 |
+
patch = image.crop(box)
|
146 |
+
images.append(patch)
|
147 |
+
patches.append(images)
|
148 |
+
|
149 |
+
return patches
|
150 |
+
|
151 |
+
def resize_by_patch_size_ur(img, min_size=1152, max_size=2240, patch_size=14):
|
152 |
+
interpolation=InterpolationMode.BICUBIC
|
153 |
+
# min_size=756, max_size=756 * 4, patch_size=14
|
154 |
+
if isinstance(img, torch.Tensor):
|
155 |
+
height, width = img.shape[:2]
|
156 |
+
else:
|
157 |
+
width, height = img.size
|
158 |
+
|
159 |
+
# Check if the shorter side is less than min_size
|
160 |
+
if min(height, width) < min_size:
|
161 |
+
# print('less than min_size')
|
162 |
+
scale_factor = min_size / min(height, width)
|
163 |
+
new_height = max(min_size, round(height * scale_factor))
|
164 |
+
new_width = max(min_size, round(width * scale_factor))
|
165 |
+
# print(self.max_size)
|
166 |
+
|
167 |
+
# Check if the longer side after resizing is greater than max_size
|
168 |
+
if max(new_height, new_width) > max_size:
|
169 |
+
scale_factor = max_size / max(new_height, new_width)
|
170 |
+
new_height = min(max_size, round(new_height * scale_factor))
|
171 |
+
new_width = min(max_size, round(new_width * scale_factor))
|
172 |
+
else:
|
173 |
+
scale_factor = min(max_size / max(height, width), 1)
|
174 |
+
new_height = round(height * scale_factor)
|
175 |
+
new_width = round(width * scale_factor)
|
176 |
+
|
177 |
+
# # Make sure the new height and width are divisible by patch_size
|
178 |
+
# new_height = (new_height // patch_size) * patch_size
|
179 |
+
# new_width = (new_width // patch_size) * patch_size
|
180 |
+
|
181 |
+
# Resize the image
|
182 |
+
# img = F.resize(img, (new_height, new_width), interpolation)
|
183 |
+
img = img.resize((new_width, new_height), Image.BICUBIC)
|
184 |
+
|
185 |
+
return img
|
vocab.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|