xiangan commited on
Commit
06ba0dc
·
verified ·
1 Parent(s): 73ec00e

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
added_tokens.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "</tool_call>": 151658,
3
+ "<tool_call>": 151657,
4
+ "<|box_end|>": 151649,
5
+ "<|box_start|>": 151648,
6
+ "<|endoftext|>": 151643,
7
+ "<|file_sep|>": 151664,
8
+ "<|fim_middle|>": 151660,
9
+ "<|fim_pad|>": 151662,
10
+ "<|fim_prefix|>": 151659,
11
+ "<|fim_suffix|>": 151661,
12
+ "<|im_end|>": 151645,
13
+ "<|im_start|>": 151644,
14
+ "<|image_pad|>": 151655,
15
+ "<|object_ref_end|>": 151647,
16
+ "<|object_ref_start|>": 151646,
17
+ "<|quad_end|>": 151651,
18
+ "<|quad_start|>": 151650,
19
+ "<|repo_name|>": 151663,
20
+ "<|video_pad|>": 151656,
21
+ "<|vision_end|>": 151653,
22
+ "<|vision_pad|>": 151654,
23
+ "<|vision_start|>": 151652
24
+ }
chat_template.jinja ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {% 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
2
+ You are a helpful assistant.<|im_end|>
3
+ {% endif %}<|im_start|>{{ message['role'] }}
4
+ {% if message['content'] is string %}{{ message['content'] }}<|im_end|>
5
+ {% else %}{% for content in message['content'] %}{% if content['type'] == 'image' or 'image' in content or 'image_url' in content %}{% set image_count.value = image_count.value + 1 %}{% if add_vision_id %}Picture {{ image_count.value }}: {% endif %}<|vision_start|><|image_pad|><|vision_end|>{% elif content['type'] == 'video' or 'video' in content %}{% set video_count.value = video_count.value + 1 %}{% if add_vision_id %}Video {{ video_count.value }}: {% endif %}<|vision_start|><|video_pad|><|vision_end|>{% elif 'text' in content %}{{ content['text'] }}{% endif %}{% endfor %}<|im_end|>
6
+ {% endif %}{% endfor %}{% if add_generation_prompt %}<|im_start|>assistant
7
+ {% endif %}
config.json ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "auto_map": {
3
+ "AutoConfig": "configuration_llava_onevision2.LlavaOnevision2Config",
4
+ "AutoModelForCausalLM": "modeling_llava_onevision2.LlavaOnevision2ForConditionalGeneration"
5
+ },
6
+ "dtype": "bfloat16",
7
+ "image_token_id": 151655,
8
+ "model_type": "llava_onevision2",
9
+ "text_config": {
10
+ "_name_or_path": "/ov2/pretrain_models/Qwen3-8B/",
11
+ "architectures": [
12
+ "LlavaOnevision2ForConditionalGeneration"
13
+ ],
14
+ "attention_bias": false,
15
+ "attention_dropout": 0.0,
16
+ "bos_token_id": 151643,
17
+ "dtype": "bfloat16",
18
+ "eos_token_id": 151645,
19
+ "head_dim": 128,
20
+ "hidden_act": "silu",
21
+ "hidden_size": 4096,
22
+ "initializer_range": 0.02,
23
+ "intermediate_size": 12288,
24
+ "layer_types": [
25
+ "full_attention",
26
+ "full_attention",
27
+ "full_attention",
28
+ "full_attention",
29
+ "full_attention",
30
+ "full_attention",
31
+ "full_attention",
32
+ "full_attention",
33
+ "full_attention",
34
+ "full_attention",
35
+ "full_attention",
36
+ "full_attention",
37
+ "full_attention",
38
+ "full_attention",
39
+ "full_attention",
40
+ "full_attention",
41
+ "full_attention",
42
+ "full_attention",
43
+ "full_attention",
44
+ "full_attention",
45
+ "full_attention",
46
+ "full_attention",
47
+ "full_attention",
48
+ "full_attention",
49
+ "full_attention",
50
+ "full_attention",
51
+ "full_attention",
52
+ "full_attention",
53
+ "full_attention",
54
+ "full_attention",
55
+ "full_attention",
56
+ "full_attention",
57
+ "full_attention",
58
+ "full_attention",
59
+ "full_attention",
60
+ "full_attention"
61
+ ],
62
+ "max_position_embeddings": 40960,
63
+ "max_window_layers": 36,
64
+ "model_type": "qwen3",
65
+ "num_attention_heads": 32,
66
+ "num_hidden_layers": 36,
67
+ "num_key_value_heads": 8,
68
+ "rms_norm_eps": 1e-06,
69
+ "rope_scaling": null,
70
+ "rope_theta": 8000000,
71
+ "sliding_window": null,
72
+ "use_cache": true,
73
+ "use_sliding_window": false,
74
+ "vocab_size": 151936
75
+ },
76
+ "transformers_version": "4.57.3",
77
+ "video_token_id": 151656,
78
+ "vision_config": {
79
+ "attention_dropout": 0.0,
80
+ "frame_windows_size": 4,
81
+ "hidden_act": "gelu",
82
+ "hidden_size": 1024,
83
+ "image_size": 448,
84
+ "initializer_range": 0.02,
85
+ "intermediate_size": 4096,
86
+ "layer_norm_eps": 1e-06,
87
+ "layer_norm_type": "layer_norm",
88
+ "max_position_embeddings": 8192,
89
+ "model_type": "llava_onevision2",
90
+ "num_attention_heads": 16,
91
+ "num_channels": 3,
92
+ "num_hidden_layers": 24,
93
+ "out_hidden_size": 4096,
94
+ "patch_position_encoding_type": "absolute",
95
+ "patch_size": 14,
96
+ "rope_theta": 10000.0,
97
+ "spatial_merge_size": 2,
98
+ "temporal_patch_size": 1,
99
+ "text_hidden_size": 4096,
100
+ "tokens_per_second": 1,
101
+ "use_head": false,
102
+ "use_patch_position_encoding": false
103
+ },
104
+ "vision_end_token_id": 151653,
105
+ "vision_start_token_id": 151652
106
+ }
configuration_llava_onevision2.py ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import CONFIG_MAPPING, AutoConfig
2
+ from transformers.configuration_utils import PretrainedConfig
3
+
4
+
5
+ class LlavaOnevision2VisionConfig(PretrainedConfig):
6
+ model_type = "llava_onevision2"
7
+ base_config_key = "vision_config"
8
+
9
+ def __init__(
10
+ self,
11
+ hidden_size=1024,
12
+ intermediate_size=4096,
13
+ num_hidden_layers=24,
14
+ num_attention_heads=16,
15
+ num_channels=3,
16
+ image_size=448,
17
+ patch_size=14,
18
+ hidden_act="gelu",
19
+ layer_norm_eps=1e-6,
20
+ layer_norm_type="layer_norm",
21
+ attention_dropout=0.0,
22
+ initializer_range=0.02,
23
+ rope_theta=10000.0,
24
+ use_head=False,
25
+ out_hidden_size=1024,
26
+ spatial_merge_size=2,
27
+ tokens_per_second=1,
28
+ temporal_patch_size=1,
29
+ frame_windows_size=4,
30
+ use_patch_position_encoding=False,
31
+ patch_position_encoding_type="absolute",
32
+ max_position_embeddings=8192,
33
+ **kwargs,
34
+ ):
35
+ super().__init__(**kwargs)
36
+ self.hidden_size = hidden_size
37
+ self.intermediate_size = intermediate_size
38
+ self.num_hidden_layers = num_hidden_layers
39
+ self.num_attention_heads = num_attention_heads
40
+ self.num_channels = num_channels
41
+ self.image_size = image_size
42
+ self.patch_size = patch_size
43
+ self.hidden_act = hidden_act
44
+ self.layer_norm_eps = layer_norm_eps
45
+ self.layer_norm_type = layer_norm_type
46
+ self.attention_dropout = attention_dropout
47
+ self.initializer_range = initializer_range
48
+ self.rope_theta = rope_theta
49
+ self.use_head = use_head
50
+ self.out_hidden_size = out_hidden_size
51
+ self.spatial_merge_size = spatial_merge_size
52
+ self.tokens_per_second = tokens_per_second
53
+ self.temporal_patch_size = temporal_patch_size
54
+ self.frame_windows_size = frame_windows_size
55
+ self.use_patch_position_encoding = use_patch_position_encoding
56
+ self.patch_position_encoding_type = patch_position_encoding_type
57
+ self.max_position_embeddings = max_position_embeddings
58
+
59
+
60
+ class LlavaOnevision2Config(PretrainedConfig):
61
+ r"""
62
+ This is the configuration class to store the configuration of a [`LlavaOnevision2Model`]. It is used to instantiate a
63
+ LlavaOnevision2Model model according to the specified arguments, defining the model architecture. Instantiating a configuration
64
+ with the defaults will yield a similar configuration to that of
65
+ Llava-Onevision 1.5 [lmms-lab/LLaVA-OneVision-1.5-8B-Instruct](https://huggingface.co/lmms-lab/LLaVA-OneVision-1.5-8B-Instruct).
66
+
67
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
68
+ documentation from [`PretrainedConfig`] for more information.
69
+
70
+ Args:
71
+ text_config (`Union[PreTrainedConfig, dict]`, *optional*, defaults to `Qwen3Config`):
72
+ The config object or dictionary of the text backbone.
73
+ vision_config (`Union[PreTrainedConfig, dict]`, *optional*, defaults to `LlavaOnevision2VisionConfig`):
74
+ The config object or dictionary of the vision backbone.
75
+ image_token_id (`int`, *optional*, defaults to 151655):
76
+ The image token index to encode the image prompt.
77
+ video_token_id (`int`, *optional*, defaults to 151656):
78
+ The video token index to encode the image prompt.
79
+ vision_start_token_id (`int`, *optional*, defaults to 151652):
80
+ The token index to denote start of vision input.
81
+ vision_end_token_id (`int`, *optional*, defaults to 151653):
82
+ The token index to denote end of vision input.
83
+
84
+ ```python
85
+ >>> from transformers import LlavaOnevision2Model, LlavaOnevision2Config
86
+
87
+ >>> # Initializing a LlavaOnevision2 style configuration
88
+ >>> configuration = LlavaOnevision2Config()
89
+
90
+ >>> # Initializing a model from the Llava-Onevision-1.5-8B style configuration
91
+ >>> model = LlavaOnevision2Model(configuration)
92
+
93
+ >>> # Accessing the model configuration
94
+ >>> configuration = model.config
95
+ ```"""
96
+
97
+ model_type = "llava_onevision2"
98
+ sub_configs = {"vision_config": LlavaOnevision2VisionConfig, "text_config": AutoConfig}
99
+ keys_to_ignore_at_inference = ["past_key_values"]
100
+
101
+ def __init__(
102
+ self,
103
+ text_config=None,
104
+ vision_config=None,
105
+ image_token_id=151655,
106
+ video_token_id=151656,
107
+ vision_start_token_id=151652,
108
+ vision_end_token_id=151653,
109
+ **kwargs,
110
+ ):
111
+ # We need to init super() here so that it does not reset values
112
+ # that are in text config to the BaseClass defaults. The Base
113
+ # config has many text related defaults and not all defaults are same as for `LlavaOnevision2TextConfig`
114
+ super().__init__(**kwargs)
115
+ if isinstance(text_config, dict):
116
+ text_config["model_type"] = text_config.get("model_type", "qwen3")
117
+ self.sub_configs["text_config"] = CONFIG_MAPPING[text_config["model_type"]]
118
+ elif text_config is None:
119
+ self.sub_configs["text_config"] = CONFIG_MAPPING["qwen3"]
120
+
121
+ if isinstance(vision_config, dict):
122
+ self.vision_config = self.sub_configs["vision_config"](**vision_config)
123
+ elif vision_config is None:
124
+ self.vision_config = self.sub_configs["vision_config"]()
125
+
126
+ if isinstance(text_config, dict):
127
+ self.text_config = self.sub_configs["text_config"](**text_config)
128
+ elif text_config is None:
129
+ # For BC use all kwargs to init `TextConfig`
130
+ self.text_config = self.sub_configs["text_config"](**kwargs)
131
+
132
+ self.image_token_id = image_token_id
133
+ self.video_token_id = video_token_id
134
+ self.vision_start_token_id = vision_start_token_id
135
+ self.vision_end_token_id = vision_end_token_id
136
+
137
+ # Attention implementation to use. It sets it recursively on sub-configs so we call it again in the end
138
+ self._attn_implementation = kwargs.pop("attn_implementation", None)
139
+
140
+ def __setattr__(self, key, value):
141
+ if (
142
+ (text_config := super().__getattribute__("__dict__").get("text_config")) is not None
143
+ and key not in ["dtype", "_attn_implementation_internal"]
144
+ and key in text_config.__dict__
145
+ ):
146
+ setattr(text_config, key, value)
147
+ else:
148
+ super().__setattr__(key, value)
149
+
150
+ def __getattribute__(self, key):
151
+ if "text_config" in super().__getattribute__("__dict__") and key not in [
152
+ "_name_or_path",
153
+ "model_type",
154
+ "dtype",
155
+ "_attn_implementation_internal",
156
+ ]:
157
+ text_config = super().__getattribute__("text_config")
158
+ if key in text_config.__dict__:
159
+ return getattr(text_config, key)
160
+
161
+ return super().__getattribute__(key)
162
+
163
+
164
+ __all__ = ["LlavaOnevision2Config"]
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.57.3"
6
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model-00001-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c1cbc2a1efbcc85ca8e80ea9634c1be3024b584c8e21ddb6b1dcfc59799a074a
3
+ size 4952666112
model-00002-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aa2dd77bfae112aa90a53c4d9239a001359dd802e3192e1785242df715e47b42
3
+ size 4983026192
model-00003-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:98841f3db11545190b74145b22c77d83a08b61eac444a274a199e82cdadb05bf
3
+ size 4986203952
model-00004-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3dc0814f6f35977ecd8f2879bfecd1a60bfd3ec99deae892ceb0c829ae9d3339
3
+ size 2132611560
model.safetensors.index.json ADDED
@@ -0,0 +1,703 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 17054427136
4
+ },
5
+ "weight_map": {
6
+ "lm_head.weight": "model-00003-of-00004.safetensors",
7
+ "model.embed_tokens.weight": "model-00001-of-00004.safetensors",
8
+ "model.layers.0.input_layernorm.weight": "model-00001-of-00004.safetensors",
9
+ "model.layers.0.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
10
+ "model.layers.0.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
11
+ "model.layers.0.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
12
+ "model.layers.0.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
13
+ "model.layers.0.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
14
+ "model.layers.0.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
15
+ "model.layers.0.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
16
+ "model.layers.0.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
17
+ "model.layers.0.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
18
+ "model.layers.0.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
19
+ "model.layers.1.input_layernorm.weight": "model-00001-of-00004.safetensors",
20
+ "model.layers.1.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
21
+ "model.layers.1.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
22
+ "model.layers.1.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
23
+ "model.layers.1.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
24
+ "model.layers.1.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
25
+ "model.layers.1.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
26
+ "model.layers.1.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
27
+ "model.layers.1.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
28
+ "model.layers.1.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
29
+ "model.layers.1.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
30
+ "model.layers.10.input_layernorm.weight": "model-00001-of-00004.safetensors",
31
+ "model.layers.10.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
32
+ "model.layers.10.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
33
+ "model.layers.10.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
34
+ "model.layers.10.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
35
+ "model.layers.10.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
36
+ "model.layers.10.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
37
+ "model.layers.10.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
38
+ "model.layers.10.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
39
+ "model.layers.10.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
40
+ "model.layers.10.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
41
+ "model.layers.11.input_layernorm.weight": "model-00001-of-00004.safetensors",
42
+ "model.layers.11.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
43
+ "model.layers.11.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
44
+ "model.layers.11.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
45
+ "model.layers.11.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
46
+ "model.layers.11.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
47
+ "model.layers.11.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
48
+ "model.layers.11.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
49
+ "model.layers.11.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
50
+ "model.layers.11.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
51
+ "model.layers.11.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
52
+ "model.layers.12.input_layernorm.weight": "model-00001-of-00004.safetensors",
53
+ "model.layers.12.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
54
+ "model.layers.12.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
55
+ "model.layers.12.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
56
+ "model.layers.12.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
57
+ "model.layers.12.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
58
+ "model.layers.12.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
59
+ "model.layers.12.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
60
+ "model.layers.12.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
61
+ "model.layers.12.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
62
+ "model.layers.12.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
63
+ "model.layers.13.input_layernorm.weight": "model-00001-of-00004.safetensors",
64
+ "model.layers.13.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
65
+ "model.layers.13.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
66
+ "model.layers.13.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
67
+ "model.layers.13.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
68
+ "model.layers.13.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
69
+ "model.layers.13.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
70
+ "model.layers.13.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
71
+ "model.layers.13.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
72
+ "model.layers.13.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
73
+ "model.layers.13.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
74
+ "model.layers.14.input_layernorm.weight": "model-00002-of-00004.safetensors",
75
+ "model.layers.14.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
76
+ "model.layers.14.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
77
+ "model.layers.14.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
78
+ "model.layers.14.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
79
+ "model.layers.14.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
80
+ "model.layers.14.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
81
+ "model.layers.14.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
82
+ "model.layers.14.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
83
+ "model.layers.14.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
84
+ "model.layers.14.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
85
+ "model.layers.15.input_layernorm.weight": "model-00002-of-00004.safetensors",
86
+ "model.layers.15.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
87
+ "model.layers.15.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
88
+ "model.layers.15.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
89
+ "model.layers.15.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
90
+ "model.layers.15.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
91
+ "model.layers.15.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
92
+ "model.layers.15.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
93
+ "model.layers.15.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
94
+ "model.layers.15.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
95
+ "model.layers.15.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
96
+ "model.layers.16.input_layernorm.weight": "model-00002-of-00004.safetensors",
97
+ "model.layers.16.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
98
+ "model.layers.16.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
99
+ "model.layers.16.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
100
+ "model.layers.16.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
101
+ "model.layers.16.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
102
+ "model.layers.16.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
103
+ "model.layers.16.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
104
+ "model.layers.16.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
105
+ "model.layers.16.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
106
+ "model.layers.16.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
107
+ "model.layers.17.input_layernorm.weight": "model-00002-of-00004.safetensors",
108
+ "model.layers.17.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
109
+ "model.layers.17.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
110
+ "model.layers.17.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
111
+ "model.layers.17.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
112
+ "model.layers.17.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
113
+ "model.layers.17.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
114
+ "model.layers.17.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
115
+ "model.layers.17.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
116
+ "model.layers.17.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
117
+ "model.layers.17.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
118
+ "model.layers.18.input_layernorm.weight": "model-00002-of-00004.safetensors",
119
+ "model.layers.18.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
120
+ "model.layers.18.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
121
+ "model.layers.18.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
122
+ "model.layers.18.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
123
+ "model.layers.18.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
124
+ "model.layers.18.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
125
+ "model.layers.18.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
126
+ "model.layers.18.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
127
+ "model.layers.18.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
128
+ "model.layers.18.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
129
+ "model.layers.19.input_layernorm.weight": "model-00002-of-00004.safetensors",
130
+ "model.layers.19.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
131
+ "model.layers.19.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
132
+ "model.layers.19.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
133
+ "model.layers.19.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
134
+ "model.layers.19.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
135
+ "model.layers.19.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
136
+ "model.layers.19.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
137
+ "model.layers.19.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
138
+ "model.layers.19.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
139
+ "model.layers.19.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
140
+ "model.layers.2.input_layernorm.weight": "model-00001-of-00004.safetensors",
141
+ "model.layers.2.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
142
+ "model.layers.2.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
143
+ "model.layers.2.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
144
+ "model.layers.2.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
145
+ "model.layers.2.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
146
+ "model.layers.2.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
147
+ "model.layers.2.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
148
+ "model.layers.2.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
149
+ "model.layers.2.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
150
+ "model.layers.2.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
151
+ "model.layers.20.input_layernorm.weight": "model-00002-of-00004.safetensors",
152
+ "model.layers.20.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
153
+ "model.layers.20.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
154
+ "model.layers.20.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
155
+ "model.layers.20.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
156
+ "model.layers.20.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
157
+ "model.layers.20.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
158
+ "model.layers.20.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
159
+ "model.layers.20.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
160
+ "model.layers.20.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
161
+ "model.layers.20.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
162
+ "model.layers.21.input_layernorm.weight": "model-00002-of-00004.safetensors",
163
+ "model.layers.21.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
164
+ "model.layers.21.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
165
+ "model.layers.21.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
166
+ "model.layers.21.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
167
+ "model.layers.21.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
168
+ "model.layers.21.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
169
+ "model.layers.21.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
170
+ "model.layers.21.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
171
+ "model.layers.21.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
172
+ "model.layers.21.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
173
+ "model.layers.22.input_layernorm.weight": "model-00002-of-00004.safetensors",
174
+ "model.layers.22.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
175
+ "model.layers.22.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
176
+ "model.layers.22.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
177
+ "model.layers.22.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
178
+ "model.layers.22.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
179
+ "model.layers.22.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
180
+ "model.layers.22.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
181
+ "model.layers.22.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
182
+ "model.layers.22.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
183
+ "model.layers.22.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
184
+ "model.layers.23.input_layernorm.weight": "model-00002-of-00004.safetensors",
185
+ "model.layers.23.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
186
+ "model.layers.23.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
187
+ "model.layers.23.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
188
+ "model.layers.23.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
189
+ "model.layers.23.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
190
+ "model.layers.23.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
191
+ "model.layers.23.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
192
+ "model.layers.23.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
193
+ "model.layers.23.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
194
+ "model.layers.23.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
195
+ "model.layers.24.input_layernorm.weight": "model-00003-of-00004.safetensors",
196
+ "model.layers.24.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
197
+ "model.layers.24.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
198
+ "model.layers.24.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
199
+ "model.layers.24.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
200
+ "model.layers.24.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
201
+ "model.layers.24.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
202
+ "model.layers.24.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
203
+ "model.layers.24.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
204
+ "model.layers.24.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
205
+ "model.layers.24.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
206
+ "model.layers.25.input_layernorm.weight": "model-00003-of-00004.safetensors",
207
+ "model.layers.25.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
208
+ "model.layers.25.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
209
+ "model.layers.25.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
210
+ "model.layers.25.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
211
+ "model.layers.25.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
212
+ "model.layers.25.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
213
+ "model.layers.25.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
214
+ "model.layers.25.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
215
+ "model.layers.25.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
216
+ "model.layers.25.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
217
+ "model.layers.26.input_layernorm.weight": "model-00003-of-00004.safetensors",
218
+ "model.layers.26.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
219
+ "model.layers.26.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
220
+ "model.layers.26.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
221
+ "model.layers.26.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
222
+ "model.layers.26.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
223
+ "model.layers.26.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
224
+ "model.layers.26.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
225
+ "model.layers.26.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
226
+ "model.layers.26.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
227
+ "model.layers.26.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
228
+ "model.layers.27.input_layernorm.weight": "model-00003-of-00004.safetensors",
229
+ "model.layers.27.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
230
+ "model.layers.27.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
231
+ "model.layers.27.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
232
+ "model.layers.27.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
233
+ "model.layers.27.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
234
+ "model.layers.27.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
235
+ "model.layers.27.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
236
+ "model.layers.27.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
237
+ "model.layers.27.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
238
+ "model.layers.27.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
239
+ "model.layers.28.input_layernorm.weight": "model-00003-of-00004.safetensors",
240
+ "model.layers.28.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
241
+ "model.layers.28.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
242
+ "model.layers.28.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
243
+ "model.layers.28.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
244
+ "model.layers.28.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
245
+ "model.layers.28.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
246
+ "model.layers.28.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
247
+ "model.layers.28.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
248
+ "model.layers.28.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
249
+ "model.layers.28.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
250
+ "model.layers.29.input_layernorm.weight": "model-00003-of-00004.safetensors",
251
+ "model.layers.29.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
252
+ "model.layers.29.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
253
+ "model.layers.29.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
254
+ "model.layers.29.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
255
+ "model.layers.29.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
256
+ "model.layers.29.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
257
+ "model.layers.29.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
258
+ "model.layers.29.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
259
+ "model.layers.29.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
260
+ "model.layers.29.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
261
+ "model.layers.3.input_layernorm.weight": "model-00001-of-00004.safetensors",
262
+ "model.layers.3.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
263
+ "model.layers.3.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
264
+ "model.layers.3.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
265
+ "model.layers.3.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
266
+ "model.layers.3.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
267
+ "model.layers.3.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
268
+ "model.layers.3.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
269
+ "model.layers.3.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
270
+ "model.layers.3.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
271
+ "model.layers.3.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
272
+ "model.layers.30.input_layernorm.weight": "model-00003-of-00004.safetensors",
273
+ "model.layers.30.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
274
+ "model.layers.30.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
275
+ "model.layers.30.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
276
+ "model.layers.30.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
277
+ "model.layers.30.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
278
+ "model.layers.30.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
279
+ "model.layers.30.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
280
+ "model.layers.30.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
281
+ "model.layers.30.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
282
+ "model.layers.30.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
283
+ "model.layers.31.input_layernorm.weight": "model-00003-of-00004.safetensors",
284
+ "model.layers.31.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
285
+ "model.layers.31.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
286
+ "model.layers.31.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
287
+ "model.layers.31.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
288
+ "model.layers.31.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
289
+ "model.layers.31.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
290
+ "model.layers.31.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
291
+ "model.layers.31.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
292
+ "model.layers.31.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
293
+ "model.layers.31.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
294
+ "model.layers.32.input_layernorm.weight": "model-00003-of-00004.safetensors",
295
+ "model.layers.32.mlp.down_proj.weight": "model-00004-of-00004.safetensors",
296
+ "model.layers.32.mlp.gate_proj.weight": "model-00004-of-00004.safetensors",
297
+ "model.layers.32.mlp.up_proj.weight": "model-00004-of-00004.safetensors",
298
+ "model.layers.32.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
299
+ "model.layers.32.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
300
+ "model.layers.32.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
301
+ "model.layers.32.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
302
+ "model.layers.32.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
303
+ "model.layers.32.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
304
+ "model.layers.32.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
305
+ "model.layers.33.input_layernorm.weight": "model-00003-of-00004.safetensors",
306
+ "model.layers.33.mlp.down_proj.weight": "model-00004-of-00004.safetensors",
307
+ "model.layers.33.mlp.gate_proj.weight": "model-00004-of-00004.safetensors",
308
+ "model.layers.33.mlp.up_proj.weight": "model-00004-of-00004.safetensors",
309
+ "model.layers.33.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
310
+ "model.layers.33.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
311
+ "model.layers.33.self_attn.k_proj.weight": "model-00004-of-00004.safetensors",
312
+ "model.layers.33.self_attn.o_proj.weight": "model-00004-of-00004.safetensors",
313
+ "model.layers.33.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
314
+ "model.layers.33.self_attn.q_proj.weight": "model-00004-of-00004.safetensors",
315
+ "model.layers.33.self_attn.v_proj.weight": "model-00004-of-00004.safetensors",
316
+ "model.layers.34.input_layernorm.weight": "model-00003-of-00004.safetensors",
317
+ "model.layers.34.mlp.down_proj.weight": "model-00004-of-00004.safetensors",
318
+ "model.layers.34.mlp.gate_proj.weight": "model-00004-of-00004.safetensors",
319
+ "model.layers.34.mlp.up_proj.weight": "model-00004-of-00004.safetensors",
320
+ "model.layers.34.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
321
+ "model.layers.34.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
322
+ "model.layers.34.self_attn.k_proj.weight": "model-00004-of-00004.safetensors",
323
+ "model.layers.34.self_attn.o_proj.weight": "model-00004-of-00004.safetensors",
324
+ "model.layers.34.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
325
+ "model.layers.34.self_attn.q_proj.weight": "model-00004-of-00004.safetensors",
326
+ "model.layers.34.self_attn.v_proj.weight": "model-00004-of-00004.safetensors",
327
+ "model.layers.35.input_layernorm.weight": "model-00003-of-00004.safetensors",
328
+ "model.layers.35.mlp.down_proj.weight": "model-00004-of-00004.safetensors",
329
+ "model.layers.35.mlp.gate_proj.weight": "model-00004-of-00004.safetensors",
330
+ "model.layers.35.mlp.up_proj.weight": "model-00004-of-00004.safetensors",
331
+ "model.layers.35.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
332
+ "model.layers.35.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
333
+ "model.layers.35.self_attn.k_proj.weight": "model-00004-of-00004.safetensors",
334
+ "model.layers.35.self_attn.o_proj.weight": "model-00004-of-00004.safetensors",
335
+ "model.layers.35.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
336
+ "model.layers.35.self_attn.q_proj.weight": "model-00004-of-00004.safetensors",
337
+ "model.layers.35.self_attn.v_proj.weight": "model-00004-of-00004.safetensors",
338
+ "model.layers.4.input_layernorm.weight": "model-00001-of-00004.safetensors",
339
+ "model.layers.4.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
340
+ "model.layers.4.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
341
+ "model.layers.4.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
342
+ "model.layers.4.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
343
+ "model.layers.4.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
344
+ "model.layers.4.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
345
+ "model.layers.4.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
346
+ "model.layers.4.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
347
+ "model.layers.4.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
348
+ "model.layers.4.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
349
+ "model.layers.5.input_layernorm.weight": "model-00001-of-00004.safetensors",
350
+ "model.layers.5.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
351
+ "model.layers.5.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
352
+ "model.layers.5.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
353
+ "model.layers.5.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
354
+ "model.layers.5.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
355
+ "model.layers.5.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
356
+ "model.layers.5.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
357
+ "model.layers.5.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
358
+ "model.layers.5.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
359
+ "model.layers.5.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
360
+ "model.layers.6.input_layernorm.weight": "model-00001-of-00004.safetensors",
361
+ "model.layers.6.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
362
+ "model.layers.6.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
363
+ "model.layers.6.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
364
+ "model.layers.6.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
365
+ "model.layers.6.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
366
+ "model.layers.6.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
367
+ "model.layers.6.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
368
+ "model.layers.6.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
369
+ "model.layers.6.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
370
+ "model.layers.6.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
371
+ "model.layers.7.input_layernorm.weight": "model-00001-of-00004.safetensors",
372
+ "model.layers.7.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
373
+ "model.layers.7.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
374
+ "model.layers.7.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
375
+ "model.layers.7.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
376
+ "model.layers.7.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
377
+ "model.layers.7.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
378
+ "model.layers.7.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
379
+ "model.layers.7.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
380
+ "model.layers.7.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
381
+ "model.layers.7.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
382
+ "model.layers.8.input_layernorm.weight": "model-00001-of-00004.safetensors",
383
+ "model.layers.8.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
384
+ "model.layers.8.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
385
+ "model.layers.8.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
386
+ "model.layers.8.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
387
+ "model.layers.8.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
388
+ "model.layers.8.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
389
+ "model.layers.8.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
390
+ "model.layers.8.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
391
+ "model.layers.8.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
392
+ "model.layers.8.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
393
+ "model.layers.9.input_layernorm.weight": "model-00001-of-00004.safetensors",
394
+ "model.layers.9.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
395
+ "model.layers.9.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
396
+ "model.layers.9.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
397
+ "model.layers.9.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
398
+ "model.layers.9.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
399
+ "model.layers.9.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
400
+ "model.layers.9.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
401
+ "model.layers.9.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
402
+ "model.layers.9.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
403
+ "model.layers.9.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
404
+ "model.norm.weight": "model-00003-of-00004.safetensors",
405
+ "visual.embeddings.patch_embedding.weight": "model-00004-of-00004.safetensors",
406
+ "visual.encoder.layers.0.layer_norm1.bias": "model-00004-of-00004.safetensors",
407
+ "visual.encoder.layers.0.layer_norm1.weight": "model-00004-of-00004.safetensors",
408
+ "visual.encoder.layers.0.layer_norm2.bias": "model-00004-of-00004.safetensors",
409
+ "visual.encoder.layers.0.layer_norm2.weight": "model-00004-of-00004.safetensors",
410
+ "visual.encoder.layers.0.mlp.fc1.bias": "model-00004-of-00004.safetensors",
411
+ "visual.encoder.layers.0.mlp.fc1.weight": "model-00004-of-00004.safetensors",
412
+ "visual.encoder.layers.0.mlp.fc2.bias": "model-00004-of-00004.safetensors",
413
+ "visual.encoder.layers.0.mlp.fc2.weight": "model-00004-of-00004.safetensors",
414
+ "visual.encoder.layers.0.self_attn.proj.bias": "model-00004-of-00004.safetensors",
415
+ "visual.encoder.layers.0.self_attn.proj.weight": "model-00004-of-00004.safetensors",
416
+ "visual.encoder.layers.0.self_attn.qkv.bias": "model-00004-of-00004.safetensors",
417
+ "visual.encoder.layers.0.self_attn.qkv.weight": "model-00004-of-00004.safetensors",
418
+ "visual.encoder.layers.1.layer_norm1.bias": "model-00004-of-00004.safetensors",
419
+ "visual.encoder.layers.1.layer_norm1.weight": "model-00004-of-00004.safetensors",
420
+ "visual.encoder.layers.1.layer_norm2.bias": "model-00004-of-00004.safetensors",
421
+ "visual.encoder.layers.1.layer_norm2.weight": "model-00004-of-00004.safetensors",
422
+ "visual.encoder.layers.1.mlp.fc1.bias": "model-00004-of-00004.safetensors",
423
+ "visual.encoder.layers.1.mlp.fc1.weight": "model-00004-of-00004.safetensors",
424
+ "visual.encoder.layers.1.mlp.fc2.bias": "model-00004-of-00004.safetensors",
425
+ "visual.encoder.layers.1.mlp.fc2.weight": "model-00004-of-00004.safetensors",
426
+ "visual.encoder.layers.1.self_attn.proj.bias": "model-00004-of-00004.safetensors",
427
+ "visual.encoder.layers.1.self_attn.proj.weight": "model-00004-of-00004.safetensors",
428
+ "visual.encoder.layers.1.self_attn.qkv.bias": "model-00004-of-00004.safetensors",
429
+ "visual.encoder.layers.1.self_attn.qkv.weight": "model-00004-of-00004.safetensors",
430
+ "visual.encoder.layers.10.layer_norm1.bias": "model-00004-of-00004.safetensors",
431
+ "visual.encoder.layers.10.layer_norm1.weight": "model-00004-of-00004.safetensors",
432
+ "visual.encoder.layers.10.layer_norm2.bias": "model-00004-of-00004.safetensors",
433
+ "visual.encoder.layers.10.layer_norm2.weight": "model-00004-of-00004.safetensors",
434
+ "visual.encoder.layers.10.mlp.fc1.bias": "model-00004-of-00004.safetensors",
435
+ "visual.encoder.layers.10.mlp.fc1.weight": "model-00004-of-00004.safetensors",
436
+ "visual.encoder.layers.10.mlp.fc2.bias": "model-00004-of-00004.safetensors",
437
+ "visual.encoder.layers.10.mlp.fc2.weight": "model-00004-of-00004.safetensors",
438
+ "visual.encoder.layers.10.self_attn.proj.bias": "model-00004-of-00004.safetensors",
439
+ "visual.encoder.layers.10.self_attn.proj.weight": "model-00004-of-00004.safetensors",
440
+ "visual.encoder.layers.10.self_attn.qkv.bias": "model-00004-of-00004.safetensors",
441
+ "visual.encoder.layers.10.self_attn.qkv.weight": "model-00004-of-00004.safetensors",
442
+ "visual.encoder.layers.11.layer_norm1.bias": "model-00004-of-00004.safetensors",
443
+ "visual.encoder.layers.11.layer_norm1.weight": "model-00004-of-00004.safetensors",
444
+ "visual.encoder.layers.11.layer_norm2.bias": "model-00004-of-00004.safetensors",
445
+ "visual.encoder.layers.11.layer_norm2.weight": "model-00004-of-00004.safetensors",
446
+ "visual.encoder.layers.11.mlp.fc1.bias": "model-00004-of-00004.safetensors",
447
+ "visual.encoder.layers.11.mlp.fc1.weight": "model-00004-of-00004.safetensors",
448
+ "visual.encoder.layers.11.mlp.fc2.bias": "model-00004-of-00004.safetensors",
449
+ "visual.encoder.layers.11.mlp.fc2.weight": "model-00004-of-00004.safetensors",
450
+ "visual.encoder.layers.11.self_attn.proj.bias": "model-00004-of-00004.safetensors",
451
+ "visual.encoder.layers.11.self_attn.proj.weight": "model-00004-of-00004.safetensors",
452
+ "visual.encoder.layers.11.self_attn.qkv.bias": "model-00004-of-00004.safetensors",
453
+ "visual.encoder.layers.11.self_attn.qkv.weight": "model-00004-of-00004.safetensors",
454
+ "visual.encoder.layers.12.layer_norm1.bias": "model-00004-of-00004.safetensors",
455
+ "visual.encoder.layers.12.layer_norm1.weight": "model-00004-of-00004.safetensors",
456
+ "visual.encoder.layers.12.layer_norm2.bias": "model-00004-of-00004.safetensors",
457
+ "visual.encoder.layers.12.layer_norm2.weight": "model-00004-of-00004.safetensors",
458
+ "visual.encoder.layers.12.mlp.fc1.bias": "model-00004-of-00004.safetensors",
459
+ "visual.encoder.layers.12.mlp.fc1.weight": "model-00004-of-00004.safetensors",
460
+ "visual.encoder.layers.12.mlp.fc2.bias": "model-00004-of-00004.safetensors",
461
+ "visual.encoder.layers.12.mlp.fc2.weight": "model-00004-of-00004.safetensors",
462
+ "visual.encoder.layers.12.self_attn.proj.bias": "model-00004-of-00004.safetensors",
463
+ "visual.encoder.layers.12.self_attn.proj.weight": "model-00004-of-00004.safetensors",
464
+ "visual.encoder.layers.12.self_attn.qkv.bias": "model-00004-of-00004.safetensors",
465
+ "visual.encoder.layers.12.self_attn.qkv.weight": "model-00004-of-00004.safetensors",
466
+ "visual.encoder.layers.13.layer_norm1.bias": "model-00004-of-00004.safetensors",
467
+ "visual.encoder.layers.13.layer_norm1.weight": "model-00004-of-00004.safetensors",
468
+ "visual.encoder.layers.13.layer_norm2.bias": "model-00004-of-00004.safetensors",
469
+ "visual.encoder.layers.13.layer_norm2.weight": "model-00004-of-00004.safetensors",
470
+ "visual.encoder.layers.13.mlp.fc1.bias": "model-00004-of-00004.safetensors",
471
+ "visual.encoder.layers.13.mlp.fc1.weight": "model-00004-of-00004.safetensors",
472
+ "visual.encoder.layers.13.mlp.fc2.bias": "model-00004-of-00004.safetensors",
473
+ "visual.encoder.layers.13.mlp.fc2.weight": "model-00004-of-00004.safetensors",
474
+ "visual.encoder.layers.13.self_attn.proj.bias": "model-00004-of-00004.safetensors",
475
+ "visual.encoder.layers.13.self_attn.proj.weight": "model-00004-of-00004.safetensors",
476
+ "visual.encoder.layers.13.self_attn.qkv.bias": "model-00004-of-00004.safetensors",
477
+ "visual.encoder.layers.13.self_attn.qkv.weight": "model-00004-of-00004.safetensors",
478
+ "visual.encoder.layers.14.layer_norm1.bias": "model-00004-of-00004.safetensors",
479
+ "visual.encoder.layers.14.layer_norm1.weight": "model-00004-of-00004.safetensors",
480
+ "visual.encoder.layers.14.layer_norm2.bias": "model-00004-of-00004.safetensors",
481
+ "visual.encoder.layers.14.layer_norm2.weight": "model-00004-of-00004.safetensors",
482
+ "visual.encoder.layers.14.mlp.fc1.bias": "model-00004-of-00004.safetensors",
483
+ "visual.encoder.layers.14.mlp.fc1.weight": "model-00004-of-00004.safetensors",
484
+ "visual.encoder.layers.14.mlp.fc2.bias": "model-00004-of-00004.safetensors",
485
+ "visual.encoder.layers.14.mlp.fc2.weight": "model-00004-of-00004.safetensors",
486
+ "visual.encoder.layers.14.self_attn.proj.bias": "model-00004-of-00004.safetensors",
487
+ "visual.encoder.layers.14.self_attn.proj.weight": "model-00004-of-00004.safetensors",
488
+ "visual.encoder.layers.14.self_attn.qkv.bias": "model-00004-of-00004.safetensors",
489
+ "visual.encoder.layers.14.self_attn.qkv.weight": "model-00004-of-00004.safetensors",
490
+ "visual.encoder.layers.15.layer_norm1.bias": "model-00004-of-00004.safetensors",
491
+ "visual.encoder.layers.15.layer_norm1.weight": "model-00004-of-00004.safetensors",
492
+ "visual.encoder.layers.15.layer_norm2.bias": "model-00004-of-00004.safetensors",
493
+ "visual.encoder.layers.15.layer_norm2.weight": "model-00004-of-00004.safetensors",
494
+ "visual.encoder.layers.15.mlp.fc1.bias": "model-00004-of-00004.safetensors",
495
+ "visual.encoder.layers.15.mlp.fc1.weight": "model-00004-of-00004.safetensors",
496
+ "visual.encoder.layers.15.mlp.fc2.bias": "model-00004-of-00004.safetensors",
497
+ "visual.encoder.layers.15.mlp.fc2.weight": "model-00004-of-00004.safetensors",
498
+ "visual.encoder.layers.15.self_attn.proj.bias": "model-00004-of-00004.safetensors",
499
+ "visual.encoder.layers.15.self_attn.proj.weight": "model-00004-of-00004.safetensors",
500
+ "visual.encoder.layers.15.self_attn.qkv.bias": "model-00004-of-00004.safetensors",
501
+ "visual.encoder.layers.15.self_attn.qkv.weight": "model-00004-of-00004.safetensors",
502
+ "visual.encoder.layers.16.layer_norm1.bias": "model-00004-of-00004.safetensors",
503
+ "visual.encoder.layers.16.layer_norm1.weight": "model-00004-of-00004.safetensors",
504
+ "visual.encoder.layers.16.layer_norm2.bias": "model-00004-of-00004.safetensors",
505
+ "visual.encoder.layers.16.layer_norm2.weight": "model-00004-of-00004.safetensors",
506
+ "visual.encoder.layers.16.mlp.fc1.bias": "model-00004-of-00004.safetensors",
507
+ "visual.encoder.layers.16.mlp.fc1.weight": "model-00004-of-00004.safetensors",
508
+ "visual.encoder.layers.16.mlp.fc2.bias": "model-00004-of-00004.safetensors",
509
+ "visual.encoder.layers.16.mlp.fc2.weight": "model-00004-of-00004.safetensors",
510
+ "visual.encoder.layers.16.self_attn.proj.bias": "model-00004-of-00004.safetensors",
511
+ "visual.encoder.layers.16.self_attn.proj.weight": "model-00004-of-00004.safetensors",
512
+ "visual.encoder.layers.16.self_attn.qkv.bias": "model-00004-of-00004.safetensors",
513
+ "visual.encoder.layers.16.self_attn.qkv.weight": "model-00004-of-00004.safetensors",
514
+ "visual.encoder.layers.17.layer_norm1.bias": "model-00004-of-00004.safetensors",
515
+ "visual.encoder.layers.17.layer_norm1.weight": "model-00004-of-00004.safetensors",
516
+ "visual.encoder.layers.17.layer_norm2.bias": "model-00004-of-00004.safetensors",
517
+ "visual.encoder.layers.17.layer_norm2.weight": "model-00004-of-00004.safetensors",
518
+ "visual.encoder.layers.17.mlp.fc1.bias": "model-00004-of-00004.safetensors",
519
+ "visual.encoder.layers.17.mlp.fc1.weight": "model-00004-of-00004.safetensors",
520
+ "visual.encoder.layers.17.mlp.fc2.bias": "model-00004-of-00004.safetensors",
521
+ "visual.encoder.layers.17.mlp.fc2.weight": "model-00004-of-00004.safetensors",
522
+ "visual.encoder.layers.17.self_attn.proj.bias": "model-00004-of-00004.safetensors",
523
+ "visual.encoder.layers.17.self_attn.proj.weight": "model-00004-of-00004.safetensors",
524
+ "visual.encoder.layers.17.self_attn.qkv.bias": "model-00004-of-00004.safetensors",
525
+ "visual.encoder.layers.17.self_attn.qkv.weight": "model-00004-of-00004.safetensors",
526
+ "visual.encoder.layers.18.layer_norm1.bias": "model-00004-of-00004.safetensors",
527
+ "visual.encoder.layers.18.layer_norm1.weight": "model-00004-of-00004.safetensors",
528
+ "visual.encoder.layers.18.layer_norm2.bias": "model-00004-of-00004.safetensors",
529
+ "visual.encoder.layers.18.layer_norm2.weight": "model-00004-of-00004.safetensors",
530
+ "visual.encoder.layers.18.mlp.fc1.bias": "model-00004-of-00004.safetensors",
531
+ "visual.encoder.layers.18.mlp.fc1.weight": "model-00004-of-00004.safetensors",
532
+ "visual.encoder.layers.18.mlp.fc2.bias": "model-00004-of-00004.safetensors",
533
+ "visual.encoder.layers.18.mlp.fc2.weight": "model-00004-of-00004.safetensors",
534
+ "visual.encoder.layers.18.self_attn.proj.bias": "model-00004-of-00004.safetensors",
535
+ "visual.encoder.layers.18.self_attn.proj.weight": "model-00004-of-00004.safetensors",
536
+ "visual.encoder.layers.18.self_attn.qkv.bias": "model-00004-of-00004.safetensors",
537
+ "visual.encoder.layers.18.self_attn.qkv.weight": "model-00004-of-00004.safetensors",
538
+ "visual.encoder.layers.19.layer_norm1.bias": "model-00004-of-00004.safetensors",
539
+ "visual.encoder.layers.19.layer_norm1.weight": "model-00004-of-00004.safetensors",
540
+ "visual.encoder.layers.19.layer_norm2.bias": "model-00004-of-00004.safetensors",
541
+ "visual.encoder.layers.19.layer_norm2.weight": "model-00004-of-00004.safetensors",
542
+ "visual.encoder.layers.19.mlp.fc1.bias": "model-00004-of-00004.safetensors",
543
+ "visual.encoder.layers.19.mlp.fc1.weight": "model-00004-of-00004.safetensors",
544
+ "visual.encoder.layers.19.mlp.fc2.bias": "model-00004-of-00004.safetensors",
545
+ "visual.encoder.layers.19.mlp.fc2.weight": "model-00004-of-00004.safetensors",
546
+ "visual.encoder.layers.19.self_attn.proj.bias": "model-00004-of-00004.safetensors",
547
+ "visual.encoder.layers.19.self_attn.proj.weight": "model-00004-of-00004.safetensors",
548
+ "visual.encoder.layers.19.self_attn.qkv.bias": "model-00004-of-00004.safetensors",
549
+ "visual.encoder.layers.19.self_attn.qkv.weight": "model-00004-of-00004.safetensors",
550
+ "visual.encoder.layers.2.layer_norm1.bias": "model-00004-of-00004.safetensors",
551
+ "visual.encoder.layers.2.layer_norm1.weight": "model-00004-of-00004.safetensors",
552
+ "visual.encoder.layers.2.layer_norm2.bias": "model-00004-of-00004.safetensors",
553
+ "visual.encoder.layers.2.layer_norm2.weight": "model-00004-of-00004.safetensors",
554
+ "visual.encoder.layers.2.mlp.fc1.bias": "model-00004-of-00004.safetensors",
555
+ "visual.encoder.layers.2.mlp.fc1.weight": "model-00004-of-00004.safetensors",
556
+ "visual.encoder.layers.2.mlp.fc2.bias": "model-00004-of-00004.safetensors",
557
+ "visual.encoder.layers.2.mlp.fc2.weight": "model-00004-of-00004.safetensors",
558
+ "visual.encoder.layers.2.self_attn.proj.bias": "model-00004-of-00004.safetensors",
559
+ "visual.encoder.layers.2.self_attn.proj.weight": "model-00004-of-00004.safetensors",
560
+ "visual.encoder.layers.2.self_attn.qkv.bias": "model-00004-of-00004.safetensors",
561
+ "visual.encoder.layers.2.self_attn.qkv.weight": "model-00004-of-00004.safetensors",
562
+ "visual.encoder.layers.20.layer_norm1.bias": "model-00004-of-00004.safetensors",
563
+ "visual.encoder.layers.20.layer_norm1.weight": "model-00004-of-00004.safetensors",
564
+ "visual.encoder.layers.20.layer_norm2.bias": "model-00004-of-00004.safetensors",
565
+ "visual.encoder.layers.20.layer_norm2.weight": "model-00004-of-00004.safetensors",
566
+ "visual.encoder.layers.20.mlp.fc1.bias": "model-00004-of-00004.safetensors",
567
+ "visual.encoder.layers.20.mlp.fc1.weight": "model-00004-of-00004.safetensors",
568
+ "visual.encoder.layers.20.mlp.fc2.bias": "model-00004-of-00004.safetensors",
569
+ "visual.encoder.layers.20.mlp.fc2.weight": "model-00004-of-00004.safetensors",
570
+ "visual.encoder.layers.20.self_attn.proj.bias": "model-00004-of-00004.safetensors",
571
+ "visual.encoder.layers.20.self_attn.proj.weight": "model-00004-of-00004.safetensors",
572
+ "visual.encoder.layers.20.self_attn.qkv.bias": "model-00004-of-00004.safetensors",
573
+ "visual.encoder.layers.20.self_attn.qkv.weight": "model-00004-of-00004.safetensors",
574
+ "visual.encoder.layers.21.layer_norm1.bias": "model-00004-of-00004.safetensors",
575
+ "visual.encoder.layers.21.layer_norm1.weight": "model-00004-of-00004.safetensors",
576
+ "visual.encoder.layers.21.layer_norm2.bias": "model-00004-of-00004.safetensors",
577
+ "visual.encoder.layers.21.layer_norm2.weight": "model-00004-of-00004.safetensors",
578
+ "visual.encoder.layers.21.mlp.fc1.bias": "model-00004-of-00004.safetensors",
579
+ "visual.encoder.layers.21.mlp.fc1.weight": "model-00004-of-00004.safetensors",
580
+ "visual.encoder.layers.21.mlp.fc2.bias": "model-00004-of-00004.safetensors",
581
+ "visual.encoder.layers.21.mlp.fc2.weight": "model-00004-of-00004.safetensors",
582
+ "visual.encoder.layers.21.self_attn.proj.bias": "model-00004-of-00004.safetensors",
583
+ "visual.encoder.layers.21.self_attn.proj.weight": "model-00004-of-00004.safetensors",
584
+ "visual.encoder.layers.21.self_attn.qkv.bias": "model-00004-of-00004.safetensors",
585
+ "visual.encoder.layers.21.self_attn.qkv.weight": "model-00004-of-00004.safetensors",
586
+ "visual.encoder.layers.22.layer_norm1.bias": "model-00004-of-00004.safetensors",
587
+ "visual.encoder.layers.22.layer_norm1.weight": "model-00004-of-00004.safetensors",
588
+ "visual.encoder.layers.22.layer_norm2.bias": "model-00004-of-00004.safetensors",
589
+ "visual.encoder.layers.22.layer_norm2.weight": "model-00004-of-00004.safetensors",
590
+ "visual.encoder.layers.22.mlp.fc1.bias": "model-00004-of-00004.safetensors",
591
+ "visual.encoder.layers.22.mlp.fc1.weight": "model-00004-of-00004.safetensors",
592
+ "visual.encoder.layers.22.mlp.fc2.bias": "model-00004-of-00004.safetensors",
593
+ "visual.encoder.layers.22.mlp.fc2.weight": "model-00004-of-00004.safetensors",
594
+ "visual.encoder.layers.22.self_attn.proj.bias": "model-00004-of-00004.safetensors",
595
+ "visual.encoder.layers.22.self_attn.proj.weight": "model-00004-of-00004.safetensors",
596
+ "visual.encoder.layers.22.self_attn.qkv.bias": "model-00004-of-00004.safetensors",
597
+ "visual.encoder.layers.22.self_attn.qkv.weight": "model-00004-of-00004.safetensors",
598
+ "visual.encoder.layers.23.layer_norm1.bias": "model-00004-of-00004.safetensors",
599
+ "visual.encoder.layers.23.layer_norm1.weight": "model-00004-of-00004.safetensors",
600
+ "visual.encoder.layers.23.layer_norm2.bias": "model-00004-of-00004.safetensors",
601
+ "visual.encoder.layers.23.layer_norm2.weight": "model-00004-of-00004.safetensors",
602
+ "visual.encoder.layers.23.mlp.fc1.bias": "model-00004-of-00004.safetensors",
603
+ "visual.encoder.layers.23.mlp.fc1.weight": "model-00004-of-00004.safetensors",
604
+ "visual.encoder.layers.23.mlp.fc2.bias": "model-00004-of-00004.safetensors",
605
+ "visual.encoder.layers.23.mlp.fc2.weight": "model-00004-of-00004.safetensors",
606
+ "visual.encoder.layers.23.self_attn.proj.bias": "model-00004-of-00004.safetensors",
607
+ "visual.encoder.layers.23.self_attn.proj.weight": "model-00004-of-00004.safetensors",
608
+ "visual.encoder.layers.23.self_attn.qkv.bias": "model-00004-of-00004.safetensors",
609
+ "visual.encoder.layers.23.self_attn.qkv.weight": "model-00004-of-00004.safetensors",
610
+ "visual.encoder.layers.3.layer_norm1.bias": "model-00004-of-00004.safetensors",
611
+ "visual.encoder.layers.3.layer_norm1.weight": "model-00004-of-00004.safetensors",
612
+ "visual.encoder.layers.3.layer_norm2.bias": "model-00004-of-00004.safetensors",
613
+ "visual.encoder.layers.3.layer_norm2.weight": "model-00004-of-00004.safetensors",
614
+ "visual.encoder.layers.3.mlp.fc1.bias": "model-00004-of-00004.safetensors",
615
+ "visual.encoder.layers.3.mlp.fc1.weight": "model-00004-of-00004.safetensors",
616
+ "visual.encoder.layers.3.mlp.fc2.bias": "model-00004-of-00004.safetensors",
617
+ "visual.encoder.layers.3.mlp.fc2.weight": "model-00004-of-00004.safetensors",
618
+ "visual.encoder.layers.3.self_attn.proj.bias": "model-00004-of-00004.safetensors",
619
+ "visual.encoder.layers.3.self_attn.proj.weight": "model-00004-of-00004.safetensors",
620
+ "visual.encoder.layers.3.self_attn.qkv.bias": "model-00004-of-00004.safetensors",
621
+ "visual.encoder.layers.3.self_attn.qkv.weight": "model-00004-of-00004.safetensors",
622
+ "visual.encoder.layers.4.layer_norm1.bias": "model-00004-of-00004.safetensors",
623
+ "visual.encoder.layers.4.layer_norm1.weight": "model-00004-of-00004.safetensors",
624
+ "visual.encoder.layers.4.layer_norm2.bias": "model-00004-of-00004.safetensors",
625
+ "visual.encoder.layers.4.layer_norm2.weight": "model-00004-of-00004.safetensors",
626
+ "visual.encoder.layers.4.mlp.fc1.bias": "model-00004-of-00004.safetensors",
627
+ "visual.encoder.layers.4.mlp.fc1.weight": "model-00004-of-00004.safetensors",
628
+ "visual.encoder.layers.4.mlp.fc2.bias": "model-00004-of-00004.safetensors",
629
+ "visual.encoder.layers.4.mlp.fc2.weight": "model-00004-of-00004.safetensors",
630
+ "visual.encoder.layers.4.self_attn.proj.bias": "model-00004-of-00004.safetensors",
631
+ "visual.encoder.layers.4.self_attn.proj.weight": "model-00004-of-00004.safetensors",
632
+ "visual.encoder.layers.4.self_attn.qkv.bias": "model-00004-of-00004.safetensors",
633
+ "visual.encoder.layers.4.self_attn.qkv.weight": "model-00004-of-00004.safetensors",
634
+ "visual.encoder.layers.5.layer_norm1.bias": "model-00004-of-00004.safetensors",
635
+ "visual.encoder.layers.5.layer_norm1.weight": "model-00004-of-00004.safetensors",
636
+ "visual.encoder.layers.5.layer_norm2.bias": "model-00004-of-00004.safetensors",
637
+ "visual.encoder.layers.5.layer_norm2.weight": "model-00004-of-00004.safetensors",
638
+ "visual.encoder.layers.5.mlp.fc1.bias": "model-00004-of-00004.safetensors",
639
+ "visual.encoder.layers.5.mlp.fc1.weight": "model-00004-of-00004.safetensors",
640
+ "visual.encoder.layers.5.mlp.fc2.bias": "model-00004-of-00004.safetensors",
641
+ "visual.encoder.layers.5.mlp.fc2.weight": "model-00004-of-00004.safetensors",
642
+ "visual.encoder.layers.5.self_attn.proj.bias": "model-00004-of-00004.safetensors",
643
+ "visual.encoder.layers.5.self_attn.proj.weight": "model-00004-of-00004.safetensors",
644
+ "visual.encoder.layers.5.self_attn.qkv.bias": "model-00004-of-00004.safetensors",
645
+ "visual.encoder.layers.5.self_attn.qkv.weight": "model-00004-of-00004.safetensors",
646
+ "visual.encoder.layers.6.layer_norm1.bias": "model-00004-of-00004.safetensors",
647
+ "visual.encoder.layers.6.layer_norm1.weight": "model-00004-of-00004.safetensors",
648
+ "visual.encoder.layers.6.layer_norm2.bias": "model-00004-of-00004.safetensors",
649
+ "visual.encoder.layers.6.layer_norm2.weight": "model-00004-of-00004.safetensors",
650
+ "visual.encoder.layers.6.mlp.fc1.bias": "model-00004-of-00004.safetensors",
651
+ "visual.encoder.layers.6.mlp.fc1.weight": "model-00004-of-00004.safetensors",
652
+ "visual.encoder.layers.6.mlp.fc2.bias": "model-00004-of-00004.safetensors",
653
+ "visual.encoder.layers.6.mlp.fc2.weight": "model-00004-of-00004.safetensors",
654
+ "visual.encoder.layers.6.self_attn.proj.bias": "model-00004-of-00004.safetensors",
655
+ "visual.encoder.layers.6.self_attn.proj.weight": "model-00004-of-00004.safetensors",
656
+ "visual.encoder.layers.6.self_attn.qkv.bias": "model-00004-of-00004.safetensors",
657
+ "visual.encoder.layers.6.self_attn.qkv.weight": "model-00004-of-00004.safetensors",
658
+ "visual.encoder.layers.7.layer_norm1.bias": "model-00004-of-00004.safetensors",
659
+ "visual.encoder.layers.7.layer_norm1.weight": "model-00004-of-00004.safetensors",
660
+ "visual.encoder.layers.7.layer_norm2.bias": "model-00004-of-00004.safetensors",
661
+ "visual.encoder.layers.7.layer_norm2.weight": "model-00004-of-00004.safetensors",
662
+ "visual.encoder.layers.7.mlp.fc1.bias": "model-00004-of-00004.safetensors",
663
+ "visual.encoder.layers.7.mlp.fc1.weight": "model-00004-of-00004.safetensors",
664
+ "visual.encoder.layers.7.mlp.fc2.bias": "model-00004-of-00004.safetensors",
665
+ "visual.encoder.layers.7.mlp.fc2.weight": "model-00004-of-00004.safetensors",
666
+ "visual.encoder.layers.7.self_attn.proj.bias": "model-00004-of-00004.safetensors",
667
+ "visual.encoder.layers.7.self_attn.proj.weight": "model-00004-of-00004.safetensors",
668
+ "visual.encoder.layers.7.self_attn.qkv.bias": "model-00004-of-00004.safetensors",
669
+ "visual.encoder.layers.7.self_attn.qkv.weight": "model-00004-of-00004.safetensors",
670
+ "visual.encoder.layers.8.layer_norm1.bias": "model-00004-of-00004.safetensors",
671
+ "visual.encoder.layers.8.layer_norm1.weight": "model-00004-of-00004.safetensors",
672
+ "visual.encoder.layers.8.layer_norm2.bias": "model-00004-of-00004.safetensors",
673
+ "visual.encoder.layers.8.layer_norm2.weight": "model-00004-of-00004.safetensors",
674
+ "visual.encoder.layers.8.mlp.fc1.bias": "model-00004-of-00004.safetensors",
675
+ "visual.encoder.layers.8.mlp.fc1.weight": "model-00004-of-00004.safetensors",
676
+ "visual.encoder.layers.8.mlp.fc2.bias": "model-00004-of-00004.safetensors",
677
+ "visual.encoder.layers.8.mlp.fc2.weight": "model-00004-of-00004.safetensors",
678
+ "visual.encoder.layers.8.self_attn.proj.bias": "model-00004-of-00004.safetensors",
679
+ "visual.encoder.layers.8.self_attn.proj.weight": "model-00004-of-00004.safetensors",
680
+ "visual.encoder.layers.8.self_attn.qkv.bias": "model-00004-of-00004.safetensors",
681
+ "visual.encoder.layers.8.self_attn.qkv.weight": "model-00004-of-00004.safetensors",
682
+ "visual.encoder.layers.9.layer_norm1.bias": "model-00004-of-00004.safetensors",
683
+ "visual.encoder.layers.9.layer_norm1.weight": "model-00004-of-00004.safetensors",
684
+ "visual.encoder.layers.9.layer_norm2.bias": "model-00004-of-00004.safetensors",
685
+ "visual.encoder.layers.9.layer_norm2.weight": "model-00004-of-00004.safetensors",
686
+ "visual.encoder.layers.9.mlp.fc1.bias": "model-00004-of-00004.safetensors",
687
+ "visual.encoder.layers.9.mlp.fc1.weight": "model-00004-of-00004.safetensors",
688
+ "visual.encoder.layers.9.mlp.fc2.bias": "model-00004-of-00004.safetensors",
689
+ "visual.encoder.layers.9.mlp.fc2.weight": "model-00004-of-00004.safetensors",
690
+ "visual.encoder.layers.9.self_attn.proj.bias": "model-00004-of-00004.safetensors",
691
+ "visual.encoder.layers.9.self_attn.proj.weight": "model-00004-of-00004.safetensors",
692
+ "visual.encoder.layers.9.self_attn.qkv.bias": "model-00004-of-00004.safetensors",
693
+ "visual.encoder.layers.9.self_attn.qkv.weight": "model-00004-of-00004.safetensors",
694
+ "visual.layernorm_pre.bias": "model-00004-of-00004.safetensors",
695
+ "visual.layernorm_pre.weight": "model-00004-of-00004.safetensors",
696
+ "visual.merger.ln_q.bias": "model-00004-of-00004.safetensors",
697
+ "visual.merger.ln_q.weight": "model-00004-of-00004.safetensors",
698
+ "visual.merger.mlp.0.bias": "model-00004-of-00004.safetensors",
699
+ "visual.merger.mlp.0.weight": "model-00004-of-00004.safetensors",
700
+ "visual.merger.mlp.2.bias": "model-00004-of-00004.safetensors",
701
+ "visual.merger.mlp.2.weight": "model-00004-of-00004.safetensors"
702
+ }
703
+ }
modeling_llava_onevision2.py ADDED
@@ -0,0 +1,1888 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dataclasses import dataclass
2
+ from typing import Any, Optional, Union
3
+
4
+ import torch
5
+ import torch.nn as nn
6
+ import torch.nn.functional as F
7
+ from torch.nn import LayerNorm
8
+
9
+ from transformers import AutoModel
10
+ from transformers.cache_utils import Cache
11
+ from transformers.generation import GenerationMixin
12
+ from transformers.modeling_outputs import BaseModelOutput, BaseModelOutputWithPooling, ModelOutput
13
+ from transformers.modeling_utils import PreTrainedModel
14
+ from transformers.models.siglip.modeling_siglip import SiglipMLP
15
+ from transformers.processing_utils import Unpack
16
+ from transformers.utils import (
17
+ TransformersKwargs,
18
+ auto_docstring,
19
+ can_return_tuple,
20
+ is_flash_attn_2_available,
21
+ replace_return_docstrings,
22
+ )
23
+
24
+ from .configuration_llava_onevision2 import LlavaOnevision2Config, LlavaOnevision2VisionConfig
25
+
26
+
27
+ if is_flash_attn_2_available():
28
+ from flash_attn import flash_attn_func, flash_attn_varlen_func
29
+
30
+
31
+ @dataclass
32
+ @auto_docstring(
33
+ custom_intro="""
34
+ Base class for Llava-Onevision-1.5 outputs, with hidden states and attentions.
35
+ """
36
+ )
37
+ class LlavaOnevision2ModelOutputWithPast(ModelOutput):
38
+ r"""
39
+ past_key_values (`Cache`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
40
+ It is a [`~cache_utils.Cache`] instance. For more details, see our [kv cache guide](https://huggingface.co/docs/transformers/en/kv_cache).
41
+
42
+ Contains pre-computed hidden-states (key and values in the self-attention blocks) that can be used (see
43
+ `past_key_values` input) to speed up sequential decoding.
44
+ """
45
+
46
+ last_hidden_state: Optional[torch.FloatTensor] = None
47
+ past_key_values: Optional[Cache] = None
48
+ hidden_states: Optional[tuple[torch.FloatTensor]] = None
49
+ attentions: Optional[tuple[torch.FloatTensor]] = None
50
+
51
+
52
+ @dataclass
53
+ @auto_docstring(
54
+ custom_intro="""
55
+ Base class for Llava-Onevision-1.5 causal language model (or autoregressive) outputs.
56
+ """
57
+ )
58
+ class LlavaOnevision2CausalLMOutputWithPast(ModelOutput):
59
+ r"""
60
+ loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
61
+ Language modeling loss (for next-token prediction).
62
+ logits (`torch.FloatTensor` of shape `(batch_size, sequence_length, config.vocab_size)`):
63
+ Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).
64
+ past_key_values (`Cache`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
65
+ It is a [`~cache_utils.Cache`] instance. For more details, see our [kv cache guide](https://huggingface.co/docs/transformers/en/kv_cache).
66
+
67
+ Contains pre-computed hidden-states (key and values in the self-attention blocks) that can be used (see
68
+ `past_key_values` input) to speed up sequential decoding.
69
+ """
70
+
71
+ loss: Optional[torch.FloatTensor] = None
72
+ logits: Optional[torch.FloatTensor] = None
73
+ past_key_values: Optional[Cache] = None
74
+ hidden_states: Optional[tuple[torch.FloatTensor]] = None
75
+ attentions: Optional[tuple[torch.FloatTensor]] = None
76
+
77
+
78
+ # ---------------------------------------------------------------------------
79
+ # Vision Rotary Embedding
80
+ # ---------------------------------------------------------------------------
81
+
82
+
83
+ class VisionRotaryEmbedding(nn.Module):
84
+ """
85
+ 3D (T,H,W) Rotary frequency constructor with 4:6:6 split.
86
+ Supports both grid_thw-based and explicit position-based RoPE computation.
87
+ """
88
+
89
+ def __init__(self, config: LlavaOnevision2VisionConfig):
90
+ super().__init__()
91
+ head_dim = config.hidden_size // config.num_attention_heads
92
+ base = config.rope_theta
93
+
94
+ assert head_dim % 2 == 0, "head_dim must be even for rotary."
95
+ assert head_dim % 16 == 0, "head_dim must be divisible by 16."
96
+ half = head_dim // 2
97
+ assert half % 16 == 0, "head_dim//2 must also be divisible by 16 to split into 4:6:6."
98
+
99
+ self.head_dim = head_dim
100
+ self.half = half
101
+
102
+ # 4:6:6 split for T:H:W
103
+ unit = half // 16
104
+ self.t_size = 4 * unit
105
+ self.h_size = 6 * unit
106
+ self.w_size = 6 * unit
107
+
108
+ self.register_buffer(
109
+ "inv_freq_t",
110
+ 1.0 / (base ** (torch.arange(self.t_size, dtype=torch.float32) / self.t_size)),
111
+ persistent=False,
112
+ )
113
+ self.register_buffer(
114
+ "inv_freq_h",
115
+ 1.0 / (base ** (torch.arange(self.h_size, dtype=torch.float32) / self.h_size)),
116
+ persistent=False,
117
+ )
118
+ self.register_buffer(
119
+ "inv_freq_w",
120
+ 1.0 / (base ** (torch.arange(self.w_size, dtype=torch.float32) / self.w_size)),
121
+ persistent=False,
122
+ )
123
+
124
+ def forward(self, grid_thw: torch.Tensor) -> torch.Tensor:
125
+ """
126
+ Compute rotary position embeddings from grid_thw (Qwen2VL style).
127
+
128
+ Args:
129
+ grid_thw: [num_samples, 3] tensor with [t, h, w] for each sample
130
+
131
+ Returns:
132
+ freqs: [total_seq_len, half] tensor of position frequencies
133
+ """
134
+ device = grid_thw.device
135
+ inv_t = self.inv_freq_t.to(device=device)
136
+ inv_h = self.inv_freq_h.to(device=device)
137
+ inv_w = self.inv_freq_w.to(device=device)
138
+
139
+ all_freqs = []
140
+ for sample_thw in grid_thw:
141
+ t, h, w = sample_thw[0].item(), sample_thw[1].item(), sample_thw[2].item()
142
+
143
+ # Compute frequency tables
144
+ ft = torch.outer(torch.arange(t, device=device, dtype=torch.float32), inv_t)
145
+ fh = torch.outer(torch.arange(h, device=device, dtype=torch.float32), inv_h)
146
+ fw = torch.outer(torch.arange(w, device=device, dtype=torch.float32), inv_w)
147
+
148
+ # Build position indices for this sample
149
+ t_ids = torch.arange(t, device=device).repeat_interleave(h * w)
150
+ h_ids = torch.arange(h, device=device).repeat_interleave(w).repeat(t)
151
+ w_ids = torch.arange(w, device=device).repeat(h).repeat(t)
152
+
153
+ # Concatenate frequencies: [seq_len, half]
154
+ sample_freqs = torch.cat([ft[t_ids], fh[h_ids], fw[w_ids]], dim=-1)
155
+ all_freqs.append(sample_freqs)
156
+
157
+ return torch.cat(all_freqs, dim=0)
158
+
159
+ def forward_from_positions(self, patch_positions: torch.Tensor) -> torch.Tensor:
160
+ """
161
+ Compute rotary position embeddings from explicit patch positions.
162
+
163
+ Args:
164
+ patch_positions: [seq_len, 3] tensor with [t, h, w] positions for each patch
165
+
166
+ Returns:
167
+ freqs: [seq_len, half] tensor of position frequencies
168
+ """
169
+ device = patch_positions.device
170
+ inv_t = self.inv_freq_t.to(device=device)
171
+ inv_h = self.inv_freq_h.to(device=device)
172
+ inv_w = self.inv_freq_w.to(device=device)
173
+
174
+ t_pos = patch_positions[:, 0].float()
175
+ h_pos = patch_positions[:, 1].float()
176
+ w_pos = patch_positions[:, 2].float()
177
+
178
+ ft = torch.outer(t_pos, inv_t)
179
+ fh = torch.outer(h_pos, inv_h)
180
+ fw = torch.outer(w_pos, inv_w)
181
+
182
+ return torch.cat([ft, fh, fw], dim=-1)
183
+
184
+ def forward_with_thw(self, t: int, h: int, w: int, device=None) -> torch.Tensor:
185
+ """
186
+ Compute rotary position embeddings from explicit t, h, w dimensions.
187
+
188
+ Args:
189
+ t: Number of temporal frames
190
+ h: Number of height patches
191
+ w: Number of width patches
192
+ device: Target device
193
+
194
+ Returns:
195
+ freqs: [t*h*w, half] tensor of position frequencies
196
+ """
197
+ if device is None:
198
+ device = self.inv_freq_t.device
199
+
200
+ inv_t = self.inv_freq_t.to(device=device)
201
+ inv_h = self.inv_freq_h.to(device=device)
202
+ inv_w = self.inv_freq_w.to(device=device)
203
+
204
+ ft = torch.outer(torch.arange(t, device=device, dtype=torch.float32), inv_t)
205
+ fh = torch.outer(torch.arange(h, device=device, dtype=torch.float32), inv_h)
206
+ fw = torch.outer(torch.arange(w, device=device, dtype=torch.float32), inv_w)
207
+
208
+ t_ids = torch.arange(t, device=device).repeat_interleave(h * w)
209
+ h_ids = torch.arange(h, device=device).repeat_interleave(w).repeat(t)
210
+ w_ids = torch.arange(w, device=device).repeat(h).repeat(t)
211
+
212
+ freqs = torch.cat([ft[t_ids], fh[h_ids], fw[w_ids]], dim=-1)
213
+ return freqs
214
+
215
+
216
+ # ---------------------------------------------------------------------------
217
+ # Patch Embedding
218
+ # ---------------------------------------------------------------------------
219
+
220
+
221
+ class OneVisionEncoderEmbeddings(nn.Module):
222
+ """
223
+ Patch embedding layer that converts pre-processed patches to embeddings.
224
+
225
+ This module is designed to receive patches that have already been extracted
226
+ and arranged by the Qwen2VL image processor in 2x2 block spatial order.
227
+
228
+ Input format: [total_patches, num_channels, patch_size, patch_size]
229
+ Output format: [total_patches, embed_dim]
230
+ """
231
+
232
+ def __init__(self, config: LlavaOnevision2VisionConfig):
233
+ super().__init__()
234
+ self.config = config
235
+ self.embed_dim = config.hidden_size
236
+ self.image_size = config.image_size
237
+ self.patch_size = config.patch_size
238
+ self.in_channels = config.num_channels
239
+
240
+ self.patch_embedding = nn.Conv2d(
241
+ in_channels=config.num_channels,
242
+ out_channels=self.embed_dim,
243
+ kernel_size=self.patch_size,
244
+ stride=self.patch_size,
245
+ bias=False,
246
+ )
247
+
248
+ def forward(self, hidden_states: torch.FloatTensor) -> torch.Tensor:
249
+ target_dtype = self.patch_embedding.weight.dtype
250
+ hidden_states = hidden_states.view(-1, self.in_channels, self.patch_size, self.patch_size)
251
+ hidden_states = self.patch_embedding(hidden_states.to(dtype=target_dtype)).view(-1, self.embed_dim)
252
+
253
+ return hidden_states
254
+
255
+
256
+ # ---------------------------------------------------------------------------
257
+ # Patch Merger
258
+ # ---------------------------------------------------------------------------
259
+
260
+
261
+ class LlavaOnevision2VisionPatchMerger(nn.Module):
262
+ """
263
+ Patch merger that merges spatial_merge_size x spatial_merge_size patches into one.
264
+
265
+ This module is designed to work with Qwen2VL-style patch processing where patches
266
+ are already arranged in 2x2 block order by the image processor.
267
+ """
268
+
269
+ def __init__(
270
+ self,
271
+ dim: int,
272
+ context_dim: int,
273
+ spatial_merge_size: int = 2,
274
+ layer_norm_eps: float = 1e-05,
275
+ use_patch_position_encoding: bool = False,
276
+ patch_position_encoding_type: str = "absolute",
277
+ max_position_embeddings: int = 8192,
278
+ ) -> None:
279
+ super().__init__()
280
+ self.hidden_size = context_dim * (spatial_merge_size**2)
281
+ self.ln_q = LayerNorm(context_dim, eps=layer_norm_eps)
282
+ self.mlp = nn.Sequential(
283
+ nn.Linear(self.hidden_size, self.hidden_size),
284
+ nn.GELU(),
285
+ nn.Linear(self.hidden_size, dim),
286
+ )
287
+ self.spatial_merge_size = spatial_merge_size
288
+ self.use_patch_position_encoding = use_patch_position_encoding
289
+ self.patch_position_encoding_type = patch_position_encoding_type
290
+
291
+ if self.use_patch_position_encoding:
292
+ if self.patch_position_encoding_type != "absolute":
293
+ raise ValueError(
294
+ f"Unknown patch_position_encoding_type: {self.patch_position_encoding_type}. "
295
+ "Only 'absolute' is supported."
296
+ )
297
+ self.pos_emb_h = nn.Embedding(max_position_embeddings, dim)
298
+ self.pos_emb_w = nn.Embedding(max_position_embeddings, dim)
299
+
300
+ def forward(self, x: torch.Tensor, patch_positions: Optional[torch.Tensor] = None) -> torch.Tensor:
301
+ """
302
+ Merge patches from Qwen2VL-style input.
303
+
304
+ The input patches are already arranged in 2x2 block order by the image processor,
305
+ so we simply need to apply LayerNorm, reshape, and project through MLP.
306
+
307
+ Args:
308
+ x: Input tensor of shape [batch_size, seq_len, hidden_size] or [seq_len, hidden_size]
309
+ where seq_len = t * h * w (patches in 2x2 block order)
310
+
311
+ Returns:
312
+ Merged tensor of shape [batch_size, seq_len // spatial_merge_size^2, dim]
313
+ or [seq_len // spatial_merge_size^2, dim]
314
+ """
315
+ if patch_positions is not None and patch_positions.dim() == 3:
316
+ patch_positions = patch_positions.squeeze(0)
317
+
318
+ x = self.ln_q(x).view(-1, self.hidden_size)
319
+ x = self.mlp(x)
320
+
321
+ if self.use_patch_position_encoding and patch_positions is not None:
322
+ pp = patch_positions.view(-1, self.spatial_merge_size**2, 3)
323
+ pp = pp[:, 0, :]
324
+ pp = (pp // self.spatial_merge_size).long()
325
+
326
+ x = x + self.pos_emb_h(pp[:, 1]) + self.pos_emb_w(pp[:, 2])
327
+
328
+ return x
329
+
330
+
331
+ def rotate_half(x):
332
+ """
333
+ Interleaved rotation to match Source model's implementation.
334
+ (x1, x2, x3, x4) -> (-x2, x1, -x4, x3)
335
+ """
336
+ x_even = x[..., ::2]
337
+ x_odd = x[..., 1::2]
338
+ return torch.stack((-x_odd, x_even), dim=-1).flatten(-2)
339
+
340
+
341
+ def get_norm_layer(config):
342
+ if config.layer_norm_type == "rms_norm":
343
+ return nn.RMSNorm(config.hidden_size, eps=config.layer_norm_eps)
344
+ else:
345
+ return nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
346
+
347
+
348
+ def apply_rotary_pos_emb(q, k, freqs):
349
+ # q, k: (B, H, L, D)
350
+ # freqs: (B, L, D)
351
+ orig_q_dtype = q.dtype
352
+ orig_k_dtype = k.dtype
353
+ q, k = q.float(), k.float()
354
+ # We need to broadcast freqs to match heads
355
+ # (B, L, D) -> (B, 1, L, D)
356
+ # Keep the same dtype as q, k to avoid memory doubling from float32 promotion
357
+ cos = freqs.cos().unsqueeze(1).float()
358
+ sin = freqs.sin().unsqueeze(1).float()
359
+
360
+ q_embed = (q * cos) + (rotate_half(q) * sin)
361
+ k_embed = (k * cos) + (rotate_half(k) * sin)
362
+ q_embed = q_embed.to(orig_q_dtype)
363
+ k_embed = k_embed.to(orig_k_dtype)
364
+ return q_embed, k_embed
365
+
366
+
367
+ def convert_rope_to_block_layout(
368
+ freqs: torch.Tensor, t: int, h: int, w: int, spatial_merge_size: int = 2
369
+ ) -> torch.Tensor:
370
+ """
371
+ Convert RoPE from row-major order (1x1 layout) to 2x2 block layout.
372
+
373
+ The image processor arranges patches in 2x2 blocks when spatial_merge_size=2:
374
+ - Row-major order: [p(0,0), p(0,1), p(0,2), p(0,3), ..., p(1,0), p(1,1), ...]
375
+ - Block order: [p(0,0), p(0,1), p(1,0), p(1,1)], [p(0,2), p(0,3), p(1,2), p(1,3)], ...
376
+
377
+ Args:
378
+ freqs: RoPE frequencies in row-major order, shape [t*h*w, half]
379
+ t: temporal dimension
380
+ h: height (unmerged patch count)
381
+ w: width (unmerged patch count)
382
+ spatial_merge_size: size of spatial merge blocks (default: 2)
383
+
384
+ Returns:
385
+ torch.Tensor: RoPE frequencies in 2x2 block order, same shape [t*h*w, half]
386
+ """
387
+ sms = spatial_merge_size
388
+ if sms == 1:
389
+ return freqs
390
+
391
+ half = freqs.shape[-1]
392
+
393
+ # freqs shape: [t*h*w, half]
394
+ # Reshape to [t, h, w, half]
395
+ freqs = freqs.view(t, h, w, half)
396
+
397
+ # Calculate merged dimensions
398
+ h_merged = h // sms
399
+ w_merged = w // sms
400
+
401
+ # Reshape to [t, h_merged, sms, w_merged, sms, half]
402
+ freqs = freqs.view(t, h_merged, sms, w_merged, sms, half)
403
+
404
+ # Permute to [t, h_merged, w_merged, sms_h, sms_w, half] - 2x2 block order
405
+ freqs = freqs.permute(0, 1, 3, 2, 4, 5).contiguous()
406
+
407
+ # Reshape back to [t*h*w, half]
408
+ freqs = freqs.view(t * h * w, half)
409
+
410
+ return freqs
411
+
412
+
413
+ def convert_rope_to_block_layout_by_positions(
414
+ freqs: torch.Tensor,
415
+ patch_positions: torch.Tensor,
416
+ spatial_merge_size: int = 2,
417
+ grid_thw: Optional[torch.Tensor] = None,
418
+ ) -> torch.Tensor:
419
+ """
420
+ Convert RoPE from row-major order to 2x2 block layout.
421
+
422
+ When grid_thw is provided, use it directly to determine the dense canvas/frame
423
+ dimensions (t, h, w) for the spatial reorder. This is correct for:
424
+ - Normal video: grid_thw = [[T, H, W]]
425
+ - Codec video: grid_thw = [[n_canvases, hb, wb]]
426
+ - Images: grid_thw = [[1, H1, W1], [1, H2, W2], ...]
427
+
428
+ The block layout reorder is purely spatial (standard raster -> 2x2 block raster)
429
+ and depends only on canvas (h, w), NOT on per-patch frame_id.
430
+
431
+ Falls back to position-based frame_id grouping only when grid_thw is not available.
432
+
433
+ Args:
434
+ freqs: RoPE frequencies in row-major order, shape [seq_len, half]
435
+ patch_positions: Patch positions tensor, shape [seq_len, 3] with [t, h, w] for each patch
436
+ spatial_merge_size: size of spatial merge blocks (default: 2)
437
+ grid_thw: Grid sizes tensor of shape [num_samples, 3] with [t, h, w] for each sample.
438
+
439
+ Returns:
440
+ torch.Tensor: RoPE frequencies in 2x2 block order, same shape [seq_len, half]
441
+ """
442
+ sms = spatial_merge_size
443
+ if sms == 1:
444
+ return freqs
445
+
446
+ # ---- Primary path: use grid_thw directly (correct for all cases) ----
447
+ if grid_thw is not None:
448
+ num_samples = grid_thw.shape[0]
449
+
450
+ # Fast path: single sample (most common)
451
+ if num_samples == 1:
452
+ t = grid_thw[0, 0].item()
453
+ h = grid_thw[0, 1].item()
454
+ w = grid_thw[0, 2].item()
455
+ return convert_rope_to_block_layout(freqs, t=t, h=h, w=w, spatial_merge_size=sms)
456
+
457
+ # Check if all samples share the same (h, w) — common for video frames
458
+ all_same_hw = (
459
+ torch.all(grid_thw[:, 1] == grid_thw[0, 1]).item()
460
+ and torch.all(grid_thw[:, 2] == grid_thw[0, 2]).item()
461
+ )
462
+ if all_same_hw:
463
+ total_t = grid_thw[:, 0].sum().item()
464
+ h = grid_thw[0, 1].item()
465
+ w = grid_thw[0, 2].item()
466
+ return convert_rope_to_block_layout(freqs, t=total_t, h=h, w=w, spatial_merge_size=sms)
467
+
468
+ # Slow path: different spatial sizes per sample (e.g. mixed image resolutions)
469
+ result = torch.empty_like(freqs)
470
+ offset = 0
471
+ for i in range(num_samples):
472
+ t = grid_thw[i, 0].item()
473
+ h = grid_thw[i, 1].item()
474
+ w = grid_thw[i, 2].item()
475
+ n = int(t * h * w)
476
+ result[offset:offset + n] = convert_rope_to_block_layout(
477
+ freqs[offset:offset + n], t=t, h=h, w=w, spatial_merge_size=sms
478
+ )
479
+ offset += n
480
+ return result
481
+
482
+ # ---- Fallback path: no grid_thw, group by frame_id from patch_positions ----
483
+ half = freqs.shape[-1]
484
+ seq_len = freqs.shape[0]
485
+
486
+ t_indices = patch_positions[:, 0]
487
+ unique_t, inverse_indices, counts = torch.unique_consecutive(t_indices, return_inverse=True, return_counts=True)
488
+ num_groups = unique_t.shape[0]
489
+
490
+ # Single image, square
491
+ if num_groups == 1:
492
+ hw = int(seq_len**0.5)
493
+ if hw * hw == seq_len:
494
+ return convert_rope_to_block_layout(freqs, t=1, h=hw, w=hw, spatial_merge_size=sms)
495
+
496
+ # All groups same size
497
+ first_count = counts[0].item()
498
+ all_same_size = torch.all(counts == first_count).item()
499
+
500
+ if all_same_size:
501
+ group_size = first_count
502
+ hw = int(group_size**0.5)
503
+ if hw * hw == group_size:
504
+ return convert_rope_to_block_layout(freqs, t=num_groups, h=hw, w=hw, spatial_merge_size=sms)
505
+
506
+ # Variable frame sizes
507
+ cum_counts = torch.cumsum(counts, dim=0)
508
+ start_indices = torch.cat([torch.tensor([0], device=counts.device), cum_counts[:-1]])
509
+ result_freqs = torch.empty_like(freqs)
510
+
511
+ for group_idx in range(num_groups):
512
+ start_idx = start_indices[group_idx].item()
513
+ group_size = counts[group_idx].item()
514
+ end_idx = start_idx + group_size
515
+
516
+ hw = int(group_size**0.5)
517
+ if hw * hw == group_size:
518
+ h, w = hw, hw
519
+ else:
520
+ h, w = _infer_hw_from_positions(patch_positions[start_idx:end_idx], sms)
521
+
522
+ result_freqs[start_idx:end_idx] = convert_rope_to_block_layout(
523
+ freqs[start_idx:end_idx], t=1, h=h, w=w, spatial_merge_size=sms
524
+ )
525
+
526
+ return result_freqs
527
+
528
+
529
+ def _infer_hw_from_positions(group_positions: torch.Tensor, spatial_merge_size: int = 2) -> tuple[int, int]:
530
+ """
531
+ Infer height and width from patch positions within a temporal group.
532
+
533
+ Args:
534
+ group_positions: Patch positions for one temporal group, shape [group_size, 3]
535
+ spatial_merge_size: size of spatial merge blocks
536
+
537
+ Returns:
538
+ tuple[int, int]: (height, width) of the spatial grid
539
+ """
540
+ # Get unique h and w values
541
+ h_values = group_positions[:, 1]
542
+ w_values = group_positions[:, 2]
543
+
544
+ h_unique = torch.unique(h_values)
545
+ w_unique = torch.unique(w_values)
546
+
547
+ h = h_unique.shape[0]
548
+ w = w_unique.shape[0]
549
+
550
+ # Validate dimensions are divisible by spatial_merge_size
551
+ assert h % spatial_merge_size == 0, f"Height {h} not divisible by {spatial_merge_size}"
552
+ assert w % spatial_merge_size == 0, f"Width {w} not divisible by {spatial_merge_size}"
553
+
554
+ return h, w
555
+
556
+
557
+ class OneVisionEncoderFlashAttention2(nn.Module):
558
+ """
559
+ Multi-headed attention with RoPE support using Flash Attention 2.
560
+ """
561
+
562
+ def __init__(self, config: LlavaOnevision2VisionConfig):
563
+ super().__init__()
564
+ self.config = config
565
+ self.embed_dim = config.hidden_size
566
+ self.num_heads = config.num_attention_heads
567
+ self.head_dim = self.embed_dim // self.num_heads
568
+ if self.head_dim * self.num_heads != self.embed_dim:
569
+ raise ValueError(
570
+ f"embed_dim must be divisible by num_heads (got `embed_dim`: {self.embed_dim} and `num_heads`: {self.num_heads})."
571
+ )
572
+
573
+ self.scale = self.head_dim**-0.5
574
+ self.dropout = config.attention_dropout
575
+ self.qkv = nn.Linear(self.embed_dim, self.embed_dim * 3)
576
+ self.proj = nn.Linear(self.embed_dim, self.embed_dim)
577
+
578
+ def forward(
579
+ self,
580
+ hidden_states: torch.Tensor,
581
+ attention_mask: Optional[torch.Tensor] = None,
582
+ rotary_pos_emb: Optional[torch.Tensor] = None,
583
+ output_attentions: bool = False,
584
+ cu_seqlens: Optional[torch.Tensor] = None,
585
+ max_seqlen: Optional[int] = None,
586
+ ) -> tuple[torch.Tensor, Optional[torch.Tensor]]:
587
+ """
588
+ Forward pass using Flash Attention 2.
589
+ """
590
+ batch_size, q_len, _ = hidden_states.size()
591
+ q, k, v = (
592
+ self.qkv(hidden_states)
593
+ .reshape(batch_size, q_len, 3, self.num_heads, self.head_dim)
594
+ .permute(2, 0, 1, 3, 4)
595
+ .unbind(0)
596
+ )
597
+
598
+ # Flash Attention requires (B, L, H, D) format
599
+ query_states = q
600
+ key_states = k
601
+ value_states = v
602
+
603
+ # Apply RoPE if provided
604
+ if rotary_pos_emb is not None:
605
+ # Transpose for RoPE application: (B, L, H, D) -> (B, H, L, D)
606
+ query_states = query_states.transpose(1, 2)
607
+ key_states = key_states.transpose(1, 2)
608
+ # NOTE: apply_rotary_pos_emb now ensures NO float32 cast happens
609
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, rotary_pos_emb)
610
+ # Transpose back: (B, H, L, D) -> (B, L, H, D)
611
+ query_states = query_states.transpose(1, 2)
612
+ key_states = key_states.transpose(1, 2)
613
+
614
+ # FIX: Removed the explicit float32 check and downcast.
615
+ # We assume input is already correct (bf16/fp16) thanks to RoPE fix.
616
+
617
+ if cu_seqlens is not None:
618
+ query_states = query_states.reshape(-1, self.num_heads, self.head_dim)
619
+ key_states = key_states.reshape(-1, self.num_heads, self.head_dim)
620
+ value_states = value_states.reshape(-1, self.num_heads, self.head_dim)
621
+
622
+ attn_output = flash_attn_varlen_func(
623
+ query_states,
624
+ key_states,
625
+ value_states,
626
+ cu_seqlens_q=cu_seqlens,
627
+ cu_seqlens_k=cu_seqlens,
628
+ max_seqlen_q=max_seqlen,
629
+ max_seqlen_k=max_seqlen,
630
+ dropout_p=self.dropout if self.training else 0.0,
631
+ softmax_scale=self.scale,
632
+ causal=False,
633
+ )
634
+ attn_output = attn_output.reshape(batch_size, q_len, self.embed_dim)
635
+
636
+ elif attention_mask is not None:
637
+ attn_mask = attention_mask
638
+ if attn_mask.dim() == 2:
639
+ attn_mask = attn_mask.unsqueeze(0)
640
+ if attn_mask.shape[0] == 1 and batch_size > 1:
641
+ attn_mask = attn_mask.expand(batch_size, -1, -1)
642
+ attn_mask = attn_mask.unsqueeze(1)
643
+
644
+ q_sdpa = query_states.transpose(1, 2)
645
+ k_sdpa = key_states.transpose(1, 2)
646
+ v_sdpa = value_states.transpose(1, 2)
647
+ attn_output = F.scaled_dot_product_attention(
648
+ q_sdpa,
649
+ k_sdpa,
650
+ v_sdpa,
651
+ attn_mask=attn_mask,
652
+ dropout_p=self.dropout if self.training else 0.0,
653
+ is_causal=False,
654
+ )
655
+ attn_output = attn_output.transpose(1, 2)
656
+ else:
657
+ # Flash Attention forward pass
658
+ attn_output = flash_attn_func(
659
+ query_states,
660
+ key_states,
661
+ value_states,
662
+ dropout_p=self.dropout if self.training else 0.0,
663
+ softmax_scale=self.scale,
664
+ causal=False,
665
+ )
666
+
667
+ # Reshape to (B, L, embed_dim)
668
+ attn_output = attn_output.reshape(batch_size, q_len, self.embed_dim)
669
+
670
+ # No extra casting here.
671
+ # attn_output = self.out_proj(attn_output)
672
+ attn_output = self.proj(attn_output)
673
+
674
+ return attn_output, None
675
+
676
+
677
+ class OneVisionEncoderEncoderLayer(nn.Module):
678
+ """Vision encoder layer with pre-norm and Flash Attention 2."""
679
+
680
+ def __init__(self, config: LlavaOnevision2VisionConfig):
681
+ super().__init__()
682
+ self.embed_dim = config.hidden_size
683
+ self.self_attn = OneVisionEncoderFlashAttention2(config)
684
+ self.layer_norm1 = get_norm_layer(config)
685
+ self.mlp = SiglipMLP(config)
686
+ self.layer_norm2 = get_norm_layer(config)
687
+
688
+ def forward(
689
+ self,
690
+ hidden_states: torch.Tensor,
691
+ attention_mask: Optional[torch.Tensor] = None,
692
+ rotary_pos_emb: Optional[torch.Tensor] = None,
693
+ output_attentions: bool = False,
694
+ cu_seqlens: Optional[torch.Tensor] = None,
695
+ max_seqlen: Optional[int] = None,
696
+ ) -> tuple[torch.Tensor, Optional[torch.Tensor]]:
697
+ residual = hidden_states
698
+ hidden_states = self.layer_norm1(hidden_states)
699
+
700
+ hidden_states, attn_weights = self.self_attn(
701
+ hidden_states=hidden_states,
702
+ attention_mask=attention_mask,
703
+ rotary_pos_emb=rotary_pos_emb,
704
+ output_attentions=output_attentions,
705
+ cu_seqlens=cu_seqlens,
706
+ max_seqlen=max_seqlen,
707
+ )
708
+ hidden_states = residual + hidden_states
709
+
710
+ residual = hidden_states
711
+ hidden_states = self.layer_norm2(hidden_states)
712
+ hidden_states = self.mlp(hidden_states)
713
+ hidden_states = residual + hidden_states
714
+
715
+ outputs = (hidden_states, attn_weights) if output_attentions else (hidden_states,)
716
+ return outputs
717
+
718
+
719
+ class OneVisionEncoderEncoder(nn.Module):
720
+ def __init__(self, config: LlavaOnevision2VisionConfig):
721
+ super().__init__()
722
+ self.config = config
723
+ self.layers = nn.ModuleList([OneVisionEncoderEncoderLayer(config) for _ in range(config.num_hidden_layers)])
724
+ # Gradient checkpointing support
725
+ self.gradient_checkpointing = False
726
+
727
+ def forward(
728
+ self,
729
+ hidden_states: torch.Tensor,
730
+ attention_mask: Optional[torch.Tensor] = None,
731
+ rotary_pos_emb: Optional[torch.Tensor] = None,
732
+ output_attentions: bool = False,
733
+ output_hidden_states: bool = False,
734
+ return_dict: bool = True,
735
+ cu_seqlens: Optional[torch.Tensor] = None,
736
+ max_seqlen: Optional[int] = None,
737
+ ) -> Union[tuple, BaseModelOutput]:
738
+ all_hidden_states = () if output_hidden_states else None
739
+ all_self_attentions = () if output_attentions else None
740
+
741
+ for layer in self.layers:
742
+ if output_hidden_states:
743
+ all_hidden_states = all_hidden_states + (hidden_states,)
744
+
745
+ if self.gradient_checkpointing and self.training:
746
+ layer_outputs = self._gradient_checkpointing_func(
747
+ layer.__call__,
748
+ hidden_states,
749
+ attention_mask,
750
+ rotary_pos_emb,
751
+ output_attentions,
752
+ cu_seqlens,
753
+ max_seqlen,
754
+ )
755
+ else:
756
+ layer_outputs = layer(
757
+ hidden_states,
758
+ attention_mask=attention_mask,
759
+ rotary_pos_emb=rotary_pos_emb,
760
+ output_attentions=output_attentions,
761
+ cu_seqlens=cu_seqlens,
762
+ max_seqlen=max_seqlen,
763
+ )
764
+
765
+ hidden_states = layer_outputs[0]
766
+
767
+ if output_attentions:
768
+ all_self_attentions = all_self_attentions + (layer_outputs[1],)
769
+
770
+ if output_hidden_states:
771
+ all_hidden_states = all_hidden_states + (hidden_states,)
772
+
773
+ if not return_dict:
774
+ return tuple(v for v in [hidden_states, all_hidden_states, all_self_attentions] if v is not None)
775
+
776
+ return BaseModelOutput(
777
+ last_hidden_state=hidden_states,
778
+ hidden_states=all_hidden_states,
779
+ attentions=all_self_attentions,
780
+ )
781
+
782
+ def forward_debug(
783
+ self,
784
+ hidden_states: torch.Tensor,
785
+ attention_mask: Optional[torch.Tensor] = None,
786
+ rotary_pos_emb: Optional[torch.Tensor] = None,
787
+ cu_seqlens: Optional[torch.Tensor] = None,
788
+ max_seqlen: Optional[int] = None,
789
+ ) -> dict:
790
+ """
791
+ Forward pass with layer-by-layer debug outputs for consistency checking.
792
+
793
+ Returns:
794
+ dict: Contains:
795
+ - 'input_hidden_states': Input to the encoder
796
+ - 'input_rotary_pos_emb': Rotary position embeddings input
797
+ - 'layer_outputs': Dict mapping layer index to output after that layer
798
+ - 'final_output': Final encoder output
799
+ """
800
+ output = {}
801
+
802
+ # Save input
803
+ output["input_hidden_states"] = hidden_states.clone()
804
+ if rotary_pos_emb is not None:
805
+ output["input_rotary_pos_emb"] = rotary_pos_emb.clone()
806
+
807
+ # Layer-by-layer outputs
808
+ layer_outputs = {}
809
+
810
+ for layer_idx, layer in enumerate(self.layers):
811
+ # Save input to this layer
812
+ layer_outputs[f"layer_{layer_idx}_input"] = hidden_states.clone()
813
+
814
+ # Forward through layer
815
+ layer_result = layer(
816
+ hidden_states,
817
+ attention_mask=attention_mask,
818
+ rotary_pos_emb=rotary_pos_emb,
819
+ output_attentions=False,
820
+ cu_seqlens=cu_seqlens,
821
+ max_seqlen=max_seqlen,
822
+ )
823
+ hidden_states = layer_result[0]
824
+
825
+ # Save output of this layer
826
+ layer_outputs[f"layer_{layer_idx}_output"] = hidden_states.clone()
827
+
828
+ output["layer_outputs"] = layer_outputs
829
+ output["final_output"] = hidden_states.clone()
830
+
831
+ return output
832
+
833
+
834
+ class LlavaOnevision2PreTrainedModel(PreTrainedModel):
835
+ config_class = LlavaOnevision2Config
836
+ base_model_prefix = "model"
837
+ supports_gradient_checkpointing = True
838
+ _supports_flash_attn_2 = True
839
+ _no_split_modules = ["OneVisionEncoderEncoderLayer"]
840
+ _skip_keys_device_placement = "past_key_values"
841
+ _supports_flash_attn = True
842
+ _supports_sdpa = True
843
+
844
+ def _init_weights(self, module):
845
+ super()._init_weights(module)
846
+ # Custom weight initialization can be added here if needed
847
+ # For LlavaOnevision2VisionPretrainedModel, we rely on default initialization
848
+
849
+
850
+ class Siglip2MultiheadAttentionPoolingHead(nn.Module):
851
+ """
852
+ Multi-Head Attention Pooling with a learned probe (PMA-style).
853
+ """
854
+
855
+ def __init__(self, config: LlavaOnevision2VisionConfig):
856
+ super().__init__()
857
+ self.embed_dim = config.hidden_size
858
+ self.probe = nn.Parameter(torch.randn(1, 1, config.hidden_size))
859
+ self.attention = nn.MultiheadAttention(config.hidden_size, config.num_attention_heads, batch_first=True)
860
+ self.norm = nn.RMSNorm(config.hidden_size, eps=config.layer_norm_eps)
861
+ self.mlp = SiglipMLP(config)
862
+
863
+ def forward(self, hidden_states):
864
+ batch_size = hidden_states.shape[0]
865
+ probe = self.probe.repeat(batch_size, 1, 1)
866
+
867
+ attn_output, _ = self.attention(probe, hidden_states, hidden_states)
868
+
869
+ residual = attn_output
870
+ attn_output = self.norm(attn_output)
871
+ attn_output = residual + self.mlp(attn_output)
872
+
873
+ return attn_output[:, 0]
874
+
875
+
876
+ # ---------------------------------------------------------------------------
877
+ # Vision Model
878
+ # ---------------------------------------------------------------------------
879
+
880
+
881
+ class LlavaOnevision2VisionPretrainedModel(LlavaOnevision2PreTrainedModel):
882
+ """
883
+ LLaVA-OneVision 2.0 Vision Model.
884
+
885
+ This vision model is designed to work with Qwen2VL-style image processing:
886
+ - Receives pre-processed patches in 2x2 block spatial order
887
+ - Applies RoPE with matching 2x2 block layout conversion
888
+ - Accepts explicit patch_positions for RoPE computation
889
+
890
+ Input format:
891
+ hidden_state: [total_patches, num_channels, patch_size, patch_size]
892
+ grid_thw: [num_samples, 3] with [t, h, w] for each sample
893
+ """
894
+
895
+ def __init__(self, config: LlavaOnevision2VisionConfig):
896
+ super().__init__(config)
897
+ self.config = config
898
+ self.spatial_merge_size = config.spatial_merge_size
899
+
900
+ # Vision components
901
+ self.embeddings = OneVisionEncoderEmbeddings(config)
902
+ self.layernorm_pre = get_norm_layer(config)
903
+ self.encoder = OneVisionEncoderEncoder(config)
904
+ self.video_rope = VisionRotaryEmbedding(config)
905
+
906
+ if config.use_head:
907
+ self.layernorm_post = get_norm_layer(config)
908
+ self.head = Siglip2MultiheadAttentionPoolingHead(config)
909
+ else:
910
+ self.layernorm_post = None
911
+ self.head = None
912
+
913
+ self.merger = LlavaOnevision2VisionPatchMerger(
914
+ dim=config.out_hidden_size,
915
+ context_dim=config.hidden_size,
916
+ spatial_merge_size=config.spatial_merge_size,
917
+ layer_norm_eps=config.layer_norm_eps,
918
+ use_patch_position_encoding=getattr(config, "use_patch_position_encoding", False),
919
+ patch_position_encoding_type=getattr(config, "patch_position_encoding_type", "absolute"),
920
+ max_position_embeddings=getattr(config, "max_position_embeddings", 8192),
921
+ )
922
+
923
+ self.post_init()
924
+
925
+ def _build_cu_seqlens(
926
+ self,
927
+ grid_thw: torch.Tensor,
928
+ total_patches: int,
929
+ fixed_t: Optional[int] = 4,
930
+ device: Optional[torch.device] = None,
931
+ ) -> tuple[torch.Tensor, int]:
932
+ if grid_thw is None or grid_thw.numel() == 0:
933
+ # Fallback for no grid_thw: treat as single sequence
934
+ return torch.tensor([0, total_patches], dtype=torch.int32, device=device), total_patches
935
+
936
+ if device is None:
937
+ device = grid_thw.device
938
+
939
+ cu_seqlens = [0]
940
+ max_seqlen = 0
941
+ total_entries = grid_thw.shape[0]
942
+ current_len = 0
943
+
944
+ # Calculate cumulative lengths: split sequences based on fixed_t if provided
945
+ for idx in range(total_entries):
946
+ t_val = grid_thw[idx, 0].item()
947
+ h_val = grid_thw[idx, 1].item()
948
+ w_val = grid_thw[idx, 2].item()
949
+
950
+ if fixed_t is not None and fixed_t > 0 and t_val > fixed_t:
951
+ # Split large t into chunks of fixed_t
952
+ num_full_windows = t_val // fixed_t
953
+ remainder = t_val % fixed_t
954
+
955
+ # Add full windows
956
+ for _ in range(num_full_windows):
957
+ chunk_patches = fixed_t * int(h_val) * int(w_val)
958
+ current_len += chunk_patches
959
+ max_seqlen = max(max_seqlen, chunk_patches)
960
+ cu_seqlens.append(current_len)
961
+
962
+ # Add remainder if any
963
+ if remainder > 0:
964
+ chunk_patches = remainder * int(h_val) * int(w_val)
965
+ current_len += chunk_patches
966
+ max_seqlen = max(max_seqlen, chunk_patches)
967
+ cu_seqlens.append(current_len)
968
+ else:
969
+ # Standard case: add as one chunk
970
+ chunk_patches = t_val * int(h_val) * int(w_val)
971
+ current_len += chunk_patches
972
+ max_seqlen = max(max_seqlen, chunk_patches)
973
+ cu_seqlens.append(current_len)
974
+
975
+ last_len = cu_seqlens[-1]
976
+ if last_len != total_patches:
977
+ raise ValueError(
978
+ "cu_seqlens calculation mismatch:\n"
979
+ f"- total_patches: {total_patches}\n"
980
+ f"- calculated total: {last_len}\n"
981
+ f"- grid_thw: {grid_thw}"
982
+ )
983
+
984
+ return torch.tensor(cu_seqlens, dtype=torch.int32, device=device), max_seqlen
985
+
986
+ def _build_block_attention_mask(
987
+ self,
988
+ grid_thw: torch.Tensor,
989
+ total_patches: int,
990
+ fixed_t: Optional[int] = 4,
991
+ device: Optional[torch.device] = None,
992
+ ) -> Optional[torch.Tensor]:
993
+ if grid_thw is None or grid_thw.numel() == 0:
994
+ return None
995
+
996
+ if device is None:
997
+ device = grid_thw.device
998
+
999
+ lengths = []
1000
+ total_entries = grid_thw.shape[0]
1001
+
1002
+ for idx in range(total_entries):
1003
+ t_val = grid_thw[idx, 0].item()
1004
+ h_val = grid_thw[idx, 1].item()
1005
+ w_val = grid_thw[idx, 2].item()
1006
+
1007
+ if fixed_t is not None and fixed_t > 0 and t_val > fixed_t:
1008
+ # Split large t into chunks of fixed_t
1009
+ num_full_windows = t_val // fixed_t
1010
+ remainder = t_val % fixed_t
1011
+
1012
+ # Add full windows
1013
+ for _ in range(num_full_windows):
1014
+ lengths.append(fixed_t * int(h_val) * int(w_val))
1015
+
1016
+ # Add remainder if any
1017
+ if remainder > 0:
1018
+ lengths.append(remainder * int(h_val) * int(w_val))
1019
+ else:
1020
+ lengths.append(t_val * int(h_val) * int(w_val))
1021
+
1022
+ total_len = sum(lengths)
1023
+ if total_len != total_patches:
1024
+ raise ValueError(
1025
+ "Block attention mask length mismatch:\n"
1026
+ f"- total_patches: {total_patches}\n"
1027
+ f"- total_len: {total_len}\n"
1028
+ f"- grid_thw: {grid_thw}"
1029
+ )
1030
+
1031
+ attn_mask = torch.ones((total_len, total_len), dtype=torch.bool, device=device)
1032
+ start = 0
1033
+ for size in lengths:
1034
+ end = start + size
1035
+ attn_mask[start:end, start:end] = False
1036
+ start = end
1037
+
1038
+ return attn_mask
1039
+
1040
+ @replace_return_docstrings(output_type=BaseModelOutputWithPooling, config_class=LlavaOnevision2VisionConfig)
1041
+ def forward(
1042
+ self,
1043
+ hidden_state: torch.Tensor,
1044
+ grid_thw: Optional[torch.Tensor] = None,
1045
+ patch_positions: Optional[torch.Tensor] = None,
1046
+ output_attentions: Optional[bool] = None,
1047
+ output_hidden_states: Optional[bool] = None,
1048
+ return_dict: Optional[bool] = None,
1049
+ skip_merger: Optional[bool] = False,
1050
+ ) -> Union[tuple, BaseModelOutputWithPooling]:
1051
+ r"""
1052
+ Forward pass for vision model.
1053
+
1054
+ This method accepts pre-processed patches from Qwen2VL image processor and applies
1055
+ RoPE (Rotary Position Embedding) in 2x2 block layout to match the spatial arrangement
1056
+ of patches.
1057
+
1058
+ Args:
1059
+ hidden_state: Pre-processed patches from Qwen2VL processor.
1060
+ Shape: [total_patches, num_channels, patch_size, patch_size]
1061
+ grid_thw: Grid sizes tensor of shape [num_samples, 3] with [t, h, w] for each sample.
1062
+ Required for computing RoPE and handling visible indices.
1063
+ patch_positions: Optional explicit patch positions for RoPE computation.
1064
+ output_attentions: Whether to return attention weights.
1065
+ output_hidden_states: Whether to return all hidden states.
1066
+ return_dict: Whether to return a ModelOutput instead of tuple.
1067
+ skip_merger: If True, skip patch merger (useful for consistency checking).
1068
+
1069
+ Returns:
1070
+ BaseModelOutputWithPooling with last_hidden_state containing merged features.
1071
+ """
1072
+ output_attentions = (
1073
+ output_attentions if output_attentions is not None else getattr(self.config, "output_attentions", False)
1074
+ )
1075
+ output_hidden_states = (
1076
+ output_hidden_states
1077
+ if output_hidden_states is not None
1078
+ else getattr(self.config, "output_hidden_states", False)
1079
+ )
1080
+ return_dict = return_dict if return_dict is not None else getattr(self.config, "use_return_dict", True)
1081
+
1082
+ # 1. Embeddings
1083
+ # Note: embeddings returns [total_patches, embed_dim], we need to add batch dimension
1084
+ hidden_states = self.embeddings(hidden_state)
1085
+ if hidden_states.dim() == 2:
1086
+ hidden_states = hidden_states.unsqueeze(0) # [1, total_patches, embed_dim]
1087
+ batch_size, total_patches, _ = hidden_states.shape
1088
+
1089
+ # 2. RoPE Construction
1090
+ # Get dimensions from grid_thw for block layout conversion
1091
+ if grid_thw is not None:
1092
+ t_frames = grid_thw[0, 0].item()
1093
+ height = grid_thw[0, 1].item()
1094
+ width = grid_thw[0, 2].item()
1095
+ else:
1096
+ # Fallback: infer from total_patches (assume single frame, square)
1097
+ t_frames = 1
1098
+ height = int(total_patches**0.5)
1099
+ width = height
1100
+
1101
+ if patch_positions is not None and patch_positions.dim() == 3:
1102
+ patch_positions = patch_positions.squeeze(0)
1103
+ freqs_visible = self.video_rope.forward_from_positions(patch_positions)
1104
+
1105
+ # Convert RoPE from row-major to block layout (matching Qwen2VL processor output)
1106
+ # Use position-based grouping for videos with variable frame sizes
1107
+ # Pass grid_thw for reliable h, w extraction (especially for non-square images)
1108
+ freqs_visible = convert_rope_to_block_layout_by_positions(
1109
+ freqs_visible, patch_positions, spatial_merge_size=2, grid_thw=grid_thw
1110
+ )
1111
+
1112
+ # Concatenate D/2 + D/2 -> D for applying rope
1113
+ freqs_visible = torch.cat([freqs_visible, freqs_visible], dim=-1)
1114
+ if freqs_visible.dim() == 2:
1115
+ freqs_visible = freqs_visible.unsqueeze(0)
1116
+
1117
+ # 3. Pre-Norm & Encoder
1118
+ hidden_states = self.layernorm_pre(hidden_states)
1119
+
1120
+ cu_seqlens, max_seqlen = self._build_cu_seqlens(
1121
+ grid_thw=grid_thw,
1122
+ total_patches=total_patches,
1123
+ fixed_t=getattr(self.config, "frame_windows_size", 4),
1124
+ device=hidden_states.device,
1125
+ )
1126
+
1127
+ encoder_outputs = self.encoder(
1128
+ hidden_states,
1129
+ attention_mask=None,
1130
+ rotary_pos_emb=freqs_visible,
1131
+ output_attentions=output_attentions,
1132
+ output_hidden_states=True, # Always get hidden states to use -2 layer
1133
+ return_dict=True,
1134
+ cu_seqlens=cu_seqlens,
1135
+ max_seqlen=max_seqlen,
1136
+ )
1137
+
1138
+ # Use second-to-last layer output for better feature representation
1139
+ if encoder_outputs.hidden_states is not None and len(encoder_outputs.hidden_states) >= 2 and not skip_merger:
1140
+ sequence_output = encoder_outputs.hidden_states[-1]
1141
+ else:
1142
+ sequence_output = encoder_outputs[0]
1143
+
1144
+ # Post-Norm
1145
+ if self.layernorm_post is not None:
1146
+ sequence_output = self.layernorm_post(sequence_output)
1147
+
1148
+ # Skip merger for consistency check with original ViT
1149
+ if skip_merger:
1150
+ pooled_output = None
1151
+ if self.head is not None:
1152
+ pooled_output = self.head(sequence_output)
1153
+
1154
+ if not return_dict:
1155
+ return (sequence_output, pooled_output) + (
1156
+ encoder_outputs.hidden_states if output_hidden_states else None,
1157
+ )
1158
+ return BaseModelOutputWithPooling(
1159
+ last_hidden_state=sequence_output,
1160
+ pooler_output=pooled_output,
1161
+ hidden_states=encoder_outputs.hidden_states if output_hidden_states else None,
1162
+ attentions=encoder_outputs.attentions if output_attentions else None,
1163
+ )
1164
+
1165
+ # Patch merger: input patches are already in 2x2 block order from Qwen2VL processor
1166
+ merged_output = self.merger(sequence_output, patch_positions=patch_positions)
1167
+
1168
+ if not return_dict:
1169
+ return (merged_output,) + (encoder_outputs.hidden_states if output_hidden_states else None,)
1170
+
1171
+ return BaseModelOutputWithPooling(
1172
+ last_hidden_state=merged_output,
1173
+ pooler_output=None,
1174
+ hidden_states=encoder_outputs.hidden_states if output_hidden_states else None,
1175
+ attentions=encoder_outputs.attentions if output_attentions else None,
1176
+ )
1177
+
1178
+ def forward_debug(
1179
+ self,
1180
+ hidden_state: torch.Tensor,
1181
+ grid_thw: torch.Tensor,
1182
+ patch_positions: Optional[torch.Tensor] = None,
1183
+ ) -> dict:
1184
+ """
1185
+ Debug version of forward pass that captures intermediate states.
1186
+
1187
+ Identical to forward() but saves intermediate outputs at key stages
1188
+ for debugging and consistency checking purposes.
1189
+
1190
+ Args:
1191
+ hidden_state: Pre-processed patches from Qwen2VL processor.
1192
+ Shape: [total_patches, num_channels, patch_size, patch_size]
1193
+ grid_thw: Grid sizes tensor of shape [num_samples, 3] with [t, h, w] for each sample.
1194
+ Required for computing RoPE and handling visible indices.
1195
+ patch_positions: Optional explicit patch positions for RoPE computation.
1196
+
1197
+ Returns:
1198
+ dict: Dictionary containing intermediate outputs:
1199
+ - "input_pixel_values": Input to the model
1200
+ - "after_patch_embed": Embeddings after patch projection
1201
+ - "rotary_pos_emb": Rotary position embeddings
1202
+ - "after_pre_layernorm": Embeddings after pre-normalization
1203
+ - "layer_outputs": Dict mapping layer index to input/output
1204
+ - "before_adapter": Final output before merger (same as after_decoder)
1205
+ - "after_merger": Output after patch merger
1206
+ """
1207
+ output = {}
1208
+
1209
+ # Store input for consistency checking
1210
+ output["input_pixel_values"] = hidden_state.clone()
1211
+ output["input_grid_thw"] = grid_thw.clone()
1212
+
1213
+ # 1. Embeddings
1214
+ # Note: embeddings returns [total_patches, embed_dim], we need to add batch dimension
1215
+ hidden_states = self.embeddings(hidden_state)
1216
+ if hidden_states.dim() == 2:
1217
+ hidden_states = hidden_states.unsqueeze(0) # [1, total_patches, embed_dim]
1218
+ output["after_patch_embed"] = hidden_states.clone()
1219
+
1220
+ batch_size, total_patches, _ = hidden_states.shape
1221
+
1222
+ # 2. RoPE Construction
1223
+ # Get dimensions from grid_thw for block layout conversion
1224
+ if grid_thw is not None:
1225
+ t_frames = grid_thw[0, 0].item()
1226
+ height = grid_thw[0, 1].item()
1227
+ width = grid_thw[0, 2].item()
1228
+
1229
+ if patch_positions is not None and patch_positions.dim() == 3:
1230
+ patch_positions = patch_positions.squeeze(0)
1231
+
1232
+ freqs_visible = self.video_rope.forward_from_positions(patch_positions)
1233
+
1234
+ # Convert RoPE from row-major to block layout (matching Qwen2VL processor output)
1235
+ # Use position-based grouping for videos with variable frame sizes
1236
+ # Pass grid_thw for reliable h, w extraction (especially for non-square images)
1237
+ freqs_visible = convert_rope_to_block_layout_by_positions(
1238
+ freqs_visible, patch_positions, spatial_merge_size=2, grid_thw=grid_thw
1239
+ )
1240
+
1241
+ # Concatenate D/2 + D/2 -> D for applying rope
1242
+ freqs_visible = torch.cat([freqs_visible, freqs_visible], dim=-1)
1243
+ if freqs_visible.dim() == 2:
1244
+ freqs_visible = freqs_visible.unsqueeze(0)
1245
+
1246
+ output["rotary_pos_emb"] = freqs_visible.clone()
1247
+
1248
+ # 3. Pre-Norm & Encoder
1249
+ hidden_states = self.layernorm_pre(hidden_states)
1250
+ output["after_pre_layernorm"] = hidden_states.clone()
1251
+
1252
+ cu_seqlens, max_seqlen = self._build_cu_seqlens(
1253
+ grid_thw=grid_thw,
1254
+ total_patches=total_patches,
1255
+ fixed_t=getattr(self.config, "frame_windows_size", 4),
1256
+ device=hidden_states.device,
1257
+ )
1258
+
1259
+ encoder_debug_output = self.encoder.forward_debug(
1260
+ hidden_states,
1261
+ attention_mask=None,
1262
+ rotary_pos_emb=freqs_visible,
1263
+ cu_seqlens=cu_seqlens,
1264
+ max_seqlen=max_seqlen,
1265
+ )
1266
+
1267
+ # Extract layer outputs
1268
+ output["layer_outputs"] = encoder_debug_output.get("layer_outputs", {})
1269
+
1270
+ # Use last layer output
1271
+ num_layers = len(self.encoder.layers)
1272
+ sequence_output = output["layer_outputs"][f"layer_{num_layers - 1}_output"]
1273
+
1274
+ # Post-Norm
1275
+ if self.layernorm_post is not None:
1276
+ sequence_output = self.layernorm_post(sequence_output)
1277
+
1278
+ output["before_adapter"] = sequence_output.clone()
1279
+
1280
+ # Patch merger
1281
+ merged_output = self.merger(sequence_output, patch_positions=patch_positions)
1282
+ output["after_merger"] = merged_output.clone()
1283
+
1284
+ return output
1285
+
1286
+
1287
+ @auto_docstring
1288
+ class LlavaOnevision2Model(LlavaOnevision2PreTrainedModel):
1289
+ base_model_prefix = ""
1290
+ _checkpoint_conversion_mapping = {"^model": "language_model"}
1291
+ # Reference: fix gemma3 grad acc #37208
1292
+ accepts_loss_kwargs = False
1293
+ config: LlavaOnevision2Config
1294
+ _no_split_modules = ["OneVisionEncoderEncoderLayer"]
1295
+
1296
+ def __init__(self, config: LlavaOnevision2Config):
1297
+ super().__init__(config)
1298
+ self.visual = LlavaOnevision2VisionPretrainedModel._from_config(config.vision_config)
1299
+ self.language_model = AutoModel.from_config(config.text_config)
1300
+ # Initialize weights and apply final processing
1301
+ self.post_init()
1302
+
1303
+ def get_input_embeddings(self):
1304
+ return self.language_model.get_input_embeddings()
1305
+
1306
+ def set_input_embeddings(self, value):
1307
+ self.language_model.set_input_embeddings(value)
1308
+
1309
+ def set_decoder(self, decoder):
1310
+ self.language_model = decoder
1311
+
1312
+ def get_decoder(self):
1313
+ return self.language_model
1314
+
1315
+ def get_video_features(
1316
+ self,
1317
+ pixel_values_videos: torch.FloatTensor,
1318
+ video_grid_thw: Optional[torch.LongTensor] = None,
1319
+ patch_positions=None,
1320
+ ):
1321
+ """
1322
+ Encodes videos into continuous embeddings that can be forwarded to the language model.
1323
+
1324
+ Args:
1325
+ pixel_values_videos: Pre-processed patches from Qwen2VL processor.
1326
+ `torch.FloatTensor` of shape `(total_patches, num_channels, patch_size, patch_size)`
1327
+ video_grid_thw (`torch.LongTensor` of shape `(num_videos, 3)`, *optional*):
1328
+ The temporal, height and width of feature shape of each video in LLM.
1329
+ """
1330
+ # Convert to correct dtype
1331
+ pixel_values_videos = pixel_values_videos.type(self.visual.embeddings.patch_embedding.weight.dtype)
1332
+
1333
+ # Forward through vision model with grid_thw
1334
+ vision_output = self.visual(pixel_values_videos, grid_thw=video_grid_thw, patch_positions=patch_positions)
1335
+
1336
+ # Extract the actual tensor from BaseModelOutputWithPooling
1337
+ if hasattr(vision_output, "last_hidden_state"):
1338
+ video_embeds = vision_output.last_hidden_state
1339
+ else:
1340
+ video_embeds = vision_output[0] # Fallback for tuple output
1341
+
1342
+ # Compute split sizes from video_grid_thw or from input shape
1343
+ if video_grid_thw is not None:
1344
+ split_sizes = (video_grid_thw.prod(-1) // self.visual.spatial_merge_size**2).tolist()
1345
+ else:
1346
+ # Compute from input shape
1347
+ batch_size = pixel_values_videos.shape[0]
1348
+ split_sizes = [video_embeds.shape[1]] * batch_size
1349
+
1350
+ # Split embeddings per video
1351
+ if len(split_sizes) > 1:
1352
+ video_embeds = torch.split(video_embeds.view(-1, video_embeds.shape[-1]), split_sizes)
1353
+ else:
1354
+ video_embeds = [video_embeds.view(-1, video_embeds.shape[-1])]
1355
+
1356
+ return video_embeds
1357
+
1358
+ def get_image_features(
1359
+ self, pixel_values, image_grid_thw: Optional[torch.LongTensor] = None, patch_positions=None
1360
+ ):
1361
+ """
1362
+ Encodes images into continuous embeddings that can be forwarded to the language model.
1363
+
1364
+ Args:
1365
+ pixel_values: Pre-processed patches from Qwen2VL processor.
1366
+ - `torch.FloatTensor` of shape `(total_patches, num_channels, patch_size, patch_size)`
1367
+ image_grid_thw (`torch.LongTensor` of shape `(num_images, 3)`, *optional*):
1368
+ The temporal, height and width of feature shape of each image in LLM.
1369
+ """
1370
+ # Standard format from Qwen2VL processor
1371
+ if pixel_values.dim() == 2:
1372
+ # Convert to correct dtype
1373
+ pixel_values = pixel_values.type(self.visual.embeddings.patch_embedding.weight.dtype)
1374
+
1375
+ # Forward through vision model with grid_thw
1376
+ vision_output = self.visual(pixel_values, grid_thw=image_grid_thw, patch_positions=patch_positions)
1377
+
1378
+ # Extract the actual tensor from BaseModelOutputWithPooling
1379
+ if hasattr(vision_output, "last_hidden_state"):
1380
+ image_embeds = vision_output.last_hidden_state
1381
+ else:
1382
+ image_embeds = vision_output[0]
1383
+
1384
+ # Compute split sizes from grid_thw
1385
+ if image_grid_thw is not None:
1386
+ split_sizes = (image_grid_thw.prod(-1) // self.visual.spatial_merge_size**2).tolist()
1387
+ else:
1388
+ # Fallback: assume single image
1389
+ split_sizes = [image_embeds.shape[0] if image_embeds.dim() == 2 else image_embeds.shape[1]]
1390
+
1391
+ # Split embeddings per image
1392
+ image_embeds_flat = image_embeds.view(-1, image_embeds.shape[-1])
1393
+ if len(split_sizes) > 1:
1394
+ image_embeds = list(torch.split(image_embeds_flat, split_sizes))
1395
+ else:
1396
+ image_embeds = [image_embeds_flat]
1397
+
1398
+ return image_embeds
1399
+ else:
1400
+ raise ValueError(
1401
+ f"Unsupported pixel_values shape: expected 4D tensor [total_patches, C, H, W], "
1402
+ f"got {pixel_values.shape if hasattr(pixel_values, 'shape') else type(pixel_values)}"
1403
+ )
1404
+
1405
+ def get_placeholder_mask(
1406
+ self,
1407
+ input_ids: torch.LongTensor,
1408
+ inputs_embeds: torch.FloatTensor,
1409
+ image_features: Optional[torch.FloatTensor] = None,
1410
+ video_features: Optional[torch.FloatTensor] = None,
1411
+ ):
1412
+ """
1413
+ Obtains multimodal placeholder mask from `input_ids` or `inputs_embeds`, and checks that the placeholder token count is
1414
+ equal to the length of multimodal features. If the lengths are different, an error is raised.
1415
+ """
1416
+ if input_ids is None:
1417
+ special_image_mask = inputs_embeds == self.get_input_embeddings()(
1418
+ torch.tensor(self.config.image_token_id, dtype=torch.long, device=inputs_embeds.device)
1419
+ )
1420
+ special_image_mask = special_image_mask.all(-1)
1421
+ special_video_mask = inputs_embeds == self.get_input_embeddings()(
1422
+ torch.tensor(self.config.video_token_id, dtype=torch.long, device=inputs_embeds.device)
1423
+ )
1424
+ special_video_mask = special_video_mask.all(-1)
1425
+ else:
1426
+ special_image_mask = input_ids == self.config.image_token_id
1427
+ special_video_mask = input_ids == self.config.video_token_id
1428
+
1429
+ n_image_tokens = special_image_mask.sum()
1430
+ special_image_mask = special_image_mask.unsqueeze(-1).expand_as(inputs_embeds).to(inputs_embeds.device)
1431
+ if image_features is not None and inputs_embeds[special_image_mask].numel() != image_features.numel():
1432
+ raise ValueError(
1433
+ f"Image features and image tokens do not match: tokens: {n_image_tokens}, features {image_features.shape[0]}"
1434
+ )
1435
+
1436
+ n_video_tokens = special_video_mask.sum()
1437
+ special_video_mask = special_video_mask.unsqueeze(-1).expand_as(inputs_embeds).to(inputs_embeds.device)
1438
+ if video_features is not None and inputs_embeds[special_video_mask].numel() != video_features.numel():
1439
+ raise ValueError(
1440
+ f"Videos features and video tokens do not match: tokens: {n_video_tokens}, features {video_features.shape[0]}"
1441
+ )
1442
+
1443
+ return special_image_mask, special_video_mask
1444
+
1445
+ @auto_docstring
1446
+ def forward(
1447
+ self,
1448
+ input_ids: Optional[torch.LongTensor] = None,
1449
+ attention_mask: Optional[torch.Tensor] = None,
1450
+ position_ids: Optional[torch.LongTensor] = None,
1451
+ past_key_values: Optional[Cache] = None,
1452
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1453
+ use_cache: Optional[bool] = None,
1454
+ output_attentions: Optional[bool] = None,
1455
+ output_hidden_states: Optional[bool] = None,
1456
+ return_dict: Optional[bool] = None,
1457
+ pixel_values: Optional[torch.Tensor] = None,
1458
+ pixel_values_videos: Optional[torch.FloatTensor] = None,
1459
+ image_grid_thw: Optional[torch.LongTensor] = None,
1460
+ patch_positions: Optional[torch.LongTensor] = None,
1461
+ video_grid_thw: Optional[torch.LongTensor] = None,
1462
+ cache_position: Optional[torch.LongTensor] = None,
1463
+ second_per_grid_ts: Optional[torch.Tensor] = None,
1464
+ **kwargs: Unpack[TransformersKwargs],
1465
+ ) -> Union[tuple, LlavaOnevision2ModelOutputWithPast]:
1466
+ r"""
1467
+ image_grid_thw (`torch.LongTensor` of shape `(num_images, 3)`, *optional*):
1468
+ The temporal, height and width of feature shape of each image in LLM.
1469
+ video_grid_thw (`torch.LongTensor` of shape `(num_videos, 3)`, *optional*):
1470
+ The temporal, height and width of feature shape of each video in LLM.
1471
+ second_per_grid_ts (`torch.Tensor` of shape `(num_videos)`, *optional*):
1472
+ The time interval (in seconds) for each grid along the temporal dimension in the 3D position IDs.
1473
+ """
1474
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
1475
+ output_hidden_states = (
1476
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
1477
+ )
1478
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
1479
+
1480
+ if inputs_embeds is None:
1481
+ inputs_embeds = self.get_input_embeddings()(input_ids)
1482
+
1483
+ image_embeds = None
1484
+
1485
+ if pixel_values is not None:
1486
+ image_embeds = self.get_image_features(pixel_values, image_grid_thw, patch_positions=patch_positions)
1487
+
1488
+ if image_embeds is not None:
1489
+ image_embeds = torch.cat(image_embeds, dim=0).to(inputs_embeds.device, inputs_embeds.dtype)
1490
+ image_mask, _ = self.get_placeholder_mask(
1491
+ input_ids, inputs_embeds=inputs_embeds, image_features=image_embeds
1492
+ )
1493
+ inputs_embeds = inputs_embeds.masked_scatter(image_mask, image_embeds)
1494
+
1495
+ if pixel_values_videos is not None:
1496
+ video_embeds = self.get_video_features(pixel_values_videos, video_grid_thw)
1497
+ video_embeds = torch.cat(video_embeds, dim=0).to(inputs_embeds.device, inputs_embeds.dtype)
1498
+ _, video_mask = self.get_placeholder_mask(
1499
+ input_ids, inputs_embeds=inputs_embeds, video_features=video_embeds
1500
+ )
1501
+ inputs_embeds = inputs_embeds.masked_scatter(video_mask, video_embeds)
1502
+
1503
+ # Use simple 1D position_ids
1504
+ if position_ids is None:
1505
+ batch_size, seq_length, _ = inputs_embeds.shape
1506
+ if attention_mask is not None:
1507
+ position_ids = attention_mask.long().cumsum(-1) - 1
1508
+ position_ids.masked_fill_(attention_mask == 0, 1)
1509
+ else:
1510
+ position_ids = (
1511
+ torch.arange(seq_length, device=inputs_embeds.device).unsqueeze(0).expand(batch_size, -1)
1512
+ )
1513
+
1514
+ # Handle cache_position for generation
1515
+ if cache_position is not None and cache_position[0] != 0:
1516
+ position_ids = position_ids + cache_position[0]
1517
+
1518
+ outputs = self.language_model(
1519
+ input_ids=None,
1520
+ position_ids=position_ids,
1521
+ attention_mask=attention_mask,
1522
+ past_key_values=past_key_values,
1523
+ inputs_embeds=inputs_embeds,
1524
+ use_cache=use_cache,
1525
+ output_attentions=output_attentions,
1526
+ output_hidden_states=output_hidden_states,
1527
+ return_dict=True,
1528
+ cache_position=cache_position,
1529
+ **kwargs,
1530
+ )
1531
+
1532
+ output = LlavaOnevision2ModelOutputWithPast(
1533
+ last_hidden_state=outputs.last_hidden_state,
1534
+ past_key_values=outputs.past_key_values,
1535
+ hidden_states=outputs.hidden_states,
1536
+ attentions=outputs.attentions,
1537
+ )
1538
+ return output if return_dict else output.to_tuple()
1539
+
1540
+
1541
+ @auto_docstring
1542
+ class LlavaOnevision2ForConditionalGeneration(LlavaOnevision2PreTrainedModel, GenerationMixin):
1543
+ _checkpoint_conversion_mapping = {
1544
+ "^visual": "model.visual",
1545
+ r"^model(?!\.(language_model|visual))": "model.language_model",
1546
+ }
1547
+ _tied_weights_keys = {"lm_head.weight": "model.language_model.embed_tokens.weight"}
1548
+ # Reference: fix gemma3 grad acc #37208
1549
+ accepts_loss_kwargs = False
1550
+
1551
+ def __init__(self, config):
1552
+ super().__init__(config)
1553
+ self.model = LlavaOnevision2Model(config)
1554
+ self.lm_head = nn.Linear(config.text_config.hidden_size, config.text_config.vocab_size, bias=False)
1555
+ self.post_init()
1556
+
1557
+ def get_input_embeddings(self):
1558
+ return self.model.get_input_embeddings()
1559
+
1560
+ def set_input_embeddings(self, value):
1561
+ self.model.set_input_embeddings(value)
1562
+
1563
+ def set_decoder(self, decoder):
1564
+ self.model.set_decoder(decoder)
1565
+
1566
+ def get_decoder(self):
1567
+ return self.model.get_decoder()
1568
+
1569
+ def get_video_features(
1570
+ self, pixel_values_videos: torch.FloatTensor, video_grid_thw: Optional[torch.LongTensor] = None
1571
+ ):
1572
+ return self.model.get_video_features(pixel_values_videos, video_grid_thw)
1573
+
1574
+ def get_image_features(self, pixel_values: torch.FloatTensor, image_grid_thw: Optional[torch.LongTensor] = None):
1575
+ return self.model.get_image_features(pixel_values, image_grid_thw)
1576
+
1577
+ # Make modules available through conditional class for BC
1578
+ @property
1579
+ def language_model(self):
1580
+ return self.model.language_model
1581
+
1582
+ @property
1583
+ def visual(self):
1584
+ return self.model.visual
1585
+
1586
+ @can_return_tuple
1587
+ @auto_docstring
1588
+ def forward(
1589
+ self,
1590
+ input_ids: Optional[torch.LongTensor] = None,
1591
+ attention_mask: Optional[torch.Tensor] = None,
1592
+ position_ids: Optional[torch.LongTensor] = None,
1593
+ past_key_values: Optional[Cache] = None,
1594
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1595
+ labels: Optional[torch.LongTensor] = None,
1596
+ use_cache: Optional[bool] = None,
1597
+ output_attentions: Optional[bool] = None,
1598
+ output_hidden_states: Optional[bool] = None,
1599
+ pixel_values: Optional[torch.Tensor] = None,
1600
+ pixel_values_videos: Optional[torch.FloatTensor] = None,
1601
+ image_grid_thw: Optional[torch.LongTensor] = None,
1602
+ patch_positions: Optional[torch.LongTensor] = None,
1603
+ video_grid_thw: Optional[torch.LongTensor] = None,
1604
+ cache_position: Optional[torch.LongTensor] = None,
1605
+ second_per_grid_ts: Optional[torch.Tensor] = None,
1606
+ logits_to_keep: Union[int, torch.Tensor] = 0,
1607
+ **kwargs: Unpack[TransformersKwargs],
1608
+ ) -> Union[tuple, LlavaOnevision2CausalLMOutputWithPast]:
1609
+ r"""
1610
+ labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
1611
+ Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
1612
+ config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
1613
+ (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
1614
+ image_grid_thw (`torch.LongTensor` of shape `(num_images, 3)`, *optional*):
1615
+ The temporal, height and width of feature shape of each image in LLM.
1616
+ video_grid_thw (`torch.LongTensor` of shape `(num_videos, 3)`, *optional*):
1617
+ The temporal, height and width of feature shape of each video in LLM.
1618
+ second_per_grid_ts (`torch.Tensor` of shape `(num_videos)`, *optional*):
1619
+ The time interval (in seconds) for each grid along the temporal dimension in the 3D position IDs.
1620
+
1621
+ Example:
1622
+
1623
+ ```python
1624
+ >>> from PIL import Image
1625
+ >>> import requests
1626
+ >>> from transformers import AutoProcessor, LlavaOnevision2ForConditionalGeneration
1627
+
1628
+ >>> model = LlavaOnevision2ForConditionalGeneration.from_pretrained("Deep-VLM/LLaVA-OneVision-1.5-8B-Instruct-hf", trust_remote_code=True)
1629
+ >>> processor = AutoProcessor.from_pretrained("Deep-VLM/LLaVA-OneVision-1.5-8B-Instruct-hf", trust_remote_code=True)
1630
+
1631
+ >>> messages = [
1632
+ {
1633
+ "role": "user",
1634
+ "content": [
1635
+ {"type": "image"},
1636
+ {"type": "text", "text": "What is shown in this image?"},
1637
+ ],
1638
+ },
1639
+ ]
1640
+ >>> url = "https://www.ilankelman.org/stopsigns/australia.jpg"
1641
+ >>> image = Image.open(requests.get(url, stream=True).raw)
1642
+
1643
+ >>> text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
1644
+ >>> inputs = processor(text=[text], images=[image], vision_infos=[vision_infos])
1645
+
1646
+ >>> # Generate
1647
+ >>> generate_ids = model.generate(inputs.input_ids, max_length=30)
1648
+ >>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
1649
+ "The image shows a street scene with a red stop sign in the foreground. In the background, there is a large red gate with Chinese characters ..."
1650
+ ```"""
1651
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
1652
+ output_hidden_states = (
1653
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
1654
+ )
1655
+ outputs = self.model(
1656
+ input_ids=input_ids,
1657
+ pixel_values=pixel_values,
1658
+ pixel_values_videos=pixel_values_videos,
1659
+ image_grid_thw=image_grid_thw,
1660
+ patch_positions=patch_positions,
1661
+ video_grid_thw=video_grid_thw,
1662
+ second_per_grid_ts=second_per_grid_ts,
1663
+ position_ids=position_ids,
1664
+ attention_mask=attention_mask,
1665
+ past_key_values=past_key_values,
1666
+ inputs_embeds=inputs_embeds,
1667
+ use_cache=use_cache,
1668
+ output_attentions=output_attentions,
1669
+ output_hidden_states=output_hidden_states,
1670
+ return_dict=True,
1671
+ cache_position=cache_position,
1672
+ **kwargs,
1673
+ )
1674
+
1675
+ hidden_states = outputs[0]
1676
+
1677
+ # Only compute necessary logits, and do not upcast them to float if we are not computing the loss
1678
+ slice_indices = slice(-logits_to_keep, None) if isinstance(logits_to_keep, int) else logits_to_keep
1679
+ logits = self.lm_head(hidden_states[:, slice_indices, :])
1680
+
1681
+ loss = None
1682
+ if labels is not None:
1683
+ loss = self.loss_function(
1684
+ logits=logits, labels=labels, vocab_size=self.config.text_config.vocab_size, **kwargs
1685
+ )
1686
+
1687
+ return LlavaOnevision2CausalLMOutputWithPast(
1688
+ loss=loss,
1689
+ logits=logits,
1690
+ past_key_values=outputs.past_key_values,
1691
+ hidden_states=outputs.hidden_states,
1692
+ attentions=outputs.attentions,
1693
+ )
1694
+
1695
+ def prepare_inputs_for_generation(
1696
+ self,
1697
+ input_ids,
1698
+ past_key_values=None,
1699
+ attention_mask=None,
1700
+ inputs_embeds=None,
1701
+ cache_position=None,
1702
+ position_ids=None,
1703
+ use_cache=True,
1704
+ pixel_values=None,
1705
+ pixel_values_videos=None,
1706
+ image_grid_thw=None,
1707
+ patch_positions=None,
1708
+ video_grid_thw=None,
1709
+ second_per_grid_ts=None,
1710
+ **kwargs,
1711
+ ):
1712
+ # Overwritten -- in specific circumstances we don't want to forward image inputs to the model
1713
+ model_inputs = super().prepare_inputs_for_generation(
1714
+ input_ids,
1715
+ past_key_values=past_key_values,
1716
+ attention_mask=attention_mask,
1717
+ inputs_embeds=inputs_embeds,
1718
+ cache_position=cache_position,
1719
+ position_ids=position_ids,
1720
+ pixel_values=pixel_values,
1721
+ pixel_values_videos=pixel_values_videos,
1722
+ image_grid_thw=image_grid_thw,
1723
+ video_grid_thw=video_grid_thw,
1724
+ second_per_grid_ts=second_per_grid_ts,
1725
+ patch_positions=patch_positions,
1726
+ use_cache=use_cache,
1727
+ **kwargs,
1728
+ )
1729
+
1730
+ if cache_position[0] != 0:
1731
+ model_inputs["pixel_values"] = None
1732
+ model_inputs["pixel_values_videos"] = None
1733
+
1734
+ return model_inputs
1735
+
1736
+ def _get_image_nums_and_video_nums(
1737
+ self,
1738
+ input_ids: Optional[torch.LongTensor],
1739
+ inputs_embeds: Optional[torch.Tensor] = None,
1740
+ ) -> tuple[torch.Tensor, torch.Tensor]:
1741
+ """
1742
+ Get the number of images and videos for each sample to calculate the separation length of the sample tensor.
1743
+ These parameters are not passed through the processor to avoid unpredictable impacts from interface modifications.
1744
+
1745
+ Args:
1746
+ input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
1747
+ Indices of input sequence tokens in the vocabulary.
1748
+
1749
+ Returns:
1750
+ image_nums (`torch.LongTensor` of shape `(batch_size, num_images_sample)`)
1751
+ video_nums (`torch.LongTensor` of shape `(batch_size, num_videos_sample)`)
1752
+ """
1753
+ image_token_id = self.config.image_token_id
1754
+ video_token_id = self.config.video_token_id
1755
+ vision_start_token_id = self.config.vision_start_token_id
1756
+
1757
+ if inputs_embeds is not None:
1758
+ vision_start_mask = (
1759
+ inputs_embeds
1760
+ == self.get_input_embeddings()(
1761
+ torch.tensor(vision_start_token_id, dtype=torch.long, device=inputs_embeds.device)
1762
+ )
1763
+ )[..., 0]
1764
+ image_mask = (
1765
+ inputs_embeds
1766
+ == self.get_input_embeddings()(
1767
+ torch.tensor(image_token_id, dtype=torch.long, device=inputs_embeds.device)
1768
+ )
1769
+ )[..., 0]
1770
+ video_mask = (
1771
+ inputs_embeds
1772
+ == self.get_input_embeddings()(
1773
+ torch.tensor(video_token_id, dtype=torch.long, device=inputs_embeds.device)
1774
+ )
1775
+ )[..., 0]
1776
+ else:
1777
+ vision_start_mask = input_ids == vision_start_token_id
1778
+ image_mask = input_ids == image_token_id
1779
+ video_mask = input_ids == video_token_id
1780
+
1781
+ vision_first_mask = torch.roll(vision_start_mask, shifts=1, dims=1)
1782
+ image_nums = torch.sum(vision_first_mask & image_mask, dim=1)
1783
+ video_nums = torch.sum(vision_first_mask & video_mask, dim=1)
1784
+
1785
+ return image_nums, video_nums
1786
+
1787
+ def _expand_inputs_for_generation(
1788
+ self,
1789
+ expand_size: int = 1,
1790
+ is_encoder_decoder: bool = False,
1791
+ input_ids: Optional[torch.LongTensor] = None,
1792
+ **model_kwargs,
1793
+ ) -> tuple[torch.LongTensor, dict[str, Any]]:
1794
+ # Overwritten -- Support for expanding tensors without a batch size dimension
1795
+ # e.g., pixel_values, image_grid_thw, pixel_values_videos, video_grid_thw, second_per_grid_t
1796
+ # pixel_values.shape[0] is sum(seqlen_images for samples)
1797
+ # image_grid_thw.shape[0] is sum(num_images for samples)
1798
+
1799
+ if expand_size == 1:
1800
+ return input_ids, model_kwargs
1801
+
1802
+ visual_keys = ["pixel_values", "image_grid_thw", "pixel_values_videos", "video_grid_thw", "second_per_grid_ts"]
1803
+
1804
+ def _expand_dict_for_generation_visual(dict_to_expand):
1805
+ image_grid_thw = model_kwargs.get("image_grid_thw", None)
1806
+ video_grid_thw = model_kwargs.get("video_grid_thw", None)
1807
+ image_nums, video_nums = self._get_image_nums_and_video_nums(
1808
+ input_ids, inputs_embeds=model_kwargs.get("inputs_embeds", None)
1809
+ )
1810
+
1811
+ def _repeat_interleave_samples(x, lengths, repeat_times):
1812
+ samples = torch.split(x, lengths)
1813
+ repeat_args = [repeat_times] + [1] * (x.dim() - 1)
1814
+ result = torch.cat([sample.repeat(*repeat_args) for sample in samples], dim=0)
1815
+ return result
1816
+
1817
+ for key in dict_to_expand:
1818
+ if key == "pixel_values":
1819
+ # split images into samples
1820
+ samples = torch.split(image_grid_thw, list(image_nums))
1821
+ # compute the sequence length of images for each sample
1822
+ lengths = [torch.prod(sample, dim=1).sum() for sample in samples]
1823
+ dict_to_expand[key] = _repeat_interleave_samples(
1824
+ dict_to_expand[key], lengths=lengths, repeat_times=expand_size
1825
+ )
1826
+ elif key == "image_grid_thw":
1827
+ # get the num of images for each sample
1828
+ lengths = list(image_nums)
1829
+ dict_to_expand[key] = _repeat_interleave_samples(
1830
+ dict_to_expand[key], lengths=lengths, repeat_times=expand_size
1831
+ )
1832
+ elif key == "pixel_values_videos":
1833
+ samples = torch.split(video_grid_thw, list(video_nums))
1834
+ lengths = [torch.prod(sample, dim=1).sum() for sample in samples]
1835
+ dict_to_expand[key] = _repeat_interleave_samples(
1836
+ dict_to_expand[key], lengths=lengths, repeat_times=expand_size
1837
+ )
1838
+ elif key == "video_grid_thw":
1839
+ lengths = list(video_nums)
1840
+ dict_to_expand[key] = _repeat_interleave_samples(
1841
+ dict_to_expand[key], lengths=lengths, repeat_times=expand_size
1842
+ )
1843
+ elif key == "second_per_grid_ts":
1844
+ dict_to_expand[key] = _repeat_interleave_samples(
1845
+ dict_to_expand[key], lengths=list(video_nums), repeat_times=expand_size
1846
+ )
1847
+ return dict_to_expand
1848
+
1849
+ def _expand_dict_for_generation(dict_to_expand):
1850
+ for key in dict_to_expand:
1851
+ if (
1852
+ key != "cache_position"
1853
+ and dict_to_expand[key] is not None
1854
+ and isinstance(dict_to_expand[key], torch.Tensor)
1855
+ and key not in visual_keys
1856
+ ):
1857
+ dict_to_expand[key] = dict_to_expand[key].repeat_interleave(expand_size, dim=0)
1858
+ return dict_to_expand
1859
+
1860
+ model_kwargs = _expand_dict_for_generation_visual(model_kwargs)
1861
+
1862
+ if input_ids is not None:
1863
+ input_ids = input_ids.repeat_interleave(expand_size, dim=0)
1864
+
1865
+ model_kwargs = _expand_dict_for_generation(model_kwargs)
1866
+
1867
+ if is_encoder_decoder:
1868
+ if model_kwargs.get("encoder_outputs") is None:
1869
+ raise ValueError("If `is_encoder_decoder` is True, make sure that `encoder_outputs` is defined.")
1870
+ model_kwargs["encoder_outputs"] = _expand_dict_for_generation(model_kwargs["encoder_outputs"])
1871
+
1872
+ return input_ids, model_kwargs
1873
+
1874
+
1875
+ __all__ = [
1876
+ "LlavaOnevision2ForConditionalGeneration",
1877
+ "LlavaOnevision2Model",
1878
+ "LlavaOnevision2PreTrainedModel",
1879
+ "LlavaOnevision2VisionPretrainedModel",
1880
+ # Vision components
1881
+ "VisionRotaryEmbedding",
1882
+ "OneVisionEncoderEmbeddings",
1883
+ "OneVisionEncoderFlashAttention2",
1884
+ "OneVisionEncoderEncoderLayer",
1885
+ "OneVisionEncoderEncoder",
1886
+ "LlavaOnevision2VisionPatchMerger",
1887
+ "Siglip2MultiheadAttentionPoolingHead",
1888
+ ]
preprocessor_config.json ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "crop_size": null,
3
+ "data_format": "channels_first",
4
+ "default_to_square": true,
5
+ "device": null,
6
+ "disable_grouping": null,
7
+ "do_center_crop": null,
8
+ "do_convert_rgb": true,
9
+ "do_normalize": true,
10
+ "do_pad": null,
11
+ "do_rescale": true,
12
+ "do_resize": true,
13
+ "image_mean": [
14
+ 0.48145466,
15
+ 0.4578275,
16
+ 0.40821073
17
+ ],
18
+ "image_processor_type": "Qwen2VLImageProcessorFast",
19
+ "image_std": [
20
+ 0.26862954,
21
+ 0.26130258,
22
+ 0.27577711
23
+ ],
24
+ "input_data_format": null,
25
+ "max_pixels": 4000000,
26
+ "merge_size": 2,
27
+ "min_pixels": 3136,
28
+ "pad_size": null,
29
+ "patch_size": 14,
30
+ "processor_class": "Qwen2_5_VLProcessor",
31
+ "resample": 3,
32
+ "rescale_factor": 0.00392156862745098,
33
+ "return_tensors": null,
34
+ "size": {
35
+ "longest_edge": 4000000,
36
+ "shortest_edge": 3136
37
+ },
38
+ "temporal_patch_size": 1
39
+ }
special_tokens_map.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|im_start|>",
4
+ "<|im_end|>",
5
+ "<|object_ref_start|>",
6
+ "<|object_ref_end|>",
7
+ "<|box_start|>",
8
+ "<|box_end|>",
9
+ "<|quad_start|>",
10
+ "<|quad_end|>",
11
+ "<|vision_start|>",
12
+ "<|vision_end|>",
13
+ "<|vision_pad|>",
14
+ "<|image_pad|>",
15
+ "<|video_pad|>"
16
+ ],
17
+ "eos_token": {
18
+ "content": "<|im_end|>",
19
+ "lstrip": false,
20
+ "normalized": false,
21
+ "rstrip": false,
22
+ "single_word": false
23
+ },
24
+ "pad_token": {
25
+ "content": "<|endoftext|>",
26
+ "lstrip": false,
27
+ "normalized": false,
28
+ "rstrip": false,
29
+ "single_word": false
30
+ }
31
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ba0c439f7be467bf47d12a7e6f9adc6116201056fc60c67f431c679b7c16afc8
3
+ size 11422064
tokenizer_config.json ADDED
@@ -0,0 +1,213 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": false,
3
+ "add_prefix_space": false,
4
+ "added_tokens_decoder": {
5
+ "151643": {
6
+ "content": "<|endoftext|>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "151644": {
14
+ "content": "<|im_start|>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "151645": {
22
+ "content": "<|im_end|>",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false,
27
+ "special": true
28
+ },
29
+ "151646": {
30
+ "content": "<|object_ref_start|>",
31
+ "lstrip": false,
32
+ "normalized": false,
33
+ "rstrip": false,
34
+ "single_word": false,
35
+ "special": true
36
+ },
37
+ "151647": {
38
+ "content": "<|object_ref_end|>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false,
43
+ "special": true
44
+ },
45
+ "151648": {
46
+ "content": "<|box_start|>",
47
+ "lstrip": false,
48
+ "normalized": false,
49
+ "rstrip": false,
50
+ "single_word": false,
51
+ "special": true
52
+ },
53
+ "151649": {
54
+ "content": "<|box_end|>",
55
+ "lstrip": false,
56
+ "normalized": false,
57
+ "rstrip": false,
58
+ "single_word": false,
59
+ "special": true
60
+ },
61
+ "151650": {
62
+ "content": "<|quad_start|>",
63
+ "lstrip": false,
64
+ "normalized": false,
65
+ "rstrip": false,
66
+ "single_word": false,
67
+ "special": true
68
+ },
69
+ "151651": {
70
+ "content": "<|quad_end|>",
71
+ "lstrip": false,
72
+ "normalized": false,
73
+ "rstrip": false,
74
+ "single_word": false,
75
+ "special": true
76
+ },
77
+ "151652": {
78
+ "content": "<|vision_start|>",
79
+ "lstrip": false,
80
+ "normalized": false,
81
+ "rstrip": false,
82
+ "single_word": false,
83
+ "special": true
84
+ },
85
+ "151653": {
86
+ "content": "<|vision_end|>",
87
+ "lstrip": false,
88
+ "normalized": false,
89
+ "rstrip": false,
90
+ "single_word": false,
91
+ "special": true
92
+ },
93
+ "151654": {
94
+ "content": "<|vision_pad|>",
95
+ "lstrip": false,
96
+ "normalized": false,
97
+ "rstrip": false,
98
+ "single_word": false,
99
+ "special": true
100
+ },
101
+ "151655": {
102
+ "content": "<|image_pad|>",
103
+ "lstrip": false,
104
+ "normalized": false,
105
+ "rstrip": false,
106
+ "single_word": false,
107
+ "special": true
108
+ },
109
+ "151656": {
110
+ "content": "<|video_pad|>",
111
+ "lstrip": false,
112
+ "normalized": false,
113
+ "rstrip": false,
114
+ "single_word": false,
115
+ "special": true
116
+ },
117
+ "151657": {
118
+ "content": "<tool_call>",
119
+ "lstrip": false,
120
+ "normalized": false,
121
+ "rstrip": false,
122
+ "single_word": false,
123
+ "special": false
124
+ },
125
+ "151658": {
126
+ "content": "</tool_call>",
127
+ "lstrip": false,
128
+ "normalized": false,
129
+ "rstrip": false,
130
+ "single_word": false,
131
+ "special": false
132
+ },
133
+ "151659": {
134
+ "content": "<|fim_prefix|>",
135
+ "lstrip": false,
136
+ "normalized": false,
137
+ "rstrip": false,
138
+ "single_word": false,
139
+ "special": false
140
+ },
141
+ "151660": {
142
+ "content": "<|fim_middle|>",
143
+ "lstrip": false,
144
+ "normalized": false,
145
+ "rstrip": false,
146
+ "single_word": false,
147
+ "special": false
148
+ },
149
+ "151661": {
150
+ "content": "<|fim_suffix|>",
151
+ "lstrip": false,
152
+ "normalized": false,
153
+ "rstrip": false,
154
+ "single_word": false,
155
+ "special": false
156
+ },
157
+ "151662": {
158
+ "content": "<|fim_pad|>",
159
+ "lstrip": false,
160
+ "normalized": false,
161
+ "rstrip": false,
162
+ "single_word": false,
163
+ "special": false
164
+ },
165
+ "151663": {
166
+ "content": "<|repo_name|>",
167
+ "lstrip": false,
168
+ "normalized": false,
169
+ "rstrip": false,
170
+ "single_word": false,
171
+ "special": false
172
+ },
173
+ "151664": {
174
+ "content": "<|file_sep|>",
175
+ "lstrip": false,
176
+ "normalized": false,
177
+ "rstrip": false,
178
+ "single_word": false,
179
+ "special": false
180
+ }
181
+ },
182
+ "additional_special_tokens": [
183
+ "<|im_start|>",
184
+ "<|im_end|>",
185
+ "<|object_ref_start|>",
186
+ "<|object_ref_end|>",
187
+ "<|box_start|>",
188
+ "<|box_end|>",
189
+ "<|quad_start|>",
190
+ "<|quad_end|>",
191
+ "<|vision_start|>",
192
+ "<|vision_end|>",
193
+ "<|vision_pad|>",
194
+ "<|image_pad|>",
195
+ "<|video_pad|>"
196
+ ],
197
+ "bos_token": null,
198
+ "clean_up_tokenization_spaces": false,
199
+ "eos_token": "<|im_end|>",
200
+ "errors": "replace",
201
+ "extra_special_tokens": {},
202
+ "max_length": null,
203
+ "model_max_length": 131072,
204
+ "pad_to_multiple_of": null,
205
+ "pad_token": "<|endoftext|>",
206
+ "pad_token_type_id": 0,
207
+ "padding_side": "right",
208
+ "processor_class": "Qwen2_5_VLProcessor",
209
+ "split_special_tokens": false,
210
+ "tokenizer_class": "Qwen2Tokenizer",
211
+ "unk_token": null,
212
+ "use_fast": true
213
+ }
video_preprocessor_config.json ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "crop_size": null,
3
+ "data_format": "channels_first",
4
+ "default_to_square": true,
5
+ "device": null,
6
+ "do_center_crop": null,
7
+ "do_convert_rgb": true,
8
+ "do_normalize": true,
9
+ "do_rescale": true,
10
+ "do_resize": true,
11
+ "do_sample_frames": false,
12
+ "fps": null,
13
+ "image_mean": [
14
+ 0.48145466,
15
+ 0.4578275,
16
+ 0.40821073
17
+ ],
18
+ "image_std": [
19
+ 0.26862954,
20
+ 0.26130258,
21
+ 0.27577711
22
+ ],
23
+ "input_data_format": null,
24
+ "max_frames": 768,
25
+ "max_pixels": 12845056,
26
+ "merge_size": 2,
27
+ "min_frames": 4,
28
+ "min_pixels": 3136,
29
+ "num_frames": null,
30
+ "pad_size": null,
31
+ "patch_size": 14,
32
+ "processor_class": "Qwen2_5_VLProcessor",
33
+ "resample": 3,
34
+ "rescale_factor": 0.00392156862745098,
35
+ "return_metadata": false,
36
+ "size": {
37
+ "longest_edge": 12845056,
38
+ "shortest_edge": 3136
39
+ },
40
+ "temporal_patch_size": 2,
41
+ "video_metadata": null,
42
+ "video_processor_type": "Qwen2VLVideoProcessor"
43
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff