teowu commited on
Commit
e9c5390
1 Parent(s): 3ce9f48

Upload folder using huggingface_hub

Browse files
config.json ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "_attn_implementation": "flash_attention_2",
34
+ "vision_config": {
35
+ "_flash_attn_2_enabled": true,
36
+ "_attn_implementation": "flash_attention_2",
37
+ "architectures": [
38
+ "AriaVisionModel"
39
+ ],
40
+ "hidden_size": 1152,
41
+ "image_size": 980,
42
+ "intermediate_size": 4304,
43
+ "model_type": "aria_vision_model",
44
+ "num_attention_heads": 16,
45
+ "num_hidden_layers": 27,
46
+ "patch_size": 14,
47
+ "torch_dtype": "bfloat16"
48
+ }
49
+ }
configuration_aria.py ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
22
+ from transformers.configuration_utils import PretrainedConfig
23
+
24
+ from .moe_lm import AriaMoELMConfig
25
+ from .vision_encoder import AriaVisionConfig
26
+
27
+ logger = logging.getLogger(__name__)
28
+
29
+
30
+ # adapted from transformers.models.llava.configuration_llava.LlavaConfig
31
+ class AriaConfig(PretrainedConfig):
32
+ """
33
+ Configuration class for Aria model.
34
+
35
+ This class handles the configuration for both vision and text components of the Aria model,
36
+ as well as additional parameters for image token handling and projector mapping.
37
+
38
+ Args:
39
+ vision_config (AriaVisionConfig or dict): Configuration for the vision component.
40
+ text_config (AriaMoELMConfig or dict): Configuration for the text component.
41
+ projector_patch_to_query_dict (dict): Mapping of patch sizes to query dimensions.
42
+ ignore_index (int): Index to ignore in loss calculation.
43
+ image_token_index (int): Index used to represent image tokens.
44
+ **kwargs: Additional keyword arguments passed to the parent class.
45
+
46
+ Attributes:
47
+ model_type (str): Type of the model, set to "aria".
48
+ is_composition (bool): Whether the model is a composition of multiple components.
49
+ ignore_index (int): Index to ignore in loss calculation.
50
+ image_token_index (int): Index used to represent image tokens.
51
+ projector_patch_to_query_dict (dict): Mapping of patch sizes to query dimensions.
52
+ vision_config (AriaVisionConfig): Configuration for the vision component.
53
+ text_config (AriaMoELMConfig): Configuration for the text component.
54
+ """
55
+
56
+ model_type = "aria"
57
+ is_composition = False
58
+
59
+ def __init__(
60
+ self,
61
+ vision_config=AriaVisionConfig(),
62
+ text_config=AriaMoELMConfig(),
63
+ projector_patch_to_query_dict={
64
+ 1225: 128,
65
+ 4900: 256,
66
+ },
67
+ ignore_index=-100,
68
+ image_token_index=32000,
69
+ tie_word_embeddings=False,
70
+ **kwargs,
71
+ ):
72
+ super().__init__(**kwargs)
73
+ self.ignore_index = ignore_index
74
+ self.image_token_index = image_token_index
75
+ self.tie_word_embeddings = tie_word_embeddings
76
+ attn_implementation = kwargs.pop("attn_implementation", None)
77
+
78
+ # Set the default attention implementation to flash_attention_2 if not specified
79
+ self._attn_implementation = (
80
+ "flash_attention_2" if attn_implementation is None else attn_implementation
81
+ )
82
+
83
+ # Convert the keys and values of projector_patch_to_query_dict to integers
84
+ # This ensures consistency even if they were provided as strings
85
+ self.projector_patch_to_query_dict = {
86
+ int(k): int(v) for k, v in projector_patch_to_query_dict.items()
87
+ }
88
+
89
+ if isinstance(vision_config, dict) and "model_type" in vision_config:
90
+ vision_config = AriaVisionConfig(**vision_config)
91
+ if attn_implementation is None:
92
+ vision_attn_implementation = "flash_attention_2"
93
+ elif attn_implementation == "sdpa":
94
+ logger.warning(
95
+ "SDPA is not supported for vit, using flash_attention_2 instead"
96
+ )
97
+ vision_attn_implementation = "flash_attention_2"
98
+ else:
99
+ vision_attn_implementation = attn_implementation
100
+ vision_config._attn_implementation = vision_attn_implementation
101
+
102
+ self.vision_config = vision_config
103
+
104
+ if isinstance(text_config, dict) and "model_type" in text_config:
105
+ text_attn_implementation = (
106
+ "sdpa" if attn_implementation is None else attn_implementation
107
+ )
108
+ text_config = AriaMoELMConfig(**text_config)
109
+ text_config._attn_implementation = text_attn_implementation
110
+
111
+ self.text_config = text_config
112
+
113
+ # This is needed for the static kv cache
114
+ self.num_hidden_layers = self.text_config.num_hidden_layers
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:60b373aec7648973696bf09f1be8efabee81d70cadd54054cb8d5cfc7b9ef353
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:e28ea6899bee9fb55c3d684dd3c5138343dbcc3112b67a7bebc4f121a69cb83e
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:74d1a04c14400e55c3350de920dba71b762eefa8c0894631e7e79e3dd7041aef
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:fe416e790b16039c1dc4db6ef84b9e43146da1fd8a21137ed20a1e52fdbae75f
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:65f15b84f52d16e686c11a92a0034b83de889a1d82c87bd3873587845a933bb2
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:915eff7120204b9366c9404c5a7d5280f02f1b855f7afe90b17f5b0de52c558e
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:262115131343776b9dd919bf4955f444900301e0c7fdd4751d6ec2fd713713cd
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:9da5c8b02a7a0774a35b4b71c17d9b4bcfb1b1b8e74e4b176f958a2d5300a9bb
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:0a616cb997f240d1fd12b2d5da4f8560f868c0e9e7209202d16496d4c9616c02
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:af6548e72103d7b208c639a892249593c7dcbe71280b51dee15e6fce5548ece6
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:8e06b62376377fa6f5fc479b3d463af45c6053d99c8ba485711a8ef369f375f0
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:d43c7bbf7a74516d5dcb8aa62b096409c7ade75a88c4d96ab963c512942e52b0
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,365 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 GenerationMixin, PreTrainedModel
27
+ from transformers.modeling_outputs import ModelOutput
28
+ from transformers.utils import logging
29
+
30
+ from .configuration_aria import AriaConfig
31
+ from .moe_lm import AriaMoELMForCausalLM
32
+ from .projector import AriaProjector
33
+ from .vision_encoder import AriaVisionModel
34
+
35
+ logger = logging.get_logger(__name__)
36
+
37
+
38
+ class AriaPretrainedModel(PreTrainedModel):
39
+ """
40
+ An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained models.
41
+ """
42
+
43
+ config_class = AriaConfig
44
+ base_model_prefix = "model"
45
+ _no_split_modules = []
46
+ supports_gradient_checkpointing = True
47
+ _skip_keys_device_placement = "past_key_values"
48
+ _supports_flash_attn_2 = True
49
+ _supports_cache_class = True
50
+ _supports_static_cache = 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, GenerationMixin):
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 get_output_embeddings(self):
169
+ """Retrieve the output embeddings from the language model."""
170
+ return self.language_model.get_output_embeddings()
171
+
172
+ def set_output_embeddings(self, value):
173
+ """Set the output embeddings for the language model."""
174
+ self.language_model.set_output_embeddings(value)
175
+
176
+ def set_moe_z_loss_coeff(self, value):
177
+ """
178
+ Set the z-loss coefficient for Mixture of Experts (MoE) models.
179
+
180
+ Args:
181
+ value: The z-loss coefficient value to set.
182
+ """
183
+ self.language_model.set_z_loss_coeff(value)
184
+
185
+ def set_moe_aux_loss_coeff(self, value):
186
+ """
187
+ Set the auxiliary loss coefficient for Mixture of Experts (MoE) models.
188
+
189
+ Args:
190
+ value: The auxiliary loss coefficient value to set.
191
+ """
192
+ self.language_model.set_aux_loss_coeff(value)
193
+
194
+ def forward(
195
+ self,
196
+ input_ids: torch.LongTensor = None,
197
+ pixel_values: torch.FloatTensor = None,
198
+ pixel_mask: torch.LongTensor = None,
199
+ attention_mask: Optional[torch.Tensor] = None,
200
+ position_ids: Optional[torch.LongTensor] = None,
201
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
202
+ inputs_embeds: Optional[torch.FloatTensor] = None,
203
+ labels: Optional[torch.LongTensor] = None,
204
+ use_cache: Optional[bool] = None,
205
+ output_attentions: Optional[bool] = None,
206
+ output_hidden_states: Optional[bool] = None,
207
+ return_dict: Optional[bool] = None,
208
+ cache_position: Optional[torch.LongTensor] = None,
209
+ num_logits_to_keep: int = 0,
210
+ ) -> Union[Tuple, AriaCausalLMOutputWithPast]:
211
+ """
212
+ Forward pass of the AriaForConditionalGeneration model.
213
+
214
+ This method processes both text and image inputs, merges them if necessary,
215
+ and generates output using the language model.
216
+
217
+ Args:
218
+ input_ids (torch.LongTensor, optional): Input token ids.
219
+ pixel_values (torch.FloatTensor, optional): Pixel values of the images.
220
+ pixel_mask (torch.LongTensor, optional): Mask for the pixel values.
221
+ attention_mask (torch.Tensor, optional): Attention mask.
222
+ position_ids (torch.LongTensor, optional): Position ids.
223
+ past_key_values (List[torch.FloatTensor], optional): Past key values for efficient processing.
224
+ inputs_embeds (torch.FloatTensor, optional): Input embeddings.
225
+ labels (torch.LongTensor, optional): Labels for computing the language modeling loss.
226
+ use_cache (bool, optional): Whether to use the model's cache mechanism.
227
+ output_attentions (bool, optional): Whether to output attention weights.
228
+ output_hidden_states (bool, optional): Whether to output hidden states.
229
+ return_dict (bool, optional): Whether to return a ModelOutput object.
230
+
231
+ Returns:
232
+ Union[Tuple, AriaCausalLMOutputWithPast]: Model outputs.
233
+ """
234
+ output_attentions = (
235
+ output_attentions
236
+ if output_attentions is not None
237
+ else self.config.output_attentions
238
+ )
239
+ output_hidden_states = (
240
+ output_hidden_states
241
+ if output_hidden_states is not None
242
+ else self.config.output_hidden_states
243
+ )
244
+ return_dict = (
245
+ return_dict if return_dict is not None else self.config.use_return_dict
246
+ )
247
+
248
+ if inputs_embeds is None:
249
+ # 1. Extra the input embeddings
250
+ inputs_embeds = self.get_input_embeddings()(input_ids)
251
+
252
+ image_features = None
253
+ if pixel_values is not None:
254
+ image_outputs, image_attn_mask = self.vision_tower(
255
+ pixel_values,
256
+ pixel_mask=pixel_mask,
257
+ )
258
+
259
+ selected_image_feature = image_outputs.last_hidden_state
260
+ image_features = self.multi_modal_projector(
261
+ selected_image_feature, attn_mask=image_attn_mask
262
+ )
263
+
264
+ if image_features is not None:
265
+ n_image_tokens = (input_ids == self.config.image_token_index).sum().item()
266
+ n_image_features = image_features.shape[0] * image_features.shape[1]
267
+
268
+ if n_image_tokens != n_image_features:
269
+ raise ValueError(
270
+ f"Image features and image tokens do not match: tokens: {n_image_tokens}, features {n_image_features}"
271
+ )
272
+ special_image_mask = (
273
+ (input_ids == self.config.image_token_index)
274
+ .unsqueeze(-1)
275
+ .expand_as(inputs_embeds)
276
+ .to(inputs_embeds.device)
277
+ )
278
+ image_features = image_features.to(
279
+ inputs_embeds.device, inputs_embeds.dtype
280
+ )
281
+ inputs_embeds = inputs_embeds.masked_scatter(
282
+ special_image_mask, image_features
283
+ )
284
+
285
+ outputs = self.language_model(
286
+ attention_mask=attention_mask,
287
+ position_ids=position_ids,
288
+ past_key_values=past_key_values,
289
+ inputs_embeds=inputs_embeds,
290
+ use_cache=use_cache,
291
+ output_attentions=output_attentions,
292
+ output_hidden_states=output_hidden_states,
293
+ return_dict=return_dict,
294
+ cache_position=cache_position,
295
+ num_logits_to_keep=num_logits_to_keep,
296
+ )
297
+
298
+ logits = outputs[0]
299
+
300
+ loss = None
301
+ if labels is not None:
302
+ # Shift so that tokens < n predict n
303
+ if attention_mask is not None:
304
+ # we use the input attention mask to shift the logits and labels, because it is 2D.
305
+ # we also crop attn mask in case it is longer, which happens in PrefixTuning with peft
306
+ shift_attention_mask = attention_mask[:, -(logits.shape[1] - 1) :].to(
307
+ logits.device
308
+ )
309
+ shift_logits = logits[..., :-1, :][
310
+ shift_attention_mask.to(logits.device) != 0
311
+ ].contiguous()
312
+ shift_labels = labels[..., 1:][
313
+ shift_attention_mask.to(labels.device) != 0
314
+ ].contiguous()
315
+ else:
316
+ shift_logits = logits[..., :-1, :].contiguous()
317
+ shift_labels = labels[..., 1:].contiguous()
318
+ # Flatten the tokens
319
+ loss_fct = nn.CrossEntropyLoss()
320
+ loss = loss_fct(
321
+ shift_logits.view(-1, shift_logits.size(-1)),
322
+ shift_labels.view(-1).to(shift_logits.device),
323
+ )
324
+
325
+ if not return_dict:
326
+ output = (logits,) + outputs[1:]
327
+ return (loss,) + output if loss is not None else output
328
+
329
+ return AriaCausalLMOutputWithPast(
330
+ loss=loss,
331
+ logits=logits,
332
+ past_key_values=outputs.past_key_values,
333
+ hidden_states=outputs.hidden_states,
334
+ attentions=outputs.attentions,
335
+ )
336
+
337
+ def prepare_inputs_for_generation(
338
+ self,
339
+ input_ids,
340
+ past_key_values=None,
341
+ inputs_embeds=None,
342
+ pixel_values=None,
343
+ pixel_mask=None,
344
+ attention_mask=None,
345
+ cache_position=None,
346
+ num_logits_to_keep=None,
347
+ **kwargs,
348
+ ):
349
+ model_inputs = self.language_model.prepare_inputs_for_generation(
350
+ input_ids,
351
+ past_key_values=past_key_values,
352
+ inputs_embeds=inputs_embeds,
353
+ attention_mask=attention_mask,
354
+ cache_position=cache_position,
355
+ num_logits_to_keep=num_logits_to_keep,
356
+ **kwargs,
357
+ )
358
+
359
+ if cache_position[0] == 0:
360
+ # If we're in cached decoding stage, pixel values should be None because input ids do not contain special image token anymore
361
+ # Otherwise we need pixel values to be passed to model
362
+ model_inputs["pixel_values"] = pixel_values
363
+ model_inputs["pixel_mask"] = pixel_mask
364
+
365
+ return model_inputs
moe_lm.py ADDED
@@ -0,0 +1,679 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 GenerationMixin, 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 balancing.
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
+ if self.training:
259
+ logits = self.apply_z_loss(logits)
260
+
261
+ top_logits, top_indices = torch.topk(logits, k=self.config.moe_topk, dim=1)
262
+ scores = torch.softmax(top_logits, dim=-1, dtype=torch.float32).type_as(logits)
263
+
264
+ tokens_per_expert = torch.histc(
265
+ top_indices.flatten(),
266
+ bins=self.config.moe_num_experts,
267
+ min=0,
268
+ max=self.config.moe_num_experts - 1,
269
+ )
270
+
271
+ if self.training:
272
+ scores = self.apply_aux_loss(logits, tokens_per_expert, scores)
273
+ return scores, top_indices, tokens_per_expert
274
+
275
+ def forward(
276
+ self, input: torch.Tensor
277
+ ) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
278
+ """
279
+ Forward pass of the TopKRouter.
280
+
281
+ Args:
282
+ input (torch.Tensor): Input tensor of shape [batch_size * seq_len, hidden_size].
283
+
284
+ Returns:
285
+ Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
286
+ - scores: Softmax probabilities for top-k experts.
287
+ - top_indices: Indices of top-k experts for each token.
288
+ - tokens_per_expert: Number of tokens assigned to each expert.
289
+ """
290
+ logits = self.gating(input)
291
+ logits = logits.view(-1, self.config.moe_num_experts)
292
+ scores, top_indices, tokens_per_expert = self.routing(logits)
293
+ return scores, top_indices, tokens_per_expert
294
+
295
+
296
+ # adapted from https://github.com/NVIDIA/Megatron-LM/blob/54f1f78529cbc2b9cddad313e7f9d96ac0420a27/megatron/core/transformer/moe/token_dispatcher.py#L291-L587
297
+ class TokenDispatcher:
298
+ """
299
+ Handles the dispatching and gathering of tokens to and from experts.
300
+
301
+ This class is responsible for permuting tokens based on expert assignments and
302
+ unpermuting them after expert processing.
303
+
304
+ Args:
305
+ config (AriaMoELMConfig): Configuration object containing MoE-related parameters.
306
+ """
307
+
308
+ def __init__(self, config: AriaMoELMConfig):
309
+ self.config = config
310
+ self.hidden_states_shape = None
311
+ self.reversed_input_permutation_mapping = None
312
+
313
+ def token_permutation(
314
+ self, hidden_states: torch.Tensor, indices: torch.Tensor
315
+ ) -> torch.Tensor:
316
+ """
317
+ Permute tokens based on expert assignments.
318
+
319
+ Args:
320
+ hidden_states (torch.Tensor): Input hidden states.
321
+ indices (torch.Tensor): Expert assignment indices.
322
+
323
+ Returns:
324
+ torch.Tensor: Permuted tokens.
325
+ """
326
+ self.hidden_states_shape = hidden_states.shape
327
+ hidden_states = hidden_states.view(-1, hidden_states.size(-1))
328
+ flatten_indices = indices.flatten()
329
+ sorted_indices = torch.argsort(flatten_indices, stable=True)
330
+ permuted_tokens = hidden_states.index_select(
331
+ 0, sorted_indices // self.config.moe_topk
332
+ )
333
+ self.reversed_input_permutation_mapping = sorted_indices
334
+ return permuted_tokens
335
+
336
+ def token_unpermutation(
337
+ self, permuted_tokens: torch.Tensor, scores: torch.Tensor
338
+ ) -> torch.Tensor:
339
+ """
340
+ Unpermute tokens and combine expert outputs.
341
+
342
+ Args:
343
+ permuted_tokens (torch.Tensor): Tokens after expert processing.
344
+ scores (torch.Tensor): Expert assignment scores.
345
+
346
+ Returns:
347
+ torch.Tensor: Unpermuted and combined output.
348
+ """
349
+ num_unpermuted_tokens = scores.numel()
350
+ unpermuted_tokens = torch.zeros(
351
+ (num_unpermuted_tokens, permuted_tokens.size(1)),
352
+ dtype=permuted_tokens.dtype,
353
+ device=permuted_tokens.device,
354
+ )
355
+ unpermuted_tokens.index_copy_(
356
+ 0, self.reversed_input_permutation_mapping, permuted_tokens
357
+ )
358
+ unpermuted_tokens = unpermuted_tokens.reshape(
359
+ -1, self.config.moe_topk, permuted_tokens.size(1)
360
+ )
361
+
362
+ unpermuted_tokens = unpermuted_tokens * scores.unsqueeze(-1)
363
+ unpermuted_tokens = unpermuted_tokens.sum(dim=1).type_as(permuted_tokens)
364
+ output = unpermuted_tokens.view(self.hidden_states_shape)
365
+ return output
366
+
367
+
368
+ class SharedExpertMLP(LlamaMLP):
369
+ """
370
+ Shared Expert MLP for shared experts.
371
+
372
+ Unlike routed experts, shared experts process all tokens without routing.
373
+ This class reconfigures the intermediate size in comparison to the LlamaMLP.
374
+
375
+ Args:
376
+ config (AriaMoELMConfig): Configuration object for the AriaMoE language model.
377
+ """
378
+
379
+ def __init__(self, config: AriaMoELMConfig):
380
+ nn.Module.__init__(self)
381
+ self.config = config
382
+ self.hidden_size = config.hidden_size
383
+ self.intermediate_size = (
384
+ config.moe_intermediate_size * config.moe_num_shared_experts
385
+ )
386
+ self.gate_proj = nn.Linear(
387
+ self.hidden_size, self.intermediate_size, bias=config.mlp_bias
388
+ )
389
+ self.up_proj = nn.Linear(
390
+ self.hidden_size, self.intermediate_size, bias=config.mlp_bias
391
+ )
392
+ self.down_proj = nn.Linear(
393
+ self.intermediate_size, self.hidden_size, bias=config.mlp_bias
394
+ )
395
+ self.act_fn = ACT2FN[config.hidden_act]
396
+
397
+
398
+ def sequential_gemm(input, weight, tokens_per_expert):
399
+ """
400
+ Compute the matrix multiplication (GEMM) for each expert sequentially. This approach is computationally inefficient, especially when dealing with a large number of experts.
401
+
402
+ Args:
403
+ input (torch.Tensor): Input tensor of shape (num_tokens, in_features).
404
+ weight (torch.Tensor): Weight tensor of shape (num_experts, in_features, out_features).
405
+ tokens_per_expert (torch.Tensor): Number of tokens assigned to each expert.
406
+
407
+ Returns:
408
+ torch.Tensor: Output tensor of shape (num_tokens, out_features).
409
+ """
410
+ num_tokens = input.shape[0]
411
+ out_features = weight.shape[-1]
412
+ output = torch.zeros(
413
+ num_tokens, out_features, dtype=input.dtype, device=input.device
414
+ )
415
+
416
+ cumsum_num_tokens = torch.cumsum(tokens_per_expert, dim=0)
417
+ # Insert zero at the begining for offset index's convenience
418
+ zero_tensor = torch.zeros(1, dtype=torch.long, device=cumsum_num_tokens.device)
419
+ cumsum_num_tokens = torch.cat((zero_tensor, cumsum_num_tokens))
420
+
421
+ for expert_num in range(weight.shape[0]):
422
+ start = cumsum_num_tokens[expert_num]
423
+ end = cumsum_num_tokens[expert_num + 1]
424
+ tokens = input[start:end]
425
+
426
+ out = torch.matmul(tokens, weight[expert_num])
427
+ output[start:end] = out
428
+ return output
429
+
430
+
431
+ try:
432
+ from grouped_gemm.ops import gmm as experts_gemm
433
+
434
+ if os.environ.get("USE_GROUPED_GEMM", "1") == "0":
435
+ logger.warning(
436
+ "environment variable USE_GROUPED_GEMM is set to 0, using sequential GEMM instead."
437
+ )
438
+ experts_gemm = sequential_gemm
439
+ except ImportError:
440
+ logger.warning(
441
+ "`grouped_gemm` is not installed, using sequential GEMM, which is slower."
442
+ )
443
+ experts_gemm = sequential_gemm
444
+
445
+
446
+ class GroupedGEMM(nn.Module):
447
+ """
448
+ Grouped GEMM (General Matrix Multiplication) module for efficient expert computation.
449
+ This module utilizes the grouped_gemm library (https://github.com/fanshiqing/grouped_gemm)
450
+ for optimized performance. If the grouped_gemm library is not installed, it gracefully
451
+ falls back to a sequential GEMM implementation, which may be slower but ensures
452
+ functionality.
453
+
454
+ Args:
455
+ in_features (int): Number of input features.
456
+ out_features (int): Number of output features.
457
+ groups (int): Number of expert groups.
458
+ """
459
+
460
+ def __init__(self, in_features, out_features, groups):
461
+ super().__init__()
462
+ self.in_features = in_features
463
+ self.out_features = out_features
464
+ self.groups = groups
465
+ self.weight = nn.Parameter(torch.empty(groups, in_features, out_features))
466
+
467
+ def forward(self, input, tokens_per_expert):
468
+ """
469
+ Perform grouped matrix multiplication.
470
+
471
+ Args:
472
+ input (torch.Tensor): Input tensor of shape (num_tokens, in_features).
473
+ tokens_per_expert (torch.Tensor): Number of tokens assigned to each expert.
474
+
475
+ Returns:
476
+ torch.Tensor: Output tensor of shape (num_tokens, out_features).
477
+ """
478
+ tokens_per_expert = tokens_per_expert.cpu()
479
+
480
+ # Ensure the CUDA device matches the input tensor's device.
481
+ # This mismatch can occur when using `transformers.AutoModel.from_pretrained`
482
+ # with `device_map="auto"` on a multi-GPU setup.
483
+ torch.cuda.set_device(input.device)
484
+ return experts_gemm(input, self.weight, tokens_per_expert)
485
+
486
+
487
+ class GroupedMLP(nn.Module):
488
+ """
489
+ Grouped MLP module for Mixture of Experts.
490
+
491
+ Args:
492
+ config (AriaMoELMConfig): Configuration object for the model.
493
+ """
494
+
495
+ def __init__(self, config: AriaMoELMConfig) -> None:
496
+ super().__init__()
497
+ self.config = config
498
+ self.fc1 = GroupedGEMM(
499
+ config.hidden_size, config.moe_intermediate_size * 2, config.moe_num_experts
500
+ )
501
+ self.fc2 = GroupedGEMM(
502
+ config.moe_intermediate_size, config.hidden_size, config.moe_num_experts
503
+ )
504
+
505
+ def glu(x):
506
+ x = torch.chunk(x, 2, dim=-1)
507
+ return F.silu(x[0]) * x[1]
508
+
509
+ self.activation_func = glu
510
+
511
+ def forward(self, permuted_tokens, tokens_per_expert):
512
+ """
513
+ Forward pass of the Grouped MLP.
514
+
515
+ Args:
516
+ permuted_tokens (torch.Tensor): Permuted input tokens.
517
+ tokens_per_expert (torch.Tensor): Number of tokens assigned to each expert.
518
+
519
+ Returns:
520
+ torch.Tensor: Output tensor after passing through the MLP.
521
+ """
522
+ fc1_output = self.fc1(permuted_tokens, tokens_per_expert)
523
+ fc1_output = self.activation_func(fc1_output)
524
+ fc2_output = self.fc2(fc1_output, tokens_per_expert)
525
+ return fc2_output
526
+
527
+
528
+ class MoELayer(nn.Module):
529
+ """
530
+ Mixture of Experts (MoE) Layer for the AriaMoE model.
531
+
532
+ This layer implements the MoE mechanism, which routes input tokens to different experts
533
+ based on a routing algorithm, processes them through the experts, and then combines
534
+ the outputs.
535
+
536
+ Args:
537
+ config (AriaMoELMConfig): Configuration object for the MoE layer.
538
+ """
539
+
540
+ def __init__(self, config: AriaMoELMConfig):
541
+ super().__init__()
542
+
543
+ self.router = TopKRouter(config)
544
+ self.token_dispatcher = TokenDispatcher(config)
545
+ self.experts = GroupedMLP(config)
546
+ self.shared_experts = SharedExpertMLP(config)
547
+
548
+ def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
549
+ """
550
+ Forward pass of the MoE Layer.
551
+
552
+ Args:
553
+ hidden_states (torch.Tensor): Input tensor of shape (batch_size, sequence_length, hidden_size).
554
+
555
+ Returns:
556
+ torch.Tensor: Output tensor after passing through the MoE layer.
557
+
558
+ Process:
559
+ 1. Route tokens to experts using the router.
560
+ 2. Permute tokens based on routing decisions.
561
+ 3. Process tokens through experts.
562
+ 4. Unpermute and combine expert outputs.
563
+ 5. Add shared expert output to the final result.
564
+ """
565
+ scores, indices, tokens_per_expert = self.router(hidden_states)
566
+
567
+ permuted_tokens = self.token_dispatcher.token_permutation(
568
+ hidden_states, indices
569
+ )
570
+
571
+ expert_output = self.experts(permuted_tokens, tokens_per_expert)
572
+
573
+ output = self.token_dispatcher.token_unpermutation(expert_output, scores)
574
+
575
+ shared_expert_output = self.shared_experts(hidden_states)
576
+ output += shared_expert_output
577
+ return output
578
+
579
+
580
+ class MoEDecoderLayer(LlamaDecoderLayer):
581
+ """
582
+ Custom Decoder Layer for the AriaMoE model which modifies the standard `LlamaDecoderLayer` by
583
+ replacing the traditional MLP with a Mixture of Experts (MoE) Layer.
584
+
585
+ Args:
586
+ config (LlamaConfig): Configuration object for the layer.
587
+ layer_idx (int): Index of the current layer in the model.
588
+ """
589
+
590
+ def __init__(self, config: LlamaConfig, layer_idx: int):
591
+ nn.Module.__init__(self)
592
+ self.hidden_size = config.hidden_size
593
+
594
+ self.self_attn = LLAMA_ATTENTION_CLASSES[config._attn_implementation](
595
+ config=config, layer_idx=layer_idx
596
+ )
597
+
598
+ self.mlp = MoELayer(config)
599
+ self.input_layernorm = LlamaRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
600
+ self.post_attention_layernorm = LlamaRMSNorm(
601
+ config.hidden_size, eps=config.rms_norm_eps
602
+ )
603
+
604
+
605
+ class AriaMoELMModel(LlamaModel):
606
+ """
607
+ Custom LlamaModel for the AriaMoE model which modifies the standard LlamaModel by
608
+ replacing the `LlamaDecoderLayer` with `MoEDecoderLayer`.
609
+
610
+ This model implements a Mixture of Experts (MoE) approach, where each layer contains
611
+ multiple expert networks that specialize in different aspects of the input.
612
+
613
+ Args:
614
+ config (LlamaConfig): Configuration object for the model.
615
+ """
616
+
617
+ def __init__(self, config: LlamaConfig):
618
+ super().__init__(config)
619
+ self.padding_idx = config.pad_token_id
620
+ self.vocab_size = config.vocab_size
621
+
622
+ self.embed_tokens = nn.Embedding(
623
+ config.vocab_size, config.hidden_size, self.padding_idx
624
+ )
625
+ self.layers = nn.ModuleList(
626
+ [
627
+ MoEDecoderLayer(config, layer_idx)
628
+ for layer_idx in range(config.num_hidden_layers)
629
+ ]
630
+ )
631
+ self.norm = LlamaRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
632
+ self.rotary_emb = LlamaRotaryEmbedding(config=config)
633
+ self.gradient_checkpointing = False
634
+
635
+ # Initialize weights and apply final processing
636
+ self.post_init()
637
+
638
+
639
+ class AriaMoELMForCausalLM(LlamaForCausalLM, GenerationMixin):
640
+ """
641
+ AriaMoE model for causal language modeling tasks.
642
+
643
+ This class extends LlamaForCausalLM to incorporate the Mixture of Experts (MoE) approach,
644
+ allowing for more efficient and scalable language modeling.
645
+
646
+ Args:
647
+ config (AriaMoELMConfig): Configuration object for the model.
648
+ """
649
+
650
+ _tied_weights_keys = ["lm_head.weight"]
651
+ config_class = AriaMoELMConfig
652
+ _no_split_modules = ["MoEDecoderLayer"]
653
+
654
+ def __init__(self, config):
655
+ super().__init__(config)
656
+ self.model = AriaMoELMModel(config)
657
+ self.vocab_size = config.vocab_size
658
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
659
+
660
+ # Initialize weights and apply final processing
661
+ self.post_init()
662
+
663
+ def set_z_loss_coeff(self, z_loss_coeff: float):
664
+ """
665
+ Set the coefficient for the z-loss in the MoE routing.
666
+
667
+ Args:
668
+ z_loss_coeff (float): The coefficient for the z-loss.
669
+ """
670
+ self.config.moe_z_loss_coeff = z_loss_coeff
671
+
672
+ def set_aux_loss_coeff(self, aux_loss_coeff: float):
673
+ """
674
+ Set the coefficient for the auxiliary loss in the MoE routing.
675
+
676
+ Args:
677
+ aux_loss_coeff (float): The coefficient for the auxiliary loss.
678
+ """
679
+ 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,305 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ import logging
22
+ import re
23
+ from typing import List, Optional, Union
24
+
25
+ from transformers import AutoTokenizer, BatchFeature
26
+ from transformers.image_utils import ImageInput
27
+ from transformers.processing_utils import ProcessorMixin
28
+ from transformers.tokenization_utils import (
29
+ PaddingStrategy,
30
+ PreTokenizedInput,
31
+ TensorType,
32
+ TextInput,
33
+ TruncationStrategy,
34
+ )
35
+
36
+ from .vision_processor import AriaVisionProcessor
37
+
38
+ logger = logging.getLogger(__name__)
39
+
40
+
41
+ class AriaProcessor(ProcessorMixin):
42
+ """
43
+ AriaProcessor is a processor for the Aria model which wraps the Aria image preprocessor and the LLama slow tokenizer.
44
+ Args:
45
+ image_processor(AriaVisionProcessor): The AriaVisionProcessor to use for image preprocessing.
46
+ tokenizer(AutoTokenizer): The AutoTokenizer to use for tokenizing the text.
47
+ patch_size(int): The patch size to use for the image processor.
48
+ chat_template(str): The chat template to use for the tokenizer.
49
+ image_token(str): The image token to use for the tokenizer.
50
+ """
51
+
52
+ attributes = []
53
+ valid_kwargs = ["chat_template", "patch_size", "image_token"]
54
+ image_processor_class = None
55
+ tokenizer_class = "AutoTokenizer"
56
+
57
+ def __init__(
58
+ self,
59
+ image_processor: AriaVisionProcessor = None,
60
+ tokenizer: Union[AutoTokenizer, str] = None,
61
+ patch_size: int = 490,
62
+ chat_template: str = None,
63
+ image_token: str = "<|img|>",
64
+ ):
65
+ super().__init__(chat_template=chat_template)
66
+
67
+ if image_processor is None:
68
+ self.image_processor = AriaVisionProcessor(max_image_size=patch_size)
69
+ else:
70
+ self.image_processor = image_processor
71
+
72
+ if isinstance(tokenizer, str):
73
+ self.tokenizer = AutoTokenizer.from_pretrained(
74
+ tokenizer, trust_remote_code=True, use_fast=False
75
+ )
76
+ else:
77
+ self.tokenizer = tokenizer
78
+
79
+ if self.tokenizer is not None and self.tokenizer.pad_token is None:
80
+ self.tokenizer.pad_token = self.tokenizer.unk_token
81
+
82
+ self.image_token = image_token
83
+
84
+ # Copied from transformers.models.llava_next.processing_llave_next.LlavaNextProcessor.__call__
85
+ def __call__(
86
+ self,
87
+ text: Union[
88
+ TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]
89
+ ],
90
+ images: ImageInput = None,
91
+ padding: Union[bool, str, PaddingStrategy] = False,
92
+ truncation: Union[bool, str, TruncationStrategy] = None,
93
+ max_length: Optional[int] = None,
94
+ max_image_size: Optional[int] = 980,
95
+ split_image: Optional[bool] = False,
96
+ return_tensors: Optional[Union[str, TensorType]] = TensorType.PYTORCH,
97
+ return_final_prompts: Optional[bool] = False,
98
+ ) -> BatchFeature:
99
+ """
100
+ Main method to prepare for the model one or several sequences(s) and image(s). Please refer to the doctsring
101
+ of the above two methods for more information.
102
+
103
+ Args:
104
+ text (`str`, `List[str]`, `List[List[str]]`):
105
+ The sequence or batch of sequences to be encoded. Each sequence can be a string or a list of strings
106
+ (pretokenized string). If the sequences are provided as list of strings (pretokenized), you must set
107
+ `is_split_into_words=True` (to lift the ambiguity with a batch of sequences).
108
+ images (`PIL.Image.Image`, `np.ndarray`, `torch.Tensor`, `List[PIL.Image.Image]`, `List[np.ndarray]`, `List[torch.Tensor]`):
109
+ The image or batch of images to be prepared. Each image can be a PIL image, NumPy array or PyTorch
110
+ tensor. Both channels-first and channels-last formats are supported.
111
+ padding (`bool`, `str` or [`~utils.PaddingStrategy`], *optional*, defaults to `False`):
112
+ Select a strategy to pad the returned sequences (according to the model's padding side and padding
113
+ index) among:
114
+ - `True` or `'longest'`: Pad to the longest sequence in the batch (or no padding if only a single
115
+ sequence if provided).
116
+ - `'max_length'`: Pad to a maximum length specified with the argument `max_length` or to the maximum
117
+ acceptable input length for the model if that argument is not provided.
118
+ - `False` or `'do_not_pad'` (default): No padding (i.e., can output a batch with sequences of different
119
+ lengths).
120
+ max_length (`int`, *optional*):
121
+ Maximum length of the returned list and optionally padding length (see above).
122
+ max_image_size (`int`, *optional*):
123
+ Maximum size of the image to be processed.
124
+ split_image (`bool`, *optional*):
125
+ Whether to split the image into patches before processing.
126
+ truncation (`bool`, *optional*):
127
+ Activates truncation to cut input sequences longer than `max_length` to `max_length`.
128
+ return_tensors (`str` or [`~utils.TensorType`], *optional*):
129
+ If set, will return tensors of a particular framework. Acceptable values are:
130
+
131
+ - `'tf'`: Return TensorFlow `tf.constant` objects.
132
+ - `'pt'`: Return PyTorch `torch.Tensor` objects.
133
+ - `'np'`: Return NumPy `np.ndarray` objects.
134
+ - `'jax'`: Return JAX `jnp.ndarray` objects.
135
+
136
+ Returns:
137
+ [`BatchFeature`]: A [`BatchFeature`] with the following fields:
138
+
139
+ - **input_ids** -- List of token ids to be fed to a model. Returned when `text` is not `None`.
140
+ - **attention_mask** -- List of indices specifying which tokens should be attended to by the model (when
141
+ `return_attention_mask=True` or if *"attention_mask"* is in `self.model_input_names` and if `text` is not
142
+ `None`).
143
+ - **pixel_values** -- Pixel values to be fed to a model. Returned when `images` is not `None`.
144
+ - **pixel_mask** -- Pixel mask to be fed to a model. Returned when `images` is not `None`.
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
+ if images is not None:
154
+ image_inputs = self.image_processor(
155
+ images,
156
+ return_tensors=return_tensors,
157
+ max_image_size=max_image_size,
158
+ split_image=split_image,
159
+ )
160
+ # expand the image_token according to the num_crops of image
161
+ prompt_strings = []
162
+ crop_iter = iter(image_inputs.pop("num_crops"))
163
+ for prompt in text:
164
+ prompt_strings.append(
165
+ re.sub(
166
+ re.escape(self.image_token),
167
+ lambda _: next(crop_iter) * self.image_token,
168
+ prompt,
169
+ )
170
+ )
171
+
172
+ max_image_size = (
173
+ max_image_size
174
+ if max_image_size is not None
175
+ else self.image_processor.max_image_size
176
+ )
177
+ if max_image_size == 490:
178
+ num_image_tokens = 128
179
+ elif max_image_size == 980:
180
+ num_image_tokens = 256
181
+ else:
182
+ raise ValueError(
183
+ f"max_image_size must be either 490 or 980, got {max_image_size}"
184
+ )
185
+ prompt_strings = [
186
+ sample.replace(self.image_token, self.image_token * num_image_tokens)
187
+ for sample in prompt_strings
188
+ ]
189
+
190
+ else:
191
+ image_inputs = {}
192
+ prompt_strings = text
193
+
194
+ text_inputs = self.tokenizer(
195
+ prompt_strings,
196
+ return_tensors=return_tensors,
197
+ padding=padding,
198
+ truncation=truncation,
199
+ max_length=max_length,
200
+ )
201
+
202
+ if return_final_prompts:
203
+ return BatchFeature(data={**text_inputs, **image_inputs}), prompt_strings
204
+ else:
205
+ return BatchFeature(data={**text_inputs, **image_inputs})
206
+
207
+ @staticmethod
208
+ def _extract_kwargs(func: callable, **kwargs) -> dict:
209
+ """
210
+ Extract the kwargs that are valid for the given function.
211
+ """
212
+ return {
213
+ k: v for k, v in kwargs.items() if k in inspect.signature(func).parameters
214
+ }
215
+
216
+ def save_pretrained(self, save_directory, **kwargs):
217
+ """
218
+ Save both the image processor and tokenizer.
219
+ """
220
+ if self.image_processor is not None:
221
+ self.image_processor.save_pretrained(
222
+ save_directory,
223
+ **self._extract_kwargs(self.image_processor.save_pretrained, **kwargs),
224
+ )
225
+ if self.tokenizer is not None:
226
+ self.tokenizer.save_pretrained(
227
+ save_directory,
228
+ **self._extract_kwargs(self.tokenizer.save_pretrained, **kwargs),
229
+ )
230
+
231
+ @classmethod
232
+ def from_pretrained(
233
+ cls,
234
+ pretrained_model_name_or_path,
235
+ tokenizer_path=None,
236
+ image_processor_path=None,
237
+ **kwargs,
238
+ ):
239
+ """
240
+ Load both the image processor and tokenizer from a pretrained model path.
241
+ """
242
+ tokenizer_path = (
243
+ tokenizer_path
244
+ if tokenizer_path is not None
245
+ else pretrained_model_name_or_path
246
+ )
247
+ image_processor_path = (
248
+ image_processor_path
249
+ if image_processor_path is not None
250
+ else pretrained_model_name_or_path
251
+ )
252
+ image_processor = AriaVisionProcessor.from_pretrained(
253
+ image_processor_path,
254
+ **cls._extract_kwargs(AriaVisionProcessor.from_pretrained, **kwargs),
255
+ )
256
+ if "use_fast" in kwargs:
257
+ logger.warning("use_fast is not supported for AriaProcessor. Ignoring...")
258
+ kwargs.pop("use_fast")
259
+ try:
260
+ tokenizer = AutoTokenizer.from_pretrained(
261
+ tokenizer_path,
262
+ use_fast=False,
263
+ **cls._extract_kwargs(AutoTokenizer.from_pretrained, **kwargs),
264
+ )
265
+ chat_template = tokenizer.chat_template
266
+ except Exception as e:
267
+ logger.warning(f"Failed to load tokenizer from {tokenizer_path}: {e}")
268
+ tokenizer = None
269
+ chat_template = None
270
+ return cls(
271
+ image_processor=image_processor,
272
+ tokenizer=tokenizer,
273
+ chat_template=chat_template,
274
+ )
275
+
276
+ # Copied from transformers.models.clip.processing_clip.CLIPProcessor.batch_decode with CLIP->Llama
277
+ def batch_decode(self, *args, **kwargs):
278
+ """
279
+ This method forwards all its arguments to LlamaTokenizerFast's [`~PreTrainedTokenizer.batch_decode`]. Please
280
+ refer to the docstring of this method for more information.
281
+ """
282
+ if self.tokenizer is None:
283
+ raise ValueError(
284
+ "Tokenizer is not initialized. Please provide a valid tokenizer."
285
+ )
286
+ return self.tokenizer.batch_decode(*args, **kwargs)
287
+
288
+ # Copied from transformers.models.clip.processing_clip.CLIPProcessor.decode with CLIP->Llama
289
+ def decode(self, *args, **kwargs):
290
+ """
291
+ This method forwards all its arguments to LlamaTokenizerFast's [`~PreTrainedTokenizer.decode`]. Please refer to
292
+ the docstring of this method for more information.
293
+ """
294
+ if self.tokenizer is None:
295
+ raise ValueError(
296
+ "Tokenizer is not initialized. Please provide a valid tokenizer."
297
+ )
298
+ return self.tokenizer.decode(*args, **kwargs)
299
+
300
+ @property
301
+ # Copied from transformers.models.clip.processing_clip.CLIPProcessor.model_input_names
302
+ def model_input_names(self):
303
+ tokenizer_input_names = self.tokenizer.model_input_names
304
+ image_processor_input_names = self.image_processor.model_input_names
305
+ 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,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "unk_token": {
3
+ "content": "<unk>",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ }
9
+ }
tokenizer_config.json ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ },
15
+ "bos_token": null,
16
+ "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 %}",
17
+ "clean_up_tokenization_spaces": false,
18
+ "eos_token": null,
19
+ "legacy": true,
20
+ "model_max_length": 1000000000000000019884624838656,
21
+ "pad_token": null,
22
+ "sp_model_kwargs": {},
23
+ "spaces_between_special_tokens": false,
24
+ "tokenizer_class": "LlamaTokenizer",
25
+ "unk_token": "<unk>",
26
+ "use_default_system_prompt": false
27
+ }
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
+
42
+
43
+ class IdentityOp(torch.nn.Module):
44
+ """
45
+ An identity operation that returns the input unchanged.
46
+
47
+ This can be used as a placeholder or to maintain architectural consistency
48
+ when a specific operation is not needed.
49
+ """
50
+
51
+ def __init__(self, *args, **kwargs):
52
+ super().__init__()
53
+
54
+ def forward(self, x, *args, **kwargs):
55
+ return x
56
+
57
+
58
+ class AriaVisionTransformer(Idefics2VisionTransformer):
59
+ """
60
+ Aria Vision Transformer model based on Idefics2VisionTransformer.
61
+
62
+ This class extends the original Idefics2VisionTransformer by removing the post-layernorm operation.
63
+ """
64
+
65
+ def __init__(self, config: AriaVisionConfig):
66
+ super().__init__(config)
67
+ self.post_layernorm = IdentityOp()
68
+
69
+
70
+ class AriaVisionModel(SiglipVisionModel):
71
+ """
72
+ Aria Vision Model extends SiglipVisionModel to support pixel_mask.
73
+
74
+ The pixel_mask is a 2D boolean tensor that indicates which pixels in the input
75
+ image are actual content and which are padding. It has the same height and width
76
+ as the input image, where:
77
+ - True (1) values represent pixels from the original image
78
+ - False (0) values represent padding pixels
79
+
80
+ This mask helps the model focus on the relevant parts of the image during processing.
81
+ """
82
+
83
+ config_class = AriaVisionConfig
84
+ main_input_name = "pixel_values"
85
+ _supports_sdpa = False
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,321 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 numpy as np
23
+ import torch
24
+ from PIL import Image, ImageOps
25
+ from torchvision import transforms
26
+ from transformers import BaseImageProcessor, BatchFeature, TensorType
27
+
28
+
29
+ def _select_best_resolution(
30
+ img_width: int, img_height: int, target_ratios: List[List[int]], patch_size: int
31
+ ):
32
+ """
33
+ Selects the best resolution from a list of possible resolutions based on the original size.
34
+
35
+ Args:
36
+ img_width: the original widths of images.
37
+ img_height: the original heights of images.
38
+ target_ratios (2d numpy array): dimension size (M,2)
39
+ patch_size (int): image patch size
40
+
41
+ Returns:
42
+ tuple: The best fit resolution in the format (width, height).
43
+ """
44
+
45
+ aspect_ratio = img_width / img_height
46
+ best_ratio_diff = float("inf")
47
+ best_ratio_w, best_ratio_h = 1, 1
48
+ area = np.int32(img_width) * np.int32(img_height)
49
+ for ratio in target_ratios:
50
+ target_aspect_ratio = ratio[0] / ratio[1]
51
+ ratio_diff = abs(aspect_ratio - target_aspect_ratio)
52
+ if ratio_diff < best_ratio_diff:
53
+ best_ratio_diff = ratio_diff
54
+ best_ratio_w, best_ratio_h = ratio[0], ratio[1]
55
+ elif (
56
+ ratio_diff == best_ratio_diff
57
+ and area > 0.5 * patch_size * patch_size * ratio[0] * ratio[1]
58
+ ):
59
+ best_ratio_w, best_ratio_h = ratio[0], ratio[1]
60
+
61
+ return best_ratio_w, best_ratio_h
62
+
63
+
64
+ def _split_image(
65
+ image: Image.Image,
66
+ split_image: bool,
67
+ split_ratio: List[List[int]],
68
+ patch_size: int,
69
+ ) -> List[Image.Image]:
70
+ """
71
+ Split image into multiple patches
72
+
73
+ Args:
74
+ image (PIL.Image): Input image.
75
+ split_image (bool): Whether to split the image into patches.
76
+ split_ratio (2d numpy array): dimension size (M,2)
77
+ patch_size (int): image patch size
78
+
79
+ Returns:
80
+ List[PIL.Image]: List of splitted images.
81
+ """
82
+ if split_image:
83
+ ratio_width, ratio_height = _select_best_resolution(
84
+ image.width, image.height, split_ratio, patch_size
85
+ )
86
+ resize_width = patch_size * ratio_width
87
+ resize_height = patch_size * ratio_height
88
+ blocks = ratio_width * ratio_height
89
+ resized_img = image.resize((resize_width, resize_height))
90
+ processed_images = []
91
+ for i in range(blocks):
92
+ box = (
93
+ (i % (resize_width // patch_size)) * patch_size,
94
+ (i // (resize_width // patch_size)) * patch_size,
95
+ ((i % (resize_width // patch_size)) + 1) * patch_size,
96
+ ((i // (resize_width // patch_size)) + 1) * patch_size,
97
+ )
98
+ # split the image
99
+ split_img = resized_img.crop(box)
100
+ processed_images.append(split_img)
101
+ assert len(processed_images) == blocks
102
+ if len(processed_images) != 1:
103
+ processed_images.insert(0, image)
104
+ return processed_images
105
+ else:
106
+ return [image]
107
+
108
+
109
+ def keep_ratio_resize_and_pixel_mask(
110
+ img: Image.Image, max_size, min_size=336, padding_value=0
111
+ ):
112
+ """
113
+ Resize an image while maintaining aspect ratio and create a pixel mask.
114
+
115
+ Args:
116
+ img (PIL.Image): Input image.
117
+ max_size (int): Maximum size for the larger dimension of the image.
118
+ min_size (int, optional): Minimum size for the smaller dimension. Defaults to 336.
119
+ padding_value (int, optional): Value used for padding. Defaults to 0.
120
+
121
+ Returns:
122
+ tuple: A tuple containing:
123
+ - PIL.Image: Resized and padded image.
124
+ - torch.Tensor: Boolean pixel mask. This mask is a 2D tensor of shape (max_size, max_size) where:
125
+ - True (1) values indicate pixels that belong to the original resized image.
126
+ - False (0) values indicate pixels that are part of the padding.
127
+ The mask helps distinguish between actual image content and padded areas in subsequent processing steps.
128
+ """
129
+ img = img.convert("RGB")
130
+ # rescale the given image, keep the aspect ratio
131
+ scale = max_size / max(img.size)
132
+
133
+ w, h = img.size
134
+ if w >= h:
135
+ new_size = (max_size, max(int(h * scale), min_size)) # w, h
136
+ else:
137
+ new_size = (max(int(w * scale), min_size), max_size) # w, h
138
+
139
+ img_resized = img.resize(new_size, resample=Image.Resampling.BICUBIC)
140
+
141
+ # padding the right/bottom
142
+ padding_right, padding_bottom = max_size - new_size[0], max_size - new_size[1]
143
+ img_padded = ImageOps.expand(
144
+ img_resized, (0, 0, padding_right, padding_bottom), fill=padding_value
145
+ )
146
+
147
+ # Create a pixel mask
148
+ pixel_mask = torch.zeros(max_size, max_size)
149
+ pixel_mask[: new_size[1], : new_size[0]] = 1
150
+ pixel_mask = pixel_mask.bool()
151
+ return img_padded, pixel_mask
152
+
153
+
154
+ class AriaVisionProcessor(BaseImageProcessor):
155
+ """
156
+ A vision processor for the Aria model that handles image preprocessing.
157
+ """
158
+
159
+ def __init__(
160
+ self,
161
+ max_image_size=980,
162
+ min_image_size=336,
163
+ image_mean=[0.5, 0.5, 0.5],
164
+ image_std=[0.5, 0.5, 0.5],
165
+ **kwargs,
166
+ ):
167
+ """
168
+ Initialize the AriaVisionProcessor.
169
+
170
+ Args:
171
+ max_image_size (int, optional): Maximum image size. Defaults to 980.
172
+ min_image_size (int, optional): Minimum image size. Defaults to 336.
173
+ mean (list, optional): Mean values for normalization. Defaults to [0.5, 0.5, 0.5].
174
+ std (list, optional): Standard deviation values for normalization. Defaults to [0.5, 0.5, 0.5].
175
+ """
176
+ super().__init__(**kwargs)
177
+
178
+ self.max_image_size = max_image_size
179
+ self.min_image_size = min_image_size
180
+ self.image_mean = image_mean
181
+ self.image_std = image_std
182
+ self.auto_map = {
183
+ "AutoProcessor": "processing_aria.AriaProcessor",
184
+ "AutoImageProcessor": "vision_processor.AriaVisionProcessor",
185
+ }
186
+
187
+ # we make the transform a property so that it is lazily initialized,
188
+ # this could avoid the error "TypeError: Object of type Normalize is not JSON serializable"
189
+ # when we used save_pretrained or from_pretrained.
190
+ self._transform = None
191
+ self._set_processor_class("AriaProcessor")
192
+
193
+ @property
194
+ def transform(self):
195
+ if self._transform is None:
196
+ # Recreate the transform when accessed
197
+ self._transform = transforms.Compose(
198
+ [
199
+ transforms.ToTensor(),
200
+ transforms.Normalize(self.image_mean, self.image_std),
201
+ ]
202
+ )
203
+ return self._transform
204
+
205
+ def __call__(
206
+ self,
207
+ images: Union[Image.Image, List[Image.Image]],
208
+ max_image_size: Optional[int] = 980,
209
+ min_image_size: Optional[int] = 336,
210
+ return_tensors: Optional[Union[str, TensorType]] = "pt",
211
+ split_image: Optional[bool] = False,
212
+ split_ratio: Optional[List[List[int]]] = [
213
+ [1, 2],
214
+ [1, 3],
215
+ [1, 4],
216
+ [1, 5],
217
+ [1, 6],
218
+ [1, 7],
219
+ [1, 8],
220
+ [2, 4],
221
+ [2, 3],
222
+ [2, 2],
223
+ [2, 1],
224
+ [3, 1],
225
+ [3, 2],
226
+ [4, 1],
227
+ [4, 2],
228
+ [5, 1],
229
+ [6, 1],
230
+ [7, 1],
231
+ [8, 1],
232
+ ],
233
+ ):
234
+ """
235
+ Process a list of images.
236
+
237
+ Args:
238
+ images (list): List of PIL.Image objects.
239
+ max_image_size (int, optional): Override the default max image size. Defaults to None.
240
+ return_tensors (str or TensorType, optional): The type of tensor to return. Defaults to "pt".
241
+ split_image (bool, optional): Whether to split the image. Defaults to False.
242
+ split_ratio (list, optional): The ratio for splitting the image. Defaults to a list of common split ratios.
243
+ Returns:
244
+ BatchFeature: A BatchFeature object containing:
245
+ - 'pixel_values': Tensor of processed image pixel values.
246
+ - 'pixel_mask': Boolean pixel mask. This mask is a 2D tensor of shape (max_size, max_size) where:
247
+ - True (1) values indicate pixels that belong to the original resized image.
248
+ - False (0) values indicate pixels that are part of the padding.
249
+ The mask helps distinguish between actual image content and padded areas in subsequent processing steps.
250
+ - 'num_crops': Tensor of the number of crops for each image.
251
+ """
252
+ max_size = self.max_image_size if max_image_size is None else max_image_size
253
+ min_size = self.min_image_size if min_image_size is None else min_image_size
254
+
255
+ if max_size not in [490, 980]:
256
+ raise ValueError("max_image_size must be either 490 or 980")
257
+
258
+ if isinstance(images, Image.Image):
259
+ images = [images]
260
+
261
+ pixel_values = []
262
+ pixel_masks = []
263
+ num_crops = []
264
+
265
+ for image in images:
266
+ crop_images = _split_image(image, split_image, split_ratio, max_size)
267
+ num_crops.append(torch.tensor(len(crop_images)))
268
+ for crop_image in crop_images:
269
+ img_padded, pixel_mask = keep_ratio_resize_and_pixel_mask(
270
+ crop_image, max_size, min_size
271
+ )
272
+ img_padded = self.transform(img_padded)
273
+ pixel_values.append(img_padded)
274
+ pixel_masks.append(pixel_mask)
275
+
276
+ return BatchFeature(
277
+ data={
278
+ "pixel_values": torch.stack(pixel_values),
279
+ "pixel_mask": torch.stack(pixel_masks),
280
+ "num_crops": torch.stack(num_crops),
281
+ },
282
+ tensor_type=return_tensors,
283
+ )
284
+
285
+ def preprocess(
286
+ self,
287
+ images,
288
+ max_image_size=None,
289
+ min_image_size=None,
290
+ return_tensors: Optional[Union[str, TensorType]] = None,
291
+ split_image: Optional[bool] = False,
292
+ split_ratio: Optional[List[List[int]]] = [
293
+ [1, 2],
294
+ [1, 3],
295
+ [1, 4],
296
+ [1, 5],
297
+ [1, 6],
298
+ [1, 7],
299
+ [1, 8],
300
+ [2, 4],
301
+ [2, 3],
302
+ [2, 2],
303
+ [2, 1],
304
+ [3, 1],
305
+ [3, 2],
306
+ [4, 1],
307
+ [4, 2],
308
+ [5, 1],
309
+ [6, 1],
310
+ [7, 1],
311
+ [8, 1],
312
+ ],
313
+ ):
314
+ return self.__call__(
315
+ images,
316
+ max_image_size=max_image_size,
317
+ min_image_size=min_image_size,
318
+ return_tensors=return_tensors,
319
+ split_image=split_image,
320
+ split_ratio=split_ratio,
321
+ )