aria-dev commited on
Commit
0531a03
1 Parent(s): 312ab8b

first version

Browse files
added_tokens.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "</s>": 100353,
3
+ "<s>": 100352
4
+ }
config.json ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "AriaForConditionalGeneration"
4
+ ],
5
+ "auto_map": {
6
+ "AutoConfig": "modeling_aria.AriaConfig",
7
+ "AutoModelForCausalLM": "modeling_aria.AriaForConditionalGeneration"
8
+ },
9
+ "ignore_index": -100,
10
+ "image_token_index": 9,
11
+ "model_type": "aria",
12
+ "projector_patch_to_query_dict": {
13
+ "1225": 128,
14
+ "4900": 256
15
+ },
16
+ "text_config": {
17
+ "hidden_size": 2560,
18
+ "intermediate_size": 13568,
19
+ "max_position_embeddings": 65536,
20
+ "model_type": "aria_moe_lm",
21
+ "moe_intermediate_size": 1664,
22
+ "moe_num_experts": 64,
23
+ "moe_topk": 6,
24
+ "num_attention_heads": 20,
25
+ "num_experts_per_tok": 6,
26
+ "num_hidden_layers": 28,
27
+ "num_key_value_heads": 20,
28
+ "rope_theta": 5000000,
29
+ "vocab_size": 100352
30
+ },
31
+ "torch_dtype": "bfloat16",
32
+ "transformers_version": "4.45.0",
33
+ "vision_config": {
34
+ "_flash_attn_2_enabled": true,
35
+ "architectures": [
36
+ "AriaVisionModel"
37
+ ],
38
+ "hidden_size": 1152,
39
+ "image_size": 980,
40
+ "intermediate_size": 4304,
41
+ "model_type": "aria_vision_model",
42
+ "num_attention_heads": 16,
43
+ "num_hidden_layers": 27,
44
+ "patch_size": 14,
45
+ "torch_dtype": "bfloat16"
46
+ }
47
+ }
configuration_aria.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2024 Rhymes AI. All rights reserved.
2
+ #
3
+ # Licensed to the Apache Software Foundation (ASF) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The ASF licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+
20
+ from transformers.configuration_utils import PretrainedConfig
21
+
22
+ from .moe_lm import AriaMoELMConfig
23
+ from .vision_encoder import AriaVisionConfig
24
+
25
+
26
+ # adapted from transformers.models.llava.configuration_llava.LlavaConfig
27
+ class AriaConfig(PretrainedConfig):
28
+ """
29
+ Configuration class for Aria model.
30
+
31
+ This class handles the configuration for both vision and text components of the Aria model,
32
+ as well as additional parameters for image token handling and projector mapping.
33
+
34
+ Args:
35
+ vision_config (AriaVisionConfig or dict): Configuration for the vision component.
36
+ text_config (AriaMoELMConfig or dict): Configuration for the text component.
37
+ projector_patch_to_query_dict (dict): Mapping of patch sizes to query dimensions.
38
+ ignore_index (int): Index to ignore in loss calculation.
39
+ image_token_index (int): Index used to represent image tokens.
40
+ **kwargs: Additional keyword arguments passed to the parent class.
41
+
42
+ Attributes:
43
+ model_type (str): Type of the model, set to "aria".
44
+ is_composition (bool): Whether the model is a composition of multiple components.
45
+ ignore_index (int): Index to ignore in loss calculation.
46
+ image_token_index (int): Index used to represent image tokens.
47
+ projector_patch_to_query_dict (dict): Mapping of patch sizes to query dimensions.
48
+ vision_config (AriaVisionConfig): Configuration for the vision component.
49
+ text_config (AriaMoELMConfig): Configuration for the text component.
50
+ """
51
+
52
+ model_type = "aria"
53
+ is_composition = False
54
+
55
+ def __init__(
56
+ self,
57
+ vision_config=AriaVisionConfig(),
58
+ text_config=AriaMoELMConfig(),
59
+ projector_patch_to_query_dict={
60
+ 1225: 128,
61
+ 4900: 256,
62
+ },
63
+ ignore_index=-100,
64
+ image_token_index=32000,
65
+ **kwargs,
66
+ ):
67
+ super().__init__(**kwargs)
68
+ self.ignore_index = ignore_index
69
+ self.image_token_index = image_token_index
70
+
71
+ # Convert the keys and values of projector_patch_to_query_dict to integers
72
+ # This ensures consistency even if they were provided as strings
73
+ self.projector_patch_to_query_dict = {
74
+ int(k): int(v) for k, v in projector_patch_to_query_dict.items()
75
+ }
76
+
77
+ if isinstance(vision_config, dict) and "model_type" in vision_config:
78
+ vision_config = AriaVisionConfig(**vision_config)
79
+
80
+ self.vision_config = vision_config
81
+
82
+ if isinstance(text_config, dict) and "model_type" in text_config:
83
+ text_config = AriaMoELMConfig(**text_config)
84
+
85
+ self.text_config = text_config
generation_config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 1,
4
+ "eos_token_id": 2,
5
+ "pad_token_id": 2,
6
+ "transformers_version": "4.45.0"
7
+ }
model-00001-of-00012.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3f58aac6657c824d7ccbfc590cc1e4dcc25bc361d99837bd92ff5196a2019aaf
3
+ size 4922385968
model-00002-of-00012.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7e01ad06d26257a8e8db6bc52db3a9fba63bfdf81a082811c6d58dd5c04ee16f
3
+ size 4569849136
model-00003-of-00012.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9ec21b36b156902258a0c0217b3c39a0dd64043d02e000249139411a51993724
3
+ size 4128475752
model-00004-of-00012.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2ab8eb30b71ccbb5c13be1ac48a639dee6997836456d50c132195bf1c26b629b
3
+ size 4569849136
model-00005-of-00012.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8a59cb471534e8f0649f81de4f4b4cab9247e48e73f25380e4956df49d50fc68
3
+ size 4128475792
model-00006-of-00012.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0db566f7143d6b4e3a37c69515dc0df8f78230f7c92230d3e3b804cc908cde6f
3
+ size 4569849160
model-00007-of-00012.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:69756e94c50cb07cae2e1aa9690000de2ae33d013d9b1c5e4532e77308967e35
3
+ size 4128475784
model-00008-of-00012.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:335585019c0b362663fe00b7beb4a03bc13c02c856757cf01d8af6be97332157
3
+ size 4569849160
model-00009-of-00012.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3a838a0d5ca56dcf3971f9b0db6b757dc5c98eff7874b40048f9b8c7d655f58d
3
+ size 4128475784
model-00010-of-00012.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3936bec75ea6078b36a91bf82106d53a664c59d3afb64599661690dfb460c94a
3
+ size 4569849160
model-00011-of-00012.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7b1ac5302deb2f973154a4c6283c8cf24e9e2df8fda88f0ea2a941552fcaf12b
3
+ size 4128475784
model-00012-of-00012.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:42565a77db9744dfc68b9125ddfa102fbc11b0a2be79e090e0785bba51914967
3
+ size 2200715456
model.safetensors.index.json ADDED
@@ -0,0 +1,799 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 50614617824
4
+ },
5
+ "weight_map": {
6
+ "language_model.lm_head.weight": "model-00012-of-00012.safetensors",
7
+ "language_model.model.embed_tokens.weight": "model-00001-of-00012.safetensors",
8
+ "language_model.model.layers.0.input_layernorm.weight": "model-00001-of-00012.safetensors",
9
+ "language_model.model.layers.0.mlp.experts.fc1.weight": "model-00001-of-00012.safetensors",
10
+ "language_model.model.layers.0.mlp.experts.fc2.weight": "model-00001-of-00012.safetensors",
11
+ "language_model.model.layers.0.mlp.router.weight": "model-00001-of-00012.safetensors",
12
+ "language_model.model.layers.0.mlp.shared_experts.down_proj.weight": "model-00001-of-00012.safetensors",
13
+ "language_model.model.layers.0.mlp.shared_experts.gate_proj.weight": "model-00001-of-00012.safetensors",
14
+ "language_model.model.layers.0.mlp.shared_experts.up_proj.weight": "model-00001-of-00012.safetensors",
15
+ "language_model.model.layers.0.post_attention_layernorm.weight": "model-00001-of-00012.safetensors",
16
+ "language_model.model.layers.0.self_attn.k_proj.weight": "model-00001-of-00012.safetensors",
17
+ "language_model.model.layers.0.self_attn.o_proj.weight": "model-00001-of-00012.safetensors",
18
+ "language_model.model.layers.0.self_attn.q_proj.weight": "model-00001-of-00012.safetensors",
19
+ "language_model.model.layers.0.self_attn.v_proj.weight": "model-00001-of-00012.safetensors",
20
+ "language_model.model.layers.1.input_layernorm.weight": "model-00001-of-00012.safetensors",
21
+ "language_model.model.layers.1.mlp.experts.fc1.weight": "model-00001-of-00012.safetensors",
22
+ "language_model.model.layers.1.mlp.experts.fc2.weight": "model-00001-of-00012.safetensors",
23
+ "language_model.model.layers.1.mlp.router.weight": "model-00001-of-00012.safetensors",
24
+ "language_model.model.layers.1.mlp.shared_experts.down_proj.weight": "model-00001-of-00012.safetensors",
25
+ "language_model.model.layers.1.mlp.shared_experts.gate_proj.weight": "model-00001-of-00012.safetensors",
26
+ "language_model.model.layers.1.mlp.shared_experts.up_proj.weight": "model-00001-of-00012.safetensors",
27
+ "language_model.model.layers.1.post_attention_layernorm.weight": "model-00001-of-00012.safetensors",
28
+ "language_model.model.layers.1.self_attn.k_proj.weight": "model-00001-of-00012.safetensors",
29
+ "language_model.model.layers.1.self_attn.o_proj.weight": "model-00001-of-00012.safetensors",
30
+ "language_model.model.layers.1.self_attn.q_proj.weight": "model-00001-of-00012.safetensors",
31
+ "language_model.model.layers.1.self_attn.v_proj.weight": "model-00001-of-00012.safetensors",
32
+ "language_model.model.layers.10.input_layernorm.weight": "model-00005-of-00012.safetensors",
33
+ "language_model.model.layers.10.mlp.experts.fc1.weight": "model-00005-of-00012.safetensors",
34
+ "language_model.model.layers.10.mlp.experts.fc2.weight": "model-00005-of-00012.safetensors",
35
+ "language_model.model.layers.10.mlp.router.weight": "model-00005-of-00012.safetensors",
36
+ "language_model.model.layers.10.mlp.shared_experts.down_proj.weight": "model-00005-of-00012.safetensors",
37
+ "language_model.model.layers.10.mlp.shared_experts.gate_proj.weight": "model-00005-of-00012.safetensors",
38
+ "language_model.model.layers.10.mlp.shared_experts.up_proj.weight": "model-00005-of-00012.safetensors",
39
+ "language_model.model.layers.10.post_attention_layernorm.weight": "model-00005-of-00012.safetensors",
40
+ "language_model.model.layers.10.self_attn.k_proj.weight": "model-00005-of-00012.safetensors",
41
+ "language_model.model.layers.10.self_attn.o_proj.weight": "model-00005-of-00012.safetensors",
42
+ "language_model.model.layers.10.self_attn.q_proj.weight": "model-00005-of-00012.safetensors",
43
+ "language_model.model.layers.10.self_attn.v_proj.weight": "model-00005-of-00012.safetensors",
44
+ "language_model.model.layers.11.input_layernorm.weight": "model-00005-of-00012.safetensors",
45
+ "language_model.model.layers.11.mlp.experts.fc1.weight": "model-00005-of-00012.safetensors",
46
+ "language_model.model.layers.11.mlp.experts.fc2.weight": "model-00005-of-00012.safetensors",
47
+ "language_model.model.layers.11.mlp.router.weight": "model-00005-of-00012.safetensors",
48
+ "language_model.model.layers.11.mlp.shared_experts.down_proj.weight": "model-00005-of-00012.safetensors",
49
+ "language_model.model.layers.11.mlp.shared_experts.gate_proj.weight": "model-00005-of-00012.safetensors",
50
+ "language_model.model.layers.11.mlp.shared_experts.up_proj.weight": "model-00005-of-00012.safetensors",
51
+ "language_model.model.layers.11.post_attention_layernorm.weight": "model-00005-of-00012.safetensors",
52
+ "language_model.model.layers.11.self_attn.k_proj.weight": "model-00005-of-00012.safetensors",
53
+ "language_model.model.layers.11.self_attn.o_proj.weight": "model-00005-of-00012.safetensors",
54
+ "language_model.model.layers.11.self_attn.q_proj.weight": "model-00005-of-00012.safetensors",
55
+ "language_model.model.layers.11.self_attn.v_proj.weight": "model-00005-of-00012.safetensors",
56
+ "language_model.model.layers.12.input_layernorm.weight": "model-00006-of-00012.safetensors",
57
+ "language_model.model.layers.12.mlp.experts.fc1.weight": "model-00006-of-00012.safetensors",
58
+ "language_model.model.layers.12.mlp.experts.fc2.weight": "model-00006-of-00012.safetensors",
59
+ "language_model.model.layers.12.mlp.router.weight": "model-00005-of-00012.safetensors",
60
+ "language_model.model.layers.12.mlp.shared_experts.down_proj.weight": "model-00006-of-00012.safetensors",
61
+ "language_model.model.layers.12.mlp.shared_experts.gate_proj.weight": "model-00006-of-00012.safetensors",
62
+ "language_model.model.layers.12.mlp.shared_experts.up_proj.weight": "model-00006-of-00012.safetensors",
63
+ "language_model.model.layers.12.post_attention_layernorm.weight": "model-00006-of-00012.safetensors",
64
+ "language_model.model.layers.12.self_attn.k_proj.weight": "model-00005-of-00012.safetensors",
65
+ "language_model.model.layers.12.self_attn.o_proj.weight": "model-00005-of-00012.safetensors",
66
+ "language_model.model.layers.12.self_attn.q_proj.weight": "model-00005-of-00012.safetensors",
67
+ "language_model.model.layers.12.self_attn.v_proj.weight": "model-00005-of-00012.safetensors",
68
+ "language_model.model.layers.13.input_layernorm.weight": "model-00006-of-00012.safetensors",
69
+ "language_model.model.layers.13.mlp.experts.fc1.weight": "model-00006-of-00012.safetensors",
70
+ "language_model.model.layers.13.mlp.experts.fc2.weight": "model-00006-of-00012.safetensors",
71
+ "language_model.model.layers.13.mlp.router.weight": "model-00006-of-00012.safetensors",
72
+ "language_model.model.layers.13.mlp.shared_experts.down_proj.weight": "model-00006-of-00012.safetensors",
73
+ "language_model.model.layers.13.mlp.shared_experts.gate_proj.weight": "model-00006-of-00012.safetensors",
74
+ "language_model.model.layers.13.mlp.shared_experts.up_proj.weight": "model-00006-of-00012.safetensors",
75
+ "language_model.model.layers.13.post_attention_layernorm.weight": "model-00006-of-00012.safetensors",
76
+ "language_model.model.layers.13.self_attn.k_proj.weight": "model-00006-of-00012.safetensors",
77
+ "language_model.model.layers.13.self_attn.o_proj.weight": "model-00006-of-00012.safetensors",
78
+ "language_model.model.layers.13.self_attn.q_proj.weight": "model-00006-of-00012.safetensors",
79
+ "language_model.model.layers.13.self_attn.v_proj.weight": "model-00006-of-00012.safetensors",
80
+ "language_model.model.layers.14.input_layernorm.weight": "model-00007-of-00012.safetensors",
81
+ "language_model.model.layers.14.mlp.experts.fc1.weight": "model-00006-of-00012.safetensors",
82
+ "language_model.model.layers.14.mlp.experts.fc2.weight": "model-00007-of-00012.safetensors",
83
+ "language_model.model.layers.14.mlp.router.weight": "model-00006-of-00012.safetensors",
84
+ "language_model.model.layers.14.mlp.shared_experts.down_proj.weight": "model-00007-of-00012.safetensors",
85
+ "language_model.model.layers.14.mlp.shared_experts.gate_proj.weight": "model-00007-of-00012.safetensors",
86
+ "language_model.model.layers.14.mlp.shared_experts.up_proj.weight": "model-00007-of-00012.safetensors",
87
+ "language_model.model.layers.14.post_attention_layernorm.weight": "model-00007-of-00012.safetensors",
88
+ "language_model.model.layers.14.self_attn.k_proj.weight": "model-00006-of-00012.safetensors",
89
+ "language_model.model.layers.14.self_attn.o_proj.weight": "model-00006-of-00012.safetensors",
90
+ "language_model.model.layers.14.self_attn.q_proj.weight": "model-00006-of-00012.safetensors",
91
+ "language_model.model.layers.14.self_attn.v_proj.weight": "model-00006-of-00012.safetensors",
92
+ "language_model.model.layers.15.input_layernorm.weight": "model-00007-of-00012.safetensors",
93
+ "language_model.model.layers.15.mlp.experts.fc1.weight": "model-00007-of-00012.safetensors",
94
+ "language_model.model.layers.15.mlp.experts.fc2.weight": "model-00007-of-00012.safetensors",
95
+ "language_model.model.layers.15.mlp.router.weight": "model-00007-of-00012.safetensors",
96
+ "language_model.model.layers.15.mlp.shared_experts.down_proj.weight": "model-00007-of-00012.safetensors",
97
+ "language_model.model.layers.15.mlp.shared_experts.gate_proj.weight": "model-00007-of-00012.safetensors",
98
+ "language_model.model.layers.15.mlp.shared_experts.up_proj.weight": "model-00007-of-00012.safetensors",
99
+ "language_model.model.layers.15.post_attention_layernorm.weight": "model-00007-of-00012.safetensors",
100
+ "language_model.model.layers.15.self_attn.k_proj.weight": "model-00007-of-00012.safetensors",
101
+ "language_model.model.layers.15.self_attn.o_proj.weight": "model-00007-of-00012.safetensors",
102
+ "language_model.model.layers.15.self_attn.q_proj.weight": "model-00007-of-00012.safetensors",
103
+ "language_model.model.layers.15.self_attn.v_proj.weight": "model-00007-of-00012.safetensors",
104
+ "language_model.model.layers.16.input_layernorm.weight": "model-00007-of-00012.safetensors",
105
+ "language_model.model.layers.16.mlp.experts.fc1.weight": "model-00007-of-00012.safetensors",
106
+ "language_model.model.layers.16.mlp.experts.fc2.weight": "model-00007-of-00012.safetensors",
107
+ "language_model.model.layers.16.mlp.router.weight": "model-00007-of-00012.safetensors",
108
+ "language_model.model.layers.16.mlp.shared_experts.down_proj.weight": "model-00007-of-00012.safetensors",
109
+ "language_model.model.layers.16.mlp.shared_experts.gate_proj.weight": "model-00007-of-00012.safetensors",
110
+ "language_model.model.layers.16.mlp.shared_experts.up_proj.weight": "model-00007-of-00012.safetensors",
111
+ "language_model.model.layers.16.post_attention_layernorm.weight": "model-00007-of-00012.safetensors",
112
+ "language_model.model.layers.16.self_attn.k_proj.weight": "model-00007-of-00012.safetensors",
113
+ "language_model.model.layers.16.self_attn.o_proj.weight": "model-00007-of-00012.safetensors",
114
+ "language_model.model.layers.16.self_attn.q_proj.weight": "model-00007-of-00012.safetensors",
115
+ "language_model.model.layers.16.self_attn.v_proj.weight": "model-00007-of-00012.safetensors",
116
+ "language_model.model.layers.17.input_layernorm.weight": "model-00008-of-00012.safetensors",
117
+ "language_model.model.layers.17.mlp.experts.fc1.weight": "model-00008-of-00012.safetensors",
118
+ "language_model.model.layers.17.mlp.experts.fc2.weight": "model-00008-of-00012.safetensors",
119
+ "language_model.model.layers.17.mlp.router.weight": "model-00007-of-00012.safetensors",
120
+ "language_model.model.layers.17.mlp.shared_experts.down_proj.weight": "model-00008-of-00012.safetensors",
121
+ "language_model.model.layers.17.mlp.shared_experts.gate_proj.weight": "model-00008-of-00012.safetensors",
122
+ "language_model.model.layers.17.mlp.shared_experts.up_proj.weight": "model-00008-of-00012.safetensors",
123
+ "language_model.model.layers.17.post_attention_layernorm.weight": "model-00008-of-00012.safetensors",
124
+ "language_model.model.layers.17.self_attn.k_proj.weight": "model-00007-of-00012.safetensors",
125
+ "language_model.model.layers.17.self_attn.o_proj.weight": "model-00007-of-00012.safetensors",
126
+ "language_model.model.layers.17.self_attn.q_proj.weight": "model-00007-of-00012.safetensors",
127
+ "language_model.model.layers.17.self_attn.v_proj.weight": "model-00007-of-00012.safetensors",
128
+ "language_model.model.layers.18.input_layernorm.weight": "model-00008-of-00012.safetensors",
129
+ "language_model.model.layers.18.mlp.experts.fc1.weight": "model-00008-of-00012.safetensors",
130
+ "language_model.model.layers.18.mlp.experts.fc2.weight": "model-00008-of-00012.safetensors",
131
+ "language_model.model.layers.18.mlp.router.weight": "model-00008-of-00012.safetensors",
132
+ "language_model.model.layers.18.mlp.shared_experts.down_proj.weight": "model-00008-of-00012.safetensors",
133
+ "language_model.model.layers.18.mlp.shared_experts.gate_proj.weight": "model-00008-of-00012.safetensors",
134
+ "language_model.model.layers.18.mlp.shared_experts.up_proj.weight": "model-00008-of-00012.safetensors",
135
+ "language_model.model.layers.18.post_attention_layernorm.weight": "model-00008-of-00012.safetensors",
136
+ "language_model.model.layers.18.self_attn.k_proj.weight": "model-00008-of-00012.safetensors",
137
+ "language_model.model.layers.18.self_attn.o_proj.weight": "model-00008-of-00012.safetensors",
138
+ "language_model.model.layers.18.self_attn.q_proj.weight": "model-00008-of-00012.safetensors",
139
+ "language_model.model.layers.18.self_attn.v_proj.weight": "model-00008-of-00012.safetensors",
140
+ "language_model.model.layers.19.input_layernorm.weight": "model-00009-of-00012.safetensors",
141
+ "language_model.model.layers.19.mlp.experts.fc1.weight": "model-00008-of-00012.safetensors",
142
+ "language_model.model.layers.19.mlp.experts.fc2.weight": "model-00009-of-00012.safetensors",
143
+ "language_model.model.layers.19.mlp.router.weight": "model-00008-of-00012.safetensors",
144
+ "language_model.model.layers.19.mlp.shared_experts.down_proj.weight": "model-00009-of-00012.safetensors",
145
+ "language_model.model.layers.19.mlp.shared_experts.gate_proj.weight": "model-00009-of-00012.safetensors",
146
+ "language_model.model.layers.19.mlp.shared_experts.up_proj.weight": "model-00009-of-00012.safetensors",
147
+ "language_model.model.layers.19.post_attention_layernorm.weight": "model-00009-of-00012.safetensors",
148
+ "language_model.model.layers.19.self_attn.k_proj.weight": "model-00008-of-00012.safetensors",
149
+ "language_model.model.layers.19.self_attn.o_proj.weight": "model-00008-of-00012.safetensors",
150
+ "language_model.model.layers.19.self_attn.q_proj.weight": "model-00008-of-00012.safetensors",
151
+ "language_model.model.layers.19.self_attn.v_proj.weight": "model-00008-of-00012.safetensors",
152
+ "language_model.model.layers.2.input_layernorm.weight": "model-00002-of-00012.safetensors",
153
+ "language_model.model.layers.2.mlp.experts.fc1.weight": "model-00002-of-00012.safetensors",
154
+ "language_model.model.layers.2.mlp.experts.fc2.weight": "model-00002-of-00012.safetensors",
155
+ "language_model.model.layers.2.mlp.router.weight": "model-00001-of-00012.safetensors",
156
+ "language_model.model.layers.2.mlp.shared_experts.down_proj.weight": "model-00002-of-00012.safetensors",
157
+ "language_model.model.layers.2.mlp.shared_experts.gate_proj.weight": "model-00002-of-00012.safetensors",
158
+ "language_model.model.layers.2.mlp.shared_experts.up_proj.weight": "model-00002-of-00012.safetensors",
159
+ "language_model.model.layers.2.post_attention_layernorm.weight": "model-00002-of-00012.safetensors",
160
+ "language_model.model.layers.2.self_attn.k_proj.weight": "model-00001-of-00012.safetensors",
161
+ "language_model.model.layers.2.self_attn.o_proj.weight": "model-00001-of-00012.safetensors",
162
+ "language_model.model.layers.2.self_attn.q_proj.weight": "model-00001-of-00012.safetensors",
163
+ "language_model.model.layers.2.self_attn.v_proj.weight": "model-00001-of-00012.safetensors",
164
+ "language_model.model.layers.20.input_layernorm.weight": "model-00009-of-00012.safetensors",
165
+ "language_model.model.layers.20.mlp.experts.fc1.weight": "model-00009-of-00012.safetensors",
166
+ "language_model.model.layers.20.mlp.experts.fc2.weight": "model-00009-of-00012.safetensors",
167
+ "language_model.model.layers.20.mlp.router.weight": "model-00009-of-00012.safetensors",
168
+ "language_model.model.layers.20.mlp.shared_experts.down_proj.weight": "model-00009-of-00012.safetensors",
169
+ "language_model.model.layers.20.mlp.shared_experts.gate_proj.weight": "model-00009-of-00012.safetensors",
170
+ "language_model.model.layers.20.mlp.shared_experts.up_proj.weight": "model-00009-of-00012.safetensors",
171
+ "language_model.model.layers.20.post_attention_layernorm.weight": "model-00009-of-00012.safetensors",
172
+ "language_model.model.layers.20.self_attn.k_proj.weight": "model-00009-of-00012.safetensors",
173
+ "language_model.model.layers.20.self_attn.o_proj.weight": "model-00009-of-00012.safetensors",
174
+ "language_model.model.layers.20.self_attn.q_proj.weight": "model-00009-of-00012.safetensors",
175
+ "language_model.model.layers.20.self_attn.v_proj.weight": "model-00009-of-00012.safetensors",
176
+ "language_model.model.layers.21.input_layernorm.weight": "model-00009-of-00012.safetensors",
177
+ "language_model.model.layers.21.mlp.experts.fc1.weight": "model-00009-of-00012.safetensors",
178
+ "language_model.model.layers.21.mlp.experts.fc2.weight": "model-00009-of-00012.safetensors",
179
+ "language_model.model.layers.21.mlp.router.weight": "model-00009-of-00012.safetensors",
180
+ "language_model.model.layers.21.mlp.shared_experts.down_proj.weight": "model-00009-of-00012.safetensors",
181
+ "language_model.model.layers.21.mlp.shared_experts.gate_proj.weight": "model-00009-of-00012.safetensors",
182
+ "language_model.model.layers.21.mlp.shared_experts.up_proj.weight": "model-00009-of-00012.safetensors",
183
+ "language_model.model.layers.21.post_attention_layernorm.weight": "model-00009-of-00012.safetensors",
184
+ "language_model.model.layers.21.self_attn.k_proj.weight": "model-00009-of-00012.safetensors",
185
+ "language_model.model.layers.21.self_attn.o_proj.weight": "model-00009-of-00012.safetensors",
186
+ "language_model.model.layers.21.self_attn.q_proj.weight": "model-00009-of-00012.safetensors",
187
+ "language_model.model.layers.21.self_attn.v_proj.weight": "model-00009-of-00012.safetensors",
188
+ "language_model.model.layers.22.input_layernorm.weight": "model-00010-of-00012.safetensors",
189
+ "language_model.model.layers.22.mlp.experts.fc1.weight": "model-00010-of-00012.safetensors",
190
+ "language_model.model.layers.22.mlp.experts.fc2.weight": "model-00010-of-00012.safetensors",
191
+ "language_model.model.layers.22.mlp.router.weight": "model-00009-of-00012.safetensors",
192
+ "language_model.model.layers.22.mlp.shared_experts.down_proj.weight": "model-00010-of-00012.safetensors",
193
+ "language_model.model.layers.22.mlp.shared_experts.gate_proj.weight": "model-00010-of-00012.safetensors",
194
+ "language_model.model.layers.22.mlp.shared_experts.up_proj.weight": "model-00010-of-00012.safetensors",
195
+ "language_model.model.layers.22.post_attention_layernorm.weight": "model-00010-of-00012.safetensors",
196
+ "language_model.model.layers.22.self_attn.k_proj.weight": "model-00009-of-00012.safetensors",
197
+ "language_model.model.layers.22.self_attn.o_proj.weight": "model-00009-of-00012.safetensors",
198
+ "language_model.model.layers.22.self_attn.q_proj.weight": "model-00009-of-00012.safetensors",
199
+ "language_model.model.layers.22.self_attn.v_proj.weight": "model-00009-of-00012.safetensors",
200
+ "language_model.model.layers.23.input_layernorm.weight": "model-00010-of-00012.safetensors",
201
+ "language_model.model.layers.23.mlp.experts.fc1.weight": "model-00010-of-00012.safetensors",
202
+ "language_model.model.layers.23.mlp.experts.fc2.weight": "model-00010-of-00012.safetensors",
203
+ "language_model.model.layers.23.mlp.router.weight": "model-00010-of-00012.safetensors",
204
+ "language_model.model.layers.23.mlp.shared_experts.down_proj.weight": "model-00010-of-00012.safetensors",
205
+ "language_model.model.layers.23.mlp.shared_experts.gate_proj.weight": "model-00010-of-00012.safetensors",
206
+ "language_model.model.layers.23.mlp.shared_experts.up_proj.weight": "model-00010-of-00012.safetensors",
207
+ "language_model.model.layers.23.post_attention_layernorm.weight": "model-00010-of-00012.safetensors",
208
+ "language_model.model.layers.23.self_attn.k_proj.weight": "model-00010-of-00012.safetensors",
209
+ "language_model.model.layers.23.self_attn.o_proj.weight": "model-00010-of-00012.safetensors",
210
+ "language_model.model.layers.23.self_attn.q_proj.weight": "model-00010-of-00012.safetensors",
211
+ "language_model.model.layers.23.self_attn.v_proj.weight": "model-00010-of-00012.safetensors",
212
+ "language_model.model.layers.24.input_layernorm.weight": "model-00011-of-00012.safetensors",
213
+ "language_model.model.layers.24.mlp.experts.fc1.weight": "model-00010-of-00012.safetensors",
214
+ "language_model.model.layers.24.mlp.experts.fc2.weight": "model-00011-of-00012.safetensors",
215
+ "language_model.model.layers.24.mlp.router.weight": "model-00010-of-00012.safetensors",
216
+ "language_model.model.layers.24.mlp.shared_experts.down_proj.weight": "model-00011-of-00012.safetensors",
217
+ "language_model.model.layers.24.mlp.shared_experts.gate_proj.weight": "model-00011-of-00012.safetensors",
218
+ "language_model.model.layers.24.mlp.shared_experts.up_proj.weight": "model-00011-of-00012.safetensors",
219
+ "language_model.model.layers.24.post_attention_layernorm.weight": "model-00011-of-00012.safetensors",
220
+ "language_model.model.layers.24.self_attn.k_proj.weight": "model-00010-of-00012.safetensors",
221
+ "language_model.model.layers.24.self_attn.o_proj.weight": "model-00010-of-00012.safetensors",
222
+ "language_model.model.layers.24.self_attn.q_proj.weight": "model-00010-of-00012.safetensors",
223
+ "language_model.model.layers.24.self_attn.v_proj.weight": "model-00010-of-00012.safetensors",
224
+ "language_model.model.layers.25.input_layernorm.weight": "model-00011-of-00012.safetensors",
225
+ "language_model.model.layers.25.mlp.experts.fc1.weight": "model-00011-of-00012.safetensors",
226
+ "language_model.model.layers.25.mlp.experts.fc2.weight": "model-00011-of-00012.safetensors",
227
+ "language_model.model.layers.25.mlp.router.weight": "model-00011-of-00012.safetensors",
228
+ "language_model.model.layers.25.mlp.shared_experts.down_proj.weight": "model-00011-of-00012.safetensors",
229
+ "language_model.model.layers.25.mlp.shared_experts.gate_proj.weight": "model-00011-of-00012.safetensors",
230
+ "language_model.model.layers.25.mlp.shared_experts.up_proj.weight": "model-00011-of-00012.safetensors",
231
+ "language_model.model.layers.25.post_attention_layernorm.weight": "model-00011-of-00012.safetensors",
232
+ "language_model.model.layers.25.self_attn.k_proj.weight": "model-00011-of-00012.safetensors",
233
+ "language_model.model.layers.25.self_attn.o_proj.weight": "model-00011-of-00012.safetensors",
234
+ "language_model.model.layers.25.self_attn.q_proj.weight": "model-00011-of-00012.safetensors",
235
+ "language_model.model.layers.25.self_attn.v_proj.weight": "model-00011-of-00012.safetensors",
236
+ "language_model.model.layers.26.input_layernorm.weight": "model-00011-of-00012.safetensors",
237
+ "language_model.model.layers.26.mlp.experts.fc1.weight": "model-00011-of-00012.safetensors",
238
+ "language_model.model.layers.26.mlp.experts.fc2.weight": "model-00011-of-00012.safetensors",
239
+ "language_model.model.layers.26.mlp.router.weight": "model-00011-of-00012.safetensors",
240
+ "language_model.model.layers.26.mlp.shared_experts.down_proj.weight": "model-00011-of-00012.safetensors",
241
+ "language_model.model.layers.26.mlp.shared_experts.gate_proj.weight": "model-00011-of-00012.safetensors",
242
+ "language_model.model.layers.26.mlp.shared_experts.up_proj.weight": "model-00011-of-00012.safetensors",
243
+ "language_model.model.layers.26.post_attention_layernorm.weight": "model-00011-of-00012.safetensors",
244
+ "language_model.model.layers.26.self_attn.k_proj.weight": "model-00011-of-00012.safetensors",
245
+ "language_model.model.layers.26.self_attn.o_proj.weight": "model-00011-of-00012.safetensors",
246
+ "language_model.model.layers.26.self_attn.q_proj.weight": "model-00011-of-00012.safetensors",
247
+ "language_model.model.layers.26.self_attn.v_proj.weight": "model-00011-of-00012.safetensors",
248
+ "language_model.model.layers.27.input_layernorm.weight": "model-00012-of-00012.safetensors",
249
+ "language_model.model.layers.27.mlp.experts.fc1.weight": "model-00012-of-00012.safetensors",
250
+ "language_model.model.layers.27.mlp.experts.fc2.weight": "model-00012-of-00012.safetensors",
251
+ "language_model.model.layers.27.mlp.router.weight": "model-00011-of-00012.safetensors",
252
+ "language_model.model.layers.27.mlp.shared_experts.down_proj.weight": "model-00012-of-00012.safetensors",
253
+ "language_model.model.layers.27.mlp.shared_experts.gate_proj.weight": "model-00012-of-00012.safetensors",
254
+ "language_model.model.layers.27.mlp.shared_experts.up_proj.weight": "model-00012-of-00012.safetensors",
255
+ "language_model.model.layers.27.post_attention_layernorm.weight": "model-00012-of-00012.safetensors",
256
+ "language_model.model.layers.27.self_attn.k_proj.weight": "model-00011-of-00012.safetensors",
257
+ "language_model.model.layers.27.self_attn.o_proj.weight": "model-00011-of-00012.safetensors",
258
+ "language_model.model.layers.27.self_attn.q_proj.weight": "model-00011-of-00012.safetensors",
259
+ "language_model.model.layers.27.self_attn.v_proj.weight": "model-00011-of-00012.safetensors",
260
+ "language_model.model.layers.3.input_layernorm.weight": "model-00002-of-00012.safetensors",
261
+ "language_model.model.layers.3.mlp.experts.fc1.weight": "model-00002-of-00012.safetensors",
262
+ "language_model.model.layers.3.mlp.experts.fc2.weight": "model-00002-of-00012.safetensors",
263
+ "language_model.model.layers.3.mlp.router.weight": "model-00002-of-00012.safetensors",
264
+ "language_model.model.layers.3.mlp.shared_experts.down_proj.weight": "model-00002-of-00012.safetensors",
265
+ "language_model.model.layers.3.mlp.shared_experts.gate_proj.weight": "model-00002-of-00012.safetensors",
266
+ "language_model.model.layers.3.mlp.shared_experts.up_proj.weight": "model-00002-of-00012.safetensors",
267
+ "language_model.model.layers.3.post_attention_layernorm.weight": "model-00002-of-00012.safetensors",
268
+ "language_model.model.layers.3.self_attn.k_proj.weight": "model-00002-of-00012.safetensors",
269
+ "language_model.model.layers.3.self_attn.o_proj.weight": "model-00002-of-00012.safetensors",
270
+ "language_model.model.layers.3.self_attn.q_proj.weight": "model-00002-of-00012.safetensors",
271
+ "language_model.model.layers.3.self_attn.v_proj.weight": "model-00002-of-00012.safetensors",
272
+ "language_model.model.layers.4.input_layernorm.weight": "model-00003-of-00012.safetensors",
273
+ "language_model.model.layers.4.mlp.experts.fc1.weight": "model-00002-of-00012.safetensors",
274
+ "language_model.model.layers.4.mlp.experts.fc2.weight": "model-00003-of-00012.safetensors",
275
+ "language_model.model.layers.4.mlp.router.weight": "model-00002-of-00012.safetensors",
276
+ "language_model.model.layers.4.mlp.shared_experts.down_proj.weight": "model-00003-of-00012.safetensors",
277
+ "language_model.model.layers.4.mlp.shared_experts.gate_proj.weight": "model-00003-of-00012.safetensors",
278
+ "language_model.model.layers.4.mlp.shared_experts.up_proj.weight": "model-00003-of-00012.safetensors",
279
+ "language_model.model.layers.4.post_attention_layernorm.weight": "model-00003-of-00012.safetensors",
280
+ "language_model.model.layers.4.self_attn.k_proj.weight": "model-00002-of-00012.safetensors",
281
+ "language_model.model.layers.4.self_attn.o_proj.weight": "model-00002-of-00012.safetensors",
282
+ "language_model.model.layers.4.self_attn.q_proj.weight": "model-00002-of-00012.safetensors",
283
+ "language_model.model.layers.4.self_attn.v_proj.weight": "model-00002-of-00012.safetensors",
284
+ "language_model.model.layers.5.input_layernorm.weight": "model-00003-of-00012.safetensors",
285
+ "language_model.model.layers.5.mlp.experts.fc1.weight": "model-00003-of-00012.safetensors",
286
+ "language_model.model.layers.5.mlp.experts.fc2.weight": "model-00003-of-00012.safetensors",
287
+ "language_model.model.layers.5.mlp.router.weight": "model-00003-of-00012.safetensors",
288
+ "language_model.model.layers.5.mlp.shared_experts.down_proj.weight": "model-00003-of-00012.safetensors",
289
+ "language_model.model.layers.5.mlp.shared_experts.gate_proj.weight": "model-00003-of-00012.safetensors",
290
+ "language_model.model.layers.5.mlp.shared_experts.up_proj.weight": "model-00003-of-00012.safetensors",
291
+ "language_model.model.layers.5.post_attention_layernorm.weight": "model-00003-of-00012.safetensors",
292
+ "language_model.model.layers.5.self_attn.k_proj.weight": "model-00003-of-00012.safetensors",
293
+ "language_model.model.layers.5.self_attn.o_proj.weight": "model-00003-of-00012.safetensors",
294
+ "language_model.model.layers.5.self_attn.q_proj.weight": "model-00003-of-00012.safetensors",
295
+ "language_model.model.layers.5.self_attn.v_proj.weight": "model-00003-of-00012.safetensors",
296
+ "language_model.model.layers.6.input_layernorm.weight": "model-00003-of-00012.safetensors",
297
+ "language_model.model.layers.6.mlp.experts.fc1.weight": "model-00003-of-00012.safetensors",
298
+ "language_model.model.layers.6.mlp.experts.fc2.weight": "model-00003-of-00012.safetensors",
299
+ "language_model.model.layers.6.mlp.router.weight": "model-00003-of-00012.safetensors",
300
+ "language_model.model.layers.6.mlp.shared_experts.down_proj.weight": "model-00003-of-00012.safetensors",
301
+ "language_model.model.layers.6.mlp.shared_experts.gate_proj.weight": "model-00003-of-00012.safetensors",
302
+ "language_model.model.layers.6.mlp.shared_experts.up_proj.weight": "model-00003-of-00012.safetensors",
303
+ "language_model.model.layers.6.post_attention_layernorm.weight": "model-00003-of-00012.safetensors",
304
+ "language_model.model.layers.6.self_attn.k_proj.weight": "model-00003-of-00012.safetensors",
305
+ "language_model.model.layers.6.self_attn.o_proj.weight": "model-00003-of-00012.safetensors",
306
+ "language_model.model.layers.6.self_attn.q_proj.weight": "model-00003-of-00012.safetensors",
307
+ "language_model.model.layers.6.self_attn.v_proj.weight": "model-00003-of-00012.safetensors",
308
+ "language_model.model.layers.7.input_layernorm.weight": "model-00004-of-00012.safetensors",
309
+ "language_model.model.layers.7.mlp.experts.fc1.weight": "model-00004-of-00012.safetensors",
310
+ "language_model.model.layers.7.mlp.experts.fc2.weight": "model-00004-of-00012.safetensors",
311
+ "language_model.model.layers.7.mlp.router.weight": "model-00003-of-00012.safetensors",
312
+ "language_model.model.layers.7.mlp.shared_experts.down_proj.weight": "model-00004-of-00012.safetensors",
313
+ "language_model.model.layers.7.mlp.shared_experts.gate_proj.weight": "model-00004-of-00012.safetensors",
314
+ "language_model.model.layers.7.mlp.shared_experts.up_proj.weight": "model-00004-of-00012.safetensors",
315
+ "language_model.model.layers.7.post_attention_layernorm.weight": "model-00004-of-00012.safetensors",
316
+ "language_model.model.layers.7.self_attn.k_proj.weight": "model-00003-of-00012.safetensors",
317
+ "language_model.model.layers.7.self_attn.o_proj.weight": "model-00003-of-00012.safetensors",
318
+ "language_model.model.layers.7.self_attn.q_proj.weight": "model-00003-of-00012.safetensors",
319
+ "language_model.model.layers.7.self_attn.v_proj.weight": "model-00003-of-00012.safetensors",
320
+ "language_model.model.layers.8.input_layernorm.weight": "model-00004-of-00012.safetensors",
321
+ "language_model.model.layers.8.mlp.experts.fc1.weight": "model-00004-of-00012.safetensors",
322
+ "language_model.model.layers.8.mlp.experts.fc2.weight": "model-00004-of-00012.safetensors",
323
+ "language_model.model.layers.8.mlp.router.weight": "model-00004-of-00012.safetensors",
324
+ "language_model.model.layers.8.mlp.shared_experts.down_proj.weight": "model-00004-of-00012.safetensors",
325
+ "language_model.model.layers.8.mlp.shared_experts.gate_proj.weight": "model-00004-of-00012.safetensors",
326
+ "language_model.model.layers.8.mlp.shared_experts.up_proj.weight": "model-00004-of-00012.safetensors",
327
+ "language_model.model.layers.8.post_attention_layernorm.weight": "model-00004-of-00012.safetensors",
328
+ "language_model.model.layers.8.self_attn.k_proj.weight": "model-00004-of-00012.safetensors",
329
+ "language_model.model.layers.8.self_attn.o_proj.weight": "model-00004-of-00012.safetensors",
330
+ "language_model.model.layers.8.self_attn.q_proj.weight": "model-00004-of-00012.safetensors",
331
+ "language_model.model.layers.8.self_attn.v_proj.weight": "model-00004-of-00012.safetensors",
332
+ "language_model.model.layers.9.input_layernorm.weight": "model-00005-of-00012.safetensors",
333
+ "language_model.model.layers.9.mlp.experts.fc1.weight": "model-00004-of-00012.safetensors",
334
+ "language_model.model.layers.9.mlp.experts.fc2.weight": "model-00005-of-00012.safetensors",
335
+ "language_model.model.layers.9.mlp.router.weight": "model-00004-of-00012.safetensors",
336
+ "language_model.model.layers.9.mlp.shared_experts.down_proj.weight": "model-00005-of-00012.safetensors",
337
+ "language_model.model.layers.9.mlp.shared_experts.gate_proj.weight": "model-00005-of-00012.safetensors",
338
+ "language_model.model.layers.9.mlp.shared_experts.up_proj.weight": "model-00005-of-00012.safetensors",
339
+ "language_model.model.layers.9.post_attention_layernorm.weight": "model-00005-of-00012.safetensors",
340
+ "language_model.model.layers.9.self_attn.k_proj.weight": "model-00004-of-00012.safetensors",
341
+ "language_model.model.layers.9.self_attn.o_proj.weight": "model-00004-of-00012.safetensors",
342
+ "language_model.model.layers.9.self_attn.q_proj.weight": "model-00004-of-00012.safetensors",
343
+ "language_model.model.layers.9.self_attn.v_proj.weight": "model-00004-of-00012.safetensors",
344
+ "language_model.model.norm.weight": "model-00012-of-00012.safetensors",
345
+ "multi_modal_projector.cross_attn.k_proj.weight": "model-00001-of-00012.safetensors",
346
+ "multi_modal_projector.cross_attn.layer_norm.bias": "model-00001-of-00012.safetensors",
347
+ "multi_modal_projector.cross_attn.layer_norm.weight": "model-00001-of-00012.safetensors",
348
+ "multi_modal_projector.cross_attn.linear.bias": "model-00001-of-00012.safetensors",
349
+ "multi_modal_projector.cross_attn.linear.weight": "model-00001-of-00012.safetensors",
350
+ "multi_modal_projector.cross_attn.ln_kv.bias": "model-00001-of-00012.safetensors",
351
+ "multi_modal_projector.cross_attn.ln_kv.weight": "model-00001-of-00012.safetensors",
352
+ "multi_modal_projector.cross_attn.multihead_attn.in_proj_bias": "model-00001-of-00012.safetensors",
353
+ "multi_modal_projector.cross_attn.multihead_attn.in_proj_weight": "model-00001-of-00012.safetensors",
354
+ "multi_modal_projector.cross_attn.multihead_attn.out_proj.bias": "model-00001-of-00012.safetensors",
355
+ "multi_modal_projector.cross_attn.multihead_attn.out_proj.weight": "model-00001-of-00012.safetensors",
356
+ "multi_modal_projector.cross_attn.q_proj.weight": "model-00001-of-00012.safetensors",
357
+ "multi_modal_projector.cross_attn.v_proj.weight": "model-00001-of-00012.safetensors",
358
+ "multi_modal_projector.ffn.linear_in.weight": "model-00001-of-00012.safetensors",
359
+ "multi_modal_projector.ffn.linear_out.weight": "model-00001-of-00012.safetensors",
360
+ "multi_modal_projector.ln_ffn.bias": "model-00001-of-00012.safetensors",
361
+ "multi_modal_projector.ln_ffn.weight": "model-00001-of-00012.safetensors",
362
+ "multi_modal_projector.query": "model-00001-of-00012.safetensors",
363
+ "vision_tower.vision_model.embeddings.patch_embedding.bias": "model-00001-of-00012.safetensors",
364
+ "vision_tower.vision_model.embeddings.patch_embedding.weight": "model-00001-of-00012.safetensors",
365
+ "vision_tower.vision_model.embeddings.position_embedding.weight": "model-00001-of-00012.safetensors",
366
+ "vision_tower.vision_model.encoder.layers.0.layer_norm1.bias": "model-00001-of-00012.safetensors",
367
+ "vision_tower.vision_model.encoder.layers.0.layer_norm1.weight": "model-00001-of-00012.safetensors",
368
+ "vision_tower.vision_model.encoder.layers.0.layer_norm2.bias": "model-00001-of-00012.safetensors",
369
+ "vision_tower.vision_model.encoder.layers.0.layer_norm2.weight": "model-00001-of-00012.safetensors",
370
+ "vision_tower.vision_model.encoder.layers.0.mlp.fc1.bias": "model-00001-of-00012.safetensors",
371
+ "vision_tower.vision_model.encoder.layers.0.mlp.fc1.weight": "model-00001-of-00012.safetensors",
372
+ "vision_tower.vision_model.encoder.layers.0.mlp.fc2.bias": "model-00001-of-00012.safetensors",
373
+ "vision_tower.vision_model.encoder.layers.0.mlp.fc2.weight": "model-00001-of-00012.safetensors",
374
+ "vision_tower.vision_model.encoder.layers.0.self_attn.k_proj.bias": "model-00001-of-00012.safetensors",
375
+ "vision_tower.vision_model.encoder.layers.0.self_attn.k_proj.weight": "model-00001-of-00012.safetensors",
376
+ "vision_tower.vision_model.encoder.layers.0.self_attn.out_proj.bias": "model-00001-of-00012.safetensors",
377
+ "vision_tower.vision_model.encoder.layers.0.self_attn.out_proj.weight": "model-00001-of-00012.safetensors",
378
+ "vision_tower.vision_model.encoder.layers.0.self_attn.q_proj.bias": "model-00001-of-00012.safetensors",
379
+ "vision_tower.vision_model.encoder.layers.0.self_attn.q_proj.weight": "model-00001-of-00012.safetensors",
380
+ "vision_tower.vision_model.encoder.layers.0.self_attn.v_proj.bias": "model-00001-of-00012.safetensors",
381
+ "vision_tower.vision_model.encoder.layers.0.self_attn.v_proj.weight": "model-00001-of-00012.safetensors",
382
+ "vision_tower.vision_model.encoder.layers.1.layer_norm1.bias": "model-00001-of-00012.safetensors",
383
+ "vision_tower.vision_model.encoder.layers.1.layer_norm1.weight": "model-00001-of-00012.safetensors",
384
+ "vision_tower.vision_model.encoder.layers.1.layer_norm2.bias": "model-00001-of-00012.safetensors",
385
+ "vision_tower.vision_model.encoder.layers.1.layer_norm2.weight": "model-00001-of-00012.safetensors",
386
+ "vision_tower.vision_model.encoder.layers.1.mlp.fc1.bias": "model-00001-of-00012.safetensors",
387
+ "vision_tower.vision_model.encoder.layers.1.mlp.fc1.weight": "model-00001-of-00012.safetensors",
388
+ "vision_tower.vision_model.encoder.layers.1.mlp.fc2.bias": "model-00001-of-00012.safetensors",
389
+ "vision_tower.vision_model.encoder.layers.1.mlp.fc2.weight": "model-00001-of-00012.safetensors",
390
+ "vision_tower.vision_model.encoder.layers.1.self_attn.k_proj.bias": "model-00001-of-00012.safetensors",
391
+ "vision_tower.vision_model.encoder.layers.1.self_attn.k_proj.weight": "model-00001-of-00012.safetensors",
392
+ "vision_tower.vision_model.encoder.layers.1.self_attn.out_proj.bias": "model-00001-of-00012.safetensors",
393
+ "vision_tower.vision_model.encoder.layers.1.self_attn.out_proj.weight": "model-00001-of-00012.safetensors",
394
+ "vision_tower.vision_model.encoder.layers.1.self_attn.q_proj.bias": "model-00001-of-00012.safetensors",
395
+ "vision_tower.vision_model.encoder.layers.1.self_attn.q_proj.weight": "model-00001-of-00012.safetensors",
396
+ "vision_tower.vision_model.encoder.layers.1.self_attn.v_proj.bias": "model-00001-of-00012.safetensors",
397
+ "vision_tower.vision_model.encoder.layers.1.self_attn.v_proj.weight": "model-00001-of-00012.safetensors",
398
+ "vision_tower.vision_model.encoder.layers.10.layer_norm1.bias": "model-00001-of-00012.safetensors",
399
+ "vision_tower.vision_model.encoder.layers.10.layer_norm1.weight": "model-00001-of-00012.safetensors",
400
+ "vision_tower.vision_model.encoder.layers.10.layer_norm2.bias": "model-00001-of-00012.safetensors",
401
+ "vision_tower.vision_model.encoder.layers.10.layer_norm2.weight": "model-00001-of-00012.safetensors",
402
+ "vision_tower.vision_model.encoder.layers.10.mlp.fc1.bias": "model-00001-of-00012.safetensors",
403
+ "vision_tower.vision_model.encoder.layers.10.mlp.fc1.weight": "model-00001-of-00012.safetensors",
404
+ "vision_tower.vision_model.encoder.layers.10.mlp.fc2.bias": "model-00001-of-00012.safetensors",
405
+ "vision_tower.vision_model.encoder.layers.10.mlp.fc2.weight": "model-00001-of-00012.safetensors",
406
+ "vision_tower.vision_model.encoder.layers.10.self_attn.k_proj.bias": "model-00001-of-00012.safetensors",
407
+ "vision_tower.vision_model.encoder.layers.10.self_attn.k_proj.weight": "model-00001-of-00012.safetensors",
408
+ "vision_tower.vision_model.encoder.layers.10.self_attn.out_proj.bias": "model-00001-of-00012.safetensors",
409
+ "vision_tower.vision_model.encoder.layers.10.self_attn.out_proj.weight": "model-00001-of-00012.safetensors",
410
+ "vision_tower.vision_model.encoder.layers.10.self_attn.q_proj.bias": "model-00001-of-00012.safetensors",
411
+ "vision_tower.vision_model.encoder.layers.10.self_attn.q_proj.weight": "model-00001-of-00012.safetensors",
412
+ "vision_tower.vision_model.encoder.layers.10.self_attn.v_proj.bias": "model-00001-of-00012.safetensors",
413
+ "vision_tower.vision_model.encoder.layers.10.self_attn.v_proj.weight": "model-00001-of-00012.safetensors",
414
+ "vision_tower.vision_model.encoder.layers.11.layer_norm1.bias": "model-00001-of-00012.safetensors",
415
+ "vision_tower.vision_model.encoder.layers.11.layer_norm1.weight": "model-00001-of-00012.safetensors",
416
+ "vision_tower.vision_model.encoder.layers.11.layer_norm2.bias": "model-00001-of-00012.safetensors",
417
+ "vision_tower.vision_model.encoder.layers.11.layer_norm2.weight": "model-00001-of-00012.safetensors",
418
+ "vision_tower.vision_model.encoder.layers.11.mlp.fc1.bias": "model-00001-of-00012.safetensors",
419
+ "vision_tower.vision_model.encoder.layers.11.mlp.fc1.weight": "model-00001-of-00012.safetensors",
420
+ "vision_tower.vision_model.encoder.layers.11.mlp.fc2.bias": "model-00001-of-00012.safetensors",
421
+ "vision_tower.vision_model.encoder.layers.11.mlp.fc2.weight": "model-00001-of-00012.safetensors",
422
+ "vision_tower.vision_model.encoder.layers.11.self_attn.k_proj.bias": "model-00001-of-00012.safetensors",
423
+ "vision_tower.vision_model.encoder.layers.11.self_attn.k_proj.weight": "model-00001-of-00012.safetensors",
424
+ "vision_tower.vision_model.encoder.layers.11.self_attn.out_proj.bias": "model-00001-of-00012.safetensors",
425
+ "vision_tower.vision_model.encoder.layers.11.self_attn.out_proj.weight": "model-00001-of-00012.safetensors",
426
+ "vision_tower.vision_model.encoder.layers.11.self_attn.q_proj.bias": "model-00001-of-00012.safetensors",
427
+ "vision_tower.vision_model.encoder.layers.11.self_attn.q_proj.weight": "model-00001-of-00012.safetensors",
428
+ "vision_tower.vision_model.encoder.layers.11.self_attn.v_proj.bias": "model-00001-of-00012.safetensors",
429
+ "vision_tower.vision_model.encoder.layers.11.self_attn.v_proj.weight": "model-00001-of-00012.safetensors",
430
+ "vision_tower.vision_model.encoder.layers.12.layer_norm1.bias": "model-00001-of-00012.safetensors",
431
+ "vision_tower.vision_model.encoder.layers.12.layer_norm1.weight": "model-00001-of-00012.safetensors",
432
+ "vision_tower.vision_model.encoder.layers.12.layer_norm2.bias": "model-00001-of-00012.safetensors",
433
+ "vision_tower.vision_model.encoder.layers.12.layer_norm2.weight": "model-00001-of-00012.safetensors",
434
+ "vision_tower.vision_model.encoder.layers.12.mlp.fc1.bias": "model-00001-of-00012.safetensors",
435
+ "vision_tower.vision_model.encoder.layers.12.mlp.fc1.weight": "model-00001-of-00012.safetensors",
436
+ "vision_tower.vision_model.encoder.layers.12.mlp.fc2.bias": "model-00001-of-00012.safetensors",
437
+ "vision_tower.vision_model.encoder.layers.12.mlp.fc2.weight": "model-00001-of-00012.safetensors",
438
+ "vision_tower.vision_model.encoder.layers.12.self_attn.k_proj.bias": "model-00001-of-00012.safetensors",
439
+ "vision_tower.vision_model.encoder.layers.12.self_attn.k_proj.weight": "model-00001-of-00012.safetensors",
440
+ "vision_tower.vision_model.encoder.layers.12.self_attn.out_proj.bias": "model-00001-of-00012.safetensors",
441
+ "vision_tower.vision_model.encoder.layers.12.self_attn.out_proj.weight": "model-00001-of-00012.safetensors",
442
+ "vision_tower.vision_model.encoder.layers.12.self_attn.q_proj.bias": "model-00001-of-00012.safetensors",
443
+ "vision_tower.vision_model.encoder.layers.12.self_attn.q_proj.weight": "model-00001-of-00012.safetensors",
444
+ "vision_tower.vision_model.encoder.layers.12.self_attn.v_proj.bias": "model-00001-of-00012.safetensors",
445
+ "vision_tower.vision_model.encoder.layers.12.self_attn.v_proj.weight": "model-00001-of-00012.safetensors",
446
+ "vision_tower.vision_model.encoder.layers.13.layer_norm1.bias": "model-00001-of-00012.safetensors",
447
+ "vision_tower.vision_model.encoder.layers.13.layer_norm1.weight": "model-00001-of-00012.safetensors",
448
+ "vision_tower.vision_model.encoder.layers.13.layer_norm2.bias": "model-00001-of-00012.safetensors",
449
+ "vision_tower.vision_model.encoder.layers.13.layer_norm2.weight": "model-00001-of-00012.safetensors",
450
+ "vision_tower.vision_model.encoder.layers.13.mlp.fc1.bias": "model-00001-of-00012.safetensors",
451
+ "vision_tower.vision_model.encoder.layers.13.mlp.fc1.weight": "model-00001-of-00012.safetensors",
452
+ "vision_tower.vision_model.encoder.layers.13.mlp.fc2.bias": "model-00001-of-00012.safetensors",
453
+ "vision_tower.vision_model.encoder.layers.13.mlp.fc2.weight": "model-00001-of-00012.safetensors",
454
+ "vision_tower.vision_model.encoder.layers.13.self_attn.k_proj.bias": "model-00001-of-00012.safetensors",
455
+ "vision_tower.vision_model.encoder.layers.13.self_attn.k_proj.weight": "model-00001-of-00012.safetensors",
456
+ "vision_tower.vision_model.encoder.layers.13.self_attn.out_proj.bias": "model-00001-of-00012.safetensors",
457
+ "vision_tower.vision_model.encoder.layers.13.self_attn.out_proj.weight": "model-00001-of-00012.safetensors",
458
+ "vision_tower.vision_model.encoder.layers.13.self_attn.q_proj.bias": "model-00001-of-00012.safetensors",
459
+ "vision_tower.vision_model.encoder.layers.13.self_attn.q_proj.weight": "model-00001-of-00012.safetensors",
460
+ "vision_tower.vision_model.encoder.layers.13.self_attn.v_proj.bias": "model-00001-of-00012.safetensors",
461
+ "vision_tower.vision_model.encoder.layers.13.self_attn.v_proj.weight": "model-00001-of-00012.safetensors",
462
+ "vision_tower.vision_model.encoder.layers.14.layer_norm1.bias": "model-00001-of-00012.safetensors",
463
+ "vision_tower.vision_model.encoder.layers.14.layer_norm1.weight": "model-00001-of-00012.safetensors",
464
+ "vision_tower.vision_model.encoder.layers.14.layer_norm2.bias": "model-00001-of-00012.safetensors",
465
+ "vision_tower.vision_model.encoder.layers.14.layer_norm2.weight": "model-00001-of-00012.safetensors",
466
+ "vision_tower.vision_model.encoder.layers.14.mlp.fc1.bias": "model-00001-of-00012.safetensors",
467
+ "vision_tower.vision_model.encoder.layers.14.mlp.fc1.weight": "model-00001-of-00012.safetensors",
468
+ "vision_tower.vision_model.encoder.layers.14.mlp.fc2.bias": "model-00001-of-00012.safetensors",
469
+ "vision_tower.vision_model.encoder.layers.14.mlp.fc2.weight": "model-00001-of-00012.safetensors",
470
+ "vision_tower.vision_model.encoder.layers.14.self_attn.k_proj.bias": "model-00001-of-00012.safetensors",
471
+ "vision_tower.vision_model.encoder.layers.14.self_attn.k_proj.weight": "model-00001-of-00012.safetensors",
472
+ "vision_tower.vision_model.encoder.layers.14.self_attn.out_proj.bias": "model-00001-of-00012.safetensors",
473
+ "vision_tower.vision_model.encoder.layers.14.self_attn.out_proj.weight": "model-00001-of-00012.safetensors",
474
+ "vision_tower.vision_model.encoder.layers.14.self_attn.q_proj.bias": "model-00001-of-00012.safetensors",
475
+ "vision_tower.vision_model.encoder.layers.14.self_attn.q_proj.weight": "model-00001-of-00012.safetensors",
476
+ "vision_tower.vision_model.encoder.layers.14.self_attn.v_proj.bias": "model-00001-of-00012.safetensors",
477
+ "vision_tower.vision_model.encoder.layers.14.self_attn.v_proj.weight": "model-00001-of-00012.safetensors",
478
+ "vision_tower.vision_model.encoder.layers.15.layer_norm1.bias": "model-00001-of-00012.safetensors",
479
+ "vision_tower.vision_model.encoder.layers.15.layer_norm1.weight": "model-00001-of-00012.safetensors",
480
+ "vision_tower.vision_model.encoder.layers.15.layer_norm2.bias": "model-00001-of-00012.safetensors",
481
+ "vision_tower.vision_model.encoder.layers.15.layer_norm2.weight": "model-00001-of-00012.safetensors",
482
+ "vision_tower.vision_model.encoder.layers.15.mlp.fc1.bias": "model-00001-of-00012.safetensors",
483
+ "vision_tower.vision_model.encoder.layers.15.mlp.fc1.weight": "model-00001-of-00012.safetensors",
484
+ "vision_tower.vision_model.encoder.layers.15.mlp.fc2.bias": "model-00001-of-00012.safetensors",
485
+ "vision_tower.vision_model.encoder.layers.15.mlp.fc2.weight": "model-00001-of-00012.safetensors",
486
+ "vision_tower.vision_model.encoder.layers.15.self_attn.k_proj.bias": "model-00001-of-00012.safetensors",
487
+ "vision_tower.vision_model.encoder.layers.15.self_attn.k_proj.weight": "model-00001-of-00012.safetensors",
488
+ "vision_tower.vision_model.encoder.layers.15.self_attn.out_proj.bias": "model-00001-of-00012.safetensors",
489
+ "vision_tower.vision_model.encoder.layers.15.self_attn.out_proj.weight": "model-00001-of-00012.safetensors",
490
+ "vision_tower.vision_model.encoder.layers.15.self_attn.q_proj.bias": "model-00001-of-00012.safetensors",
491
+ "vision_tower.vision_model.encoder.layers.15.self_attn.q_proj.weight": "model-00001-of-00012.safetensors",
492
+ "vision_tower.vision_model.encoder.layers.15.self_attn.v_proj.bias": "model-00001-of-00012.safetensors",
493
+ "vision_tower.vision_model.encoder.layers.15.self_attn.v_proj.weight": "model-00001-of-00012.safetensors",
494
+ "vision_tower.vision_model.encoder.layers.16.layer_norm1.bias": "model-00001-of-00012.safetensors",
495
+ "vision_tower.vision_model.encoder.layers.16.layer_norm1.weight": "model-00001-of-00012.safetensors",
496
+ "vision_tower.vision_model.encoder.layers.16.layer_norm2.bias": "model-00001-of-00012.safetensors",
497
+ "vision_tower.vision_model.encoder.layers.16.layer_norm2.weight": "model-00001-of-00012.safetensors",
498
+ "vision_tower.vision_model.encoder.layers.16.mlp.fc1.bias": "model-00001-of-00012.safetensors",
499
+ "vision_tower.vision_model.encoder.layers.16.mlp.fc1.weight": "model-00001-of-00012.safetensors",
500
+ "vision_tower.vision_model.encoder.layers.16.mlp.fc2.bias": "model-00001-of-00012.safetensors",
501
+ "vision_tower.vision_model.encoder.layers.16.mlp.fc2.weight": "model-00001-of-00012.safetensors",
502
+ "vision_tower.vision_model.encoder.layers.16.self_attn.k_proj.bias": "model-00001-of-00012.safetensors",
503
+ "vision_tower.vision_model.encoder.layers.16.self_attn.k_proj.weight": "model-00001-of-00012.safetensors",
504
+ "vision_tower.vision_model.encoder.layers.16.self_attn.out_proj.bias": "model-00001-of-00012.safetensors",
505
+ "vision_tower.vision_model.encoder.layers.16.self_attn.out_proj.weight": "model-00001-of-00012.safetensors",
506
+ "vision_tower.vision_model.encoder.layers.16.self_attn.q_proj.bias": "model-00001-of-00012.safetensors",
507
+ "vision_tower.vision_model.encoder.layers.16.self_attn.q_proj.weight": "model-00001-of-00012.safetensors",
508
+ "vision_tower.vision_model.encoder.layers.16.self_attn.v_proj.bias": "model-00001-of-00012.safetensors",
509
+ "vision_tower.vision_model.encoder.layers.16.self_attn.v_proj.weight": "model-00001-of-00012.safetensors",
510
+ "vision_tower.vision_model.encoder.layers.17.layer_norm1.bias": "model-00001-of-00012.safetensors",
511
+ "vision_tower.vision_model.encoder.layers.17.layer_norm1.weight": "model-00001-of-00012.safetensors",
512
+ "vision_tower.vision_model.encoder.layers.17.layer_norm2.bias": "model-00001-of-00012.safetensors",
513
+ "vision_tower.vision_model.encoder.layers.17.layer_norm2.weight": "model-00001-of-00012.safetensors",
514
+ "vision_tower.vision_model.encoder.layers.17.mlp.fc1.bias": "model-00001-of-00012.safetensors",
515
+ "vision_tower.vision_model.encoder.layers.17.mlp.fc1.weight": "model-00001-of-00012.safetensors",
516
+ "vision_tower.vision_model.encoder.layers.17.mlp.fc2.bias": "model-00001-of-00012.safetensors",
517
+ "vision_tower.vision_model.encoder.layers.17.mlp.fc2.weight": "model-00001-of-00012.safetensors",
518
+ "vision_tower.vision_model.encoder.layers.17.self_attn.k_proj.bias": "model-00001-of-00012.safetensors",
519
+ "vision_tower.vision_model.encoder.layers.17.self_attn.k_proj.weight": "model-00001-of-00012.safetensors",
520
+ "vision_tower.vision_model.encoder.layers.17.self_attn.out_proj.bias": "model-00001-of-00012.safetensors",
521
+ "vision_tower.vision_model.encoder.layers.17.self_attn.out_proj.weight": "model-00001-of-00012.safetensors",
522
+ "vision_tower.vision_model.encoder.layers.17.self_attn.q_proj.bias": "model-00001-of-00012.safetensors",
523
+ "vision_tower.vision_model.encoder.layers.17.self_attn.q_proj.weight": "model-00001-of-00012.safetensors",
524
+ "vision_tower.vision_model.encoder.layers.17.self_attn.v_proj.bias": "model-00001-of-00012.safetensors",
525
+ "vision_tower.vision_model.encoder.layers.17.self_attn.v_proj.weight": "model-00001-of-00012.safetensors",
526
+ "vision_tower.vision_model.encoder.layers.18.layer_norm1.bias": "model-00001-of-00012.safetensors",
527
+ "vision_tower.vision_model.encoder.layers.18.layer_norm1.weight": "model-00001-of-00012.safetensors",
528
+ "vision_tower.vision_model.encoder.layers.18.layer_norm2.bias": "model-00001-of-00012.safetensors",
529
+ "vision_tower.vision_model.encoder.layers.18.layer_norm2.weight": "model-00001-of-00012.safetensors",
530
+ "vision_tower.vision_model.encoder.layers.18.mlp.fc1.bias": "model-00001-of-00012.safetensors",
531
+ "vision_tower.vision_model.encoder.layers.18.mlp.fc1.weight": "model-00001-of-00012.safetensors",
532
+ "vision_tower.vision_model.encoder.layers.18.mlp.fc2.bias": "model-00001-of-00012.safetensors",
533
+ "vision_tower.vision_model.encoder.layers.18.mlp.fc2.weight": "model-00001-of-00012.safetensors",
534
+ "vision_tower.vision_model.encoder.layers.18.self_attn.k_proj.bias": "model-00001-of-00012.safetensors",
535
+ "vision_tower.vision_model.encoder.layers.18.self_attn.k_proj.weight": "model-00001-of-00012.safetensors",
536
+ "vision_tower.vision_model.encoder.layers.18.self_attn.out_proj.bias": "model-00001-of-00012.safetensors",
537
+ "vision_tower.vision_model.encoder.layers.18.self_attn.out_proj.weight": "model-00001-of-00012.safetensors",
538
+ "vision_tower.vision_model.encoder.layers.18.self_attn.q_proj.bias": "model-00001-of-00012.safetensors",
539
+ "vision_tower.vision_model.encoder.layers.18.self_attn.q_proj.weight": "model-00001-of-00012.safetensors",
540
+ "vision_tower.vision_model.encoder.layers.18.self_attn.v_proj.bias": "model-00001-of-00012.safetensors",
541
+ "vision_tower.vision_model.encoder.layers.18.self_attn.v_proj.weight": "model-00001-of-00012.safetensors",
542
+ "vision_tower.vision_model.encoder.layers.19.layer_norm1.bias": "model-00001-of-00012.safetensors",
543
+ "vision_tower.vision_model.encoder.layers.19.layer_norm1.weight": "model-00001-of-00012.safetensors",
544
+ "vision_tower.vision_model.encoder.layers.19.layer_norm2.bias": "model-00001-of-00012.safetensors",
545
+ "vision_tower.vision_model.encoder.layers.19.layer_norm2.weight": "model-00001-of-00012.safetensors",
546
+ "vision_tower.vision_model.encoder.layers.19.mlp.fc1.bias": "model-00001-of-00012.safetensors",
547
+ "vision_tower.vision_model.encoder.layers.19.mlp.fc1.weight": "model-00001-of-00012.safetensors",
548
+ "vision_tower.vision_model.encoder.layers.19.mlp.fc2.bias": "model-00001-of-00012.safetensors",
549
+ "vision_tower.vision_model.encoder.layers.19.mlp.fc2.weight": "model-00001-of-00012.safetensors",
550
+ "vision_tower.vision_model.encoder.layers.19.self_attn.k_proj.bias": "model-00001-of-00012.safetensors",
551
+ "vision_tower.vision_model.encoder.layers.19.self_attn.k_proj.weight": "model-00001-of-00012.safetensors",
552
+ "vision_tower.vision_model.encoder.layers.19.self_attn.out_proj.bias": "model-00001-of-00012.safetensors",
553
+ "vision_tower.vision_model.encoder.layers.19.self_attn.out_proj.weight": "model-00001-of-00012.safetensors",
554
+ "vision_tower.vision_model.encoder.layers.19.self_attn.q_proj.bias": "model-00001-of-00012.safetensors",
555
+ "vision_tower.vision_model.encoder.layers.19.self_attn.q_proj.weight": "model-00001-of-00012.safetensors",
556
+ "vision_tower.vision_model.encoder.layers.19.self_attn.v_proj.bias": "model-00001-of-00012.safetensors",
557
+ "vision_tower.vision_model.encoder.layers.19.self_attn.v_proj.weight": "model-00001-of-00012.safetensors",
558
+ "vision_tower.vision_model.encoder.layers.2.layer_norm1.bias": "model-00001-of-00012.safetensors",
559
+ "vision_tower.vision_model.encoder.layers.2.layer_norm1.weight": "model-00001-of-00012.safetensors",
560
+ "vision_tower.vision_model.encoder.layers.2.layer_norm2.bias": "model-00001-of-00012.safetensors",
561
+ "vision_tower.vision_model.encoder.layers.2.layer_norm2.weight": "model-00001-of-00012.safetensors",
562
+ "vision_tower.vision_model.encoder.layers.2.mlp.fc1.bias": "model-00001-of-00012.safetensors",
563
+ "vision_tower.vision_model.encoder.layers.2.mlp.fc1.weight": "model-00001-of-00012.safetensors",
564
+ "vision_tower.vision_model.encoder.layers.2.mlp.fc2.bias": "model-00001-of-00012.safetensors",
565
+ "vision_tower.vision_model.encoder.layers.2.mlp.fc2.weight": "model-00001-of-00012.safetensors",
566
+ "vision_tower.vision_model.encoder.layers.2.self_attn.k_proj.bias": "model-00001-of-00012.safetensors",
567
+ "vision_tower.vision_model.encoder.layers.2.self_attn.k_proj.weight": "model-00001-of-00012.safetensors",
568
+ "vision_tower.vision_model.encoder.layers.2.self_attn.out_proj.bias": "model-00001-of-00012.safetensors",
569
+ "vision_tower.vision_model.encoder.layers.2.self_attn.out_proj.weight": "model-00001-of-00012.safetensors",
570
+ "vision_tower.vision_model.encoder.layers.2.self_attn.q_proj.bias": "model-00001-of-00012.safetensors",
571
+ "vision_tower.vision_model.encoder.layers.2.self_attn.q_proj.weight": "model-00001-of-00012.safetensors",
572
+ "vision_tower.vision_model.encoder.layers.2.self_attn.v_proj.bias": "model-00001-of-00012.safetensors",
573
+ "vision_tower.vision_model.encoder.layers.2.self_attn.v_proj.weight": "model-00001-of-00012.safetensors",
574
+ "vision_tower.vision_model.encoder.layers.20.layer_norm1.bias": "model-00001-of-00012.safetensors",
575
+ "vision_tower.vision_model.encoder.layers.20.layer_norm1.weight": "model-00001-of-00012.safetensors",
576
+ "vision_tower.vision_model.encoder.layers.20.layer_norm2.bias": "model-00001-of-00012.safetensors",
577
+ "vision_tower.vision_model.encoder.layers.20.layer_norm2.weight": "model-00001-of-00012.safetensors",
578
+ "vision_tower.vision_model.encoder.layers.20.mlp.fc1.bias": "model-00001-of-00012.safetensors",
579
+ "vision_tower.vision_model.encoder.layers.20.mlp.fc1.weight": "model-00001-of-00012.safetensors",
580
+ "vision_tower.vision_model.encoder.layers.20.mlp.fc2.bias": "model-00001-of-00012.safetensors",
581
+ "vision_tower.vision_model.encoder.layers.20.mlp.fc2.weight": "model-00001-of-00012.safetensors",
582
+ "vision_tower.vision_model.encoder.layers.20.self_attn.k_proj.bias": "model-00001-of-00012.safetensors",
583
+ "vision_tower.vision_model.encoder.layers.20.self_attn.k_proj.weight": "model-00001-of-00012.safetensors",
584
+ "vision_tower.vision_model.encoder.layers.20.self_attn.out_proj.bias": "model-00001-of-00012.safetensors",
585
+ "vision_tower.vision_model.encoder.layers.20.self_attn.out_proj.weight": "model-00001-of-00012.safetensors",
586
+ "vision_tower.vision_model.encoder.layers.20.self_attn.q_proj.bias": "model-00001-of-00012.safetensors",
587
+ "vision_tower.vision_model.encoder.layers.20.self_attn.q_proj.weight": "model-00001-of-00012.safetensors",
588
+ "vision_tower.vision_model.encoder.layers.20.self_attn.v_proj.bias": "model-00001-of-00012.safetensors",
589
+ "vision_tower.vision_model.encoder.layers.20.self_attn.v_proj.weight": "model-00001-of-00012.safetensors",
590
+ "vision_tower.vision_model.encoder.layers.21.layer_norm1.bias": "model-00001-of-00012.safetensors",
591
+ "vision_tower.vision_model.encoder.layers.21.layer_norm1.weight": "model-00001-of-00012.safetensors",
592
+ "vision_tower.vision_model.encoder.layers.21.layer_norm2.bias": "model-00001-of-00012.safetensors",
593
+ "vision_tower.vision_model.encoder.layers.21.layer_norm2.weight": "model-00001-of-00012.safetensors",
594
+ "vision_tower.vision_model.encoder.layers.21.mlp.fc1.bias": "model-00001-of-00012.safetensors",
595
+ "vision_tower.vision_model.encoder.layers.21.mlp.fc1.weight": "model-00001-of-00012.safetensors",
596
+ "vision_tower.vision_model.encoder.layers.21.mlp.fc2.bias": "model-00001-of-00012.safetensors",
597
+ "vision_tower.vision_model.encoder.layers.21.mlp.fc2.weight": "model-00001-of-00012.safetensors",
598
+ "vision_tower.vision_model.encoder.layers.21.self_attn.k_proj.bias": "model-00001-of-00012.safetensors",
599
+ "vision_tower.vision_model.encoder.layers.21.self_attn.k_proj.weight": "model-00001-of-00012.safetensors",
600
+ "vision_tower.vision_model.encoder.layers.21.self_attn.out_proj.bias": "model-00001-of-00012.safetensors",
601
+ "vision_tower.vision_model.encoder.layers.21.self_attn.out_proj.weight": "model-00001-of-00012.safetensors",
602
+ "vision_tower.vision_model.encoder.layers.21.self_attn.q_proj.bias": "model-00001-of-00012.safetensors",
603
+ "vision_tower.vision_model.encoder.layers.21.self_attn.q_proj.weight": "model-00001-of-00012.safetensors",
604
+ "vision_tower.vision_model.encoder.layers.21.self_attn.v_proj.bias": "model-00001-of-00012.safetensors",
605
+ "vision_tower.vision_model.encoder.layers.21.self_attn.v_proj.weight": "model-00001-of-00012.safetensors",
606
+ "vision_tower.vision_model.encoder.layers.22.layer_norm1.bias": "model-00001-of-00012.safetensors",
607
+ "vision_tower.vision_model.encoder.layers.22.layer_norm1.weight": "model-00001-of-00012.safetensors",
608
+ "vision_tower.vision_model.encoder.layers.22.layer_norm2.bias": "model-00001-of-00012.safetensors",
609
+ "vision_tower.vision_model.encoder.layers.22.layer_norm2.weight": "model-00001-of-00012.safetensors",
610
+ "vision_tower.vision_model.encoder.layers.22.mlp.fc1.bias": "model-00001-of-00012.safetensors",
611
+ "vision_tower.vision_model.encoder.layers.22.mlp.fc1.weight": "model-00001-of-00012.safetensors",
612
+ "vision_tower.vision_model.encoder.layers.22.mlp.fc2.bias": "model-00001-of-00012.safetensors",
613
+ "vision_tower.vision_model.encoder.layers.22.mlp.fc2.weight": "model-00001-of-00012.safetensors",
614
+ "vision_tower.vision_model.encoder.layers.22.self_attn.k_proj.bias": "model-00001-of-00012.safetensors",
615
+ "vision_tower.vision_model.encoder.layers.22.self_attn.k_proj.weight": "model-00001-of-00012.safetensors",
616
+ "vision_tower.vision_model.encoder.layers.22.self_attn.out_proj.bias": "model-00001-of-00012.safetensors",
617
+ "vision_tower.vision_model.encoder.layers.22.self_attn.out_proj.weight": "model-00001-of-00012.safetensors",
618
+ "vision_tower.vision_model.encoder.layers.22.self_attn.q_proj.bias": "model-00001-of-00012.safetensors",
619
+ "vision_tower.vision_model.encoder.layers.22.self_attn.q_proj.weight": "model-00001-of-00012.safetensors",
620
+ "vision_tower.vision_model.encoder.layers.22.self_attn.v_proj.bias": "model-00001-of-00012.safetensors",
621
+ "vision_tower.vision_model.encoder.layers.22.self_attn.v_proj.weight": "model-00001-of-00012.safetensors",
622
+ "vision_tower.vision_model.encoder.layers.23.layer_norm1.bias": "model-00001-of-00012.safetensors",
623
+ "vision_tower.vision_model.encoder.layers.23.layer_norm1.weight": "model-00001-of-00012.safetensors",
624
+ "vision_tower.vision_model.encoder.layers.23.layer_norm2.bias": "model-00001-of-00012.safetensors",
625
+ "vision_tower.vision_model.encoder.layers.23.layer_norm2.weight": "model-00001-of-00012.safetensors",
626
+ "vision_tower.vision_model.encoder.layers.23.mlp.fc1.bias": "model-00001-of-00012.safetensors",
627
+ "vision_tower.vision_model.encoder.layers.23.mlp.fc1.weight": "model-00001-of-00012.safetensors",
628
+ "vision_tower.vision_model.encoder.layers.23.mlp.fc2.bias": "model-00001-of-00012.safetensors",
629
+ "vision_tower.vision_model.encoder.layers.23.mlp.fc2.weight": "model-00001-of-00012.safetensors",
630
+ "vision_tower.vision_model.encoder.layers.23.self_attn.k_proj.bias": "model-00001-of-00012.safetensors",
631
+ "vision_tower.vision_model.encoder.layers.23.self_attn.k_proj.weight": "model-00001-of-00012.safetensors",
632
+ "vision_tower.vision_model.encoder.layers.23.self_attn.out_proj.bias": "model-00001-of-00012.safetensors",
633
+ "vision_tower.vision_model.encoder.layers.23.self_attn.out_proj.weight": "model-00001-of-00012.safetensors",
634
+ "vision_tower.vision_model.encoder.layers.23.self_attn.q_proj.bias": "model-00001-of-00012.safetensors",
635
+ "vision_tower.vision_model.encoder.layers.23.self_attn.q_proj.weight": "model-00001-of-00012.safetensors",
636
+ "vision_tower.vision_model.encoder.layers.23.self_attn.v_proj.bias": "model-00001-of-00012.safetensors",
637
+ "vision_tower.vision_model.encoder.layers.23.self_attn.v_proj.weight": "model-00001-of-00012.safetensors",
638
+ "vision_tower.vision_model.encoder.layers.24.layer_norm1.bias": "model-00001-of-00012.safetensors",
639
+ "vision_tower.vision_model.encoder.layers.24.layer_norm1.weight": "model-00001-of-00012.safetensors",
640
+ "vision_tower.vision_model.encoder.layers.24.layer_norm2.bias": "model-00001-of-00012.safetensors",
641
+ "vision_tower.vision_model.encoder.layers.24.layer_norm2.weight": "model-00001-of-00012.safetensors",
642
+ "vision_tower.vision_model.encoder.layers.24.mlp.fc1.bias": "model-00001-of-00012.safetensors",
643
+ "vision_tower.vision_model.encoder.layers.24.mlp.fc1.weight": "model-00001-of-00012.safetensors",
644
+ "vision_tower.vision_model.encoder.layers.24.mlp.fc2.bias": "model-00001-of-00012.safetensors",
645
+ "vision_tower.vision_model.encoder.layers.24.mlp.fc2.weight": "model-00001-of-00012.safetensors",
646
+ "vision_tower.vision_model.encoder.layers.24.self_attn.k_proj.bias": "model-00001-of-00012.safetensors",
647
+ "vision_tower.vision_model.encoder.layers.24.self_attn.k_proj.weight": "model-00001-of-00012.safetensors",
648
+ "vision_tower.vision_model.encoder.layers.24.self_attn.out_proj.bias": "model-00001-of-00012.safetensors",
649
+ "vision_tower.vision_model.encoder.layers.24.self_attn.out_proj.weight": "model-00001-of-00012.safetensors",
650
+ "vision_tower.vision_model.encoder.layers.24.self_attn.q_proj.bias": "model-00001-of-00012.safetensors",
651
+ "vision_tower.vision_model.encoder.layers.24.self_attn.q_proj.weight": "model-00001-of-00012.safetensors",
652
+ "vision_tower.vision_model.encoder.layers.24.self_attn.v_proj.bias": "model-00001-of-00012.safetensors",
653
+ "vision_tower.vision_model.encoder.layers.24.self_attn.v_proj.weight": "model-00001-of-00012.safetensors",
654
+ "vision_tower.vision_model.encoder.layers.25.layer_norm1.bias": "model-00001-of-00012.safetensors",
655
+ "vision_tower.vision_model.encoder.layers.25.layer_norm1.weight": "model-00001-of-00012.safetensors",
656
+ "vision_tower.vision_model.encoder.layers.25.layer_norm2.bias": "model-00001-of-00012.safetensors",
657
+ "vision_tower.vision_model.encoder.layers.25.layer_norm2.weight": "model-00001-of-00012.safetensors",
658
+ "vision_tower.vision_model.encoder.layers.25.mlp.fc1.bias": "model-00001-of-00012.safetensors",
659
+ "vision_tower.vision_model.encoder.layers.25.mlp.fc1.weight": "model-00001-of-00012.safetensors",
660
+ "vision_tower.vision_model.encoder.layers.25.mlp.fc2.bias": "model-00001-of-00012.safetensors",
661
+ "vision_tower.vision_model.encoder.layers.25.mlp.fc2.weight": "model-00001-of-00012.safetensors",
662
+ "vision_tower.vision_model.encoder.layers.25.self_attn.k_proj.bias": "model-00001-of-00012.safetensors",
663
+ "vision_tower.vision_model.encoder.layers.25.self_attn.k_proj.weight": "model-00001-of-00012.safetensors",
664
+ "vision_tower.vision_model.encoder.layers.25.self_attn.out_proj.bias": "model-00001-of-00012.safetensors",
665
+ "vision_tower.vision_model.encoder.layers.25.self_attn.out_proj.weight": "model-00001-of-00012.safetensors",
666
+ "vision_tower.vision_model.encoder.layers.25.self_attn.q_proj.bias": "model-00001-of-00012.safetensors",
667
+ "vision_tower.vision_model.encoder.layers.25.self_attn.q_proj.weight": "model-00001-of-00012.safetensors",
668
+ "vision_tower.vision_model.encoder.layers.25.self_attn.v_proj.bias": "model-00001-of-00012.safetensors",
669
+ "vision_tower.vision_model.encoder.layers.25.self_attn.v_proj.weight": "model-00001-of-00012.safetensors",
670
+ "vision_tower.vision_model.encoder.layers.26.layer_norm1.bias": "model-00001-of-00012.safetensors",
671
+ "vision_tower.vision_model.encoder.layers.26.layer_norm1.weight": "model-00001-of-00012.safetensors",
672
+ "vision_tower.vision_model.encoder.layers.26.layer_norm2.bias": "model-00001-of-00012.safetensors",
673
+ "vision_tower.vision_model.encoder.layers.26.layer_norm2.weight": "model-00001-of-00012.safetensors",
674
+ "vision_tower.vision_model.encoder.layers.26.mlp.fc1.bias": "model-00001-of-00012.safetensors",
675
+ "vision_tower.vision_model.encoder.layers.26.mlp.fc1.weight": "model-00001-of-00012.safetensors",
676
+ "vision_tower.vision_model.encoder.layers.26.mlp.fc2.bias": "model-00001-of-00012.safetensors",
677
+ "vision_tower.vision_model.encoder.layers.26.mlp.fc2.weight": "model-00001-of-00012.safetensors",
678
+ "vision_tower.vision_model.encoder.layers.26.self_attn.k_proj.bias": "model-00001-of-00012.safetensors",
679
+ "vision_tower.vision_model.encoder.layers.26.self_attn.k_proj.weight": "model-00001-of-00012.safetensors",
680
+ "vision_tower.vision_model.encoder.layers.26.self_attn.out_proj.bias": "model-00001-of-00012.safetensors",
681
+ "vision_tower.vision_model.encoder.layers.26.self_attn.out_proj.weight": "model-00001-of-00012.safetensors",
682
+ "vision_tower.vision_model.encoder.layers.26.self_attn.q_proj.bias": "model-00001-of-00012.safetensors",
683
+ "vision_tower.vision_model.encoder.layers.26.self_attn.q_proj.weight": "model-00001-of-00012.safetensors",
684
+ "vision_tower.vision_model.encoder.layers.26.self_attn.v_proj.bias": "model-00001-of-00012.safetensors",
685
+ "vision_tower.vision_model.encoder.layers.26.self_attn.v_proj.weight": "model-00001-of-00012.safetensors",
686
+ "vision_tower.vision_model.encoder.layers.3.layer_norm1.bias": "model-00001-of-00012.safetensors",
687
+ "vision_tower.vision_model.encoder.layers.3.layer_norm1.weight": "model-00001-of-00012.safetensors",
688
+ "vision_tower.vision_model.encoder.layers.3.layer_norm2.bias": "model-00001-of-00012.safetensors",
689
+ "vision_tower.vision_model.encoder.layers.3.layer_norm2.weight": "model-00001-of-00012.safetensors",
690
+ "vision_tower.vision_model.encoder.layers.3.mlp.fc1.bias": "model-00001-of-00012.safetensors",
691
+ "vision_tower.vision_model.encoder.layers.3.mlp.fc1.weight": "model-00001-of-00012.safetensors",
692
+ "vision_tower.vision_model.encoder.layers.3.mlp.fc2.bias": "model-00001-of-00012.safetensors",
693
+ "vision_tower.vision_model.encoder.layers.3.mlp.fc2.weight": "model-00001-of-00012.safetensors",
694
+ "vision_tower.vision_model.encoder.layers.3.self_attn.k_proj.bias": "model-00001-of-00012.safetensors",
695
+ "vision_tower.vision_model.encoder.layers.3.self_attn.k_proj.weight": "model-00001-of-00012.safetensors",
696
+ "vision_tower.vision_model.encoder.layers.3.self_attn.out_proj.bias": "model-00001-of-00012.safetensors",
697
+ "vision_tower.vision_model.encoder.layers.3.self_attn.out_proj.weight": "model-00001-of-00012.safetensors",
698
+ "vision_tower.vision_model.encoder.layers.3.self_attn.q_proj.bias": "model-00001-of-00012.safetensors",
699
+ "vision_tower.vision_model.encoder.layers.3.self_attn.q_proj.weight": "model-00001-of-00012.safetensors",
700
+ "vision_tower.vision_model.encoder.layers.3.self_attn.v_proj.bias": "model-00001-of-00012.safetensors",
701
+ "vision_tower.vision_model.encoder.layers.3.self_attn.v_proj.weight": "model-00001-of-00012.safetensors",
702
+ "vision_tower.vision_model.encoder.layers.4.layer_norm1.bias": "model-00001-of-00012.safetensors",
703
+ "vision_tower.vision_model.encoder.layers.4.layer_norm1.weight": "model-00001-of-00012.safetensors",
704
+ "vision_tower.vision_model.encoder.layers.4.layer_norm2.bias": "model-00001-of-00012.safetensors",
705
+ "vision_tower.vision_model.encoder.layers.4.layer_norm2.weight": "model-00001-of-00012.safetensors",
706
+ "vision_tower.vision_model.encoder.layers.4.mlp.fc1.bias": "model-00001-of-00012.safetensors",
707
+ "vision_tower.vision_model.encoder.layers.4.mlp.fc1.weight": "model-00001-of-00012.safetensors",
708
+ "vision_tower.vision_model.encoder.layers.4.mlp.fc2.bias": "model-00001-of-00012.safetensors",
709
+ "vision_tower.vision_model.encoder.layers.4.mlp.fc2.weight": "model-00001-of-00012.safetensors",
710
+ "vision_tower.vision_model.encoder.layers.4.self_attn.k_proj.bias": "model-00001-of-00012.safetensors",
711
+ "vision_tower.vision_model.encoder.layers.4.self_attn.k_proj.weight": "model-00001-of-00012.safetensors",
712
+ "vision_tower.vision_model.encoder.layers.4.self_attn.out_proj.bias": "model-00001-of-00012.safetensors",
713
+ "vision_tower.vision_model.encoder.layers.4.self_attn.out_proj.weight": "model-00001-of-00012.safetensors",
714
+ "vision_tower.vision_model.encoder.layers.4.self_attn.q_proj.bias": "model-00001-of-00012.safetensors",
715
+ "vision_tower.vision_model.encoder.layers.4.self_attn.q_proj.weight": "model-00001-of-00012.safetensors",
716
+ "vision_tower.vision_model.encoder.layers.4.self_attn.v_proj.bias": "model-00001-of-00012.safetensors",
717
+ "vision_tower.vision_model.encoder.layers.4.self_attn.v_proj.weight": "model-00001-of-00012.safetensors",
718
+ "vision_tower.vision_model.encoder.layers.5.layer_norm1.bias": "model-00001-of-00012.safetensors",
719
+ "vision_tower.vision_model.encoder.layers.5.layer_norm1.weight": "model-00001-of-00012.safetensors",
720
+ "vision_tower.vision_model.encoder.layers.5.layer_norm2.bias": "model-00001-of-00012.safetensors",
721
+ "vision_tower.vision_model.encoder.layers.5.layer_norm2.weight": "model-00001-of-00012.safetensors",
722
+ "vision_tower.vision_model.encoder.layers.5.mlp.fc1.bias": "model-00001-of-00012.safetensors",
723
+ "vision_tower.vision_model.encoder.layers.5.mlp.fc1.weight": "model-00001-of-00012.safetensors",
724
+ "vision_tower.vision_model.encoder.layers.5.mlp.fc2.bias": "model-00001-of-00012.safetensors",
725
+ "vision_tower.vision_model.encoder.layers.5.mlp.fc2.weight": "model-00001-of-00012.safetensors",
726
+ "vision_tower.vision_model.encoder.layers.5.self_attn.k_proj.bias": "model-00001-of-00012.safetensors",
727
+ "vision_tower.vision_model.encoder.layers.5.self_attn.k_proj.weight": "model-00001-of-00012.safetensors",
728
+ "vision_tower.vision_model.encoder.layers.5.self_attn.out_proj.bias": "model-00001-of-00012.safetensors",
729
+ "vision_tower.vision_model.encoder.layers.5.self_attn.out_proj.weight": "model-00001-of-00012.safetensors",
730
+ "vision_tower.vision_model.encoder.layers.5.self_attn.q_proj.bias": "model-00001-of-00012.safetensors",
731
+ "vision_tower.vision_model.encoder.layers.5.self_attn.q_proj.weight": "model-00001-of-00012.safetensors",
732
+ "vision_tower.vision_model.encoder.layers.5.self_attn.v_proj.bias": "model-00001-of-00012.safetensors",
733
+ "vision_tower.vision_model.encoder.layers.5.self_attn.v_proj.weight": "model-00001-of-00012.safetensors",
734
+ "vision_tower.vision_model.encoder.layers.6.layer_norm1.bias": "model-00001-of-00012.safetensors",
735
+ "vision_tower.vision_model.encoder.layers.6.layer_norm1.weight": "model-00001-of-00012.safetensors",
736
+ "vision_tower.vision_model.encoder.layers.6.layer_norm2.bias": "model-00001-of-00012.safetensors",
737
+ "vision_tower.vision_model.encoder.layers.6.layer_norm2.weight": "model-00001-of-00012.safetensors",
738
+ "vision_tower.vision_model.encoder.layers.6.mlp.fc1.bias": "model-00001-of-00012.safetensors",
739
+ "vision_tower.vision_model.encoder.layers.6.mlp.fc1.weight": "model-00001-of-00012.safetensors",
740
+ "vision_tower.vision_model.encoder.layers.6.mlp.fc2.bias": "model-00001-of-00012.safetensors",
741
+ "vision_tower.vision_model.encoder.layers.6.mlp.fc2.weight": "model-00001-of-00012.safetensors",
742
+ "vision_tower.vision_model.encoder.layers.6.self_attn.k_proj.bias": "model-00001-of-00012.safetensors",
743
+ "vision_tower.vision_model.encoder.layers.6.self_attn.k_proj.weight": "model-00001-of-00012.safetensors",
744
+ "vision_tower.vision_model.encoder.layers.6.self_attn.out_proj.bias": "model-00001-of-00012.safetensors",
745
+ "vision_tower.vision_model.encoder.layers.6.self_attn.out_proj.weight": "model-00001-of-00012.safetensors",
746
+ "vision_tower.vision_model.encoder.layers.6.self_attn.q_proj.bias": "model-00001-of-00012.safetensors",
747
+ "vision_tower.vision_model.encoder.layers.6.self_attn.q_proj.weight": "model-00001-of-00012.safetensors",
748
+ "vision_tower.vision_model.encoder.layers.6.self_attn.v_proj.bias": "model-00001-of-00012.safetensors",
749
+ "vision_tower.vision_model.encoder.layers.6.self_attn.v_proj.weight": "model-00001-of-00012.safetensors",
750
+ "vision_tower.vision_model.encoder.layers.7.layer_norm1.bias": "model-00001-of-00012.safetensors",
751
+ "vision_tower.vision_model.encoder.layers.7.layer_norm1.weight": "model-00001-of-00012.safetensors",
752
+ "vision_tower.vision_model.encoder.layers.7.layer_norm2.bias": "model-00001-of-00012.safetensors",
753
+ "vision_tower.vision_model.encoder.layers.7.layer_norm2.weight": "model-00001-of-00012.safetensors",
754
+ "vision_tower.vision_model.encoder.layers.7.mlp.fc1.bias": "model-00001-of-00012.safetensors",
755
+ "vision_tower.vision_model.encoder.layers.7.mlp.fc1.weight": "model-00001-of-00012.safetensors",
756
+ "vision_tower.vision_model.encoder.layers.7.mlp.fc2.bias": "model-00001-of-00012.safetensors",
757
+ "vision_tower.vision_model.encoder.layers.7.mlp.fc2.weight": "model-00001-of-00012.safetensors",
758
+ "vision_tower.vision_model.encoder.layers.7.self_attn.k_proj.bias": "model-00001-of-00012.safetensors",
759
+ "vision_tower.vision_model.encoder.layers.7.self_attn.k_proj.weight": "model-00001-of-00012.safetensors",
760
+ "vision_tower.vision_model.encoder.layers.7.self_attn.out_proj.bias": "model-00001-of-00012.safetensors",
761
+ "vision_tower.vision_model.encoder.layers.7.self_attn.out_proj.weight": "model-00001-of-00012.safetensors",
762
+ "vision_tower.vision_model.encoder.layers.7.self_attn.q_proj.bias": "model-00001-of-00012.safetensors",
763
+ "vision_tower.vision_model.encoder.layers.7.self_attn.q_proj.weight": "model-00001-of-00012.safetensors",
764
+ "vision_tower.vision_model.encoder.layers.7.self_attn.v_proj.bias": "model-00001-of-00012.safetensors",
765
+ "vision_tower.vision_model.encoder.layers.7.self_attn.v_proj.weight": "model-00001-of-00012.safetensors",
766
+ "vision_tower.vision_model.encoder.layers.8.layer_norm1.bias": "model-00001-of-00012.safetensors",
767
+ "vision_tower.vision_model.encoder.layers.8.layer_norm1.weight": "model-00001-of-00012.safetensors",
768
+ "vision_tower.vision_model.encoder.layers.8.layer_norm2.bias": "model-00001-of-00012.safetensors",
769
+ "vision_tower.vision_model.encoder.layers.8.layer_norm2.weight": "model-00001-of-00012.safetensors",
770
+ "vision_tower.vision_model.encoder.layers.8.mlp.fc1.bias": "model-00001-of-00012.safetensors",
771
+ "vision_tower.vision_model.encoder.layers.8.mlp.fc1.weight": "model-00001-of-00012.safetensors",
772
+ "vision_tower.vision_model.encoder.layers.8.mlp.fc2.bias": "model-00001-of-00012.safetensors",
773
+ "vision_tower.vision_model.encoder.layers.8.mlp.fc2.weight": "model-00001-of-00012.safetensors",
774
+ "vision_tower.vision_model.encoder.layers.8.self_attn.k_proj.bias": "model-00001-of-00012.safetensors",
775
+ "vision_tower.vision_model.encoder.layers.8.self_attn.k_proj.weight": "model-00001-of-00012.safetensors",
776
+ "vision_tower.vision_model.encoder.layers.8.self_attn.out_proj.bias": "model-00001-of-00012.safetensors",
777
+ "vision_tower.vision_model.encoder.layers.8.self_attn.out_proj.weight": "model-00001-of-00012.safetensors",
778
+ "vision_tower.vision_model.encoder.layers.8.self_attn.q_proj.bias": "model-00001-of-00012.safetensors",
779
+ "vision_tower.vision_model.encoder.layers.8.self_attn.q_proj.weight": "model-00001-of-00012.safetensors",
780
+ "vision_tower.vision_model.encoder.layers.8.self_attn.v_proj.bias": "model-00001-of-00012.safetensors",
781
+ "vision_tower.vision_model.encoder.layers.8.self_attn.v_proj.weight": "model-00001-of-00012.safetensors",
782
+ "vision_tower.vision_model.encoder.layers.9.layer_norm1.bias": "model-00001-of-00012.safetensors",
783
+ "vision_tower.vision_model.encoder.layers.9.layer_norm1.weight": "model-00001-of-00012.safetensors",
784
+ "vision_tower.vision_model.encoder.layers.9.layer_norm2.bias": "model-00001-of-00012.safetensors",
785
+ "vision_tower.vision_model.encoder.layers.9.layer_norm2.weight": "model-00001-of-00012.safetensors",
786
+ "vision_tower.vision_model.encoder.layers.9.mlp.fc1.bias": "model-00001-of-00012.safetensors",
787
+ "vision_tower.vision_model.encoder.layers.9.mlp.fc1.weight": "model-00001-of-00012.safetensors",
788
+ "vision_tower.vision_model.encoder.layers.9.mlp.fc2.bias": "model-00001-of-00012.safetensors",
789
+ "vision_tower.vision_model.encoder.layers.9.mlp.fc2.weight": "model-00001-of-00012.safetensors",
790
+ "vision_tower.vision_model.encoder.layers.9.self_attn.k_proj.bias": "model-00001-of-00012.safetensors",
791
+ "vision_tower.vision_model.encoder.layers.9.self_attn.k_proj.weight": "model-00001-of-00012.safetensors",
792
+ "vision_tower.vision_model.encoder.layers.9.self_attn.out_proj.bias": "model-00001-of-00012.safetensors",
793
+ "vision_tower.vision_model.encoder.layers.9.self_attn.out_proj.weight": "model-00001-of-00012.safetensors",
794
+ "vision_tower.vision_model.encoder.layers.9.self_attn.q_proj.bias": "model-00001-of-00012.safetensors",
795
+ "vision_tower.vision_model.encoder.layers.9.self_attn.q_proj.weight": "model-00001-of-00012.safetensors",
796
+ "vision_tower.vision_model.encoder.layers.9.self_attn.v_proj.bias": "model-00001-of-00012.safetensors",
797
+ "vision_tower.vision_model.encoder.layers.9.self_attn.v_proj.weight": "model-00001-of-00012.safetensors"
798
+ }
799
+ }
modeling_aria.py ADDED
@@ -0,0 +1,566 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2024 Rhymes AI. All rights reserved.
2
+ #
3
+ # Licensed to the Apache Software Foundation (ASF) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The ASF licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+
20
+ from dataclasses import dataclass
21
+ from typing import List, Optional, Tuple, Union
22
+
23
+ import torch
24
+ import torch.nn as nn
25
+ from torch import nn
26
+ from transformers import PreTrainedModel
27
+ from transformers.cache_utils import Cache
28
+ from transformers.modeling_outputs import ModelOutput
29
+ from transformers.utils import logging
30
+
31
+ from .configuration_aria import AriaConfig
32
+ from .moe_lm import AriaMoELMForCausalLM
33
+ from .projector import AriaProjector
34
+ from .vision_encoder import AriaVisionModel
35
+
36
+ logger = logging.get_logger(__name__)
37
+
38
+
39
+ class AriaPretrainedModel(PreTrainedModel):
40
+ """
41
+ An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained models.
42
+ """
43
+
44
+ config_class = AriaConfig
45
+ base_model_prefix = "model"
46
+ _no_split_modules = []
47
+ supports_gradient_checkpointing = True
48
+ _skip_keys_device_placement = "past_key_values"
49
+ _supports_flash_attn_2 = True
50
+ _supports_cache_class = True
51
+
52
+ @property
53
+ def _supports_sdpa(self):
54
+ """
55
+ Retrieve language_model's attribute to check whether the model supports
56
+ SDPA (Scaled Dot Product Attention) or not.
57
+ """
58
+ return self.language_model._supports_sdpa
59
+
60
+
61
+ @dataclass
62
+ # Copied from transformers.models.llava.modeling_llava.LlavaCausalLMOutputWithPast with Llava->Aria
63
+ class AriaCausalLMOutputWithPast(ModelOutput):
64
+ """
65
+ Base class for Aria causal language model (or autoregressive) outputs.
66
+
67
+ Args:
68
+ loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
69
+ Language modeling loss (for next-token prediction).
70
+ logits (`torch.FloatTensor` of shape `(batch_size, sequence_length, config.vocab_size)`):
71
+ Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).
72
+ past_key_values (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
73
+ Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of shape
74
+ `(batch_size, num_heads, sequence_length, embed_size_per_head)`)
75
+
76
+ Contains pre-computed hidden-states (key and values in the self-attention blocks) that can be used (see
77
+ `past_key_values` input) to speed up sequential decoding.
78
+ hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
79
+ Tuple of `torch.FloatTensor` (one for the output of the embeddings, if the model has an embedding layer, +
80
+ one for the output of each layer) of shape `(batch_size, sequence_length, hidden_size)`.
81
+
82
+ Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.
83
+ attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
84
+ Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
85
+ sequence_length)`.
86
+
87
+ Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
88
+ heads.
89
+ image_hidden_states (`tuple(torch.FloatTensor)`, *optional*):
90
+ Tuple of `torch.FloatTensor` (one for the output of the image embeddings, `(batch_size, num_images,
91
+ sequence_length, hidden_size)`.
92
+
93
+ image_hidden_states of the model produced by the vision encoder, and optionally by the perceiver
94
+ """
95
+
96
+ loss: Optional[torch.FloatTensor] = None
97
+ logits: torch.FloatTensor = None
98
+ past_key_values: Optional[List[torch.FloatTensor]] = None
99
+ hidden_states: Optional[Tuple[torch.FloatTensor]] = None
100
+ attentions: Optional[Tuple[torch.FloatTensor]] = None
101
+ image_hidden_states: Optional[Tuple[torch.FloatTensor]] = None
102
+
103
+
104
+ def build_mm_projector(config: AriaConfig):
105
+ """
106
+ Builds and returns an AriaProjector instance based on the provided configuration.
107
+
108
+ Args:
109
+ config (AriaConfig): The configuration object containing necessary parameters.
110
+
111
+ Returns:
112
+ AriaProjector: An instance of the AriaProjector class.
113
+ """
114
+ return AriaProjector(
115
+ patch_to_query_dict=config.projector_patch_to_query_dict,
116
+ embed_dim=config.vision_config.hidden_size,
117
+ num_heads=config.vision_config.num_attention_heads,
118
+ kv_dim=config.vision_config.hidden_size,
119
+ ff_dim=config.text_config.hidden_size,
120
+ output_dim=config.text_config.hidden_size,
121
+ )
122
+
123
+
124
+ # adapted from transformers.models.llava.modeling_llava.LlavaForConditionalGeneration
125
+ class AriaForConditionalGeneration(AriaPretrainedModel):
126
+ """
127
+ Aria model for conditional generation tasks.
128
+
129
+ This model combines a vision tower, a multi-modal projector, and a language model
130
+ to perform tasks that involve both image and text inputs.
131
+ """
132
+
133
+ def __init__(self, config: AriaConfig):
134
+ super().__init__(config)
135
+
136
+ self.vision_tower = AriaVisionModel(config.vision_config)
137
+ self.multi_modal_projector = build_mm_projector(config)
138
+ self.vocab_size = config.text_config.vocab_size
139
+ self.language_model = AriaMoELMForCausalLM(config.text_config)
140
+ self.pad_token_id = (
141
+ self.config.pad_token_id if self.config.pad_token_id is not None else -1
142
+ )
143
+ self.post_init()
144
+
145
+ def freeze_vit(self):
146
+ """Freeze the parameters of the vision tower."""
147
+ for param in self.vision_tower.parameters():
148
+ param.requires_grad = False
149
+
150
+ def freeze_projector(self):
151
+ """Freeze the parameters of the multi-modal projector."""
152
+ for param in self.multi_modal_projector.parameters():
153
+ param.requires_grad = False
154
+
155
+ def freeze_llm(self):
156
+ """Freeze the parameters of the language model."""
157
+ for param in self.language_model.parameters():
158
+ param.requires_grad = False
159
+
160
+ def get_input_embeddings(self) -> nn.Module:
161
+ """Retrieve the input embeddings from the language model."""
162
+ return self.language_model.get_input_embeddings()
163
+
164
+ def set_input_embeddings(self, value):
165
+ """Set the input embeddings for the language model."""
166
+ self.language_model.set_input_embeddings(value)
167
+
168
+ def set_moe_z_loss_coeff(self, value):
169
+ """
170
+ Set the z-loss coefficient for Mixture of Experts (MoE) models.
171
+
172
+ Args:
173
+ value: The z-loss coefficient value to set.
174
+ """
175
+ self.language_model.set_z_loss_coeff(value)
176
+
177
+ def set_moe_aux_loss_coeff(self, value):
178
+ """
179
+ Set the auxiliary loss coefficient for Mixture of Experts (MoE) models.
180
+
181
+ Args:
182
+ value: The auxiliary loss coefficient value to set.
183
+ """
184
+ self.language_model.set_aux_loss_coeff(value)
185
+
186
+ # copied from transformers.models.llava.modeling_llava.LlavaForConditionalGeneration
187
+ def _merge_input_ids_with_image_features(
188
+ self, image_features, inputs_embeds, input_ids, attention_mask, labels
189
+ ):
190
+ """
191
+ Merge input IDs with image features to create a combined input representation.
192
+
193
+ This method handles the complex logic of interleaving text and image tokens,
194
+ adjusting attention masks and labels accordingly.
195
+
196
+ Args:
197
+ image_features (torch.Tensor): Processed image features.
198
+ inputs_embeds (torch.Tensor): Text input embeddings.
199
+ input_ids (torch.Tensor): Input token IDs.
200
+ attention_mask (torch.Tensor): Attention mask for input tokens.
201
+ labels (torch.Tensor, optional): Labels for language modeling.
202
+
203
+ Returns:
204
+ tuple: Contains the merged embeddings, updated attention mask,
205
+ updated labels, and position IDs.
206
+ """
207
+ num_images, num_image_patches, embed_dim = image_features.shape
208
+ batch_size, sequence_length = input_ids.shape
209
+ left_padding = not torch.sum(
210
+ input_ids[:, -1] == torch.tensor(self.pad_token_id)
211
+ )
212
+ # 1. Create a mask to know where special image tokens are
213
+ special_image_token_mask = input_ids == self.config.image_token_index
214
+ num_special_image_tokens = torch.sum(special_image_token_mask, dim=-1)
215
+ # Compute the maximum embed dimension
216
+ max_embed_dim = (
217
+ num_special_image_tokens.max() * (num_image_patches - 1)
218
+ ) + sequence_length
219
+ batch_indices, non_image_indices = torch.where(
220
+ input_ids != self.config.image_token_index
221
+ )
222
+
223
+ # 2. Compute the positions where text should be written
224
+ # Calculate new positions for text tokens in merged image-text sequence.
225
+ # `special_image_token_mask` identifies image tokens. Each image token will be replaced by `nb_text_tokens_per_images - 1` text tokens.
226
+ # `torch.cumsum` computes how each image token shifts subsequent text token positions.
227
+ # - 1 to adjust for zero-based indexing, as `cumsum` inherently increases indices by one.
228
+ new_token_positions = (
229
+ torch.cumsum((special_image_token_mask * (num_image_patches - 1) + 1), -1)
230
+ - 1
231
+ )
232
+ nb_image_pad = max_embed_dim - 1 - new_token_positions[:, -1]
233
+ if left_padding:
234
+ new_token_positions += nb_image_pad[:, None] # offset for left padding
235
+ text_to_overwrite = new_token_positions[batch_indices, non_image_indices]
236
+
237
+ # 3. Create the full embedding, already padded to the maximum position
238
+ final_embedding = torch.zeros(
239
+ batch_size,
240
+ max_embed_dim,
241
+ embed_dim,
242
+ dtype=inputs_embeds.dtype,
243
+ device=inputs_embeds.device,
244
+ )
245
+ final_attention_mask = torch.zeros(
246
+ batch_size,
247
+ max_embed_dim,
248
+ dtype=attention_mask.dtype,
249
+ device=inputs_embeds.device,
250
+ )
251
+ if labels is not None:
252
+ final_labels = torch.full(
253
+ (batch_size, max_embed_dim),
254
+ self.config.ignore_index,
255
+ dtype=input_ids.dtype,
256
+ device=input_ids.device,
257
+ )
258
+ # In case the Vision model or the Language model has been offloaded to CPU, we need to manually
259
+ # set the corresponding tensors into their correct target device.
260
+ target_device = inputs_embeds.device
261
+ batch_indices, non_image_indices, text_to_overwrite = (
262
+ batch_indices.to(target_device),
263
+ non_image_indices.to(target_device),
264
+ text_to_overwrite.to(target_device),
265
+ )
266
+ attention_mask = attention_mask.to(target_device)
267
+
268
+ # 4. Fill the embeddings based on the mask. If we have ["hey" "<image>", "how", "are"]
269
+ # we need to index copy on [0, 577, 578, 579] for the text and [1:576] for the image features
270
+ final_embedding[batch_indices, text_to_overwrite] = inputs_embeds[
271
+ batch_indices, non_image_indices
272
+ ]
273
+ final_attention_mask[batch_indices, text_to_overwrite] = attention_mask[
274
+ batch_indices, non_image_indices
275
+ ]
276
+ if labels is not None:
277
+ final_labels[batch_indices, text_to_overwrite] = labels[
278
+ batch_indices, non_image_indices
279
+ ]
280
+
281
+ # 5. Fill the embeddings corresponding to the images. Anything that is not `text_positions` needs filling (#29835)
282
+ image_to_overwrite = torch.full(
283
+ (batch_size, max_embed_dim),
284
+ True,
285
+ dtype=torch.bool,
286
+ device=inputs_embeds.device,
287
+ )
288
+ image_to_overwrite[batch_indices, text_to_overwrite] = False
289
+ image_to_overwrite &= image_to_overwrite.cumsum(-1) - 1 >= nb_image_pad[
290
+ :, None
291
+ ].to(target_device)
292
+
293
+ if image_to_overwrite.sum() != image_features.shape[:-1].numel():
294
+ raise ValueError(
295
+ f"The input provided to the model are wrong. The number of image tokens is {torch.sum(special_image_token_mask)} while"
296
+ f" the number of image given to the model is {num_images}. This prevents correct indexing and breaks batch generation."
297
+ )
298
+
299
+ final_embedding[image_to_overwrite] = (
300
+ image_features.contiguous().reshape(-1, embed_dim).to(target_device)
301
+ )
302
+ final_attention_mask |= image_to_overwrite
303
+ position_ids = (final_attention_mask.cumsum(-1) - 1).masked_fill_(
304
+ (final_attention_mask == 0), 1
305
+ )
306
+
307
+ # 6. Mask out the embedding at padding positions, as we later use the past_key_value value to determine the non-attended tokens.
308
+ batch_indices, pad_indices = torch.where(input_ids == self.pad_token_id)
309
+ indices_to_mask = new_token_positions[batch_indices, pad_indices]
310
+
311
+ final_embedding[batch_indices, indices_to_mask] = 0
312
+
313
+ if labels is None:
314
+ final_labels = None
315
+
316
+ return final_embedding, final_attention_mask, final_labels, position_ids
317
+
318
+ def forward(
319
+ self,
320
+ input_ids: torch.LongTensor = None,
321
+ pixel_values: torch.FloatTensor = None,
322
+ pixel_mask: torch.LongTensor = None,
323
+ attention_mask: Optional[torch.Tensor] = None,
324
+ position_ids: Optional[torch.LongTensor] = None,
325
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
326
+ inputs_embeds: Optional[torch.FloatTensor] = None,
327
+ labels: Optional[torch.LongTensor] = None,
328
+ use_cache: Optional[bool] = None,
329
+ output_attentions: Optional[bool] = None,
330
+ output_hidden_states: Optional[bool] = None,
331
+ return_dict: Optional[bool] = None,
332
+ ) -> Union[Tuple, AriaCausalLMOutputWithPast]:
333
+ """
334
+ Forward pass of the AriaForConditionalGeneration model.
335
+
336
+ This method processes both text and image inputs, merges them if necessary,
337
+ and generates output using the language model.
338
+
339
+ Args:
340
+ input_ids (torch.LongTensor, optional): Input token ids.
341
+ pixel_values (torch.FloatTensor, optional): Pixel values of the images.
342
+ pixel_mask (torch.LongTensor, optional): Mask for the pixel values.
343
+ attention_mask (torch.Tensor, optional): Attention mask.
344
+ position_ids (torch.LongTensor, optional): Position ids.
345
+ past_key_values (List[torch.FloatTensor], optional): Past key values for efficient processing.
346
+ inputs_embeds (torch.FloatTensor, optional): Input embeddings.
347
+ labels (torch.LongTensor, optional): Labels for computing the language modeling loss.
348
+ use_cache (bool, optional): Whether to use the model's cache mechanism.
349
+ output_attentions (bool, optional): Whether to output attention weights.
350
+ output_hidden_states (bool, optional): Whether to output hidden states.
351
+ return_dict (bool, optional): Whether to return a ModelOutput object.
352
+
353
+ Returns:
354
+ Union[Tuple, AriaCausalLMOutputWithPast]: Model outputs.
355
+ """
356
+ output_attentions = (
357
+ output_attentions
358
+ if output_attentions is not None
359
+ else self.config.output_attentions
360
+ )
361
+ output_hidden_states = (
362
+ output_hidden_states
363
+ if output_hidden_states is not None
364
+ else self.config.output_hidden_states
365
+ )
366
+ return_dict = (
367
+ return_dict if return_dict is not None else self.config.use_return_dict
368
+ )
369
+
370
+ if inputs_embeds is None:
371
+ # 1. Extra the input embeddings
372
+ inputs_embeds = self.get_input_embeddings()(input_ids)
373
+
374
+ # 2. Merge text and images
375
+ if pixel_values is not None and input_ids.shape[1] != 1:
376
+ image_outputs, image_attn_mask = self.vision_tower(
377
+ pixel_values,
378
+ pixel_mask=pixel_mask,
379
+ )
380
+ selected_image_feature = image_outputs.last_hidden_state
381
+
382
+ image_features = self.multi_modal_projector(
383
+ selected_image_feature, attn_mask=image_attn_mask
384
+ )
385
+
386
+ inputs_embeds = inputs_embeds.to(image_features.dtype)
387
+ (
388
+ inputs_embeds,
389
+ attention_mask,
390
+ labels,
391
+ position_ids,
392
+ ) = self._merge_input_ids_with_image_features(
393
+ image_features, inputs_embeds, input_ids, attention_mask, labels
394
+ )
395
+
396
+ # In case input_ids.shape[1] == 1 & pixel_values != None & past_key_values != None, we are in the case of
397
+ # generation with cache
398
+ elif (
399
+ past_key_values is not None
400
+ and pixel_values is not None
401
+ and input_ids.shape[1] == 1
402
+ ):
403
+ # Retrieve the first layer to inspect the logits and mask out the hidden states
404
+ # that are set to 0
405
+ first_layer_past_key_value = past_key_values[0][0][:, :, :, 0]
406
+
407
+ # Sum all dimensions of head_dim (-2) to avoid random errors
408
+ # such as: https://github.com/huggingface/transformers/pull/28032#issuecomment-1863691941
409
+ batch_index, non_attended_tokens = torch.where(
410
+ first_layer_past_key_value.float().sum(-2) == 0
411
+ )
412
+
413
+ # Get the target length
414
+ target_length = input_ids.shape[1]
415
+ past_length = first_layer_past_key_value.shape[-1]
416
+
417
+ extended_attention_mask = torch.ones(
418
+ (attention_mask.shape[0], past_length),
419
+ dtype=attention_mask.dtype,
420
+ device=attention_mask.device,
421
+ )
422
+
423
+ # Filter out only the tokens that can be un-attended, this can happen
424
+ # if one uses Llava + Fused modules where the cache on the
425
+ # first iteration is already big enough, or if one passes custom cache
426
+ valid_indices = non_attended_tokens < extended_attention_mask.size(-1)
427
+ new_batch_index = batch_index[valid_indices]
428
+ new_non_attended_tokens = non_attended_tokens[valid_indices]
429
+
430
+ # Zero-out the places where we don't need to attend
431
+ extended_attention_mask[new_batch_index, new_non_attended_tokens] = 0
432
+
433
+ attention_mask = torch.cat(
434
+ (extended_attention_mask, attention_mask[:, -target_length:]), dim=1
435
+ )
436
+ position_ids = torch.sum(attention_mask, dim=1).unsqueeze(-1) - 1
437
+
438
+ outputs = self.language_model(
439
+ attention_mask=attention_mask,
440
+ position_ids=position_ids,
441
+ past_key_values=past_key_values,
442
+ inputs_embeds=inputs_embeds,
443
+ use_cache=use_cache,
444
+ output_attentions=output_attentions,
445
+ output_hidden_states=output_hidden_states,
446
+ return_dict=return_dict,
447
+ )
448
+
449
+ logits = outputs[0]
450
+
451
+ loss = None
452
+ if labels is not None:
453
+ # Shift so that tokens < n predict n
454
+ if attention_mask is not None:
455
+ shift_attention_mask = attention_mask[..., 1:]
456
+ shift_logits = logits[..., :-1, :][
457
+ shift_attention_mask.to(logits.device) != 0
458
+ ].contiguous()
459
+ shift_labels = labels[..., 1:][
460
+ shift_attention_mask.to(labels.device) != 0
461
+ ].contiguous()
462
+ else:
463
+ shift_logits = logits[..., :-1, :].contiguous()
464
+ shift_labels = labels[..., 1:].contiguous()
465
+ # Flatten the tokens
466
+ loss_fct = nn.CrossEntropyLoss()
467
+ loss = loss_fct(
468
+ shift_logits.view(-1, shift_logits.size(-1)),
469
+ shift_labels.view(-1).to(shift_logits.device),
470
+ )
471
+
472
+ if not return_dict:
473
+ output = (logits,) + outputs[1:]
474
+ return (loss,) + output if loss is not None else output
475
+
476
+ return AriaCausalLMOutputWithPast(
477
+ loss=loss,
478
+ logits=logits,
479
+ past_key_values=outputs.past_key_values,
480
+ hidden_states=outputs.hidden_states,
481
+ attentions=outputs.attentions,
482
+ )
483
+
484
+ def prepare_inputs_for_generation(
485
+ self,
486
+ input_ids,
487
+ past_key_values=None,
488
+ inputs_embeds=None,
489
+ pixel_values=None,
490
+ pixel_mask=None,
491
+ attention_mask=None,
492
+ **kwargs,
493
+ ):
494
+ """
495
+ Prepare inputs for generation step.
496
+
497
+ This method prepares the inputs for the generation step, handling both
498
+ text and image inputs, and managing the model's cache mechanism.
499
+
500
+ Args:
501
+ input_ids (torch.LongTensor): Input token ids.
502
+ past_key_values (Cache or List[torch.FloatTensor], optional): Past key values for efficient processing.
503
+ inputs_embeds (torch.FloatTensor, optional): Input embeddings.
504
+ pixel_values (torch.FloatTensor, optional): Pixel values of the images.
505
+ pixel_mask (torch.LongTensor, optional): Mask for the pixel values.
506
+ attention_mask (torch.Tensor, optional): Attention mask.
507
+ **kwargs: Additional keyword arguments.
508
+
509
+ Returns:
510
+ dict: A dictionary containing the prepared inputs for the generation step.
511
+ """
512
+ if past_key_values is not None:
513
+ if isinstance(past_key_values, Cache):
514
+ cache_length = past_key_values.get_seq_length()
515
+ past_length = past_key_values.seen_tokens
516
+ else:
517
+ cache_length = past_length = past_key_values[0][0].shape[2]
518
+
519
+ # Keep only the unprocessed tokens:
520
+ # 1 - If the length of the attention_mask exceeds the length of input_ids, then we are in a setting where
521
+ # some of the inputs are exclusively passed as part of the cache (e.g. when passing input_embeds as
522
+ # input)
523
+ if (
524
+ attention_mask is not None
525
+ and attention_mask.shape[1] > input_ids.shape[1]
526
+ ):
527
+ input_ids = input_ids[:, -(attention_mask.shape[1] - past_length) :]
528
+ # 2 - If the past_length is smaller than input_ids', then input_ids holds all input tokens. We can discard
529
+ # input_ids based on the past_length.
530
+ elif past_length < input_ids.shape[1]:
531
+ input_ids = input_ids[:, past_length:]
532
+ # 3 - Otherwise (past_length >= input_ids.shape[1]), let's assume input_ids only has unprocessed tokens.
533
+ elif self.config.image_token_index in input_ids:
534
+ input_ids = input_ids[:, input_ids.shape[1] - 1 :]
535
+ # If the cache has seen more tokens than it can hold, then the cache has a size limit. Let's discard the
536
+ # older attention values, as their corresponding values are not part of the input.
537
+ if cache_length < past_length and attention_mask is not None:
538
+ attention_mask = attention_mask[
539
+ :, -(cache_length + input_ids.shape[1]) :
540
+ ]
541
+
542
+ position_ids = kwargs.get("position_ids", None)
543
+ if attention_mask is not None and position_ids is None:
544
+ # create position_ids on the fly for batch generation
545
+ position_ids = attention_mask.long().cumsum(-1) - 1
546
+ position_ids.masked_fill_(attention_mask == 0, 1)
547
+ if past_key_values:
548
+ position_ids = position_ids[:, -input_ids.shape[1] :]
549
+
550
+ # if `inputs_embeds` are passed, we only want to use them in the 1st generation step
551
+ if inputs_embeds is not None and past_key_values is None:
552
+ model_inputs = {"inputs_embeds": inputs_embeds}
553
+ else:
554
+ model_inputs = {"input_ids": input_ids}
555
+
556
+ model_inputs.update(
557
+ {
558
+ "position_ids": position_ids,
559
+ "past_key_values": past_key_values,
560
+ "use_cache": kwargs.get("use_cache"),
561
+ "attention_mask": attention_mask,
562
+ "pixel_values": pixel_values,
563
+ "pixel_mask": pixel_mask,
564
+ }
565
+ )
566
+ return model_inputs
moe_lm.py ADDED
@@ -0,0 +1,677 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2024 Rhymes AI. All rights reserved.
2
+ #
3
+ # Licensed to the Apache Software Foundation (ASF) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The ASF licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+
20
+ import logging
21
+ import os
22
+ from typing import Tuple
23
+
24
+ import torch
25
+ import torch.nn as nn
26
+ import torch.nn.functional as F
27
+ from torch import nn
28
+ from transformers import LlamaConfig
29
+ from transformers.models.llama.modeling_llama import (
30
+ ACT2FN,
31
+ LLAMA_ATTENTION_CLASSES,
32
+ LlamaDecoderLayer,
33
+ LlamaForCausalLM,
34
+ LlamaMLP,
35
+ LlamaModel,
36
+ LlamaRMSNorm,
37
+ LlamaRotaryEmbedding,
38
+ )
39
+
40
+ logger = logging.getLogger(__name__)
41
+
42
+
43
+ class AriaMoELMConfig(LlamaConfig):
44
+ """
45
+ Configuration class for AriaMoE language model.
46
+
47
+ This class extends the LlamaConfig to include additional parameters specific to the Mixture of Experts (MoE) architecture.
48
+ """
49
+
50
+ model_type = "aria_moe_lm"
51
+
52
+ def __init__(
53
+ self,
54
+ moe_intermediate_size: int = 4096,
55
+ moe_num_experts: int = 8,
56
+ moe_topk: int = 2,
57
+ moe_z_loss_coeff: float = 1e-5,
58
+ moe_aux_loss_coeff: float = 1e-3,
59
+ moe_num_shared_experts: int = 2,
60
+ **kwargs,
61
+ ):
62
+ """
63
+ Initialize the AriaMoELMConfig.
64
+
65
+ Args:
66
+ moe_intermediate_size (int): The intermediate size for MoE layers. Default is 4096.
67
+ moe_num_experts (int): The number of experts in the MoE layer. Default is 8.
68
+ moe_topk (int): The number of top experts to route to for each token. Default is 2.
69
+ moe_z_loss_coeff (float): The coefficient for the auxiliary z-loss. Default is 1e-5.
70
+ moe_aux_loss_coeff (float): The coefficient for the auxiliary load balancing loss. Default is 1e-3.
71
+ moe_num_shared_experts (int): The number of shared experts. Default is 2.
72
+ **kwargs: Additional keyword arguments to be passed to the parent LlamaConfig.
73
+ """
74
+ super().__init__(**kwargs)
75
+ self.moe_intermediate_size = moe_intermediate_size
76
+ self.moe_num_experts = moe_num_experts
77
+ self.moe_topk = moe_topk
78
+ self.moe_z_loss_coeff = moe_z_loss_coeff
79
+ self.moe_aux_loss_coeff = moe_aux_loss_coeff
80
+ self.moe_num_shared_experts = moe_num_shared_experts
81
+
82
+
83
+ # copied from https://github.com/NVIDIA/Megatron-LM/blob/54f1f78529cbc2b9cddad313e7f9d96ac0420a27/megatron/core/transformer/moe/moe_utils.py#L101-L142
84
+ class MoEAuxLossAutoScaler(torch.autograd.Function):
85
+ """An AutoScaler that compute and scales the grad for auxiliary loss."""
86
+
87
+ main_loss_backward_scale: torch.Tensor = torch.tensor(1.0)
88
+
89
+ @staticmethod
90
+ def forward(ctx, output: torch.Tensor, aux_loss: torch.Tensor):
91
+ """Preserve the aux_loss by storing it in the context to avoid garbage collection.
92
+
93
+ Args:
94
+ output (torch.Tensor): The output tensor.
95
+ aux_loss (torch.Tensor): The auxiliary loss tensor.
96
+
97
+ Returns:
98
+ torch.Tensor: The output tensor.
99
+ """
100
+ ctx.save_for_backward(aux_loss)
101
+ return output
102
+
103
+ @staticmethod
104
+ def backward(ctx, grad_output: torch.Tensor):
105
+ """Compute and scale the gradient for auxiliary loss..
106
+
107
+ Args:
108
+ grad_output (torch.Tensor): The gradient of the output.
109
+
110
+ Returns:
111
+ Tuple[torch.Tensor, torch.Tensor]: The gradient of the output, scaled auxiliary loss gradient.
112
+ """
113
+ (aux_loss,) = ctx.saved_tensors
114
+ aux_loss_backward_scale = MoEAuxLossAutoScaler.main_loss_backward_scale
115
+ scaled_aux_loss_grad = torch.ones_like(aux_loss) * aux_loss_backward_scale
116
+ return grad_output, scaled_aux_loss_grad
117
+
118
+ @staticmethod
119
+ def set_loss_scale(scale: torch.Tensor):
120
+ """set the scale of the aux loss.
121
+
122
+ Args:
123
+ scale (torch.Tensor): The scale value to set. Please ensure that the scale passed in matches the scale of the main_loss.
124
+ """
125
+ MoEAuxLossAutoScaler.main_loss_backward_scale = scale
126
+
127
+
128
+ def z_loss_func(logits, z_loss_coeff):
129
+ """Encourages the router's logits to remain small to enhance stability.
130
+ Please refer to the ST-MoE paper (https://arxiv.org/pdf/2202.08906.pdf) for details.
131
+
132
+ Args:
133
+ logits (torch.Tensor): The logits of the router.
134
+
135
+ Returns:
136
+ torch.Tensor: The logits after applying the z-loss.
137
+ """
138
+
139
+ z_loss = torch.mean(torch.square(torch.logsumexp(logits, dim=-1))) * z_loss_coeff
140
+ return z_loss
141
+
142
+
143
+ def switch_load_balancing_loss_func(
144
+ probs: torch.Tensor,
145
+ tokens_per_expert: torch.Tensor,
146
+ topk: int,
147
+ moe_aux_loss_coeff: float,
148
+ ):
149
+ """Calculate the auxiliary loss for better load balacing.
150
+ Please refer to the Switch Transformer paper (https://arxiv.org/abs/2101.03961) for details.
151
+
152
+ Args:
153
+ probs (torch.Tensor): The softmax probs output by the router for each token. [num_tokens, num_experts]
154
+ tokens_per_expert (torch.Tensor): The number of assigned tokens for each expert. [num_experts]
155
+
156
+ Returns:
157
+ torch.Tensor: The auxiliary loss for load balancing.
158
+ """
159
+ num_tokens = probs.shape[0] * topk
160
+ num_experts = probs.shape[1]
161
+
162
+ probs_mean_per_expert = probs.mean(dim=0)
163
+ aux_loss = torch.sum(probs_mean_per_expert * tokens_per_expert) * (
164
+ num_experts / num_tokens * moe_aux_loss_coeff
165
+ )
166
+ return aux_loss
167
+
168
+
169
+ # adapted from https://github.com/NVIDIA/Megatron-LM/blob/54f1f78529cbc2b9cddad313e7f9d96ac0420a27/megatron/core/transformer/moe/router.py#L96-L304
170
+ class TopKRouter(nn.Module):
171
+ """
172
+ Top-K Router for Mixture of Experts (MoE) models.
173
+
174
+ This router determines which experts should process each token based on the top-k scoring experts.
175
+ It also applies auxiliary losses to encourage load balancing among experts.
176
+
177
+ Args:
178
+ config (AriaMoELMConfig): Configuration object containing MoE-related parameters.
179
+ """
180
+
181
+ def __init__(self, config: AriaMoELMConfig):
182
+ super().__init__()
183
+ self.config = config
184
+
185
+ self.weight = nn.Parameter(
186
+ torch.empty((self.config.moe_num_experts, self.config.hidden_size))
187
+ )
188
+ # FIXME: initialize the weight
189
+
190
+ def gating(self, input: torch.Tensor) -> torch.Tensor:
191
+ """
192
+ Compute the gating logits for each token-expert pair.
193
+
194
+ Args:
195
+ input (torch.Tensor): Input tensor of shape [batch_size * seq_len, hidden_size].
196
+
197
+ Returns:
198
+ torch.Tensor: Logits tensor of shape [batch_size * seq_len, num_experts].
199
+ """
200
+ logits = torch.nn.functional.linear(input, self.weight)
201
+ return logits
202
+
203
+ def apply_z_loss(self, logits: torch.Tensor) -> torch.Tensor:
204
+ """
205
+ Apply z-loss to encourage router logits to remain small for enhanced stability.
206
+
207
+ Args:
208
+ logits (torch.Tensor): Router logits.
209
+
210
+ Returns:
211
+ torch.Tensor: Logits with z-loss applied.
212
+ """
213
+ z_loss = z_loss_func(logits, self.config.moe_z_loss_coeff)
214
+ logits = MoEAuxLossAutoScaler.apply(logits, z_loss)
215
+ return logits
216
+
217
+ def apply_aux_loss(
218
+ self,
219
+ logits: torch.Tensor,
220
+ tokens_per_expert: torch.Tensor,
221
+ activation: torch.Tensor,
222
+ ) -> torch.Tensor:
223
+ """
224
+ Apply auxiliary loss for load balancing among experts.
225
+
226
+ Args:
227
+ logits (torch.Tensor): Router logits.
228
+ tokens_per_expert (torch.Tensor): Number of tokens assigned to each expert.
229
+ activation (torch.Tensor): Activation values.
230
+
231
+ Returns:
232
+ torch.Tensor: Activation with auxiliary loss applied.
233
+ """
234
+ probs = torch.softmax(logits, dim=-1, dtype=torch.float32)
235
+ aux_loss = switch_load_balancing_loss_func(
236
+ probs,
237
+ tokens_per_expert,
238
+ self.config.moe_topk,
239
+ self.config.moe_aux_loss_coeff,
240
+ )
241
+ return MoEAuxLossAutoScaler.apply(activation, aux_loss)
242
+
243
+ def routing(
244
+ self, logits: torch.Tensor
245
+ ) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
246
+ """
247
+ Perform the routing operation to determine expert assignments.
248
+
249
+ Args:
250
+ logits (torch.Tensor): Router logits.
251
+
252
+ Returns:
253
+ Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
254
+ - scores: Softmax probabilities for top-k experts.
255
+ - top_indices: Indices of top-k experts for each token.
256
+ - tokens_per_expert: Number of tokens assigned to each expert.
257
+ """
258
+ logits = self.apply_z_loss(logits)
259
+
260
+ top_logits, top_indices = torch.topk(logits, k=self.config.moe_topk, dim=1)
261
+ scores = torch.softmax(top_logits, dim=-1, dtype=torch.float32).type_as(logits)
262
+
263
+ tokens_per_expert = torch.histc(
264
+ top_indices.flatten(),
265
+ bins=self.config.moe_num_experts,
266
+ min=0,
267
+ max=self.config.moe_num_experts - 1,
268
+ )
269
+
270
+ scores = self.apply_aux_loss(logits, tokens_per_expert, scores)
271
+ return scores, top_indices, tokens_per_expert
272
+
273
+ def forward(
274
+ self, input: torch.Tensor
275
+ ) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
276
+ """
277
+ Forward pass of the TopKRouter.
278
+
279
+ Args:
280
+ input (torch.Tensor): Input tensor of shape [batch_size * seq_len, hidden_size].
281
+
282
+ Returns:
283
+ Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
284
+ - scores: Softmax probabilities for top-k experts.
285
+ - top_indices: Indices of top-k experts for each token.
286
+ - tokens_per_expert: Number of tokens assigned to each expert.
287
+ """
288
+ logits = self.gating(input)
289
+ logits = logits.view(-1, self.config.moe_num_experts)
290
+ scores, top_indices, tokens_per_expert = self.routing(logits)
291
+ return scores, top_indices, tokens_per_expert
292
+
293
+
294
+ # adapted from https://github.com/NVIDIA/Megatron-LM/blob/54f1f78529cbc2b9cddad313e7f9d96ac0420a27/megatron/core/transformer/moe/token_dispatcher.py#L291-L587
295
+ class TokenDispatcher:
296
+ """
297
+ Handles the dispatching and gathering of tokens to and from experts.
298
+
299
+ This class is responsible for permuting tokens based on expert assignments and
300
+ unpermuting them after expert processing.
301
+
302
+ Args:
303
+ config (AriaMoELMConfig): Configuration object containing MoE-related parameters.
304
+ """
305
+
306
+ def __init__(self, config: AriaMoELMConfig):
307
+ self.config = config
308
+ self.hidden_states_shape = None
309
+ self.reversed_input_permutation_mapping = None
310
+
311
+ def token_permutation(
312
+ self, hidden_states: torch.Tensor, indices: torch.Tensor
313
+ ) -> torch.Tensor:
314
+ """
315
+ Permute tokens based on expert assignments.
316
+
317
+ Args:
318
+ hidden_states (torch.Tensor): Input hidden states.
319
+ indices (torch.Tensor): Expert assignment indices.
320
+
321
+ Returns:
322
+ torch.Tensor: Permuted tokens.
323
+ """
324
+ self.hidden_states_shape = hidden_states.shape
325
+ hidden_states = hidden_states.view(-1, hidden_states.size(-1))
326
+ flatten_indices = indices.flatten()
327
+ sorted_indices = torch.argsort(flatten_indices, stable=True)
328
+ permuted_tokens = hidden_states.index_select(
329
+ 0, sorted_indices // self.config.moe_topk
330
+ )
331
+ self.reversed_input_permutation_mapping = sorted_indices
332
+ return permuted_tokens
333
+
334
+ def token_unpermutation(
335
+ self, permuted_tokens: torch.Tensor, scores: torch.Tensor
336
+ ) -> torch.Tensor:
337
+ """
338
+ Unpermute tokens and combine expert outputs.
339
+
340
+ Args:
341
+ permuted_tokens (torch.Tensor): Tokens after expert processing.
342
+ scores (torch.Tensor): Expert assignment scores.
343
+
344
+ Returns:
345
+ torch.Tensor: Unpermuted and combined output.
346
+ """
347
+ num_unpermuted_tokens = scores.numel()
348
+ unpermuted_tokens = torch.zeros(
349
+ (num_unpermuted_tokens, permuted_tokens.size(1)),
350
+ dtype=permuted_tokens.dtype,
351
+ device=permuted_tokens.device,
352
+ )
353
+ unpermuted_tokens.index_copy_(
354
+ 0, self.reversed_input_permutation_mapping, permuted_tokens
355
+ )
356
+ unpermuted_tokens = unpermuted_tokens.reshape(
357
+ -1, self.config.moe_topk, permuted_tokens.size(1)
358
+ )
359
+
360
+ unpermuted_tokens = unpermuted_tokens * scores.unsqueeze(-1)
361
+ unpermuted_tokens = unpermuted_tokens.sum(dim=1).type_as(permuted_tokens)
362
+ output = unpermuted_tokens.view(self.hidden_states_shape)
363
+ return output
364
+
365
+
366
+ class SharedExpertMLP(LlamaMLP):
367
+ """
368
+ Shared Expert MLP for shared experts.
369
+
370
+ Unlike routed experts, shared experts process all tokens without routing.
371
+ This class reconfigures the intermediate size in comparison to the LlamaMLP.
372
+
373
+ Args:
374
+ config (AriaMoELMConfig): Configuration object for the AriaMoE language model.
375
+ """
376
+
377
+ def __init__(self, config: AriaMoELMConfig):
378
+ nn.Module.__init__(self)
379
+ self.config = config
380
+ self.hidden_size = config.hidden_size
381
+ self.intermediate_size = (
382
+ config.moe_intermediate_size * config.moe_num_shared_experts
383
+ )
384
+ self.gate_proj = nn.Linear(
385
+ self.hidden_size, self.intermediate_size, bias=config.mlp_bias
386
+ )
387
+ self.up_proj = nn.Linear(
388
+ self.hidden_size, self.intermediate_size, bias=config.mlp_bias
389
+ )
390
+ self.down_proj = nn.Linear(
391
+ self.intermediate_size, self.hidden_size, bias=config.mlp_bias
392
+ )
393
+ self.act_fn = ACT2FN[config.hidden_act]
394
+
395
+
396
+ def sequential_gemm(input, weight, tokens_per_expert):
397
+ """
398
+ Compute the matrix multiplication (GEMM) for each expert sequentially. This approach is computationally inefficient, especially when dealing with a large number of experts.
399
+
400
+ Args:
401
+ input (torch.Tensor): Input tensor of shape (num_tokens, in_features).
402
+ weight (torch.Tensor): Weight tensor of shape (num_experts, in_features, out_features).
403
+ tokens_per_expert (torch.Tensor): Number of tokens assigned to each expert.
404
+
405
+ Returns:
406
+ torch.Tensor: Output tensor of shape (num_tokens, out_features).
407
+ """
408
+ num_tokens = input.shape[0]
409
+ out_features = weight.shape[-1]
410
+ output = torch.zeros(
411
+ num_tokens, out_features, dtype=input.dtype, device=input.device
412
+ )
413
+
414
+ cumsum_num_tokens = torch.cumsum(tokens_per_expert, dim=0)
415
+ # Insert zero at the begining for offset index's convenience
416
+ zero_tensor = torch.zeros(1, dtype=torch.long, device=cumsum_num_tokens.device)
417
+ cumsum_num_tokens = torch.cat((zero_tensor, cumsum_num_tokens))
418
+
419
+ for expert_num in range(weight.shape[0]):
420
+ start = cumsum_num_tokens[expert_num]
421
+ end = cumsum_num_tokens[expert_num + 1]
422
+ tokens = input[start:end]
423
+
424
+ out = torch.matmul(tokens, weight[expert_num])
425
+ output[start:end] = out
426
+ return output
427
+
428
+
429
+ try:
430
+ from grouped_gemm.ops import gmm as experts_gemm
431
+
432
+ if os.environ.get("USE_GROUPED_GEMM", "1") == "0":
433
+ logger.warning(
434
+ "environment variable USE_GROUPED_GEMM is set to 0, using sequential GEMM instead."
435
+ )
436
+ experts_gemm = sequential_gemm
437
+ except ImportError:
438
+ logger.warning(
439
+ "`grouped_gemm` is not installed, using sequential GEMM, which is slower."
440
+ )
441
+ experts_gemm = sequential_gemm
442
+
443
+
444
+ class GroupedGEMM(nn.Module):
445
+ """
446
+ Grouped GEMM (General Matrix Multiplication) module for efficient expert computation.
447
+ This module utilizes the grouped_gemm library (https://github.com/fanshiqing/grouped_gemm)
448
+ for optimized performance. If the grouped_gemm library is not installed, it gracefully
449
+ falls back to a sequential GEMM implementation, which may be slower but ensures
450
+ functionality.
451
+
452
+ Args:
453
+ in_features (int): Number of input features.
454
+ out_features (int): Number of output features.
455
+ groups (int): Number of expert groups.
456
+ """
457
+
458
+ def __init__(self, in_features, out_features, groups):
459
+ super().__init__()
460
+ self.in_features = in_features
461
+ self.out_features = out_features
462
+ self.groups = groups
463
+ self.weight = nn.Parameter(torch.empty(groups, in_features, out_features))
464
+
465
+ def forward(self, input, tokens_per_expert):
466
+ """
467
+ Perform grouped matrix multiplication.
468
+
469
+ Args:
470
+ input (torch.Tensor): Input tensor of shape (num_tokens, in_features).
471
+ tokens_per_expert (torch.Tensor): Number of tokens assigned to each expert.
472
+
473
+ Returns:
474
+ torch.Tensor: Output tensor of shape (num_tokens, out_features).
475
+ """
476
+ tokens_per_expert = tokens_per_expert.cpu()
477
+
478
+ # Ensure the CUDA device matches the input tensor's device.
479
+ # This mismatch can occur when using `transformers.AutoModel.from_pretrained`
480
+ # with `device_map="auto"` on a multi-GPU setup.
481
+ torch.cuda.set_device(input.device)
482
+ return experts_gemm(input, self.weight, tokens_per_expert)
483
+
484
+
485
+ class GroupedMLP(nn.Module):
486
+ """
487
+ Grouped MLP module for Mixture of Experts.
488
+
489
+ Args:
490
+ config (AriaMoELMConfig): Configuration object for the model.
491
+ """
492
+
493
+ def __init__(self, config: AriaMoELMConfig) -> None:
494
+ super().__init__()
495
+ self.config = config
496
+ self.fc1 = GroupedGEMM(
497
+ config.hidden_size, config.moe_intermediate_size * 2, config.moe_num_experts
498
+ )
499
+ self.fc2 = GroupedGEMM(
500
+ config.moe_intermediate_size, config.hidden_size, config.moe_num_experts
501
+ )
502
+
503
+ def glu(x):
504
+ x = torch.chunk(x, 2, dim=-1)
505
+ return F.silu(x[0]) * x[1]
506
+
507
+ self.activation_func = glu
508
+
509
+ def forward(self, permuted_tokens, tokens_per_expert):
510
+ """
511
+ Forward pass of the Grouped MLP.
512
+
513
+ Args:
514
+ permuted_tokens (torch.Tensor): Permuted input tokens.
515
+ tokens_per_expert (torch.Tensor): Number of tokens assigned to each expert.
516
+
517
+ Returns:
518
+ torch.Tensor: Output tensor after passing through the MLP.
519
+ """
520
+ fc1_output = self.fc1(permuted_tokens, tokens_per_expert)
521
+ fc1_output = self.activation_func(fc1_output)
522
+ fc2_output = self.fc2(fc1_output, tokens_per_expert)
523
+ return fc2_output
524
+
525
+
526
+ class MoELayer(nn.Module):
527
+ """
528
+ Mixture of Experts (MoE) Layer for the AriaMoE model.
529
+
530
+ This layer implements the MoE mechanism, which routes input tokens to different experts
531
+ based on a routing algorithm, processes them through the experts, and then combines
532
+ the outputs.
533
+
534
+ Args:
535
+ config (AriaMoELMConfig): Configuration object for the MoE layer.
536
+ """
537
+
538
+ def __init__(self, config: AriaMoELMConfig):
539
+ super().__init__()
540
+
541
+ self.router = TopKRouter(config)
542
+ self.token_dispatcher = TokenDispatcher(config)
543
+ self.experts = GroupedMLP(config)
544
+ self.shared_experts = SharedExpertMLP(config)
545
+
546
+ def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
547
+ """
548
+ Forward pass of the MoE Layer.
549
+
550
+ Args:
551
+ hidden_states (torch.Tensor): Input tensor of shape (batch_size, sequence_length, hidden_size).
552
+
553
+ Returns:
554
+ torch.Tensor: Output tensor after passing through the MoE layer.
555
+
556
+ Process:
557
+ 1. Route tokens to experts using the router.
558
+ 2. Permute tokens based on routing decisions.
559
+ 3. Process tokens through experts.
560
+ 4. Unpermute and combine expert outputs.
561
+ 5. Add shared expert output to the final result.
562
+ """
563
+ scores, indices, tokens_per_expert = self.router(hidden_states)
564
+
565
+ permuted_tokens = self.token_dispatcher.token_permutation(
566
+ hidden_states, indices
567
+ )
568
+
569
+ expert_output = self.experts(permuted_tokens, tokens_per_expert)
570
+
571
+ output = self.token_dispatcher.token_unpermutation(expert_output, scores)
572
+
573
+ shared_expert_output = self.shared_experts(hidden_states)
574
+ output += shared_expert_output
575
+ return output
576
+
577
+
578
+ class MoEDecoderLayer(LlamaDecoderLayer):
579
+ """
580
+ Custom Decoder Layer for the AriaMoE model which modifies the standard `LlamaDecoderLayer` by
581
+ replacing the traditional MLP with a Mixture of Experts (MoE) Layer.
582
+
583
+ Args:
584
+ config (LlamaConfig): Configuration object for the layer.
585
+ layer_idx (int): Index of the current layer in the model.
586
+ """
587
+
588
+ def __init__(self, config: LlamaConfig, layer_idx: int):
589
+ nn.Module.__init__(self)
590
+ self.hidden_size = config.hidden_size
591
+
592
+ self.self_attn = LLAMA_ATTENTION_CLASSES[config._attn_implementation](
593
+ config=config, layer_idx=layer_idx
594
+ )
595
+
596
+ self.mlp = MoELayer(config)
597
+ self.input_layernorm = LlamaRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
598
+ self.post_attention_layernorm = LlamaRMSNorm(
599
+ config.hidden_size, eps=config.rms_norm_eps
600
+ )
601
+
602
+
603
+ class AriaMoELMModel(LlamaModel):
604
+ """
605
+ Custom LlamaModel for the AriaMoE model which modifies the standard LlamaModel by
606
+ replacing the `LlamaDecoderLayer` with `MoEDecoderLayer`.
607
+
608
+ This model implements a Mixture of Experts (MoE) approach, where each layer contains
609
+ multiple expert networks that specialize in different aspects of the input.
610
+
611
+ Args:
612
+ config (LlamaConfig): Configuration object for the model.
613
+ """
614
+
615
+ def __init__(self, config: LlamaConfig):
616
+ super().__init__(config)
617
+ self.padding_idx = config.pad_token_id
618
+ self.vocab_size = config.vocab_size
619
+
620
+ self.embed_tokens = nn.Embedding(
621
+ config.vocab_size, config.hidden_size, self.padding_idx
622
+ )
623
+ self.layers = nn.ModuleList(
624
+ [
625
+ MoEDecoderLayer(config, layer_idx)
626
+ for layer_idx in range(config.num_hidden_layers)
627
+ ]
628
+ )
629
+ self.norm = LlamaRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
630
+ self.rotary_emb = LlamaRotaryEmbedding(config=config)
631
+ self.gradient_checkpointing = False
632
+
633
+ # Initialize weights and apply final processing
634
+ self.post_init()
635
+
636
+
637
+ class AriaMoELMForCausalLM(LlamaForCausalLM):
638
+ """
639
+ AriaMoE model for causal language modeling tasks.
640
+
641
+ This class extends LlamaForCausalLM to incorporate the Mixture of Experts (MoE) approach,
642
+ allowing for more efficient and scalable language modeling.
643
+
644
+ Args:
645
+ config (AriaMoELMConfig): Configuration object for the model.
646
+ """
647
+
648
+ _tied_weights_keys = ["lm_head.weight"]
649
+ config_class = AriaMoELMConfig
650
+ _no_split_modules = ["MoEDecoderLayer"]
651
+
652
+ def __init__(self, config):
653
+ super().__init__(config)
654
+ self.model = AriaMoELMModel(config)
655
+ self.vocab_size = config.vocab_size
656
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
657
+
658
+ # Initialize weights and apply final processing
659
+ self.post_init()
660
+
661
+ def set_z_loss_coeff(self, z_loss_coeff: float):
662
+ """
663
+ Set the coefficient for the z-loss in the MoE routing.
664
+
665
+ Args:
666
+ z_loss_coeff (float): The coefficient for the z-loss.
667
+ """
668
+ self.config.moe_z_loss_coeff = z_loss_coeff
669
+
670
+ def set_aux_loss_coeff(self, aux_loss_coeff: float):
671
+ """
672
+ Set the coefficient for the auxiliary loss in the MoE routing.
673
+
674
+ Args:
675
+ aux_loss_coeff (float): The coefficient for the auxiliary loss.
676
+ """
677
+ self.config.moe_aux_loss_coeff = aux_loss_coeff
preprocessor_config.json ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_transform": null,
3
+ "auto_map": {
4
+ "AutoImageProcessor": "vision_processor.AriaVisionProcessor",
5
+ "AutoProcessor": "processing_aria.AriaProcessor"
6
+ },
7
+ "image_mean": [
8
+ 0.5,
9
+ 0.5,
10
+ 0.5
11
+ ],
12
+ "image_processor_type": "AriaVisionProcessor",
13
+ "image_std": [
14
+ 0.5,
15
+ 0.5,
16
+ 0.5
17
+ ],
18
+ "max_image_size": 980,
19
+ "min_image_size": 336,
20
+ "processor_class": "AriaProcessor"
21
+ }
processing_aria.py ADDED
@@ -0,0 +1,258 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2024 Rhymes AI. All rights reserved.
2
+ #
3
+ # Licensed to the Apache Software Foundation (ASF) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The ASF licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+
20
+ import inspect
21
+ from typing import List, Optional, Union
22
+
23
+ from transformers import AutoTokenizer, BatchFeature
24
+ from transformers.image_utils import ImageInput
25
+ from transformers.processing_utils import ProcessorMixin
26
+ from transformers.tokenization_utils import (
27
+ PaddingStrategy,
28
+ PreTokenizedInput,
29
+ TensorType,
30
+ TextInput,
31
+ TruncationStrategy,
32
+ )
33
+
34
+ from .vision_processor import AriaVisionProcessor
35
+
36
+
37
+ class AriaProcessor(ProcessorMixin):
38
+ """
39
+ AriaProcessor is a processor for the Aria model which wraps the Aria image preprocessor and the LLama slow tokenizer.
40
+ Args:
41
+ image_processor(AriaVisionProcessor): The AriaVisionProcessor to use for image preprocessing.
42
+ tokenizer(AutoTokenizer): The AutoTokenizer to use for tokenizing the text.
43
+ patch_size(int): The patch size to use for the image processor.
44
+ chat_template(str): The chat template to use for the tokenizer.
45
+ image_token(str): The image token to use for the tokenizer.
46
+ """
47
+
48
+ attributes = []
49
+ valid_kwargs = ["chat_template", "patch_size", "image_token"]
50
+ image_processor_class = None
51
+ tokenizer_class = "AutoTokenizer"
52
+
53
+ def __init__(
54
+ self,
55
+ image_processor: AriaVisionProcessor = None,
56
+ tokenizer: Union[AutoTokenizer, str] = None,
57
+ patch_size: int = 490,
58
+ chat_template: str = None,
59
+ image_token: str = "<|img|>",
60
+ ):
61
+ super().__init__(chat_template=chat_template)
62
+
63
+ if image_processor is None:
64
+ self.image_processor = AriaVisionProcessor(image_max_size=patch_size)
65
+ else:
66
+ self.image_processor = image_processor
67
+
68
+ if isinstance(tokenizer, str):
69
+ self.tokenizer = AutoTokenizer.from_pretrained(
70
+ tokenizer, trust_remote_code=True, use_fast=False
71
+ )
72
+ if self.tokenizer.pad_token is None:
73
+ self.tokenizer.pad_token = self.tokenizer.unk_token
74
+ else:
75
+ self.tokenizer = tokenizer
76
+
77
+ self.image_token = image_token
78
+
79
+ # Copied from transformers.models.llava_next.processing_llave_next.LlavaNextProcessor.__call__
80
+ def __call__(
81
+ self,
82
+ text: Union[
83
+ TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]
84
+ ],
85
+ images: ImageInput = None,
86
+ padding: Union[bool, str, PaddingStrategy] = False,
87
+ truncation: Union[bool, str, TruncationStrategy] = None,
88
+ max_length: Optional[int] = None,
89
+ max_image_size: Optional[int] = 980,
90
+ return_tensors: Optional[Union[str, TensorType]] = TensorType.PYTORCH,
91
+ ) -> BatchFeature:
92
+ """
93
+ Main method to prepare for the model one or several sequences(s) and image(s). Please refer to the doctsring
94
+ of the above two methods for more information.
95
+
96
+ Args:
97
+ text (`str`, `List[str]`, `List[List[str]]`):
98
+ The sequence or batch of sequences to be encoded. Each sequence can be a string or a list of strings
99
+ (pretokenized string). If the sequences are provided as list of strings (pretokenized), you must set
100
+ `is_split_into_words=True` (to lift the ambiguity with a batch of sequences).
101
+ images (`PIL.Image.Image`, `np.ndarray`, `torch.Tensor`, `List[PIL.Image.Image]`, `List[np.ndarray]`, `List[torch.Tensor]`):
102
+ The image or batch of images to be prepared. Each image can be a PIL image, NumPy array or PyTorch
103
+ tensor. Both channels-first and channels-last formats are supported.
104
+ padding (`bool`, `str` or [`~utils.PaddingStrategy`], *optional*, defaults to `False`):
105
+ Select a strategy to pad the returned sequences (according to the model's padding side and padding
106
+ index) among:
107
+ - `True` or `'longest'`: Pad to the longest sequence in the batch (or no padding if only a single
108
+ sequence if provided).
109
+ - `'max_length'`: Pad to a maximum length specified with the argument `max_length` or to the maximum
110
+ acceptable input length for the model if that argument is not provided.
111
+ - `False` or `'do_not_pad'` (default): No padding (i.e., can output a batch with sequences of different
112
+ lengths).
113
+ max_length (`int`, *optional*):
114
+ Maximum length of the returned list and optionally padding length (see above).
115
+ max_image_size (`int`, *optional*):
116
+ Maximum size of the image to be processed.
117
+ truncation (`bool`, *optional*):
118
+ Activates truncation to cut input sequences longer than `max_length` to `max_length`.
119
+ return_tensors (`str` or [`~utils.TensorType`], *optional*):
120
+ If set, will return tensors of a particular framework. Acceptable values are:
121
+
122
+ - `'tf'`: Return TensorFlow `tf.constant` objects.
123
+ - `'pt'`: Return PyTorch `torch.Tensor` objects.
124
+ - `'np'`: Return NumPy `np.ndarray` objects.
125
+ - `'jax'`: Return JAX `jnp.ndarray` objects.
126
+
127
+ Returns:
128
+ [`BatchFeature`]: A [`BatchFeature`] with the following fields:
129
+
130
+ - **input_ids** -- List of token ids to be fed to a model. Returned when `text` is not `None`.
131
+ - **attention_mask** -- List of indices specifying which tokens should be attended to by the model (when
132
+ `return_attention_mask=True` or if *"attention_mask"* is in `self.model_input_names` and if `text` is not
133
+ `None`).
134
+ - **pixel_values** -- Pixel values to be fed to a model. Returned when `images` is not `None`.
135
+ - **pixel_mask** -- Pixel mask to be fed to a model. Returned when `images` is not `None`.
136
+ """
137
+ if images is not None:
138
+ image_inputs = self.image_processor(
139
+ images,
140
+ return_tensors=return_tensors,
141
+ max_image_size=max_image_size,
142
+ )
143
+ else:
144
+ image_inputs = {}
145
+
146
+ if isinstance(text, str):
147
+ text = [text]
148
+ elif not isinstance(text, list) and not isinstance(text[0], str):
149
+ raise ValueError(
150
+ "Invalid input text. Please provide a string, or a list of strings"
151
+ )
152
+
153
+ prompt_strings = text
154
+
155
+ text_inputs = self.tokenizer(
156
+ prompt_strings,
157
+ return_tensors=return_tensors,
158
+ padding=padding,
159
+ truncation=truncation,
160
+ max_length=max_length,
161
+ )
162
+
163
+ return BatchFeature(data={**text_inputs, **image_inputs})
164
+
165
+ @staticmethod
166
+ def _extract_kwargs(func: callable, **kwargs) -> dict:
167
+ """
168
+ Extract the kwargs that are valid for the given function.
169
+ """
170
+ return {
171
+ k: v for k, v in kwargs.items() if k in inspect.signature(func).parameters
172
+ }
173
+
174
+ def save_pretrained(self, save_directory, **kwargs):
175
+ """
176
+ Save both the image processor and tokenizer.
177
+ """
178
+ if self.image_processor is not None:
179
+ self.image_processor.save_pretrained(
180
+ save_directory,
181
+ **self._extract_kwargs(self.image_processor.save_pretrained, **kwargs),
182
+ )
183
+ if self.tokenizer is not None:
184
+ self.tokenizer.save_pretrained(
185
+ save_directory,
186
+ **self._extract_kwargs(self.tokenizer.save_pretrained, **kwargs),
187
+ )
188
+
189
+ @classmethod
190
+ def from_pretrained(
191
+ cls,
192
+ pretrained_model_name_or_path,
193
+ tokenizer_path=None,
194
+ image_processor_path=None,
195
+ **kwargs,
196
+ ):
197
+ """
198
+ Load both the image processor and tokenizer from a pretrained model path.
199
+ """
200
+ tokenizer_path = (
201
+ tokenizer_path
202
+ if tokenizer_path is not None
203
+ else pretrained_model_name_or_path
204
+ )
205
+ image_processor_path = (
206
+ image_processor_path
207
+ if image_processor_path is not None
208
+ else pretrained_model_name_or_path
209
+ )
210
+ image_processor = AriaVisionProcessor.from_pretrained(
211
+ image_processor_path,
212
+ **cls._extract_kwargs(AriaVisionProcessor.from_pretrained, **kwargs),
213
+ )
214
+ try:
215
+ tokenizer = AutoTokenizer.from_pretrained(
216
+ tokenizer_path,
217
+ **cls._extract_kwargs(AutoTokenizer.from_pretrained, **kwargs),
218
+ )
219
+ chat_template = tokenizer.chat_template
220
+ except Exception:
221
+ tokenizer = None
222
+ chat_template = None
223
+ return cls(
224
+ image_processor=image_processor,
225
+ tokenizer=tokenizer,
226
+ chat_template=chat_template,
227
+ )
228
+
229
+ # Copied from transformers.models.clip.processing_clip.CLIPProcessor.batch_decode with CLIP->Llama
230
+ def batch_decode(self, *args, **kwargs):
231
+ """
232
+ This method forwards all its arguments to LlamaTokenizerFast's [`~PreTrainedTokenizer.batch_decode`]. Please
233
+ refer to the docstring of this method for more information.
234
+ """
235
+ if self.tokenizer is None:
236
+ raise ValueError(
237
+ "Tokenizer is not initialized. Please provide a valid tokenizer."
238
+ )
239
+ return self.tokenizer.batch_decode(*args, **kwargs)
240
+
241
+ # Copied from transformers.models.clip.processing_clip.CLIPProcessor.decode with CLIP->Llama
242
+ def decode(self, *args, **kwargs):
243
+ """
244
+ This method forwards all its arguments to LlamaTokenizerFast's [`~PreTrainedTokenizer.decode`]. Please refer to
245
+ the docstring of this method for more information.
246
+ """
247
+ if self.tokenizer is None:
248
+ raise ValueError(
249
+ "Tokenizer is not initialized. Please provide a valid tokenizer."
250
+ )
251
+ return self.tokenizer.decode(*args, **kwargs)
252
+
253
+ @property
254
+ # Copied from transformers.models.clip.processing_clip.CLIPProcessor.model_input_names
255
+ def model_input_names(self):
256
+ tokenizer_input_names = self.tokenizer.model_input_names
257
+ image_processor_input_names = self.image_processor.model_input_names
258
+ return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names))
projector.py ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2024 Rhymes AI. All rights reserved.
2
+ #
3
+ # Licensed to the Apache Software Foundation (ASF) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The ASF licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+
20
+ import torch
21
+ import torch.nn as nn
22
+ from torch.nn.init import trunc_normal_
23
+ from transformers.activations import ACT2FN
24
+
25
+
26
+ class FFN(nn.Module):
27
+ """
28
+ Feed-Forward Network module.
29
+
30
+ Args:
31
+ embed_dim (int): Input embedding dimension.
32
+ ff_dim (int): Hidden dimension of the feed-forward network.
33
+ output_dim (int): Output dimension.
34
+ """
35
+
36
+ def __init__(self, embed_dim, ff_dim, output_dim):
37
+ super().__init__()
38
+ self.linear_in = nn.Linear(embed_dim, ff_dim, bias=False)
39
+ self.linear_out = nn.Linear(ff_dim, output_dim, bias=False)
40
+ self.act = ACT2FN["gelu_new"]
41
+
42
+ def forward(self, hidden_states):
43
+ hidden_states = self.act(self.linear_in(hidden_states))
44
+ hidden_states = self.linear_out(hidden_states)
45
+ return hidden_states
46
+
47
+
48
+ class CrossAttention(nn.Module):
49
+ """
50
+ Cross-Attention module.
51
+
52
+ Args:
53
+ kv_dim (int): Dimension of key and value.
54
+ embed_dim (int): Embedding dimension.
55
+ num_heads (int): Number of attention heads.
56
+ drop_out_rate (float): Dropout rate. Default is 0.
57
+ """
58
+
59
+ def __init__(self, kv_dim, embed_dim, num_heads, drop_out_rate=0):
60
+ super().__init__()
61
+ self.num_heads = num_heads
62
+ self.q_proj = nn.Linear(embed_dim, embed_dim, bias=False)
63
+ self.k_proj = nn.Linear(kv_dim, embed_dim, bias=False)
64
+ self.v_proj = nn.Linear(kv_dim, embed_dim, bias=False)
65
+
66
+ self.multihead_attn = nn.MultiheadAttention(embed_dim, num_heads)
67
+ self.linear = nn.Linear(embed_dim, embed_dim)
68
+ self.dropout = nn.Dropout(drop_out_rate)
69
+
70
+ self.layer_norm = nn.LayerNorm(embed_dim)
71
+ self.ln_kv = nn.LayerNorm(kv_dim)
72
+
73
+ def forward(self, x, hidden_states, attn_mask=None, add_residual=False):
74
+ """
75
+ Forward pass of the CrossAttention module.
76
+
77
+ Args:
78
+ x (torch.Tensor): Input tensor for key and value.
79
+ hidden_states (torch.Tensor): Input tensor for query.
80
+ attn_mask (torch.Tensor, optional): Attention mask. Default is None.
81
+ add_residual (bool): Whether to add residual connection. Default is False.
82
+
83
+ Returns:
84
+ torch.Tensor: Output tensor after cross-attention.
85
+ """
86
+ normed_hidden_states = self.layer_norm(hidden_states)
87
+ query = self.q_proj(normed_hidden_states).permute(1, 0, 2)
88
+
89
+ x = self.ln_kv(x)
90
+ key = self.k_proj(x).permute(1, 0, 2)
91
+ value = self.v_proj(x).permute(1, 0, 2)
92
+
93
+ attn_output, _ = self.multihead_attn(query, key, value, attn_mask=attn_mask)
94
+
95
+ attn_output = attn_output.permute(1, 0, 2)
96
+
97
+ if add_residual:
98
+ attn_output = hidden_states + self.dropout(self.linear(attn_output))
99
+ else:
100
+ attn_output = self.dropout(self.linear(attn_output))
101
+
102
+ return attn_output
103
+
104
+
105
+ class AriaProjector(nn.Module):
106
+ """
107
+ A projection module with one cross attention layer and one FFN layer, which projects ViT's outputs into MoE's inputs.
108
+
109
+ Args:
110
+ patch_to_query_dict (dict): Maps patch numbers to their corresponding query numbers,
111
+ e.g., {1225: 128, 4900: 256}. This allows for different query sizes based on image resolution.
112
+ embed_dim (int): Embedding dimension.
113
+ num_heads (int): Number of attention heads.
114
+ kv_dim (int): Dimension of key and value.
115
+ ff_dim (int): Hidden dimension of the feed-forward network.
116
+ output_dim (int): Output dimension.
117
+ norm_layer (nn.Module): Normalization layer. Default is nn.LayerNorm.
118
+
119
+ Outputs:
120
+ A tensor with the shape of (batch_size, query_number, output_dim)
121
+ """
122
+
123
+ def __init__(
124
+ self,
125
+ patch_to_query_dict,
126
+ embed_dim,
127
+ num_heads,
128
+ kv_dim,
129
+ ff_dim,
130
+ output_dim,
131
+ norm_layer=nn.LayerNorm,
132
+ ):
133
+ super().__init__()
134
+ self.patch_to_query_dict = patch_to_query_dict
135
+ self.embed_dim = embed_dim
136
+ self.num_heads = num_heads
137
+
138
+ self.query = nn.Parameter(
139
+ torch.zeros(max(patch_to_query_dict.values()), self.embed_dim)
140
+ )
141
+
142
+ trunc_normal_(self.query, std=0.02)
143
+
144
+ self.cross_attn = CrossAttention(kv_dim, embed_dim, num_heads)
145
+
146
+ self.ln_ffn = norm_layer(embed_dim)
147
+ self.ffn = FFN(embed_dim, ff_dim, output_dim)
148
+
149
+ self.apply(self._init_weights)
150
+
151
+ def _init_weights(self, m):
152
+ if isinstance(m, nn.Linear):
153
+ trunc_normal_(m.weight, std=0.02)
154
+ if isinstance(m, nn.Linear) and m.bias is not None:
155
+ nn.init.constant_(m.bias, 0)
156
+ elif isinstance(m, nn.LayerNorm):
157
+ nn.init.constant_(m.bias, 0)
158
+ nn.init.constant_(m.weight, 1.0)
159
+
160
+ def forward(self, x, attn_mask=None):
161
+ """
162
+ Forward pass of the Projector module.
163
+
164
+ Args:
165
+ x (torch.Tensor): Input tensor of shape (batch_size, num_patches, kv_dim).
166
+ attn_mask (torch.Tensor, optional): Attention mask. Default is None.
167
+
168
+ Returns:
169
+ torch.Tensor: Output tensor of shape (batch_size, query_number, output_dim).
170
+ """
171
+ bs = x.shape[0]
172
+ queries = self.query.unsqueeze(0).repeat(bs, 1, 1)
173
+
174
+ query_num = self.patch_to_query_dict.get(x.shape[1], None)
175
+ assert (
176
+ query_num is not None
177
+ ), f"Query number for {x.shape[1]} patches is not provided"
178
+
179
+ queries = queries[:, :query_num, :]
180
+
181
+ if attn_mask is not None:
182
+ attn_mask = attn_mask.repeat_interleave(self.num_heads, 0)
183
+ attn_mask = attn_mask.unsqueeze(1).expand(-1, queries.size(1), -1)
184
+
185
+ attention_out = self.cross_attn(x, queries, attn_mask=attn_mask)
186
+
187
+ out = self.ffn(self.ln_ffn(attention_out))
188
+
189
+ return out
special_tokens_map.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<s>",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "eos_token": {
10
+ "content": "</s>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "unk_token": {
17
+ "content": "<unk>",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ }
23
+ }
tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e429a008ed1045d14464933311e0b3258575980efc9db4e61f368e399c719d2a
3
+ size 1696299
tokenizer_config.json ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": false,
3
+ "add_eos_token": false,
4
+ "add_prefix_space": true,
5
+ "added_tokens_decoder": {
6
+ "0": {
7
+ "content": "<unk>",
8
+ "lstrip": false,
9
+ "normalized": false,
10
+ "rstrip": false,
11
+ "single_word": false,
12
+ "special": true
13
+ },
14
+ "100352": {
15
+ "content": "<s>",
16
+ "lstrip": false,
17
+ "normalized": false,
18
+ "rstrip": false,
19
+ "single_word": false,
20
+ "special": true
21
+ },
22
+ "100353": {
23
+ "content": "</s>",
24
+ "lstrip": false,
25
+ "normalized": false,
26
+ "rstrip": false,
27
+ "single_word": false,
28
+ "special": true
29
+ }
30
+ },
31
+ "bos_token": "<s>",
32
+ "chat_template": "{% if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif %}{% for message in messages %}<|im_start|>{{ message['role'] }}\n{% if message['content'] is string %}{{ message['content'] }}{% elif message['content'] is iterable %}{% for item in message['content'] %}{% if item['type'] == 'text' %}{{ item['text'] }}{% elif item['type'] == 'image' %}<fim_prefix><|img|><fim_suffix>{% endif %}{% endfor %}{% endif %}<|im_end|>\n{% endfor %}{% if add_generation_prompt %}<|im_start|>assistant\n{% endif %}",
33
+ "clean_up_tokenization_spaces": false,
34
+ "eos_token": "</s>",
35
+ "legacy": true,
36
+ "model_max_length": 1000000000000000019884624838656,
37
+ "pad_token": null,
38
+ "sp_model_kwargs": {},
39
+ "spaces_between_special_tokens": false,
40
+ "tokenizer_class": "LlamaTokenizer",
41
+ "unk_token": "<unk>",
42
+ "use_default_system_prompt": false
43
+ }
vision_encoder.py ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2024 Rhymes AI. All rights reserved.
2
+ #
3
+ # Licensed to the Apache Software Foundation (ASF) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The ASF licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+
20
+ """PyTorch Aria vision transformer."""
21
+
22
+ from typing import Optional, Tuple, Union
23
+
24
+ import torch
25
+ import torch.utils.checkpoint
26
+ from transformers import SiglipVisionConfig, SiglipVisionModel
27
+ from transformers.modeling_outputs import BaseModelOutputWithPooling
28
+ from transformers.models.idefics2.modeling_idefics2 import Idefics2VisionTransformer
29
+
30
+
31
+ class AriaVisionConfig(SiglipVisionConfig):
32
+ """Configuration class for AriaVisionModel."""
33
+
34
+ model_type = "aria_vision_model"
35
+
36
+ def __init__(
37
+ self,
38
+ **kwargs,
39
+ ):
40
+ super().__init__(**kwargs)
41
+ self._attn_implementation = "flash_attention_2"
42
+
43
+
44
+ class IdentityOp(torch.nn.Module):
45
+ """
46
+ An identity operation that returns the input unchanged.
47
+
48
+ This can be used as a placeholder or to maintain architectural consistency
49
+ when a specific operation is not needed.
50
+ """
51
+
52
+ def __init__(self, *args, **kwargs):
53
+ super().__init__()
54
+
55
+ def forward(self, x, *args, **kwargs):
56
+ return x
57
+
58
+
59
+ class AriaVisionTransformer(Idefics2VisionTransformer):
60
+ """
61
+ Aria Vision Transformer model based on Idefics2VisionTransformer.
62
+
63
+ This class extends the original Idefics2VisionTransformer by removing the post-layernorm operation.
64
+ """
65
+
66
+ def __init__(self, config: AriaVisionConfig):
67
+ super().__init__(config)
68
+ self.post_layernorm = IdentityOp()
69
+
70
+
71
+ class AriaVisionModel(SiglipVisionModel):
72
+ """
73
+ Aria Vision Model extends SiglipVisionModel to support pixel_mask.
74
+
75
+ The pixel_mask is a 2D boolean tensor that indicates which pixels in the input
76
+ image are actual content and which are padding. It has the same height and width
77
+ as the input image, where:
78
+ - True (1) values represent pixels from the original image
79
+ - False (0) values represent padding pixels
80
+
81
+ This mask helps the model focus on the relevant parts of the image during processing.
82
+ """
83
+
84
+ config_class = AriaVisionConfig
85
+ main_input_name = "pixel_values"
86
+
87
+ def __init__(self, config: AriaVisionConfig):
88
+ super().__init__(config)
89
+ self.vision_model = AriaVisionTransformer(config)
90
+
91
+ # Initialize weights and apply final processing
92
+ self.post_init()
93
+
94
+ def forward(
95
+ self,
96
+ pixel_values: torch.Tensor,
97
+ pixel_mask: Optional[torch.BoolTensor] = None,
98
+ output_attentions: Optional[bool] = None,
99
+ output_hidden_states: Optional[bool] = None,
100
+ return_dict: Optional[bool] = None,
101
+ ) -> Union[Tuple, BaseModelOutputWithPooling]:
102
+ """
103
+ Forward pass of the AriaVisionModel.
104
+
105
+ Args:
106
+ pixel_values (torch.Tensor): The pixel values of the input images.
107
+ pixel_mask (Optional[torch.BoolTensor]): Mask for the pixel values.
108
+ output_attentions (Optional[bool]): Whether to output attentions.
109
+ output_hidden_states (Optional[bool]): Whether to output hidden states.
110
+ return_dict (Optional[bool]): Whether to return a ModelOutput object.
111
+
112
+ Returns:
113
+ Union[Tuple, BaseModelOutputWithPooling]: The model's output.
114
+ """
115
+ return_dict = (
116
+ return_dict if return_dict is not None else self.config.use_return_dict
117
+ )
118
+ patch_attention_mask = self._create_patch_attention_mask(pixel_mask)
119
+
120
+ vit_oup = self.vision_model(
121
+ pixel_values=pixel_values,
122
+ patch_attention_mask=patch_attention_mask,
123
+ output_attentions=output_attentions,
124
+ output_hidden_states=output_hidden_states,
125
+ return_dict=return_dict,
126
+ )
127
+
128
+ image_atts = self._create_image_attention_mask(patch_attention_mask)
129
+
130
+ return vit_oup, image_atts
131
+
132
+ def _create_patch_attention_mask(self, pixel_mask):
133
+ if pixel_mask is None:
134
+ return None
135
+
136
+ patches_subgrid = pixel_mask.unfold(
137
+ dimension=1,
138
+ size=self.vision_model.config.patch_size,
139
+ step=self.vision_model.config.patch_size,
140
+ ).unfold(
141
+ dimension=2,
142
+ size=self.vision_model.config.patch_size,
143
+ step=self.vision_model.config.patch_size,
144
+ )
145
+ return (patches_subgrid.sum(dim=(-1, -2)) > 0).bool()
146
+
147
+ def _create_image_attention_mask(self, patch_attention_mask):
148
+ if patch_attention_mask is None:
149
+ return None
150
+
151
+ flattened_mask = patch_attention_mask.flatten(1)
152
+ return torch.logical_not(flattened_mask)
vision_processor.py ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2024 Rhymes AI. All rights reserved.
2
+ #
3
+ # Licensed to the Apache Software Foundation (ASF) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The ASF licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+
20
+ from typing import List, Optional, Union
21
+
22
+ import torch
23
+ from PIL import Image, ImageOps
24
+ from torchvision import transforms
25
+ from transformers import BaseImageProcessor, BatchFeature, TensorType
26
+
27
+
28
+ def keep_ratio_resize_and_pixel_mask(
29
+ img: Image.Image, max_size, min_size=336, padding_value=0
30
+ ):
31
+ """
32
+ Resize an image while maintaining aspect ratio and create a pixel mask.
33
+
34
+ Args:
35
+ img (PIL.Image): Input image.
36
+ max_size (int): Maximum size for the larger dimension of the image.
37
+ min_size (int, optional): Minimum size for the smaller dimension. Defaults to 336.
38
+ padding_value (int, optional): Value used for padding. Defaults to 0.
39
+
40
+ Returns:
41
+ tuple: A tuple containing:
42
+ - PIL.Image: Resized and padded image.
43
+ - torch.Tensor: Boolean pixel mask. This mask is a 2D tensor of shape (max_size, max_size) where:
44
+ - True (1) values indicate pixels that belong to the original resized image.
45
+ - False (0) values indicate pixels that are part of the padding.
46
+ The mask helps distinguish between actual image content and padded areas in subsequent processing steps.
47
+ """
48
+ img = img.convert("RGB")
49
+ # rescale the given image, keep the aspect ratio
50
+ scale = max_size / max(img.size)
51
+
52
+ w, h = img.size
53
+ if w >= h:
54
+ new_size = (max_size, max(int(h * scale), min_size)) # w, h
55
+ else:
56
+ new_size = (max(int(w * scale), min_size), max_size) # w, h
57
+
58
+ img_resized = img.resize(new_size, resample=Image.Resampling.BICUBIC)
59
+
60
+ # padding the right/bottom
61
+ padding_right, padding_bottom = max_size - new_size[0], max_size - new_size[1]
62
+ img_padded = ImageOps.expand(
63
+ img_resized, (0, 0, padding_right, padding_bottom), fill=padding_value
64
+ )
65
+
66
+ # Create a pixel mask
67
+ pixel_mask = torch.zeros(max_size, max_size)
68
+ pixel_mask[: new_size[1], : new_size[0]] = 1
69
+ pixel_mask = pixel_mask.bool()
70
+ return img_padded, pixel_mask
71
+
72
+
73
+ class AriaVisionProcessor(BaseImageProcessor):
74
+ """
75
+ A vision processor for the Aria model that handles image preprocessing.
76
+ """
77
+
78
+ def __init__(
79
+ self,
80
+ max_image_size=980,
81
+ min_image_size=336,
82
+ image_mean=[0.5, 0.5, 0.5],
83
+ image_std=[0.5, 0.5, 0.5],
84
+ **kwargs,
85
+ ):
86
+ """
87
+ Initialize the AriaVisionProcessor.
88
+
89
+ Args:
90
+ max_image_size (int, optional): Maximum image size. Defaults to 980.
91
+ min_image_size (int, optional): Minimum image size. Defaults to 336.
92
+ mean (list, optional): Mean values for normalization. Defaults to [0.5, 0.5, 0.5].
93
+ std (list, optional): Standard deviation values for normalization. Defaults to [0.5, 0.5, 0.5].
94
+ """
95
+ super().__init__(**kwargs)
96
+
97
+ self.max_image_size = max_image_size
98
+ self.min_image_size = min_image_size
99
+ self.image_mean = image_mean
100
+ self.image_std = image_std
101
+ self.auto_map = {
102
+ "AutoProcessor": "processing_aria.AriaProcessor",
103
+ "AutoImageProcessor": "vision_processor.AriaVisionProcessor",
104
+ }
105
+
106
+ # we make the transform a property so that it is lazily initialized,
107
+ # this could avoid the error "TypeError: Object of type Normalize is not JSON serializable"
108
+ # when we used save_pretrained or from_pretrained.
109
+ self._transform = None
110
+ self._set_processor_class("AriaProcessor")
111
+
112
+ @property
113
+ def transform(self):
114
+ if self._transform is None:
115
+ # Recreate the transform when accessed
116
+ self._transform = transforms.Compose(
117
+ [
118
+ transforms.ToTensor(),
119
+ transforms.Normalize(self.image_mean, self.image_std),
120
+ ]
121
+ )
122
+ return self._transform
123
+
124
+ def __call__(
125
+ self,
126
+ images: Union[Image.Image, List[Image.Image]],
127
+ max_image_size: Optional[int] = 980,
128
+ min_image_size: Optional[int] = 336,
129
+ return_tensors: Optional[Union[str, TensorType]] = "pt",
130
+ ):
131
+ """
132
+ Process a list of images.
133
+
134
+ Args:
135
+ images (list): List of PIL.Image objects.
136
+ max_image_size (int, optional): Override the default max image size. Defaults to None.
137
+ return_tensors (str or TensorType, optional): The type of tensor to return. Defaults to "pt".
138
+ Returns:
139
+ BatchFeature: A BatchFeature object containing:
140
+ - 'pixel_values': Tensor of processed image pixel values.
141
+ - 'pixel_mask': Boolean pixel mask. This mask is a 2D tensor of shape (max_size, max_size) where:
142
+ - True (1) values indicate pixels that belong to the original resized image.
143
+ - False (0) values indicate pixels that are part of the padding.
144
+ The mask helps distinguish between actual image content and padded areas in subsequent processing steps.
145
+ """
146
+ max_size = self.max_image_size if max_image_size is None else max_image_size
147
+ min_size = self.min_image_size if min_image_size is None else min_image_size
148
+
149
+ if max_size not in [490, 980]:
150
+ raise ValueError("max_image_size must be either 490 or 980")
151
+
152
+ if isinstance(images, Image.Image):
153
+ images = [images]
154
+
155
+ pixel_values = []
156
+ pixel_masks = []
157
+
158
+ for image in images:
159
+ img_padded, pixel_mask = keep_ratio_resize_and_pixel_mask(
160
+ image, max_size, min_size
161
+ )
162
+ img_padded = self.transform(img_padded)
163
+ pixel_values.append(img_padded)
164
+ pixel_masks.append(pixel_mask)
165
+
166
+ return BatchFeature(
167
+ data={
168
+ "pixel_values": torch.stack(pixel_values),
169
+ "pixel_mask": torch.stack(pixel_masks),
170
+ },
171
+ tensor_type=return_tensors,
172
+ )
173
+
174
+ def preprocess(
175
+ self,
176
+ images,
177
+ max_image_size=None,
178
+ min_image_size=None,
179
+ return_tensors: Optional[Union[str, TensorType]] = None,
180
+ ):
181
+ return self.__call__(
182
+ images,
183
+ max_image_size=max_image_size,
184
+ min_image_size=min_image_size,
185
+ return_tensors=return_tensors,
186
+ )