Upload models
Browse files- .DS_Store +0 -0
- added_tokens.json +39 -0
- chat_template.json +3 -0
- config.json +84 -0
- configuration_eagle3_vl.py +94 -0
- generation_config.json +6 -0
- image_processing_eagle3_vl_fast.py +221 -0
- merge_report.json +20 -0
- merges.txt +0 -0
- model.safetensors +3 -0
- model.safetensors.index.json +772 -0
- modeling_eagle3_vl.py +415 -0
- modeling_siglip2.py +1419 -0
- preprocessor_config.json +36 -0
- processing_eagle3_vl.py +905 -0
- processor_config.json +14 -0
- special_tokens_map.json +42 -0
- tokenizer_config.json +344 -0
- vocab.json +0 -0
.DS_Store
ADDED
|
Binary file (8.2 kB). View file
|
|
|
added_tokens.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"</box>": 151673,
|
| 3 |
+
"</img>": 151671,
|
| 4 |
+
"</interval>": 151679,
|
| 5 |
+
"</quad>": 151675,
|
| 6 |
+
"</ref>": 151677,
|
| 7 |
+
"</think>": 151668,
|
| 8 |
+
"</tool_call>": 151658,
|
| 9 |
+
"</tool_response>": 151666,
|
| 10 |
+
"<IMG_CONTEXT>": 151669,
|
| 11 |
+
"<box>": 151672,
|
| 12 |
+
"<img>": 151670,
|
| 13 |
+
"<interval>": 151678,
|
| 14 |
+
"<quad>": 151674,
|
| 15 |
+
"<ref>": 151676,
|
| 16 |
+
"<think>": 151667,
|
| 17 |
+
"<tool_call>": 151657,
|
| 18 |
+
"<tool_response>": 151665,
|
| 19 |
+
"<|box_end|>": 151649,
|
| 20 |
+
"<|box_start|>": 151648,
|
| 21 |
+
"<|endoftext|>": 151643,
|
| 22 |
+
"<|file_sep|>": 151664,
|
| 23 |
+
"<|fim_middle|>": 151660,
|
| 24 |
+
"<|fim_pad|>": 151662,
|
| 25 |
+
"<|fim_prefix|>": 151659,
|
| 26 |
+
"<|fim_suffix|>": 151661,
|
| 27 |
+
"<|im_end|>": 151645,
|
| 28 |
+
"<|im_start|>": 151644,
|
| 29 |
+
"<|image_pad|>": 151655,
|
| 30 |
+
"<|object_ref_end|>": 151647,
|
| 31 |
+
"<|object_ref_start|>": 151646,
|
| 32 |
+
"<|quad_end|>": 151651,
|
| 33 |
+
"<|quad_start|>": 151650,
|
| 34 |
+
"<|repo_name|>": 151663,
|
| 35 |
+
"<|video_pad|>": 151656,
|
| 36 |
+
"<|vision_end|>": 151653,
|
| 37 |
+
"<|vision_pad|>": 151654,
|
| 38 |
+
"<|vision_start|>": 151652
|
| 39 |
+
}
|
chat_template.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"chat_template": "{% set image_count = namespace(value=0) %}{% set video_count = namespace(value=0) %}{% for message in messages %}{% if loop.first and message['role'] != 'system' %}<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n{% endif %}<|im_start|>{{ message['role'] }}\n{% if message['content'] is string %}{{ message['content'] }}<|im_end|>\n{% else %}{% for content in message['content'] %}{% if content['type'] == 'image' or 'image' in content or 'image_url' in content %}{% set image_count.value = image_count.value + 1 %}{% if add_vision_id %}<image {{ image_count.value }}>{% endif %}<image-{{ image_count.value }}>{% elif content['type'] == 'video' or 'video' in content %}{% set video_count.value = video_count.value + 1 %}{% if add_vision_id %}<video {{ video_count.value }}>{% endif %}<video-{{ video_count.value }}>{% elif 'text' in content %}{{ content['text'] }}{% endif %}{% endfor %}<|im_end|>\n{% endif %}{% endfor %}{% if add_generation_prompt %}<|im_start|>assistant\n{% endif %}"
|
| 3 |
+
}
|
config.json
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_attn_implementation": "flash_attention_2",
|
| 3 |
+
"_commit_hash": "950beaa7db5649958a88c9565837d32e3e6a7543",
|
| 4 |
+
"architectures": [
|
| 5 |
+
"Eagle3_VLForConditionalGeneration"
|
| 6 |
+
],
|
| 7 |
+
"auto_map": {
|
| 8 |
+
"AutoConfig": "configuration_eagle3_vl.Eagle3_VLConfig",
|
| 9 |
+
"AutoModel": "modeling_eagle3_vl.Eagle3_VLForConditionalGeneration",
|
| 10 |
+
"AutoModelForCausalLM": "modeling_eagle3_vl.Eagle3_VLForConditionalGeneration"
|
| 11 |
+
},
|
| 12 |
+
"downsample_ratio": 0.5,
|
| 13 |
+
"dynamic_image_size": false,
|
| 14 |
+
"image_token_index": 151669,
|
| 15 |
+
"loss_version": "efficient_v2_cp_head",
|
| 16 |
+
"max_dynamic_tiles": 12,
|
| 17 |
+
"min_dynamic_tiles": 1,
|
| 18 |
+
"mlp_checkpoint": false,
|
| 19 |
+
"mlp_connector_layers": 2,
|
| 20 |
+
"model_type": "eagle_3_vl",
|
| 21 |
+
"pad2square": false,
|
| 22 |
+
"select_layer": -1,
|
| 23 |
+
"text_config": {
|
| 24 |
+
"_attn_implementation_autoset": true,
|
| 25 |
+
"_name_or_path": "Qwen/Qwen3-1.7B",
|
| 26 |
+
"architectures": [
|
| 27 |
+
"Qwen3ForCausalLM"
|
| 28 |
+
],
|
| 29 |
+
"attention_bias": false,
|
| 30 |
+
"attention_dropout": 0.0,
|
| 31 |
+
"bos_token_id": 151643,
|
| 32 |
+
"eos_token_id": 151645,
|
| 33 |
+
"head_dim": 128,
|
| 34 |
+
"hidden_act": "silu",
|
| 35 |
+
"hidden_size": 2048,
|
| 36 |
+
"initializer_range": 0.02,
|
| 37 |
+
"intermediate_size": 6144,
|
| 38 |
+
"max_position_embeddings": 40960,
|
| 39 |
+
"max_window_layers": 28,
|
| 40 |
+
"model_type": "qwen3",
|
| 41 |
+
"num_attention_heads": 16,
|
| 42 |
+
"num_hidden_layers": 28,
|
| 43 |
+
"num_key_value_heads": 8,
|
| 44 |
+
"rms_norm_eps": 1e-06,
|
| 45 |
+
"rope_scaling": null,
|
| 46 |
+
"rope_theta": 1000000,
|
| 47 |
+
"sliding_window": null,
|
| 48 |
+
"tie_word_embeddings": true,
|
| 49 |
+
"torch_dtype": "bfloat16",
|
| 50 |
+
"use_cache": false,
|
| 51 |
+
"use_sliding_window": false,
|
| 52 |
+
"vocab_size": 151680
|
| 53 |
+
},
|
| 54 |
+
"torch_dtype": "bfloat16",
|
| 55 |
+
"transformers_version": null,
|
| 56 |
+
"use_backbone_lora": 0,
|
| 57 |
+
"use_llm_lora": 0,
|
| 58 |
+
"use_pixel_shuffle": true,
|
| 59 |
+
"use_thumbnail": false,
|
| 60 |
+
"vision_config": {
|
| 61 |
+
"_attn_implementation_autoset": true,
|
| 62 |
+
"attention_dropout": 0.0,
|
| 63 |
+
"full_attention_indexes": [
|
| 64 |
+
7,
|
| 65 |
+
14,
|
| 66 |
+
21,
|
| 67 |
+
26
|
| 68 |
+
],
|
| 69 |
+
"hidden_act": "gelu_pytorch_tanh",
|
| 70 |
+
"hidden_size": 1152,
|
| 71 |
+
"intermediate_size": 4304,
|
| 72 |
+
"layer_norm_eps": 1e-06,
|
| 73 |
+
"model_type": "siglip2_vision_model",
|
| 74 |
+
"num_attention_heads": 16,
|
| 75 |
+
"num_channels": 3,
|
| 76 |
+
"num_hidden_layers": 27,
|
| 77 |
+
"num_patches": 256,
|
| 78 |
+
"patch_size": 14,
|
| 79 |
+
"torch_dtype": "bfloat16",
|
| 80 |
+
"use_rope": false,
|
| 81 |
+
"use_windows_attn": false,
|
| 82 |
+
"window_size": 14
|
| 83 |
+
}
|
| 84 |
+
}
|
configuration_eagle3_vl.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import copy
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
from transformers.models.qwen2.configuration_qwen2 import Qwen2Config
|
| 5 |
+
from transformers.models.qwen3.configuration_qwen3 import Qwen3Config
|
| 6 |
+
from transformers.configuration_utils import PretrainedConfig
|
| 7 |
+
from transformers.utils import logging
|
| 8 |
+
from transformers.models.siglip.configuration_siglip import SiglipVisionConfig
|
| 9 |
+
from .modeling_siglip2 import Siglip2VisionConfig
|
| 10 |
+
|
| 11 |
+
logger = logging.get_logger(__name__)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class Eagle3_VLConfig(PretrainedConfig):
|
| 15 |
+
model_type = 'eagle_3_vl'
|
| 16 |
+
is_composition = True
|
| 17 |
+
sub_configs = {"vision_config": SiglipVisionConfig, "text_config": Qwen2Config}
|
| 18 |
+
def __init__(
|
| 19 |
+
self,
|
| 20 |
+
vision_config=None,
|
| 21 |
+
text_config=None,
|
| 22 |
+
use_backbone_lora=0,
|
| 23 |
+
use_llm_lora=0,
|
| 24 |
+
pad2square=False,
|
| 25 |
+
select_layer=-4,
|
| 26 |
+
downsample_ratio=0.5,
|
| 27 |
+
template=None,
|
| 28 |
+
loss_version='v1',
|
| 29 |
+
mlp_checkpoint=False,
|
| 30 |
+
image_token_index=151667,
|
| 31 |
+
**kwargs):
|
| 32 |
+
super().__init__(**kwargs)
|
| 33 |
+
|
| 34 |
+
if vision_config is None:
|
| 35 |
+
vision_config = {'model_type': 'siglip_vision_model'}
|
| 36 |
+
logger.info('vision_config is None. Initializing the InternVisionConfig with default values.')
|
| 37 |
+
|
| 38 |
+
if text_config is None:
|
| 39 |
+
text_config = {'architectures': ['Qwen2ForCausalLM']}
|
| 40 |
+
logger.info('text_config is None. Initializing the LlamaConfig config with default values (`LlamaConfig`).')
|
| 41 |
+
|
| 42 |
+
if vision_config['model_type'] == 'siglip_vision_model':
|
| 43 |
+
self.vision_config = SiglipVisionConfig(**vision_config)
|
| 44 |
+
elif vision_config['model_type'] == 'siglip2_vision_model':
|
| 45 |
+
self.vision_config = Siglip2VisionConfig(**vision_config)
|
| 46 |
+
elif vision_config['model_type'] == 'intern_vit_6b':
|
| 47 |
+
self.vision_config = InternVisionConfig(**vision_config)
|
| 48 |
+
elif vision_config['model_type'] == 'radio':
|
| 49 |
+
self.vision_config = RADIOConfig(**vision_config)
|
| 50 |
+
else:
|
| 51 |
+
raise ValueError('Unsupported model_type: {}'.format(vision_config['model_type']))
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
if text_config['architectures'][0] == 'LlamaForCausalLM':
|
| 55 |
+
self.text_config = LlamaConfig(**text_config)
|
| 56 |
+
elif text_config['architectures'][0] == 'Phi3ForCausalLM':
|
| 57 |
+
self.text_config = Phi3Config(**text_config)
|
| 58 |
+
elif text_config['architectures'][0] == 'Qwen2ForCausalLM':
|
| 59 |
+
self.text_config = Qwen2Config(**text_config)
|
| 60 |
+
elif text_config['architectures'][0] == 'Qwen3ForCausalLM':
|
| 61 |
+
self.text_config = Qwen3Config(**text_config)
|
| 62 |
+
else:
|
| 63 |
+
raise ValueError('Unsupported architecture: {}'.format(text_config['architectures'][0]))
|
| 64 |
+
self.use_backbone_lora = use_backbone_lora
|
| 65 |
+
self.use_llm_lora = use_llm_lora
|
| 66 |
+
self.mlp_checkpoint = mlp_checkpoint
|
| 67 |
+
self.pad2square = pad2square
|
| 68 |
+
self.select_layer = select_layer
|
| 69 |
+
self.downsample_ratio = downsample_ratio
|
| 70 |
+
self.template = template
|
| 71 |
+
self.loss_version = loss_version
|
| 72 |
+
self.tie_word_embeddings = self.text_config.tie_word_embeddings
|
| 73 |
+
self.image_token_index = image_token_index
|
| 74 |
+
|
| 75 |
+
def to_dict(self):
|
| 76 |
+
"""
|
| 77 |
+
Serializes this instance to a Python dictionary. Override the default [`~PretrainedConfig.to_dict`].
|
| 78 |
+
|
| 79 |
+
Returns:
|
| 80 |
+
`Dict[str, any]`: Dictionary of all the attributes that make up this configuration instance,
|
| 81 |
+
"""
|
| 82 |
+
output = copy.deepcopy(self.__dict__)
|
| 83 |
+
output['vision_config'] = self.vision_config.to_dict()
|
| 84 |
+
output['text_config'] = self.text_config.to_dict()
|
| 85 |
+
output['model_type'] = self.__class__.model_type
|
| 86 |
+
output['use_backbone_lora'] = self.use_backbone_lora
|
| 87 |
+
output['use_llm_lora'] = self.use_llm_lora
|
| 88 |
+
output['select_layer'] = self.select_layer
|
| 89 |
+
output['downsample_ratio'] = self.downsample_ratio
|
| 90 |
+
output['template'] = self.template
|
| 91 |
+
output['image_token_index'] = self.image_token_index
|
| 92 |
+
output['_attn_implementation'] = self._attn_implementation
|
| 93 |
+
output['_attn_implementation_autoset'] = self._attn_implementation_autoset
|
| 94 |
+
return output
|
generation_config.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"bos_token_id": 151643,
|
| 4 |
+
"eos_token_id": 151645,
|
| 5 |
+
"transformers_version": "4.51.0"
|
| 6 |
+
}
|
image_processing_eagle3_vl_fast.py
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# --------------------------------------------------------
|
| 2 |
+
# NVIDIA
|
| 3 |
+
# Copyright (c) 2025 NVIDIA
|
| 4 |
+
# Licensed under The MIT License [see LICENSE for details]
|
| 5 |
+
# --------------------------------------------------------
|
| 6 |
+
|
| 7 |
+
# copy from https://github.com/huggingface/transformers/blob/main/src/transformers/models/llava_onevision/image_processing_llava_onevision_fast.py
|
| 8 |
+
from typing import List, Optional, Union
|
| 9 |
+
|
| 10 |
+
from transformers.image_processing_utils import BatchFeature, get_patch_output_size, select_best_resolution
|
| 11 |
+
from transformers.image_processing_utils_fast import (
|
| 12 |
+
BASE_IMAGE_PROCESSOR_FAST_DOCSTRING,
|
| 13 |
+
BASE_IMAGE_PROCESSOR_FAST_DOCSTRING_PREPROCESS,
|
| 14 |
+
BaseImageProcessorFast,
|
| 15 |
+
DefaultFastImageProcessorKwargs,
|
| 16 |
+
divide_to_patches,
|
| 17 |
+
group_images_by_shape,
|
| 18 |
+
reorder_images,
|
| 19 |
+
)
|
| 20 |
+
from transformers.image_utils import (
|
| 21 |
+
OPENAI_CLIP_MEAN,
|
| 22 |
+
OPENAI_CLIP_STD,
|
| 23 |
+
IMAGENET_STANDARD_MEAN, # 0.5, 0.5, 0.5
|
| 24 |
+
IMAGENET_STANDARD_STD, # 0.5, 0.5, 0.5
|
| 25 |
+
ChannelDimension,
|
| 26 |
+
ImageInput,
|
| 27 |
+
VideoInput,
|
| 28 |
+
PILImageResampling,
|
| 29 |
+
SizeDict,
|
| 30 |
+
get_image_size,
|
| 31 |
+
make_flat_list_of_images,
|
| 32 |
+
make_batched_videos,
|
| 33 |
+
validate_kwargs
|
| 34 |
+
)
|
| 35 |
+
from transformers.processing_utils import Unpack
|
| 36 |
+
from transformers.utils import TensorType, add_start_docstrings, is_torch_available, is_torchvision_v2_available
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
if is_torch_available():
|
| 40 |
+
import torch
|
| 41 |
+
if is_torchvision_v2_available():
|
| 42 |
+
from transformers.image_utils import pil_torch_interpolation_mapping
|
| 43 |
+
|
| 44 |
+
from torchvision.transforms.v2 import functional as F
|
| 45 |
+
else:
|
| 46 |
+
from torchvision.transforms import functional as F
|
| 47 |
+
|
| 48 |
+
def crop(img: torch.Tensor, left: int, top: int, right: int, bottom: int) -> torch.Tensor:
|
| 49 |
+
"""Crop the given numpy array.
|
| 50 |
+
|
| 51 |
+
Args:
|
| 52 |
+
img (torch.Tensor): Image to be cropped. Format should be (C, H, W).
|
| 53 |
+
left (int): The left coordinate of the crop box.
|
| 54 |
+
top (int): The top coordinate of the crop box.
|
| 55 |
+
right (int): The right coordinate of the crop box.
|
| 56 |
+
bottom (int): The bottom coordinate of the crop box.
|
| 57 |
+
|
| 58 |
+
Returns:
|
| 59 |
+
torch.Tensor: Cropped image.
|
| 60 |
+
"""
|
| 61 |
+
if not isinstance(img, torch.Tensor):
|
| 62 |
+
raise TypeError('img should be torch.Tensor. Got {}'.format(type(img)))
|
| 63 |
+
|
| 64 |
+
if img.ndim not in [2, 3]:
|
| 65 |
+
raise ValueError('Image should have 2 or 3 dimensions. Got {}'.format(img.ndim))
|
| 66 |
+
|
| 67 |
+
img_height = img.shape[1]
|
| 68 |
+
img_width = img.shape[2]
|
| 69 |
+
if top < 0 or left < 0 or bottom > img_height or right > img_width:
|
| 70 |
+
raise ValueError('Crop coordinates out of bounds')
|
| 71 |
+
|
| 72 |
+
if top >= bottom or left >= right:
|
| 73 |
+
raise ValueError('Invalid crop coordinates')
|
| 74 |
+
|
| 75 |
+
return img[:, top:bottom, left:right]
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
class Eagle3_VLFastImageProcessorKwargs(DefaultFastImageProcessorKwargs):
|
| 79 |
+
do_pad: Optional[bool]
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
@add_start_docstrings(
|
| 83 |
+
"Constructs a fast ConvNeXT image processor. Based on [`SiglipImageProcessor`] with incorporation of processing each video frame.",
|
| 84 |
+
BASE_IMAGE_PROCESSOR_FAST_DOCSTRING,
|
| 85 |
+
"""
|
| 86 |
+
image_grid_pinpoints (`List[List[int]]`, *optional*):
|
| 87 |
+
A list of possible resolutions to use for processing high resolution images. The best resolution is selected
|
| 88 |
+
based on the original size of the image. Can be overridden by `image_grid_pinpoints` in the `preprocess`
|
| 89 |
+
method. Not used for processing videos.
|
| 90 |
+
do_pad (`bool`, *optional*):
|
| 91 |
+
Whether to pad the image. If `True`, will pad the patch dimension of the images in the batch to the largest
|
| 92 |
+
number of patches in the batch. Padding will be applied to the bottom and right with zeros.
|
| 93 |
+
""",
|
| 94 |
+
)
|
| 95 |
+
class Eagle3_VLImageProcessorFast(BaseImageProcessorFast):
|
| 96 |
+
resample = PILImageResampling.BICUBIC
|
| 97 |
+
image_mean = IMAGENET_STANDARD_MEAN
|
| 98 |
+
image_std = IMAGENET_STANDARD_STD
|
| 99 |
+
size = {"height": 448, "width": 448}
|
| 100 |
+
default_to_square = False
|
| 101 |
+
crop_size = None
|
| 102 |
+
do_resize = True
|
| 103 |
+
do_center_crop = None
|
| 104 |
+
do_rescale = True
|
| 105 |
+
do_normalize = True
|
| 106 |
+
do_convert_rgb = True
|
| 107 |
+
do_pad = True
|
| 108 |
+
valid_kwargs = Eagle3_VLFastImageProcessorKwargs
|
| 109 |
+
model_input_names = ["pixel_values_videos"]
|
| 110 |
+
|
| 111 |
+
def __init__(self, **kwargs: Unpack[Eagle3_VLFastImageProcessorKwargs]):
|
| 112 |
+
super().__init__(**kwargs)
|
| 113 |
+
|
| 114 |
+
@add_start_docstrings(
|
| 115 |
+
BASE_IMAGE_PROCESSOR_FAST_DOCSTRING_PREPROCESS,
|
| 116 |
+
"""
|
| 117 |
+
do_pad (`bool`, *optional*):
|
| 118 |
+
Whether to pad the image. If `True`, will pad the patch dimension of the images in the batch to the largest
|
| 119 |
+
number of patches in the batch. Padding will be applied to the bottom and right with zeros.
|
| 120 |
+
""",
|
| 121 |
+
)
|
| 122 |
+
def preprocess(self, images: ImageInput, **kwargs: Unpack[Eagle3_VLFastImageProcessorKwargs]) -> BatchFeature:
|
| 123 |
+
return super().preprocess(images, **kwargs)
|
| 124 |
+
|
| 125 |
+
def _prepare_images_structure(
|
| 126 |
+
self,
|
| 127 |
+
images: ImageInput,
|
| 128 |
+
) -> ImageInput:
|
| 129 |
+
"""
|
| 130 |
+
Prepare the images structure for processing.
|
| 131 |
+
|
| 132 |
+
Args:
|
| 133 |
+
images (`ImageInput`):
|
| 134 |
+
The input images to process.
|
| 135 |
+
|
| 136 |
+
Returns:
|
| 137 |
+
`ImageInput`: The images with a valid nesting.
|
| 138 |
+
"""
|
| 139 |
+
return make_flat_list_of_images(images)
|
| 140 |
+
|
| 141 |
+
def _preprocess(
|
| 142 |
+
self,
|
| 143 |
+
images: List["torch.Tensor"],
|
| 144 |
+
do_resize: bool,
|
| 145 |
+
size: SizeDict,
|
| 146 |
+
interpolation: Optional["F.InterpolationMode"],
|
| 147 |
+
do_center_crop: bool,
|
| 148 |
+
crop_size: SizeDict,
|
| 149 |
+
do_rescale: bool,
|
| 150 |
+
rescale_factor: float,
|
| 151 |
+
do_normalize: bool,
|
| 152 |
+
image_mean: Optional[Union[float, List[float]]],
|
| 153 |
+
image_std: Optional[Union[float, List[float]]],
|
| 154 |
+
do_pad: bool,
|
| 155 |
+
return_tensors: Optional[Union[str, TensorType]],
|
| 156 |
+
) -> BatchFeature:
|
| 157 |
+
|
| 158 |
+
image_sizes = [get_image_size(image, channel_dim=ChannelDimension.FIRST) for image in images]
|
| 159 |
+
|
| 160 |
+
# Group images by size for further processing
|
| 161 |
+
# Needed in case do_resize is False, or resize returns images with different sizes
|
| 162 |
+
grouped_images, grouped_images_index = group_images_by_shape(images)
|
| 163 |
+
processed_images_grouped = {}
|
| 164 |
+
for shape, stacked_images in grouped_images.items():
|
| 165 |
+
# Fused rescale and normalize
|
| 166 |
+
stacked_images = self.rescale_and_normalize(
|
| 167 |
+
stacked_images, do_rescale, rescale_factor, do_normalize, image_mean, image_std
|
| 168 |
+
)
|
| 169 |
+
processed_images_grouped[shape] = stacked_images
|
| 170 |
+
|
| 171 |
+
processed_images = reorder_images(processed_images_grouped, grouped_images_index)
|
| 172 |
+
processed_images = torch.stack(processed_images)
|
| 173 |
+
|
| 174 |
+
return BatchFeature(
|
| 175 |
+
data={"pixel_values": processed_images, "image_sizes": image_sizes}, tensor_type=return_tensors
|
| 176 |
+
)
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
def preprocess(self, images: ImageInput, videos: VideoInput=None, **kwargs: Unpack[Eagle3_VLFastImageProcessorKwargs]) -> BatchFeature:
|
| 180 |
+
validate_kwargs(captured_kwargs=kwargs.keys(), valid_processor_keys=self.valid_kwargs.__annotations__.keys())
|
| 181 |
+
# Set default kwargs from self. This ensures that if a kwarg is not provided
|
| 182 |
+
# by the user, it gets its default value from the instance, or is set to None.
|
| 183 |
+
for kwarg_name in self.valid_kwargs.__annotations__:
|
| 184 |
+
kwargs.setdefault(kwarg_name, getattr(self, kwarg_name, None))
|
| 185 |
+
|
| 186 |
+
# Extract parameters that are only used for preparing the input images
|
| 187 |
+
do_convert_rgb = kwargs.pop("do_convert_rgb")
|
| 188 |
+
input_data_format = kwargs.pop("input_data_format")
|
| 189 |
+
device = kwargs.pop("device")
|
| 190 |
+
# Prepare input images
|
| 191 |
+
if images is not None:
|
| 192 |
+
images = self._prepare_input_images(
|
| 193 |
+
images=images, do_convert_rgb=do_convert_rgb, input_data_format=input_data_format, device=device
|
| 194 |
+
)
|
| 195 |
+
|
| 196 |
+
if videos is not None:
|
| 197 |
+
videos = self._prepare_input_images(
|
| 198 |
+
images=videos, do_convert_rgb=do_convert_rgb, input_data_format=input_data_format, device=device
|
| 199 |
+
)
|
| 200 |
+
|
| 201 |
+
# Update kwargs that need further processing before being validated
|
| 202 |
+
kwargs = self._further_process_kwargs(**kwargs)
|
| 203 |
+
|
| 204 |
+
# Validate kwargs
|
| 205 |
+
self._validate_preprocess_kwargs(**kwargs)
|
| 206 |
+
|
| 207 |
+
# torch resize uses interpolation instead of resample
|
| 208 |
+
resample = kwargs.pop("resample")
|
| 209 |
+
kwargs["interpolation"] = (
|
| 210 |
+
pil_torch_interpolation_mapping[resample] if isinstance(resample, (PILImageResampling, int)) else resample
|
| 211 |
+
)
|
| 212 |
+
|
| 213 |
+
# Pop kwargs that are not needed in _preprocess
|
| 214 |
+
kwargs.pop("default_to_square")
|
| 215 |
+
kwargs.pop("data_format")
|
| 216 |
+
if images is not None:
|
| 217 |
+
return self._preprocess(images, **kwargs)
|
| 218 |
+
elif videos is not None:
|
| 219 |
+
return self._preprocess(videos, **kwargs)
|
| 220 |
+
|
| 221 |
+
__all__ = ["Eagle3_VLImageProcessorFast"]
|
merge_report.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"copy_language_nonlayer_from_groot": false,
|
| 3 |
+
"eagle3_dir": "/sjw_alinlab1/home/byungwoo/Eagle3",
|
| 4 |
+
"groot_model_id": "nvidia/GR00T-N1.6-3B",
|
| 5 |
+
"groot_revision": null,
|
| 6 |
+
"max_llm_layer_from_groot": 15,
|
| 7 |
+
"output_dir": "/sjw_alinlab1/home/byungwoo/Eagle3_groot16_mix",
|
| 8 |
+
"qwen_model_id": "Qwen/Qwen3-1.7B",
|
| 9 |
+
"qwen_revision": null,
|
| 10 |
+
"stats": {
|
| 11 |
+
"groot_lm_selected": 176,
|
| 12 |
+
"groot_mlp_selected": 6,
|
| 13 |
+
"groot_selected": 630,
|
| 14 |
+
"groot_vision_selected": 448,
|
| 15 |
+
"manifest_total": 765,
|
| 16 |
+
"qwen_overridden_by_groot": 176,
|
| 17 |
+
"qwen_selected": 311
|
| 18 |
+
},
|
| 19 |
+
"written_tensors": 765
|
| 20 |
+
}
|
merges.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256: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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"metadata": {
|
| 3 |
+
"total_size": 4946130816
|
| 4 |
+
},
|
| 5 |
+
"weight_map": {
|
| 6 |
+
"language_model.lm_head.weight": "model.safetensors",
|
| 7 |
+
"language_model.model.embed_tokens.weight": "model.safetensors",
|
| 8 |
+
"language_model.model.layers.0.input_layernorm.weight": "model.safetensors",
|
| 9 |
+
"language_model.model.layers.0.mlp.down_proj.weight": "model.safetensors",
|
| 10 |
+
"language_model.model.layers.0.mlp.gate_proj.weight": "model.safetensors",
|
| 11 |
+
"language_model.model.layers.0.mlp.up_proj.weight": "model.safetensors",
|
| 12 |
+
"language_model.model.layers.0.post_attention_layernorm.weight": "model.safetensors",
|
| 13 |
+
"language_model.model.layers.0.self_attn.k_norm.weight": "model.safetensors",
|
| 14 |
+
"language_model.model.layers.0.self_attn.k_proj.weight": "model.safetensors",
|
| 15 |
+
"language_model.model.layers.0.self_attn.o_proj.weight": "model.safetensors",
|
| 16 |
+
"language_model.model.layers.0.self_attn.q_norm.weight": "model.safetensors",
|
| 17 |
+
"language_model.model.layers.0.self_attn.q_proj.weight": "model.safetensors",
|
| 18 |
+
"language_model.model.layers.0.self_attn.v_proj.weight": "model.safetensors",
|
| 19 |
+
"language_model.model.layers.1.input_layernorm.weight": "model.safetensors",
|
| 20 |
+
"language_model.model.layers.1.mlp.down_proj.weight": "model.safetensors",
|
| 21 |
+
"language_model.model.layers.1.mlp.gate_proj.weight": "model.safetensors",
|
| 22 |
+
"language_model.model.layers.1.mlp.up_proj.weight": "model.safetensors",
|
| 23 |
+
"language_model.model.layers.1.post_attention_layernorm.weight": "model.safetensors",
|
| 24 |
+
"language_model.model.layers.1.self_attn.k_norm.weight": "model.safetensors",
|
| 25 |
+
"language_model.model.layers.1.self_attn.k_proj.weight": "model.safetensors",
|
| 26 |
+
"language_model.model.layers.1.self_attn.o_proj.weight": "model.safetensors",
|
| 27 |
+
"language_model.model.layers.1.self_attn.q_norm.weight": "model.safetensors",
|
| 28 |
+
"language_model.model.layers.1.self_attn.q_proj.weight": "model.safetensors",
|
| 29 |
+
"language_model.model.layers.1.self_attn.v_proj.weight": "model.safetensors",
|
| 30 |
+
"language_model.model.layers.10.input_layernorm.weight": "model.safetensors",
|
| 31 |
+
"language_model.model.layers.10.mlp.down_proj.weight": "model.safetensors",
|
| 32 |
+
"language_model.model.layers.10.mlp.gate_proj.weight": "model.safetensors",
|
| 33 |
+
"language_model.model.layers.10.mlp.up_proj.weight": "model.safetensors",
|
| 34 |
+
"language_model.model.layers.10.post_attention_layernorm.weight": "model.safetensors",
|
| 35 |
+
"language_model.model.layers.10.self_attn.k_norm.weight": "model.safetensors",
|
| 36 |
+
"language_model.model.layers.10.self_attn.k_proj.weight": "model.safetensors",
|
| 37 |
+
"language_model.model.layers.10.self_attn.o_proj.weight": "model.safetensors",
|
| 38 |
+
"language_model.model.layers.10.self_attn.q_norm.weight": "model.safetensors",
|
| 39 |
+
"language_model.model.layers.10.self_attn.q_proj.weight": "model.safetensors",
|
| 40 |
+
"language_model.model.layers.10.self_attn.v_proj.weight": "model.safetensors",
|
| 41 |
+
"language_model.model.layers.11.input_layernorm.weight": "model.safetensors",
|
| 42 |
+
"language_model.model.layers.11.mlp.down_proj.weight": "model.safetensors",
|
| 43 |
+
"language_model.model.layers.11.mlp.gate_proj.weight": "model.safetensors",
|
| 44 |
+
"language_model.model.layers.11.mlp.up_proj.weight": "model.safetensors",
|
| 45 |
+
"language_model.model.layers.11.post_attention_layernorm.weight": "model.safetensors",
|
| 46 |
+
"language_model.model.layers.11.self_attn.k_norm.weight": "model.safetensors",
|
| 47 |
+
"language_model.model.layers.11.self_attn.k_proj.weight": "model.safetensors",
|
| 48 |
+
"language_model.model.layers.11.self_attn.o_proj.weight": "model.safetensors",
|
| 49 |
+
"language_model.model.layers.11.self_attn.q_norm.weight": "model.safetensors",
|
| 50 |
+
"language_model.model.layers.11.self_attn.q_proj.weight": "model.safetensors",
|
| 51 |
+
"language_model.model.layers.11.self_attn.v_proj.weight": "model.safetensors",
|
| 52 |
+
"language_model.model.layers.12.input_layernorm.weight": "model.safetensors",
|
| 53 |
+
"language_model.model.layers.12.mlp.down_proj.weight": "model.safetensors",
|
| 54 |
+
"language_model.model.layers.12.mlp.gate_proj.weight": "model.safetensors",
|
| 55 |
+
"language_model.model.layers.12.mlp.up_proj.weight": "model.safetensors",
|
| 56 |
+
"language_model.model.layers.12.post_attention_layernorm.weight": "model.safetensors",
|
| 57 |
+
"language_model.model.layers.12.self_attn.k_norm.weight": "model.safetensors",
|
| 58 |
+
"language_model.model.layers.12.self_attn.k_proj.weight": "model.safetensors",
|
| 59 |
+
"language_model.model.layers.12.self_attn.o_proj.weight": "model.safetensors",
|
| 60 |
+
"language_model.model.layers.12.self_attn.q_norm.weight": "model.safetensors",
|
| 61 |
+
"language_model.model.layers.12.self_attn.q_proj.weight": "model.safetensors",
|
| 62 |
+
"language_model.model.layers.12.self_attn.v_proj.weight": "model.safetensors",
|
| 63 |
+
"language_model.model.layers.13.input_layernorm.weight": "model.safetensors",
|
| 64 |
+
"language_model.model.layers.13.mlp.down_proj.weight": "model.safetensors",
|
| 65 |
+
"language_model.model.layers.13.mlp.gate_proj.weight": "model.safetensors",
|
| 66 |
+
"language_model.model.layers.13.mlp.up_proj.weight": "model.safetensors",
|
| 67 |
+
"language_model.model.layers.13.post_attention_layernorm.weight": "model.safetensors",
|
| 68 |
+
"language_model.model.layers.13.self_attn.k_norm.weight": "model.safetensors",
|
| 69 |
+
"language_model.model.layers.13.self_attn.k_proj.weight": "model.safetensors",
|
| 70 |
+
"language_model.model.layers.13.self_attn.o_proj.weight": "model.safetensors",
|
| 71 |
+
"language_model.model.layers.13.self_attn.q_norm.weight": "model.safetensors",
|
| 72 |
+
"language_model.model.layers.13.self_attn.q_proj.weight": "model.safetensors",
|
| 73 |
+
"language_model.model.layers.13.self_attn.v_proj.weight": "model.safetensors",
|
| 74 |
+
"language_model.model.layers.14.input_layernorm.weight": "model.safetensors",
|
| 75 |
+
"language_model.model.layers.14.mlp.down_proj.weight": "model.safetensors",
|
| 76 |
+
"language_model.model.layers.14.mlp.gate_proj.weight": "model.safetensors",
|
| 77 |
+
"language_model.model.layers.14.mlp.up_proj.weight": "model.safetensors",
|
| 78 |
+
"language_model.model.layers.14.post_attention_layernorm.weight": "model.safetensors",
|
| 79 |
+
"language_model.model.layers.14.self_attn.k_norm.weight": "model.safetensors",
|
| 80 |
+
"language_model.model.layers.14.self_attn.k_proj.weight": "model.safetensors",
|
| 81 |
+
"language_model.model.layers.14.self_attn.o_proj.weight": "model.safetensors",
|
| 82 |
+
"language_model.model.layers.14.self_attn.q_norm.weight": "model.safetensors",
|
| 83 |
+
"language_model.model.layers.14.self_attn.q_proj.weight": "model.safetensors",
|
| 84 |
+
"language_model.model.layers.14.self_attn.v_proj.weight": "model.safetensors",
|
| 85 |
+
"language_model.model.layers.15.input_layernorm.weight": "model.safetensors",
|
| 86 |
+
"language_model.model.layers.15.mlp.down_proj.weight": "model.safetensors",
|
| 87 |
+
"language_model.model.layers.15.mlp.gate_proj.weight": "model.safetensors",
|
| 88 |
+
"language_model.model.layers.15.mlp.up_proj.weight": "model.safetensors",
|
| 89 |
+
"language_model.model.layers.15.post_attention_layernorm.weight": "model.safetensors",
|
| 90 |
+
"language_model.model.layers.15.self_attn.k_norm.weight": "model.safetensors",
|
| 91 |
+
"language_model.model.layers.15.self_attn.k_proj.weight": "model.safetensors",
|
| 92 |
+
"language_model.model.layers.15.self_attn.o_proj.weight": "model.safetensors",
|
| 93 |
+
"language_model.model.layers.15.self_attn.q_norm.weight": "model.safetensors",
|
| 94 |
+
"language_model.model.layers.15.self_attn.q_proj.weight": "model.safetensors",
|
| 95 |
+
"language_model.model.layers.15.self_attn.v_proj.weight": "model.safetensors",
|
| 96 |
+
"language_model.model.layers.16.input_layernorm.weight": "model.safetensors",
|
| 97 |
+
"language_model.model.layers.16.mlp.down_proj.weight": "model.safetensors",
|
| 98 |
+
"language_model.model.layers.16.mlp.gate_proj.weight": "model.safetensors",
|
| 99 |
+
"language_model.model.layers.16.mlp.up_proj.weight": "model.safetensors",
|
| 100 |
+
"language_model.model.layers.16.post_attention_layernorm.weight": "model.safetensors",
|
| 101 |
+
"language_model.model.layers.16.self_attn.k_norm.weight": "model.safetensors",
|
| 102 |
+
"language_model.model.layers.16.self_attn.k_proj.weight": "model.safetensors",
|
| 103 |
+
"language_model.model.layers.16.self_attn.o_proj.weight": "model.safetensors",
|
| 104 |
+
"language_model.model.layers.16.self_attn.q_norm.weight": "model.safetensors",
|
| 105 |
+
"language_model.model.layers.16.self_attn.q_proj.weight": "model.safetensors",
|
| 106 |
+
"language_model.model.layers.16.self_attn.v_proj.weight": "model.safetensors",
|
| 107 |
+
"language_model.model.layers.17.input_layernorm.weight": "model.safetensors",
|
| 108 |
+
"language_model.model.layers.17.mlp.down_proj.weight": "model.safetensors",
|
| 109 |
+
"language_model.model.layers.17.mlp.gate_proj.weight": "model.safetensors",
|
| 110 |
+
"language_model.model.layers.17.mlp.up_proj.weight": "model.safetensors",
|
| 111 |
+
"language_model.model.layers.17.post_attention_layernorm.weight": "model.safetensors",
|
| 112 |
+
"language_model.model.layers.17.self_attn.k_norm.weight": "model.safetensors",
|
| 113 |
+
"language_model.model.layers.17.self_attn.k_proj.weight": "model.safetensors",
|
| 114 |
+
"language_model.model.layers.17.self_attn.o_proj.weight": "model.safetensors",
|
| 115 |
+
"language_model.model.layers.17.self_attn.q_norm.weight": "model.safetensors",
|
| 116 |
+
"language_model.model.layers.17.self_attn.q_proj.weight": "model.safetensors",
|
| 117 |
+
"language_model.model.layers.17.self_attn.v_proj.weight": "model.safetensors",
|
| 118 |
+
"language_model.model.layers.18.input_layernorm.weight": "model.safetensors",
|
| 119 |
+
"language_model.model.layers.18.mlp.down_proj.weight": "model.safetensors",
|
| 120 |
+
"language_model.model.layers.18.mlp.gate_proj.weight": "model.safetensors",
|
| 121 |
+
"language_model.model.layers.18.mlp.up_proj.weight": "model.safetensors",
|
| 122 |
+
"language_model.model.layers.18.post_attention_layernorm.weight": "model.safetensors",
|
| 123 |
+
"language_model.model.layers.18.self_attn.k_norm.weight": "model.safetensors",
|
| 124 |
+
"language_model.model.layers.18.self_attn.k_proj.weight": "model.safetensors",
|
| 125 |
+
"language_model.model.layers.18.self_attn.o_proj.weight": "model.safetensors",
|
| 126 |
+
"language_model.model.layers.18.self_attn.q_norm.weight": "model.safetensors",
|
| 127 |
+
"language_model.model.layers.18.self_attn.q_proj.weight": "model.safetensors",
|
| 128 |
+
"language_model.model.layers.18.self_attn.v_proj.weight": "model.safetensors",
|
| 129 |
+
"language_model.model.layers.19.input_layernorm.weight": "model.safetensors",
|
| 130 |
+
"language_model.model.layers.19.mlp.down_proj.weight": "model.safetensors",
|
| 131 |
+
"language_model.model.layers.19.mlp.gate_proj.weight": "model.safetensors",
|
| 132 |
+
"language_model.model.layers.19.mlp.up_proj.weight": "model.safetensors",
|
| 133 |
+
"language_model.model.layers.19.post_attention_layernorm.weight": "model.safetensors",
|
| 134 |
+
"language_model.model.layers.19.self_attn.k_norm.weight": "model.safetensors",
|
| 135 |
+
"language_model.model.layers.19.self_attn.k_proj.weight": "model.safetensors",
|
| 136 |
+
"language_model.model.layers.19.self_attn.o_proj.weight": "model.safetensors",
|
| 137 |
+
"language_model.model.layers.19.self_attn.q_norm.weight": "model.safetensors",
|
| 138 |
+
"language_model.model.layers.19.self_attn.q_proj.weight": "model.safetensors",
|
| 139 |
+
"language_model.model.layers.19.self_attn.v_proj.weight": "model.safetensors",
|
| 140 |
+
"language_model.model.layers.2.input_layernorm.weight": "model.safetensors",
|
| 141 |
+
"language_model.model.layers.2.mlp.down_proj.weight": "model.safetensors",
|
| 142 |
+
"language_model.model.layers.2.mlp.gate_proj.weight": "model.safetensors",
|
| 143 |
+
"language_model.model.layers.2.mlp.up_proj.weight": "model.safetensors",
|
| 144 |
+
"language_model.model.layers.2.post_attention_layernorm.weight": "model.safetensors",
|
| 145 |
+
"language_model.model.layers.2.self_attn.k_norm.weight": "model.safetensors",
|
| 146 |
+
"language_model.model.layers.2.self_attn.k_proj.weight": "model.safetensors",
|
| 147 |
+
"language_model.model.layers.2.self_attn.o_proj.weight": "model.safetensors",
|
| 148 |
+
"language_model.model.layers.2.self_attn.q_norm.weight": "model.safetensors",
|
| 149 |
+
"language_model.model.layers.2.self_attn.q_proj.weight": "model.safetensors",
|
| 150 |
+
"language_model.model.layers.2.self_attn.v_proj.weight": "model.safetensors",
|
| 151 |
+
"language_model.model.layers.20.input_layernorm.weight": "model.safetensors",
|
| 152 |
+
"language_model.model.layers.20.mlp.down_proj.weight": "model.safetensors",
|
| 153 |
+
"language_model.model.layers.20.mlp.gate_proj.weight": "model.safetensors",
|
| 154 |
+
"language_model.model.layers.20.mlp.up_proj.weight": "model.safetensors",
|
| 155 |
+
"language_model.model.layers.20.post_attention_layernorm.weight": "model.safetensors",
|
| 156 |
+
"language_model.model.layers.20.self_attn.k_norm.weight": "model.safetensors",
|
| 157 |
+
"language_model.model.layers.20.self_attn.k_proj.weight": "model.safetensors",
|
| 158 |
+
"language_model.model.layers.20.self_attn.o_proj.weight": "model.safetensors",
|
| 159 |
+
"language_model.model.layers.20.self_attn.q_norm.weight": "model.safetensors",
|
| 160 |
+
"language_model.model.layers.20.self_attn.q_proj.weight": "model.safetensors",
|
| 161 |
+
"language_model.model.layers.20.self_attn.v_proj.weight": "model.safetensors",
|
| 162 |
+
"language_model.model.layers.21.input_layernorm.weight": "model.safetensors",
|
| 163 |
+
"language_model.model.layers.21.mlp.down_proj.weight": "model.safetensors",
|
| 164 |
+
"language_model.model.layers.21.mlp.gate_proj.weight": "model.safetensors",
|
| 165 |
+
"language_model.model.layers.21.mlp.up_proj.weight": "model.safetensors",
|
| 166 |
+
"language_model.model.layers.21.post_attention_layernorm.weight": "model.safetensors",
|
| 167 |
+
"language_model.model.layers.21.self_attn.k_norm.weight": "model.safetensors",
|
| 168 |
+
"language_model.model.layers.21.self_attn.k_proj.weight": "model.safetensors",
|
| 169 |
+
"language_model.model.layers.21.self_attn.o_proj.weight": "model.safetensors",
|
| 170 |
+
"language_model.model.layers.21.self_attn.q_norm.weight": "model.safetensors",
|
| 171 |
+
"language_model.model.layers.21.self_attn.q_proj.weight": "model.safetensors",
|
| 172 |
+
"language_model.model.layers.21.self_attn.v_proj.weight": "model.safetensors",
|
| 173 |
+
"language_model.model.layers.22.input_layernorm.weight": "model.safetensors",
|
| 174 |
+
"language_model.model.layers.22.mlp.down_proj.weight": "model.safetensors",
|
| 175 |
+
"language_model.model.layers.22.mlp.gate_proj.weight": "model.safetensors",
|
| 176 |
+
"language_model.model.layers.22.mlp.up_proj.weight": "model.safetensors",
|
| 177 |
+
"language_model.model.layers.22.post_attention_layernorm.weight": "model.safetensors",
|
| 178 |
+
"language_model.model.layers.22.self_attn.k_norm.weight": "model.safetensors",
|
| 179 |
+
"language_model.model.layers.22.self_attn.k_proj.weight": "model.safetensors",
|
| 180 |
+
"language_model.model.layers.22.self_attn.o_proj.weight": "model.safetensors",
|
| 181 |
+
"language_model.model.layers.22.self_attn.q_norm.weight": "model.safetensors",
|
| 182 |
+
"language_model.model.layers.22.self_attn.q_proj.weight": "model.safetensors",
|
| 183 |
+
"language_model.model.layers.22.self_attn.v_proj.weight": "model.safetensors",
|
| 184 |
+
"language_model.model.layers.23.input_layernorm.weight": "model.safetensors",
|
| 185 |
+
"language_model.model.layers.23.mlp.down_proj.weight": "model.safetensors",
|
| 186 |
+
"language_model.model.layers.23.mlp.gate_proj.weight": "model.safetensors",
|
| 187 |
+
"language_model.model.layers.23.mlp.up_proj.weight": "model.safetensors",
|
| 188 |
+
"language_model.model.layers.23.post_attention_layernorm.weight": "model.safetensors",
|
| 189 |
+
"language_model.model.layers.23.self_attn.k_norm.weight": "model.safetensors",
|
| 190 |
+
"language_model.model.layers.23.self_attn.k_proj.weight": "model.safetensors",
|
| 191 |
+
"language_model.model.layers.23.self_attn.o_proj.weight": "model.safetensors",
|
| 192 |
+
"language_model.model.layers.23.self_attn.q_norm.weight": "model.safetensors",
|
| 193 |
+
"language_model.model.layers.23.self_attn.q_proj.weight": "model.safetensors",
|
| 194 |
+
"language_model.model.layers.23.self_attn.v_proj.weight": "model.safetensors",
|
| 195 |
+
"language_model.model.layers.24.input_layernorm.weight": "model.safetensors",
|
| 196 |
+
"language_model.model.layers.24.mlp.down_proj.weight": "model.safetensors",
|
| 197 |
+
"language_model.model.layers.24.mlp.gate_proj.weight": "model.safetensors",
|
| 198 |
+
"language_model.model.layers.24.mlp.up_proj.weight": "model.safetensors",
|
| 199 |
+
"language_model.model.layers.24.post_attention_layernorm.weight": "model.safetensors",
|
| 200 |
+
"language_model.model.layers.24.self_attn.k_norm.weight": "model.safetensors",
|
| 201 |
+
"language_model.model.layers.24.self_attn.k_proj.weight": "model.safetensors",
|
| 202 |
+
"language_model.model.layers.24.self_attn.o_proj.weight": "model.safetensors",
|
| 203 |
+
"language_model.model.layers.24.self_attn.q_norm.weight": "model.safetensors",
|
| 204 |
+
"language_model.model.layers.24.self_attn.q_proj.weight": "model.safetensors",
|
| 205 |
+
"language_model.model.layers.24.self_attn.v_proj.weight": "model.safetensors",
|
| 206 |
+
"language_model.model.layers.25.input_layernorm.weight": "model.safetensors",
|
| 207 |
+
"language_model.model.layers.25.mlp.down_proj.weight": "model.safetensors",
|
| 208 |
+
"language_model.model.layers.25.mlp.gate_proj.weight": "model.safetensors",
|
| 209 |
+
"language_model.model.layers.25.mlp.up_proj.weight": "model.safetensors",
|
| 210 |
+
"language_model.model.layers.25.post_attention_layernorm.weight": "model.safetensors",
|
| 211 |
+
"language_model.model.layers.25.self_attn.k_norm.weight": "model.safetensors",
|
| 212 |
+
"language_model.model.layers.25.self_attn.k_proj.weight": "model.safetensors",
|
| 213 |
+
"language_model.model.layers.25.self_attn.o_proj.weight": "model.safetensors",
|
| 214 |
+
"language_model.model.layers.25.self_attn.q_norm.weight": "model.safetensors",
|
| 215 |
+
"language_model.model.layers.25.self_attn.q_proj.weight": "model.safetensors",
|
| 216 |
+
"language_model.model.layers.25.self_attn.v_proj.weight": "model.safetensors",
|
| 217 |
+
"language_model.model.layers.26.input_layernorm.weight": "model.safetensors",
|
| 218 |
+
"language_model.model.layers.26.mlp.down_proj.weight": "model.safetensors",
|
| 219 |
+
"language_model.model.layers.26.mlp.gate_proj.weight": "model.safetensors",
|
| 220 |
+
"language_model.model.layers.26.mlp.up_proj.weight": "model.safetensors",
|
| 221 |
+
"language_model.model.layers.26.post_attention_layernorm.weight": "model.safetensors",
|
| 222 |
+
"language_model.model.layers.26.self_attn.k_norm.weight": "model.safetensors",
|
| 223 |
+
"language_model.model.layers.26.self_attn.k_proj.weight": "model.safetensors",
|
| 224 |
+
"language_model.model.layers.26.self_attn.o_proj.weight": "model.safetensors",
|
| 225 |
+
"language_model.model.layers.26.self_attn.q_norm.weight": "model.safetensors",
|
| 226 |
+
"language_model.model.layers.26.self_attn.q_proj.weight": "model.safetensors",
|
| 227 |
+
"language_model.model.layers.26.self_attn.v_proj.weight": "model.safetensors",
|
| 228 |
+
"language_model.model.layers.27.input_layernorm.weight": "model.safetensors",
|
| 229 |
+
"language_model.model.layers.27.mlp.down_proj.weight": "model.safetensors",
|
| 230 |
+
"language_model.model.layers.27.mlp.gate_proj.weight": "model.safetensors",
|
| 231 |
+
"language_model.model.layers.27.mlp.up_proj.weight": "model.safetensors",
|
| 232 |
+
"language_model.model.layers.27.post_attention_layernorm.weight": "model.safetensors",
|
| 233 |
+
"language_model.model.layers.27.self_attn.k_norm.weight": "model.safetensors",
|
| 234 |
+
"language_model.model.layers.27.self_attn.k_proj.weight": "model.safetensors",
|
| 235 |
+
"language_model.model.layers.27.self_attn.o_proj.weight": "model.safetensors",
|
| 236 |
+
"language_model.model.layers.27.self_attn.q_norm.weight": "model.safetensors",
|
| 237 |
+
"language_model.model.layers.27.self_attn.q_proj.weight": "model.safetensors",
|
| 238 |
+
"language_model.model.layers.27.self_attn.v_proj.weight": "model.safetensors",
|
| 239 |
+
"language_model.model.layers.3.input_layernorm.weight": "model.safetensors",
|
| 240 |
+
"language_model.model.layers.3.mlp.down_proj.weight": "model.safetensors",
|
| 241 |
+
"language_model.model.layers.3.mlp.gate_proj.weight": "model.safetensors",
|
| 242 |
+
"language_model.model.layers.3.mlp.up_proj.weight": "model.safetensors",
|
| 243 |
+
"language_model.model.layers.3.post_attention_layernorm.weight": "model.safetensors",
|
| 244 |
+
"language_model.model.layers.3.self_attn.k_norm.weight": "model.safetensors",
|
| 245 |
+
"language_model.model.layers.3.self_attn.k_proj.weight": "model.safetensors",
|
| 246 |
+
"language_model.model.layers.3.self_attn.o_proj.weight": "model.safetensors",
|
| 247 |
+
"language_model.model.layers.3.self_attn.q_norm.weight": "model.safetensors",
|
| 248 |
+
"language_model.model.layers.3.self_attn.q_proj.weight": "model.safetensors",
|
| 249 |
+
"language_model.model.layers.3.self_attn.v_proj.weight": "model.safetensors",
|
| 250 |
+
"language_model.model.layers.4.input_layernorm.weight": "model.safetensors",
|
| 251 |
+
"language_model.model.layers.4.mlp.down_proj.weight": "model.safetensors",
|
| 252 |
+
"language_model.model.layers.4.mlp.gate_proj.weight": "model.safetensors",
|
| 253 |
+
"language_model.model.layers.4.mlp.up_proj.weight": "model.safetensors",
|
| 254 |
+
"language_model.model.layers.4.post_attention_layernorm.weight": "model.safetensors",
|
| 255 |
+
"language_model.model.layers.4.self_attn.k_norm.weight": "model.safetensors",
|
| 256 |
+
"language_model.model.layers.4.self_attn.k_proj.weight": "model.safetensors",
|
| 257 |
+
"language_model.model.layers.4.self_attn.o_proj.weight": "model.safetensors",
|
| 258 |
+
"language_model.model.layers.4.self_attn.q_norm.weight": "model.safetensors",
|
| 259 |
+
"language_model.model.layers.4.self_attn.q_proj.weight": "model.safetensors",
|
| 260 |
+
"language_model.model.layers.4.self_attn.v_proj.weight": "model.safetensors",
|
| 261 |
+
"language_model.model.layers.5.input_layernorm.weight": "model.safetensors",
|
| 262 |
+
"language_model.model.layers.5.mlp.down_proj.weight": "model.safetensors",
|
| 263 |
+
"language_model.model.layers.5.mlp.gate_proj.weight": "model.safetensors",
|
| 264 |
+
"language_model.model.layers.5.mlp.up_proj.weight": "model.safetensors",
|
| 265 |
+
"language_model.model.layers.5.post_attention_layernorm.weight": "model.safetensors",
|
| 266 |
+
"language_model.model.layers.5.self_attn.k_norm.weight": "model.safetensors",
|
| 267 |
+
"language_model.model.layers.5.self_attn.k_proj.weight": "model.safetensors",
|
| 268 |
+
"language_model.model.layers.5.self_attn.o_proj.weight": "model.safetensors",
|
| 269 |
+
"language_model.model.layers.5.self_attn.q_norm.weight": "model.safetensors",
|
| 270 |
+
"language_model.model.layers.5.self_attn.q_proj.weight": "model.safetensors",
|
| 271 |
+
"language_model.model.layers.5.self_attn.v_proj.weight": "model.safetensors",
|
| 272 |
+
"language_model.model.layers.6.input_layernorm.weight": "model.safetensors",
|
| 273 |
+
"language_model.model.layers.6.mlp.down_proj.weight": "model.safetensors",
|
| 274 |
+
"language_model.model.layers.6.mlp.gate_proj.weight": "model.safetensors",
|
| 275 |
+
"language_model.model.layers.6.mlp.up_proj.weight": "model.safetensors",
|
| 276 |
+
"language_model.model.layers.6.post_attention_layernorm.weight": "model.safetensors",
|
| 277 |
+
"language_model.model.layers.6.self_attn.k_norm.weight": "model.safetensors",
|
| 278 |
+
"language_model.model.layers.6.self_attn.k_proj.weight": "model.safetensors",
|
| 279 |
+
"language_model.model.layers.6.self_attn.o_proj.weight": "model.safetensors",
|
| 280 |
+
"language_model.model.layers.6.self_attn.q_norm.weight": "model.safetensors",
|
| 281 |
+
"language_model.model.layers.6.self_attn.q_proj.weight": "model.safetensors",
|
| 282 |
+
"language_model.model.layers.6.self_attn.v_proj.weight": "model.safetensors",
|
| 283 |
+
"language_model.model.layers.7.input_layernorm.weight": "model.safetensors",
|
| 284 |
+
"language_model.model.layers.7.mlp.down_proj.weight": "model.safetensors",
|
| 285 |
+
"language_model.model.layers.7.mlp.gate_proj.weight": "model.safetensors",
|
| 286 |
+
"language_model.model.layers.7.mlp.up_proj.weight": "model.safetensors",
|
| 287 |
+
"language_model.model.layers.7.post_attention_layernorm.weight": "model.safetensors",
|
| 288 |
+
"language_model.model.layers.7.self_attn.k_norm.weight": "model.safetensors",
|
| 289 |
+
"language_model.model.layers.7.self_attn.k_proj.weight": "model.safetensors",
|
| 290 |
+
"language_model.model.layers.7.self_attn.o_proj.weight": "model.safetensors",
|
| 291 |
+
"language_model.model.layers.7.self_attn.q_norm.weight": "model.safetensors",
|
| 292 |
+
"language_model.model.layers.7.self_attn.q_proj.weight": "model.safetensors",
|
| 293 |
+
"language_model.model.layers.7.self_attn.v_proj.weight": "model.safetensors",
|
| 294 |
+
"language_model.model.layers.8.input_layernorm.weight": "model.safetensors",
|
| 295 |
+
"language_model.model.layers.8.mlp.down_proj.weight": "model.safetensors",
|
| 296 |
+
"language_model.model.layers.8.mlp.gate_proj.weight": "model.safetensors",
|
| 297 |
+
"language_model.model.layers.8.mlp.up_proj.weight": "model.safetensors",
|
| 298 |
+
"language_model.model.layers.8.post_attention_layernorm.weight": "model.safetensors",
|
| 299 |
+
"language_model.model.layers.8.self_attn.k_norm.weight": "model.safetensors",
|
| 300 |
+
"language_model.model.layers.8.self_attn.k_proj.weight": "model.safetensors",
|
| 301 |
+
"language_model.model.layers.8.self_attn.o_proj.weight": "model.safetensors",
|
| 302 |
+
"language_model.model.layers.8.self_attn.q_norm.weight": "model.safetensors",
|
| 303 |
+
"language_model.model.layers.8.self_attn.q_proj.weight": "model.safetensors",
|
| 304 |
+
"language_model.model.layers.8.self_attn.v_proj.weight": "model.safetensors",
|
| 305 |
+
"language_model.model.layers.9.input_layernorm.weight": "model.safetensors",
|
| 306 |
+
"language_model.model.layers.9.mlp.down_proj.weight": "model.safetensors",
|
| 307 |
+
"language_model.model.layers.9.mlp.gate_proj.weight": "model.safetensors",
|
| 308 |
+
"language_model.model.layers.9.mlp.up_proj.weight": "model.safetensors",
|
| 309 |
+
"language_model.model.layers.9.post_attention_layernorm.weight": "model.safetensors",
|
| 310 |
+
"language_model.model.layers.9.self_attn.k_norm.weight": "model.safetensors",
|
| 311 |
+
"language_model.model.layers.9.self_attn.k_proj.weight": "model.safetensors",
|
| 312 |
+
"language_model.model.layers.9.self_attn.o_proj.weight": "model.safetensors",
|
| 313 |
+
"language_model.model.layers.9.self_attn.q_norm.weight": "model.safetensors",
|
| 314 |
+
"language_model.model.layers.9.self_attn.q_proj.weight": "model.safetensors",
|
| 315 |
+
"language_model.model.layers.9.self_attn.v_proj.weight": "model.safetensors",
|
| 316 |
+
"language_model.model.norm.weight": "model.safetensors",
|
| 317 |
+
"mlp1.0.bias": "model.safetensors",
|
| 318 |
+
"mlp1.0.weight": "model.safetensors",
|
| 319 |
+
"mlp1.1.bias": "model.safetensors",
|
| 320 |
+
"mlp1.1.weight": "model.safetensors",
|
| 321 |
+
"mlp1.3.bias": "model.safetensors",
|
| 322 |
+
"mlp1.3.weight": "model.safetensors",
|
| 323 |
+
"vision_model.vision_model.embeddings.patch_embedding.bias": "model.safetensors",
|
| 324 |
+
"vision_model.vision_model.embeddings.patch_embedding.weight": "model.safetensors",
|
| 325 |
+
"vision_model.vision_model.embeddings.position_embedding.weight": "model.safetensors",
|
| 326 |
+
"vision_model.vision_model.encoder.layers.0.layer_norm1.bias": "model.safetensors",
|
| 327 |
+
"vision_model.vision_model.encoder.layers.0.layer_norm1.weight": "model.safetensors",
|
| 328 |
+
"vision_model.vision_model.encoder.layers.0.layer_norm2.bias": "model.safetensors",
|
| 329 |
+
"vision_model.vision_model.encoder.layers.0.layer_norm2.weight": "model.safetensors",
|
| 330 |
+
"vision_model.vision_model.encoder.layers.0.mlp.fc1.bias": "model.safetensors",
|
| 331 |
+
"vision_model.vision_model.encoder.layers.0.mlp.fc1.weight": "model.safetensors",
|
| 332 |
+
"vision_model.vision_model.encoder.layers.0.mlp.fc2.bias": "model.safetensors",
|
| 333 |
+
"vision_model.vision_model.encoder.layers.0.mlp.fc2.weight": "model.safetensors",
|
| 334 |
+
"vision_model.vision_model.encoder.layers.0.self_attn.k_proj.bias": "model.safetensors",
|
| 335 |
+
"vision_model.vision_model.encoder.layers.0.self_attn.k_proj.weight": "model.safetensors",
|
| 336 |
+
"vision_model.vision_model.encoder.layers.0.self_attn.out_proj.bias": "model.safetensors",
|
| 337 |
+
"vision_model.vision_model.encoder.layers.0.self_attn.out_proj.weight": "model.safetensors",
|
| 338 |
+
"vision_model.vision_model.encoder.layers.0.self_attn.q_proj.bias": "model.safetensors",
|
| 339 |
+
"vision_model.vision_model.encoder.layers.0.self_attn.q_proj.weight": "model.safetensors",
|
| 340 |
+
"vision_model.vision_model.encoder.layers.0.self_attn.v_proj.bias": "model.safetensors",
|
| 341 |
+
"vision_model.vision_model.encoder.layers.0.self_attn.v_proj.weight": "model.safetensors",
|
| 342 |
+
"vision_model.vision_model.encoder.layers.1.layer_norm1.bias": "model.safetensors",
|
| 343 |
+
"vision_model.vision_model.encoder.layers.1.layer_norm1.weight": "model.safetensors",
|
| 344 |
+
"vision_model.vision_model.encoder.layers.1.layer_norm2.bias": "model.safetensors",
|
| 345 |
+
"vision_model.vision_model.encoder.layers.1.layer_norm2.weight": "model.safetensors",
|
| 346 |
+
"vision_model.vision_model.encoder.layers.1.mlp.fc1.bias": "model.safetensors",
|
| 347 |
+
"vision_model.vision_model.encoder.layers.1.mlp.fc1.weight": "model.safetensors",
|
| 348 |
+
"vision_model.vision_model.encoder.layers.1.mlp.fc2.bias": "model.safetensors",
|
| 349 |
+
"vision_model.vision_model.encoder.layers.1.mlp.fc2.weight": "model.safetensors",
|
| 350 |
+
"vision_model.vision_model.encoder.layers.1.self_attn.k_proj.bias": "model.safetensors",
|
| 351 |
+
"vision_model.vision_model.encoder.layers.1.self_attn.k_proj.weight": "model.safetensors",
|
| 352 |
+
"vision_model.vision_model.encoder.layers.1.self_attn.out_proj.bias": "model.safetensors",
|
| 353 |
+
"vision_model.vision_model.encoder.layers.1.self_attn.out_proj.weight": "model.safetensors",
|
| 354 |
+
"vision_model.vision_model.encoder.layers.1.self_attn.q_proj.bias": "model.safetensors",
|
| 355 |
+
"vision_model.vision_model.encoder.layers.1.self_attn.q_proj.weight": "model.safetensors",
|
| 356 |
+
"vision_model.vision_model.encoder.layers.1.self_attn.v_proj.bias": "model.safetensors",
|
| 357 |
+
"vision_model.vision_model.encoder.layers.1.self_attn.v_proj.weight": "model.safetensors",
|
| 358 |
+
"vision_model.vision_model.encoder.layers.10.layer_norm1.bias": "model.safetensors",
|
| 359 |
+
"vision_model.vision_model.encoder.layers.10.layer_norm1.weight": "model.safetensors",
|
| 360 |
+
"vision_model.vision_model.encoder.layers.10.layer_norm2.bias": "model.safetensors",
|
| 361 |
+
"vision_model.vision_model.encoder.layers.10.layer_norm2.weight": "model.safetensors",
|
| 362 |
+
"vision_model.vision_model.encoder.layers.10.mlp.fc1.bias": "model.safetensors",
|
| 363 |
+
"vision_model.vision_model.encoder.layers.10.mlp.fc1.weight": "model.safetensors",
|
| 364 |
+
"vision_model.vision_model.encoder.layers.10.mlp.fc2.bias": "model.safetensors",
|
| 365 |
+
"vision_model.vision_model.encoder.layers.10.mlp.fc2.weight": "model.safetensors",
|
| 366 |
+
"vision_model.vision_model.encoder.layers.10.self_attn.k_proj.bias": "model.safetensors",
|
| 367 |
+
"vision_model.vision_model.encoder.layers.10.self_attn.k_proj.weight": "model.safetensors",
|
| 368 |
+
"vision_model.vision_model.encoder.layers.10.self_attn.out_proj.bias": "model.safetensors",
|
| 369 |
+
"vision_model.vision_model.encoder.layers.10.self_attn.out_proj.weight": "model.safetensors",
|
| 370 |
+
"vision_model.vision_model.encoder.layers.10.self_attn.q_proj.bias": "model.safetensors",
|
| 371 |
+
"vision_model.vision_model.encoder.layers.10.self_attn.q_proj.weight": "model.safetensors",
|
| 372 |
+
"vision_model.vision_model.encoder.layers.10.self_attn.v_proj.bias": "model.safetensors",
|
| 373 |
+
"vision_model.vision_model.encoder.layers.10.self_attn.v_proj.weight": "model.safetensors",
|
| 374 |
+
"vision_model.vision_model.encoder.layers.11.layer_norm1.bias": "model.safetensors",
|
| 375 |
+
"vision_model.vision_model.encoder.layers.11.layer_norm1.weight": "model.safetensors",
|
| 376 |
+
"vision_model.vision_model.encoder.layers.11.layer_norm2.bias": "model.safetensors",
|
| 377 |
+
"vision_model.vision_model.encoder.layers.11.layer_norm2.weight": "model.safetensors",
|
| 378 |
+
"vision_model.vision_model.encoder.layers.11.mlp.fc1.bias": "model.safetensors",
|
| 379 |
+
"vision_model.vision_model.encoder.layers.11.mlp.fc1.weight": "model.safetensors",
|
| 380 |
+
"vision_model.vision_model.encoder.layers.11.mlp.fc2.bias": "model.safetensors",
|
| 381 |
+
"vision_model.vision_model.encoder.layers.11.mlp.fc2.weight": "model.safetensors",
|
| 382 |
+
"vision_model.vision_model.encoder.layers.11.self_attn.k_proj.bias": "model.safetensors",
|
| 383 |
+
"vision_model.vision_model.encoder.layers.11.self_attn.k_proj.weight": "model.safetensors",
|
| 384 |
+
"vision_model.vision_model.encoder.layers.11.self_attn.out_proj.bias": "model.safetensors",
|
| 385 |
+
"vision_model.vision_model.encoder.layers.11.self_attn.out_proj.weight": "model.safetensors",
|
| 386 |
+
"vision_model.vision_model.encoder.layers.11.self_attn.q_proj.bias": "model.safetensors",
|
| 387 |
+
"vision_model.vision_model.encoder.layers.11.self_attn.q_proj.weight": "model.safetensors",
|
| 388 |
+
"vision_model.vision_model.encoder.layers.11.self_attn.v_proj.bias": "model.safetensors",
|
| 389 |
+
"vision_model.vision_model.encoder.layers.11.self_attn.v_proj.weight": "model.safetensors",
|
| 390 |
+
"vision_model.vision_model.encoder.layers.12.layer_norm1.bias": "model.safetensors",
|
| 391 |
+
"vision_model.vision_model.encoder.layers.12.layer_norm1.weight": "model.safetensors",
|
| 392 |
+
"vision_model.vision_model.encoder.layers.12.layer_norm2.bias": "model.safetensors",
|
| 393 |
+
"vision_model.vision_model.encoder.layers.12.layer_norm2.weight": "model.safetensors",
|
| 394 |
+
"vision_model.vision_model.encoder.layers.12.mlp.fc1.bias": "model.safetensors",
|
| 395 |
+
"vision_model.vision_model.encoder.layers.12.mlp.fc1.weight": "model.safetensors",
|
| 396 |
+
"vision_model.vision_model.encoder.layers.12.mlp.fc2.bias": "model.safetensors",
|
| 397 |
+
"vision_model.vision_model.encoder.layers.12.mlp.fc2.weight": "model.safetensors",
|
| 398 |
+
"vision_model.vision_model.encoder.layers.12.self_attn.k_proj.bias": "model.safetensors",
|
| 399 |
+
"vision_model.vision_model.encoder.layers.12.self_attn.k_proj.weight": "model.safetensors",
|
| 400 |
+
"vision_model.vision_model.encoder.layers.12.self_attn.out_proj.bias": "model.safetensors",
|
| 401 |
+
"vision_model.vision_model.encoder.layers.12.self_attn.out_proj.weight": "model.safetensors",
|
| 402 |
+
"vision_model.vision_model.encoder.layers.12.self_attn.q_proj.bias": "model.safetensors",
|
| 403 |
+
"vision_model.vision_model.encoder.layers.12.self_attn.q_proj.weight": "model.safetensors",
|
| 404 |
+
"vision_model.vision_model.encoder.layers.12.self_attn.v_proj.bias": "model.safetensors",
|
| 405 |
+
"vision_model.vision_model.encoder.layers.12.self_attn.v_proj.weight": "model.safetensors",
|
| 406 |
+
"vision_model.vision_model.encoder.layers.13.layer_norm1.bias": "model.safetensors",
|
| 407 |
+
"vision_model.vision_model.encoder.layers.13.layer_norm1.weight": "model.safetensors",
|
| 408 |
+
"vision_model.vision_model.encoder.layers.13.layer_norm2.bias": "model.safetensors",
|
| 409 |
+
"vision_model.vision_model.encoder.layers.13.layer_norm2.weight": "model.safetensors",
|
| 410 |
+
"vision_model.vision_model.encoder.layers.13.mlp.fc1.bias": "model.safetensors",
|
| 411 |
+
"vision_model.vision_model.encoder.layers.13.mlp.fc1.weight": "model.safetensors",
|
| 412 |
+
"vision_model.vision_model.encoder.layers.13.mlp.fc2.bias": "model.safetensors",
|
| 413 |
+
"vision_model.vision_model.encoder.layers.13.mlp.fc2.weight": "model.safetensors",
|
| 414 |
+
"vision_model.vision_model.encoder.layers.13.self_attn.k_proj.bias": "model.safetensors",
|
| 415 |
+
"vision_model.vision_model.encoder.layers.13.self_attn.k_proj.weight": "model.safetensors",
|
| 416 |
+
"vision_model.vision_model.encoder.layers.13.self_attn.out_proj.bias": "model.safetensors",
|
| 417 |
+
"vision_model.vision_model.encoder.layers.13.self_attn.out_proj.weight": "model.safetensors",
|
| 418 |
+
"vision_model.vision_model.encoder.layers.13.self_attn.q_proj.bias": "model.safetensors",
|
| 419 |
+
"vision_model.vision_model.encoder.layers.13.self_attn.q_proj.weight": "model.safetensors",
|
| 420 |
+
"vision_model.vision_model.encoder.layers.13.self_attn.v_proj.bias": "model.safetensors",
|
| 421 |
+
"vision_model.vision_model.encoder.layers.13.self_attn.v_proj.weight": "model.safetensors",
|
| 422 |
+
"vision_model.vision_model.encoder.layers.14.layer_norm1.bias": "model.safetensors",
|
| 423 |
+
"vision_model.vision_model.encoder.layers.14.layer_norm1.weight": "model.safetensors",
|
| 424 |
+
"vision_model.vision_model.encoder.layers.14.layer_norm2.bias": "model.safetensors",
|
| 425 |
+
"vision_model.vision_model.encoder.layers.14.layer_norm2.weight": "model.safetensors",
|
| 426 |
+
"vision_model.vision_model.encoder.layers.14.mlp.fc1.bias": "model.safetensors",
|
| 427 |
+
"vision_model.vision_model.encoder.layers.14.mlp.fc1.weight": "model.safetensors",
|
| 428 |
+
"vision_model.vision_model.encoder.layers.14.mlp.fc2.bias": "model.safetensors",
|
| 429 |
+
"vision_model.vision_model.encoder.layers.14.mlp.fc2.weight": "model.safetensors",
|
| 430 |
+
"vision_model.vision_model.encoder.layers.14.self_attn.k_proj.bias": "model.safetensors",
|
| 431 |
+
"vision_model.vision_model.encoder.layers.14.self_attn.k_proj.weight": "model.safetensors",
|
| 432 |
+
"vision_model.vision_model.encoder.layers.14.self_attn.out_proj.bias": "model.safetensors",
|
| 433 |
+
"vision_model.vision_model.encoder.layers.14.self_attn.out_proj.weight": "model.safetensors",
|
| 434 |
+
"vision_model.vision_model.encoder.layers.14.self_attn.q_proj.bias": "model.safetensors",
|
| 435 |
+
"vision_model.vision_model.encoder.layers.14.self_attn.q_proj.weight": "model.safetensors",
|
| 436 |
+
"vision_model.vision_model.encoder.layers.14.self_attn.v_proj.bias": "model.safetensors",
|
| 437 |
+
"vision_model.vision_model.encoder.layers.14.self_attn.v_proj.weight": "model.safetensors",
|
| 438 |
+
"vision_model.vision_model.encoder.layers.15.layer_norm1.bias": "model.safetensors",
|
| 439 |
+
"vision_model.vision_model.encoder.layers.15.layer_norm1.weight": "model.safetensors",
|
| 440 |
+
"vision_model.vision_model.encoder.layers.15.layer_norm2.bias": "model.safetensors",
|
| 441 |
+
"vision_model.vision_model.encoder.layers.15.layer_norm2.weight": "model.safetensors",
|
| 442 |
+
"vision_model.vision_model.encoder.layers.15.mlp.fc1.bias": "model.safetensors",
|
| 443 |
+
"vision_model.vision_model.encoder.layers.15.mlp.fc1.weight": "model.safetensors",
|
| 444 |
+
"vision_model.vision_model.encoder.layers.15.mlp.fc2.bias": "model.safetensors",
|
| 445 |
+
"vision_model.vision_model.encoder.layers.15.mlp.fc2.weight": "model.safetensors",
|
| 446 |
+
"vision_model.vision_model.encoder.layers.15.self_attn.k_proj.bias": "model.safetensors",
|
| 447 |
+
"vision_model.vision_model.encoder.layers.15.self_attn.k_proj.weight": "model.safetensors",
|
| 448 |
+
"vision_model.vision_model.encoder.layers.15.self_attn.out_proj.bias": "model.safetensors",
|
| 449 |
+
"vision_model.vision_model.encoder.layers.15.self_attn.out_proj.weight": "model.safetensors",
|
| 450 |
+
"vision_model.vision_model.encoder.layers.15.self_attn.q_proj.bias": "model.safetensors",
|
| 451 |
+
"vision_model.vision_model.encoder.layers.15.self_attn.q_proj.weight": "model.safetensors",
|
| 452 |
+
"vision_model.vision_model.encoder.layers.15.self_attn.v_proj.bias": "model.safetensors",
|
| 453 |
+
"vision_model.vision_model.encoder.layers.15.self_attn.v_proj.weight": "model.safetensors",
|
| 454 |
+
"vision_model.vision_model.encoder.layers.16.layer_norm1.bias": "model.safetensors",
|
| 455 |
+
"vision_model.vision_model.encoder.layers.16.layer_norm1.weight": "model.safetensors",
|
| 456 |
+
"vision_model.vision_model.encoder.layers.16.layer_norm2.bias": "model.safetensors",
|
| 457 |
+
"vision_model.vision_model.encoder.layers.16.layer_norm2.weight": "model.safetensors",
|
| 458 |
+
"vision_model.vision_model.encoder.layers.16.mlp.fc1.bias": "model.safetensors",
|
| 459 |
+
"vision_model.vision_model.encoder.layers.16.mlp.fc1.weight": "model.safetensors",
|
| 460 |
+
"vision_model.vision_model.encoder.layers.16.mlp.fc2.bias": "model.safetensors",
|
| 461 |
+
"vision_model.vision_model.encoder.layers.16.mlp.fc2.weight": "model.safetensors",
|
| 462 |
+
"vision_model.vision_model.encoder.layers.16.self_attn.k_proj.bias": "model.safetensors",
|
| 463 |
+
"vision_model.vision_model.encoder.layers.16.self_attn.k_proj.weight": "model.safetensors",
|
| 464 |
+
"vision_model.vision_model.encoder.layers.16.self_attn.out_proj.bias": "model.safetensors",
|
| 465 |
+
"vision_model.vision_model.encoder.layers.16.self_attn.out_proj.weight": "model.safetensors",
|
| 466 |
+
"vision_model.vision_model.encoder.layers.16.self_attn.q_proj.bias": "model.safetensors",
|
| 467 |
+
"vision_model.vision_model.encoder.layers.16.self_attn.q_proj.weight": "model.safetensors",
|
| 468 |
+
"vision_model.vision_model.encoder.layers.16.self_attn.v_proj.bias": "model.safetensors",
|
| 469 |
+
"vision_model.vision_model.encoder.layers.16.self_attn.v_proj.weight": "model.safetensors",
|
| 470 |
+
"vision_model.vision_model.encoder.layers.17.layer_norm1.bias": "model.safetensors",
|
| 471 |
+
"vision_model.vision_model.encoder.layers.17.layer_norm1.weight": "model.safetensors",
|
| 472 |
+
"vision_model.vision_model.encoder.layers.17.layer_norm2.bias": "model.safetensors",
|
| 473 |
+
"vision_model.vision_model.encoder.layers.17.layer_norm2.weight": "model.safetensors",
|
| 474 |
+
"vision_model.vision_model.encoder.layers.17.mlp.fc1.bias": "model.safetensors",
|
| 475 |
+
"vision_model.vision_model.encoder.layers.17.mlp.fc1.weight": "model.safetensors",
|
| 476 |
+
"vision_model.vision_model.encoder.layers.17.mlp.fc2.bias": "model.safetensors",
|
| 477 |
+
"vision_model.vision_model.encoder.layers.17.mlp.fc2.weight": "model.safetensors",
|
| 478 |
+
"vision_model.vision_model.encoder.layers.17.self_attn.k_proj.bias": "model.safetensors",
|
| 479 |
+
"vision_model.vision_model.encoder.layers.17.self_attn.k_proj.weight": "model.safetensors",
|
| 480 |
+
"vision_model.vision_model.encoder.layers.17.self_attn.out_proj.bias": "model.safetensors",
|
| 481 |
+
"vision_model.vision_model.encoder.layers.17.self_attn.out_proj.weight": "model.safetensors",
|
| 482 |
+
"vision_model.vision_model.encoder.layers.17.self_attn.q_proj.bias": "model.safetensors",
|
| 483 |
+
"vision_model.vision_model.encoder.layers.17.self_attn.q_proj.weight": "model.safetensors",
|
| 484 |
+
"vision_model.vision_model.encoder.layers.17.self_attn.v_proj.bias": "model.safetensors",
|
| 485 |
+
"vision_model.vision_model.encoder.layers.17.self_attn.v_proj.weight": "model.safetensors",
|
| 486 |
+
"vision_model.vision_model.encoder.layers.18.layer_norm1.bias": "model.safetensors",
|
| 487 |
+
"vision_model.vision_model.encoder.layers.18.layer_norm1.weight": "model.safetensors",
|
| 488 |
+
"vision_model.vision_model.encoder.layers.18.layer_norm2.bias": "model.safetensors",
|
| 489 |
+
"vision_model.vision_model.encoder.layers.18.layer_norm2.weight": "model.safetensors",
|
| 490 |
+
"vision_model.vision_model.encoder.layers.18.mlp.fc1.bias": "model.safetensors",
|
| 491 |
+
"vision_model.vision_model.encoder.layers.18.mlp.fc1.weight": "model.safetensors",
|
| 492 |
+
"vision_model.vision_model.encoder.layers.18.mlp.fc2.bias": "model.safetensors",
|
| 493 |
+
"vision_model.vision_model.encoder.layers.18.mlp.fc2.weight": "model.safetensors",
|
| 494 |
+
"vision_model.vision_model.encoder.layers.18.self_attn.k_proj.bias": "model.safetensors",
|
| 495 |
+
"vision_model.vision_model.encoder.layers.18.self_attn.k_proj.weight": "model.safetensors",
|
| 496 |
+
"vision_model.vision_model.encoder.layers.18.self_attn.out_proj.bias": "model.safetensors",
|
| 497 |
+
"vision_model.vision_model.encoder.layers.18.self_attn.out_proj.weight": "model.safetensors",
|
| 498 |
+
"vision_model.vision_model.encoder.layers.18.self_attn.q_proj.bias": "model.safetensors",
|
| 499 |
+
"vision_model.vision_model.encoder.layers.18.self_attn.q_proj.weight": "model.safetensors",
|
| 500 |
+
"vision_model.vision_model.encoder.layers.18.self_attn.v_proj.bias": "model.safetensors",
|
| 501 |
+
"vision_model.vision_model.encoder.layers.18.self_attn.v_proj.weight": "model.safetensors",
|
| 502 |
+
"vision_model.vision_model.encoder.layers.19.layer_norm1.bias": "model.safetensors",
|
| 503 |
+
"vision_model.vision_model.encoder.layers.19.layer_norm1.weight": "model.safetensors",
|
| 504 |
+
"vision_model.vision_model.encoder.layers.19.layer_norm2.bias": "model.safetensors",
|
| 505 |
+
"vision_model.vision_model.encoder.layers.19.layer_norm2.weight": "model.safetensors",
|
| 506 |
+
"vision_model.vision_model.encoder.layers.19.mlp.fc1.bias": "model.safetensors",
|
| 507 |
+
"vision_model.vision_model.encoder.layers.19.mlp.fc1.weight": "model.safetensors",
|
| 508 |
+
"vision_model.vision_model.encoder.layers.19.mlp.fc2.bias": "model.safetensors",
|
| 509 |
+
"vision_model.vision_model.encoder.layers.19.mlp.fc2.weight": "model.safetensors",
|
| 510 |
+
"vision_model.vision_model.encoder.layers.19.self_attn.k_proj.bias": "model.safetensors",
|
| 511 |
+
"vision_model.vision_model.encoder.layers.19.self_attn.k_proj.weight": "model.safetensors",
|
| 512 |
+
"vision_model.vision_model.encoder.layers.19.self_attn.out_proj.bias": "model.safetensors",
|
| 513 |
+
"vision_model.vision_model.encoder.layers.19.self_attn.out_proj.weight": "model.safetensors",
|
| 514 |
+
"vision_model.vision_model.encoder.layers.19.self_attn.q_proj.bias": "model.safetensors",
|
| 515 |
+
"vision_model.vision_model.encoder.layers.19.self_attn.q_proj.weight": "model.safetensors",
|
| 516 |
+
"vision_model.vision_model.encoder.layers.19.self_attn.v_proj.bias": "model.safetensors",
|
| 517 |
+
"vision_model.vision_model.encoder.layers.19.self_attn.v_proj.weight": "model.safetensors",
|
| 518 |
+
"vision_model.vision_model.encoder.layers.2.layer_norm1.bias": "model.safetensors",
|
| 519 |
+
"vision_model.vision_model.encoder.layers.2.layer_norm1.weight": "model.safetensors",
|
| 520 |
+
"vision_model.vision_model.encoder.layers.2.layer_norm2.bias": "model.safetensors",
|
| 521 |
+
"vision_model.vision_model.encoder.layers.2.layer_norm2.weight": "model.safetensors",
|
| 522 |
+
"vision_model.vision_model.encoder.layers.2.mlp.fc1.bias": "model.safetensors",
|
| 523 |
+
"vision_model.vision_model.encoder.layers.2.mlp.fc1.weight": "model.safetensors",
|
| 524 |
+
"vision_model.vision_model.encoder.layers.2.mlp.fc2.bias": "model.safetensors",
|
| 525 |
+
"vision_model.vision_model.encoder.layers.2.mlp.fc2.weight": "model.safetensors",
|
| 526 |
+
"vision_model.vision_model.encoder.layers.2.self_attn.k_proj.bias": "model.safetensors",
|
| 527 |
+
"vision_model.vision_model.encoder.layers.2.self_attn.k_proj.weight": "model.safetensors",
|
| 528 |
+
"vision_model.vision_model.encoder.layers.2.self_attn.out_proj.bias": "model.safetensors",
|
| 529 |
+
"vision_model.vision_model.encoder.layers.2.self_attn.out_proj.weight": "model.safetensors",
|
| 530 |
+
"vision_model.vision_model.encoder.layers.2.self_attn.q_proj.bias": "model.safetensors",
|
| 531 |
+
"vision_model.vision_model.encoder.layers.2.self_attn.q_proj.weight": "model.safetensors",
|
| 532 |
+
"vision_model.vision_model.encoder.layers.2.self_attn.v_proj.bias": "model.safetensors",
|
| 533 |
+
"vision_model.vision_model.encoder.layers.2.self_attn.v_proj.weight": "model.safetensors",
|
| 534 |
+
"vision_model.vision_model.encoder.layers.20.layer_norm1.bias": "model.safetensors",
|
| 535 |
+
"vision_model.vision_model.encoder.layers.20.layer_norm1.weight": "model.safetensors",
|
| 536 |
+
"vision_model.vision_model.encoder.layers.20.layer_norm2.bias": "model.safetensors",
|
| 537 |
+
"vision_model.vision_model.encoder.layers.20.layer_norm2.weight": "model.safetensors",
|
| 538 |
+
"vision_model.vision_model.encoder.layers.20.mlp.fc1.bias": "model.safetensors",
|
| 539 |
+
"vision_model.vision_model.encoder.layers.20.mlp.fc1.weight": "model.safetensors",
|
| 540 |
+
"vision_model.vision_model.encoder.layers.20.mlp.fc2.bias": "model.safetensors",
|
| 541 |
+
"vision_model.vision_model.encoder.layers.20.mlp.fc2.weight": "model.safetensors",
|
| 542 |
+
"vision_model.vision_model.encoder.layers.20.self_attn.k_proj.bias": "model.safetensors",
|
| 543 |
+
"vision_model.vision_model.encoder.layers.20.self_attn.k_proj.weight": "model.safetensors",
|
| 544 |
+
"vision_model.vision_model.encoder.layers.20.self_attn.out_proj.bias": "model.safetensors",
|
| 545 |
+
"vision_model.vision_model.encoder.layers.20.self_attn.out_proj.weight": "model.safetensors",
|
| 546 |
+
"vision_model.vision_model.encoder.layers.20.self_attn.q_proj.bias": "model.safetensors",
|
| 547 |
+
"vision_model.vision_model.encoder.layers.20.self_attn.q_proj.weight": "model.safetensors",
|
| 548 |
+
"vision_model.vision_model.encoder.layers.20.self_attn.v_proj.bias": "model.safetensors",
|
| 549 |
+
"vision_model.vision_model.encoder.layers.20.self_attn.v_proj.weight": "model.safetensors",
|
| 550 |
+
"vision_model.vision_model.encoder.layers.21.layer_norm1.bias": "model.safetensors",
|
| 551 |
+
"vision_model.vision_model.encoder.layers.21.layer_norm1.weight": "model.safetensors",
|
| 552 |
+
"vision_model.vision_model.encoder.layers.21.layer_norm2.bias": "model.safetensors",
|
| 553 |
+
"vision_model.vision_model.encoder.layers.21.layer_norm2.weight": "model.safetensors",
|
| 554 |
+
"vision_model.vision_model.encoder.layers.21.mlp.fc1.bias": "model.safetensors",
|
| 555 |
+
"vision_model.vision_model.encoder.layers.21.mlp.fc1.weight": "model.safetensors",
|
| 556 |
+
"vision_model.vision_model.encoder.layers.21.mlp.fc2.bias": "model.safetensors",
|
| 557 |
+
"vision_model.vision_model.encoder.layers.21.mlp.fc2.weight": "model.safetensors",
|
| 558 |
+
"vision_model.vision_model.encoder.layers.21.self_attn.k_proj.bias": "model.safetensors",
|
| 559 |
+
"vision_model.vision_model.encoder.layers.21.self_attn.k_proj.weight": "model.safetensors",
|
| 560 |
+
"vision_model.vision_model.encoder.layers.21.self_attn.out_proj.bias": "model.safetensors",
|
| 561 |
+
"vision_model.vision_model.encoder.layers.21.self_attn.out_proj.weight": "model.safetensors",
|
| 562 |
+
"vision_model.vision_model.encoder.layers.21.self_attn.q_proj.bias": "model.safetensors",
|
| 563 |
+
"vision_model.vision_model.encoder.layers.21.self_attn.q_proj.weight": "model.safetensors",
|
| 564 |
+
"vision_model.vision_model.encoder.layers.21.self_attn.v_proj.bias": "model.safetensors",
|
| 565 |
+
"vision_model.vision_model.encoder.layers.21.self_attn.v_proj.weight": "model.safetensors",
|
| 566 |
+
"vision_model.vision_model.encoder.layers.22.layer_norm1.bias": "model.safetensors",
|
| 567 |
+
"vision_model.vision_model.encoder.layers.22.layer_norm1.weight": "model.safetensors",
|
| 568 |
+
"vision_model.vision_model.encoder.layers.22.layer_norm2.bias": "model.safetensors",
|
| 569 |
+
"vision_model.vision_model.encoder.layers.22.layer_norm2.weight": "model.safetensors",
|
| 570 |
+
"vision_model.vision_model.encoder.layers.22.mlp.fc1.bias": "model.safetensors",
|
| 571 |
+
"vision_model.vision_model.encoder.layers.22.mlp.fc1.weight": "model.safetensors",
|
| 572 |
+
"vision_model.vision_model.encoder.layers.22.mlp.fc2.bias": "model.safetensors",
|
| 573 |
+
"vision_model.vision_model.encoder.layers.22.mlp.fc2.weight": "model.safetensors",
|
| 574 |
+
"vision_model.vision_model.encoder.layers.22.self_attn.k_proj.bias": "model.safetensors",
|
| 575 |
+
"vision_model.vision_model.encoder.layers.22.self_attn.k_proj.weight": "model.safetensors",
|
| 576 |
+
"vision_model.vision_model.encoder.layers.22.self_attn.out_proj.bias": "model.safetensors",
|
| 577 |
+
"vision_model.vision_model.encoder.layers.22.self_attn.out_proj.weight": "model.safetensors",
|
| 578 |
+
"vision_model.vision_model.encoder.layers.22.self_attn.q_proj.bias": "model.safetensors",
|
| 579 |
+
"vision_model.vision_model.encoder.layers.22.self_attn.q_proj.weight": "model.safetensors",
|
| 580 |
+
"vision_model.vision_model.encoder.layers.22.self_attn.v_proj.bias": "model.safetensors",
|
| 581 |
+
"vision_model.vision_model.encoder.layers.22.self_attn.v_proj.weight": "model.safetensors",
|
| 582 |
+
"vision_model.vision_model.encoder.layers.23.layer_norm1.bias": "model.safetensors",
|
| 583 |
+
"vision_model.vision_model.encoder.layers.23.layer_norm1.weight": "model.safetensors",
|
| 584 |
+
"vision_model.vision_model.encoder.layers.23.layer_norm2.bias": "model.safetensors",
|
| 585 |
+
"vision_model.vision_model.encoder.layers.23.layer_norm2.weight": "model.safetensors",
|
| 586 |
+
"vision_model.vision_model.encoder.layers.23.mlp.fc1.bias": "model.safetensors",
|
| 587 |
+
"vision_model.vision_model.encoder.layers.23.mlp.fc1.weight": "model.safetensors",
|
| 588 |
+
"vision_model.vision_model.encoder.layers.23.mlp.fc2.bias": "model.safetensors",
|
| 589 |
+
"vision_model.vision_model.encoder.layers.23.mlp.fc2.weight": "model.safetensors",
|
| 590 |
+
"vision_model.vision_model.encoder.layers.23.self_attn.k_proj.bias": "model.safetensors",
|
| 591 |
+
"vision_model.vision_model.encoder.layers.23.self_attn.k_proj.weight": "model.safetensors",
|
| 592 |
+
"vision_model.vision_model.encoder.layers.23.self_attn.out_proj.bias": "model.safetensors",
|
| 593 |
+
"vision_model.vision_model.encoder.layers.23.self_attn.out_proj.weight": "model.safetensors",
|
| 594 |
+
"vision_model.vision_model.encoder.layers.23.self_attn.q_proj.bias": "model.safetensors",
|
| 595 |
+
"vision_model.vision_model.encoder.layers.23.self_attn.q_proj.weight": "model.safetensors",
|
| 596 |
+
"vision_model.vision_model.encoder.layers.23.self_attn.v_proj.bias": "model.safetensors",
|
| 597 |
+
"vision_model.vision_model.encoder.layers.23.self_attn.v_proj.weight": "model.safetensors",
|
| 598 |
+
"vision_model.vision_model.encoder.layers.24.layer_norm1.bias": "model.safetensors",
|
| 599 |
+
"vision_model.vision_model.encoder.layers.24.layer_norm1.weight": "model.safetensors",
|
| 600 |
+
"vision_model.vision_model.encoder.layers.24.layer_norm2.bias": "model.safetensors",
|
| 601 |
+
"vision_model.vision_model.encoder.layers.24.layer_norm2.weight": "model.safetensors",
|
| 602 |
+
"vision_model.vision_model.encoder.layers.24.mlp.fc1.bias": "model.safetensors",
|
| 603 |
+
"vision_model.vision_model.encoder.layers.24.mlp.fc1.weight": "model.safetensors",
|
| 604 |
+
"vision_model.vision_model.encoder.layers.24.mlp.fc2.bias": "model.safetensors",
|
| 605 |
+
"vision_model.vision_model.encoder.layers.24.mlp.fc2.weight": "model.safetensors",
|
| 606 |
+
"vision_model.vision_model.encoder.layers.24.self_attn.k_proj.bias": "model.safetensors",
|
| 607 |
+
"vision_model.vision_model.encoder.layers.24.self_attn.k_proj.weight": "model.safetensors",
|
| 608 |
+
"vision_model.vision_model.encoder.layers.24.self_attn.out_proj.bias": "model.safetensors",
|
| 609 |
+
"vision_model.vision_model.encoder.layers.24.self_attn.out_proj.weight": "model.safetensors",
|
| 610 |
+
"vision_model.vision_model.encoder.layers.24.self_attn.q_proj.bias": "model.safetensors",
|
| 611 |
+
"vision_model.vision_model.encoder.layers.24.self_attn.q_proj.weight": "model.safetensors",
|
| 612 |
+
"vision_model.vision_model.encoder.layers.24.self_attn.v_proj.bias": "model.safetensors",
|
| 613 |
+
"vision_model.vision_model.encoder.layers.24.self_attn.v_proj.weight": "model.safetensors",
|
| 614 |
+
"vision_model.vision_model.encoder.layers.25.layer_norm1.bias": "model.safetensors",
|
| 615 |
+
"vision_model.vision_model.encoder.layers.25.layer_norm1.weight": "model.safetensors",
|
| 616 |
+
"vision_model.vision_model.encoder.layers.25.layer_norm2.bias": "model.safetensors",
|
| 617 |
+
"vision_model.vision_model.encoder.layers.25.layer_norm2.weight": "model.safetensors",
|
| 618 |
+
"vision_model.vision_model.encoder.layers.25.mlp.fc1.bias": "model.safetensors",
|
| 619 |
+
"vision_model.vision_model.encoder.layers.25.mlp.fc1.weight": "model.safetensors",
|
| 620 |
+
"vision_model.vision_model.encoder.layers.25.mlp.fc2.bias": "model.safetensors",
|
| 621 |
+
"vision_model.vision_model.encoder.layers.25.mlp.fc2.weight": "model.safetensors",
|
| 622 |
+
"vision_model.vision_model.encoder.layers.25.self_attn.k_proj.bias": "model.safetensors",
|
| 623 |
+
"vision_model.vision_model.encoder.layers.25.self_attn.k_proj.weight": "model.safetensors",
|
| 624 |
+
"vision_model.vision_model.encoder.layers.25.self_attn.out_proj.bias": "model.safetensors",
|
| 625 |
+
"vision_model.vision_model.encoder.layers.25.self_attn.out_proj.weight": "model.safetensors",
|
| 626 |
+
"vision_model.vision_model.encoder.layers.25.self_attn.q_proj.bias": "model.safetensors",
|
| 627 |
+
"vision_model.vision_model.encoder.layers.25.self_attn.q_proj.weight": "model.safetensors",
|
| 628 |
+
"vision_model.vision_model.encoder.layers.25.self_attn.v_proj.bias": "model.safetensors",
|
| 629 |
+
"vision_model.vision_model.encoder.layers.25.self_attn.v_proj.weight": "model.safetensors",
|
| 630 |
+
"vision_model.vision_model.encoder.layers.26.layer_norm1.bias": "model.safetensors",
|
| 631 |
+
"vision_model.vision_model.encoder.layers.26.layer_norm1.weight": "model.safetensors",
|
| 632 |
+
"vision_model.vision_model.encoder.layers.26.layer_norm2.bias": "model.safetensors",
|
| 633 |
+
"vision_model.vision_model.encoder.layers.26.layer_norm2.weight": "model.safetensors",
|
| 634 |
+
"vision_model.vision_model.encoder.layers.26.mlp.fc1.bias": "model.safetensors",
|
| 635 |
+
"vision_model.vision_model.encoder.layers.26.mlp.fc1.weight": "model.safetensors",
|
| 636 |
+
"vision_model.vision_model.encoder.layers.26.mlp.fc2.bias": "model.safetensors",
|
| 637 |
+
"vision_model.vision_model.encoder.layers.26.mlp.fc2.weight": "model.safetensors",
|
| 638 |
+
"vision_model.vision_model.encoder.layers.26.self_attn.k_proj.bias": "model.safetensors",
|
| 639 |
+
"vision_model.vision_model.encoder.layers.26.self_attn.k_proj.weight": "model.safetensors",
|
| 640 |
+
"vision_model.vision_model.encoder.layers.26.self_attn.out_proj.bias": "model.safetensors",
|
| 641 |
+
"vision_model.vision_model.encoder.layers.26.self_attn.out_proj.weight": "model.safetensors",
|
| 642 |
+
"vision_model.vision_model.encoder.layers.26.self_attn.q_proj.bias": "model.safetensors",
|
| 643 |
+
"vision_model.vision_model.encoder.layers.26.self_attn.q_proj.weight": "model.safetensors",
|
| 644 |
+
"vision_model.vision_model.encoder.layers.26.self_attn.v_proj.bias": "model.safetensors",
|
| 645 |
+
"vision_model.vision_model.encoder.layers.26.self_attn.v_proj.weight": "model.safetensors",
|
| 646 |
+
"vision_model.vision_model.encoder.layers.3.layer_norm1.bias": "model.safetensors",
|
| 647 |
+
"vision_model.vision_model.encoder.layers.3.layer_norm1.weight": "model.safetensors",
|
| 648 |
+
"vision_model.vision_model.encoder.layers.3.layer_norm2.bias": "model.safetensors",
|
| 649 |
+
"vision_model.vision_model.encoder.layers.3.layer_norm2.weight": "model.safetensors",
|
| 650 |
+
"vision_model.vision_model.encoder.layers.3.mlp.fc1.bias": "model.safetensors",
|
| 651 |
+
"vision_model.vision_model.encoder.layers.3.mlp.fc1.weight": "model.safetensors",
|
| 652 |
+
"vision_model.vision_model.encoder.layers.3.mlp.fc2.bias": "model.safetensors",
|
| 653 |
+
"vision_model.vision_model.encoder.layers.3.mlp.fc2.weight": "model.safetensors",
|
| 654 |
+
"vision_model.vision_model.encoder.layers.3.self_attn.k_proj.bias": "model.safetensors",
|
| 655 |
+
"vision_model.vision_model.encoder.layers.3.self_attn.k_proj.weight": "model.safetensors",
|
| 656 |
+
"vision_model.vision_model.encoder.layers.3.self_attn.out_proj.bias": "model.safetensors",
|
| 657 |
+
"vision_model.vision_model.encoder.layers.3.self_attn.out_proj.weight": "model.safetensors",
|
| 658 |
+
"vision_model.vision_model.encoder.layers.3.self_attn.q_proj.bias": "model.safetensors",
|
| 659 |
+
"vision_model.vision_model.encoder.layers.3.self_attn.q_proj.weight": "model.safetensors",
|
| 660 |
+
"vision_model.vision_model.encoder.layers.3.self_attn.v_proj.bias": "model.safetensors",
|
| 661 |
+
"vision_model.vision_model.encoder.layers.3.self_attn.v_proj.weight": "model.safetensors",
|
| 662 |
+
"vision_model.vision_model.encoder.layers.4.layer_norm1.bias": "model.safetensors",
|
| 663 |
+
"vision_model.vision_model.encoder.layers.4.layer_norm1.weight": "model.safetensors",
|
| 664 |
+
"vision_model.vision_model.encoder.layers.4.layer_norm2.bias": "model.safetensors",
|
| 665 |
+
"vision_model.vision_model.encoder.layers.4.layer_norm2.weight": "model.safetensors",
|
| 666 |
+
"vision_model.vision_model.encoder.layers.4.mlp.fc1.bias": "model.safetensors",
|
| 667 |
+
"vision_model.vision_model.encoder.layers.4.mlp.fc1.weight": "model.safetensors",
|
| 668 |
+
"vision_model.vision_model.encoder.layers.4.mlp.fc2.bias": "model.safetensors",
|
| 669 |
+
"vision_model.vision_model.encoder.layers.4.mlp.fc2.weight": "model.safetensors",
|
| 670 |
+
"vision_model.vision_model.encoder.layers.4.self_attn.k_proj.bias": "model.safetensors",
|
| 671 |
+
"vision_model.vision_model.encoder.layers.4.self_attn.k_proj.weight": "model.safetensors",
|
| 672 |
+
"vision_model.vision_model.encoder.layers.4.self_attn.out_proj.bias": "model.safetensors",
|
| 673 |
+
"vision_model.vision_model.encoder.layers.4.self_attn.out_proj.weight": "model.safetensors",
|
| 674 |
+
"vision_model.vision_model.encoder.layers.4.self_attn.q_proj.bias": "model.safetensors",
|
| 675 |
+
"vision_model.vision_model.encoder.layers.4.self_attn.q_proj.weight": "model.safetensors",
|
| 676 |
+
"vision_model.vision_model.encoder.layers.4.self_attn.v_proj.bias": "model.safetensors",
|
| 677 |
+
"vision_model.vision_model.encoder.layers.4.self_attn.v_proj.weight": "model.safetensors",
|
| 678 |
+
"vision_model.vision_model.encoder.layers.5.layer_norm1.bias": "model.safetensors",
|
| 679 |
+
"vision_model.vision_model.encoder.layers.5.layer_norm1.weight": "model.safetensors",
|
| 680 |
+
"vision_model.vision_model.encoder.layers.5.layer_norm2.bias": "model.safetensors",
|
| 681 |
+
"vision_model.vision_model.encoder.layers.5.layer_norm2.weight": "model.safetensors",
|
| 682 |
+
"vision_model.vision_model.encoder.layers.5.mlp.fc1.bias": "model.safetensors",
|
| 683 |
+
"vision_model.vision_model.encoder.layers.5.mlp.fc1.weight": "model.safetensors",
|
| 684 |
+
"vision_model.vision_model.encoder.layers.5.mlp.fc2.bias": "model.safetensors",
|
| 685 |
+
"vision_model.vision_model.encoder.layers.5.mlp.fc2.weight": "model.safetensors",
|
| 686 |
+
"vision_model.vision_model.encoder.layers.5.self_attn.k_proj.bias": "model.safetensors",
|
| 687 |
+
"vision_model.vision_model.encoder.layers.5.self_attn.k_proj.weight": "model.safetensors",
|
| 688 |
+
"vision_model.vision_model.encoder.layers.5.self_attn.out_proj.bias": "model.safetensors",
|
| 689 |
+
"vision_model.vision_model.encoder.layers.5.self_attn.out_proj.weight": "model.safetensors",
|
| 690 |
+
"vision_model.vision_model.encoder.layers.5.self_attn.q_proj.bias": "model.safetensors",
|
| 691 |
+
"vision_model.vision_model.encoder.layers.5.self_attn.q_proj.weight": "model.safetensors",
|
| 692 |
+
"vision_model.vision_model.encoder.layers.5.self_attn.v_proj.bias": "model.safetensors",
|
| 693 |
+
"vision_model.vision_model.encoder.layers.5.self_attn.v_proj.weight": "model.safetensors",
|
| 694 |
+
"vision_model.vision_model.encoder.layers.6.layer_norm1.bias": "model.safetensors",
|
| 695 |
+
"vision_model.vision_model.encoder.layers.6.layer_norm1.weight": "model.safetensors",
|
| 696 |
+
"vision_model.vision_model.encoder.layers.6.layer_norm2.bias": "model.safetensors",
|
| 697 |
+
"vision_model.vision_model.encoder.layers.6.layer_norm2.weight": "model.safetensors",
|
| 698 |
+
"vision_model.vision_model.encoder.layers.6.mlp.fc1.bias": "model.safetensors",
|
| 699 |
+
"vision_model.vision_model.encoder.layers.6.mlp.fc1.weight": "model.safetensors",
|
| 700 |
+
"vision_model.vision_model.encoder.layers.6.mlp.fc2.bias": "model.safetensors",
|
| 701 |
+
"vision_model.vision_model.encoder.layers.6.mlp.fc2.weight": "model.safetensors",
|
| 702 |
+
"vision_model.vision_model.encoder.layers.6.self_attn.k_proj.bias": "model.safetensors",
|
| 703 |
+
"vision_model.vision_model.encoder.layers.6.self_attn.k_proj.weight": "model.safetensors",
|
| 704 |
+
"vision_model.vision_model.encoder.layers.6.self_attn.out_proj.bias": "model.safetensors",
|
| 705 |
+
"vision_model.vision_model.encoder.layers.6.self_attn.out_proj.weight": "model.safetensors",
|
| 706 |
+
"vision_model.vision_model.encoder.layers.6.self_attn.q_proj.bias": "model.safetensors",
|
| 707 |
+
"vision_model.vision_model.encoder.layers.6.self_attn.q_proj.weight": "model.safetensors",
|
| 708 |
+
"vision_model.vision_model.encoder.layers.6.self_attn.v_proj.bias": "model.safetensors",
|
| 709 |
+
"vision_model.vision_model.encoder.layers.6.self_attn.v_proj.weight": "model.safetensors",
|
| 710 |
+
"vision_model.vision_model.encoder.layers.7.layer_norm1.bias": "model.safetensors",
|
| 711 |
+
"vision_model.vision_model.encoder.layers.7.layer_norm1.weight": "model.safetensors",
|
| 712 |
+
"vision_model.vision_model.encoder.layers.7.layer_norm2.bias": "model.safetensors",
|
| 713 |
+
"vision_model.vision_model.encoder.layers.7.layer_norm2.weight": "model.safetensors",
|
| 714 |
+
"vision_model.vision_model.encoder.layers.7.mlp.fc1.bias": "model.safetensors",
|
| 715 |
+
"vision_model.vision_model.encoder.layers.7.mlp.fc1.weight": "model.safetensors",
|
| 716 |
+
"vision_model.vision_model.encoder.layers.7.mlp.fc2.bias": "model.safetensors",
|
| 717 |
+
"vision_model.vision_model.encoder.layers.7.mlp.fc2.weight": "model.safetensors",
|
| 718 |
+
"vision_model.vision_model.encoder.layers.7.self_attn.k_proj.bias": "model.safetensors",
|
| 719 |
+
"vision_model.vision_model.encoder.layers.7.self_attn.k_proj.weight": "model.safetensors",
|
| 720 |
+
"vision_model.vision_model.encoder.layers.7.self_attn.out_proj.bias": "model.safetensors",
|
| 721 |
+
"vision_model.vision_model.encoder.layers.7.self_attn.out_proj.weight": "model.safetensors",
|
| 722 |
+
"vision_model.vision_model.encoder.layers.7.self_attn.q_proj.bias": "model.safetensors",
|
| 723 |
+
"vision_model.vision_model.encoder.layers.7.self_attn.q_proj.weight": "model.safetensors",
|
| 724 |
+
"vision_model.vision_model.encoder.layers.7.self_attn.v_proj.bias": "model.safetensors",
|
| 725 |
+
"vision_model.vision_model.encoder.layers.7.self_attn.v_proj.weight": "model.safetensors",
|
| 726 |
+
"vision_model.vision_model.encoder.layers.8.layer_norm1.bias": "model.safetensors",
|
| 727 |
+
"vision_model.vision_model.encoder.layers.8.layer_norm1.weight": "model.safetensors",
|
| 728 |
+
"vision_model.vision_model.encoder.layers.8.layer_norm2.bias": "model.safetensors",
|
| 729 |
+
"vision_model.vision_model.encoder.layers.8.layer_norm2.weight": "model.safetensors",
|
| 730 |
+
"vision_model.vision_model.encoder.layers.8.mlp.fc1.bias": "model.safetensors",
|
| 731 |
+
"vision_model.vision_model.encoder.layers.8.mlp.fc1.weight": "model.safetensors",
|
| 732 |
+
"vision_model.vision_model.encoder.layers.8.mlp.fc2.bias": "model.safetensors",
|
| 733 |
+
"vision_model.vision_model.encoder.layers.8.mlp.fc2.weight": "model.safetensors",
|
| 734 |
+
"vision_model.vision_model.encoder.layers.8.self_attn.k_proj.bias": "model.safetensors",
|
| 735 |
+
"vision_model.vision_model.encoder.layers.8.self_attn.k_proj.weight": "model.safetensors",
|
| 736 |
+
"vision_model.vision_model.encoder.layers.8.self_attn.out_proj.bias": "model.safetensors",
|
| 737 |
+
"vision_model.vision_model.encoder.layers.8.self_attn.out_proj.weight": "model.safetensors",
|
| 738 |
+
"vision_model.vision_model.encoder.layers.8.self_attn.q_proj.bias": "model.safetensors",
|
| 739 |
+
"vision_model.vision_model.encoder.layers.8.self_attn.q_proj.weight": "model.safetensors",
|
| 740 |
+
"vision_model.vision_model.encoder.layers.8.self_attn.v_proj.bias": "model.safetensors",
|
| 741 |
+
"vision_model.vision_model.encoder.layers.8.self_attn.v_proj.weight": "model.safetensors",
|
| 742 |
+
"vision_model.vision_model.encoder.layers.9.layer_norm1.bias": "model.safetensors",
|
| 743 |
+
"vision_model.vision_model.encoder.layers.9.layer_norm1.weight": "model.safetensors",
|
| 744 |
+
"vision_model.vision_model.encoder.layers.9.layer_norm2.bias": "model.safetensors",
|
| 745 |
+
"vision_model.vision_model.encoder.layers.9.layer_norm2.weight": "model.safetensors",
|
| 746 |
+
"vision_model.vision_model.encoder.layers.9.mlp.fc1.bias": "model.safetensors",
|
| 747 |
+
"vision_model.vision_model.encoder.layers.9.mlp.fc1.weight": "model.safetensors",
|
| 748 |
+
"vision_model.vision_model.encoder.layers.9.mlp.fc2.bias": "model.safetensors",
|
| 749 |
+
"vision_model.vision_model.encoder.layers.9.mlp.fc2.weight": "model.safetensors",
|
| 750 |
+
"vision_model.vision_model.encoder.layers.9.self_attn.k_proj.bias": "model.safetensors",
|
| 751 |
+
"vision_model.vision_model.encoder.layers.9.self_attn.k_proj.weight": "model.safetensors",
|
| 752 |
+
"vision_model.vision_model.encoder.layers.9.self_attn.out_proj.bias": "model.safetensors",
|
| 753 |
+
"vision_model.vision_model.encoder.layers.9.self_attn.out_proj.weight": "model.safetensors",
|
| 754 |
+
"vision_model.vision_model.encoder.layers.9.self_attn.q_proj.bias": "model.safetensors",
|
| 755 |
+
"vision_model.vision_model.encoder.layers.9.self_attn.q_proj.weight": "model.safetensors",
|
| 756 |
+
"vision_model.vision_model.encoder.layers.9.self_attn.v_proj.bias": "model.safetensors",
|
| 757 |
+
"vision_model.vision_model.encoder.layers.9.self_attn.v_proj.weight": "model.safetensors",
|
| 758 |
+
"vision_model.vision_model.head.attention.in_proj_bias": "model.safetensors",
|
| 759 |
+
"vision_model.vision_model.head.attention.in_proj_weight": "model.safetensors",
|
| 760 |
+
"vision_model.vision_model.head.attention.out_proj.bias": "model.safetensors",
|
| 761 |
+
"vision_model.vision_model.head.attention.out_proj.weight": "model.safetensors",
|
| 762 |
+
"vision_model.vision_model.head.layernorm.bias": "model.safetensors",
|
| 763 |
+
"vision_model.vision_model.head.layernorm.weight": "model.safetensors",
|
| 764 |
+
"vision_model.vision_model.head.mlp.fc1.bias": "model.safetensors",
|
| 765 |
+
"vision_model.vision_model.head.mlp.fc1.weight": "model.safetensors",
|
| 766 |
+
"vision_model.vision_model.head.mlp.fc2.bias": "model.safetensors",
|
| 767 |
+
"vision_model.vision_model.head.mlp.fc2.weight": "model.safetensors",
|
| 768 |
+
"vision_model.vision_model.head.probe": "model.safetensors",
|
| 769 |
+
"vision_model.vision_model.post_layernorm.bias": "model.safetensors",
|
| 770 |
+
"vision_model.vision_model.post_layernorm.weight": "model.safetensors"
|
| 771 |
+
}
|
| 772 |
+
}
|
modeling_eagle3_vl.py
ADDED
|
@@ -0,0 +1,415 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# --------------------------------------------------------
|
| 2 |
+
# NVIDIA
|
| 3 |
+
# Copyright (c) 2025 NVIDIA
|
| 4 |
+
# Licensed under The MIT License [see LICENSE for details]
|
| 5 |
+
# --------------------------------------------------------
|
| 6 |
+
|
| 7 |
+
import warnings
|
| 8 |
+
import inspect
|
| 9 |
+
from typing import Any, List, Optional, Tuple, Union
|
| 10 |
+
import torch
|
| 11 |
+
from torch import nn
|
| 12 |
+
import torch.distributed as dist
|
| 13 |
+
from torch.nn import CrossEntropyLoss
|
| 14 |
+
import torch.nn.functional as F
|
| 15 |
+
from transformers.models.qwen2.modeling_qwen2 import Qwen2ForCausalLM
|
| 16 |
+
from transformers.models.qwen3.modeling_qwen3 import Qwen3ForCausalLM
|
| 17 |
+
from transformers.models.llama.modeling_llama import LlamaForCausalLM
|
| 18 |
+
import torch.utils.checkpoint as cp
|
| 19 |
+
from transformers.models.siglip.modeling_siglip import SiglipVisionModel
|
| 20 |
+
from .modeling_siglip2 import Siglip2VisionModel
|
| 21 |
+
from peft import LoraConfig, get_peft_model
|
| 22 |
+
from transformers.generation import GenerationMixin
|
| 23 |
+
from transformers import GenerationConfig
|
| 24 |
+
from transformers.modeling_outputs import CausalLMOutputWithPast
|
| 25 |
+
from transformers.modeling_utils import PreTrainedModel
|
| 26 |
+
from transformers.utils import ModelOutput, logging
|
| 27 |
+
from .configuration_eagle3_vl import Eagle3_VLConfig
|
| 28 |
+
from transformers.utils import add_start_docstrings, add_start_docstrings_to_model_forward, logging, replace_return_docstrings
|
| 29 |
+
from collections import defaultdict
|
| 30 |
+
logger = logging.get_logger(__name__)
|
| 31 |
+
|
| 32 |
+
# copy from https://github.com/huggingface/transformers/blob/main/src/transformers/models/llava_onevision/modeling_llava_onevision.py#L241C1-L280C1
|
| 33 |
+
EAGLE3_VL_START_DOCSTRING = r"""
|
| 34 |
+
This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
|
| 35 |
+
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
|
| 36 |
+
etc.)
|
| 37 |
+
|
| 38 |
+
This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
|
| 39 |
+
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
|
| 40 |
+
and behavior.
|
| 41 |
+
|
| 42 |
+
Parameters:
|
| 43 |
+
config ([`Eagle3_VLConfig`]):
|
| 44 |
+
Model configuration class with all the parameters of the model. Initializing with a config file does not
|
| 45 |
+
load the weights associated with the model, only the configuration. Check out the
|
| 46 |
+
[`~PreTrainedModel.from_pretrained`] method to load the model weights.
|
| 47 |
+
"""
|
| 48 |
+
|
| 49 |
+
@add_start_docstrings(
|
| 50 |
+
"The bare Eagle3_VL Model outputting raw hidden-states without any specific head on top.",
|
| 51 |
+
EAGLE3_VL_START_DOCSTRING,
|
| 52 |
+
)
|
| 53 |
+
class Eagle3_VLPreTrainedModel(PreTrainedModel):
|
| 54 |
+
config_class = Eagle3_VLConfig
|
| 55 |
+
base_model_prefix = "model"
|
| 56 |
+
main_input_name = 'input_ids'
|
| 57 |
+
supports_gradient_checkpointing = True
|
| 58 |
+
_no_split_modules = ["Qwen2DecoderLayer", "LlamaDecoderLayer" ,"Siglip2EncoderLayer", "SiglipEncoderLayer"]
|
| 59 |
+
_skip_keys_device_placement = "past_key_values"
|
| 60 |
+
_supports_flash_attn_2 = True
|
| 61 |
+
_supports_cache_class = True
|
| 62 |
+
_supports_static_cache = True
|
| 63 |
+
_supports_quantized_cache = True
|
| 64 |
+
_supports_sdpa = True
|
| 65 |
+
|
| 66 |
+
def _init_weights(self, module):
|
| 67 |
+
std = self.config.initializer_range
|
| 68 |
+
if isinstance(module, (nn.Linear, nn.Conv2d)):
|
| 69 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
| 70 |
+
if module.bias is not None:
|
| 71 |
+
module.bias.data.zero_()
|
| 72 |
+
elif isinstance(module, nn.Embedding):
|
| 73 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
| 74 |
+
if module.padding_idx is not None:
|
| 75 |
+
module.weight.data[module.padding_idx].zero_()
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
class Eagle3_VLForConditionalGeneration(Eagle3_VLPreTrainedModel, GenerationMixin):
|
| 79 |
+
config_class = Eagle3_VLConfig
|
| 80 |
+
def __init__(self, config: Eagle3_VLConfig, vision_model=None, language_model=None):
|
| 81 |
+
super().__init__(config)
|
| 82 |
+
|
| 83 |
+
self.select_layer = config.select_layer
|
| 84 |
+
self.template = config.template
|
| 85 |
+
self.downsample_ratio = config.downsample_ratio
|
| 86 |
+
self.loss_version = config.loss_version
|
| 87 |
+
self.mlp_checkpoint = config.mlp_checkpoint
|
| 88 |
+
|
| 89 |
+
logger.info(f'mlp_checkpoint: {self.mlp_checkpoint}')
|
| 90 |
+
if vision_model is not None:
|
| 91 |
+
self.vision_model = vision_model
|
| 92 |
+
else:
|
| 93 |
+
if config.vision_config.model_type == 'intern_vit_6b':
|
| 94 |
+
self.vision_model = InternVisionModel(config.vision_config)
|
| 95 |
+
elif config.vision_config.model_type == 'siglip_vision_model':
|
| 96 |
+
config.vision_config._attn_implementation = 'flash_attention_2'
|
| 97 |
+
self.vision_model = SiglipVisionModel(config.vision_config)
|
| 98 |
+
elif config.vision_config.model_type == 'siglip2_vision_model':
|
| 99 |
+
config.vision_config._attn_implementation = 'flash_attention_2'
|
| 100 |
+
self.vision_model = Siglip2VisionModel(config.vision_config)
|
| 101 |
+
elif config.vision_config.model_type == 'radio':
|
| 102 |
+
self.vision_model = RADIOModel(config.vision_config)
|
| 103 |
+
|
| 104 |
+
if language_model is not None:
|
| 105 |
+
self.language_model = language_model
|
| 106 |
+
else:
|
| 107 |
+
if config.text_config.architectures[0] == 'LlamaForCausalLM':
|
| 108 |
+
self.language_model = LlamaForCausalLM(config.text_config)
|
| 109 |
+
elif config.text_config.architectures[0] == 'Phi3ForCausalLM':
|
| 110 |
+
self.language_model = Phi3ForCausalLM(config.text_config)
|
| 111 |
+
elif config.text_config.architectures[0] == 'Qwen2ForCausalLM':
|
| 112 |
+
assert config.text_config._attn_implementation == 'flash_attention_2', f"Qwen2 must use flash_attention_2 but got {config.text_config._attn_implementation}"
|
| 113 |
+
self.language_model = Qwen2ForCausalLM(config.text_config)
|
| 114 |
+
elif config.text_config.architectures[0] == 'Qwen3ForCausalLM':
|
| 115 |
+
assert config.text_config._attn_implementation == 'flash_attention_2', f"Qwen3 must use flash_attention_2 but got {config.text_config._attn_implementation}"
|
| 116 |
+
self.language_model = Qwen3ForCausalLM(config.text_config)
|
| 117 |
+
else:
|
| 118 |
+
raise NotImplementedError(f'{config.text_config.architectures[0]} is not implemented.')
|
| 119 |
+
|
| 120 |
+
vit_hidden_size = config.vision_config.hidden_size
|
| 121 |
+
llm_hidden_size = config.text_config.hidden_size
|
| 122 |
+
|
| 123 |
+
self.mlp1 = nn.Sequential(
|
| 124 |
+
nn.LayerNorm(vit_hidden_size * int(1 / self.downsample_ratio) ** 2),
|
| 125 |
+
nn.Linear(vit_hidden_size * int(1 / self.downsample_ratio) ** 2, llm_hidden_size),
|
| 126 |
+
nn.GELU(),
|
| 127 |
+
nn.Linear(llm_hidden_size, llm_hidden_size)
|
| 128 |
+
)
|
| 129 |
+
self.image_token_index = config.image_token_index
|
| 130 |
+
self.neftune_alpha = None
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
if config.use_backbone_lora:
|
| 134 |
+
self.wrap_backbone_lora(r=config.use_backbone_lora, lora_alpha=2 * config.use_backbone_lora)
|
| 135 |
+
|
| 136 |
+
self.use_llm_lora = config.use_llm_lora
|
| 137 |
+
if config.use_llm_lora:
|
| 138 |
+
self.wrap_llm_lora(r=config.use_llm_lora, lora_alpha=2 * config.use_llm_lora)
|
| 139 |
+
|
| 140 |
+
self.check_forward_kwargs()
|
| 141 |
+
|
| 142 |
+
def check_forward_kwargs(self):
|
| 143 |
+
# We intentionally avoid using **kwargs in forward because Hugging Face Transformers
|
| 144 |
+
# has special handling for functions with **kwargs parameters that would affect
|
| 145 |
+
# how our model is processed during training and inference.
|
| 146 |
+
forward_params = inspect.signature(self.forward).parameters
|
| 147 |
+
assert not any(k.kind == inspect.Parameter.VAR_KEYWORD for k in forward_params.values())
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def wrap_backbone_lora(self, r=128, lora_alpha=256, lora_dropout=0.05):
|
| 151 |
+
lora_config = LoraConfig(
|
| 152 |
+
r=r,
|
| 153 |
+
target_modules=['self_attn.q_proj', 'self_attn.k_proj', 'self_attn.v_proj', 'self_attn.out_proj',
|
| 154 |
+
'mlp.fc1', 'mlp.fc2'],
|
| 155 |
+
lora_alpha=lora_alpha,
|
| 156 |
+
lora_dropout=lora_dropout,
|
| 157 |
+
)
|
| 158 |
+
self.vision_model = get_peft_model(self.vision_model, lora_config)
|
| 159 |
+
self.vision_model.print_trainable_parameters()
|
| 160 |
+
|
| 161 |
+
def wrap_llm_lora(self, r=128, lora_alpha=256, lora_dropout=0.05):
|
| 162 |
+
lora_config = LoraConfig(
|
| 163 |
+
r=r,
|
| 164 |
+
target_modules=['self_attn.q_proj', 'self_attn.k_proj', 'self_attn.v_proj', 'self_attn.o_proj',
|
| 165 |
+
'mlp.gate_proj', 'mlp.down_proj', 'mlp.up_proj'],
|
| 166 |
+
lora_alpha=lora_alpha,
|
| 167 |
+
lora_dropout=lora_dropout,
|
| 168 |
+
task_type='CAUSAL_LM'
|
| 169 |
+
)
|
| 170 |
+
self.language_model = get_peft_model(self.language_model, lora_config)
|
| 171 |
+
self.language_model.enable_input_require_grads()
|
| 172 |
+
self.language_model.print_trainable_parameters()
|
| 173 |
+
self.use_llm_lora = True
|
| 174 |
+
|
| 175 |
+
def forward(
|
| 176 |
+
self,
|
| 177 |
+
pixel_values: List[torch.FloatTensor],
|
| 178 |
+
input_ids: torch.LongTensor = None,
|
| 179 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 180 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 181 |
+
image_flags: Optional[torch.LongTensor] = None,
|
| 182 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None,
|
| 183 |
+
labels: Optional[torch.LongTensor] = None,
|
| 184 |
+
use_cache: Optional[bool] = None,
|
| 185 |
+
output_attentions: Optional[bool] = None,
|
| 186 |
+
output_hidden_states: Optional[bool] = None,
|
| 187 |
+
return_dict: Optional[bool] = None,
|
| 188 |
+
) -> Union[Tuple, CausalLMOutputWithPast]:
|
| 189 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 190 |
+
|
| 191 |
+
input_embeds = self.language_model.get_input_embeddings()(input_ids)
|
| 192 |
+
|
| 193 |
+
num_images = len(pixel_values)
|
| 194 |
+
|
| 195 |
+
if image_flags is not None:
|
| 196 |
+
image_flags = image_flags.view(-1)
|
| 197 |
+
|
| 198 |
+
vit_embeds = self.extract_feature(pixel_values, image_flags)
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
B, N, C = input_embeds.shape
|
| 202 |
+
input_embeds = input_embeds.reshape(B * N, C)
|
| 203 |
+
|
| 204 |
+
input_ids = input_ids.reshape(B * N)
|
| 205 |
+
selected = (input_ids == self.image_token_index)
|
| 206 |
+
try:
|
| 207 |
+
input_embeds[selected] = input_embeds[selected] * 0.0 + vit_embeds
|
| 208 |
+
except Exception as e:
|
| 209 |
+
print(f'warning: {e}, input_embeds[selected].shape={input_embeds[selected].shape}, '
|
| 210 |
+
f'vit_embeds.shape={vit_embeds.shape}')
|
| 211 |
+
n_token = selected.sum()
|
| 212 |
+
input_embeds[selected] = input_embeds[selected] * 0.0 + vit_embeds[:n_token]
|
| 213 |
+
|
| 214 |
+
input_embeds = input_embeds.reshape(B, N, C)
|
| 215 |
+
|
| 216 |
+
outputs = self.language_model(
|
| 217 |
+
inputs_embeds=input_embeds,
|
| 218 |
+
attention_mask=attention_mask,
|
| 219 |
+
position_ids=position_ids,
|
| 220 |
+
past_key_values=past_key_values,
|
| 221 |
+
use_cache=use_cache,
|
| 222 |
+
output_attentions=output_attentions,
|
| 223 |
+
output_hidden_states=output_hidden_states,
|
| 224 |
+
)
|
| 225 |
+
logits = outputs.logits
|
| 226 |
+
|
| 227 |
+
loss = None
|
| 228 |
+
if labels is not None:
|
| 229 |
+
# Shift so that tokens < n predict n
|
| 230 |
+
shift_logits = logits[..., :-1, :].contiguous()
|
| 231 |
+
shift_labels = labels[..., 1:].contiguous()
|
| 232 |
+
# Flatten the tokens
|
| 233 |
+
loss_fct = CrossEntropyLoss()
|
| 234 |
+
shift_logits = shift_logits.view(-1, self.language_model.config.vocab_size)
|
| 235 |
+
shift_labels = shift_labels.view(-1)
|
| 236 |
+
# Enable model parallelism
|
| 237 |
+
shift_labels = shift_labels.to(shift_logits.device)
|
| 238 |
+
loss = loss_fct(shift_logits, shift_labels)
|
| 239 |
+
|
| 240 |
+
if not return_dict:
|
| 241 |
+
output = (logits,) + outputs[1:]
|
| 242 |
+
return (loss,) + output if loss is not None else output
|
| 243 |
+
|
| 244 |
+
return CausalLMOutputWithPast(
|
| 245 |
+
loss=loss,
|
| 246 |
+
logits=logits,
|
| 247 |
+
past_key_values=outputs.past_key_values,
|
| 248 |
+
hidden_states=outputs.hidden_states,
|
| 249 |
+
attentions=outputs.attentions,
|
| 250 |
+
)
|
| 251 |
+
|
| 252 |
+
def pixel_shuffle_back(self, vit_embeds, spatial_shapes):
|
| 253 |
+
# Assume vit_embeds: [1, 15020, 1152], spatial_shapes: [(h1,w1), (h2,w2), ...] length 64
|
| 254 |
+
B, N, C = vit_embeds.shape
|
| 255 |
+
shapes = spatial_shapes.tolist() # List of (h, w)
|
| 256 |
+
|
| 257 |
+
# 1) Split at once
|
| 258 |
+
lengths = [h * w for (h, w) in shapes] # Number of patches per image
|
| 259 |
+
slices = torch.split(vit_embeds.view(-1, C), lengths, dim=0)
|
| 260 |
+
# slices[i]: [hi*wi, C]
|
| 261 |
+
|
| 262 |
+
# 2) Convert to [C, H, W]
|
| 263 |
+
features = [
|
| 264 |
+
sl.transpose(0, 1).reshape(C, h, w)
|
| 265 |
+
for sl, (h, w) in zip(slices, shapes)
|
| 266 |
+
] # Each item [C, hi, wi]
|
| 267 |
+
# visualize_tensor_list(features, 'features.jpg')
|
| 268 |
+
|
| 269 |
+
# 3) Group by scale and batch unshuffle
|
| 270 |
+
down_feats = [None] * len(features)
|
| 271 |
+
grouped: dict = defaultdict(list)
|
| 272 |
+
for idx, (h, w) in enumerate(shapes):
|
| 273 |
+
grouped[(h, w)].append(idx)
|
| 274 |
+
|
| 275 |
+
for (h, w), idxs in grouped.items():
|
| 276 |
+
# Stack features of the same scale -> [n, C, H, W]
|
| 277 |
+
grp = torch.stack([features[i] for i in idxs], dim=0)
|
| 278 |
+
# Pixel Unshuffle at once
|
| 279 |
+
out = F.pixel_unshuffle(grp, downscale_factor=int(1/self.downsample_ratio)) # [n, C*4, H//2, W//2]
|
| 280 |
+
out = out.flatten(start_dim=2).transpose(1, 2) # [n, H//2 * W//2, C*4]
|
| 281 |
+
# Split back to respective positions
|
| 282 |
+
for i, feat in zip(idxs, out):
|
| 283 |
+
down_feats[i] = feat
|
| 284 |
+
|
| 285 |
+
down_feats = torch.cat(down_feats, dim=0).unsqueeze(0)
|
| 286 |
+
return down_feats, (spatial_shapes*self.downsample_ratio).to(torch.int32)
|
| 287 |
+
|
| 288 |
+
def mask_valid_tokens(self, vit_embeds, spatial_shapes, image_flags):
|
| 289 |
+
"""
|
| 290 |
+
vit_embeds: Tensor, shape [1, N, C] or [N, C]
|
| 291 |
+
spatial_shapes: Tensor of shape [num_images, 2], each row is (H, W)
|
| 292 |
+
image_flags: list[int], e.g. [1, 0, 1, ...]
|
| 293 |
+
Returns:
|
| 294 |
+
valid_tokens: Tensor [num_valid_tokens, C]
|
| 295 |
+
"""
|
| 296 |
+
|
| 297 |
+
lengths = spatial_shapes[:, 0] * spatial_shapes[:, 1] # [num_images]
|
| 298 |
+
valid_mask = []
|
| 299 |
+
for flag, length in zip(image_flags, lengths):
|
| 300 |
+
valid_mask.extend([flag] * length)
|
| 301 |
+
|
| 302 |
+
valid_mask = torch.tensor(valid_mask, dtype=torch.bool, device=vit_embeds.device)
|
| 303 |
+
valid_tokens = vit_embeds[valid_mask] # [num_valid_tokens, C]
|
| 304 |
+
|
| 305 |
+
return valid_tokens
|
| 306 |
+
|
| 307 |
+
def extract_feature(self, pixel_values, image_flags=None):
|
| 308 |
+
|
| 309 |
+
if self.select_layer == -1:
|
| 310 |
+
vision_model_output = self.vision_model(
|
| 311 |
+
pixel_values=pixel_values,
|
| 312 |
+
output_hidden_states=False,
|
| 313 |
+
return_dict=True)
|
| 314 |
+
if hasattr(vision_model_output, 'last_hidden_state'):
|
| 315 |
+
vit_embeds = vision_model_output.last_hidden_state
|
| 316 |
+
if hasattr(vision_model_output, 'spatial_shapes'):
|
| 317 |
+
spatial_shapes = vision_model_output.spatial_shapes
|
| 318 |
+
else:
|
| 319 |
+
vit_embeds = self.vision_model(
|
| 320 |
+
pixel_values=pixel_values,
|
| 321 |
+
output_hidden_states=True,
|
| 322 |
+
return_dict=True).hidden_states[self.select_layer]
|
| 323 |
+
|
| 324 |
+
vit_embeds, spatial_shapes = self.pixel_shuffle_back(vit_embeds, spatial_shapes)
|
| 325 |
+
|
| 326 |
+
|
| 327 |
+
if self.mlp_checkpoint and vit_embeds.requires_grad:
|
| 328 |
+
vit_embeds = cp.checkpoint(self.mlp1, vit_embeds)
|
| 329 |
+
else:
|
| 330 |
+
vit_embeds = self.mlp1(vit_embeds)
|
| 331 |
+
|
| 332 |
+
B, N, C = vit_embeds.shape
|
| 333 |
+
vit_embeds = vit_embeds.reshape(B * N, C)
|
| 334 |
+
|
| 335 |
+
if image_flags is not None and any(image_flags==0):
|
| 336 |
+
vit_embeds = self.mask_valid_tokens(vit_embeds, spatial_shapes, image_flags)
|
| 337 |
+
|
| 338 |
+
return vit_embeds
|
| 339 |
+
|
| 340 |
+
@torch.no_grad()
|
| 341 |
+
def generate(
|
| 342 |
+
self,
|
| 343 |
+
pixel_values: Optional[torch.FloatTensor] = None,
|
| 344 |
+
input_ids: Optional[torch.FloatTensor] = None,
|
| 345 |
+
attention_mask: Optional[torch.LongTensor] = None,
|
| 346 |
+
visual_features: Optional[torch.FloatTensor] = None,
|
| 347 |
+
generation_config: Optional[GenerationConfig] = None,
|
| 348 |
+
output_hidden_states: Optional[bool] = None,
|
| 349 |
+
image_sizes: Optional[List[Tuple[int, int]]] = None,
|
| 350 |
+
**generate_kwargs,
|
| 351 |
+
) -> torch.LongTensor:
|
| 352 |
+
|
| 353 |
+
if pixel_values is not None:
|
| 354 |
+
if visual_features is not None:
|
| 355 |
+
vit_embeds = visual_features
|
| 356 |
+
else:
|
| 357 |
+
pixel_values = [each.to(self.device) for each in pixel_values]
|
| 358 |
+
import time
|
| 359 |
+
torch.cuda.synchronize()
|
| 360 |
+
begin_time = time.time()
|
| 361 |
+
for _ in range(10):
|
| 362 |
+
vit_embeds = self.extract_feature(pixel_values)
|
| 363 |
+
torch.cuda.synchronize()
|
| 364 |
+
end_time = time.time()
|
| 365 |
+
|
| 366 |
+
input_embeds = self.language_model.get_input_embeddings()(input_ids)
|
| 367 |
+
B, N, C = input_embeds.shape
|
| 368 |
+
input_embeds = input_embeds.reshape(B * N, C)
|
| 369 |
+
|
| 370 |
+
input_ids = input_ids.reshape(B * N)
|
| 371 |
+
selected = (input_ids == self.config.image_token_index)
|
| 372 |
+
assert selected.sum() != 0
|
| 373 |
+
input_embeds[selected] = vit_embeds.to(input_embeds.device)
|
| 374 |
+
|
| 375 |
+
input_embeds = input_embeds.reshape(B, N, C)
|
| 376 |
+
else:
|
| 377 |
+
input_embeds = self.language_model.get_input_embeddings()(input_ids)
|
| 378 |
+
|
| 379 |
+
if 'use_cache' not in generate_kwargs:
|
| 380 |
+
generate_kwargs['use_cache'] = True
|
| 381 |
+
|
| 382 |
+
outputs = self.language_model.generate(
|
| 383 |
+
inputs_embeds=input_embeds,
|
| 384 |
+
attention_mask=attention_mask,
|
| 385 |
+
generation_config=generation_config,
|
| 386 |
+
output_hidden_states=output_hidden_states,
|
| 387 |
+
**generate_kwargs,
|
| 388 |
+
)
|
| 389 |
+
|
| 390 |
+
return outputs
|
| 391 |
+
|
| 392 |
+
# Copied from transformers.models.llava_next.modeling_llava_next.LlavaNextForConditionalGeneration.get_input_embeddings
|
| 393 |
+
def get_input_embeddings(self):
|
| 394 |
+
return self.language_model.get_input_embeddings()
|
| 395 |
+
|
| 396 |
+
# Copied from transformers.models.llava_next.modeling_llava_next.LlavaNextForConditionalGeneration.set_input_embeddings
|
| 397 |
+
def set_input_embeddings(self, value):
|
| 398 |
+
self.language_model.set_input_embeddings(value)
|
| 399 |
+
|
| 400 |
+
# Copied from transformers.models.llava_next.modeling_llava_next.LlavaNextForConditionalGeneration.get_output_embeddings
|
| 401 |
+
def get_output_embeddings(self):
|
| 402 |
+
return self.language_model.get_output_embeddings()
|
| 403 |
+
|
| 404 |
+
# Copied from transformers.models.llava_next.modeling_llava_next.LlavaNextForConditionalGeneration.set_output_embeddings
|
| 405 |
+
def set_output_embeddings(self, new_embeddings):
|
| 406 |
+
self.language_model.set_output_embeddings(new_embeddings)
|
| 407 |
+
|
| 408 |
+
# Copied from transformers.models.llava_next.modeling_llava_next.LlavaNextForConditionalGeneration.set_decoder
|
| 409 |
+
def set_decoder(self, decoder):
|
| 410 |
+
self.language_model.set_decoder(decoder)
|
| 411 |
+
|
| 412 |
+
# Copied from transformers.models.llava_next.modeling_llava_next.LlavaNextForConditionalGeneration.get_decoder
|
| 413 |
+
def get_decoder(self):
|
| 414 |
+
return self.language_model.get_decoder()
|
| 415 |
+
|
modeling_siglip2.py
ADDED
|
@@ -0,0 +1,1419 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
|
| 2 |
+
# This file was automatically generated from src/transformers/models/siglip2/modular_siglip2.py.
|
| 3 |
+
# Copyright 2025 The HuggingFace Inc. team.
|
| 4 |
+
#
|
| 5 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 6 |
+
# you may not use this file except in compliance with the License.
|
| 7 |
+
# You may obtain a copy of the License at
|
| 8 |
+
#
|
| 9 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
#
|
| 11 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
# See the License for the specific language governing permissions and
|
| 15 |
+
# limitations under the License.
|
| 16 |
+
import math
|
| 17 |
+
import warnings
|
| 18 |
+
from dataclasses import dataclass
|
| 19 |
+
from typing import Any, Callable, Optional, Tuple, Union, List
|
| 20 |
+
|
| 21 |
+
import numpy as np
|
| 22 |
+
import torch
|
| 23 |
+
import torch.nn as nn
|
| 24 |
+
import torch.nn.functional as F
|
| 25 |
+
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
|
| 26 |
+
from torch.nn.init import _calculate_fan_in_and_fan_out
|
| 27 |
+
|
| 28 |
+
from transformers.activations import ACT2FN
|
| 29 |
+
from transformers.modeling_attn_mask_utils import _prepare_4d_attention_mask
|
| 30 |
+
from transformers.configuration_utils import PretrainedConfig
|
| 31 |
+
|
| 32 |
+
from transformers.modeling_outputs import BaseModelOutput, BaseModelOutputWithPooling, ImageClassifierOutput
|
| 33 |
+
from transformers.modeling_utils import ALL_ATTENTION_FUNCTIONS, PreTrainedModel
|
| 34 |
+
from transformers.utils import (
|
| 35 |
+
ModelOutput,
|
| 36 |
+
add_start_docstrings,
|
| 37 |
+
add_start_docstrings_to_model_forward,
|
| 38 |
+
can_return_tuple,
|
| 39 |
+
logging,
|
| 40 |
+
replace_return_docstrings,
|
| 41 |
+
)
|
| 42 |
+
from transformers.models.siglip2.configuration_siglip2 import Siglip2Config, Siglip2TextConfig
|
| 43 |
+
from collections import defaultdict
|
| 44 |
+
from itertools import accumulate
|
| 45 |
+
from math import isqrt
|
| 46 |
+
from typing import Dict
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
logger = logging.get_logger(__name__)
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
import inspect
|
| 53 |
+
import os
|
| 54 |
+
from typing import Optional, Tuple
|
| 55 |
+
|
| 56 |
+
import torch
|
| 57 |
+
import torch.nn.functional as F
|
| 58 |
+
|
| 59 |
+
from transformers.utils import is_flash_attn_2_available, is_flash_attn_greater_or_equal, logging
|
| 60 |
+
from transformers.integrations.flash_attention import flash_attention_forward as original_flash_attention_forward
|
| 61 |
+
flash_241 = is_flash_attn_greater_or_equal("2.4.1")
|
| 62 |
+
deterministic_g = os.environ.get("FLASH_ATTENTION_DETERMINISTIC", "0") == "1"
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
logger = logging.get_logger(__name__)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
if is_flash_attn_2_available():
|
| 69 |
+
from flash_attn.bert_padding import index_first_axis, pad_input, unpad_input # noqa
|
| 70 |
+
from flash_attn import flash_attn_func, flash_attn_varlen_func, flash_attn_varlen_qkvpacked_func
|
| 71 |
+
|
| 72 |
+
_flash_supports_window_size = "window_size" in list(inspect.signature(flash_attn_func).parameters)
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def _flash_attention_forward(
|
| 76 |
+
query_states: torch.Tensor,
|
| 77 |
+
key_states: torch.Tensor,
|
| 78 |
+
value_states: torch.Tensor,
|
| 79 |
+
attention_mask: torch.Tensor,
|
| 80 |
+
query_length: int,
|
| 81 |
+
is_causal: bool,
|
| 82 |
+
dropout: float = 0.0,
|
| 83 |
+
position_ids: Optional[torch.Tensor] = None,
|
| 84 |
+
softmax_scale: Optional[float] = None,
|
| 85 |
+
sliding_window: Optional[int] = None,
|
| 86 |
+
use_top_left_mask: bool = False,
|
| 87 |
+
softcap: Optional[float] = None,
|
| 88 |
+
deterministic: bool = None,
|
| 89 |
+
cu_seq_lens_q: Optional[torch.LongTensor] = None,
|
| 90 |
+
cu_seq_lens_k: Optional[torch.LongTensor] = None,
|
| 91 |
+
max_length_q: Optional[int] = None,
|
| 92 |
+
max_length_k: Optional[int] = None,
|
| 93 |
+
target_dtype: Optional[torch.dtype] = None,
|
| 94 |
+
**kwargs,
|
| 95 |
+
):
|
| 96 |
+
"""
|
| 97 |
+
Calls the forward method of Flash Attention - if the input hidden states contain at least one padding token
|
| 98 |
+
first unpad the input, then computes the attention scores and pad the final attention scores.
|
| 99 |
+
Args:
|
| 100 |
+
query_states (`torch.Tensor`):
|
| 101 |
+
Input query states to be passed to Flash Attention API
|
| 102 |
+
key_states (`torch.Tensor`):
|
| 103 |
+
Input key states to be passed to Flash Attention API
|
| 104 |
+
value_states (`torch.Tensor`):
|
| 105 |
+
Input value states to be passed to Flash Attention API
|
| 106 |
+
attention_mask (`torch.Tensor`):
|
| 107 |
+
The padding mask - corresponds to a tensor of size `(batch_size, seq_len)` where 0 stands for the
|
| 108 |
+
position of padding tokens and 1 for the position of non-padding tokens.
|
| 109 |
+
dropout (`int`, *optional*):
|
| 110 |
+
Attention dropout
|
| 111 |
+
softmax_scale (`float`, *optional*):
|
| 112 |
+
The scaling of QK^T before applying softmax. Default to 1 / sqrt(head_dim)
|
| 113 |
+
use_sliding_windows (`bool`, *optional*):
|
| 114 |
+
Whether to activate sliding window attention.
|
| 115 |
+
"""
|
| 116 |
+
|
| 117 |
+
if not use_top_left_mask:
|
| 118 |
+
causal = is_causal
|
| 119 |
+
else:
|
| 120 |
+
# TODO: Remove the `query_length != 1` check once Flash Attention for RoCm is bumped to 2.1. For details, please see the comment in LlamaFlashAttention2 __init__.
|
| 121 |
+
causal = is_causal and query_length != 1
|
| 122 |
+
# Assuming 4D tensors, key_states.shape[1] is the key/value sequence length (source length).
|
| 123 |
+
use_sliding_windows = (
|
| 124 |
+
_flash_supports_window_size and sliding_window is not None and key_states.shape[1] > sliding_window
|
| 125 |
+
)
|
| 126 |
+
flash_kwargs = {"window_size": (sliding_window, sliding_window)} if use_sliding_windows else {}
|
| 127 |
+
if flash_241:
|
| 128 |
+
if deterministic is None:
|
| 129 |
+
deterministic = deterministic_g
|
| 130 |
+
flash_kwargs["deterministic"] = deterministic
|
| 131 |
+
|
| 132 |
+
if softcap is not None:
|
| 133 |
+
flash_kwargs["softcap"] = softcap
|
| 134 |
+
|
| 135 |
+
attn_output = flash_attn_varlen_func(
|
| 136 |
+
query_states[0],
|
| 137 |
+
key_states[0],
|
| 138 |
+
value_states[0],
|
| 139 |
+
cu_seqlens_q=cu_seq_lens_q,
|
| 140 |
+
cu_seqlens_k=cu_seq_lens_k,
|
| 141 |
+
max_seqlen_q=max_length_q,
|
| 142 |
+
max_seqlen_k=max_length_k,
|
| 143 |
+
dropout_p=dropout,
|
| 144 |
+
softmax_scale=softmax_scale,
|
| 145 |
+
causal=causal,
|
| 146 |
+
**flash_kwargs,
|
| 147 |
+
)
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
return attn_output
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
from transformers.utils import is_flash_attn_greater_or_equal_2_10
|
| 154 |
+
_use_top_left_mask = not is_flash_attn_greater_or_equal_2_10()
|
| 155 |
+
|
| 156 |
+
def flash_attention_forward_for_packing(
|
| 157 |
+
module: torch.nn.Module,
|
| 158 |
+
query: torch.Tensor,
|
| 159 |
+
key: torch.Tensor,
|
| 160 |
+
value: torch.Tensor,
|
| 161 |
+
attention_mask: Optional[torch.Tensor]=None,
|
| 162 |
+
dropout: float = 0.0,
|
| 163 |
+
scaling: Optional[float] = None,
|
| 164 |
+
sliding_window: Optional[int] = None,
|
| 165 |
+
softcap: Optional[float] = None,
|
| 166 |
+
seq_len_list: Optional[List[int]] = None,
|
| 167 |
+
**kwargs,
|
| 168 |
+
) -> Tuple[torch.Tensor, None]:
|
| 169 |
+
|
| 170 |
+
# This is before the transpose
|
| 171 |
+
seq_len = query.shape[2]
|
| 172 |
+
|
| 173 |
+
# FA2 uses non-transposed inputs
|
| 174 |
+
query = query.transpose(1, 2)
|
| 175 |
+
key = key.transpose(1, 2)
|
| 176 |
+
value = value.transpose(1, 2)
|
| 177 |
+
|
| 178 |
+
# In PEFT, usually we cast the layer norms in float32 for training stability reasons
|
| 179 |
+
# therefore the input hidden states gets silently casted in float32. Hence, we need
|
| 180 |
+
# cast them back in the correct dtype just to be sure everything works as expected.
|
| 181 |
+
# This might slowdown training & inference so it is recommended to not cast the LayerNorms
|
| 182 |
+
# in fp32. (usually our RMSNorm modules handle it correctly)
|
| 183 |
+
target_dtype = None
|
| 184 |
+
if query.dtype == torch.float32:
|
| 185 |
+
if torch.is_autocast_enabled():
|
| 186 |
+
target_dtype = torch.get_autocast_gpu_dtype()
|
| 187 |
+
# Handle the case where the model is quantized
|
| 188 |
+
elif hasattr(module.config, "_pre_quantization_dtype"):
|
| 189 |
+
target_dtype = module.config._pre_quantization_dtype
|
| 190 |
+
else:
|
| 191 |
+
target_dtype = next(layer for layer in module.modules() if isinstance(layer, torch.nn.Linear)).weight.dtype
|
| 192 |
+
|
| 193 |
+
# FA2 always relies on the value set in the module, so remove it if present in kwargs to avoid passing it twice
|
| 194 |
+
kwargs.pop("is_causal", None)
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
cu_seqlens = F.pad(torch.cumsum(torch.tensor(seq_len_list, device=query.device, dtype=torch.int32), dim=0), (1, 0))
|
| 198 |
+
cu_seqlens = cu_seqlens.to(torch.int32)
|
| 199 |
+
max_seq_len = max(seq_len_list)
|
| 200 |
+
attn_output = _flash_attention_forward(
|
| 201 |
+
query,
|
| 202 |
+
key,
|
| 203 |
+
value,
|
| 204 |
+
attention_mask,
|
| 205 |
+
query_length=seq_len,
|
| 206 |
+
is_causal=module.is_causal,
|
| 207 |
+
dropout=dropout,
|
| 208 |
+
softmax_scale=scaling,
|
| 209 |
+
sliding_window=sliding_window,
|
| 210 |
+
softcap=softcap,
|
| 211 |
+
use_top_left_mask=_use_top_left_mask,
|
| 212 |
+
target_dtype=target_dtype,
|
| 213 |
+
cu_seq_lens_q=cu_seqlens,
|
| 214 |
+
cu_seq_lens_k=cu_seqlens,
|
| 215 |
+
max_length_q=max_seq_len,
|
| 216 |
+
max_length_k=max_seq_len,
|
| 217 |
+
**kwargs,
|
| 218 |
+
)
|
| 219 |
+
return attn_output.squeeze(0), None
|
| 220 |
+
|
| 221 |
+
# General docstring
|
| 222 |
+
_CONFIG_FOR_DOC = "Siglip2Config"
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
class Siglip2VisionConfig(PretrainedConfig):
|
| 227 |
+
r"""
|
| 228 |
+
This is the configuration class to store the configuration of a [`Siglip2VisionModel`]. It is used to instantiate a
|
| 229 |
+
Siglip2 vision encoder according to the specified arguments, defining the model architecture. Instantiating a
|
| 230 |
+
configuration with the defaults will yield a similar configuration to that of the vision encoder of the Siglip2
|
| 231 |
+
[google/siglip2-base-patch16-naflex](https://huggingface.co/google/siglip2-base-patch16-naflex) architecture.
|
| 232 |
+
|
| 233 |
+
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
| 234 |
+
documentation from [`PretrainedConfig`] for more information.
|
| 235 |
+
|
| 236 |
+
Args:
|
| 237 |
+
hidden_size (`int`, *optional*, defaults to 768):
|
| 238 |
+
Dimensionality of the encoder layers and the pooler layer.
|
| 239 |
+
intermediate_size (`int`, *optional*, defaults to 3072):
|
| 240 |
+
Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
|
| 241 |
+
num_hidden_layers (`int`, *optional*, defaults to 12):
|
| 242 |
+
Number of hidden layers in the Transformer encoder.
|
| 243 |
+
num_attention_heads (`int`, *optional*, defaults to 12):
|
| 244 |
+
Number of attention heads for each attention layer in the Transformer encoder.
|
| 245 |
+
num_channels (`int`, *optional*, defaults to 3):
|
| 246 |
+
Number of channels in the input images.
|
| 247 |
+
num_patches (`int`, *optional*, defaults to 256):
|
| 248 |
+
The number of patches in the image with the size of (`patch_size`, `patch_size`).
|
| 249 |
+
The image is resized to fill maximum of this number of patches, and to preserve
|
| 250 |
+
the aspect ratio. In case the resulted number of patches is lower, the image is
|
| 251 |
+
padded in "patch" dimension.
|
| 252 |
+
patch_size (`int`, *optional*, defaults to 16):
|
| 253 |
+
The size (resolution) of each patch.
|
| 254 |
+
hidden_act (`str` or `function`, *optional*, defaults to `"gelu_pytorch_tanh"`):
|
| 255 |
+
The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
|
| 256 |
+
`"relu"`, `"selu"` and `"gelu_new"` `"quick_gelu"` are supported.
|
| 257 |
+
layer_norm_eps (`float`, *optional*, defaults to 1e-06):
|
| 258 |
+
The epsilon used by the layer normalization layers.
|
| 259 |
+
attention_dropout (`float`, *optional*, defaults to 0.0):
|
| 260 |
+
The dropout ratio for the attention probabilities.
|
| 261 |
+
|
| 262 |
+
Example:
|
| 263 |
+
|
| 264 |
+
```python
|
| 265 |
+
>>> from transformers import Siglip2VisionConfig, Siglip2VisionModel
|
| 266 |
+
|
| 267 |
+
>>> # Initializing a Siglip2VisionConfig with google/siglip2-base-patch16-naflex style configuration
|
| 268 |
+
>>> configuration = Siglip2VisionConfig()
|
| 269 |
+
|
| 270 |
+
>>> # Initializing a Siglip2VisionModel (with random weights) from the google/siglip2-base-patch16-naflex style configuration
|
| 271 |
+
>>> model = Siglip2VisionModel(configuration)
|
| 272 |
+
|
| 273 |
+
>>> # Accessing the model configuration
|
| 274 |
+
>>> configuration = model.config
|
| 275 |
+
```"""
|
| 276 |
+
|
| 277 |
+
model_type = "siglip2_vision_model"
|
| 278 |
+
base_config_key = "vision_config"
|
| 279 |
+
|
| 280 |
+
def __init__(
|
| 281 |
+
self,
|
| 282 |
+
hidden_size=1152,
|
| 283 |
+
intermediate_size=4304,
|
| 284 |
+
num_hidden_layers=27,
|
| 285 |
+
num_attention_heads=16,
|
| 286 |
+
num_channels=3,
|
| 287 |
+
num_patches=256,
|
| 288 |
+
patch_size=14, # manully modified
|
| 289 |
+
hidden_act="gelu_pytorch_tanh",
|
| 290 |
+
layer_norm_eps=1e-6,
|
| 291 |
+
attention_dropout=0.0,
|
| 292 |
+
window_size=14, #
|
| 293 |
+
full_attention_indexes=[7, 14, 21, 26],
|
| 294 |
+
use_rope=True,
|
| 295 |
+
use_windows_attn=True,
|
| 296 |
+
**kwargs,
|
| 297 |
+
):
|
| 298 |
+
super().__init__(**kwargs)
|
| 299 |
+
|
| 300 |
+
self.hidden_size = hidden_size
|
| 301 |
+
self.intermediate_size = intermediate_size
|
| 302 |
+
self.num_hidden_layers = num_hidden_layers
|
| 303 |
+
self.num_attention_heads = num_attention_heads
|
| 304 |
+
self.num_channels = num_channels
|
| 305 |
+
self.patch_size = patch_size
|
| 306 |
+
self.attention_dropout = attention_dropout
|
| 307 |
+
self.layer_norm_eps = layer_norm_eps
|
| 308 |
+
self.hidden_act = hidden_act
|
| 309 |
+
self.num_patches = num_patches
|
| 310 |
+
self.window_size = window_size
|
| 311 |
+
self.full_attention_indexes = full_attention_indexes
|
| 312 |
+
self.use_windows_attn = use_windows_attn
|
| 313 |
+
self.use_rope = use_rope
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
@dataclass
|
| 317 |
+
class Siglip2VisionOutput(ModelOutput):
|
| 318 |
+
"""
|
| 319 |
+
Base class for vision model's outputs that also contains image embeddings of the pooling of the last hidden states.
|
| 320 |
+
|
| 321 |
+
Args:
|
| 322 |
+
image_embeds (`torch.FloatTensor` of shape `(batch_size, output_dim)` *optional* returned when model is initialized with `with_projection=True`):
|
| 323 |
+
The image embeddings obtained by applying the projection layer to the pooler_output.
|
| 324 |
+
last_hidden_state (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
|
| 325 |
+
Sequence of hidden-states at the output of the last layer of the model.
|
| 326 |
+
hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
|
| 327 |
+
Tuple of `torch.FloatTensor` (one for the output of the embeddings, if the model has an embedding layer, +
|
| 328 |
+
one for the output of each layer) of shape `(batch_size, sequence_length, hidden_size)`.
|
| 329 |
+
|
| 330 |
+
Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.
|
| 331 |
+
attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
|
| 332 |
+
Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
|
| 333 |
+
sequence_length)`.
|
| 334 |
+
|
| 335 |
+
Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
|
| 336 |
+
heads.
|
| 337 |
+
"""
|
| 338 |
+
|
| 339 |
+
image_embeds: Optional[torch.FloatTensor] = None
|
| 340 |
+
last_hidden_state: Optional[torch.FloatTensor] = None
|
| 341 |
+
hidden_states: Optional[Tuple[torch.FloatTensor, ...]] = None
|
| 342 |
+
attentions: Optional[Tuple[torch.FloatTensor, ...]] = None
|
| 343 |
+
spatial_shapes: Optional[torch.LongTensor] = None
|
| 344 |
+
|
| 345 |
+
|
| 346 |
+
def convert_image_to_patches(image: "torch.Tensor", patch_size: int) -> "torch.Tensor":
|
| 347 |
+
"""
|
| 348 |
+
Convert 3D tensor image of shape (num_channels, image_height, image_width) into 2D tensor of patches of shape
|
| 349 |
+
(num_patches_height * num_patches_width, patch_size * patch_size * num_channels).
|
| 350 |
+
"""
|
| 351 |
+
num_channels, image_height, image_width = image.shape
|
| 352 |
+
num_patches_height = image_height // patch_size
|
| 353 |
+
num_patches_width = image_width // patch_size
|
| 354 |
+
patched_image = image.reshape(num_channels, num_patches_height, patch_size, num_patches_width, patch_size)
|
| 355 |
+
patched_image = patched_image.permute(1, 3, 2, 4, 0)
|
| 356 |
+
patched_image = patched_image.reshape(num_patches_height * num_patches_width, -1)
|
| 357 |
+
return patched_image
|
| 358 |
+
|
| 359 |
+
def convert_images_to_patches(image: "torch.Tensor", patch_size: int) -> "torch.Tensor":
|
| 360 |
+
"""
|
| 361 |
+
Convert 4D tensor image of shape (batch_size, num_channels, image_height, image_width) into 2D tensor of patches of shape
|
| 362 |
+
(batch_size, num_patches_height * num_patches_width, patch_size * patch_size * num_channels).
|
| 363 |
+
"""
|
| 364 |
+
batch_size, num_channels, image_height, image_width = image.shape
|
| 365 |
+
assert image_height % patch_size == 0 and image_width % patch_size == 0, f"image_height % patch_size == 0 and image_width % patch_size == 0"
|
| 366 |
+
num_patches_height = image_height // patch_size
|
| 367 |
+
num_patches_width = image_width // patch_size
|
| 368 |
+
patched_image = image.reshape(batch_size, num_channels, num_patches_height, patch_size, num_patches_width, patch_size)
|
| 369 |
+
patched_image = patched_image.permute(0, 2, 4, 3, 5, 1) # (batch_size, num_patches_height, num_patches_width, patch_size, patch_size, num_channels)
|
| 370 |
+
|
| 371 |
+
patched_image = patched_image.reshape(batch_size * num_patches_height * num_patches_width, -1)
|
| 372 |
+
return patched_image
|
| 373 |
+
|
| 374 |
+
|
| 375 |
+
class Siglip2VisionEmbeddings(nn.Module):
|
| 376 |
+
def __init__(self, config: Siglip2VisionConfig):
|
| 377 |
+
super().__init__()
|
| 378 |
+
self.config = config
|
| 379 |
+
self.embed_dim = config.hidden_size
|
| 380 |
+
self.patch_size = config.patch_size
|
| 381 |
+
self.window_size = config.window_size
|
| 382 |
+
|
| 383 |
+
self.patch_embedding = nn.Linear(
|
| 384 |
+
in_features=config.num_channels * self.patch_size * self.patch_size,
|
| 385 |
+
out_features=self.embed_dim,
|
| 386 |
+
)
|
| 387 |
+
|
| 388 |
+
self.num_patches = config.num_patches
|
| 389 |
+
self.position_embedding_size = int(self.num_patches**0.5)
|
| 390 |
+
self.position_embedding = nn.Embedding(self.num_patches, self.embed_dim)
|
| 391 |
+
|
| 392 |
+
|
| 393 |
+
def split_patch_embeddings_to_windows_with_meta(self, patch_embeds, batch_hw, window_size):
|
| 394 |
+
"""
|
| 395 |
+
Args:
|
| 396 |
+
patch_embeds: Tensor, shape (1, sum(H_i*W_i), C)
|
| 397 |
+
batch_hw: List[(H_i, W_i)]
|
| 398 |
+
window_size: int
|
| 399 |
+
|
| 400 |
+
Returns:
|
| 401 |
+
windows_tensor: Tensor, shape (total_windows, window_size*window_size, C)
|
| 402 |
+
win_meta_list: List[dict] with keys:
|
| 403 |
+
- img_idx: index in batch_hw
|
| 404 |
+
- patch_hw: original (H, W)
|
| 405 |
+
- win_xy: (h0, w0) 左上角相对于原图
|
| 406 |
+
- win_hw: 原图内有效窗口大小 (h_eff, w_eff)
|
| 407 |
+
"""
|
| 408 |
+
|
| 409 |
+
# 1. 计算每张图在 flat tensor 中的起始位置
|
| 410 |
+
batch_hw = batch_hw.tolist()
|
| 411 |
+
counts = [H * W for (H, W) in batch_hw]
|
| 412 |
+
starts = [0] + list(accumulate(counts))[:-1]
|
| 413 |
+
|
| 414 |
+
# 2. 按 (H,W) 分组,同一尺寸一起处理
|
| 415 |
+
size2info = defaultdict(list)
|
| 416 |
+
for img_idx, ((H, W), start) in enumerate(zip(batch_hw, starts)):
|
| 417 |
+
size2info[(H, W)].append((img_idx, start))
|
| 418 |
+
|
| 419 |
+
all_windows = []
|
| 420 |
+
all_meta = []
|
| 421 |
+
# print(size2info)
|
| 422 |
+
# 3. 对每个尺寸组做 batch unfold + pad
|
| 423 |
+
for (H, W), info in size2info.items():
|
| 424 |
+
H, W = int(H), int(W)
|
| 425 |
+
B = len(info)
|
| 426 |
+
C = patch_embeds.shape[-1]
|
| 427 |
+
img_idxs, img_starts = zip(*info)
|
| 428 |
+
|
| 429 |
+
# 3.1 取出并 reshape 成 (B, C, H, W)
|
| 430 |
+
imgs = []
|
| 431 |
+
for st in img_starts:
|
| 432 |
+
flat = patch_embeds[0, st: st + H * W] # (H*W, C)
|
| 433 |
+
imgs.append(flat.transpose(0,1).reshape(C, H, W))
|
| 434 |
+
batch_tensor = torch.stack(imgs, dim=0) # (B, C, H, W)
|
| 435 |
+
# 3.2 计算 pad 大小 (bottom, right),保证能被 window_size 整除
|
| 436 |
+
pad_h = (window_size - H % window_size) % window_size
|
| 437 |
+
pad_w = (window_size - W % window_size) % window_size
|
| 438 |
+
|
| 439 |
+
# pad 格式: (left, right, top, bottom) for last two dims
|
| 440 |
+
batch_padded = F.pad(batch_tensor, (0, pad_w, 0, pad_h))
|
| 441 |
+
|
| 442 |
+
H_pad, W_pad = H + pad_h, W + pad_w
|
| 443 |
+
n_h = H_pad // window_size
|
| 444 |
+
n_w = W_pad // window_size
|
| 445 |
+
n_windows = n_h * n_w
|
| 446 |
+
|
| 447 |
+
# 3.3 batched unfold -> (B, C*ws*ws, n_windows)
|
| 448 |
+
patches_unf = F.unfold(
|
| 449 |
+
batch_padded,
|
| 450 |
+
kernel_size=(window_size, window_size),
|
| 451 |
+
stride=(window_size, window_size)
|
| 452 |
+
)
|
| 453 |
+
|
| 454 |
+
# 3.4 reshape到 (B*n_windows, ws*ws, C)
|
| 455 |
+
patches = (
|
| 456 |
+
patches_unf
|
| 457 |
+
.view(B, C, window_size * window_size, n_windows) # (B, C, ws*ws, n_win)
|
| 458 |
+
.permute(0, 3, 2, 1) # (B, n_win, ws*ws, C)
|
| 459 |
+
.reshape(-1, window_size * window_size, C) # (B*n_win, ws*ws, C)
|
| 460 |
+
)
|
| 461 |
+
all_windows.append(patches)
|
| 462 |
+
|
| 463 |
+
# 3.5 生成 meta:记录原图内有效窗口大小
|
| 464 |
+
for b, img_idx in enumerate(img_idxs):
|
| 465 |
+
for win_id in range(n_windows):
|
| 466 |
+
i, j = divmod(win_id, n_w)
|
| 467 |
+
h0, w0 = i * window_size, j * window_size
|
| 468 |
+
# 在原图内的实际结束坐标
|
| 469 |
+
h1 = min(h0 + window_size, H)
|
| 470 |
+
w1 = min(w0 + window_size, W)
|
| 471 |
+
all_meta.append({
|
| 472 |
+
'img_idx': img_idx,
|
| 473 |
+
'patch_hw': (H, W),
|
| 474 |
+
'win_xy': (h0, w0),
|
| 475 |
+
'win_hw': (h1 - h0, w1 - w0), # 有效区域大小
|
| 476 |
+
})
|
| 477 |
+
|
| 478 |
+
# 4. 拼接并根据 img_idx + win_xy 排序,恢复输入顺序
|
| 479 |
+
sorted_idx = sorted(
|
| 480 |
+
range(len(all_meta)),
|
| 481 |
+
key=lambda k: (
|
| 482 |
+
all_meta[k]['img_idx'],
|
| 483 |
+
all_meta[k]['win_xy'][0],
|
| 484 |
+
all_meta[k]['win_xy'][1]
|
| 485 |
+
)
|
| 486 |
+
)
|
| 487 |
+
all_windows = torch.cat(all_windows, dim=0)
|
| 488 |
+
all_windows = all_windows[sorted_idx]
|
| 489 |
+
win_meta_list = [all_meta[i] for i in sorted_idx]
|
| 490 |
+
|
| 491 |
+
windows_list = []
|
| 492 |
+
for meta, win in zip(win_meta_list, all_windows):
|
| 493 |
+
h_eff, w_eff = meta['win_hw']
|
| 494 |
+
valid_num = h_eff * w_eff
|
| 495 |
+
# 只保留真正来自原图的 patch tokens
|
| 496 |
+
if valid_num == window_size * window_size:
|
| 497 |
+
windows_list.append(win)
|
| 498 |
+
else:
|
| 499 |
+
win = win.view(window_size, window_size, -1)[:h_eff, :w_eff, :].reshape(h_eff * w_eff, -1)
|
| 500 |
+
windows_list.append(win) # shape (valid_num, C)
|
| 501 |
+
|
| 502 |
+
# 如果你需要一个单一 tensor,可以再 cat 一次:
|
| 503 |
+
all_tokens = torch.cat(windows_list, dim=0).unsqueeze(0) # shape (sum(valid_num), C)
|
| 504 |
+
|
| 505 |
+
|
| 506 |
+
# 1. 先重算每张图在原始 flat tensor 中的起始位置
|
| 507 |
+
counts = [H * W for H, W in batch_hw]
|
| 508 |
+
starts = [0] + list(accumulate(counts))[:-1]
|
| 509 |
+
total_patches = sum(counts)
|
| 510 |
+
|
| 511 |
+
# 2. 构造映射:mapping[orig_idx] = new_idx
|
| 512 |
+
mapping = [None] * total_patches
|
| 513 |
+
offset = 0 # all_tokens 维度上的游标
|
| 514 |
+
|
| 515 |
+
for meta in win_meta_list:
|
| 516 |
+
img_idx = meta['img_idx']
|
| 517 |
+
H, W = meta['patch_hw']
|
| 518 |
+
h0, w0 = meta['win_xy']
|
| 519 |
+
h_eff, w_eff = meta['win_hw']
|
| 520 |
+
base = starts[img_idx]
|
| 521 |
+
|
| 522 |
+
# 对该窗口内所有真正来自原图的 patch token 计算映射
|
| 523 |
+
for u in range(h_eff):
|
| 524 |
+
for v in range(w_eff):
|
| 525 |
+
# 原始 flat 坐标
|
| 526 |
+
orig_idx = base + (h0+u) * W + (w0) + v
|
| 527 |
+
# 在 all_tokens 里的位置:在该窗口区段里按 row-major 展平
|
| 528 |
+
p = u * w_eff + v
|
| 529 |
+
mapping[orig_idx] = offset + p
|
| 530 |
+
|
| 531 |
+
# 窗口结束后,offset 推进该窗口的有效 token 数
|
| 532 |
+
offset += h_eff * w_eff
|
| 533 |
+
reverse_mapping = torch.tensor(mapping, dtype=torch.long)
|
| 534 |
+
|
| 535 |
+
return all_tokens, win_meta_list, reverse_mapping
|
| 536 |
+
|
| 537 |
+
@staticmethod
|
| 538 |
+
def resize_positional_embeddings(
|
| 539 |
+
positional_embeddings: torch.Tensor,
|
| 540 |
+
spatial_shapes: torch.LongTensor,
|
| 541 |
+
) -> torch.Tensor:
|
| 542 |
+
"""
|
| 543 |
+
Resize positional embeddings to image-specific size and pad to a fixed size.
|
| 544 |
+
|
| 545 |
+
Args:
|
| 546 |
+
positional_embeddings (`torch.Tensor`):
|
| 547 |
+
Position embeddings of shape (height, width, embed_dim)
|
| 548 |
+
spatial_shapes (`torch.LongTensor`):
|
| 549 |
+
Spatial shapes of shape (batch_size, 2) to resize the positional embeddings to
|
| 550 |
+
max_length (`int`):
|
| 551 |
+
Maximum length of the positional embeddings to pad resized positional embeddings to
|
| 552 |
+
|
| 553 |
+
Returns:
|
| 554 |
+
`torch.Tensor`: Embeddings of shape (batch_size, max_length, embed_dim)
|
| 555 |
+
"""
|
| 556 |
+
batch_size = spatial_shapes.shape[0]
|
| 557 |
+
embed_dim = positional_embeddings.shape[-1]
|
| 558 |
+
source_dtype = positional_embeddings.dtype
|
| 559 |
+
|
| 560 |
+
resulted_positional_embeddings = []
|
| 561 |
+
|
| 562 |
+
# (height, width, embed_dim) -> (1, embed_dim, height, width) for interpolation
|
| 563 |
+
positional_embeddings = positional_embeddings.permute(2, 0, 1).unsqueeze(0)
|
| 564 |
+
|
| 565 |
+
# Upcast to float32 on CPU because antialias is not supported for bfloat16/float16 on CPU
|
| 566 |
+
if positional_embeddings.device.type == "cpu":
|
| 567 |
+
positional_embeddings = positional_embeddings.to(torch.float32)
|
| 568 |
+
|
| 569 |
+
for i in range(batch_size):
|
| 570 |
+
# (1, dim, height, width) -> (1, dim, target_height, target_width)
|
| 571 |
+
height, width = spatial_shapes[i]
|
| 572 |
+
resized_embeddings = F.interpolate(
|
| 573 |
+
positional_embeddings,
|
| 574 |
+
size=(height, width),
|
| 575 |
+
mode="bilinear",
|
| 576 |
+
align_corners=False,
|
| 577 |
+
antialias=True,
|
| 578 |
+
)
|
| 579 |
+
|
| 580 |
+
# (1, dim, target_height, target_width) -> (target_height * target_width, dim)
|
| 581 |
+
resized_embeddings = resized_embeddings.reshape(embed_dim, height * width).transpose(0, 1)
|
| 582 |
+
|
| 583 |
+
# Cast to original dtype
|
| 584 |
+
resized_embeddings = resized_embeddings.to(source_dtype)
|
| 585 |
+
|
| 586 |
+
resulted_positional_embeddings.append(resized_embeddings)
|
| 587 |
+
|
| 588 |
+
return torch.cat(resulted_positional_embeddings, dim=0).unsqueeze(0)
|
| 589 |
+
|
| 590 |
+
def get_spatial_shapes(self, bchw_list: List[torch.Tensor]) -> torch.Tensor:
|
| 591 |
+
hw_list = []
|
| 592 |
+
for shape in bchw_list:
|
| 593 |
+
b, _, h, w = shape
|
| 594 |
+
hw_list.extend([(h//self.patch_size, w//self.patch_size)] * b)
|
| 595 |
+
hw_tensor = torch.tensor(hw_list)
|
| 596 |
+
return hw_tensor
|
| 597 |
+
|
| 598 |
+
def forward(self, pixel_values: torch.FloatTensor) -> torch.Tensor:
|
| 599 |
+
"""
|
| 600 |
+
Args:
|
| 601 |
+
pixel_values (`torch.FloatTensor`):
|
| 602 |
+
Pixel values of shape (batch_size, num_channels, height, width)
|
| 603 |
+
"""
|
| 604 |
+
|
| 605 |
+
bchw_list = [each.shape for each in pixel_values]
|
| 606 |
+
|
| 607 |
+
pixel_values = torch.cat([convert_images_to_patches(each, self.patch_size) for each in pixel_values], dim=0)
|
| 608 |
+
|
| 609 |
+
# Apply patch embeddings to already patchified pixel values
|
| 610 |
+
target_dtype = self.patch_embedding.weight.dtype
|
| 611 |
+
patch_embeds = self.patch_embedding(pixel_values.to(dtype=target_dtype))
|
| 612 |
+
|
| 613 |
+
# Get positional resized and padded positional embeddings
|
| 614 |
+
positional_embeddings = self.position_embedding.weight.reshape(
|
| 615 |
+
self.position_embedding_size, self.position_embedding_size, -1
|
| 616 |
+
)
|
| 617 |
+
spatial_shapes = self.get_spatial_shapes(bchw_list)
|
| 618 |
+
|
| 619 |
+
resized_positional_embeddings = self.resize_positional_embeddings(
|
| 620 |
+
positional_embeddings, spatial_shapes
|
| 621 |
+
)
|
| 622 |
+
# Add positional embeddings to patch embeddings
|
| 623 |
+
embeddings = patch_embeds + resized_positional_embeddings
|
| 624 |
+
|
| 625 |
+
windows_tensor, win_meta_list, reverse_mapping = self.split_patch_embeddings_to_windows_with_meta(embeddings, spatial_shapes, self.window_size)
|
| 626 |
+
|
| 627 |
+
return windows_tensor, win_meta_list, spatial_shapes, reverse_mapping
|
| 628 |
+
|
| 629 |
+
|
| 630 |
+
class Rope2DPosEmb(nn.Module):
|
| 631 |
+
|
| 632 |
+
"""
|
| 633 |
+
copy from https://huggingface.co/moonshotai/Kimi-VL-A3B-Thinking/blob/main/modeling_kimi_vl.py#L324
|
| 634 |
+
2D rotary position embedding with multi-resolution support.
|
| 635 |
+
This class is intended to be used in the following way:
|
| 636 |
+
1. Before training, create an instance of Rope2DPosEmb. This instance will hold the precomputed cis.
|
| 637 |
+
2. Before each forward pass, call `get_freqs_cis_by_*` to get the `freqs_cis` tensor for this iteration.
|
| 638 |
+
3. During the forward pass, pass the `freqs_cis` tensor to each attention layer, and call `apply` just before each attention operation.
|
| 639 |
+
The rope is shared across all attention layers and all heads.
|
| 640 |
+
Refs:
|
| 641 |
+
- RoFormer: https://arxiv.org/abs/2104.09864
|
| 642 |
+
- VisionLLaMA: https://arxiv.org/abs/2403.00522
|
| 643 |
+
- https://github.com/Meituan-AutoML/VisionLLaMA/blob/main/dit/models.py
|
| 644 |
+
Args:
|
| 645 |
+
dim (int): usually the multi-head attention dimension, should be divisible by 4 (TODO: relax this constraint if needed)
|
| 646 |
+
max_height (int): the maximum height of the 2D grid
|
| 647 |
+
max_width (int): the maximum width of the 2D grid
|
| 648 |
+
theta_base (float): the base of the theta
|
| 649 |
+
device (str): the device to store the precomputed cis
|
| 650 |
+
"""
|
| 651 |
+
|
| 652 |
+
def __init__(self, dim: int, max_height: int, max_width: int, theta_base=10000, window_size=14):
|
| 653 |
+
super().__init__()
|
| 654 |
+
self.dim = dim
|
| 655 |
+
assert self.dim % 4 == 0, "dim must be divisible by 4"
|
| 656 |
+
self.max_height = max_height
|
| 657 |
+
self.max_width = max_width
|
| 658 |
+
self.theta_base = theta_base
|
| 659 |
+
self.window_size = window_size
|
| 660 |
+
|
| 661 |
+
self.freqs_cis = None
|
| 662 |
+
|
| 663 |
+
def extra_repr(self):
|
| 664 |
+
return f"dim={self.dim}, max_height={self.max_height}, max_width={self.max_width}, theta_base={self.theta_base}"
|
| 665 |
+
|
| 666 |
+
def _precompute_freqs_cis(self, device: torch.device) -> torch.Tensor:
|
| 667 |
+
"""Calculate the cis(freqs) for each position in the 2D grid.
|
| 668 |
+
Return: complex tensor of shape (max_height, max_width, dim//2) and value:
|
| 669 |
+
height axis: ret[h, w, 2*i] = cis(h * theta_base**(-4*i/dim))
|
| 670 |
+
weight axis: ret[h, w, 2*i+1] = cis(w * theta_base**(-4*i/dim)) with (i in [0, dim//4))
|
| 671 |
+
note: `cis` is a mathematical notation defined by cis x = cos x + i sin x,
|
| 672 |
+
"""
|
| 673 |
+
N = self.max_height * self.max_width
|
| 674 |
+
flat_pos = torch.arange(0, N).float().to(device)
|
| 675 |
+
x_pos = flat_pos % self.max_width
|
| 676 |
+
y_pos = flat_pos // self.max_width
|
| 677 |
+
dim_range = (
|
| 678 |
+
torch.arange(0, self.dim, 4)[: (self.dim // 4)].float().to(device)
|
| 679 |
+
) # C/4
|
| 680 |
+
freqs = 1.0 / (self.theta_base ** (dim_range / self.dim))
|
| 681 |
+
x_freqs = torch.outer(x_pos, freqs).float() # N, C/4
|
| 682 |
+
y_freqs = torch.outer(y_pos, freqs).float() # N, C/4
|
| 683 |
+
x_cis = torch.polar(torch.ones_like(x_freqs), x_freqs) # N, C/4
|
| 684 |
+
y_cis = torch.polar(torch.ones_like(y_freqs), y_freqs) # N, C/4
|
| 685 |
+
# N, C/4, 2
|
| 686 |
+
freqs_cis = torch.cat(
|
| 687 |
+
[x_cis.unsqueeze(dim=-1), y_cis.unsqueeze(dim=-1)], dim=-1
|
| 688 |
+
)
|
| 689 |
+
# max_height, max_width, C/2
|
| 690 |
+
freqs_cis = freqs_cis.reshape(self.max_height, self.max_width, -1)
|
| 691 |
+
return freqs_cis
|
| 692 |
+
|
| 693 |
+
def get_freqs_cis(self, win_meta_list: List[Dict], device: torch.device) -> torch.Tensor:
|
| 694 |
+
"""
|
| 695 |
+
Args:
|
| 696 |
+
win_meta_list (List[Dict]): window meta list
|
| 697 |
+
Returns:
|
| 698 |
+
freqs_cis: tensor of shape (sum(t * height * width), dim//2)
|
| 699 |
+
"""
|
| 700 |
+
if self.freqs_cis is None:
|
| 701 |
+
self.freqs_cis = self._precompute_freqs_cis(device)
|
| 702 |
+
|
| 703 |
+
# assert all xy <512
|
| 704 |
+
assert all(win_meta['win_xy'][0] + win_meta['win_hw'][0] < 512 and win_meta['win_xy'][1] + win_meta['win_hw'][1] < 512 for win_meta in win_meta_list)
|
| 705 |
+
freqs_cis = torch.cat([self.freqs_cis[win_meta['win_xy'][0]:win_meta['win_xy'][0] + win_meta['win_hw'][0], win_meta['win_xy'][1]: win_meta['win_xy'][1] + win_meta['win_hw'][1]].reshape(-1, self.dim // 2) for win_meta in win_meta_list], dim=0)
|
| 706 |
+
freqs_cis = freqs_cis.unsqueeze(0)
|
| 707 |
+
return freqs_cis
|
| 708 |
+
|
| 709 |
+
|
| 710 |
+
def eager_attention_forward(
|
| 711 |
+
module: nn.Module,
|
| 712 |
+
query: torch.Tensor,
|
| 713 |
+
key: torch.Tensor,
|
| 714 |
+
value: torch.Tensor,
|
| 715 |
+
attention_mask: Optional[torch.Tensor],
|
| 716 |
+
scaling: float,
|
| 717 |
+
dropout: float = 0.0,
|
| 718 |
+
**kwargs,
|
| 719 |
+
):
|
| 720 |
+
attn_weights = torch.matmul(query, key.transpose(-1, -2)) * scaling
|
| 721 |
+
if attention_mask is not None:
|
| 722 |
+
attn_weights = attn_weights + attention_mask
|
| 723 |
+
|
| 724 |
+
attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query.dtype)
|
| 725 |
+
attn_weights = nn.functional.dropout(attn_weights, p=dropout, training=module.training)
|
| 726 |
+
|
| 727 |
+
attn_output = torch.matmul(attn_weights, value)
|
| 728 |
+
attn_output = attn_output.transpose(1, 2).contiguous()
|
| 729 |
+
|
| 730 |
+
return attn_output, attn_weights
|
| 731 |
+
|
| 732 |
+
|
| 733 |
+
|
| 734 |
+
def _apply_rope_input_validation(x, freqs_cis):
|
| 735 |
+
assert x.ndim == freqs_cis.ndim + 1, (x.shape, freqs_cis.shape)
|
| 736 |
+
assert x.shape[:-2] == freqs_cis.shape[:-1], (x.shape, freqs_cis.shape)
|
| 737 |
+
assert x.shape[-1] == 2 * freqs_cis.shape[-1], (x.shape, freqs_cis.shape)
|
| 738 |
+
assert freqs_cis.dtype == torch.complex64, freqs_cis.dtype
|
| 739 |
+
|
| 740 |
+
|
| 741 |
+
def apply_rope(
|
| 742 |
+
xq: torch.Tensor, xk: torch.Tensor, freqs_cis: torch.Tensor
|
| 743 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 744 |
+
"""
|
| 745 |
+
Args: (The leading dimensions of all inputs should be the same)
|
| 746 |
+
xq: query, tensor of shape (..., num_heads, head_dim)
|
| 747 |
+
xk: key, tensor of shape (..., num_heads, head_dim)
|
| 748 |
+
freqs_cis: tensor of shape (..., head_dim/2), dtype=torch.complex64. It contains the precomputed cis(freqs) for each position in the 2D grid.
|
| 749 |
+
Returns:
|
| 750 |
+
xq_out, xk_out: tensors of shape (..., num_heads, head_dim)
|
| 751 |
+
"""
|
| 752 |
+
_apply_rope_input_validation(xq, freqs_cis)
|
| 753 |
+
_apply_rope_input_validation(xk, freqs_cis)
|
| 754 |
+
|
| 755 |
+
freqs_cis = freqs_cis.unsqueeze(-2) # ..., 1, head_dim/2
|
| 756 |
+
# ..., num_heads, head_dim/2
|
| 757 |
+
xq_ = torch.view_as_complex(xq.float().view(*xq.shape[:-1], -1, 2))
|
| 758 |
+
xk_ = torch.view_as_complex(xk.float().view(*xq.shape[:-1], -1, 2))
|
| 759 |
+
xq_out = torch.view_as_real(xq_ * freqs_cis).flatten(-2) # ..., num_heads, head_dim
|
| 760 |
+
xk_out = torch.view_as_real(xk_ * freqs_cis).flatten(-2) # ..., num_heads, head_dim
|
| 761 |
+
return xq_out.type_as(xq), xk_out.type_as(xk)
|
| 762 |
+
|
| 763 |
+
|
| 764 |
+
class Siglip2Attention(nn.Module):
|
| 765 |
+
"""Multi-headed attention from 'Attention Is All You Need' paper"""
|
| 766 |
+
|
| 767 |
+
def __init__(self, config: Union[Siglip2VisionConfig, Siglip2TextConfig]):
|
| 768 |
+
super().__init__()
|
| 769 |
+
self.config = config
|
| 770 |
+
self.embed_dim = config.hidden_size
|
| 771 |
+
self.num_heads = config.num_attention_heads
|
| 772 |
+
self.head_dim = self.embed_dim // self.num_heads
|
| 773 |
+
if self.head_dim * self.num_heads != self.embed_dim:
|
| 774 |
+
raise ValueError(
|
| 775 |
+
f"embed_dim must be divisible by num_heads (got `embed_dim`: {self.embed_dim} and `num_heads`:"
|
| 776 |
+
f" {self.num_heads})."
|
| 777 |
+
)
|
| 778 |
+
self.scale = self.head_dim**-0.5
|
| 779 |
+
self.dropout = config.attention_dropout
|
| 780 |
+
self.is_causal = False
|
| 781 |
+
|
| 782 |
+
self.k_proj = nn.Linear(self.embed_dim, self.embed_dim)
|
| 783 |
+
self.v_proj = nn.Linear(self.embed_dim, self.embed_dim)
|
| 784 |
+
self.q_proj = nn.Linear(self.embed_dim, self.embed_dim)
|
| 785 |
+
self.out_proj = nn.Linear(self.embed_dim, self.embed_dim)
|
| 786 |
+
|
| 787 |
+
self.use_windows_attn = config.use_windows_attn
|
| 788 |
+
self.use_rope = config.use_rope
|
| 789 |
+
|
| 790 |
+
def forward(
|
| 791 |
+
self,
|
| 792 |
+
hidden_states: torch.Tensor,
|
| 793 |
+
output_attentions: Optional[bool] = False,
|
| 794 |
+
rope_freqs_cis: Optional[torch.Tensor] = None,
|
| 795 |
+
win_meta_list: Optional[List[Dict]] = None,
|
| 796 |
+
windows_attn: Optional[bool] = False,
|
| 797 |
+
) -> Tuple[torch.Tensor, Optional[torch.Tensor]]:
|
| 798 |
+
"""Input shape: Batch x Time x Channel"""
|
| 799 |
+
|
| 800 |
+
|
| 801 |
+
batch_size, seq_length, embed_dim = hidden_states.shape
|
| 802 |
+
|
| 803 |
+
queries = self.q_proj(hidden_states)
|
| 804 |
+
keys = self.k_proj(hidden_states)
|
| 805 |
+
values = self.v_proj(hidden_states)
|
| 806 |
+
|
| 807 |
+
|
| 808 |
+
queries = queries.view(batch_size, seq_length, self.num_heads, self.head_dim) # .transpose(1, 2)
|
| 809 |
+
keys = keys.view(batch_size, seq_length, self.num_heads, self.head_dim) # .transpose(1, 2)
|
| 810 |
+
values = values.view(batch_size, seq_length, self.num_heads, self.head_dim).transpose(1, 2)
|
| 811 |
+
|
| 812 |
+
if self.use_rope:
|
| 813 |
+
queries, keys = apply_rope(queries, keys, rope_freqs_cis)
|
| 814 |
+
|
| 815 |
+
queries = queries.transpose(1, 2)
|
| 816 |
+
keys = keys.transpose(1, 2)
|
| 817 |
+
|
| 818 |
+
attention_interface: Callable = eager_attention_forward
|
| 819 |
+
if self.config._attn_implementation != "eager":
|
| 820 |
+
if self.config._attn_implementation == "sdpa" and output_attentions:
|
| 821 |
+
logger.warning_once(
|
| 822 |
+
"`torch.nn.functional.scaled_dot_product_attention` does not support `output_attentions=True`. Falling back to "
|
| 823 |
+
'eager attention. This warning can be removed using the argument `attn_implementation="eager"` when loading the model.'
|
| 824 |
+
)
|
| 825 |
+
if self.config._attn_implementation == "flash_attention_2":
|
| 826 |
+
from transformers.modeling_utils import AttentionInterface
|
| 827 |
+
AttentionInterface._global_mapping['flash_attention_2_packing'] = flash_attention_forward_for_packing
|
| 828 |
+
setattr(AttentionInterface, 'flash_attention_2_packing', flash_attention_forward_for_packing)
|
| 829 |
+
attention_interface = ALL_ATTENTION_FUNCTIONS['flash_attention_2_packing']
|
| 830 |
+
else:
|
| 831 |
+
attention_interface = ALL_ATTENTION_FUNCTIONS[self.config._attn_implementation]
|
| 832 |
+
|
| 833 |
+
if windows_attn and self.use_windows_attn:
|
| 834 |
+
seq_len_list = [win_meta['win_hw'][0] * win_meta['win_hw'][1] for win_meta in win_meta_list]
|
| 835 |
+
else:
|
| 836 |
+
mapper = defaultdict(lambda: 0)
|
| 837 |
+
for win_meta in win_meta_list:
|
| 838 |
+
mapper[win_meta['img_idx']] += win_meta['win_hw'][0] * win_meta['win_hw'][1]
|
| 839 |
+
seq_len_list = [mapper[i] for i in range(len(mapper))]
|
| 840 |
+
|
| 841 |
+
attention_mask = None
|
| 842 |
+
attn_output, attn_weights = attention_interface(
|
| 843 |
+
self,
|
| 844 |
+
queries,
|
| 845 |
+
keys,
|
| 846 |
+
values,
|
| 847 |
+
attention_mask,
|
| 848 |
+
is_causal=self.is_causal,
|
| 849 |
+
scaling=self.scale,
|
| 850 |
+
dropout=0.0 if not self.training else self.dropout,
|
| 851 |
+
seq_len_list=seq_len_list,
|
| 852 |
+
)
|
| 853 |
+
attn_output = attn_output.reshape(batch_size, seq_length, embed_dim).contiguous()
|
| 854 |
+
attn_output = self.out_proj(attn_output)
|
| 855 |
+
|
| 856 |
+
if not output_attentions:
|
| 857 |
+
attn_weights = None
|
| 858 |
+
|
| 859 |
+
return attn_output, attn_weights
|
| 860 |
+
|
| 861 |
+
|
| 862 |
+
class Siglip2MLP(nn.Module):
|
| 863 |
+
def __init__(self, config):
|
| 864 |
+
super().__init__()
|
| 865 |
+
self.config = config
|
| 866 |
+
self.activation_fn = ACT2FN[config.hidden_act]
|
| 867 |
+
self.fc1 = nn.Linear(config.hidden_size, config.intermediate_size)
|
| 868 |
+
self.fc2 = nn.Linear(config.intermediate_size, config.hidden_size)
|
| 869 |
+
|
| 870 |
+
def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
|
| 871 |
+
hidden_states = self.fc1(hidden_states)
|
| 872 |
+
hidden_states = self.activation_fn(hidden_states)
|
| 873 |
+
hidden_states = self.fc2(hidden_states)
|
| 874 |
+
return hidden_states
|
| 875 |
+
|
| 876 |
+
|
| 877 |
+
class Siglip2EncoderLayer(nn.Module):
|
| 878 |
+
def __init__(self, config: Union[Siglip2VisionConfig, Siglip2TextConfig]):
|
| 879 |
+
super().__init__()
|
| 880 |
+
self.embed_dim = config.hidden_size
|
| 881 |
+
self.layer_norm1 = nn.LayerNorm(self.embed_dim, eps=config.layer_norm_eps)
|
| 882 |
+
self.self_attn = Siglip2Attention(config)
|
| 883 |
+
self.layer_norm2 = nn.LayerNorm(self.embed_dim, eps=config.layer_norm_eps)
|
| 884 |
+
self.mlp = Siglip2MLP(config)
|
| 885 |
+
|
| 886 |
+
def forward(
|
| 887 |
+
self,
|
| 888 |
+
hidden_states: torch.Tensor,
|
| 889 |
+
output_attentions: Optional[bool] = False,
|
| 890 |
+
rope_freqs_cis: Optional[torch.Tensor] = None,
|
| 891 |
+
win_meta_list: Optional[List[Dict]] = None,
|
| 892 |
+
windows_attn: Optional[bool] = False,
|
| 893 |
+
) -> Tuple[torch.FloatTensor]:
|
| 894 |
+
"""
|
| 895 |
+
Args:
|
| 896 |
+
hidden_states (`torch.FloatTensor`):
|
| 897 |
+
Input to the layer of shape `(batch, seq_len, embed_dim)`.
|
| 898 |
+
attention_mask (`torch.FloatTensor`):
|
| 899 |
+
Attention mask of shape `(batch, 1, q_len, k_v_seq_len)` where padding elements are indicated by very large negative values.
|
| 900 |
+
output_attentions (`bool`, *optional*, defaults to `False`):
|
| 901 |
+
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
|
| 902 |
+
returned tensors for more detail.
|
| 903 |
+
"""
|
| 904 |
+
residual = hidden_states
|
| 905 |
+
|
| 906 |
+
hidden_states = self.layer_norm1(hidden_states)
|
| 907 |
+
hidden_states, attn_weights = self.self_attn(
|
| 908 |
+
hidden_states=hidden_states,
|
| 909 |
+
output_attentions=output_attentions,
|
| 910 |
+
rope_freqs_cis=rope_freqs_cis,
|
| 911 |
+
win_meta_list=win_meta_list,
|
| 912 |
+
windows_attn=windows_attn,
|
| 913 |
+
)
|
| 914 |
+
hidden_states = residual + hidden_states
|
| 915 |
+
|
| 916 |
+
residual = hidden_states
|
| 917 |
+
hidden_states = self.layer_norm2(hidden_states)
|
| 918 |
+
hidden_states = self.mlp(hidden_states)
|
| 919 |
+
hidden_states = residual + hidden_states
|
| 920 |
+
|
| 921 |
+
outputs = (hidden_states,)
|
| 922 |
+
|
| 923 |
+
if output_attentions:
|
| 924 |
+
outputs += (attn_weights,)
|
| 925 |
+
|
| 926 |
+
return outputs
|
| 927 |
+
|
| 928 |
+
|
| 929 |
+
class Siglip2Encoder(nn.Module):
|
| 930 |
+
"""
|
| 931 |
+
Transformer encoder consisting of `config.num_hidden_layers` self attention layers. Each layer is a
|
| 932 |
+
[`Siglip2EncoderLayer`].
|
| 933 |
+
|
| 934 |
+
Args:
|
| 935 |
+
config: Siglip2Config
|
| 936 |
+
"""
|
| 937 |
+
|
| 938 |
+
def __init__(self, config: Siglip2Config):
|
| 939 |
+
super().__init__()
|
| 940 |
+
self.config = config
|
| 941 |
+
|
| 942 |
+
self.rope_2d = Rope2DPosEmb(
|
| 943 |
+
config.hidden_size // config.num_attention_heads, 512, 512, config.window_size
|
| 944 |
+
)
|
| 945 |
+
self.layers = nn.ModuleList([Siglip2EncoderLayer(config) for _ in range(config.num_hidden_layers)])
|
| 946 |
+
self.gradient_checkpointing = False
|
| 947 |
+
self.full_attention_indexes = config.full_attention_indexes
|
| 948 |
+
|
| 949 |
+
|
| 950 |
+
# Ignore copy
|
| 951 |
+
@can_return_tuple
|
| 952 |
+
def forward(
|
| 953 |
+
self,
|
| 954 |
+
inputs_embeds,
|
| 955 |
+
output_attentions: Optional[bool] = None,
|
| 956 |
+
output_hidden_states: Optional[bool] = None,
|
| 957 |
+
win_meta_list: Optional[List[Dict]] = None,
|
| 958 |
+
spatial_shapes: Optional[torch.Tensor] = None,
|
| 959 |
+
) -> BaseModelOutput:
|
| 960 |
+
r"""
|
| 961 |
+
Args:
|
| 962 |
+
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
|
| 963 |
+
Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation.
|
| 964 |
+
This is useful if you want more control over how to convert `input_ids` indices into associated vectors
|
| 965 |
+
than the model's internal embedding lookup matrix.
|
| 966 |
+
attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 967 |
+
Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
|
| 968 |
+
|
| 969 |
+
- 1 for tokens that are **not masked**,
|
| 970 |
+
- 0 for tokens that are **masked**.
|
| 971 |
+
|
| 972 |
+
[What are attention masks?](../glossary#attention-mask)
|
| 973 |
+
output_attentions (`bool`, *optional*):
|
| 974 |
+
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
|
| 975 |
+
returned tensors for more detail.
|
| 976 |
+
output_hidden_states (`bool`, *optional*):
|
| 977 |
+
Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
|
| 978 |
+
for more detail.
|
| 979 |
+
return_dict (`bool`, *optional*):
|
| 980 |
+
Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
|
| 981 |
+
"""
|
| 982 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
| 983 |
+
output_hidden_states = (
|
| 984 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
| 985 |
+
)
|
| 986 |
+
|
| 987 |
+
encoder_states = () if output_hidden_states else None
|
| 988 |
+
all_attentions = () if output_attentions else None
|
| 989 |
+
|
| 990 |
+
rope_freqs_cis = self.rope_2d.get_freqs_cis(win_meta_list=win_meta_list, device=inputs_embeds.device)
|
| 991 |
+
|
| 992 |
+
hidden_states = inputs_embeds
|
| 993 |
+
for win_idx, encoder_layer in enumerate(self.layers):
|
| 994 |
+
|
| 995 |
+
if win_idx not in self.full_attention_indexes:
|
| 996 |
+
windows_attn = True
|
| 997 |
+
else:
|
| 998 |
+
windows_attn = False
|
| 999 |
+
|
| 1000 |
+
if output_hidden_states:
|
| 1001 |
+
encoder_states = encoder_states + (hidden_states,)
|
| 1002 |
+
if self.gradient_checkpointing and self.training:
|
| 1003 |
+
layer_outputs = self._gradient_checkpointing_func(
|
| 1004 |
+
encoder_layer.__call__,
|
| 1005 |
+
hidden_states,
|
| 1006 |
+
output_attentions,
|
| 1007 |
+
rope_freqs_cis,
|
| 1008 |
+
win_meta_list,
|
| 1009 |
+
windows_attn
|
| 1010 |
+
)
|
| 1011 |
+
else:
|
| 1012 |
+
layer_outputs = encoder_layer(
|
| 1013 |
+
hidden_states,
|
| 1014 |
+
output_attentions=output_attentions,
|
| 1015 |
+
rope_freqs_cis=rope_freqs_cis,
|
| 1016 |
+
win_meta_list=win_meta_list,
|
| 1017 |
+
windows_attn=windows_attn
|
| 1018 |
+
)
|
| 1019 |
+
|
| 1020 |
+
hidden_states = layer_outputs[0]
|
| 1021 |
+
|
| 1022 |
+
if output_attentions:
|
| 1023 |
+
all_attentions = all_attentions + (layer_outputs[1],)
|
| 1024 |
+
|
| 1025 |
+
if output_hidden_states:
|
| 1026 |
+
encoder_states = encoder_states + (hidden_states,)
|
| 1027 |
+
|
| 1028 |
+
return BaseModelOutput(
|
| 1029 |
+
last_hidden_state=hidden_states,
|
| 1030 |
+
hidden_states=encoder_states,
|
| 1031 |
+
attentions=all_attentions,
|
| 1032 |
+
)
|
| 1033 |
+
|
| 1034 |
+
|
| 1035 |
+
def reconstruct_patch_embeddings(last_hidden_state: torch.Tensor, win_meta_list: list[dict], spatial_shapes: torch.Tensor) -> torch.Tensor:
|
| 1036 |
+
|
| 1037 |
+
idx_map = build_idx_map(win_meta_list, spatial_shapes)
|
| 1038 |
+
last_hidden_state = last_hidden_state[:, idx_map, :]
|
| 1039 |
+
return last_hidden_state
|
| 1040 |
+
|
| 1041 |
+
SIGLIP2_VISION_INPUTS_DOCSTRING = r"""
|
| 1042 |
+
Args:
|
| 1043 |
+
pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):
|
| 1044 |
+
Pixel values. Padding will be ignored by default should you provide it. Pixel values can be obtained using
|
| 1045 |
+
[`AutoImageProcessor`]. See [`CLIPImageProcessor.__call__`] for details.
|
| 1046 |
+
output_attentions (`bool`, *optional*):
|
| 1047 |
+
Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
|
| 1048 |
+
tensors for more detail.
|
| 1049 |
+
output_hidden_states (`bool`, *optional*):
|
| 1050 |
+
Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
|
| 1051 |
+
more detail.
|
| 1052 |
+
interpolate_pos_encoding (`bool`, *optional*, defaults to `False`):
|
| 1053 |
+
Whether to interpolate the pre-trained position encodings.
|
| 1054 |
+
return_dict (`bool`, *optional*):
|
| 1055 |
+
Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
|
| 1056 |
+
"""
|
| 1057 |
+
|
| 1058 |
+
|
| 1059 |
+
class Siglip2VisionTransformer(nn.Module):
|
| 1060 |
+
def __init__(self, config: Siglip2VisionConfig):
|
| 1061 |
+
super().__init__()
|
| 1062 |
+
self.config = config
|
| 1063 |
+
embed_dim = config.hidden_size
|
| 1064 |
+
|
| 1065 |
+
self.embeddings = Siglip2VisionEmbeddings(config)
|
| 1066 |
+
self.encoder = Siglip2Encoder(config)
|
| 1067 |
+
self.post_layernorm = nn.LayerNorm(embed_dim, eps=config.layer_norm_eps)
|
| 1068 |
+
self.use_head = True if not hasattr(config, "vision_use_head") else config.vision_use_head
|
| 1069 |
+
if self.use_head:
|
| 1070 |
+
self.head = Siglip2MultiheadAttentionPoolingHead(config)
|
| 1071 |
+
self._use_flash_attention_2 = config._attn_implementation == "flash_attention_2"
|
| 1072 |
+
|
| 1073 |
+
@can_return_tuple
|
| 1074 |
+
@add_start_docstrings_to_model_forward(SIGLIP2_VISION_INPUTS_DOCSTRING)
|
| 1075 |
+
@replace_return_docstrings(output_type=BaseModelOutputWithPooling, config_class=Siglip2VisionConfig)
|
| 1076 |
+
def forward(
|
| 1077 |
+
self,
|
| 1078 |
+
pixel_values: torch.FloatTensor,
|
| 1079 |
+
output_attentions: Optional[bool] = None,
|
| 1080 |
+
output_hidden_states: Optional[bool] = None,
|
| 1081 |
+
) -> BaseModelOutputWithPooling:
|
| 1082 |
+
r"""
|
| 1083 |
+
Returns:
|
| 1084 |
+
|
| 1085 |
+
"""
|
| 1086 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
| 1087 |
+
output_hidden_states = (
|
| 1088 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
| 1089 |
+
)
|
| 1090 |
+
|
| 1091 |
+
windows_tensor, win_meta_list, spatial_shapes, reverse_mapping = self.embeddings(pixel_values)
|
| 1092 |
+
|
| 1093 |
+
encoder_outputs: BaseModelOutput = self.encoder(
|
| 1094 |
+
inputs_embeds=windows_tensor,
|
| 1095 |
+
output_attentions=output_attentions,
|
| 1096 |
+
output_hidden_states=output_hidden_states,
|
| 1097 |
+
win_meta_list=win_meta_list,
|
| 1098 |
+
spatial_shapes=spatial_shapes,
|
| 1099 |
+
)
|
| 1100 |
+
|
| 1101 |
+
last_hidden_state = encoder_outputs.last_hidden_state
|
| 1102 |
+
last_hidden_state = self.post_layernorm(last_hidden_state)
|
| 1103 |
+
last_hidden_state = last_hidden_state[:, reverse_mapping, :]
|
| 1104 |
+
return Siglip2VisionOutput(
|
| 1105 |
+
last_hidden_state=last_hidden_state,
|
| 1106 |
+
hidden_states=encoder_outputs.hidden_states,
|
| 1107 |
+
attentions=encoder_outputs.attentions,
|
| 1108 |
+
spatial_shapes=spatial_shapes,
|
| 1109 |
+
)
|
| 1110 |
+
|
| 1111 |
+
|
| 1112 |
+
def _trunc_normal_(tensor, mean, std, a, b):
|
| 1113 |
+
# Cut & paste from PyTorch official master until it's in a few official releases - RW
|
| 1114 |
+
# Method based on https://people.sc.fsu.edu/~jburkardt/presentations/truncated_normal.pdf
|
| 1115 |
+
def norm_cdf(x):
|
| 1116 |
+
# Computes standard normal cumulative distribution function
|
| 1117 |
+
return (1.0 + math.erf(x / math.sqrt(2.0))) / 2.0
|
| 1118 |
+
|
| 1119 |
+
if (mean < a - 2 * std) or (mean > b + 2 * std):
|
| 1120 |
+
warnings.warn(
|
| 1121 |
+
"mean is more than 2 std from [a, b] in nn.init.trunc_normal_. "
|
| 1122 |
+
"The distribution of values may be incorrect.",
|
| 1123 |
+
stacklevel=2,
|
| 1124 |
+
)
|
| 1125 |
+
|
| 1126 |
+
# Values are generated by using a truncated uniform distribution and
|
| 1127 |
+
# then using the inverse CDF for the normal distribution.
|
| 1128 |
+
# Get upper and lower cdf values
|
| 1129 |
+
l = norm_cdf((a - mean) / std)
|
| 1130 |
+
u = norm_cdf((b - mean) / std)
|
| 1131 |
+
|
| 1132 |
+
# Uniformly fill tensor with values from [l, u], then translate to
|
| 1133 |
+
# [2l-1, 2u-1].
|
| 1134 |
+
tensor.uniform_(2 * l - 1, 2 * u - 1)
|
| 1135 |
+
|
| 1136 |
+
# Use inverse cdf transform for normal distribution to get truncated
|
| 1137 |
+
# standard normal
|
| 1138 |
+
tensor.erfinv_()
|
| 1139 |
+
|
| 1140 |
+
# Transform to proper mean, std
|
| 1141 |
+
tensor.mul_(std * math.sqrt(2.0))
|
| 1142 |
+
tensor.add_(mean)
|
| 1143 |
+
|
| 1144 |
+
# Clamp to ensure it's in the proper range
|
| 1145 |
+
tensor.clamp_(min=a, max=b)
|
| 1146 |
+
|
| 1147 |
+
|
| 1148 |
+
def trunc_normal_tf_(
|
| 1149 |
+
tensor: torch.Tensor, mean: float = 0.0, std: float = 1.0, a: float = -2.0, b: float = 2.0
|
| 1150 |
+
) -> torch.Tensor:
|
| 1151 |
+
"""Fills the input Tensor with values drawn from a truncated
|
| 1152 |
+
normal distribution. The values are effectively drawn from the
|
| 1153 |
+
normal distribution :math:`\\mathcal{N}(\text{mean}, \text{std}^2)`
|
| 1154 |
+
with values outside :math:`[a, b]` redrawn until they are within
|
| 1155 |
+
the bounds. The method used for generating the random values works
|
| 1156 |
+
best when :math:`a \\leq \text{mean} \\leq b`.
|
| 1157 |
+
|
| 1158 |
+
NOTE: this 'tf' variant behaves closer to Tensorflow / JAX impl where the
|
| 1159 |
+
bounds [a, b] are applied when sampling the normal distribution with mean=0, std=1.0
|
| 1160 |
+
and the result is subsequently scaled and shifted by the mean and std args.
|
| 1161 |
+
|
| 1162 |
+
Args:
|
| 1163 |
+
tensor: an n-dimensional `torch.Tensor`
|
| 1164 |
+
mean: the mean of the normal distribution
|
| 1165 |
+
std: the standard deviation of the normal distribution
|
| 1166 |
+
a: the minimum cutoff value
|
| 1167 |
+
b: the maximum cutoff value
|
| 1168 |
+
"""
|
| 1169 |
+
with torch.no_grad():
|
| 1170 |
+
_trunc_normal_(tensor, 0, 1.0, a, b)
|
| 1171 |
+
tensor.mul_(std).add_(mean)
|
| 1172 |
+
|
| 1173 |
+
|
| 1174 |
+
def variance_scaling_(tensor, scale=1.0, mode="fan_in", distribution="normal"):
|
| 1175 |
+
fan_in, fan_out = _calculate_fan_in_and_fan_out(tensor)
|
| 1176 |
+
if mode == "fan_in":
|
| 1177 |
+
denom = fan_in
|
| 1178 |
+
elif mode == "fan_out":
|
| 1179 |
+
denom = fan_out
|
| 1180 |
+
elif mode == "fan_avg":
|
| 1181 |
+
denom = (fan_in + fan_out) / 2
|
| 1182 |
+
|
| 1183 |
+
variance = scale / denom
|
| 1184 |
+
|
| 1185 |
+
if distribution == "truncated_normal":
|
| 1186 |
+
# constant is stddev of standard normal truncated to (-2, 2)
|
| 1187 |
+
trunc_normal_tf_(tensor, std=math.sqrt(variance) / 0.87962566103423978)
|
| 1188 |
+
elif distribution == "normal":
|
| 1189 |
+
with torch.no_grad():
|
| 1190 |
+
tensor.normal_(std=math.sqrt(variance))
|
| 1191 |
+
elif distribution == "uniform":
|
| 1192 |
+
bound = math.sqrt(3 * variance)
|
| 1193 |
+
with torch.no_grad():
|
| 1194 |
+
tensor.uniform_(-bound, bound)
|
| 1195 |
+
else:
|
| 1196 |
+
raise ValueError(f"invalid distribution {distribution}")
|
| 1197 |
+
|
| 1198 |
+
|
| 1199 |
+
def lecun_normal_(tensor):
|
| 1200 |
+
variance_scaling_(tensor, mode="fan_in", distribution="truncated_normal")
|
| 1201 |
+
|
| 1202 |
+
|
| 1203 |
+
def default_flax_embed_init(tensor):
|
| 1204 |
+
variance_scaling_(tensor, mode="fan_in", distribution="normal")
|
| 1205 |
+
|
| 1206 |
+
|
| 1207 |
+
SIGLIP2_START_DOCSTRING = r"""
|
| 1208 |
+
This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
|
| 1209 |
+
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
|
| 1210 |
+
etc.)
|
| 1211 |
+
|
| 1212 |
+
This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
|
| 1213 |
+
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
|
| 1214 |
+
and behavior.
|
| 1215 |
+
|
| 1216 |
+
Parameters:
|
| 1217 |
+
config ([`Siglip2Config`]): Model configuration class with all the parameters of the model.
|
| 1218 |
+
Initializing with a config file does not load the weights associated with the model, only the
|
| 1219 |
+
configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.
|
| 1220 |
+
"""
|
| 1221 |
+
|
| 1222 |
+
SIGLIP2_INPUTS_DOCSTRING = r"""
|
| 1223 |
+
Args:
|
| 1224 |
+
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
|
| 1225 |
+
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
|
| 1226 |
+
it.
|
| 1227 |
+
|
| 1228 |
+
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
|
| 1229 |
+
[`PreTrainedTokenizer.__call__`] for details.
|
| 1230 |
+
|
| 1231 |
+
[What are input IDs?](../glossary#input-ids)
|
| 1232 |
+
attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 1233 |
+
Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
|
| 1234 |
+
|
| 1235 |
+
- 1 for tokens that are **not masked**,
|
| 1236 |
+
- 0 for tokens that are **masked**.
|
| 1237 |
+
|
| 1238 |
+
[What are attention masks?](../glossary#attention-mask)
|
| 1239 |
+
position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 1240 |
+
Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
|
| 1241 |
+
config.max_position_embeddings - 1]`.
|
| 1242 |
+
|
| 1243 |
+
[What are position IDs?](../glossary#position-ids)
|
| 1244 |
+
pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):
|
| 1245 |
+
Pixel values. Padding will be ignored by default should you provide it. Pixel values can be obtained using
|
| 1246 |
+
[`AutoImageProcessor`]. See [`CLIPImageProcessor.__call__`] for details.
|
| 1247 |
+
return_loss (`bool`, *optional*):
|
| 1248 |
+
Whether or not to return the contrastive loss.
|
| 1249 |
+
output_attentions (`bool`, *optional*):
|
| 1250 |
+
Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
|
| 1251 |
+
tensors for more detail.
|
| 1252 |
+
output_hidden_states (`bool`, *optional*):
|
| 1253 |
+
Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
|
| 1254 |
+
more detail.
|
| 1255 |
+
interpolate_pos_encoding (`bool`, *optional*, defaults to `False`):
|
| 1256 |
+
Whether to interpolate the pre-trained position encodings.
|
| 1257 |
+
return_dict (`bool`, *optional*):
|
| 1258 |
+
Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
|
| 1259 |
+
"""
|
| 1260 |
+
|
| 1261 |
+
|
| 1262 |
+
class Siglip2PreTrainedModel(PreTrainedModel):
|
| 1263 |
+
"""
|
| 1264 |
+
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
|
| 1265 |
+
models.
|
| 1266 |
+
"""
|
| 1267 |
+
|
| 1268 |
+
config_class = Siglip2Config
|
| 1269 |
+
base_model_prefix = "siglip2"
|
| 1270 |
+
supports_gradient_checkpointing = True
|
| 1271 |
+
|
| 1272 |
+
_no_split_modules = [
|
| 1273 |
+
"Siglip2TextEmbeddings",
|
| 1274 |
+
"Siglip2EncoderLayer",
|
| 1275 |
+
"Siglip2VisionEmbeddings",
|
| 1276 |
+
"Siglip2EncoderLayer",
|
| 1277 |
+
"Siglip2MultiheadAttentionPoolingHead",
|
| 1278 |
+
]
|
| 1279 |
+
_supports_flash_attn_2 = True
|
| 1280 |
+
_supports_sdpa = True
|
| 1281 |
+
|
| 1282 |
+
def _init_weights(self, module):
|
| 1283 |
+
"""Initialize the weights"""
|
| 1284 |
+
if isinstance(module, Siglip2VisionEmbeddings):
|
| 1285 |
+
width = (
|
| 1286 |
+
self.config.vision_config.hidden_size
|
| 1287 |
+
if isinstance(self.config, Siglip2Config)
|
| 1288 |
+
else self.config.hidden_size
|
| 1289 |
+
)
|
| 1290 |
+
nn.init.normal_(module.position_embedding.weight, std=1 / np.sqrt(width))
|
| 1291 |
+
elif isinstance(module, nn.Embedding):
|
| 1292 |
+
default_flax_embed_init(module.weight)
|
| 1293 |
+
elif isinstance(module, Siglip2Attention):
|
| 1294 |
+
nn.init.xavier_uniform_(module.q_proj.weight)
|
| 1295 |
+
nn.init.xavier_uniform_(module.k_proj.weight)
|
| 1296 |
+
nn.init.xavier_uniform_(module.v_proj.weight)
|
| 1297 |
+
nn.init.xavier_uniform_(module.out_proj.weight)
|
| 1298 |
+
nn.init.zeros_(module.q_proj.bias)
|
| 1299 |
+
nn.init.zeros_(module.k_proj.bias)
|
| 1300 |
+
nn.init.zeros_(module.v_proj.bias)
|
| 1301 |
+
nn.init.zeros_(module.out_proj.bias)
|
| 1302 |
+
elif isinstance(module, Siglip2MLP):
|
| 1303 |
+
nn.init.xavier_uniform_(module.fc1.weight)
|
| 1304 |
+
nn.init.xavier_uniform_(module.fc2.weight)
|
| 1305 |
+
nn.init.normal_(module.fc1.bias, std=1e-6)
|
| 1306 |
+
nn.init.normal_(module.fc2.bias, std=1e-6)
|
| 1307 |
+
elif isinstance(module, Siglip2MultiheadAttentionPoolingHead):
|
| 1308 |
+
nn.init.xavier_uniform_(module.probe.data)
|
| 1309 |
+
nn.init.xavier_uniform_(module.attention.in_proj_weight.data)
|
| 1310 |
+
nn.init.zeros_(module.attention.in_proj_bias.data)
|
| 1311 |
+
elif isinstance(module, Siglip2Model):
|
| 1312 |
+
logit_scale_init = torch.log(torch.tensor(1.0))
|
| 1313 |
+
module.logit_scale.data.fill_(logit_scale_init)
|
| 1314 |
+
module.logit_bias.data.zero_()
|
| 1315 |
+
elif isinstance(module, Siglip2ForImageClassification):
|
| 1316 |
+
nn.init.normal_(
|
| 1317 |
+
module.classifier.weight,
|
| 1318 |
+
std=self.config.vision_config.hidden_size**-0.5 * self.config.initializer_factor,
|
| 1319 |
+
)
|
| 1320 |
+
elif isinstance(module, (nn.Linear, nn.Conv2d)):
|
| 1321 |
+
lecun_normal_(module.weight)
|
| 1322 |
+
if module.bias is not None:
|
| 1323 |
+
nn.init.zeros_(module.bias)
|
| 1324 |
+
elif isinstance(module, nn.LayerNorm):
|
| 1325 |
+
module.bias.data.zero_()
|
| 1326 |
+
module.weight.data.fill_(1.0)
|
| 1327 |
+
|
| 1328 |
+
|
| 1329 |
+
class Siglip2MultiheadAttentionPoolingHead(nn.Module):
|
| 1330 |
+
"""Multihead Attention Pooling."""
|
| 1331 |
+
|
| 1332 |
+
def __init__(self, config: Siglip2VisionConfig):
|
| 1333 |
+
super().__init__()
|
| 1334 |
+
|
| 1335 |
+
self.probe = nn.Parameter(torch.randn(1, 1, config.hidden_size))
|
| 1336 |
+
self.attention = torch.nn.MultiheadAttention(config.hidden_size, config.num_attention_heads, batch_first=True)
|
| 1337 |
+
self.layernorm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
|
| 1338 |
+
self.mlp = Siglip2MLP(config)
|
| 1339 |
+
self.num_heads = config.num_attention_heads
|
| 1340 |
+
|
| 1341 |
+
def forward(self, hidden_state: torch.Tensor, attention_mask: Optional[torch.Tensor] = None) -> torch.Tensor:
|
| 1342 |
+
batch_size = hidden_state.shape[0]
|
| 1343 |
+
probe = self.probe.repeat(batch_size, 1, 1)
|
| 1344 |
+
|
| 1345 |
+
if attention_mask is not None:
|
| 1346 |
+
target_len, source_len = probe.shape[1], hidden_state.shape[1]
|
| 1347 |
+
attention_mask = _prepare_4d_attention_mask(attention_mask, hidden_state.dtype, target_len)
|
| 1348 |
+
attention_mask = attention_mask.repeat(1, self.num_heads, target_len, 1)
|
| 1349 |
+
attention_mask = attention_mask.reshape(-1, target_len, source_len)
|
| 1350 |
+
|
| 1351 |
+
hidden_state = self.attention(probe, hidden_state, hidden_state, attn_mask=attention_mask)[0]
|
| 1352 |
+
|
| 1353 |
+
residual = hidden_state
|
| 1354 |
+
hidden_state = self.layernorm(hidden_state)
|
| 1355 |
+
hidden_state = residual + self.mlp(hidden_state)
|
| 1356 |
+
|
| 1357 |
+
return hidden_state[:, 0]
|
| 1358 |
+
|
| 1359 |
+
|
| 1360 |
+
@add_start_docstrings(
|
| 1361 |
+
"""The vision model from Siglip2 without any head or projection on top.""",
|
| 1362 |
+
SIGLIP2_START_DOCSTRING,
|
| 1363 |
+
)
|
| 1364 |
+
class Siglip2VisionModel(Siglip2PreTrainedModel):
|
| 1365 |
+
config_class = Siglip2VisionConfig
|
| 1366 |
+
main_input_name = "pixel_values"
|
| 1367 |
+
|
| 1368 |
+
def __init__(self, config: Siglip2VisionConfig):
|
| 1369 |
+
super().__init__(config)
|
| 1370 |
+
|
| 1371 |
+
self.vision_model = Siglip2VisionTransformer(config)
|
| 1372 |
+
|
| 1373 |
+
# Initialize weights and apply final processing
|
| 1374 |
+
self.post_init()
|
| 1375 |
+
|
| 1376 |
+
def get_input_embeddings(self) -> nn.Module:
|
| 1377 |
+
return self.vision_model.embeddings.patch_embedding
|
| 1378 |
+
|
| 1379 |
+
@can_return_tuple
|
| 1380 |
+
@add_start_docstrings_to_model_forward(SIGLIP2_VISION_INPUTS_DOCSTRING)
|
| 1381 |
+
@replace_return_docstrings(output_type=BaseModelOutputWithPooling, config_class=Siglip2VisionConfig)
|
| 1382 |
+
def forward(
|
| 1383 |
+
self,
|
| 1384 |
+
pixel_values: torch.FloatTensor,
|
| 1385 |
+
output_attentions: Optional[bool] = None,
|
| 1386 |
+
output_hidden_states: Optional[bool] = None,
|
| 1387 |
+
) -> BaseModelOutputWithPooling:
|
| 1388 |
+
r"""
|
| 1389 |
+
Returns:
|
| 1390 |
+
|
| 1391 |
+
Examples:
|
| 1392 |
+
|
| 1393 |
+
```python
|
| 1394 |
+
>>> from PIL import Image
|
| 1395 |
+
>>> import requests
|
| 1396 |
+
>>> from transformers import AutoProcessor, Siglip2VisionModel
|
| 1397 |
+
|
| 1398 |
+
>>> model = Siglip2VisionModel.from_pretrained("google/siglip2-base-patch16-224")
|
| 1399 |
+
>>> processor = AutoProcessor.from_pretrained("google/siglip2-base-patch16-224")
|
| 1400 |
+
|
| 1401 |
+
>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
|
| 1402 |
+
>>> image = Image.open(requests.get(url, stream=True).raw)
|
| 1403 |
+
|
| 1404 |
+
>>> inputs = processor(images=image, return_tensors="pt")
|
| 1405 |
+
|
| 1406 |
+
>>> outputs = model(**inputs)
|
| 1407 |
+
>>> last_hidden_state = outputs.last_hidden_state
|
| 1408 |
+
>>> pooled_output = outputs.pooler_output # pooled features
|
| 1409 |
+
```"""
|
| 1410 |
+
return self.vision_model(
|
| 1411 |
+
pixel_values=pixel_values,
|
| 1412 |
+
output_attentions=output_attentions,
|
| 1413 |
+
output_hidden_states=output_hidden_states,
|
| 1414 |
+
)
|
| 1415 |
+
|
| 1416 |
+
|
| 1417 |
+
__all__ = [
|
| 1418 |
+
"Siglip2VisionModel",
|
| 1419 |
+
]
|
preprocessor_config.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"auto_map": {
|
| 3 |
+
"AutoImageProcessor": "image_processing_eagle3_vl_fast.Eagle3_VLImageProcessorFast",
|
| 4 |
+
"AutoProcessor": "processing_eagle3_vl.Eagle3_VLProcessor"
|
| 5 |
+
},
|
| 6 |
+
"crop_size": null,
|
| 7 |
+
"data_format": "channels_first",
|
| 8 |
+
"default_to_square": false,
|
| 9 |
+
"device": null,
|
| 10 |
+
"do_center_crop": null,
|
| 11 |
+
"do_convert_rgb": true,
|
| 12 |
+
"do_normalize": true,
|
| 13 |
+
"do_pad": false,
|
| 14 |
+
"do_rescale": true,
|
| 15 |
+
"do_resize": false,
|
| 16 |
+
"image_mean": [
|
| 17 |
+
0.5,
|
| 18 |
+
0.5,
|
| 19 |
+
0.5
|
| 20 |
+
],
|
| 21 |
+
"image_processor_type": "Eagle3_VLImageProcessorFast",
|
| 22 |
+
"image_std": [
|
| 23 |
+
0.5,
|
| 24 |
+
0.5,
|
| 25 |
+
0.5
|
| 26 |
+
],
|
| 27 |
+
"input_data_format": null,
|
| 28 |
+
"processor_class": "Eagle3_VLProcessor",
|
| 29 |
+
"resample": 3,
|
| 30 |
+
"rescale_factor": 0.00392156862745098,
|
| 31 |
+
"return_tensors": null,
|
| 32 |
+
"size": {
|
| 33 |
+
"height": 448,
|
| 34 |
+
"width": 448
|
| 35 |
+
}
|
| 36 |
+
}
|
processing_eagle3_vl.py
ADDED
|
@@ -0,0 +1,905 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2024 The HuggingFace Inc. team.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
"""
|
| 16 |
+
Processor class for Eagle3_VL.
|
| 17 |
+
copy from https://github.com/huggingface/transformers/blob/main/src/transformers/models/llava_onevision/processing_llava_onevision.py
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
import math
|
| 21 |
+
import os
|
| 22 |
+
from typing import Iterable, List, Union, Literal
|
| 23 |
+
import base64
|
| 24 |
+
import sys
|
| 25 |
+
import time
|
| 26 |
+
import warnings
|
| 27 |
+
from functools import lru_cache
|
| 28 |
+
from io import BytesIO
|
| 29 |
+
import re
|
| 30 |
+
import requests
|
| 31 |
+
import torch
|
| 32 |
+
import torchvision
|
| 33 |
+
from packaging import version
|
| 34 |
+
from PIL import Image
|
| 35 |
+
from torchvision import io
|
| 36 |
+
from torchvision import transforms
|
| 37 |
+
from torch.nn import functional as F
|
| 38 |
+
from torchvision.transforms import InterpolationMode
|
| 39 |
+
from typing import Optional, Any
|
| 40 |
+
import numpy as np
|
| 41 |
+
|
| 42 |
+
from transformers.feature_extraction_utils import BatchFeature
|
| 43 |
+
from transformers.image_processing_utils import select_best_resolution
|
| 44 |
+
from transformers.image_utils import ImageInput, VideoInput, get_image_size, to_numpy_array
|
| 45 |
+
from transformers.processing_utils import ProcessingKwargs, ProcessorMixin, Unpack
|
| 46 |
+
from transformers.tokenization_utils_base import PreTokenizedInput, TextInput
|
| 47 |
+
from transformers.utils import logging
|
| 48 |
+
from transformers.models.auto import AutoImageProcessor
|
| 49 |
+
import lmdb
|
| 50 |
+
import cv2
|
| 51 |
+
import pickle
|
| 52 |
+
logger = logging.get_logger(__name__)
|
| 53 |
+
|
| 54 |
+
# Highly inspired by https://github.com/QwenLM/Qwen2.5-VL/blob/main/qwen-vl-utils/src/qwen_vl_utils/vision_process.py
|
| 55 |
+
|
| 56 |
+
FRAME_FACTOR = 2
|
| 57 |
+
FPS = 2.0
|
| 58 |
+
FPS_MIN_FRAMES = 4
|
| 59 |
+
FPS_MAX_FRAMES = 256
|
| 60 |
+
|
| 61 |
+
IMAGE_FACTOR = 28
|
| 62 |
+
MIN_PIXELS = 4 * 28 * 28
|
| 63 |
+
MAX_PIXELS = 4096 * 28 * 28
|
| 64 |
+
MAX_RATIO = 200
|
| 65 |
+
IMAGE_MAX_SIZE = 500 * 14
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
VIDEO_MIN_PIXELS = 128 * 28 * 28
|
| 69 |
+
VIDEO_MAX_PIXELS = 768 * 28 * 28
|
| 70 |
+
|
| 71 |
+
# Set the maximum number of video token inputs.
|
| 72 |
+
# Here, 128K represents the maximum number of input tokens for the VLLM model.
|
| 73 |
+
# Remember to adjust it according to your own configuration.
|
| 74 |
+
VIDEO_TOTAL_PIXELS = int(float(os.environ.get('VIDEO_MAX_PIXELS', 128000 * 28 * 28 * 0.9)))
|
| 75 |
+
logger.info(f"set VIDEO_TOTAL_PIXELS: {VIDEO_TOTAL_PIXELS}")
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def adjust_by_factor(number: int, factor: int, method: Literal['round', 'ceil', 'floor'] = 'round') -> int:
|
| 81 |
+
"""Adjusts 'number' to the nearest, ceiling, or floor multiple of 'factor'."""
|
| 82 |
+
op = {'round': round, 'ceil': math.ceil, 'floor': math.floor}[method]
|
| 83 |
+
return op(number / factor) * factor
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def to_rgb(pil_image: Image.Image) -> Image.Image:
|
| 87 |
+
if pil_image.mode == 'RGBA':
|
| 88 |
+
white_background = Image.new("RGB", pil_image.size, (255, 255, 255))
|
| 89 |
+
white_background.paste(pil_image, mask=pil_image.split()[3]) # Use alpha channel as mask
|
| 90 |
+
return white_background
|
| 91 |
+
else:
|
| 92 |
+
return pil_image.convert("RGB")
|
| 93 |
+
|
| 94 |
+
def smart_resize(
|
| 95 |
+
height: int, width: int, factor: int = IMAGE_FACTOR, min_pixels: int = MIN_PIXELS, max_pixels: int = MAX_PIXELS
|
| 96 |
+
) -> tuple[int, int]:
|
| 97 |
+
"""
|
| 98 |
+
Rescales the image so that the following conditions are met:
|
| 99 |
+
1. Both dimensions (height and width) are divisible by 'factor'.
|
| 100 |
+
2. The total number of pixels is within the range ['min_pixels', 'max_pixels'].
|
| 101 |
+
3. The aspect ratio of the image is maintained as closely as possible.
|
| 102 |
+
"""
|
| 103 |
+
if max(height, width) / min(height, width) > MAX_RATIO:
|
| 104 |
+
raise ValueError(
|
| 105 |
+
f"absolute aspect ratio must be smaller than {MAX_RATIO}, got {max(height, width) / min(height, width)}"
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
h_bar = min(max(factor, adjust_by_factor(height, factor, method='round')), IMAGE_MAX_SIZE)
|
| 110 |
+
w_bar = min(max(factor, adjust_by_factor(width, factor, method='round')), IMAGE_MAX_SIZE)
|
| 111 |
+
if h_bar * w_bar > max_pixels:
|
| 112 |
+
beta = math.sqrt((h_bar * w_bar) / max_pixels)
|
| 113 |
+
h_bar = adjust_by_factor(h_bar / beta, factor, method='floor')
|
| 114 |
+
w_bar = adjust_by_factor(w_bar / beta, factor, method='floor')
|
| 115 |
+
elif h_bar * w_bar < min_pixels:
|
| 116 |
+
beta = math.sqrt(min_pixels / (height * width))
|
| 117 |
+
h_bar = adjust_by_factor(height * beta, factor, method='ceil')
|
| 118 |
+
w_bar = adjust_by_factor(width * beta, factor, method='ceil')
|
| 119 |
+
|
| 120 |
+
return h_bar, w_bar
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def read_img_from_lmdb_v2(image_data):
|
| 124 |
+
# special case for AgiBotWorld
|
| 125 |
+
lmdb_file, lmdb_key = image_data['lmdb_file'], image_data['lmdb_key']
|
| 126 |
+
key = lmdb_key.encode('ascii')
|
| 127 |
+
env = lmdb.open(lmdb_file, max_readers=10240, readonly=True, lock=False, readahead=False, meminit=False)
|
| 128 |
+
txn = env.begin()
|
| 129 |
+
value = txn.get(key)
|
| 130 |
+
if value is None:
|
| 131 |
+
print(f"Warning: Key {key} not found.")
|
| 132 |
+
return None
|
| 133 |
+
record = pickle.loads(value)
|
| 134 |
+
image_bgr = cv2.imdecode(np.frombuffer(record['image'], dtype=np.uint8), cv2.IMREAD_COLOR)
|
| 135 |
+
image_rgb = cv2.cvtColor(image_bgr, cv2.COLOR_BGR2RGB)
|
| 136 |
+
image = Image.fromarray(image_rgb)
|
| 137 |
+
|
| 138 |
+
return image
|
| 139 |
+
|
| 140 |
+
def parse_lmdb_image_data(image_data):
|
| 141 |
+
lmdb_file = image_data['lmdb_file']
|
| 142 |
+
if not os.path.exists(lmdb_file):
|
| 143 |
+
if "/home/zhidingy/workspace/libs/eagle/Eagle2/" in lmdb_file:
|
| 144 |
+
lmdb_file = lmdb_file.replace("/home/zhidingy/workspace/libs/eagle/Eagle2/", "")
|
| 145 |
+
else:
|
| 146 |
+
raise ValueError(f"LMDB file {lmdb_file} does not exist")
|
| 147 |
+
|
| 148 |
+
# special case for AgiBotWorld, will remove it later
|
| 149 |
+
if 'AgiBotWorld' in image_data['lmdb_file']:
|
| 150 |
+
return read_img_from_lmdb_v2(image_data)
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
try:
|
| 154 |
+
env = lmdb.open(image_data['lmdb_file'], readonly=True, lock=False, max_readers=10240)
|
| 155 |
+
except Exception as e:
|
| 156 |
+
print(f"Failed to open lmdb file {image_data['lmdb_file']}. Error message: {e}", flush=True)
|
| 157 |
+
raise e
|
| 158 |
+
|
| 159 |
+
with env.begin(write=False) as txn:
|
| 160 |
+
try:
|
| 161 |
+
image_bin = txn.get(image_data['lmdb_key'].encode('ascii'))
|
| 162 |
+
buf = BytesIO(image_bin)
|
| 163 |
+
except Exception as e:
|
| 164 |
+
print(f"Failed to get image from lmdb file {image_data['lmdb_file']}. Error message: {e}", flush=True)
|
| 165 |
+
raise e
|
| 166 |
+
try:
|
| 167 |
+
image = Image.open(buf)
|
| 168 |
+
except Exception as e:
|
| 169 |
+
image_np = np.frombuffer(image_bin, dtype=np.uint8)
|
| 170 |
+
image_bgr = cv2.imdecode(image_np, cv2.IMREAD_COLOR)
|
| 171 |
+
image_rgb = cv2.cvtColor(image_bgr, cv2.COLOR_BGR2RGB)
|
| 172 |
+
image = Image.fromarray(image_rgb)
|
| 173 |
+
return image
|
| 174 |
+
|
| 175 |
+
def fetch_image(ele: dict[str, str | Image.Image], size_factor: int = IMAGE_FACTOR) -> Image.Image:
|
| 176 |
+
if "image" in ele:
|
| 177 |
+
image = ele["image"]
|
| 178 |
+
else:
|
| 179 |
+
image = ele["image_url"]
|
| 180 |
+
image_obj = None
|
| 181 |
+
if isinstance(image, Image.Image):
|
| 182 |
+
image_obj = image
|
| 183 |
+
elif isinstance(image, dict) and 'lmdb_file' in image:
|
| 184 |
+
image_obj = parse_lmdb_image_data(image)
|
| 185 |
+
elif image.startswith("http://") or image.startswith("https://"):
|
| 186 |
+
response = requests.get(image, stream=True)
|
| 187 |
+
image_obj = Image.open(BytesIO(response.content))
|
| 188 |
+
elif image.startswith("file://"):
|
| 189 |
+
image_obj = Image.open(image[7:])
|
| 190 |
+
elif image.startswith("data:image"):
|
| 191 |
+
if "base64," in image:
|
| 192 |
+
_, base64_data = image.split("base64,", 1)
|
| 193 |
+
data = base64.b64decode(base64_data)
|
| 194 |
+
image_obj = Image.open(BytesIO(data))
|
| 195 |
+
else:
|
| 196 |
+
image_obj = Image.open(image)
|
| 197 |
+
if image_obj is None:
|
| 198 |
+
raise ValueError(f"Unrecognized image input, support local path, http url, base64 and PIL.Image, got {image}")
|
| 199 |
+
image = to_rgb(image_obj)
|
| 200 |
+
# if 'scale_factor' in ele:
|
| 201 |
+
# scale_factor = ele['scale_factor']
|
| 202 |
+
# image = image.resize((image.width * scale_factor, image.height * scale_factor), Image.BILINEAR)
|
| 203 |
+
|
| 204 |
+
if "resized_height" in ele and "resized_width" in ele:
|
| 205 |
+
resized_height, resized_width = smart_resize(
|
| 206 |
+
ele["resized_height"],
|
| 207 |
+
ele["resized_width"],
|
| 208 |
+
factor=size_factor,
|
| 209 |
+
)
|
| 210 |
+
else:
|
| 211 |
+
width, height = image.size
|
| 212 |
+
min_pixels = ele.get("min_pixels", MIN_PIXELS)
|
| 213 |
+
max_pixels = ele.get("max_pixels", MAX_PIXELS)
|
| 214 |
+
resized_height, resized_width = smart_resize(
|
| 215 |
+
height,
|
| 216 |
+
width,
|
| 217 |
+
factor=size_factor,
|
| 218 |
+
min_pixels=min_pixels,
|
| 219 |
+
max_pixels=max_pixels,
|
| 220 |
+
)
|
| 221 |
+
image = image.resize((resized_width, resized_height))
|
| 222 |
+
|
| 223 |
+
return image
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
def smart_nframes(
|
| 227 |
+
ele: dict,
|
| 228 |
+
total_frames: int,
|
| 229 |
+
video_fps: int | float,
|
| 230 |
+
) -> int:
|
| 231 |
+
"""calculate the number of frames for video used for model inputs.
|
| 232 |
+
Args:
|
| 233 |
+
ele (dict): a dict contains the configuration of video.
|
| 234 |
+
support either `fps` or `nframes`:
|
| 235 |
+
- nframes: the number of frames to extract for model inputs.
|
| 236 |
+
- fps: the fps to extract frames for model inputs.
|
| 237 |
+
- min_frames: the minimum number of frames of the video, only used when fps is provided.
|
| 238 |
+
- max_frames: the maximum number of frames of the video, only used when fps is provided.
|
| 239 |
+
total_frames (int): the original total number of frames of the video.
|
| 240 |
+
video_fps (int | float): the original fps of the video.
|
| 241 |
+
Raises:
|
| 242 |
+
ValueError: nframes should in interval [FRAME_FACTOR, total_frames].
|
| 243 |
+
Returns:
|
| 244 |
+
int: the number of frames for video used for model inputs.
|
| 245 |
+
"""
|
| 246 |
+
assert not ("fps" in ele and "nframes" in ele), "Only accept either `fps` or `nframes`"
|
| 247 |
+
if "nframes" in ele:
|
| 248 |
+
nframes = adjust_by_factor(ele["nframes"], FRAME_FACTOR, method='round')
|
| 249 |
+
else:
|
| 250 |
+
fps = ele.get("fps", FPS)
|
| 251 |
+
min_frames = adjust_by_factor(ele.get("min_frames", FPS_MIN_FRAMES), FRAME_FACTOR, method='ceil')
|
| 252 |
+
max_frames = adjust_by_factor(ele.get("max_frames", min(FPS_MAX_FRAMES, total_frames)), FRAME_FACTOR, method='floor')
|
| 253 |
+
nframes = total_frames / video_fps * fps
|
| 254 |
+
if nframes > total_frames:
|
| 255 |
+
logger.warning(f"smart_nframes: nframes[{nframes}] > total_frames[{total_frames}]")
|
| 256 |
+
nframes = min(min(max(nframes, min_frames), max_frames), total_frames)
|
| 257 |
+
nframes = adjust_by_factor(nframes, FRAME_FACTOR, method='floor')
|
| 258 |
+
if not (FRAME_FACTOR <= nframes and nframes <= total_frames):
|
| 259 |
+
# raise ValueError(f"nframes should in interval [{FRAME_FACTOR}, {total_frames}], but got {nframes}.")
|
| 260 |
+
nframes = total_frames
|
| 261 |
+
return nframes
|
| 262 |
+
|
| 263 |
+
def _read_video_torchvision(
|
| 264 |
+
ele: dict,
|
| 265 |
+
) -> (torch.Tensor, float, list):
|
| 266 |
+
"""read video using torchvision.io.read_video and return also per-frame timestamps"""
|
| 267 |
+
video_path = ele["video"]
|
| 268 |
+
if version.parse(torchvision.__version__) < version.parse("0.19.0"):
|
| 269 |
+
if "http://" in video_path or "https://" in video_path:
|
| 270 |
+
warnings.warn("torchvision < 0.19.0 does not support http/https video path, please upgrade to 0.19.0.")
|
| 271 |
+
if "file://" in video_path:
|
| 272 |
+
video_path = video_path[7:]
|
| 273 |
+
st = time.time()
|
| 274 |
+
video, audio, info = io.read_video(
|
| 275 |
+
video_path,
|
| 276 |
+
start_pts=ele.get("video_start", 0.0),
|
| 277 |
+
end_pts=ele.get("video_end", None),
|
| 278 |
+
pts_unit="sec",
|
| 279 |
+
output_format="TCHW",
|
| 280 |
+
)
|
| 281 |
+
total_frames, video_fps = video.size(0), info["video_fps"]
|
| 282 |
+
logger.info(f"torchvision: {video_path=}, {total_frames=}, {video_fps=}, time={time.time() - st:.3f}s")
|
| 283 |
+
nframes = smart_nframes(ele, total_frames=total_frames, video_fps=video_fps)
|
| 284 |
+
# Calculate frame indices and corresponding timestamps (based on video start time)
|
| 285 |
+
idx = torch.linspace(0, total_frames - 1, nframes).round().long()
|
| 286 |
+
start_time = ele.get("video_start", 0.0)
|
| 287 |
+
timestamps = (start_time + idx.to(torch.float32) / video_fps).tolist()
|
| 288 |
+
sample_fps = nframes / max(total_frames, 1e-6) * video_fps
|
| 289 |
+
video = video[idx]
|
| 290 |
+
return video, sample_fps, timestamps
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
def is_pyav_available() -> bool:
|
| 295 |
+
import importlib.util
|
| 296 |
+
|
| 297 |
+
return importlib.util.find_spec("av") is not None
|
| 298 |
+
|
| 299 |
+
def _read_video_pyav(
|
| 300 |
+
ele: dict,
|
| 301 |
+
) -> (torch.Tensor, float, list):
|
| 302 |
+
"""read video using pyav and return also per-frame timestamps"""
|
| 303 |
+
import av
|
| 304 |
+
video_path = ele["video"]
|
| 305 |
+
st = time.time()
|
| 306 |
+
|
| 307 |
+
# Open video file
|
| 308 |
+
container = av.open(video_path)
|
| 309 |
+
video_stream = container.streams.video[0]
|
| 310 |
+
|
| 311 |
+
# Get video properties
|
| 312 |
+
total_frames = video_stream.frames
|
| 313 |
+
video_fps = float(video_stream.average_rate)
|
| 314 |
+
|
| 315 |
+
# Handle video start and end times
|
| 316 |
+
start_time = ele.get("video_start", 0.0)
|
| 317 |
+
end_time = ele.get("video_end", None)
|
| 318 |
+
|
| 319 |
+
if start_time > 0 or end_time is not None:
|
| 320 |
+
# Seek to start time
|
| 321 |
+
start_pts = int(start_time * video_stream.time_base.denominator / video_stream.time_base.numerator)
|
| 322 |
+
container.seek(start_pts, stream=video_stream)
|
| 323 |
+
|
| 324 |
+
# Calculate end pts if specified
|
| 325 |
+
if end_time is not None:
|
| 326 |
+
end_pts = int(end_time * video_stream.time_base.denominator / video_stream.time_base.numerator)
|
| 327 |
+
else:
|
| 328 |
+
end_pts = None
|
| 329 |
+
else:
|
| 330 |
+
end_pts = None
|
| 331 |
+
|
| 332 |
+
logger.info(f"pyav: {video_path=}, {total_frames=}, {video_fps=}, time={time.time() - st:.3f}s")
|
| 333 |
+
|
| 334 |
+
# Calculate number of frames to extract
|
| 335 |
+
nframes = smart_nframes(ele, total_frames=total_frames, video_fps=video_fps)
|
| 336 |
+
|
| 337 |
+
# Calculate frame indices and timestamps
|
| 338 |
+
idx = torch.linspace(0, total_frames - 1, nframes).round().long().tolist()
|
| 339 |
+
timestamps = [start_time + i / video_fps for i in idx]
|
| 340 |
+
|
| 341 |
+
# Extract frames
|
| 342 |
+
frames = []
|
| 343 |
+
frame_count = 0
|
| 344 |
+
target_frame_indices = set(idx)
|
| 345 |
+
|
| 346 |
+
for frame in container.decode(video_stream):
|
| 347 |
+
if frame_count in target_frame_indices:
|
| 348 |
+
# Convert frame to RGB numpy array
|
| 349 |
+
frame_array = frame.to_ndarray(format='rgb24')
|
| 350 |
+
frames.append(frame_array)
|
| 351 |
+
|
| 352 |
+
frame_count += 1
|
| 353 |
+
|
| 354 |
+
# Stop if we've reached the end time or have enough frames
|
| 355 |
+
if end_pts is not None and frame.pts >= end_pts:
|
| 356 |
+
break
|
| 357 |
+
if len(frames) >= nframes:
|
| 358 |
+
break
|
| 359 |
+
|
| 360 |
+
container.close()
|
| 361 |
+
|
| 362 |
+
# Convert to tensor
|
| 363 |
+
if frames:
|
| 364 |
+
video = torch.tensor(np.stack(frames)).permute(0, 3, 1, 2) # Convert to TCHW format
|
| 365 |
+
else:
|
| 366 |
+
# Fallback: create empty tensor with correct shape
|
| 367 |
+
video = torch.zeros((nframes, 3, 224, 224), dtype=torch.uint8)
|
| 368 |
+
|
| 369 |
+
sample_fps = nframes / max(total_frames, 1e-6) * video_fps
|
| 370 |
+
return video, sample_fps, timestamps
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
VIDEO_READER_BACKENDS = {
|
| 374 |
+
"pyav": _read_video_pyav,
|
| 375 |
+
"torchvision": _read_video_torchvision,
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
|
| 379 |
+
@lru_cache(maxsize=1)
|
| 380 |
+
def get_video_reader_backend() -> str:
|
| 381 |
+
if is_pyav_available():
|
| 382 |
+
video_reader_backend = "pyav"
|
| 383 |
+
else:
|
| 384 |
+
video_reader_backend = "torchvision"
|
| 385 |
+
return video_reader_backend
|
| 386 |
+
|
| 387 |
+
|
| 388 |
+
|
| 389 |
+
|
| 390 |
+
def fetch_video(ele: dict, image_factor: int = IMAGE_FACTOR, return_video_sample_fps: bool = False) -> torch.Tensor | list[Image.Image]:
|
| 391 |
+
|
| 392 |
+
if isinstance(ele["video"], str):
|
| 393 |
+
video_reader_backend = get_video_reader_backend()
|
| 394 |
+
try:
|
| 395 |
+
video, sample_fps, timestamps = VIDEO_READER_BACKENDS[video_reader_backend](ele)
|
| 396 |
+
except Exception as e:
|
| 397 |
+
logger.warning(f"video_reader_backend {video_reader_backend} error, use torchvision as default, msg: {e}")
|
| 398 |
+
video, sample_fps, timestamps = VIDEO_READER_BACKENDS["torchvision"](ele)
|
| 399 |
+
|
| 400 |
+
nframes, _, height, width = video.shape
|
| 401 |
+
|
| 402 |
+
min_pixels = ele.get("min_pixels", VIDEO_MIN_PIXELS)
|
| 403 |
+
total_pixels = ele.get("total_pixels", VIDEO_TOTAL_PIXELS)
|
| 404 |
+
max_pixels = max(min(VIDEO_MAX_PIXELS, total_pixels / nframes * FRAME_FACTOR), int(min_pixels * 1.05))
|
| 405 |
+
max_pixels_supposed = ele.get("max_pixels", max_pixels)
|
| 406 |
+
if max_pixels_supposed > max_pixels:
|
| 407 |
+
logger.warning(f"The given max_pixels[{max_pixels_supposed}] exceeds limit[{max_pixels}].")
|
| 408 |
+
max_pixels = min(max_pixels_supposed, max_pixels)
|
| 409 |
+
if "resized_height" in ele and "resized_width" in ele:
|
| 410 |
+
resized_height, resized_width = smart_resize(
|
| 411 |
+
ele["resized_height"],
|
| 412 |
+
ele["resized_width"],
|
| 413 |
+
factor=image_factor,
|
| 414 |
+
)
|
| 415 |
+
else:
|
| 416 |
+
resized_height, resized_width = smart_resize(
|
| 417 |
+
height,
|
| 418 |
+
width,
|
| 419 |
+
factor=image_factor,
|
| 420 |
+
min_pixels=min_pixels,
|
| 421 |
+
max_pixels=max_pixels,
|
| 422 |
+
)
|
| 423 |
+
video = transforms.functional.resize(
|
| 424 |
+
video,
|
| 425 |
+
[resized_height, resized_width],
|
| 426 |
+
interpolation=InterpolationMode.BICUBIC,
|
| 427 |
+
antialias=True,
|
| 428 |
+
).float()
|
| 429 |
+
if return_video_sample_fps:
|
| 430 |
+
return video, sample_fps, timestamps
|
| 431 |
+
return video
|
| 432 |
+
|
| 433 |
+
else:
|
| 434 |
+
assert isinstance(ele["video"], (list, tuple))
|
| 435 |
+
process_info = ele.copy()
|
| 436 |
+
process_info.pop("type", None)
|
| 437 |
+
process_info.pop("video", None)
|
| 438 |
+
images = [
|
| 439 |
+
fetch_image({"image": video_element, **process_info}, size_factor=image_factor)
|
| 440 |
+
for video_element in ele["video"]
|
| 441 |
+
]
|
| 442 |
+
nframes = adjust_by_factor(len(images), FRAME_FACTOR, method='ceil')
|
| 443 |
+
if len(images) < nframes:
|
| 444 |
+
images.extend([images[-1]] * (nframes - len(images)))
|
| 445 |
+
|
| 446 |
+
timestamps = [-1 for i in range(nframes)] # not sure about this
|
| 447 |
+
if return_video_sample_fps:
|
| 448 |
+
return images, process_info.pop("fps", 2.0), timestamps
|
| 449 |
+
return images
|
| 450 |
+
|
| 451 |
+
class Eagle3_VLProcessorKwargs(ProcessingKwargs, total=False):
|
| 452 |
+
# see processing_utils.ProcessingKwargs documentation for usage.
|
| 453 |
+
_defaults = {
|
| 454 |
+
"text_kwargs": {
|
| 455 |
+
"padding": False,
|
| 456 |
+
},
|
| 457 |
+
"images_kwargs": {},
|
| 458 |
+
"videos_kwargs": {},
|
| 459 |
+
}
|
| 460 |
+
|
| 461 |
+
|
| 462 |
+
class Eagle3_VLProcessor(ProcessorMixin):
|
| 463 |
+
r"""
|
| 464 |
+
Constructs a Eagle3_VL processor which wraps a Eagle3_VL video processor, Eagle3_VL image processor and a Eagle3_VL tokenizer into a single processor.
|
| 465 |
+
[`Eagle3_VLProcessor`] offers all the functionalities of [`Eagle3_VLVideoProcessor`], [`Eagle3_VLImageProcessor`] and [`Eagle3_VLTokenizer`]. See the
|
| 466 |
+
[`~Eagle3_VLVideoProcessor.__call__`], [`~Eagle3_VLProcessor.__call__`] and [`~Eagle3_VLProcessor.decode`] for more information.
|
| 467 |
+
Args:
|
| 468 |
+
image_processor ([`LlavaOnevisionImageProcessor`], *optional*):
|
| 469 |
+
The image processor is a required input.
|
| 470 |
+
tokenizer ([`LlamaTokenizerFast`], *optional*):
|
| 471 |
+
The tokenizer is a required input.
|
| 472 |
+
num_image_tokens (`int`, *optional*):
|
| 473 |
+
Number of image tokens for one imagethat will be returned by vision tower.
|
| 474 |
+
vision_feature_select_strategy (`str`, *optional*):
|
| 475 |
+
The feature selection strategy used to select the vision feature from the vision backbone.
|
| 476 |
+
Shoudl be same as in model's config
|
| 477 |
+
chat_template (`str`, *optional*): A Jinja template which will be used to convert lists of messages
|
| 478 |
+
in a chat into a tokenizable string.
|
| 479 |
+
image_token (`str`, *optional*, defaults to `"<image>"`):
|
| 480 |
+
Special token used to denote image location.
|
| 481 |
+
video_token (`str`, *optional*, defaults to `"<video>"`):
|
| 482 |
+
Special token used to denote video location.
|
| 483 |
+
"""
|
| 484 |
+
|
| 485 |
+
attributes = ["image_processor", "tokenizer"]
|
| 486 |
+
valid_kwargs = [
|
| 487 |
+
"chat_template",
|
| 488 |
+
"num_image_tokens",
|
| 489 |
+
"vision_feature_select_strategy",
|
| 490 |
+
"image_token",
|
| 491 |
+
"video_token",
|
| 492 |
+
"images_kwargs",
|
| 493 |
+
"videos_kwargs",
|
| 494 |
+
"text_kwargs",
|
| 495 |
+
]
|
| 496 |
+
image_processor_class = "AutoImageProcessor"
|
| 497 |
+
tokenizer_class = "AutoTokenizer"
|
| 498 |
+
|
| 499 |
+
def __init__(
|
| 500 |
+
self,
|
| 501 |
+
image_processor=None,
|
| 502 |
+
tokenizer=None,
|
| 503 |
+
vision_feature_select_strategy=None,
|
| 504 |
+
chat_template=None,
|
| 505 |
+
image_token='<IMG_CONTEXT>',
|
| 506 |
+
video_token='<IMG_CONTEXT>',
|
| 507 |
+
pixels_per_token=28*28,
|
| 508 |
+
image_placeholder='image',
|
| 509 |
+
video_placeholder='video',
|
| 510 |
+
image_start_token='<img>',
|
| 511 |
+
image_end_token='</img>',
|
| 512 |
+
**kwargs,
|
| 513 |
+
):
|
| 514 |
+
self.vision_feature_select_strategy = vision_feature_select_strategy
|
| 515 |
+
self.image_token = tokenizer.image_token if hasattr(tokenizer, "image_token") else image_token
|
| 516 |
+
self.video_token = tokenizer.video_token if hasattr(tokenizer, "video_token") else video_token
|
| 517 |
+
self.image_token_id = (
|
| 518 |
+
tokenizer.image_token_id
|
| 519 |
+
if getattr(tokenizer, "image_token_id", None)
|
| 520 |
+
else tokenizer.convert_tokens_to_ids(self.image_token)
|
| 521 |
+
)
|
| 522 |
+
self.video_token_id = (
|
| 523 |
+
tokenizer.video_token_id
|
| 524 |
+
if getattr(tokenizer, "video_token_id", None)
|
| 525 |
+
else tokenizer.convert_tokens_to_ids(self.video_token)
|
| 526 |
+
)
|
| 527 |
+
self.image_placeholder = image_placeholder
|
| 528 |
+
self.video_placeholder = video_placeholder
|
| 529 |
+
self.pixels_per_token = pixels_per_token
|
| 530 |
+
self.image_start_token = image_start_token
|
| 531 |
+
self.image_end_token = image_end_token
|
| 532 |
+
if 'auto_map' in kwargs:
|
| 533 |
+
self.auto_map = kwargs['auto_map']
|
| 534 |
+
super().__init__(image_processor, tokenizer, chat_template=chat_template)
|
| 535 |
+
|
| 536 |
+
|
| 537 |
+
def replace_media_placeholder(self, text, image_list, video_list, timestamps_list, fps_list, **output_kwargs):
|
| 538 |
+
|
| 539 |
+
num_of_images_in_this_sample = 0
|
| 540 |
+
num_of_videos_in_this_sample = 0
|
| 541 |
+
# Regular expression pattern to match formats like <image-1> or <video-2>
|
| 542 |
+
pattern = re.compile(rf"<({self.image_placeholder}|{self.video_placeholder})-(\d+)>")
|
| 543 |
+
unified_frame_list = []
|
| 544 |
+
|
| 545 |
+
# Function to replace tags in a single text
|
| 546 |
+
def replace_in_text(text):
|
| 547 |
+
# repl callback function for each match replacement operation
|
| 548 |
+
def repl(match):
|
| 549 |
+
nonlocal unified_frame_list
|
| 550 |
+
nonlocal num_of_images_in_this_sample
|
| 551 |
+
nonlocal num_of_videos_in_this_sample
|
| 552 |
+
media_type = match.group(1) # 'image' or 'video'
|
| 553 |
+
idx_in_list = int(match.group(2)) - 1 # Convert to list index (0-based)
|
| 554 |
+
# Select the corresponding path based on media type
|
| 555 |
+
idx_mapper = {0: "first", 1: "second", 2: "third", 3: "fourth", 4: "fifth", 5: "sixth", 6: "seventh", 7: "eighth", 8: "ninth", 9: "tenth"}
|
| 556 |
+
if media_type == 'image':
|
| 557 |
+
image_inputs = self.image_processor(images=[image_list[idx_in_list]], videos=None, **output_kwargs["images_kwargs"])
|
| 558 |
+
image_height, image_width = image_inputs['image_sizes'][0]
|
| 559 |
+
assert image_height <= IMAGE_MAX_SIZE and image_width <= IMAGE_MAX_SIZE, f"image_height: {image_height}, image_width: {image_width}"
|
| 560 |
+
image_tokens = image_height * image_width // self.pixels_per_token
|
| 561 |
+
special_placeholder = f"<image {idx_in_list+1}>{self.image_start_token}{self.image_token * image_tokens}{self.image_end_token}"
|
| 562 |
+
unified_frame_list.append(image_inputs)
|
| 563 |
+
num_of_images_in_this_sample += 1
|
| 564 |
+
|
| 565 |
+
elif media_type == 'video':
|
| 566 |
+
|
| 567 |
+
video_inputs = self.image_processor(images=None, videos=video_list[idx_in_list], **output_kwargs["videos_kwargs"])
|
| 568 |
+
N, C, image_height, image_width = video_inputs['pixel_values'].shape
|
| 569 |
+
image_tokens = image_height * image_width // self.pixels_per_token
|
| 570 |
+
|
| 571 |
+
assert image_height <= IMAGE_MAX_SIZE and image_width <= IMAGE_MAX_SIZE, f"image_height: {image_height}, image_width: {image_width}"
|
| 572 |
+
|
| 573 |
+
if timestamps_list is not None and -1 not in timestamps_list:
|
| 574 |
+
frame_timestamps = timestamps_list[idx_in_list]
|
| 575 |
+
else:
|
| 576 |
+
frame_timestamps = None
|
| 577 |
+
sampled_fps = fps_list[idx_in_list] if fps_list is not None else None
|
| 578 |
+
|
| 579 |
+
num_of_tokens_list = [image_tokens] * N
|
| 580 |
+
|
| 581 |
+
if frame_timestamps is not None:
|
| 582 |
+
assert len(frame_timestamps) == len(num_of_tokens_list), f"The number of timestamps is not equal to the number of frames: {len(frame_timestamps)} != {len(num_of_tokens_list)}"
|
| 583 |
+
special_placeholder = [f"Frame {i+1} sample at {frame_timestamps[i]:.2f}s: {self.image_start_token}{self.image_token * num_of_tokens}{self.image_end_token}" for i, num_of_tokens in enumerate(num_of_tokens_list)]
|
| 584 |
+
else:
|
| 585 |
+
special_placeholder = [f"Frame {i+1}: {self.image_start_token}{self.image_token * num_of_tokens}{self.image_end_token}" for i, num_of_tokens in enumerate(num_of_tokens_list)]
|
| 586 |
+
|
| 587 |
+
if sampled_fps is not None:
|
| 588 |
+
special_placeholder = f"The {idx_mapper[idx_in_list]} video sampled with {sampled_fps:.2f} fps: " + "".join(special_placeholder)
|
| 589 |
+
else:
|
| 590 |
+
special_placeholder = f"The {idx_mapper[idx_in_list]} video: " + "".join(special_placeholder)
|
| 591 |
+
unified_frame_list.append(video_inputs)
|
| 592 |
+
num_of_videos_in_this_sample += 1
|
| 593 |
+
else:
|
| 594 |
+
raise ValueError(f'Unknown media type: {media_type}')
|
| 595 |
+
return special_placeholder
|
| 596 |
+
return pattern.sub(repl, text)
|
| 597 |
+
text = replace_in_text(text)
|
| 598 |
+
if len(unified_frame_list) > 0:
|
| 599 |
+
pixel_values = [frame['pixel_values'] for frame in unified_frame_list]
|
| 600 |
+
image_sizes = torch.cat([frame['image_sizes'] for frame in unified_frame_list], dim=0)
|
| 601 |
+
else:
|
| 602 |
+
pixel_values = []
|
| 603 |
+
image_sizes = []
|
| 604 |
+
return text, pixel_values, image_sizes, num_of_images_in_this_sample, num_of_videos_in_this_sample
|
| 605 |
+
|
| 606 |
+
def __call__(
|
| 607 |
+
self,
|
| 608 |
+
images: ImageInput = None,
|
| 609 |
+
text: Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None,
|
| 610 |
+
audio=None,
|
| 611 |
+
videos: VideoInput = None,
|
| 612 |
+
**kwargs: Unpack[Eagle3_VLProcessorKwargs],
|
| 613 |
+
) -> BatchFeature:
|
| 614 |
+
"""
|
| 615 |
+
Main method to prepare for the model one or several sequences(s) and image(s). This method forwards the `text`
|
| 616 |
+
and `kwargs` arguments to LlamaTokenizerFast's [`~LlamaTokenizerFast.__call__`] if `text` is not `None` to encode
|
| 617 |
+
the text. To prepare the image(s), this method forwards the `images` and `kwrags` arguments to
|
| 618 |
+
LlavaNextImageProcessor's [`~LlavaNextImageProcessor.__call__`] if `images` is not `None`. Please refer to the docstring
|
| 619 |
+
of the above two methods for more information.
|
| 620 |
+
Args:
|
| 621 |
+
images (`PIL.Image.Image`, `np.ndarray`, `torch.Tensor`, `List[PIL.Image.Image]`, `List[np.ndarray]`, `List[torch.Tensor]`):
|
| 622 |
+
The image or batch of images to be prepared. Each image can be a PIL image, NumPy array or PyTorch
|
| 623 |
+
tensor. Both channels-first and channels-last formats are supported.
|
| 624 |
+
text (`str`, `List[str]`, `List[List[str]]`):
|
| 625 |
+
The sequence or batch of sequences to be encoded. Each sequence can be a string or a list of strings
|
| 626 |
+
(pretokenized string). If the sequences are provided as list of strings (pretokenized), you must set
|
| 627 |
+
`is_split_into_words=True` (to lift the ambiguity with a batch of sequences).
|
| 628 |
+
videos (`np.ndarray`, `torch.Tensor`, `List[np.ndarray]`, `List[torch.Tensor]`):
|
| 629 |
+
The image or batch of videos to be prepared. Each video can be a 4D NumPy array or PyTorch
|
| 630 |
+
Returns:
|
| 631 |
+
[`BatchFeature`]: A [`BatchFeature`] with the following fields:
|
| 632 |
+
- **input_ids** -- List of token ids to be fed to a model. Returned when `text` is not `None`.
|
| 633 |
+
- **attention_mask** -- List of indices specifying which tokens should be attended to by the model (when
|
| 634 |
+
`return_attention_mask=True` or if *"attention_mask"* is in `self.model_input_names` and if `text` is not
|
| 635 |
+
`None`).
|
| 636 |
+
- **pixel_values** -- Pixel values to be fed to a model. Returned when `images` is not `None`.
|
| 637 |
+
- **pixel_values_videos** -- Pixel values of a video input to be fed to a model. Returned when `videos` is not `None`.
|
| 638 |
+
- **image_sizes** -- Size of each image that will be used to unpad an image. Returned when `images` is not `None`.
|
| 639 |
+
"""
|
| 640 |
+
|
| 641 |
+
|
| 642 |
+
output_kwargs = self._merge_kwargs(
|
| 643 |
+
Eagle3_VLProcessorKwargs,
|
| 644 |
+
tokenizer_init_kwargs=self.tokenizer.init_kwargs,
|
| 645 |
+
**kwargs,
|
| 646 |
+
)
|
| 647 |
+
|
| 648 |
+
if isinstance(text, str):
|
| 649 |
+
text_list = [text]
|
| 650 |
+
elif not isinstance(text, list) and not isinstance(text[0], str):
|
| 651 |
+
raise ValueError("Invalid input text. Please provide a string, or a list of strings")
|
| 652 |
+
elif isinstance(text, list) and isinstance(text[0], str):
|
| 653 |
+
text_list = text
|
| 654 |
+
|
| 655 |
+
if images is None: images = []
|
| 656 |
+
if videos is None: videos = []
|
| 657 |
+
|
| 658 |
+
pixel_values_list = []
|
| 659 |
+
image_sizes_list = []
|
| 660 |
+
new_sample_list = []
|
| 661 |
+
image_start_idx = 0
|
| 662 |
+
video_start_idx = 0
|
| 663 |
+
timestamps_batch = output_kwargs['videos_kwargs'].pop("timestamps", None)
|
| 664 |
+
fps_batch = output_kwargs['videos_kwargs'].pop("fps", None)
|
| 665 |
+
for sample in text_list:
|
| 666 |
+
timestamps_list = timestamps_batch[video_start_idx:] if timestamps_batch is not None else None
|
| 667 |
+
fps_list = fps_batch[video_start_idx:] if fps_batch is not None else None
|
| 668 |
+
sample, pixel_values, image_sizes, num_of_images_in_this_sample, num_of_videos_in_this_sample = self.replace_media_placeholder(sample, images[image_start_idx:], videos[video_start_idx:], timestamps_list, fps_list, **output_kwargs)
|
| 669 |
+
new_sample_list.append(sample)
|
| 670 |
+
pixel_values_list.extend(pixel_values)
|
| 671 |
+
image_sizes_list.extend(image_sizes)
|
| 672 |
+
|
| 673 |
+
image_start_idx += num_of_images_in_this_sample
|
| 674 |
+
video_start_idx += num_of_videos_in_this_sample
|
| 675 |
+
|
| 676 |
+
if len(pixel_values) > 0:
|
| 677 |
+
image_inputs = {
|
| 678 |
+
'pixel_values':pixel_values_list,
|
| 679 |
+
'image_sizes': torch.stack(image_sizes_list, dim=0)
|
| 680 |
+
}
|
| 681 |
+
else:
|
| 682 |
+
image_inputs = {}
|
| 683 |
+
video_inputs = {}
|
| 684 |
+
text_inputs = self.tokenizer(new_sample_list, **output_kwargs["text_kwargs"])
|
| 685 |
+
return BatchFeature(data={**text_inputs, **image_inputs, **video_inputs})
|
| 686 |
+
|
| 687 |
+
# Copied from transformers.models.clip.processing_clip.CLIPProcessor.batch_decode with CLIP->Llama
|
| 688 |
+
def batch_decode(self, *args, **kwargs):
|
| 689 |
+
"""
|
| 690 |
+
This method forwards all its arguments to LlamaTokenizerFast's [`~PreTrainedTokenizer.batch_decode`]. Please
|
| 691 |
+
refer to the docstring of this method for more information.
|
| 692 |
+
"""
|
| 693 |
+
return self.tokenizer.batch_decode(*args, **kwargs)
|
| 694 |
+
|
| 695 |
+
# Copied from transformers.models.clip.processing_clip.CLIPProcessor.decode with CLIP->Llama
|
| 696 |
+
def decode(self, *args, **kwargs):
|
| 697 |
+
"""
|
| 698 |
+
This method forwards all its arguments to LlamaTokenizerFast's [`~PreTrainedTokenizer.decode`]. Please refer to
|
| 699 |
+
the docstring of this method for more information.
|
| 700 |
+
"""
|
| 701 |
+
return self.tokenizer.decode(*args, **kwargs)
|
| 702 |
+
|
| 703 |
+
@property
|
| 704 |
+
# Copied from transformers.models.clip.processing_clip.CLIPProcessor.model_input_names
|
| 705 |
+
def model_input_names(self):
|
| 706 |
+
tokenizer_input_names = self.tokenizer.model_input_names
|
| 707 |
+
image_processor_input_names = self.image_processor.model_input_names
|
| 708 |
+
return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names))
|
| 709 |
+
|
| 710 |
+
# override to save video-config in a separate config file
|
| 711 |
+
def save_pretrained(self, save_directory, **kwargs):
|
| 712 |
+
if os.path.isfile(save_directory):
|
| 713 |
+
raise ValueError(f"Provided path ({save_directory}) should be a directory, not a file")
|
| 714 |
+
os.makedirs(save_directory, exist_ok=True)
|
| 715 |
+
|
| 716 |
+
outputs = super().save_pretrained(save_directory, **kwargs)
|
| 717 |
+
return outputs
|
| 718 |
+
|
| 719 |
+
# override to load video-config from a separate config file
|
| 720 |
+
@classmethod
|
| 721 |
+
def from_pretrained(cls, pretrained_model_name_or_path, **kwargs):
|
| 722 |
+
processor = super().from_pretrained(pretrained_model_name_or_path, **kwargs)
|
| 723 |
+
|
| 724 |
+
# if return_unused_kwargs a tuple is returned where the second element is 'unused_kwargs'
|
| 725 |
+
if isinstance(processor, tuple):
|
| 726 |
+
processor = processor[0]
|
| 727 |
+
return processor
|
| 728 |
+
|
| 729 |
+
# Copy from https://github.com/QwenLM/Qwen2.5-VL/blob/main/qwen-vl-utils/src/qwen_vl_utils/vision_process.py
|
| 730 |
+
def process_vision_info(
|
| 731 |
+
self,
|
| 732 |
+
conversations: list[dict] | list[list[dict]],
|
| 733 |
+
return_video_kwargs: bool = False,
|
| 734 |
+
) -> tuple[list[Image.Image] | None, list[torch.Tensor | list[Image.Image]] | None, Optional[dict]]:
|
| 735 |
+
|
| 736 |
+
vision_infos = self.extract_vision_info(conversations)
|
| 737 |
+
## Read images or videos
|
| 738 |
+
image_inputs = []
|
| 739 |
+
video_inputs = []
|
| 740 |
+
video_sample_fps_list = []
|
| 741 |
+
video_timestamps_list = []
|
| 742 |
+
for vision_info in vision_infos:
|
| 743 |
+
if "image" in vision_info or "image_url" in vision_info:
|
| 744 |
+
image_inputs.append(fetch_image(vision_info))
|
| 745 |
+
elif "video" in vision_info:
|
| 746 |
+
video_input, video_sample_fps, video_timestamps = fetch_video(vision_info, return_video_sample_fps=True)
|
| 747 |
+
video_sample_fps_list.append(video_sample_fps)
|
| 748 |
+
video_inputs.append(video_input)
|
| 749 |
+
video_timestamps_list.append(video_timestamps)
|
| 750 |
+
else:
|
| 751 |
+
raise ValueError("image, image_url or video should in content.")
|
| 752 |
+
if len(image_inputs) == 0:
|
| 753 |
+
image_inputs = None
|
| 754 |
+
if len(video_inputs) == 0:
|
| 755 |
+
video_inputs = None
|
| 756 |
+
if return_video_kwargs:
|
| 757 |
+
return image_inputs, video_inputs, {'fps': video_sample_fps_list, 'timestamps': video_timestamps_list}
|
| 758 |
+
return image_inputs, video_inputs
|
| 759 |
+
|
| 760 |
+
def extract_vision_info(self, conversations: list[dict] | list[list[dict]]) -> list[dict]:
|
| 761 |
+
vision_infos = []
|
| 762 |
+
if isinstance(conversations[0], dict):
|
| 763 |
+
conversations = [conversations]
|
| 764 |
+
for conversation in conversations:
|
| 765 |
+
for message in conversation:
|
| 766 |
+
if isinstance(message["content"], list):
|
| 767 |
+
for ele in message["content"]:
|
| 768 |
+
if (
|
| 769 |
+
"image" in ele
|
| 770 |
+
or "image_url" in ele
|
| 771 |
+
or "video" in ele
|
| 772 |
+
or ele["type"] in ("image", "image_url", "video")
|
| 773 |
+
):
|
| 774 |
+
vision_infos.append(ele)
|
| 775 |
+
return vision_infos
|
| 776 |
+
|
| 777 |
+
def py_apply_chat_template(self, messages, tokenize=False, add_generation_prompt=False):
|
| 778 |
+
"""
|
| 779 |
+
Renders a chat conversation using a custom template with verification of tokens.
|
| 780 |
+
The purpose is to check for the existence of tokens like "<image-1>" or "<video-1>"
|
| 781 |
+
in the message text and skip adding them if they already exist.
|
| 782 |
+
Args:
|
| 783 |
+
messages (list): A list of message dictionaries. Each message should contain:
|
| 784 |
+
- 'role': The role of the speaker (e.g., 'system', 'user', 'assistant').
|
| 785 |
+
- 'content': Either a string or a list of content blocks. In the list each block may contain:
|
| 786 |
+
* 'type': The type of content, such as 'image' or 'video'.
|
| 787 |
+
* 'text': The actual text if present.
|
| 788 |
+
* Other keys such as 'image', 'image_url', or 'video'.
|
| 789 |
+
add_generation_prompt (bool): If True, appends "<|im_start|>assistant" at the end of the rendered string.
|
| 790 |
+
tokenize (bool): If True, tokenize the rendered string.
|
| 791 |
+
Returns:
|
| 792 |
+
str: The final rendered chat string according to the specified template.
|
| 793 |
+
"""
|
| 794 |
+
assert tokenize == False, "tokenize is not supported yet"
|
| 795 |
+
result = ""
|
| 796 |
+
image_count = 0
|
| 797 |
+
video_count = 0
|
| 798 |
+
|
| 799 |
+
message_text = ""
|
| 800 |
+
for idx, message in enumerate(messages):
|
| 801 |
+
if message.get('role') != 'user': continue
|
| 802 |
+
# If content is a string, simply output it.
|
| 803 |
+
content = message.get('content')
|
| 804 |
+
if isinstance(content, str):
|
| 805 |
+
message_text += content
|
| 806 |
+
elif isinstance(content, list):
|
| 807 |
+
# Process each content item.
|
| 808 |
+
for item in content:
|
| 809 |
+
# If the block is a dictionary and contains text, add it to message_text.
|
| 810 |
+
if isinstance(item, dict) and "text" in item:
|
| 811 |
+
message_text += item["text"]
|
| 812 |
+
# If an item is already a string in the list, add it directly.
|
| 813 |
+
elif isinstance(item, str):
|
| 814 |
+
message_text += item
|
| 815 |
+
|
| 816 |
+
for idx, message in enumerate(messages):
|
| 817 |
+
# If the first message is not from the system, prepend a default system message.
|
| 818 |
+
if idx == 0 and message.get('role') != 'system':
|
| 819 |
+
result += "<|im_start|>system\n"
|
| 820 |
+
result += "You are a helpful assistant.\n"
|
| 821 |
+
result += "<|im_end|>\n"
|
| 822 |
+
|
| 823 |
+
# Start the current message block with its role.
|
| 824 |
+
result += f"<|im_start|>{message.get('role', '')}\n"
|
| 825 |
+
content = message.get('content')
|
| 826 |
+
|
| 827 |
+
# If content is a string, simply output it.
|
| 828 |
+
if isinstance(content, str):
|
| 829 |
+
result += content
|
| 830 |
+
result += "<|im_end|>\n"
|
| 831 |
+
else:
|
| 832 |
+
# Process each content item.
|
| 833 |
+
for item in content:
|
| 834 |
+
# Check if the item is an image (explicitly by type or by key presence).
|
| 835 |
+
if (isinstance(item, dict) and (item.get('type') == 'image' or 'image' in item or 'image_url' in item)):
|
| 836 |
+
image_count += 1
|
| 837 |
+
candidate_token = f"<image-{image_count}>"
|
| 838 |
+
# Only add the token if it is not already present in the collected text.
|
| 839 |
+
if candidate_token not in message_text:
|
| 840 |
+
result += candidate_token
|
| 841 |
+
# Check if the item is a video.
|
| 842 |
+
elif (isinstance(item, dict) and (item.get('type') == 'video' or 'video' in item)):
|
| 843 |
+
video_count += 1
|
| 844 |
+
candidate_token = f"<video-{video_count}>"
|
| 845 |
+
# Only add the token if it is not already present.
|
| 846 |
+
if candidate_token not in message_text:
|
| 847 |
+
result += candidate_token
|
| 848 |
+
# If the item contains text, add it.
|
| 849 |
+
elif isinstance(item, dict) and 'text' in item:
|
| 850 |
+
result += item['text']
|
| 851 |
+
# If the item is a string (and not handled already), add it.
|
| 852 |
+
elif isinstance(item, str):
|
| 853 |
+
result += item
|
| 854 |
+
result += "<|im_end|>\n"
|
| 855 |
+
|
| 856 |
+
# Optionally add assistant generation prompt at the end.
|
| 857 |
+
if add_generation_prompt:
|
| 858 |
+
result += "<|im_start|>assistant\n"
|
| 859 |
+
|
| 860 |
+
return result
|
| 861 |
+
|
| 862 |
+
|
| 863 |
+
@classmethod
|
| 864 |
+
def from_args_and_dict(cls, args, processor_dict: dict[str, Any], **kwargs):
|
| 865 |
+
"""
|
| 866 |
+
Instantiates a type of [`~processing_utils.ProcessingMixin`] from a Python dictionary of parameters.
|
| 867 |
+
Args:
|
| 868 |
+
processor_dict (`Dict[str, Any]`):
|
| 869 |
+
Dictionary that will be used to instantiate the processor object. Such a dictionary can be
|
| 870 |
+
retrieved from a pretrained checkpoint by leveraging the
|
| 871 |
+
[`~processing_utils.ProcessingMixin.to_dict`] method.
|
| 872 |
+
kwargs (`Dict[str, Any]`):
|
| 873 |
+
Additional parameters from which to initialize the processor object.
|
| 874 |
+
Returns:
|
| 875 |
+
[`~processing_utils.ProcessingMixin`]: The processor object instantiated from those
|
| 876 |
+
parameters.
|
| 877 |
+
"""
|
| 878 |
+
processor_dict = processor_dict.copy()
|
| 879 |
+
return_unused_kwargs = kwargs.pop("return_unused_kwargs", False)
|
| 880 |
+
|
| 881 |
+
# We have to pop up some unused (but specific) kwargs and then validate that it doesn't contain unused kwargs
|
| 882 |
+
# If we don't pop, some specific kwargs will raise a warning
|
| 883 |
+
if "processor_class" in processor_dict:
|
| 884 |
+
del processor_dict["processor_class"]
|
| 885 |
+
|
| 886 |
+
#if "auto_map" in processor_dict:
|
| 887 |
+
# del processor_dict["auto_map"]
|
| 888 |
+
|
| 889 |
+
unused_kwargs = cls.validate_init_kwargs(processor_config=processor_dict, valid_kwargs=cls.valid_kwargs)
|
| 890 |
+
processor = cls(*args, **processor_dict)
|
| 891 |
+
|
| 892 |
+
# Update processor with kwargs if needed
|
| 893 |
+
for key in set(kwargs.keys()):
|
| 894 |
+
if hasattr(processor, key):
|
| 895 |
+
setattr(processor, key, kwargs.pop(key))
|
| 896 |
+
|
| 897 |
+
kwargs.update(unused_kwargs)
|
| 898 |
+
logger.info(f"Processor {processor}")
|
| 899 |
+
if return_unused_kwargs:
|
| 900 |
+
return processor, kwargs
|
| 901 |
+
else:
|
| 902 |
+
return processor
|
| 903 |
+
|
| 904 |
+
|
| 905 |
+
__all__ = ["Eagle3_VLProcessor"]
|
processor_config.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"auto_map": {
|
| 3 |
+
"AutoProcessor": "processing_eagle3_vl.Eagle3_VLProcessor"
|
| 4 |
+
},
|
| 5 |
+
"image_end_token": "</img>",
|
| 6 |
+
"image_placeholder": "image",
|
| 7 |
+
"image_start_token": "<img>",
|
| 8 |
+
"image_token": "<IMG_CONTEXT>",
|
| 9 |
+
"pixels_per_token": 784,
|
| 10 |
+
"processor_class": "Eagle3_VLProcessor",
|
| 11 |
+
"video_placeholder": "video",
|
| 12 |
+
"video_token": "<IMG_CONTEXT>",
|
| 13 |
+
"vision_feature_select_strategy": null
|
| 14 |
+
}
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
"<IMG_CONTEXT>",
|
| 17 |
+
"<img>",
|
| 18 |
+
"</img>",
|
| 19 |
+
"<box>",
|
| 20 |
+
"</box>",
|
| 21 |
+
"<quad>",
|
| 22 |
+
"</quad>",
|
| 23 |
+
"<ref>",
|
| 24 |
+
"</ref>",
|
| 25 |
+
"<interval>",
|
| 26 |
+
"</interval>"
|
| 27 |
+
],
|
| 28 |
+
"eos_token": {
|
| 29 |
+
"content": "<|im_end|>",
|
| 30 |
+
"lstrip": false,
|
| 31 |
+
"normalized": false,
|
| 32 |
+
"rstrip": false,
|
| 33 |
+
"single_word": false
|
| 34 |
+
},
|
| 35 |
+
"pad_token": {
|
| 36 |
+
"content": "<|endoftext|>",
|
| 37 |
+
"lstrip": false,
|
| 38 |
+
"normalized": false,
|
| 39 |
+
"rstrip": false,
|
| 40 |
+
"single_word": false
|
| 41 |
+
}
|
| 42 |
+
}
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,344 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_bos_token": false,
|
| 3 |
+
"add_eos_token": false,
|
| 4 |
+
"add_prefix_space": false,
|
| 5 |
+
"added_tokens_decoder": {
|
| 6 |
+
"151643": {
|
| 7 |
+
"content": "<|endoftext|>",
|
| 8 |
+
"lstrip": false,
|
| 9 |
+
"normalized": false,
|
| 10 |
+
"rstrip": false,
|
| 11 |
+
"single_word": false,
|
| 12 |
+
"special": true
|
| 13 |
+
},
|
| 14 |
+
"151644": {
|
| 15 |
+
"content": "<|im_start|>",
|
| 16 |
+
"lstrip": false,
|
| 17 |
+
"normalized": false,
|
| 18 |
+
"rstrip": false,
|
| 19 |
+
"single_word": false,
|
| 20 |
+
"special": true
|
| 21 |
+
},
|
| 22 |
+
"151645": {
|
| 23 |
+
"content": "<|im_end|>",
|
| 24 |
+
"lstrip": false,
|
| 25 |
+
"normalized": false,
|
| 26 |
+
"rstrip": false,
|
| 27 |
+
"single_word": false,
|
| 28 |
+
"special": true
|
| 29 |
+
},
|
| 30 |
+
"151646": {
|
| 31 |
+
"content": "<|object_ref_start|>",
|
| 32 |
+
"lstrip": false,
|
| 33 |
+
"normalized": false,
|
| 34 |
+
"rstrip": false,
|
| 35 |
+
"single_word": false,
|
| 36 |
+
"special": true
|
| 37 |
+
},
|
| 38 |
+
"151647": {
|
| 39 |
+
"content": "<|object_ref_end|>",
|
| 40 |
+
"lstrip": false,
|
| 41 |
+
"normalized": false,
|
| 42 |
+
"rstrip": false,
|
| 43 |
+
"single_word": false,
|
| 44 |
+
"special": true
|
| 45 |
+
},
|
| 46 |
+
"151648": {
|
| 47 |
+
"content": "<|box_start|>",
|
| 48 |
+
"lstrip": false,
|
| 49 |
+
"normalized": false,
|
| 50 |
+
"rstrip": false,
|
| 51 |
+
"single_word": false,
|
| 52 |
+
"special": true
|
| 53 |
+
},
|
| 54 |
+
"151649": {
|
| 55 |
+
"content": "<|box_end|>",
|
| 56 |
+
"lstrip": false,
|
| 57 |
+
"normalized": false,
|
| 58 |
+
"rstrip": false,
|
| 59 |
+
"single_word": false,
|
| 60 |
+
"special": true
|
| 61 |
+
},
|
| 62 |
+
"151650": {
|
| 63 |
+
"content": "<|quad_start|>",
|
| 64 |
+
"lstrip": false,
|
| 65 |
+
"normalized": false,
|
| 66 |
+
"rstrip": false,
|
| 67 |
+
"single_word": false,
|
| 68 |
+
"special": true
|
| 69 |
+
},
|
| 70 |
+
"151651": {
|
| 71 |
+
"content": "<|quad_end|>",
|
| 72 |
+
"lstrip": false,
|
| 73 |
+
"normalized": false,
|
| 74 |
+
"rstrip": false,
|
| 75 |
+
"single_word": false,
|
| 76 |
+
"special": true
|
| 77 |
+
},
|
| 78 |
+
"151652": {
|
| 79 |
+
"content": "<|vision_start|>",
|
| 80 |
+
"lstrip": false,
|
| 81 |
+
"normalized": false,
|
| 82 |
+
"rstrip": false,
|
| 83 |
+
"single_word": false,
|
| 84 |
+
"special": true
|
| 85 |
+
},
|
| 86 |
+
"151653": {
|
| 87 |
+
"content": "<|vision_end|>",
|
| 88 |
+
"lstrip": false,
|
| 89 |
+
"normalized": false,
|
| 90 |
+
"rstrip": false,
|
| 91 |
+
"single_word": false,
|
| 92 |
+
"special": true
|
| 93 |
+
},
|
| 94 |
+
"151654": {
|
| 95 |
+
"content": "<|vision_pad|>",
|
| 96 |
+
"lstrip": false,
|
| 97 |
+
"normalized": false,
|
| 98 |
+
"rstrip": false,
|
| 99 |
+
"single_word": false,
|
| 100 |
+
"special": true
|
| 101 |
+
},
|
| 102 |
+
"151655": {
|
| 103 |
+
"content": "<|image_pad|>",
|
| 104 |
+
"lstrip": false,
|
| 105 |
+
"normalized": false,
|
| 106 |
+
"rstrip": false,
|
| 107 |
+
"single_word": false,
|
| 108 |
+
"special": true
|
| 109 |
+
},
|
| 110 |
+
"151656": {
|
| 111 |
+
"content": "<|video_pad|>",
|
| 112 |
+
"lstrip": false,
|
| 113 |
+
"normalized": false,
|
| 114 |
+
"rstrip": false,
|
| 115 |
+
"single_word": false,
|
| 116 |
+
"special": true
|
| 117 |
+
},
|
| 118 |
+
"151657": {
|
| 119 |
+
"content": "<tool_call>",
|
| 120 |
+
"lstrip": false,
|
| 121 |
+
"normalized": false,
|
| 122 |
+
"rstrip": false,
|
| 123 |
+
"single_word": false,
|
| 124 |
+
"special": false
|
| 125 |
+
},
|
| 126 |
+
"151658": {
|
| 127 |
+
"content": "</tool_call>",
|
| 128 |
+
"lstrip": false,
|
| 129 |
+
"normalized": false,
|
| 130 |
+
"rstrip": false,
|
| 131 |
+
"single_word": false,
|
| 132 |
+
"special": false
|
| 133 |
+
},
|
| 134 |
+
"151659": {
|
| 135 |
+
"content": "<|fim_prefix|>",
|
| 136 |
+
"lstrip": false,
|
| 137 |
+
"normalized": false,
|
| 138 |
+
"rstrip": false,
|
| 139 |
+
"single_word": false,
|
| 140 |
+
"special": false
|
| 141 |
+
},
|
| 142 |
+
"151660": {
|
| 143 |
+
"content": "<|fim_middle|>",
|
| 144 |
+
"lstrip": false,
|
| 145 |
+
"normalized": false,
|
| 146 |
+
"rstrip": false,
|
| 147 |
+
"single_word": false,
|
| 148 |
+
"special": false
|
| 149 |
+
},
|
| 150 |
+
"151661": {
|
| 151 |
+
"content": "<|fim_suffix|>",
|
| 152 |
+
"lstrip": false,
|
| 153 |
+
"normalized": false,
|
| 154 |
+
"rstrip": false,
|
| 155 |
+
"single_word": false,
|
| 156 |
+
"special": false
|
| 157 |
+
},
|
| 158 |
+
"151662": {
|
| 159 |
+
"content": "<|fim_pad|>",
|
| 160 |
+
"lstrip": false,
|
| 161 |
+
"normalized": false,
|
| 162 |
+
"rstrip": false,
|
| 163 |
+
"single_word": false,
|
| 164 |
+
"special": false
|
| 165 |
+
},
|
| 166 |
+
"151663": {
|
| 167 |
+
"content": "<|repo_name|>",
|
| 168 |
+
"lstrip": false,
|
| 169 |
+
"normalized": false,
|
| 170 |
+
"rstrip": false,
|
| 171 |
+
"single_word": false,
|
| 172 |
+
"special": false
|
| 173 |
+
},
|
| 174 |
+
"151664": {
|
| 175 |
+
"content": "<|file_sep|>",
|
| 176 |
+
"lstrip": false,
|
| 177 |
+
"normalized": false,
|
| 178 |
+
"rstrip": false,
|
| 179 |
+
"single_word": false,
|
| 180 |
+
"special": false
|
| 181 |
+
},
|
| 182 |
+
"151665": {
|
| 183 |
+
"content": "<tool_response>",
|
| 184 |
+
"lstrip": false,
|
| 185 |
+
"normalized": false,
|
| 186 |
+
"rstrip": false,
|
| 187 |
+
"single_word": false,
|
| 188 |
+
"special": false
|
| 189 |
+
},
|
| 190 |
+
"151666": {
|
| 191 |
+
"content": "</tool_response>",
|
| 192 |
+
"lstrip": false,
|
| 193 |
+
"normalized": false,
|
| 194 |
+
"rstrip": false,
|
| 195 |
+
"single_word": false,
|
| 196 |
+
"special": false
|
| 197 |
+
},
|
| 198 |
+
"151667": {
|
| 199 |
+
"content": "<think>",
|
| 200 |
+
"lstrip": false,
|
| 201 |
+
"normalized": false,
|
| 202 |
+
"rstrip": false,
|
| 203 |
+
"single_word": false,
|
| 204 |
+
"special": false
|
| 205 |
+
},
|
| 206 |
+
"151668": {
|
| 207 |
+
"content": "</think>",
|
| 208 |
+
"lstrip": false,
|
| 209 |
+
"normalized": false,
|
| 210 |
+
"rstrip": false,
|
| 211 |
+
"single_word": false,
|
| 212 |
+
"special": false
|
| 213 |
+
},
|
| 214 |
+
"151669": {
|
| 215 |
+
"content": "<IMG_CONTEXT>",
|
| 216 |
+
"lstrip": false,
|
| 217 |
+
"normalized": false,
|
| 218 |
+
"rstrip": false,
|
| 219 |
+
"single_word": false,
|
| 220 |
+
"special": true
|
| 221 |
+
},
|
| 222 |
+
"151670": {
|
| 223 |
+
"content": "<img>",
|
| 224 |
+
"lstrip": false,
|
| 225 |
+
"normalized": false,
|
| 226 |
+
"rstrip": false,
|
| 227 |
+
"single_word": false,
|
| 228 |
+
"special": true
|
| 229 |
+
},
|
| 230 |
+
"151671": {
|
| 231 |
+
"content": "</img>",
|
| 232 |
+
"lstrip": false,
|
| 233 |
+
"normalized": false,
|
| 234 |
+
"rstrip": false,
|
| 235 |
+
"single_word": false,
|
| 236 |
+
"special": true
|
| 237 |
+
},
|
| 238 |
+
"151672": {
|
| 239 |
+
"content": "<box>",
|
| 240 |
+
"lstrip": false,
|
| 241 |
+
"normalized": false,
|
| 242 |
+
"rstrip": false,
|
| 243 |
+
"single_word": false,
|
| 244 |
+
"special": true
|
| 245 |
+
},
|
| 246 |
+
"151673": {
|
| 247 |
+
"content": "</box>",
|
| 248 |
+
"lstrip": false,
|
| 249 |
+
"normalized": false,
|
| 250 |
+
"rstrip": false,
|
| 251 |
+
"single_word": false,
|
| 252 |
+
"special": true
|
| 253 |
+
},
|
| 254 |
+
"151674": {
|
| 255 |
+
"content": "<quad>",
|
| 256 |
+
"lstrip": false,
|
| 257 |
+
"normalized": false,
|
| 258 |
+
"rstrip": false,
|
| 259 |
+
"single_word": false,
|
| 260 |
+
"special": true
|
| 261 |
+
},
|
| 262 |
+
"151675": {
|
| 263 |
+
"content": "</quad>",
|
| 264 |
+
"lstrip": false,
|
| 265 |
+
"normalized": false,
|
| 266 |
+
"rstrip": false,
|
| 267 |
+
"single_word": false,
|
| 268 |
+
"special": true
|
| 269 |
+
},
|
| 270 |
+
"151676": {
|
| 271 |
+
"content": "<ref>",
|
| 272 |
+
"lstrip": false,
|
| 273 |
+
"normalized": false,
|
| 274 |
+
"rstrip": false,
|
| 275 |
+
"single_word": false,
|
| 276 |
+
"special": true
|
| 277 |
+
},
|
| 278 |
+
"151677": {
|
| 279 |
+
"content": "</ref>",
|
| 280 |
+
"lstrip": false,
|
| 281 |
+
"normalized": false,
|
| 282 |
+
"rstrip": false,
|
| 283 |
+
"single_word": false,
|
| 284 |
+
"special": true
|
| 285 |
+
},
|
| 286 |
+
"151678": {
|
| 287 |
+
"content": "<interval>",
|
| 288 |
+
"lstrip": false,
|
| 289 |
+
"normalized": false,
|
| 290 |
+
"rstrip": false,
|
| 291 |
+
"single_word": false,
|
| 292 |
+
"special": true
|
| 293 |
+
},
|
| 294 |
+
"151679": {
|
| 295 |
+
"content": "</interval>",
|
| 296 |
+
"lstrip": false,
|
| 297 |
+
"normalized": false,
|
| 298 |
+
"rstrip": false,
|
| 299 |
+
"single_word": false,
|
| 300 |
+
"special": true
|
| 301 |
+
}
|
| 302 |
+
},
|
| 303 |
+
"additional_special_tokens": [
|
| 304 |
+
"<|im_start|>",
|
| 305 |
+
"<|im_end|>",
|
| 306 |
+
"<|object_ref_start|>",
|
| 307 |
+
"<|object_ref_end|>",
|
| 308 |
+
"<|box_start|>",
|
| 309 |
+
"<|box_end|>",
|
| 310 |
+
"<|quad_start|>",
|
| 311 |
+
"<|quad_end|>",
|
| 312 |
+
"<|vision_start|>",
|
| 313 |
+
"<|vision_end|>",
|
| 314 |
+
"<|vision_pad|>",
|
| 315 |
+
"<|image_pad|>",
|
| 316 |
+
"<|video_pad|>",
|
| 317 |
+
"<IMG_CONTEXT>",
|
| 318 |
+
"<img>",
|
| 319 |
+
"</img>",
|
| 320 |
+
"<box>",
|
| 321 |
+
"</box>",
|
| 322 |
+
"<quad>",
|
| 323 |
+
"</quad>",
|
| 324 |
+
"<ref>",
|
| 325 |
+
"</ref>",
|
| 326 |
+
"<interval>",
|
| 327 |
+
"</interval>"
|
| 328 |
+
],
|
| 329 |
+
"auto_map": {
|
| 330 |
+
"AutoProcessor": "woshichaoren123/pretrain-2B-anyres--processing_eagle3_vl.Eagle3_VLProcessor"
|
| 331 |
+
},
|
| 332 |
+
"bos_token": null,
|
| 333 |
+
"chat_template": "{%- if tools %}\n {{- '<|im_start|>system\\n' }}\n {%- if messages[0].role == 'system' %}\n {{- messages[0].content + '\\n\\n' }}\n {%- endif %}\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 {%- endif %}\n{%- endif %}\n{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}\n{%- for message in messages[::-1] %}\n {%- set index = (messages|length - 1) - loop.index0 %}\n {%- if ns.multi_step_tool and message.role == \"user\" and message.content is string and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}\n {%- set ns.multi_step_tool = false %}\n {%- set ns.last_query_index = index %}\n {%- endif %}\n{%- endfor %}\n{%- for message in messages %}\n {%- if message.content is string %}\n {%- set content = message.content %}\n {%- else %}\n {%- set content = '' %}\n {%- endif %}\n {%- if (message.role == \"user\") or (message.role == \"system\" and not loop.first) %}\n {{- '<|im_start|>' + message.role + '\\n' + content + '<|im_end|>' + '\\n' }}\n {%- elif message.role == \"assistant\" %}\n {%- set reasoning_content = '' %}\n {%- if message.reasoning_content is string %}\n {%- set reasoning_content = message.reasoning_content %}\n {%- else %}\n {%- if '</think>' in content %}\n {%- set reasoning_content = content.split('</think>')[0].rstrip('\\n').split('<think>')[-1].lstrip('\\n') %}\n {%- set content = content.split('</think>')[-1].lstrip('\\n') %}\n {%- endif %}\n {%- endif %}\n {%- if loop.index0 > ns.last_query_index %}\n {%- if loop.last or (not loop.last and reasoning_content) %}\n {{- '<|im_start|>' + message.role + '\\n<think>\\n' + reasoning_content.strip('\\n') + '\\n</think>\\n\\n' + content.lstrip('\\n') }}\n {%- else %}\n {{- '<|im_start|>' + message.role + '\\n' + content }}\n {%- endif %}\n {%- else %}\n {{- '<|im_start|>' + message.role + '\\n' + content }}\n {%- endif %}\n {%- if message.tool_calls %}\n {%- for tool_call in message.tool_calls %}\n {%- if (loop.first and content) or (not loop.first) %}\n {{- '\\n' }}\n {%- endif %}\n {%- if tool_call.function %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {{- '<tool_call>\\n{\"name\": \"' }}\n {{- tool_call.name }}\n {{- '\", \"arguments\": ' }}\n {%- if tool_call.arguments is string %}\n {{- tool_call.arguments }}\n {%- else %}\n {{- tool_call.arguments | tojson }}\n {%- endif %}\n {{- '}\\n</tool_call>' }}\n {%- endfor %}\n {%- endif %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if loop.first or (messages[loop.index0 - 1].role != \"tool\") %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- 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 {%- if enable_thinking is defined and enable_thinking is false %}\n {{- '<think>\\n\\n</think>\\n\\n' }}\n {%- endif %}\n{%- endif %}",
|
| 334 |
+
"clean_up_tokenization_spaces": false,
|
| 335 |
+
"eos_token": "<|im_end|>",
|
| 336 |
+
"errors": "replace",
|
| 337 |
+
"extra_special_tokens": {},
|
| 338 |
+
"model_max_length": 32768,
|
| 339 |
+
"pad_token": "<|endoftext|>",
|
| 340 |
+
"processor_class": "Eagle3_VLProcessor",
|
| 341 |
+
"split_special_tokens": false,
|
| 342 |
+
"tokenizer_class": "Qwen2Tokenizer",
|
| 343 |
+
"unk_token": null
|
| 344 |
+
}
|
vocab.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|