Upload folder using huggingface_hub
Browse files- .gitattributes +3 -2
- README.md +112 -3
- adapters.py +63 -0
- added_tokens.json +24 -0
- config.json +115 -0
- configuration_FlashVLDynamicISS.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_FlashVLDynamicISS.py +393 -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 +200 -0
- vocab.json +0 -0
.gitattributes
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
|
@@ -22,8 +23,6 @@
|
|
| 22 |
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
*.tflite filter=lfs diff=lfs merge=lfs -text
|
|
@@ -33,3 +32,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 1 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 2 |
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 3 |
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 4 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 23 |
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 24 |
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 25 |
*.rar filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
| 26 |
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 28 |
*.tflite filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
model-00001-of-00002.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
model-00002-of-00002.safetensors filter=lfs diff=lfs merge=lfs -text
|
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-ISS
|
| 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-ISS"
|
| 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=256)
|
| 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,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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),
|
| 31 |
+
nn.Linear(config.vision_config.hidden_size, 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 |
+
self.retained_feature_size = int(config.retained_image_size/config.vision_config.patch_size)
|
| 38 |
+
self.retained_border_size = int((config.vision_config.image_size-config.retained_image_size)/2/config.vision_config.patch_size)
|
| 39 |
+
|
| 40 |
+
def freeze(self):
|
| 41 |
+
self.freeze_module(self.p0)
|
| 42 |
+
self.freeze_module(self.proj)
|
| 43 |
+
|
| 44 |
+
def pixel_shuffle(self, x, scale_factor=0.5):
|
| 45 |
+
n, w, h, c = x.size()
|
| 46 |
+
# N, W, H, C --> N, W, H * scale, C // scale
|
| 47 |
+
x = x.reshape(n, w, int(h * scale_factor), int(c / scale_factor))
|
| 48 |
+
# N, W, H * scale, C // scale --> N, H * scale, W, C // scale
|
| 49 |
+
x = x.permute(0, 2, 1, 3).contiguous()
|
| 50 |
+
# N, H * scale, W, C // scale --> N, H * scale, W * scale, C // (scale ** 2)
|
| 51 |
+
x = x.view(n, int(h * scale_factor), int(w * scale_factor),
|
| 52 |
+
int(c / (scale_factor * scale_factor)))
|
| 53 |
+
return x
|
| 54 |
+
|
| 55 |
+
def forward_adapter_modules(self, hidden_states):
|
| 56 |
+
h = w = int(hidden_states.shape[1] ** 0.5)
|
| 57 |
+
hidden_states = hidden_states.reshape(hidden_states.shape[0], h, w, -1)
|
| 58 |
+
hidden_states = hidden_states[:, self.retained_border_size:self.retained_border_size+self.retained_feature_size, self.retained_border_size:self.retained_border_size+self.retained_feature_size, :]
|
| 59 |
+
hidden_states = hidden_states.reshape(hidden_states.shape[0], -1, hidden_states.shape[-1])
|
| 60 |
+
|
| 61 |
+
hidden_states = self.proj(self.p0(hidden_states))
|
| 62 |
+
|
| 63 |
+
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,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "/mnt/dolphinfs/ssd_pool/docker/user/hadoop-mlm/lishuo/repo/fine_tuning_package/model",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"FlashVLDynamicISS"
|
| 5 |
+
],
|
| 6 |
+
"auto_map": {
|
| 7 |
+
"AutoConfig": "configuration_FlashVLDynamicISS.FlashVLDynamicISSConfig",
|
| 8 |
+
"AutoModel": "modeling_FlashVLDynamicISS.FlashVLDynamicISS"
|
| 9 |
+
},
|
| 10 |
+
"intermediate_size": 7168,
|
| 11 |
+
"image_token_num": 576,
|
| 12 |
+
"image_split": 4,
|
| 13 |
+
"retained_image_size": 336,
|
| 14 |
+
"llm_config":{
|
| 15 |
+
"attention_dropout": 0.0,
|
| 16 |
+
"bos_token_id": 151643,
|
| 17 |
+
"eos_token_id": 151645,
|
| 18 |
+
"hidden_act": "silu",
|
| 19 |
+
"hidden_size": 1536,
|
| 20 |
+
"initializer_range": 0.02,
|
| 21 |
+
"intermediate_size": 8960,
|
| 22 |
+
"max_position_embeddings": 32768,
|
| 23 |
+
"max_window_layers": 21,
|
| 24 |
+
"model_type": "qwen2",
|
| 25 |
+
"num_attention_heads": 12,
|
| 26 |
+
"num_hidden_layers": 28,
|
| 27 |
+
"num_key_value_heads": 2,
|
| 28 |
+
"rms_norm_eps": 1e-06,
|
| 29 |
+
"rope_scaling": null,
|
| 30 |
+
"rope_theta": 1000000.0,
|
| 31 |
+
"sliding_window": null,
|
| 32 |
+
"tie_word_embeddings": true,
|
| 33 |
+
"torch_dtype": "bfloat16",
|
| 34 |
+
"transformers_version": "4.45.0.dev0",
|
| 35 |
+
"use_cache": true,
|
| 36 |
+
"use_sliding_window": false,
|
| 37 |
+
"vocab_size": 151936
|
| 38 |
+
},
|
| 39 |
+
"vision_config": {
|
| 40 |
+
"_name_or_path": "",
|
| 41 |
+
"add_cross_attention": false,
|
| 42 |
+
"architectures": null,
|
| 43 |
+
"attention_dropout": 0.0,
|
| 44 |
+
"bad_words_ids": null,
|
| 45 |
+
"begin_suppress_tokens": null,
|
| 46 |
+
"bos_token_id": null,
|
| 47 |
+
"chunk_size_feed_forward": 0,
|
| 48 |
+
"cross_attention_hidden_size": null,
|
| 49 |
+
"decoder_start_token_id": null,
|
| 50 |
+
"diversity_penalty": 0.0,
|
| 51 |
+
"do_sample": false,
|
| 52 |
+
"early_stopping": false,
|
| 53 |
+
"encoder_no_repeat_ngram_size": 0,
|
| 54 |
+
"eos_token_id": null,
|
| 55 |
+
"exponential_decay_length_penalty": null,
|
| 56 |
+
"finetuning_task": null,
|
| 57 |
+
"forced_bos_token_id": null,
|
| 58 |
+
"forced_eos_token_id": null,
|
| 59 |
+
"hidden_size": 1536,
|
| 60 |
+
"id2label": {
|
| 61 |
+
"0": "LABEL_0",
|
| 62 |
+
"1": "LABEL_1"
|
| 63 |
+
},
|
| 64 |
+
"image_size": 448,
|
| 65 |
+
"intermediate_size": 4096,
|
| 66 |
+
"is_decoder": false,
|
| 67 |
+
"is_encoder_decoder": false,
|
| 68 |
+
"label2id": {
|
| 69 |
+
"LABEL_0": 0,
|
| 70 |
+
"LABEL_1": 1
|
| 71 |
+
},
|
| 72 |
+
"length_penalty": 1.0,
|
| 73 |
+
"max_length": 20,
|
| 74 |
+
"min_length": 0,
|
| 75 |
+
"model_type": "aimv2",
|
| 76 |
+
"no_repeat_ngram_size": 0,
|
| 77 |
+
"num_attention_heads": 12,
|
| 78 |
+
"num_beam_groups": 1,
|
| 79 |
+
"num_beams": 1,
|
| 80 |
+
"num_channels": 3,
|
| 81 |
+
"num_hidden_layers": 24,
|
| 82 |
+
"num_return_sequences": 1,
|
| 83 |
+
"output_attentions": false,
|
| 84 |
+
"output_hidden_states": false,
|
| 85 |
+
"output_scores": false,
|
| 86 |
+
"pad_token_id": null,
|
| 87 |
+
"patch_size": 14,
|
| 88 |
+
"prefix": null,
|
| 89 |
+
"problem_type": null,
|
| 90 |
+
"proj_output_dim": 1536,
|
| 91 |
+
"projection_dropout": 0.0,
|
| 92 |
+
"pruned_heads": {},
|
| 93 |
+
"qkv_bias": false,
|
| 94 |
+
"remove_invalid_values": false,
|
| 95 |
+
"repetition_penalty": 1.0,
|
| 96 |
+
"return_dict": true,
|
| 97 |
+
"return_dict_in_generate": false,
|
| 98 |
+
"rms_norm_eps": 1e-05,
|
| 99 |
+
"sep_token_id": null,
|
| 100 |
+
"suppress_tokens": null,
|
| 101 |
+
"task_specific_params": null,
|
| 102 |
+
"temperature": 1.0,
|
| 103 |
+
"tf_legacy_loss": false,
|
| 104 |
+
"tie_encoder_decoder": false,
|
| 105 |
+
"tie_word_embeddings": true,
|
| 106 |
+
"tokenizer_class": null,
|
| 107 |
+
"top_k": 50,
|
| 108 |
+
"top_p": 1.0,
|
| 109 |
+
"torch_dtype": null,
|
| 110 |
+
"torchscript": false,
|
| 111 |
+
"typical_p": 1.0,
|
| 112 |
+
"use_bfloat16": false,
|
| 113 |
+
"use_bias": false
|
| 114 |
+
}
|
| 115 |
+
}
|
configuration_FlashVLDynamicISS.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 FlashVLDynamicISSConfig(PretrainedConfig):
|
| 7 |
+
model_type = 'FlashVLDynamicISSConfig'
|
| 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:7c4970188b818d5994b54c4fdb8ddec64e0c723b8c5d164594abdf51564bf1c2
|
| 3 |
+
size 4940339496
|
model-00002-of-00002.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:42d5c7ddfe5d493f0deff512cb2c2965d85fd71ddccd5159613af301cdddb363
|
| 3 |
+
size 124798336
|
model.safetensors.index.json
ADDED
|
@@ -0,0 +1,527 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"metadata": {
|
| 3 |
+
"total_size": 5065077760
|
| 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-00001-of-00002.safetensors",
|
| 9 |
+
"adp.p0.1.weight": "model-00001-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_FlashVLDynamicISS.py
ADDED
|
@@ -0,0 +1,393 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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_FlashVLDynamicISS import FlashVLDynamicISSConfig
|
| 24 |
+
from .modeling_aimv2 import AIMv2Model
|
| 25 |
+
|
| 26 |
+
@dataclass
|
| 27 |
+
class FlashVLDynamicISSOutputWithPast(ModelOutput):
|
| 28 |
+
loss: Optional[torch.FloatTensor] = None
|
| 29 |
+
logits: torch.FloatTensor = None
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class FlashVLDynamicISS(PreTrainedModel):
|
| 33 |
+
config_class = FlashVLDynamicISSConfig
|
| 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.retained_image_size = config.retained_image_size
|
| 44 |
+
self.image_split = config.image_split
|
| 45 |
+
|
| 46 |
+
def merge_text_image_tokens(self, inputs, add_start_end=False):
|
| 47 |
+
input_ids, image_features, targets, attn_mask, loss_mask = inputs
|
| 48 |
+
micro_batch_size, tokens_len = input_ids.shape
|
| 49 |
+
device = input_ids.device
|
| 50 |
+
|
| 51 |
+
img_rows, img_cols = torch.where(input_ids == IMAGE_TOKEN_INDEX)
|
| 52 |
+
image_idxs = {i: [] for i in range(micro_batch_size)}
|
| 53 |
+
for row, col in zip(img_rows.tolist(), img_cols.tolist()):
|
| 54 |
+
image_idxs[row].append(col)
|
| 55 |
+
for row in range(micro_batch_size):
|
| 56 |
+
image_idxs[row] = sorted(image_idxs[row])
|
| 57 |
+
|
| 58 |
+
split_sizes = []
|
| 59 |
+
for row in range(micro_batch_size):
|
| 60 |
+
image_num = len(image_idxs[row])
|
| 61 |
+
if image_num == 0:
|
| 62 |
+
split_sizes.append(tokens_len)
|
| 63 |
+
continue
|
| 64 |
+
|
| 65 |
+
if image_idxs[row][0] != 0:
|
| 66 |
+
split_sizes.append(image_idxs[row][0])
|
| 67 |
+
|
| 68 |
+
for idx in range(image_num - 1):
|
| 69 |
+
split_sizes.append(self.image_token_num)
|
| 70 |
+
if image_idxs[row][idx + 1] > image_idxs[row][idx] + self.image_token_num:
|
| 71 |
+
split_sizes.append(image_idxs[row][idx + 1] - (image_idxs[row][idx] + self.image_token_num))
|
| 72 |
+
|
| 73 |
+
if image_idxs[row][image_num - 1] + self.image_token_num >= tokens_len:
|
| 74 |
+
split_sizes.append(tokens_len - image_idxs[row][image_num - 1])
|
| 75 |
+
else:
|
| 76 |
+
split_sizes.append(self.image_token_num)
|
| 77 |
+
split_sizes.append(tokens_len - (image_idxs[row][image_num - 1] + self.image_token_num))
|
| 78 |
+
|
| 79 |
+
input_ids_noim = torch.where(input_ids < 0, 151643, input_ids)
|
| 80 |
+
input_ids_noim = input_ids_noim.view(-1)
|
| 81 |
+
input_embeds = self.llm.model.embed_tokens(input_ids_noim)
|
| 82 |
+
input_embeds_split = torch.split(input_embeds, split_sizes, dim=0)
|
| 83 |
+
|
| 84 |
+
vl_embeds_list = []
|
| 85 |
+
cur_language_idx = 0
|
| 86 |
+
cur_image_idx = 0
|
| 87 |
+
for row in range(micro_batch_size):
|
| 88 |
+
image_num = len(image_idxs[row])
|
| 89 |
+
if image_num == 0:
|
| 90 |
+
vl_embeds_list.append(input_embeds_split[cur_language_idx])
|
| 91 |
+
cur_language_idx += 1
|
| 92 |
+
vl_embeds_list.append(image_features[cur_image_idx][0:0])
|
| 93 |
+
cur_image_idx += 1
|
| 94 |
+
continue
|
| 95 |
+
|
| 96 |
+
if image_idxs[row][0] != 0:
|
| 97 |
+
vl_embeds_list.append(input_embeds_split[cur_language_idx])
|
| 98 |
+
cur_language_idx += 1
|
| 99 |
+
|
| 100 |
+
for idx in range(image_num - 1):
|
| 101 |
+
vl_embeds_list.append(image_features[cur_image_idx])
|
| 102 |
+
cur_language_idx += 1
|
| 103 |
+
cur_image_idx += 1
|
| 104 |
+
|
| 105 |
+
if image_idxs[row][idx + 1] > image_idxs[row][idx] + self.image_token_num:
|
| 106 |
+
vl_embeds_list.append(input_embeds_split[cur_language_idx])
|
| 107 |
+
cur_language_idx += 1
|
| 108 |
+
|
| 109 |
+
if image_idxs[row][image_num - 1] + self.image_token_num >= tokens_len:
|
| 110 |
+
vl_embeds_list.append(image_features[cur_image_idx][0 : tokens_len - image_idxs[row][image_num - 1]])
|
| 111 |
+
cur_language_idx += 1
|
| 112 |
+
cur_image_idx += 1
|
| 113 |
+
else:
|
| 114 |
+
vl_embeds_list.append(image_features[cur_image_idx])
|
| 115 |
+
cur_language_idx += 1
|
| 116 |
+
cur_image_idx += 1
|
| 117 |
+
vl_embeds_list.append(input_embeds_split[cur_language_idx])
|
| 118 |
+
cur_language_idx += 1
|
| 119 |
+
|
| 120 |
+
vl_embeds = torch.cat(vl_embeds_list)
|
| 121 |
+
vl_embeds = vl_embeds.view(micro_batch_size, tokens_len, vl_embeds.shape[-1])
|
| 122 |
+
return (input_ids, vl_embeds, targets, attn_mask, loss_mask)
|
| 123 |
+
|
| 124 |
+
def forward(
|
| 125 |
+
self,
|
| 126 |
+
input_ids: torch.LongTensor = None,
|
| 127 |
+
pixel_values: torch.FloatTensor = None,
|
| 128 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 129 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 130 |
+
labels: Optional[torch.LongTensor] = None,
|
| 131 |
+
output_attentions: Optional[bool] = None,
|
| 132 |
+
output_hidden_states: Optional[bool] = None,
|
| 133 |
+
return_dict: Optional[bool] = None,
|
| 134 |
+
local_pos_batch: Optional[torch.LongTensor] = None,
|
| 135 |
+
image_idx_batch: Optional[torch.Tensor] = None,
|
| 136 |
+
loss_mask_batch: Optional[torch.Tensor] = None,
|
| 137 |
+
use_cache: Optional[bool] = None,
|
| 138 |
+
):
|
| 139 |
+
inputs = [input_ids, pixel_values, labels, attention_mask, loss_mask_batch]
|
| 140 |
+
|
| 141 |
+
if isinstance(inputs[1], list):
|
| 142 |
+
pixel_values = [p.bfloat16() for p in inputs[1]]
|
| 143 |
+
else:
|
| 144 |
+
pixel_values = inputs[1].bfloat16()
|
| 145 |
+
img_token = self.vit.forward(pixel_values)
|
| 146 |
+
|
| 147 |
+
if hasattr(img_token, 'last_hidden_state'):
|
| 148 |
+
img_token = img_token.last_hidden_state
|
| 149 |
+
|
| 150 |
+
inputs = self.adp(inputs[:1]+[img_token]+inputs[2:])
|
| 151 |
+
|
| 152 |
+
inputs = self.merge_text_image_tokens(inputs)
|
| 153 |
+
tokens, hidden_states, targets, attn_mask, loss_mask = inputs
|
| 154 |
+
|
| 155 |
+
outputs = self.llm.forward(
|
| 156 |
+
inputs_embeds=hidden_states,
|
| 157 |
+
attention_mask=attn_mask,
|
| 158 |
+
use_cache=use_cache)
|
| 159 |
+
|
| 160 |
+
lm_logits = outputs.logits
|
| 161 |
+
|
| 162 |
+
loss = None
|
| 163 |
+
if targets is not None:
|
| 164 |
+
labels = targets.to(lm_logits.device)
|
| 165 |
+
shift_logits = lm_logits[..., :-1, :].contiguous()
|
| 166 |
+
shift_labels = labels[..., 1:].contiguous()
|
| 167 |
+
|
| 168 |
+
loss_fct = CrossEntropyLoss(reduction='none')
|
| 169 |
+
loss = loss_fct(
|
| 170 |
+
shift_logits.view(-1, shift_logits.size(-1)), shift_labels.view(-1)
|
| 171 |
+
)
|
| 172 |
+
|
| 173 |
+
batch_size = labels.size(0)
|
| 174 |
+
loss_mask = loss_mask[:, 1:].to(loss.dtype)
|
| 175 |
+
loss = (loss.view(batch_size, -1) * loss_mask).sum() / loss_mask.sum()
|
| 176 |
+
|
| 177 |
+
return FlashVLDynamicISSOutputWithPast(
|
| 178 |
+
loss=loss,
|
| 179 |
+
logits=lm_logits,
|
| 180 |
+
)
|
| 181 |
+
|
| 182 |
+
def get_input_embeddings(self):
|
| 183 |
+
return self.llm.get_input_embeddings()
|
| 184 |
+
|
| 185 |
+
def split_image_minicpm(self, image):
|
| 186 |
+
|
| 187 |
+
splits, grid_shapes = split_image_ur(image, self.image_split, self.retained_image_size, self.image_size, force_min_size=True)
|
| 188 |
+
|
| 189 |
+
prefix = ''
|
| 190 |
+
flatten_splits = [splits[0]] # global image
|
| 191 |
+
prefix += '<image>\n'
|
| 192 |
+
if len(splits) > 1:
|
| 193 |
+
prefix += DEFAULT_SLICE_START_TOKEN # slice starts
|
| 194 |
+
for i in range(1, len(splits)):
|
| 195 |
+
prefix += '<image>'
|
| 196 |
+
prefix += '\n'
|
| 197 |
+
flatten_splits += [splits[i]]
|
| 198 |
+
prefix += DEFAULT_SLICE_END_TOKEN # slice ends
|
| 199 |
+
|
| 200 |
+
return flatten_splits, prefix
|
| 201 |
+
|
| 202 |
+
def to_llava_format(self, data):
|
| 203 |
+
img_pil = data['img']
|
| 204 |
+
messages = data['messages']
|
| 205 |
+
text_only = data['text_only']
|
| 206 |
+
is_video=False
|
| 207 |
+
if 'is_video' in data:
|
| 208 |
+
is_video=data['is_video']
|
| 209 |
+
messages.append({'role': 'assistant', 'content': ''})
|
| 210 |
+
conversations = []
|
| 211 |
+
for i,m in enumerate(messages):
|
| 212 |
+
if m['role'] == 'user':
|
| 213 |
+
value = str(m['content']).replace('<image>', '')
|
| 214 |
+
|
| 215 |
+
if i == 0 and not text_only:
|
| 216 |
+
assert not isinstance(img_pil, list)
|
| 217 |
+
img_pil, prefix = self.split_image_minicpm(img_pil)
|
| 218 |
+
value = prefix + value
|
| 219 |
+
|
| 220 |
+
conversations.append({'from': 'human', 'value': value})
|
| 221 |
+
elif m['role'] == 'assistant':
|
| 222 |
+
conversations.append({'from': 'gpt', 'value': str(m['content']).replace('<image>', '')})
|
| 223 |
+
else:
|
| 224 |
+
raise ValueError(f"Wrong role in conversation. {m['role']}")
|
| 225 |
+
return {'image': img_pil,
|
| 226 |
+
'text_only': text_only,
|
| 227 |
+
'is_video':is_video,
|
| 228 |
+
'conversations': conversations}
|
| 229 |
+
|
| 230 |
+
def generate(
|
| 231 |
+
self,
|
| 232 |
+
input_ids=None,
|
| 233 |
+
pixel_values=None,
|
| 234 |
+
attention_mask=None,
|
| 235 |
+
streamer=None,
|
| 236 |
+
**kwargs
|
| 237 |
+
):
|
| 238 |
+
image = kwargs.get('image')
|
| 239 |
+
img_token = self.vit.forward(image.bfloat16())
|
| 240 |
+
if hasattr(img_token, 'last_hidden_state'):
|
| 241 |
+
img_token = img_token.last_hidden_state
|
| 242 |
+
inputs = self.adp((
|
| 243 |
+
input_ids.to(self.device),
|
| 244 |
+
img_token,
|
| 245 |
+
None, None, None))
|
| 246 |
+
inputs = self.merge_text_image_tokens(inputs)
|
| 247 |
+
tokens, hidden_states, targets, attn_mask, loss_mask = inputs
|
| 248 |
+
|
| 249 |
+
keys_to_pop = ['loss_mask', 'paddings','targets','attn_mask','image']
|
| 250 |
+
kwargs = {k: v for k, v in kwargs.items() if k not in keys_to_pop}
|
| 251 |
+
outputs = self.llm.generate(
|
| 252 |
+
inputs_embeds=hidden_states.bfloat16(),
|
| 253 |
+
max_new_tokens=2048,
|
| 254 |
+
do_sample=False,
|
| 255 |
+
**kwargs
|
| 256 |
+
)
|
| 257 |
+
|
| 258 |
+
return outputs
|
| 259 |
+
|
| 260 |
+
def chat(self, pil_image, messages, answer_prompt=None, do_sample=True, max_new_tokens=256):
|
| 261 |
+
|
| 262 |
+
data={}
|
| 263 |
+
data['img'] = pil_image
|
| 264 |
+
data['text_only'] = (pil_image is None)
|
| 265 |
+
data['messages'] = messages
|
| 266 |
+
|
| 267 |
+
sources = self.to_llava_format(data)
|
| 268 |
+
sources = [sources]
|
| 269 |
+
has_image = not sources[0]['text_only']
|
| 270 |
+
|
| 271 |
+
if has_image:
|
| 272 |
+
img_list = sources[0]['image']
|
| 273 |
+
if not isinstance(img_list, list):
|
| 274 |
+
img_list = [img_list]
|
| 275 |
+
image = torch.stack([torch.from_numpy(self.im_trans(i)['pixel_values'][0]) for i in img_list], dim=0)
|
| 276 |
+
|
| 277 |
+
sources = copy.deepcopy([e["conversations"] for e in sources])
|
| 278 |
+
|
| 279 |
+
data_dict = self.preprocess_qwen(
|
| 280 |
+
sources,
|
| 281 |
+
self.tokenizer,
|
| 282 |
+
has_image=has_image,
|
| 283 |
+
)
|
| 284 |
+
|
| 285 |
+
input_ids_data = data_dict["input_ids"][0]
|
| 286 |
+
data_dict["input_ids"] = [ input_ids_data, ]
|
| 287 |
+
|
| 288 |
+
if not has_image:
|
| 289 |
+
image = torch.zeros(1, 3, self.image_size, self.image_size)
|
| 290 |
+
data_dict = dict(tokens=data_dict["input_ids"][0],)
|
| 291 |
+
|
| 292 |
+
img_token = self.vit.forward(image.cuda().bfloat16())
|
| 293 |
+
|
| 294 |
+
if hasattr(img_token, 'last_hidden_state'):
|
| 295 |
+
img_token = img_token.last_hidden_state
|
| 296 |
+
|
| 297 |
+
inputs = self.adp((
|
| 298 |
+
data_dict['tokens'].unsqueeze(0).to(self.device),
|
| 299 |
+
img_token,
|
| 300 |
+
None, None, None))
|
| 301 |
+
|
| 302 |
+
inputs = self.merge_text_image_tokens(inputs)
|
| 303 |
+
tokens, hidden_states, targets, attn_mask, loss_mask = inputs
|
| 304 |
+
|
| 305 |
+
outputs = self.llm.generate(
|
| 306 |
+
inputs_embeds=hidden_states.bfloat16(),
|
| 307 |
+
return_dict_in_generate=False,
|
| 308 |
+
max_new_tokens=max_new_tokens,
|
| 309 |
+
do_sample=do_sample,
|
| 310 |
+
pad_token_id=False,
|
| 311 |
+
)
|
| 312 |
+
decoded = self.tokenizer.decode(outputs[0])
|
| 313 |
+
|
| 314 |
+
stop_words_ids = [self.llm.generation_config.bos_token_id,
|
| 315 |
+
self.llm.generation_config.eos_token_id,
|
| 316 |
+
self.tokenizer.convert_tokens_to_ids('<|im_start|>')]
|
| 317 |
+
stop_words = [self.tokenizer.decode(w) for w in stop_words_ids]
|
| 318 |
+
|
| 319 |
+
for stop_word in stop_words:
|
| 320 |
+
decoded = decoded.replace(stop_word, "").strip()
|
| 321 |
+
|
| 322 |
+
return decoded
|
| 323 |
+
|
| 324 |
+
def preprocess_qwen(
|
| 325 |
+
self,
|
| 326 |
+
sources,
|
| 327 |
+
tokenizer: transformers.PreTrainedTokenizer,
|
| 328 |
+
has_image: bool = False,
|
| 329 |
+
max_len=2048,
|
| 330 |
+
system_message: str = "You are a helpful assistant.",) -> Dict:
|
| 331 |
+
|
| 332 |
+
roles = {"human": "user", "gpt": "assistant"}
|
| 333 |
+
tokenizer = copy.deepcopy(tokenizer)
|
| 334 |
+
|
| 335 |
+
tokenizer.add_tokens(["<image>"], special_tokens=True)
|
| 336 |
+
image_token_index = tokenizer.convert_tokens_to_ids("<image>")
|
| 337 |
+
im_start, im_end = tokenizer.additional_special_tokens_ids[:2]
|
| 338 |
+
# unmask_tokens = ["<|im_start|>", "<|im_start|>", "\n"]
|
| 339 |
+
unmask_tokens_idx = [198, im_start, im_end]
|
| 340 |
+
nl_tokens = tokenizer("\n").input_ids
|
| 341 |
+
|
| 342 |
+
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 %}"
|
| 343 |
+
tokenizer.chat_template = chat_template
|
| 344 |
+
|
| 345 |
+
input_ids, targets = [], []
|
| 346 |
+
for i, source in enumerate(sources):
|
| 347 |
+
if roles[source[0]["from"]] != roles["human"]:
|
| 348 |
+
source = source[1:]
|
| 349 |
+
input_id, target = [], []
|
| 350 |
+
|
| 351 |
+
input_id += tokenizer.apply_chat_template([{"role" : "system", "content" : system_message}])
|
| 352 |
+
target += [IGNORE_INDEX] * len(input_id)
|
| 353 |
+
i=0
|
| 354 |
+
for conv in source:
|
| 355 |
+
try:
|
| 356 |
+
role = conv["role"]
|
| 357 |
+
content = conv["content"]
|
| 358 |
+
except:
|
| 359 |
+
role = conv["from"]
|
| 360 |
+
content = conv["value"]
|
| 361 |
+
role = roles.get(role, role)
|
| 362 |
+
|
| 363 |
+
if i==len(source)-1:
|
| 364 |
+
conv = [{"role" : role, "content" : content}]
|
| 365 |
+
encode_id = tokenizer.apply_chat_template(conv,add_generation_prompt=True)
|
| 366 |
+
else:
|
| 367 |
+
conv = [{"role" : role, "content" : content}]
|
| 368 |
+
encode_id = tokenizer.apply_chat_template(conv)
|
| 369 |
+
i=i+1
|
| 370 |
+
if image_token_index in encode_id:
|
| 371 |
+
encode_id = tokenizer_image_token_qwen(encode_id, tokenizer, image_token_index,image_token_num=self.image_token_num)
|
| 372 |
+
|
| 373 |
+
input_id += encode_id
|
| 374 |
+
if role in ["user", "system"]:
|
| 375 |
+
target += [IGNORE_INDEX] * len(encode_id)
|
| 376 |
+
else:
|
| 377 |
+
target += encode_id
|
| 378 |
+
|
| 379 |
+
|
| 380 |
+
assert len(input_id) == len(target), f"{len(input_id)} != {len(target)}"
|
| 381 |
+
for idx, encode_id in enumerate(input_id):
|
| 382 |
+
if encode_id in unmask_tokens_idx:
|
| 383 |
+
target[idx] = encode_id
|
| 384 |
+
if encode_id == image_token_index:
|
| 385 |
+
input_id[idx] = IMAGE_TOKEN_INDEX
|
| 386 |
+
input_ids.append(input_id)
|
| 387 |
+
targets.append(target)
|
| 388 |
+
input_ids = torch.tensor(input_ids, dtype=torch.long)
|
| 389 |
+
targets = torch.tensor(targets, dtype=torch.long)
|
| 390 |
+
return dict(
|
| 391 |
+
input_ids=input_ids,
|
| 392 |
+
labels=targets,
|
| 393 |
+
)
|
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=576):
|
| 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,200 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import os
|
| 3 |
+
import asyncio
|
| 4 |
+
import requests
|
| 5 |
+
from io import BytesIO
|
| 6 |
+
from PIL import Image
|
| 7 |
+
from urllib.parse import urlparse
|
| 8 |
+
import numpy as np
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def split_image_ur(img, max_slice_num, image_size, vit_image_size, force_min_size=False):
|
| 12 |
+
if force_min_size:
|
| 13 |
+
img = resize_by_patch_size_ur(img, min_size= image_size, max_size= image_size * max_slice_num, patch_size=14)
|
| 14 |
+
slice_config = {
|
| 15 |
+
"max_slice_nums": max_slice_num,
|
| 16 |
+
"scale_resolution": image_size,
|
| 17 |
+
"patch_size": 14
|
| 18 |
+
}
|
| 19 |
+
source_image, sub_images, _ = do_slice_by_minicpmv_strategy_ur(
|
| 20 |
+
img, max_slice_nums=slice_config["max_slice_nums"], scale_resolution=slice_config["scale_resolution"], patch_size=slice_config["patch_size"], vit_image_size=vit_image_size)
|
| 21 |
+
splits = []
|
| 22 |
+
splits.append(source_image)
|
| 23 |
+
for i in range(len(sub_images)):
|
| 24 |
+
for j in range(len(sub_images[0])):
|
| 25 |
+
splits.append(sub_images[i][j])
|
| 26 |
+
sliced_images, sliced_shapes = [], []
|
| 27 |
+
for slice_image in splits:
|
| 28 |
+
sliced_images.append(slice_image)
|
| 29 |
+
sliced_shapes.append(np.array((slice_image.size[0] // slice_config["patch_size"], slice_image.size[1] // slice_config["patch_size"])))
|
| 30 |
+
|
| 31 |
+
return sliced_images, sliced_shapes
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
import math
|
| 35 |
+
from PIL import Image
|
| 36 |
+
import torch
|
| 37 |
+
import torchvision.transforms.functional as F
|
| 38 |
+
from torchvision.transforms import InterpolationMode
|
| 39 |
+
|
| 40 |
+
# Strategy: MiniCPM-V
|
| 41 |
+
def do_slice_by_minicpmv_strategy_ur(image, max_slice_nums=9, scale_resolution=1120, patch_size=14, vit_image_size=448, never_split=False):
|
| 42 |
+
|
| 43 |
+
original_size = image.size
|
| 44 |
+
original_width, original_height = original_size
|
| 45 |
+
log_ratio = math.log(original_width / original_height)
|
| 46 |
+
ratio = original_width * original_height / (scale_resolution * scale_resolution)
|
| 47 |
+
multiple = min(math.ceil(ratio), max_slice_nums)
|
| 48 |
+
|
| 49 |
+
source_image = None
|
| 50 |
+
best_grid = None
|
| 51 |
+
patches = []
|
| 52 |
+
|
| 53 |
+
if multiple <= 1 or never_split:
|
| 54 |
+
# dont need to slice, upsample
|
| 55 |
+
# best_size = find_best_resize(
|
| 56 |
+
# original_size, scale_resolution, patch_size, allow_upscale=True
|
| 57 |
+
# )
|
| 58 |
+
best_size = (scale_resolution, scale_resolution)
|
| 59 |
+
source_image = image.resize(best_size, Image.BICUBIC)
|
| 60 |
+
border_size = (vit_image_size-scale_resolution)/2
|
| 61 |
+
from PIL import ImageOps
|
| 62 |
+
source_image = ImageOps.expand(source_image, border=int(border_size), fill=(0,0,0))
|
| 63 |
+
else:
|
| 64 |
+
candidate_split_grids_nums = []
|
| 65 |
+
for i in [multiple - 1, multiple, multiple + 1]:
|
| 66 |
+
if i == 1 or i > max_slice_nums:
|
| 67 |
+
continue
|
| 68 |
+
candidate_split_grids_nums.append(i)
|
| 69 |
+
|
| 70 |
+
# source image, down-sampling and ensure divided by patch_size
|
| 71 |
+
# best_resize = find_best_resize(original_size, scale_resolution, patch_size)
|
| 72 |
+
# source_image = image.copy().resize(best_resize, Image.BICUBIC)
|
| 73 |
+
source_image = image.copy().resize((scale_resolution,scale_resolution), Image.BICUBIC)
|
| 74 |
+
candidate_grids = []
|
| 75 |
+
|
| 76 |
+
# find best grid
|
| 77 |
+
for split_grids_nums in candidate_split_grids_nums:
|
| 78 |
+
m = 1
|
| 79 |
+
while m <= split_grids_nums:
|
| 80 |
+
if split_grids_nums % m == 0:
|
| 81 |
+
candidate_grids.append([m, split_grids_nums // m])
|
| 82 |
+
m += 1
|
| 83 |
+
# print("candidate_grids: ", candidate_grids)
|
| 84 |
+
|
| 85 |
+
best_grid = [1, 1]
|
| 86 |
+
min_error = float("inf")
|
| 87 |
+
for grid in candidate_grids:
|
| 88 |
+
error = abs(log_ratio - math.log(grid[0] / grid[1]))
|
| 89 |
+
if error < min_error:
|
| 90 |
+
best_grid = grid
|
| 91 |
+
min_error = error
|
| 92 |
+
|
| 93 |
+
refine_size = get_refine_size(
|
| 94 |
+
original_size, best_grid, scale_resolution, patch_size, allow_upscale=True
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
refine_image = image.resize(refine_size, Image.BICUBIC)
|
| 98 |
+
patches = split_to_patches(refine_image, best_grid, scale_resolution, vit_image_size)
|
| 99 |
+
|
| 100 |
+
return source_image, patches, best_grid
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def ensure_divide(length, patch_size):
|
| 104 |
+
return max(round(length / patch_size) * patch_size, patch_size)
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def find_best_resize(original_size, scale_resolution, patch_size, allow_upscale=False):
|
| 108 |
+
width, height = original_size
|
| 109 |
+
if (width * height > scale_resolution * scale_resolution) or allow_upscale:
|
| 110 |
+
r = width / height
|
| 111 |
+
height = int(scale_resolution / math.sqrt(r))
|
| 112 |
+
width = int(height * r)
|
| 113 |
+
best_width = ensure_divide(width, patch_size)
|
| 114 |
+
best_height = ensure_divide(height, patch_size)
|
| 115 |
+
|
| 116 |
+
# print(best_width, best_height, scale_resolution)
|
| 117 |
+
while best_width * best_height > scale_resolution ** 2:
|
| 118 |
+
# print(best_width)
|
| 119 |
+
best_width -= patch_size
|
| 120 |
+
|
| 121 |
+
return (best_width, best_height)
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
def get_refine_size(original_size, grid, scale_resolution, patch_size, allow_upscale=False):
|
| 125 |
+
width, height = original_size
|
| 126 |
+
grid_x, grid_y = grid
|
| 127 |
+
|
| 128 |
+
# refine_width = ensure_divide(width, grid_x)
|
| 129 |
+
# refine_height = ensure_divide(height, grid_y)
|
| 130 |
+
|
| 131 |
+
# grid_width = refine_width / grid_x
|
| 132 |
+
# grid_height = refine_height / grid_y
|
| 133 |
+
|
| 134 |
+
# best_grid_size = find_best_resize(
|
| 135 |
+
# (grid_width, grid_height),
|
| 136 |
+
# scale_resolution,
|
| 137 |
+
# patch_size,
|
| 138 |
+
# allow_upscale=allow_upscale,
|
| 139 |
+
# )
|
| 140 |
+
|
| 141 |
+
refine_size = (scale_resolution * grid_x, scale_resolution * grid_y)
|
| 142 |
+
|
| 143 |
+
return refine_size
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
def split_to_patches(image, grid, scale_resolution, vit_image_size):
|
| 147 |
+
patches = []
|
| 148 |
+
width, height = image.size
|
| 149 |
+
grid_x = int(width / grid[0])
|
| 150 |
+
grid_y = int(height / grid[1])
|
| 151 |
+
|
| 152 |
+
from PIL import ImageOps
|
| 153 |
+
border_size = (vit_image_size - scale_resolution)/2
|
| 154 |
+
padded_img = ImageOps.expand(image, border=int(border_size), fill=(0,0,0))
|
| 155 |
+
padded_width, padded_height = padded_img.size
|
| 156 |
+
for i in range(0, padded_height-vit_image_size+1, scale_resolution):
|
| 157 |
+
images = []
|
| 158 |
+
for j in range(0, padded_width-vit_image_size+1, scale_resolution):
|
| 159 |
+
box = (j, i, j + vit_image_size, i + vit_image_size)
|
| 160 |
+
patch = padded_img.crop(box)
|
| 161 |
+
images.append(patch)
|
| 162 |
+
patches.append(images)
|
| 163 |
+
|
| 164 |
+
return patches
|
| 165 |
+
|
| 166 |
+
def resize_by_patch_size_ur(img, min_size=1152, max_size=2240, patch_size=14):
|
| 167 |
+
interpolation=InterpolationMode.BICUBIC
|
| 168 |
+
# min_size=756, max_size=756 * 4, patch_size=14
|
| 169 |
+
if isinstance(img, torch.Tensor):
|
| 170 |
+
height, width = img.shape[:2]
|
| 171 |
+
else:
|
| 172 |
+
width, height = img.size
|
| 173 |
+
|
| 174 |
+
# Check if the shorter side is less than min_size
|
| 175 |
+
if min(height, width) < min_size:
|
| 176 |
+
# print('less than min_size')
|
| 177 |
+
scale_factor = min_size / min(height, width)
|
| 178 |
+
new_height = max(min_size, round(height * scale_factor))
|
| 179 |
+
new_width = max(min_size, round(width * scale_factor))
|
| 180 |
+
# print(self.max_size)
|
| 181 |
+
|
| 182 |
+
# Check if the longer side after resizing is greater than max_size
|
| 183 |
+
if max(new_height, new_width) > max_size:
|
| 184 |
+
scale_factor = max_size / max(new_height, new_width)
|
| 185 |
+
new_height = min(max_size, round(new_height * scale_factor))
|
| 186 |
+
new_width = min(max_size, round(new_width * scale_factor))
|
| 187 |
+
else:
|
| 188 |
+
scale_factor = min(max_size / max(height, width), 1)
|
| 189 |
+
new_height = round(height * scale_factor)
|
| 190 |
+
new_width = round(width * scale_factor)
|
| 191 |
+
|
| 192 |
+
# # Make sure the new height and width are divisible by patch_size
|
| 193 |
+
# new_height = (new_height // patch_size) * patch_size
|
| 194 |
+
# new_width = (new_width // patch_size) * patch_size
|
| 195 |
+
|
| 196 |
+
# Resize the image
|
| 197 |
+
# img = F.resize(img, (new_height, new_width), interpolation)
|
| 198 |
+
img = img.resize((new_width, new_height), Image.BICUBIC)
|
| 199 |
+
|
| 200 |
+
return img
|
vocab.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|