Transformers
Safetensors
English
mc-llava
llava
phi
custom_code
Inference Endpoints
wilbown commited on
Commit
8b0fa0e
1 Parent(s): 8139d64

clone https://huggingface.co/visheratin/MC-LLaVA-3b

Browse files
README.md ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ datasets:
3
+ - liuhaotian/LLaVA-Pretrain
4
+ - liuhaotian/LLaVA-Instruct-150K
5
+ language:
6
+ - en
7
+ tags:
8
+ - llava
9
+ - phi
10
+ license: mit
11
+ library_name: transformers
12
+ widget:
13
+ - text: "What animal is it?"
14
+ src: "https://huggingface.co/datasets/mishig/sample_images/resolve/main/tiger.jpg"
15
+ - text: "Where is it?"
16
+ src: "https://huggingface.co/datasets/mishig/sample_images/resolve/main/palace.jpg"
17
+ ---
18
+
19
+ # Multi-crop LLaVA-3b
20
+
21
+ <a target="_blank" href="https://colab.research.google.com/drive/1W7JQrFXwFunAY1XvS31mwC7mrXBgGD_M">
22
+ <img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/>
23
+ </a>
24
+
25
+ ## Model details
26
+
27
+ Usually, in LLaVA models, we generate N embeddings for the image, which we then combine with text embeddings and send to the LLM. But what if instead of creating N tokens
28
+ for one image, we create K<<N tokens for M<N parts of the image (crops)? It would allow us to get visual information from small parts of the image and not inflate the
29
+ number of image "tokens" too much. I called this method multi-crop LLaVA (MC-LLaVA).
30
+
31
+ You can read more about the model in the [blog post](https://huggingface.co/blog/visheratin/vlm-resolution-curse).
32
+
33
+ MC-LLaVA-3b was fine-tuned from [Phi-2 merge](vince62s/phi-2-psy) using vision tower from
34
+ [SigLIP 400M](https://huggingface.co/google/siglip-so400m-patch14-384).
35
+
36
+ As Dolphin 2.6 Phi, LLaVA-3b uses ChatML prompt format:
37
+
38
+ ```
39
+ <|im_start|>user
40
+ {prompt}<|im_end|>
41
+ <|im_start|>assistant
42
+
43
+ ```
44
+
45
+ ## How to use
46
+
47
+ ```python
48
+ from transformers import AutoModel, AutoProcessor
49
+ import torch
50
+
51
+ model = AutoModel.from_pretrained("visheratin/MC-LLaVA-3b", torch_dtype=torch.float16, trust_remote_code=True).to("cuda")
52
+
53
+ processor = AutoProcessor.from_pretrained("visheratin/MC-LLaVA-3b", trust_remote_code=True)
54
+
55
+ with torch.inference_mode():
56
+ inputs = processor(prompt, [raw_image], model, max_crops=100, num_tokens=728)
57
+ output = model.generate(**inputs, max_new_tokens=200, use_cache=True, do_sample=False,
58
+ eos_token_id=processor.tokenizer.eos_token_id, pad_token_id=processor.tokenizer.eos_token_id)
59
+
60
+ result = processor.tokenizer.decode(output[0]).replace(prompt, "").replace("<|im_end|>", "")
61
+ print(result)
62
+ ```
63
+
64
+ ## Benchmarks
65
+
66
+ - TextVQA - 50.9%
67
+ - GQA - 59.5%
68
+ - VQAv2 - 76.72%
69
+ - VizWiz - 32.68%
70
+ - V*-bench - OCR - 56.66%, GPT4V-hard - 52.94%, direct attributes - 40.86%, relative position - 56.57%
71
+
72
+ ## Examples
73
+
74
+ <a target="_blank" href="https://colab.research.google.com/drive/1sXDvVl5s9fTcE0N2bQGOlXhnNlKEdeun">
75
+ <img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/>
76
+ </a>
77
+
78
+ ## License
79
+
80
+ The model is licensed under MIT license, but since the data used for model training is largely synthetic, you should also follow OpenAI and Google Gemini terms of service.
81
+ Which means don't create competitor models for them.
82
+
83
+ ## Acknowledgments
84
+
85
+ Thanks to [Lambda](https://lambdalabs.com/) for providing a machine to train the model.
86
+
87
+ Thanks to [ML Collective](https://mlcollective.org/) for continuous support and providing compute resources for testing the model.
added_tokens.json ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "\t\t": 50294,
3
+ "\t\t\t": 50293,
4
+ "\t\t\t\t": 50292,
5
+ "\t\t\t\t\t": 50291,
6
+ "\t\t\t\t\t\t": 50290,
7
+ "\t\t\t\t\t\t\t": 50289,
8
+ "\t\t\t\t\t\t\t\t": 50288,
9
+ "\t\t\t\t\t\t\t\t\t": 50287,
10
+ " ": 50286,
11
+ " ": 50285,
12
+ " ": 50284,
13
+ " ": 50283,
14
+ " ": 50282,
15
+ " ": 50281,
16
+ " ": 50280,
17
+ " ": 50279,
18
+ " ": 50278,
19
+ " ": 50277,
20
+ " ": 50276,
21
+ " ": 50275,
22
+ " ": 50274,
23
+ " ": 50273,
24
+ " ": 50272,
25
+ " ": 50271,
26
+ " ": 50270,
27
+ " ": 50269,
28
+ " ": 50268,
29
+ " ": 50267,
30
+ " ": 50266,
31
+ " ": 50265,
32
+ " ": 50264,
33
+ " ": 50263,
34
+ " ": 50262,
35
+ " ": 50261,
36
+ " ": 50260,
37
+ " ": 50259,
38
+ " ": 50258,
39
+ " ": 50257,
40
+ "<image>": 50297,
41
+ "<pad>": 50298,
42
+ "<|im_end|>": 50295,
43
+ "<|im_start|>": 50296
44
+ }
config.json ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "auto_map": {
3
+ "AutoConfig": "modeling_llava.LlavaConfig",
4
+ "AutoModel": "modeling_llava.LlavaForCausalLM",
5
+ "AutoModelForCausalLM": "modeling_llava.LlavaForCausalLM"
6
+ },
7
+ "model_type": "mc-llava",
8
+ "ignore_index": -100,
9
+ "image_token_index": 50297,
10
+ "projector_hidden_act": "gelu",
11
+ "projector_tokens_num": 1,
12
+ "text_config": {
13
+ "_name_or_path": "vince62s/phi-2-psy",
14
+ "add_cross_attention": false,
15
+ "architectures": [
16
+ "PhiForCausalLM"
17
+ ],
18
+ "attention_dropout": 0.0,
19
+ "auto_map": {
20
+ "AutoConfig": "vince62s/phi-2-psy--configuration_phi.PhiConfig",
21
+ "AutoModelForCausalLM": "vince62s/phi-2-psy--modeling_phi.PhiForCausalLM"
22
+ },
23
+ "bad_words_ids": null,
24
+ "begin_suppress_tokens": null,
25
+ "bos_token_id": null,
26
+ "chunk_size_feed_forward": 0,
27
+ "cross_attention_hidden_size": null,
28
+ "decoder_start_token_id": null,
29
+ "diversity_penalty": 0.0,
30
+ "do_sample": false,
31
+ "early_stopping": false,
32
+ "embd_pdrop": 0.0,
33
+ "encoder_no_repeat_ngram_size": 0,
34
+ "eos_token_id": null,
35
+ "exponential_decay_length_penalty": null,
36
+ "finetuning_task": null,
37
+ "forced_bos_token_id": null,
38
+ "forced_eos_token_id": null,
39
+ "hidden_act": "gelu_new",
40
+ "hidden_size": 2560,
41
+ "id2label": {
42
+ "0": "LABEL_0",
43
+ "1": "LABEL_1"
44
+ },
45
+ "initializer_range": 0.02,
46
+ "intermediate_size": 10240,
47
+ "is_decoder": false,
48
+ "is_encoder_decoder": false,
49
+ "label2id": {
50
+ "LABEL_0": 0,
51
+ "LABEL_1": 1
52
+ },
53
+ "layer_norm_eps": 1e-05,
54
+ "length_penalty": 1.0,
55
+ "max_length": 20,
56
+ "max_position_embeddings": 2048,
57
+ "min_length": 0,
58
+ "model_type": "phi",
59
+ "no_repeat_ngram_size": 0,
60
+ "num_attention_heads": 32,
61
+ "num_beam_groups": 1,
62
+ "num_beams": 1,
63
+ "num_hidden_layers": 32,
64
+ "num_key_value_heads": 32,
65
+ "num_return_sequences": 1,
66
+ "output_attentions": false,
67
+ "output_hidden_states": false,
68
+ "output_scores": false,
69
+ "pad_token_id": null,
70
+ "partial_rotary_factor": 0.4,
71
+ "prefix": null,
72
+ "problem_type": null,
73
+ "pruned_heads": {},
74
+ "qk_layernorm": false,
75
+ "remove_invalid_values": false,
76
+ "repetition_penalty": 1.0,
77
+ "resid_pdrop": 0.1,
78
+ "return_dict": true,
79
+ "return_dict_in_generate": false,
80
+ "rope_scaling": null,
81
+ "rope_theta": 10000.0,
82
+ "sep_token_id": null,
83
+ "suppress_tokens": null,
84
+ "task_specific_params": null,
85
+ "temperature": 1.0,
86
+ "tf_legacy_loss": false,
87
+ "tie_encoder_decoder": false,
88
+ "tie_word_embeddings": false,
89
+ "tokenizer_class": null,
90
+ "top_k": 50,
91
+ "top_p": 1.0,
92
+ "torch_dtype": "bfloat16",
93
+ "torchscript": false,
94
+ "typical_p": 1.0,
95
+ "use_bfloat16": false,
96
+ "use_cache": true,
97
+ "vocab_size": 51200
98
+ },
99
+ "torch_dtype": "bfloat16",
100
+ "transformers_version": "4.37.2",
101
+ "vision_config": {
102
+ "hidden_size": 1152,
103
+ "image_size": 384,
104
+ "intermediate_size": 4304,
105
+ "model_type": "siglip_vision_model",
106
+ "num_attention_heads": 16,
107
+ "num_hidden_layers": 27,
108
+ "patch_size": 14
109
+ },
110
+ "vision_embed_dim": 1152,
111
+ "vision_tower_name": "google/siglip-so400m-patch14-384",
112
+ "vocab_size": 51200
113
+ }
configuration_llava.py ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers.configuration_utils import PretrainedConfig
2
+ from transformers.utils import logging
3
+ from transformers import SiglipVisionConfig
4
+
5
+
6
+ logger = logging.get_logger(__name__)
7
+
8
+
9
+ class PhiConfig(PretrainedConfig):
10
+ model_type = "phi"
11
+ keys_to_ignore_at_inference = ["past_key_values"]
12
+
13
+ def __init__(
14
+ self,
15
+ vocab_size=51200,
16
+ hidden_size=2048,
17
+ intermediate_size=8192,
18
+ num_hidden_layers=24,
19
+ num_attention_heads=32,
20
+ num_key_value_heads=None,
21
+ resid_pdrop=0.0,
22
+ embd_pdrop=0.0,
23
+ attention_dropout=0.0,
24
+ hidden_act="gelu_new",
25
+ max_position_embeddings=2048,
26
+ initializer_range=0.02,
27
+ layer_norm_eps=1e-5,
28
+ use_cache=True,
29
+ tie_word_embeddings=False,
30
+ rope_theta=10000.0,
31
+ rope_scaling=None,
32
+ partial_rotary_factor=0.5,
33
+ qk_layernorm=False,
34
+ bos_token_id=1,
35
+ eos_token_id=2,
36
+ **kwargs,
37
+ ):
38
+ self.vocab_size = vocab_size
39
+ self.hidden_size = hidden_size
40
+ self.intermediate_size = intermediate_size
41
+ self.num_hidden_layers = num_hidden_layers
42
+ self.num_attention_heads = num_attention_heads
43
+
44
+ if num_key_value_heads is None:
45
+ num_key_value_heads = num_attention_heads
46
+
47
+ self.num_key_value_heads = num_key_value_heads
48
+ self.resid_pdrop = resid_pdrop
49
+ self.embd_pdrop = embd_pdrop
50
+ self.attention_dropout = attention_dropout
51
+ self.hidden_act = hidden_act
52
+ self.max_position_embeddings = max_position_embeddings
53
+ self.initializer_range = initializer_range
54
+ self.layer_norm_eps = layer_norm_eps
55
+ self.use_cache = use_cache
56
+ self.rope_theta = rope_theta
57
+ self.rope_scaling = rope_scaling
58
+ self.partial_rotary_factor = partial_rotary_factor
59
+ self.qk_layernorm = qk_layernorm
60
+ self._rope_scaling_validation()
61
+
62
+ super().__init__(
63
+ bos_token_id=bos_token_id,
64
+ eos_token_id=eos_token_id,
65
+ tie_word_embeddings=tie_word_embeddings,
66
+ **kwargs,
67
+ )
68
+
69
+ def _rope_scaling_validation(self):
70
+ """
71
+ Validate the `rope_scaling` configuration.
72
+ """
73
+ if self.rope_scaling is None:
74
+ return
75
+
76
+ if not isinstance(self.rope_scaling, dict) or len(self.rope_scaling) != 2:
77
+ raise ValueError(
78
+ "`rope_scaling` must be a dictionary with with two fields, `type` and `factor`, "
79
+ f"got {self.rope_scaling}"
80
+ )
81
+ rope_scaling_type = self.rope_scaling.get("type", None)
82
+ rope_scaling_factor = self.rope_scaling.get("factor", None)
83
+ if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic"]:
84
+ raise ValueError(
85
+ f"`rope_scaling`'s type field must be one of ['linear', 'dynamic'], got {rope_scaling_type}"
86
+ )
87
+ if (
88
+ rope_scaling_factor is None
89
+ or not isinstance(rope_scaling_factor, float)
90
+ or rope_scaling_factor <= 1.0
91
+ ):
92
+ raise ValueError(
93
+ f"`rope_scaling`'s factor field must be a float > 1, got {rope_scaling_factor}"
94
+ )
95
+
96
+
97
+ class LlavaConfig(PretrainedConfig):
98
+ model_type = "mc-llava"
99
+ is_composition = False
100
+
101
+ def __init__(
102
+ self,
103
+ text_config=None,
104
+ vision_config=None,
105
+ ignore_index=-100,
106
+ image_token_index=50297,
107
+ projector_hidden_act="gelu",
108
+ projector_tokens_num=1,
109
+ vocab_size=51200,
110
+ **kwargs,
111
+ ):
112
+ self.ignore_index = ignore_index
113
+ self.image_token_index = image_token_index
114
+ self.projector_hidden_act = projector_hidden_act
115
+ self.projector_tokens_num = projector_tokens_num
116
+ self.vocab_size = vocab_size
117
+
118
+ self.text_config = text_config
119
+ if isinstance(self.text_config, dict):
120
+ text_config["model_type"] = (
121
+ text_config["model_type"] if "model_type" in text_config else "phi"
122
+ )
123
+ self.text_config = PhiConfig(**text_config)
124
+ self.vocab_size = self.text_config.vocab_size
125
+
126
+ self.vision_config = vision_config
127
+ if isinstance(self.vision_config, dict):
128
+ self.vision_config = SiglipVisionConfig(**vision_config)
129
+ self.vision_embed_dim = self.vision_config.hidden_size
130
+
131
+ super().__init__(**kwargs)
configuration_phi.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Microsoft Corporation.
2
+ # Licensed under the MIT license.
3
+
4
+ import math
5
+ from typing import Optional
6
+
7
+ from transformers import PretrainedConfig
8
+
9
+
10
+ class PhiConfig(PretrainedConfig):
11
+ """Phi configuration."""
12
+
13
+ model_type = "phi-msft"
14
+ attribute_map = {
15
+ "max_position_embeddings": "n_positions",
16
+ "hidden_size": "n_embd",
17
+ "num_attention_heads": "n_head",
18
+ "num_hidden_layers": "n_layer",
19
+ }
20
+
21
+ def __init__(
22
+ self,
23
+ vocab_size: int = 51200,
24
+ n_positions: int = 2048,
25
+ n_embd: int = 1024,
26
+ n_layer: int = 20,
27
+ n_inner: Optional[int] = None,
28
+ n_head: int = 16,
29
+ n_head_kv: Optional[int] = None,
30
+ rotary_dim: Optional[int] = 32,
31
+ activation_function: Optional[str] = "gelu_new",
32
+ flash_attn: bool = False,
33
+ flash_rotary: bool = False,
34
+ fused_dense: bool = False,
35
+ attn_pdrop: float = 0.0,
36
+ embd_pdrop: float = 0.0,
37
+ resid_pdrop: float = 0.0,
38
+ layer_norm_epsilon: float = 1e-5,
39
+ initializer_range: float = 0.02,
40
+ tie_word_embeddings: bool = False,
41
+ pad_vocab_size_multiple: int = 64,
42
+ **kwargs
43
+ ) -> None:
44
+ self.vocab_size = int(math.ceil(vocab_size / pad_vocab_size_multiple) * pad_vocab_size_multiple)
45
+ self.n_positions = n_positions
46
+ self.n_embd = n_embd
47
+ self.n_layer = n_layer
48
+ self.n_inner = n_inner
49
+ self.n_head = n_head
50
+ self.n_head_kv = n_head_kv
51
+ self.rotary_dim = min(rotary_dim, n_embd // n_head)
52
+ self.activation_function = activation_function
53
+ self.flash_attn = flash_attn
54
+ self.flash_rotary = flash_rotary
55
+ self.fused_dense = fused_dense
56
+ self.attn_pdrop = attn_pdrop
57
+ self.embd_pdrop = embd_pdrop
58
+ self.resid_pdrop = resid_pdrop
59
+ self.layer_norm_epsilon = layer_norm_epsilon
60
+ self.initializer_range = initializer_range
61
+
62
+ super().__init__(tie_word_embeddings=tie_word_embeddings, **kwargs)
convert_model.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2023 The HuggingFace Inc. team. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ import argparse
15
+
16
+ import torch
17
+
18
+ from transformers import (
19
+ AddedToken,
20
+ AutoConfig,
21
+ AutoTokenizer,
22
+ )
23
+ from configuration_llava import LlavaConfig
24
+ from modeling_llava import LlavaForConditionalGeneration
25
+
26
+
27
+ KEYS_TO_MODIFY_MAPPING = {
28
+ "transformer.vision_tower.vision_tower": "vision_model",
29
+ "transformer.mm_projector": "multi_modal_projector",
30
+ "transformer": "language_model.transformer",
31
+ "lm_head": "language_model.lm_head",
32
+ "model.model": "language_model.transformer",
33
+ "multi_modal_projector.0": "multi_modal_projector.linear_1",
34
+ "multi_modal_projector.2": "multi_modal_projector.linear_2",
35
+ }
36
+
37
+
38
+ def convert_state_dict_to_hf(state_dict):
39
+ new_state_dict = {}
40
+ for key, value in state_dict.items():
41
+ for key_to_modify, new_key in KEYS_TO_MODIFY_MAPPING.items():
42
+ if key_to_modify in key:
43
+ key = key.replace(key_to_modify, new_key)
44
+
45
+ new_state_dict[key] = value
46
+ return new_state_dict
47
+
48
+
49
+ def convert_llava_llama_to_hf(text_model_id, vision_model_id, projector_tokens_num, output_path, old_state_dict_path):
50
+ torch.set_default_dtype(torch.float16)
51
+ text_config = AutoConfig.from_pretrained(text_model_id, trust_remote_code=True)
52
+
53
+ tokenizer = AutoTokenizer.from_pretrained(text_model_id)
54
+ tokenizer.add_tokens(AddedToken("<image>", special=True, normalized=False), special_tokens=True)
55
+ tokenizer.add_special_tokens({"pad_token": "<pad>"})
56
+
57
+ config = LlavaConfig(text_config=text_config, vocab_size=51200, vision_tower_name=vision_model_id, projector_tokens_num=projector_tokens_num)
58
+ config.text_config.vocab_size = config.vocab_size
59
+
60
+ with torch.device("cuda"):
61
+ model = LlavaForConditionalGeneration(config)
62
+
63
+ state_dict = torch.load(old_state_dict_path, map_location="cpu")
64
+ state_dict = convert_state_dict_to_hf(state_dict)
65
+ model.load_state_dict(state_dict, strict=True, assign=True)
66
+
67
+ model.config.vocab_size = model.config.vocab_size
68
+ model.config.text_config.vocab_size = model.config.text_config.vocab_size
69
+
70
+ model.save_pretrained(output_path)
71
+ tokenizer.save_pretrained(output_path)
72
+
73
+
74
+ def main():
75
+ parser = argparse.ArgumentParser()
76
+ parser.add_argument(
77
+ "--text_model_id",
78
+ help="Hub location of the text model",
79
+ )
80
+ parser.add_argument(
81
+ "--vision_model_id",
82
+ help="Hub location of the vision model",
83
+ )
84
+ parser.add_argument(
85
+ "--output_path",
86
+ help="Location of the converted model",
87
+ )
88
+ parser.add_argument(
89
+ "--old_state_dict_path",
90
+ help="Location on the hub of the raw state dict of the original model. The filename needs to be `model_state_dict.bin`",
91
+ )
92
+ parser.add_argument(
93
+ "--tokens_num",
94
+ type=int,
95
+ default=1
96
+ )
97
+ args = parser.parse_args()
98
+ convert_llava_llama_to_hf(args.text_model_id, args.vision_model_id, args.tokens_num, args.output_path, args.old_state_dict_path)
99
+
100
+
101
+ if __name__ == "__main__":
102
+ main()
generation_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "transformers_version": "4.37.2"
4
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model-00001-of-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0fa70d660b4f81b87cc3a93e89e8da38f6abf08dae6f51b2bef772f420799cec
3
+ size 4969060728
model-00002-of-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2e45b58c3bebb723eb7493f75356e75e090f0c62865e49a19e19ba73b80241a2
3
+ size 1468562584
model.safetensors.index.json ADDED
@@ -0,0 +1,916 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 6437497984
4
+ },
5
+ "weight_map": {
6
+ "language_model.lm_head.bias": "model-00002-of-00002.safetensors",
7
+ "language_model.lm_head.weight": "model-00002-of-00002.safetensors",
8
+ "language_model.model.embed_tokens.weight": "model-00001-of-00002.safetensors",
9
+ "language_model.model.final_layernorm.bias": "model-00002-of-00002.safetensors",
10
+ "language_model.model.final_layernorm.weight": "model-00002-of-00002.safetensors",
11
+ "language_model.model.layers.0.input_layernorm.bias": "model-00001-of-00002.safetensors",
12
+ "language_model.model.layers.0.input_layernorm.weight": "model-00001-of-00002.safetensors",
13
+ "language_model.model.layers.0.mlp.fc1.bias": "model-00001-of-00002.safetensors",
14
+ "language_model.model.layers.0.mlp.fc1.weight": "model-00001-of-00002.safetensors",
15
+ "language_model.model.layers.0.mlp.fc2.bias": "model-00001-of-00002.safetensors",
16
+ "language_model.model.layers.0.mlp.fc2.weight": "model-00001-of-00002.safetensors",
17
+ "language_model.model.layers.0.self_attn.dense.bias": "model-00001-of-00002.safetensors",
18
+ "language_model.model.layers.0.self_attn.dense.weight": "model-00001-of-00002.safetensors",
19
+ "language_model.model.layers.0.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
20
+ "language_model.model.layers.0.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
21
+ "language_model.model.layers.0.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
22
+ "language_model.model.layers.0.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
23
+ "language_model.model.layers.0.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
24
+ "language_model.model.layers.0.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
25
+ "language_model.model.layers.1.input_layernorm.bias": "model-00001-of-00002.safetensors",
26
+ "language_model.model.layers.1.input_layernorm.weight": "model-00001-of-00002.safetensors",
27
+ "language_model.model.layers.1.mlp.fc1.bias": "model-00001-of-00002.safetensors",
28
+ "language_model.model.layers.1.mlp.fc1.weight": "model-00001-of-00002.safetensors",
29
+ "language_model.model.layers.1.mlp.fc2.bias": "model-00001-of-00002.safetensors",
30
+ "language_model.model.layers.1.mlp.fc2.weight": "model-00001-of-00002.safetensors",
31
+ "language_model.model.layers.1.self_attn.dense.bias": "model-00001-of-00002.safetensors",
32
+ "language_model.model.layers.1.self_attn.dense.weight": "model-00001-of-00002.safetensors",
33
+ "language_model.model.layers.1.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
34
+ "language_model.model.layers.1.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
35
+ "language_model.model.layers.1.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
36
+ "language_model.model.layers.1.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
37
+ "language_model.model.layers.1.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
38
+ "language_model.model.layers.1.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
39
+ "language_model.model.layers.10.input_layernorm.bias": "model-00001-of-00002.safetensors",
40
+ "language_model.model.layers.10.input_layernorm.weight": "model-00001-of-00002.safetensors",
41
+ "language_model.model.layers.10.mlp.fc1.bias": "model-00001-of-00002.safetensors",
42
+ "language_model.model.layers.10.mlp.fc1.weight": "model-00001-of-00002.safetensors",
43
+ "language_model.model.layers.10.mlp.fc2.bias": "model-00001-of-00002.safetensors",
44
+ "language_model.model.layers.10.mlp.fc2.weight": "model-00001-of-00002.safetensors",
45
+ "language_model.model.layers.10.self_attn.dense.bias": "model-00001-of-00002.safetensors",
46
+ "language_model.model.layers.10.self_attn.dense.weight": "model-00001-of-00002.safetensors",
47
+ "language_model.model.layers.10.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
48
+ "language_model.model.layers.10.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
49
+ "language_model.model.layers.10.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
50
+ "language_model.model.layers.10.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
51
+ "language_model.model.layers.10.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
52
+ "language_model.model.layers.10.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
53
+ "language_model.model.layers.11.input_layernorm.bias": "model-00001-of-00002.safetensors",
54
+ "language_model.model.layers.11.input_layernorm.weight": "model-00001-of-00002.safetensors",
55
+ "language_model.model.layers.11.mlp.fc1.bias": "model-00001-of-00002.safetensors",
56
+ "language_model.model.layers.11.mlp.fc1.weight": "model-00001-of-00002.safetensors",
57
+ "language_model.model.layers.11.mlp.fc2.bias": "model-00001-of-00002.safetensors",
58
+ "language_model.model.layers.11.mlp.fc2.weight": "model-00001-of-00002.safetensors",
59
+ "language_model.model.layers.11.self_attn.dense.bias": "model-00001-of-00002.safetensors",
60
+ "language_model.model.layers.11.self_attn.dense.weight": "model-00001-of-00002.safetensors",
61
+ "language_model.model.layers.11.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
62
+ "language_model.model.layers.11.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
63
+ "language_model.model.layers.11.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
64
+ "language_model.model.layers.11.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
65
+ "language_model.model.layers.11.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
66
+ "language_model.model.layers.11.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
67
+ "language_model.model.layers.12.input_layernorm.bias": "model-00001-of-00002.safetensors",
68
+ "language_model.model.layers.12.input_layernorm.weight": "model-00001-of-00002.safetensors",
69
+ "language_model.model.layers.12.mlp.fc1.bias": "model-00001-of-00002.safetensors",
70
+ "language_model.model.layers.12.mlp.fc1.weight": "model-00001-of-00002.safetensors",
71
+ "language_model.model.layers.12.mlp.fc2.bias": "model-00001-of-00002.safetensors",
72
+ "language_model.model.layers.12.mlp.fc2.weight": "model-00001-of-00002.safetensors",
73
+ "language_model.model.layers.12.self_attn.dense.bias": "model-00001-of-00002.safetensors",
74
+ "language_model.model.layers.12.self_attn.dense.weight": "model-00001-of-00002.safetensors",
75
+ "language_model.model.layers.12.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
76
+ "language_model.model.layers.12.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
77
+ "language_model.model.layers.12.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
78
+ "language_model.model.layers.12.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
79
+ "language_model.model.layers.12.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
80
+ "language_model.model.layers.12.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
81
+ "language_model.model.layers.13.input_layernorm.bias": "model-00001-of-00002.safetensors",
82
+ "language_model.model.layers.13.input_layernorm.weight": "model-00001-of-00002.safetensors",
83
+ "language_model.model.layers.13.mlp.fc1.bias": "model-00001-of-00002.safetensors",
84
+ "language_model.model.layers.13.mlp.fc1.weight": "model-00001-of-00002.safetensors",
85
+ "language_model.model.layers.13.mlp.fc2.bias": "model-00001-of-00002.safetensors",
86
+ "language_model.model.layers.13.mlp.fc2.weight": "model-00001-of-00002.safetensors",
87
+ "language_model.model.layers.13.self_attn.dense.bias": "model-00001-of-00002.safetensors",
88
+ "language_model.model.layers.13.self_attn.dense.weight": "model-00001-of-00002.safetensors",
89
+ "language_model.model.layers.13.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
90
+ "language_model.model.layers.13.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
91
+ "language_model.model.layers.13.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
92
+ "language_model.model.layers.13.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
93
+ "language_model.model.layers.13.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
94
+ "language_model.model.layers.13.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
95
+ "language_model.model.layers.14.input_layernorm.bias": "model-00001-of-00002.safetensors",
96
+ "language_model.model.layers.14.input_layernorm.weight": "model-00001-of-00002.safetensors",
97
+ "language_model.model.layers.14.mlp.fc1.bias": "model-00001-of-00002.safetensors",
98
+ "language_model.model.layers.14.mlp.fc1.weight": "model-00001-of-00002.safetensors",
99
+ "language_model.model.layers.14.mlp.fc2.bias": "model-00001-of-00002.safetensors",
100
+ "language_model.model.layers.14.mlp.fc2.weight": "model-00001-of-00002.safetensors",
101
+ "language_model.model.layers.14.self_attn.dense.bias": "model-00001-of-00002.safetensors",
102
+ "language_model.model.layers.14.self_attn.dense.weight": "model-00001-of-00002.safetensors",
103
+ "language_model.model.layers.14.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
104
+ "language_model.model.layers.14.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
105
+ "language_model.model.layers.14.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
106
+ "language_model.model.layers.14.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
107
+ "language_model.model.layers.14.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
108
+ "language_model.model.layers.14.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
109
+ "language_model.model.layers.15.input_layernorm.bias": "model-00001-of-00002.safetensors",
110
+ "language_model.model.layers.15.input_layernorm.weight": "model-00001-of-00002.safetensors",
111
+ "language_model.model.layers.15.mlp.fc1.bias": "model-00001-of-00002.safetensors",
112
+ "language_model.model.layers.15.mlp.fc1.weight": "model-00001-of-00002.safetensors",
113
+ "language_model.model.layers.15.mlp.fc2.bias": "model-00001-of-00002.safetensors",
114
+ "language_model.model.layers.15.mlp.fc2.weight": "model-00001-of-00002.safetensors",
115
+ "language_model.model.layers.15.self_attn.dense.bias": "model-00001-of-00002.safetensors",
116
+ "language_model.model.layers.15.self_attn.dense.weight": "model-00001-of-00002.safetensors",
117
+ "language_model.model.layers.15.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
118
+ "language_model.model.layers.15.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
119
+ "language_model.model.layers.15.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
120
+ "language_model.model.layers.15.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
121
+ "language_model.model.layers.15.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
122
+ "language_model.model.layers.15.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
123
+ "language_model.model.layers.16.input_layernorm.bias": "model-00001-of-00002.safetensors",
124
+ "language_model.model.layers.16.input_layernorm.weight": "model-00001-of-00002.safetensors",
125
+ "language_model.model.layers.16.mlp.fc1.bias": "model-00001-of-00002.safetensors",
126
+ "language_model.model.layers.16.mlp.fc1.weight": "model-00001-of-00002.safetensors",
127
+ "language_model.model.layers.16.mlp.fc2.bias": "model-00001-of-00002.safetensors",
128
+ "language_model.model.layers.16.mlp.fc2.weight": "model-00001-of-00002.safetensors",
129
+ "language_model.model.layers.16.self_attn.dense.bias": "model-00001-of-00002.safetensors",
130
+ "language_model.model.layers.16.self_attn.dense.weight": "model-00001-of-00002.safetensors",
131
+ "language_model.model.layers.16.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
132
+ "language_model.model.layers.16.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
133
+ "language_model.model.layers.16.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
134
+ "language_model.model.layers.16.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
135
+ "language_model.model.layers.16.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
136
+ "language_model.model.layers.16.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
137
+ "language_model.model.layers.17.input_layernorm.bias": "model-00001-of-00002.safetensors",
138
+ "language_model.model.layers.17.input_layernorm.weight": "model-00001-of-00002.safetensors",
139
+ "language_model.model.layers.17.mlp.fc1.bias": "model-00001-of-00002.safetensors",
140
+ "language_model.model.layers.17.mlp.fc1.weight": "model-00001-of-00002.safetensors",
141
+ "language_model.model.layers.17.mlp.fc2.bias": "model-00001-of-00002.safetensors",
142
+ "language_model.model.layers.17.mlp.fc2.weight": "model-00001-of-00002.safetensors",
143
+ "language_model.model.layers.17.self_attn.dense.bias": "model-00001-of-00002.safetensors",
144
+ "language_model.model.layers.17.self_attn.dense.weight": "model-00001-of-00002.safetensors",
145
+ "language_model.model.layers.17.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
146
+ "language_model.model.layers.17.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
147
+ "language_model.model.layers.17.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
148
+ "language_model.model.layers.17.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
149
+ "language_model.model.layers.17.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
150
+ "language_model.model.layers.17.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
151
+ "language_model.model.layers.18.input_layernorm.bias": "model-00001-of-00002.safetensors",
152
+ "language_model.model.layers.18.input_layernorm.weight": "model-00001-of-00002.safetensors",
153
+ "language_model.model.layers.18.mlp.fc1.bias": "model-00001-of-00002.safetensors",
154
+ "language_model.model.layers.18.mlp.fc1.weight": "model-00001-of-00002.safetensors",
155
+ "language_model.model.layers.18.mlp.fc2.bias": "model-00001-of-00002.safetensors",
156
+ "language_model.model.layers.18.mlp.fc2.weight": "model-00001-of-00002.safetensors",
157
+ "language_model.model.layers.18.self_attn.dense.bias": "model-00001-of-00002.safetensors",
158
+ "language_model.model.layers.18.self_attn.dense.weight": "model-00001-of-00002.safetensors",
159
+ "language_model.model.layers.18.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
160
+ "language_model.model.layers.18.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
161
+ "language_model.model.layers.18.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
162
+ "language_model.model.layers.18.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
163
+ "language_model.model.layers.18.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
164
+ "language_model.model.layers.18.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
165
+ "language_model.model.layers.19.input_layernorm.bias": "model-00001-of-00002.safetensors",
166
+ "language_model.model.layers.19.input_layernorm.weight": "model-00001-of-00002.safetensors",
167
+ "language_model.model.layers.19.mlp.fc1.bias": "model-00001-of-00002.safetensors",
168
+ "language_model.model.layers.19.mlp.fc1.weight": "model-00001-of-00002.safetensors",
169
+ "language_model.model.layers.19.mlp.fc2.bias": "model-00001-of-00002.safetensors",
170
+ "language_model.model.layers.19.mlp.fc2.weight": "model-00001-of-00002.safetensors",
171
+ "language_model.model.layers.19.self_attn.dense.bias": "model-00001-of-00002.safetensors",
172
+ "language_model.model.layers.19.self_attn.dense.weight": "model-00001-of-00002.safetensors",
173
+ "language_model.model.layers.19.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
174
+ "language_model.model.layers.19.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
175
+ "language_model.model.layers.19.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
176
+ "language_model.model.layers.19.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
177
+ "language_model.model.layers.19.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
178
+ "language_model.model.layers.19.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
179
+ "language_model.model.layers.2.input_layernorm.bias": "model-00001-of-00002.safetensors",
180
+ "language_model.model.layers.2.input_layernorm.weight": "model-00001-of-00002.safetensors",
181
+ "language_model.model.layers.2.mlp.fc1.bias": "model-00001-of-00002.safetensors",
182
+ "language_model.model.layers.2.mlp.fc1.weight": "model-00001-of-00002.safetensors",
183
+ "language_model.model.layers.2.mlp.fc2.bias": "model-00001-of-00002.safetensors",
184
+ "language_model.model.layers.2.mlp.fc2.weight": "model-00001-of-00002.safetensors",
185
+ "language_model.model.layers.2.self_attn.dense.bias": "model-00001-of-00002.safetensors",
186
+ "language_model.model.layers.2.self_attn.dense.weight": "model-00001-of-00002.safetensors",
187
+ "language_model.model.layers.2.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
188
+ "language_model.model.layers.2.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
189
+ "language_model.model.layers.2.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
190
+ "language_model.model.layers.2.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
191
+ "language_model.model.layers.2.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
192
+ "language_model.model.layers.2.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
193
+ "language_model.model.layers.20.input_layernorm.bias": "model-00001-of-00002.safetensors",
194
+ "language_model.model.layers.20.input_layernorm.weight": "model-00001-of-00002.safetensors",
195
+ "language_model.model.layers.20.mlp.fc1.bias": "model-00001-of-00002.safetensors",
196
+ "language_model.model.layers.20.mlp.fc1.weight": "model-00001-of-00002.safetensors",
197
+ "language_model.model.layers.20.mlp.fc2.bias": "model-00001-of-00002.safetensors",
198
+ "language_model.model.layers.20.mlp.fc2.weight": "model-00001-of-00002.safetensors",
199
+ "language_model.model.layers.20.self_attn.dense.bias": "model-00001-of-00002.safetensors",
200
+ "language_model.model.layers.20.self_attn.dense.weight": "model-00001-of-00002.safetensors",
201
+ "language_model.model.layers.20.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
202
+ "language_model.model.layers.20.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
203
+ "language_model.model.layers.20.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
204
+ "language_model.model.layers.20.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
205
+ "language_model.model.layers.20.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
206
+ "language_model.model.layers.20.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
207
+ "language_model.model.layers.21.input_layernorm.bias": "model-00001-of-00002.safetensors",
208
+ "language_model.model.layers.21.input_layernorm.weight": "model-00001-of-00002.safetensors",
209
+ "language_model.model.layers.21.mlp.fc1.bias": "model-00001-of-00002.safetensors",
210
+ "language_model.model.layers.21.mlp.fc1.weight": "model-00001-of-00002.safetensors",
211
+ "language_model.model.layers.21.mlp.fc2.bias": "model-00001-of-00002.safetensors",
212
+ "language_model.model.layers.21.mlp.fc2.weight": "model-00001-of-00002.safetensors",
213
+ "language_model.model.layers.21.self_attn.dense.bias": "model-00001-of-00002.safetensors",
214
+ "language_model.model.layers.21.self_attn.dense.weight": "model-00001-of-00002.safetensors",
215
+ "language_model.model.layers.21.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
216
+ "language_model.model.layers.21.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
217
+ "language_model.model.layers.21.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
218
+ "language_model.model.layers.21.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
219
+ "language_model.model.layers.21.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
220
+ "language_model.model.layers.21.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
221
+ "language_model.model.layers.22.input_layernorm.bias": "model-00001-of-00002.safetensors",
222
+ "language_model.model.layers.22.input_layernorm.weight": "model-00001-of-00002.safetensors",
223
+ "language_model.model.layers.22.mlp.fc1.bias": "model-00001-of-00002.safetensors",
224
+ "language_model.model.layers.22.mlp.fc1.weight": "model-00001-of-00002.safetensors",
225
+ "language_model.model.layers.22.mlp.fc2.bias": "model-00001-of-00002.safetensors",
226
+ "language_model.model.layers.22.mlp.fc2.weight": "model-00001-of-00002.safetensors",
227
+ "language_model.model.layers.22.self_attn.dense.bias": "model-00001-of-00002.safetensors",
228
+ "language_model.model.layers.22.self_attn.dense.weight": "model-00001-of-00002.safetensors",
229
+ "language_model.model.layers.22.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
230
+ "language_model.model.layers.22.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
231
+ "language_model.model.layers.22.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
232
+ "language_model.model.layers.22.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
233
+ "language_model.model.layers.22.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
234
+ "language_model.model.layers.22.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
235
+ "language_model.model.layers.23.input_layernorm.bias": "model-00001-of-00002.safetensors",
236
+ "language_model.model.layers.23.input_layernorm.weight": "model-00001-of-00002.safetensors",
237
+ "language_model.model.layers.23.mlp.fc1.bias": "model-00001-of-00002.safetensors",
238
+ "language_model.model.layers.23.mlp.fc1.weight": "model-00001-of-00002.safetensors",
239
+ "language_model.model.layers.23.mlp.fc2.bias": "model-00001-of-00002.safetensors",
240
+ "language_model.model.layers.23.mlp.fc2.weight": "model-00001-of-00002.safetensors",
241
+ "language_model.model.layers.23.self_attn.dense.bias": "model-00001-of-00002.safetensors",
242
+ "language_model.model.layers.23.self_attn.dense.weight": "model-00001-of-00002.safetensors",
243
+ "language_model.model.layers.23.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
244
+ "language_model.model.layers.23.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
245
+ "language_model.model.layers.23.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
246
+ "language_model.model.layers.23.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
247
+ "language_model.model.layers.23.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
248
+ "language_model.model.layers.23.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
249
+ "language_model.model.layers.24.input_layernorm.bias": "model-00002-of-00002.safetensors",
250
+ "language_model.model.layers.24.input_layernorm.weight": "model-00002-of-00002.safetensors",
251
+ "language_model.model.layers.24.mlp.fc1.bias": "model-00002-of-00002.safetensors",
252
+ "language_model.model.layers.24.mlp.fc1.weight": "model-00002-of-00002.safetensors",
253
+ "language_model.model.layers.24.mlp.fc2.bias": "model-00002-of-00002.safetensors",
254
+ "language_model.model.layers.24.mlp.fc2.weight": "model-00002-of-00002.safetensors",
255
+ "language_model.model.layers.24.self_attn.dense.bias": "model-00001-of-00002.safetensors",
256
+ "language_model.model.layers.24.self_attn.dense.weight": "model-00001-of-00002.safetensors",
257
+ "language_model.model.layers.24.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
258
+ "language_model.model.layers.24.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
259
+ "language_model.model.layers.24.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
260
+ "language_model.model.layers.24.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
261
+ "language_model.model.layers.24.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
262
+ "language_model.model.layers.24.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
263
+ "language_model.model.layers.25.input_layernorm.bias": "model-00002-of-00002.safetensors",
264
+ "language_model.model.layers.25.input_layernorm.weight": "model-00002-of-00002.safetensors",
265
+ "language_model.model.layers.25.mlp.fc1.bias": "model-00002-of-00002.safetensors",
266
+ "language_model.model.layers.25.mlp.fc1.weight": "model-00002-of-00002.safetensors",
267
+ "language_model.model.layers.25.mlp.fc2.bias": "model-00002-of-00002.safetensors",
268
+ "language_model.model.layers.25.mlp.fc2.weight": "model-00002-of-00002.safetensors",
269
+ "language_model.model.layers.25.self_attn.dense.bias": "model-00002-of-00002.safetensors",
270
+ "language_model.model.layers.25.self_attn.dense.weight": "model-00002-of-00002.safetensors",
271
+ "language_model.model.layers.25.self_attn.k_proj.bias": "model-00002-of-00002.safetensors",
272
+ "language_model.model.layers.25.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
273
+ "language_model.model.layers.25.self_attn.q_proj.bias": "model-00002-of-00002.safetensors",
274
+ "language_model.model.layers.25.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
275
+ "language_model.model.layers.25.self_attn.v_proj.bias": "model-00002-of-00002.safetensors",
276
+ "language_model.model.layers.25.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
277
+ "language_model.model.layers.26.input_layernorm.bias": "model-00002-of-00002.safetensors",
278
+ "language_model.model.layers.26.input_layernorm.weight": "model-00002-of-00002.safetensors",
279
+ "language_model.model.layers.26.mlp.fc1.bias": "model-00002-of-00002.safetensors",
280
+ "language_model.model.layers.26.mlp.fc1.weight": "model-00002-of-00002.safetensors",
281
+ "language_model.model.layers.26.mlp.fc2.bias": "model-00002-of-00002.safetensors",
282
+ "language_model.model.layers.26.mlp.fc2.weight": "model-00002-of-00002.safetensors",
283
+ "language_model.model.layers.26.self_attn.dense.bias": "model-00002-of-00002.safetensors",
284
+ "language_model.model.layers.26.self_attn.dense.weight": "model-00002-of-00002.safetensors",
285
+ "language_model.model.layers.26.self_attn.k_proj.bias": "model-00002-of-00002.safetensors",
286
+ "language_model.model.layers.26.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
287
+ "language_model.model.layers.26.self_attn.q_proj.bias": "model-00002-of-00002.safetensors",
288
+ "language_model.model.layers.26.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
289
+ "language_model.model.layers.26.self_attn.v_proj.bias": "model-00002-of-00002.safetensors",
290
+ "language_model.model.layers.26.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
291
+ "language_model.model.layers.27.input_layernorm.bias": "model-00002-of-00002.safetensors",
292
+ "language_model.model.layers.27.input_layernorm.weight": "model-00002-of-00002.safetensors",
293
+ "language_model.model.layers.27.mlp.fc1.bias": "model-00002-of-00002.safetensors",
294
+ "language_model.model.layers.27.mlp.fc1.weight": "model-00002-of-00002.safetensors",
295
+ "language_model.model.layers.27.mlp.fc2.bias": "model-00002-of-00002.safetensors",
296
+ "language_model.model.layers.27.mlp.fc2.weight": "model-00002-of-00002.safetensors",
297
+ "language_model.model.layers.27.self_attn.dense.bias": "model-00002-of-00002.safetensors",
298
+ "language_model.model.layers.27.self_attn.dense.weight": "model-00002-of-00002.safetensors",
299
+ "language_model.model.layers.27.self_attn.k_proj.bias": "model-00002-of-00002.safetensors",
300
+ "language_model.model.layers.27.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
301
+ "language_model.model.layers.27.self_attn.q_proj.bias": "model-00002-of-00002.safetensors",
302
+ "language_model.model.layers.27.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
303
+ "language_model.model.layers.27.self_attn.v_proj.bias": "model-00002-of-00002.safetensors",
304
+ "language_model.model.layers.27.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
305
+ "language_model.model.layers.28.input_layernorm.bias": "model-00002-of-00002.safetensors",
306
+ "language_model.model.layers.28.input_layernorm.weight": "model-00002-of-00002.safetensors",
307
+ "language_model.model.layers.28.mlp.fc1.bias": "model-00002-of-00002.safetensors",
308
+ "language_model.model.layers.28.mlp.fc1.weight": "model-00002-of-00002.safetensors",
309
+ "language_model.model.layers.28.mlp.fc2.bias": "model-00002-of-00002.safetensors",
310
+ "language_model.model.layers.28.mlp.fc2.weight": "model-00002-of-00002.safetensors",
311
+ "language_model.model.layers.28.self_attn.dense.bias": "model-00002-of-00002.safetensors",
312
+ "language_model.model.layers.28.self_attn.dense.weight": "model-00002-of-00002.safetensors",
313
+ "language_model.model.layers.28.self_attn.k_proj.bias": "model-00002-of-00002.safetensors",
314
+ "language_model.model.layers.28.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
315
+ "language_model.model.layers.28.self_attn.q_proj.bias": "model-00002-of-00002.safetensors",
316
+ "language_model.model.layers.28.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
317
+ "language_model.model.layers.28.self_attn.v_proj.bias": "model-00002-of-00002.safetensors",
318
+ "language_model.model.layers.28.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
319
+ "language_model.model.layers.29.input_layernorm.bias": "model-00002-of-00002.safetensors",
320
+ "language_model.model.layers.29.input_layernorm.weight": "model-00002-of-00002.safetensors",
321
+ "language_model.model.layers.29.mlp.fc1.bias": "model-00002-of-00002.safetensors",
322
+ "language_model.model.layers.29.mlp.fc1.weight": "model-00002-of-00002.safetensors",
323
+ "language_model.model.layers.29.mlp.fc2.bias": "model-00002-of-00002.safetensors",
324
+ "language_model.model.layers.29.mlp.fc2.weight": "model-00002-of-00002.safetensors",
325
+ "language_model.model.layers.29.self_attn.dense.bias": "model-00002-of-00002.safetensors",
326
+ "language_model.model.layers.29.self_attn.dense.weight": "model-00002-of-00002.safetensors",
327
+ "language_model.model.layers.29.self_attn.k_proj.bias": "model-00002-of-00002.safetensors",
328
+ "language_model.model.layers.29.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
329
+ "language_model.model.layers.29.self_attn.q_proj.bias": "model-00002-of-00002.safetensors",
330
+ "language_model.model.layers.29.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
331
+ "language_model.model.layers.29.self_attn.v_proj.bias": "model-00002-of-00002.safetensors",
332
+ "language_model.model.layers.29.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
333
+ "language_model.model.layers.3.input_layernorm.bias": "model-00001-of-00002.safetensors",
334
+ "language_model.model.layers.3.input_layernorm.weight": "model-00001-of-00002.safetensors",
335
+ "language_model.model.layers.3.mlp.fc1.bias": "model-00001-of-00002.safetensors",
336
+ "language_model.model.layers.3.mlp.fc1.weight": "model-00001-of-00002.safetensors",
337
+ "language_model.model.layers.3.mlp.fc2.bias": "model-00001-of-00002.safetensors",
338
+ "language_model.model.layers.3.mlp.fc2.weight": "model-00001-of-00002.safetensors",
339
+ "language_model.model.layers.3.self_attn.dense.bias": "model-00001-of-00002.safetensors",
340
+ "language_model.model.layers.3.self_attn.dense.weight": "model-00001-of-00002.safetensors",
341
+ "language_model.model.layers.3.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
342
+ "language_model.model.layers.3.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
343
+ "language_model.model.layers.3.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
344
+ "language_model.model.layers.3.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
345
+ "language_model.model.layers.3.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
346
+ "language_model.model.layers.3.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
347
+ "language_model.model.layers.30.input_layernorm.bias": "model-00002-of-00002.safetensors",
348
+ "language_model.model.layers.30.input_layernorm.weight": "model-00002-of-00002.safetensors",
349
+ "language_model.model.layers.30.mlp.fc1.bias": "model-00002-of-00002.safetensors",
350
+ "language_model.model.layers.30.mlp.fc1.weight": "model-00002-of-00002.safetensors",
351
+ "language_model.model.layers.30.mlp.fc2.bias": "model-00002-of-00002.safetensors",
352
+ "language_model.model.layers.30.mlp.fc2.weight": "model-00002-of-00002.safetensors",
353
+ "language_model.model.layers.30.self_attn.dense.bias": "model-00002-of-00002.safetensors",
354
+ "language_model.model.layers.30.self_attn.dense.weight": "model-00002-of-00002.safetensors",
355
+ "language_model.model.layers.30.self_attn.k_proj.bias": "model-00002-of-00002.safetensors",
356
+ "language_model.model.layers.30.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
357
+ "language_model.model.layers.30.self_attn.q_proj.bias": "model-00002-of-00002.safetensors",
358
+ "language_model.model.layers.30.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
359
+ "language_model.model.layers.30.self_attn.v_proj.bias": "model-00002-of-00002.safetensors",
360
+ "language_model.model.layers.30.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
361
+ "language_model.model.layers.31.input_layernorm.bias": "model-00002-of-00002.safetensors",
362
+ "language_model.model.layers.31.input_layernorm.weight": "model-00002-of-00002.safetensors",
363
+ "language_model.model.layers.31.mlp.fc1.bias": "model-00002-of-00002.safetensors",
364
+ "language_model.model.layers.31.mlp.fc1.weight": "model-00002-of-00002.safetensors",
365
+ "language_model.model.layers.31.mlp.fc2.bias": "model-00002-of-00002.safetensors",
366
+ "language_model.model.layers.31.mlp.fc2.weight": "model-00002-of-00002.safetensors",
367
+ "language_model.model.layers.31.self_attn.dense.bias": "model-00002-of-00002.safetensors",
368
+ "language_model.model.layers.31.self_attn.dense.weight": "model-00002-of-00002.safetensors",
369
+ "language_model.model.layers.31.self_attn.k_proj.bias": "model-00002-of-00002.safetensors",
370
+ "language_model.model.layers.31.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
371
+ "language_model.model.layers.31.self_attn.q_proj.bias": "model-00002-of-00002.safetensors",
372
+ "language_model.model.layers.31.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
373
+ "language_model.model.layers.31.self_attn.v_proj.bias": "model-00002-of-00002.safetensors",
374
+ "language_model.model.layers.31.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
375
+ "language_model.model.layers.4.input_layernorm.bias": "model-00001-of-00002.safetensors",
376
+ "language_model.model.layers.4.input_layernorm.weight": "model-00001-of-00002.safetensors",
377
+ "language_model.model.layers.4.mlp.fc1.bias": "model-00001-of-00002.safetensors",
378
+ "language_model.model.layers.4.mlp.fc1.weight": "model-00001-of-00002.safetensors",
379
+ "language_model.model.layers.4.mlp.fc2.bias": "model-00001-of-00002.safetensors",
380
+ "language_model.model.layers.4.mlp.fc2.weight": "model-00001-of-00002.safetensors",
381
+ "language_model.model.layers.4.self_attn.dense.bias": "model-00001-of-00002.safetensors",
382
+ "language_model.model.layers.4.self_attn.dense.weight": "model-00001-of-00002.safetensors",
383
+ "language_model.model.layers.4.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
384
+ "language_model.model.layers.4.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
385
+ "language_model.model.layers.4.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
386
+ "language_model.model.layers.4.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
387
+ "language_model.model.layers.4.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
388
+ "language_model.model.layers.4.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
389
+ "language_model.model.layers.5.input_layernorm.bias": "model-00001-of-00002.safetensors",
390
+ "language_model.model.layers.5.input_layernorm.weight": "model-00001-of-00002.safetensors",
391
+ "language_model.model.layers.5.mlp.fc1.bias": "model-00001-of-00002.safetensors",
392
+ "language_model.model.layers.5.mlp.fc1.weight": "model-00001-of-00002.safetensors",
393
+ "language_model.model.layers.5.mlp.fc2.bias": "model-00001-of-00002.safetensors",
394
+ "language_model.model.layers.5.mlp.fc2.weight": "model-00001-of-00002.safetensors",
395
+ "language_model.model.layers.5.self_attn.dense.bias": "model-00001-of-00002.safetensors",
396
+ "language_model.model.layers.5.self_attn.dense.weight": "model-00001-of-00002.safetensors",
397
+ "language_model.model.layers.5.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
398
+ "language_model.model.layers.5.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
399
+ "language_model.model.layers.5.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
400
+ "language_model.model.layers.5.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
401
+ "language_model.model.layers.5.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
402
+ "language_model.model.layers.5.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
403
+ "language_model.model.layers.6.input_layernorm.bias": "model-00001-of-00002.safetensors",
404
+ "language_model.model.layers.6.input_layernorm.weight": "model-00001-of-00002.safetensors",
405
+ "language_model.model.layers.6.mlp.fc1.bias": "model-00001-of-00002.safetensors",
406
+ "language_model.model.layers.6.mlp.fc1.weight": "model-00001-of-00002.safetensors",
407
+ "language_model.model.layers.6.mlp.fc2.bias": "model-00001-of-00002.safetensors",
408
+ "language_model.model.layers.6.mlp.fc2.weight": "model-00001-of-00002.safetensors",
409
+ "language_model.model.layers.6.self_attn.dense.bias": "model-00001-of-00002.safetensors",
410
+ "language_model.model.layers.6.self_attn.dense.weight": "model-00001-of-00002.safetensors",
411
+ "language_model.model.layers.6.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
412
+ "language_model.model.layers.6.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
413
+ "language_model.model.layers.6.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
414
+ "language_model.model.layers.6.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
415
+ "language_model.model.layers.6.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
416
+ "language_model.model.layers.6.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
417
+ "language_model.model.layers.7.input_layernorm.bias": "model-00001-of-00002.safetensors",
418
+ "language_model.model.layers.7.input_layernorm.weight": "model-00001-of-00002.safetensors",
419
+ "language_model.model.layers.7.mlp.fc1.bias": "model-00001-of-00002.safetensors",
420
+ "language_model.model.layers.7.mlp.fc1.weight": "model-00001-of-00002.safetensors",
421
+ "language_model.model.layers.7.mlp.fc2.bias": "model-00001-of-00002.safetensors",
422
+ "language_model.model.layers.7.mlp.fc2.weight": "model-00001-of-00002.safetensors",
423
+ "language_model.model.layers.7.self_attn.dense.bias": "model-00001-of-00002.safetensors",
424
+ "language_model.model.layers.7.self_attn.dense.weight": "model-00001-of-00002.safetensors",
425
+ "language_model.model.layers.7.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
426
+ "language_model.model.layers.7.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
427
+ "language_model.model.layers.7.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
428
+ "language_model.model.layers.7.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
429
+ "language_model.model.layers.7.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
430
+ "language_model.model.layers.7.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
431
+ "language_model.model.layers.8.input_layernorm.bias": "model-00001-of-00002.safetensors",
432
+ "language_model.model.layers.8.input_layernorm.weight": "model-00001-of-00002.safetensors",
433
+ "language_model.model.layers.8.mlp.fc1.bias": "model-00001-of-00002.safetensors",
434
+ "language_model.model.layers.8.mlp.fc1.weight": "model-00001-of-00002.safetensors",
435
+ "language_model.model.layers.8.mlp.fc2.bias": "model-00001-of-00002.safetensors",
436
+ "language_model.model.layers.8.mlp.fc2.weight": "model-00001-of-00002.safetensors",
437
+ "language_model.model.layers.8.self_attn.dense.bias": "model-00001-of-00002.safetensors",
438
+ "language_model.model.layers.8.self_attn.dense.weight": "model-00001-of-00002.safetensors",
439
+ "language_model.model.layers.8.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
440
+ "language_model.model.layers.8.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
441
+ "language_model.model.layers.8.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
442
+ "language_model.model.layers.8.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
443
+ "language_model.model.layers.8.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
444
+ "language_model.model.layers.8.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
445
+ "language_model.model.layers.9.input_layernorm.bias": "model-00001-of-00002.safetensors",
446
+ "language_model.model.layers.9.input_layernorm.weight": "model-00001-of-00002.safetensors",
447
+ "language_model.model.layers.9.mlp.fc1.bias": "model-00001-of-00002.safetensors",
448
+ "language_model.model.layers.9.mlp.fc1.weight": "model-00001-of-00002.safetensors",
449
+ "language_model.model.layers.9.mlp.fc2.bias": "model-00001-of-00002.safetensors",
450
+ "language_model.model.layers.9.mlp.fc2.weight": "model-00001-of-00002.safetensors",
451
+ "language_model.model.layers.9.self_attn.dense.bias": "model-00001-of-00002.safetensors",
452
+ "language_model.model.layers.9.self_attn.dense.weight": "model-00001-of-00002.safetensors",
453
+ "language_model.model.layers.9.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
454
+ "language_model.model.layers.9.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
455
+ "language_model.model.layers.9.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
456
+ "language_model.model.layers.9.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
457
+ "language_model.model.layers.9.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
458
+ "language_model.model.layers.9.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
459
+ "multi_modal_projector.linear_1.bias": "model-00001-of-00002.safetensors",
460
+ "multi_modal_projector.linear_1.weight": "model-00001-of-00002.safetensors",
461
+ "multi_modal_projector.linear_2.bias": "model-00001-of-00002.safetensors",
462
+ "multi_modal_projector.linear_2.weight": "model-00001-of-00002.safetensors",
463
+ "vision_model.coord_embed.0.bias": "model-00001-of-00002.safetensors",
464
+ "vision_model.coord_embed.0.weight": "model-00001-of-00002.safetensors",
465
+ "vision_model.coord_embed.2.bias": "model-00001-of-00002.safetensors",
466
+ "vision_model.coord_embed.2.weight": "model-00001-of-00002.safetensors",
467
+ "vision_model.vision_tower.vision_model.embeddings.patch_embedding.bias": "model-00001-of-00002.safetensors",
468
+ "vision_model.vision_tower.vision_model.embeddings.patch_embedding.weight": "model-00001-of-00002.safetensors",
469
+ "vision_model.vision_tower.vision_model.embeddings.position_embedding.weight": "model-00001-of-00002.safetensors",
470
+ "vision_model.vision_tower.vision_model.encoder.layers.0.layer_norm1.bias": "model-00001-of-00002.safetensors",
471
+ "vision_model.vision_tower.vision_model.encoder.layers.0.layer_norm1.weight": "model-00001-of-00002.safetensors",
472
+ "vision_model.vision_tower.vision_model.encoder.layers.0.layer_norm2.bias": "model-00001-of-00002.safetensors",
473
+ "vision_model.vision_tower.vision_model.encoder.layers.0.layer_norm2.weight": "model-00001-of-00002.safetensors",
474
+ "vision_model.vision_tower.vision_model.encoder.layers.0.mlp.fc1.bias": "model-00001-of-00002.safetensors",
475
+ "vision_model.vision_tower.vision_model.encoder.layers.0.mlp.fc1.weight": "model-00001-of-00002.safetensors",
476
+ "vision_model.vision_tower.vision_model.encoder.layers.0.mlp.fc2.bias": "model-00001-of-00002.safetensors",
477
+ "vision_model.vision_tower.vision_model.encoder.layers.0.mlp.fc2.weight": "model-00001-of-00002.safetensors",
478
+ "vision_model.vision_tower.vision_model.encoder.layers.0.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
479
+ "vision_model.vision_tower.vision_model.encoder.layers.0.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
480
+ "vision_model.vision_tower.vision_model.encoder.layers.0.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
481
+ "vision_model.vision_tower.vision_model.encoder.layers.0.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
482
+ "vision_model.vision_tower.vision_model.encoder.layers.0.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
483
+ "vision_model.vision_tower.vision_model.encoder.layers.0.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
484
+ "vision_model.vision_tower.vision_model.encoder.layers.0.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
485
+ "vision_model.vision_tower.vision_model.encoder.layers.0.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
486
+ "vision_model.vision_tower.vision_model.encoder.layers.1.layer_norm1.bias": "model-00001-of-00002.safetensors",
487
+ "vision_model.vision_tower.vision_model.encoder.layers.1.layer_norm1.weight": "model-00001-of-00002.safetensors",
488
+ "vision_model.vision_tower.vision_model.encoder.layers.1.layer_norm2.bias": "model-00001-of-00002.safetensors",
489
+ "vision_model.vision_tower.vision_model.encoder.layers.1.layer_norm2.weight": "model-00001-of-00002.safetensors",
490
+ "vision_model.vision_tower.vision_model.encoder.layers.1.mlp.fc1.bias": "model-00001-of-00002.safetensors",
491
+ "vision_model.vision_tower.vision_model.encoder.layers.1.mlp.fc1.weight": "model-00001-of-00002.safetensors",
492
+ "vision_model.vision_tower.vision_model.encoder.layers.1.mlp.fc2.bias": "model-00001-of-00002.safetensors",
493
+ "vision_model.vision_tower.vision_model.encoder.layers.1.mlp.fc2.weight": "model-00001-of-00002.safetensors",
494
+ "vision_model.vision_tower.vision_model.encoder.layers.1.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
495
+ "vision_model.vision_tower.vision_model.encoder.layers.1.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
496
+ "vision_model.vision_tower.vision_model.encoder.layers.1.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
497
+ "vision_model.vision_tower.vision_model.encoder.layers.1.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
498
+ "vision_model.vision_tower.vision_model.encoder.layers.1.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
499
+ "vision_model.vision_tower.vision_model.encoder.layers.1.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
500
+ "vision_model.vision_tower.vision_model.encoder.layers.1.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
501
+ "vision_model.vision_tower.vision_model.encoder.layers.1.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
502
+ "vision_model.vision_tower.vision_model.encoder.layers.10.layer_norm1.bias": "model-00001-of-00002.safetensors",
503
+ "vision_model.vision_tower.vision_model.encoder.layers.10.layer_norm1.weight": "model-00001-of-00002.safetensors",
504
+ "vision_model.vision_tower.vision_model.encoder.layers.10.layer_norm2.bias": "model-00001-of-00002.safetensors",
505
+ "vision_model.vision_tower.vision_model.encoder.layers.10.layer_norm2.weight": "model-00001-of-00002.safetensors",
506
+ "vision_model.vision_tower.vision_model.encoder.layers.10.mlp.fc1.bias": "model-00001-of-00002.safetensors",
507
+ "vision_model.vision_tower.vision_model.encoder.layers.10.mlp.fc1.weight": "model-00001-of-00002.safetensors",
508
+ "vision_model.vision_tower.vision_model.encoder.layers.10.mlp.fc2.bias": "model-00001-of-00002.safetensors",
509
+ "vision_model.vision_tower.vision_model.encoder.layers.10.mlp.fc2.weight": "model-00001-of-00002.safetensors",
510
+ "vision_model.vision_tower.vision_model.encoder.layers.10.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
511
+ "vision_model.vision_tower.vision_model.encoder.layers.10.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
512
+ "vision_model.vision_tower.vision_model.encoder.layers.10.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
513
+ "vision_model.vision_tower.vision_model.encoder.layers.10.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
514
+ "vision_model.vision_tower.vision_model.encoder.layers.10.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
515
+ "vision_model.vision_tower.vision_model.encoder.layers.10.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
516
+ "vision_model.vision_tower.vision_model.encoder.layers.10.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
517
+ "vision_model.vision_tower.vision_model.encoder.layers.10.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
518
+ "vision_model.vision_tower.vision_model.encoder.layers.11.layer_norm1.bias": "model-00001-of-00002.safetensors",
519
+ "vision_model.vision_tower.vision_model.encoder.layers.11.layer_norm1.weight": "model-00001-of-00002.safetensors",
520
+ "vision_model.vision_tower.vision_model.encoder.layers.11.layer_norm2.bias": "model-00001-of-00002.safetensors",
521
+ "vision_model.vision_tower.vision_model.encoder.layers.11.layer_norm2.weight": "model-00001-of-00002.safetensors",
522
+ "vision_model.vision_tower.vision_model.encoder.layers.11.mlp.fc1.bias": "model-00001-of-00002.safetensors",
523
+ "vision_model.vision_tower.vision_model.encoder.layers.11.mlp.fc1.weight": "model-00001-of-00002.safetensors",
524
+ "vision_model.vision_tower.vision_model.encoder.layers.11.mlp.fc2.bias": "model-00001-of-00002.safetensors",
525
+ "vision_model.vision_tower.vision_model.encoder.layers.11.mlp.fc2.weight": "model-00001-of-00002.safetensors",
526
+ "vision_model.vision_tower.vision_model.encoder.layers.11.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
527
+ "vision_model.vision_tower.vision_model.encoder.layers.11.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
528
+ "vision_model.vision_tower.vision_model.encoder.layers.11.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
529
+ "vision_model.vision_tower.vision_model.encoder.layers.11.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
530
+ "vision_model.vision_tower.vision_model.encoder.layers.11.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
531
+ "vision_model.vision_tower.vision_model.encoder.layers.11.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
532
+ "vision_model.vision_tower.vision_model.encoder.layers.11.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
533
+ "vision_model.vision_tower.vision_model.encoder.layers.11.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
534
+ "vision_model.vision_tower.vision_model.encoder.layers.12.layer_norm1.bias": "model-00001-of-00002.safetensors",
535
+ "vision_model.vision_tower.vision_model.encoder.layers.12.layer_norm1.weight": "model-00001-of-00002.safetensors",
536
+ "vision_model.vision_tower.vision_model.encoder.layers.12.layer_norm2.bias": "model-00001-of-00002.safetensors",
537
+ "vision_model.vision_tower.vision_model.encoder.layers.12.layer_norm2.weight": "model-00001-of-00002.safetensors",
538
+ "vision_model.vision_tower.vision_model.encoder.layers.12.mlp.fc1.bias": "model-00001-of-00002.safetensors",
539
+ "vision_model.vision_tower.vision_model.encoder.layers.12.mlp.fc1.weight": "model-00001-of-00002.safetensors",
540
+ "vision_model.vision_tower.vision_model.encoder.layers.12.mlp.fc2.bias": "model-00001-of-00002.safetensors",
541
+ "vision_model.vision_tower.vision_model.encoder.layers.12.mlp.fc2.weight": "model-00001-of-00002.safetensors",
542
+ "vision_model.vision_tower.vision_model.encoder.layers.12.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
543
+ "vision_model.vision_tower.vision_model.encoder.layers.12.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
544
+ "vision_model.vision_tower.vision_model.encoder.layers.12.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
545
+ "vision_model.vision_tower.vision_model.encoder.layers.12.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
546
+ "vision_model.vision_tower.vision_model.encoder.layers.12.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
547
+ "vision_model.vision_tower.vision_model.encoder.layers.12.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
548
+ "vision_model.vision_tower.vision_model.encoder.layers.12.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
549
+ "vision_model.vision_tower.vision_model.encoder.layers.12.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
550
+ "vision_model.vision_tower.vision_model.encoder.layers.13.layer_norm1.bias": "model-00001-of-00002.safetensors",
551
+ "vision_model.vision_tower.vision_model.encoder.layers.13.layer_norm1.weight": "model-00001-of-00002.safetensors",
552
+ "vision_model.vision_tower.vision_model.encoder.layers.13.layer_norm2.bias": "model-00001-of-00002.safetensors",
553
+ "vision_model.vision_tower.vision_model.encoder.layers.13.layer_norm2.weight": "model-00001-of-00002.safetensors",
554
+ "vision_model.vision_tower.vision_model.encoder.layers.13.mlp.fc1.bias": "model-00001-of-00002.safetensors",
555
+ "vision_model.vision_tower.vision_model.encoder.layers.13.mlp.fc1.weight": "model-00001-of-00002.safetensors",
556
+ "vision_model.vision_tower.vision_model.encoder.layers.13.mlp.fc2.bias": "model-00001-of-00002.safetensors",
557
+ "vision_model.vision_tower.vision_model.encoder.layers.13.mlp.fc2.weight": "model-00001-of-00002.safetensors",
558
+ "vision_model.vision_tower.vision_model.encoder.layers.13.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
559
+ "vision_model.vision_tower.vision_model.encoder.layers.13.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
560
+ "vision_model.vision_tower.vision_model.encoder.layers.13.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
561
+ "vision_model.vision_tower.vision_model.encoder.layers.13.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
562
+ "vision_model.vision_tower.vision_model.encoder.layers.13.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
563
+ "vision_model.vision_tower.vision_model.encoder.layers.13.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
564
+ "vision_model.vision_tower.vision_model.encoder.layers.13.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
565
+ "vision_model.vision_tower.vision_model.encoder.layers.13.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
566
+ "vision_model.vision_tower.vision_model.encoder.layers.14.layer_norm1.bias": "model-00001-of-00002.safetensors",
567
+ "vision_model.vision_tower.vision_model.encoder.layers.14.layer_norm1.weight": "model-00001-of-00002.safetensors",
568
+ "vision_model.vision_tower.vision_model.encoder.layers.14.layer_norm2.bias": "model-00001-of-00002.safetensors",
569
+ "vision_model.vision_tower.vision_model.encoder.layers.14.layer_norm2.weight": "model-00001-of-00002.safetensors",
570
+ "vision_model.vision_tower.vision_model.encoder.layers.14.mlp.fc1.bias": "model-00001-of-00002.safetensors",
571
+ "vision_model.vision_tower.vision_model.encoder.layers.14.mlp.fc1.weight": "model-00001-of-00002.safetensors",
572
+ "vision_model.vision_tower.vision_model.encoder.layers.14.mlp.fc2.bias": "model-00001-of-00002.safetensors",
573
+ "vision_model.vision_tower.vision_model.encoder.layers.14.mlp.fc2.weight": "model-00001-of-00002.safetensors",
574
+ "vision_model.vision_tower.vision_model.encoder.layers.14.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
575
+ "vision_model.vision_tower.vision_model.encoder.layers.14.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
576
+ "vision_model.vision_tower.vision_model.encoder.layers.14.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
577
+ "vision_model.vision_tower.vision_model.encoder.layers.14.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
578
+ "vision_model.vision_tower.vision_model.encoder.layers.14.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
579
+ "vision_model.vision_tower.vision_model.encoder.layers.14.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
580
+ "vision_model.vision_tower.vision_model.encoder.layers.14.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
581
+ "vision_model.vision_tower.vision_model.encoder.layers.14.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
582
+ "vision_model.vision_tower.vision_model.encoder.layers.15.layer_norm1.bias": "model-00001-of-00002.safetensors",
583
+ "vision_model.vision_tower.vision_model.encoder.layers.15.layer_norm1.weight": "model-00001-of-00002.safetensors",
584
+ "vision_model.vision_tower.vision_model.encoder.layers.15.layer_norm2.bias": "model-00001-of-00002.safetensors",
585
+ "vision_model.vision_tower.vision_model.encoder.layers.15.layer_norm2.weight": "model-00001-of-00002.safetensors",
586
+ "vision_model.vision_tower.vision_model.encoder.layers.15.mlp.fc1.bias": "model-00001-of-00002.safetensors",
587
+ "vision_model.vision_tower.vision_model.encoder.layers.15.mlp.fc1.weight": "model-00001-of-00002.safetensors",
588
+ "vision_model.vision_tower.vision_model.encoder.layers.15.mlp.fc2.bias": "model-00001-of-00002.safetensors",
589
+ "vision_model.vision_tower.vision_model.encoder.layers.15.mlp.fc2.weight": "model-00001-of-00002.safetensors",
590
+ "vision_model.vision_tower.vision_model.encoder.layers.15.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
591
+ "vision_model.vision_tower.vision_model.encoder.layers.15.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
592
+ "vision_model.vision_tower.vision_model.encoder.layers.15.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
593
+ "vision_model.vision_tower.vision_model.encoder.layers.15.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
594
+ "vision_model.vision_tower.vision_model.encoder.layers.15.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
595
+ "vision_model.vision_tower.vision_model.encoder.layers.15.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
596
+ "vision_model.vision_tower.vision_model.encoder.layers.15.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
597
+ "vision_model.vision_tower.vision_model.encoder.layers.15.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
598
+ "vision_model.vision_tower.vision_model.encoder.layers.16.layer_norm1.bias": "model-00001-of-00002.safetensors",
599
+ "vision_model.vision_tower.vision_model.encoder.layers.16.layer_norm1.weight": "model-00001-of-00002.safetensors",
600
+ "vision_model.vision_tower.vision_model.encoder.layers.16.layer_norm2.bias": "model-00001-of-00002.safetensors",
601
+ "vision_model.vision_tower.vision_model.encoder.layers.16.layer_norm2.weight": "model-00001-of-00002.safetensors",
602
+ "vision_model.vision_tower.vision_model.encoder.layers.16.mlp.fc1.bias": "model-00001-of-00002.safetensors",
603
+ "vision_model.vision_tower.vision_model.encoder.layers.16.mlp.fc1.weight": "model-00001-of-00002.safetensors",
604
+ "vision_model.vision_tower.vision_model.encoder.layers.16.mlp.fc2.bias": "model-00001-of-00002.safetensors",
605
+ "vision_model.vision_tower.vision_model.encoder.layers.16.mlp.fc2.weight": "model-00001-of-00002.safetensors",
606
+ "vision_model.vision_tower.vision_model.encoder.layers.16.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
607
+ "vision_model.vision_tower.vision_model.encoder.layers.16.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
608
+ "vision_model.vision_tower.vision_model.encoder.layers.16.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
609
+ "vision_model.vision_tower.vision_model.encoder.layers.16.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
610
+ "vision_model.vision_tower.vision_model.encoder.layers.16.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
611
+ "vision_model.vision_tower.vision_model.encoder.layers.16.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
612
+ "vision_model.vision_tower.vision_model.encoder.layers.16.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
613
+ "vision_model.vision_tower.vision_model.encoder.layers.16.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
614
+ "vision_model.vision_tower.vision_model.encoder.layers.17.layer_norm1.bias": "model-00001-of-00002.safetensors",
615
+ "vision_model.vision_tower.vision_model.encoder.layers.17.layer_norm1.weight": "model-00001-of-00002.safetensors",
616
+ "vision_model.vision_tower.vision_model.encoder.layers.17.layer_norm2.bias": "model-00001-of-00002.safetensors",
617
+ "vision_model.vision_tower.vision_model.encoder.layers.17.layer_norm2.weight": "model-00001-of-00002.safetensors",
618
+ "vision_model.vision_tower.vision_model.encoder.layers.17.mlp.fc1.bias": "model-00001-of-00002.safetensors",
619
+ "vision_model.vision_tower.vision_model.encoder.layers.17.mlp.fc1.weight": "model-00001-of-00002.safetensors",
620
+ "vision_model.vision_tower.vision_model.encoder.layers.17.mlp.fc2.bias": "model-00001-of-00002.safetensors",
621
+ "vision_model.vision_tower.vision_model.encoder.layers.17.mlp.fc2.weight": "model-00001-of-00002.safetensors",
622
+ "vision_model.vision_tower.vision_model.encoder.layers.17.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
623
+ "vision_model.vision_tower.vision_model.encoder.layers.17.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
624
+ "vision_model.vision_tower.vision_model.encoder.layers.17.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
625
+ "vision_model.vision_tower.vision_model.encoder.layers.17.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
626
+ "vision_model.vision_tower.vision_model.encoder.layers.17.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
627
+ "vision_model.vision_tower.vision_model.encoder.layers.17.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
628
+ "vision_model.vision_tower.vision_model.encoder.layers.17.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
629
+ "vision_model.vision_tower.vision_model.encoder.layers.17.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
630
+ "vision_model.vision_tower.vision_model.encoder.layers.18.layer_norm1.bias": "model-00001-of-00002.safetensors",
631
+ "vision_model.vision_tower.vision_model.encoder.layers.18.layer_norm1.weight": "model-00001-of-00002.safetensors",
632
+ "vision_model.vision_tower.vision_model.encoder.layers.18.layer_norm2.bias": "model-00001-of-00002.safetensors",
633
+ "vision_model.vision_tower.vision_model.encoder.layers.18.layer_norm2.weight": "model-00001-of-00002.safetensors",
634
+ "vision_model.vision_tower.vision_model.encoder.layers.18.mlp.fc1.bias": "model-00001-of-00002.safetensors",
635
+ "vision_model.vision_tower.vision_model.encoder.layers.18.mlp.fc1.weight": "model-00001-of-00002.safetensors",
636
+ "vision_model.vision_tower.vision_model.encoder.layers.18.mlp.fc2.bias": "model-00001-of-00002.safetensors",
637
+ "vision_model.vision_tower.vision_model.encoder.layers.18.mlp.fc2.weight": "model-00001-of-00002.safetensors",
638
+ "vision_model.vision_tower.vision_model.encoder.layers.18.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
639
+ "vision_model.vision_tower.vision_model.encoder.layers.18.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
640
+ "vision_model.vision_tower.vision_model.encoder.layers.18.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
641
+ "vision_model.vision_tower.vision_model.encoder.layers.18.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
642
+ "vision_model.vision_tower.vision_model.encoder.layers.18.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
643
+ "vision_model.vision_tower.vision_model.encoder.layers.18.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
644
+ "vision_model.vision_tower.vision_model.encoder.layers.18.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
645
+ "vision_model.vision_tower.vision_model.encoder.layers.18.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
646
+ "vision_model.vision_tower.vision_model.encoder.layers.19.layer_norm1.bias": "model-00001-of-00002.safetensors",
647
+ "vision_model.vision_tower.vision_model.encoder.layers.19.layer_norm1.weight": "model-00001-of-00002.safetensors",
648
+ "vision_model.vision_tower.vision_model.encoder.layers.19.layer_norm2.bias": "model-00001-of-00002.safetensors",
649
+ "vision_model.vision_tower.vision_model.encoder.layers.19.layer_norm2.weight": "model-00001-of-00002.safetensors",
650
+ "vision_model.vision_tower.vision_model.encoder.layers.19.mlp.fc1.bias": "model-00001-of-00002.safetensors",
651
+ "vision_model.vision_tower.vision_model.encoder.layers.19.mlp.fc1.weight": "model-00001-of-00002.safetensors",
652
+ "vision_model.vision_tower.vision_model.encoder.layers.19.mlp.fc2.bias": "model-00001-of-00002.safetensors",
653
+ "vision_model.vision_tower.vision_model.encoder.layers.19.mlp.fc2.weight": "model-00001-of-00002.safetensors",
654
+ "vision_model.vision_tower.vision_model.encoder.layers.19.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
655
+ "vision_model.vision_tower.vision_model.encoder.layers.19.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
656
+ "vision_model.vision_tower.vision_model.encoder.layers.19.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
657
+ "vision_model.vision_tower.vision_model.encoder.layers.19.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
658
+ "vision_model.vision_tower.vision_model.encoder.layers.19.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
659
+ "vision_model.vision_tower.vision_model.encoder.layers.19.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
660
+ "vision_model.vision_tower.vision_model.encoder.layers.19.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
661
+ "vision_model.vision_tower.vision_model.encoder.layers.19.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
662
+ "vision_model.vision_tower.vision_model.encoder.layers.2.layer_norm1.bias": "model-00001-of-00002.safetensors",
663
+ "vision_model.vision_tower.vision_model.encoder.layers.2.layer_norm1.weight": "model-00001-of-00002.safetensors",
664
+ "vision_model.vision_tower.vision_model.encoder.layers.2.layer_norm2.bias": "model-00001-of-00002.safetensors",
665
+ "vision_model.vision_tower.vision_model.encoder.layers.2.layer_norm2.weight": "model-00001-of-00002.safetensors",
666
+ "vision_model.vision_tower.vision_model.encoder.layers.2.mlp.fc1.bias": "model-00001-of-00002.safetensors",
667
+ "vision_model.vision_tower.vision_model.encoder.layers.2.mlp.fc1.weight": "model-00001-of-00002.safetensors",
668
+ "vision_model.vision_tower.vision_model.encoder.layers.2.mlp.fc2.bias": "model-00001-of-00002.safetensors",
669
+ "vision_model.vision_tower.vision_model.encoder.layers.2.mlp.fc2.weight": "model-00001-of-00002.safetensors",
670
+ "vision_model.vision_tower.vision_model.encoder.layers.2.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
671
+ "vision_model.vision_tower.vision_model.encoder.layers.2.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
672
+ "vision_model.vision_tower.vision_model.encoder.layers.2.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
673
+ "vision_model.vision_tower.vision_model.encoder.layers.2.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
674
+ "vision_model.vision_tower.vision_model.encoder.layers.2.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
675
+ "vision_model.vision_tower.vision_model.encoder.layers.2.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
676
+ "vision_model.vision_tower.vision_model.encoder.layers.2.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
677
+ "vision_model.vision_tower.vision_model.encoder.layers.2.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
678
+ "vision_model.vision_tower.vision_model.encoder.layers.20.layer_norm1.bias": "model-00001-of-00002.safetensors",
679
+ "vision_model.vision_tower.vision_model.encoder.layers.20.layer_norm1.weight": "model-00001-of-00002.safetensors",
680
+ "vision_model.vision_tower.vision_model.encoder.layers.20.layer_norm2.bias": "model-00001-of-00002.safetensors",
681
+ "vision_model.vision_tower.vision_model.encoder.layers.20.layer_norm2.weight": "model-00001-of-00002.safetensors",
682
+ "vision_model.vision_tower.vision_model.encoder.layers.20.mlp.fc1.bias": "model-00001-of-00002.safetensors",
683
+ "vision_model.vision_tower.vision_model.encoder.layers.20.mlp.fc1.weight": "model-00001-of-00002.safetensors",
684
+ "vision_model.vision_tower.vision_model.encoder.layers.20.mlp.fc2.bias": "model-00001-of-00002.safetensors",
685
+ "vision_model.vision_tower.vision_model.encoder.layers.20.mlp.fc2.weight": "model-00001-of-00002.safetensors",
686
+ "vision_model.vision_tower.vision_model.encoder.layers.20.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
687
+ "vision_model.vision_tower.vision_model.encoder.layers.20.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
688
+ "vision_model.vision_tower.vision_model.encoder.layers.20.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
689
+ "vision_model.vision_tower.vision_model.encoder.layers.20.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
690
+ "vision_model.vision_tower.vision_model.encoder.layers.20.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
691
+ "vision_model.vision_tower.vision_model.encoder.layers.20.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
692
+ "vision_model.vision_tower.vision_model.encoder.layers.20.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
693
+ "vision_model.vision_tower.vision_model.encoder.layers.20.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
694
+ "vision_model.vision_tower.vision_model.encoder.layers.21.layer_norm1.bias": "model-00001-of-00002.safetensors",
695
+ "vision_model.vision_tower.vision_model.encoder.layers.21.layer_norm1.weight": "model-00001-of-00002.safetensors",
696
+ "vision_model.vision_tower.vision_model.encoder.layers.21.layer_norm2.bias": "model-00001-of-00002.safetensors",
697
+ "vision_model.vision_tower.vision_model.encoder.layers.21.layer_norm2.weight": "model-00001-of-00002.safetensors",
698
+ "vision_model.vision_tower.vision_model.encoder.layers.21.mlp.fc1.bias": "model-00001-of-00002.safetensors",
699
+ "vision_model.vision_tower.vision_model.encoder.layers.21.mlp.fc1.weight": "model-00001-of-00002.safetensors",
700
+ "vision_model.vision_tower.vision_model.encoder.layers.21.mlp.fc2.bias": "model-00001-of-00002.safetensors",
701
+ "vision_model.vision_tower.vision_model.encoder.layers.21.mlp.fc2.weight": "model-00001-of-00002.safetensors",
702
+ "vision_model.vision_tower.vision_model.encoder.layers.21.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
703
+ "vision_model.vision_tower.vision_model.encoder.layers.21.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
704
+ "vision_model.vision_tower.vision_model.encoder.layers.21.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
705
+ "vision_model.vision_tower.vision_model.encoder.layers.21.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
706
+ "vision_model.vision_tower.vision_model.encoder.layers.21.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
707
+ "vision_model.vision_tower.vision_model.encoder.layers.21.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
708
+ "vision_model.vision_tower.vision_model.encoder.layers.21.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
709
+ "vision_model.vision_tower.vision_model.encoder.layers.21.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
710
+ "vision_model.vision_tower.vision_model.encoder.layers.22.layer_norm1.bias": "model-00001-of-00002.safetensors",
711
+ "vision_model.vision_tower.vision_model.encoder.layers.22.layer_norm1.weight": "model-00001-of-00002.safetensors",
712
+ "vision_model.vision_tower.vision_model.encoder.layers.22.layer_norm2.bias": "model-00001-of-00002.safetensors",
713
+ "vision_model.vision_tower.vision_model.encoder.layers.22.layer_norm2.weight": "model-00001-of-00002.safetensors",
714
+ "vision_model.vision_tower.vision_model.encoder.layers.22.mlp.fc1.bias": "model-00001-of-00002.safetensors",
715
+ "vision_model.vision_tower.vision_model.encoder.layers.22.mlp.fc1.weight": "model-00001-of-00002.safetensors",
716
+ "vision_model.vision_tower.vision_model.encoder.layers.22.mlp.fc2.bias": "model-00001-of-00002.safetensors",
717
+ "vision_model.vision_tower.vision_model.encoder.layers.22.mlp.fc2.weight": "model-00001-of-00002.safetensors",
718
+ "vision_model.vision_tower.vision_model.encoder.layers.22.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
719
+ "vision_model.vision_tower.vision_model.encoder.layers.22.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
720
+ "vision_model.vision_tower.vision_model.encoder.layers.22.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
721
+ "vision_model.vision_tower.vision_model.encoder.layers.22.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
722
+ "vision_model.vision_tower.vision_model.encoder.layers.22.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
723
+ "vision_model.vision_tower.vision_model.encoder.layers.22.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
724
+ "vision_model.vision_tower.vision_model.encoder.layers.22.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
725
+ "vision_model.vision_tower.vision_model.encoder.layers.22.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
726
+ "vision_model.vision_tower.vision_model.encoder.layers.23.layer_norm1.bias": "model-00001-of-00002.safetensors",
727
+ "vision_model.vision_tower.vision_model.encoder.layers.23.layer_norm1.weight": "model-00001-of-00002.safetensors",
728
+ "vision_model.vision_tower.vision_model.encoder.layers.23.layer_norm2.bias": "model-00001-of-00002.safetensors",
729
+ "vision_model.vision_tower.vision_model.encoder.layers.23.layer_norm2.weight": "model-00001-of-00002.safetensors",
730
+ "vision_model.vision_tower.vision_model.encoder.layers.23.mlp.fc1.bias": "model-00001-of-00002.safetensors",
731
+ "vision_model.vision_tower.vision_model.encoder.layers.23.mlp.fc1.weight": "model-00001-of-00002.safetensors",
732
+ "vision_model.vision_tower.vision_model.encoder.layers.23.mlp.fc2.bias": "model-00001-of-00002.safetensors",
733
+ "vision_model.vision_tower.vision_model.encoder.layers.23.mlp.fc2.weight": "model-00001-of-00002.safetensors",
734
+ "vision_model.vision_tower.vision_model.encoder.layers.23.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
735
+ "vision_model.vision_tower.vision_model.encoder.layers.23.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
736
+ "vision_model.vision_tower.vision_model.encoder.layers.23.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
737
+ "vision_model.vision_tower.vision_model.encoder.layers.23.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
738
+ "vision_model.vision_tower.vision_model.encoder.layers.23.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
739
+ "vision_model.vision_tower.vision_model.encoder.layers.23.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
740
+ "vision_model.vision_tower.vision_model.encoder.layers.23.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
741
+ "vision_model.vision_tower.vision_model.encoder.layers.23.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
742
+ "vision_model.vision_tower.vision_model.encoder.layers.24.layer_norm1.bias": "model-00001-of-00002.safetensors",
743
+ "vision_model.vision_tower.vision_model.encoder.layers.24.layer_norm1.weight": "model-00001-of-00002.safetensors",
744
+ "vision_model.vision_tower.vision_model.encoder.layers.24.layer_norm2.bias": "model-00001-of-00002.safetensors",
745
+ "vision_model.vision_tower.vision_model.encoder.layers.24.layer_norm2.weight": "model-00001-of-00002.safetensors",
746
+ "vision_model.vision_tower.vision_model.encoder.layers.24.mlp.fc1.bias": "model-00001-of-00002.safetensors",
747
+ "vision_model.vision_tower.vision_model.encoder.layers.24.mlp.fc1.weight": "model-00001-of-00002.safetensors",
748
+ "vision_model.vision_tower.vision_model.encoder.layers.24.mlp.fc2.bias": "model-00001-of-00002.safetensors",
749
+ "vision_model.vision_tower.vision_model.encoder.layers.24.mlp.fc2.weight": "model-00001-of-00002.safetensors",
750
+ "vision_model.vision_tower.vision_model.encoder.layers.24.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
751
+ "vision_model.vision_tower.vision_model.encoder.layers.24.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
752
+ "vision_model.vision_tower.vision_model.encoder.layers.24.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
753
+ "vision_model.vision_tower.vision_model.encoder.layers.24.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
754
+ "vision_model.vision_tower.vision_model.encoder.layers.24.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
755
+ "vision_model.vision_tower.vision_model.encoder.layers.24.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
756
+ "vision_model.vision_tower.vision_model.encoder.layers.24.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
757
+ "vision_model.vision_tower.vision_model.encoder.layers.24.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
758
+ "vision_model.vision_tower.vision_model.encoder.layers.25.layer_norm1.bias": "model-00001-of-00002.safetensors",
759
+ "vision_model.vision_tower.vision_model.encoder.layers.25.layer_norm1.weight": "model-00001-of-00002.safetensors",
760
+ "vision_model.vision_tower.vision_model.encoder.layers.25.layer_norm2.bias": "model-00001-of-00002.safetensors",
761
+ "vision_model.vision_tower.vision_model.encoder.layers.25.layer_norm2.weight": "model-00001-of-00002.safetensors",
762
+ "vision_model.vision_tower.vision_model.encoder.layers.25.mlp.fc1.bias": "model-00001-of-00002.safetensors",
763
+ "vision_model.vision_tower.vision_model.encoder.layers.25.mlp.fc1.weight": "model-00001-of-00002.safetensors",
764
+ "vision_model.vision_tower.vision_model.encoder.layers.25.mlp.fc2.bias": "model-00001-of-00002.safetensors",
765
+ "vision_model.vision_tower.vision_model.encoder.layers.25.mlp.fc2.weight": "model-00001-of-00002.safetensors",
766
+ "vision_model.vision_tower.vision_model.encoder.layers.25.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
767
+ "vision_model.vision_tower.vision_model.encoder.layers.25.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
768
+ "vision_model.vision_tower.vision_model.encoder.layers.25.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
769
+ "vision_model.vision_tower.vision_model.encoder.layers.25.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
770
+ "vision_model.vision_tower.vision_model.encoder.layers.25.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
771
+ "vision_model.vision_tower.vision_model.encoder.layers.25.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
772
+ "vision_model.vision_tower.vision_model.encoder.layers.25.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
773
+ "vision_model.vision_tower.vision_model.encoder.layers.25.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
774
+ "vision_model.vision_tower.vision_model.encoder.layers.26.layer_norm1.bias": "model-00001-of-00002.safetensors",
775
+ "vision_model.vision_tower.vision_model.encoder.layers.26.layer_norm1.weight": "model-00001-of-00002.safetensors",
776
+ "vision_model.vision_tower.vision_model.encoder.layers.26.layer_norm2.bias": "model-00001-of-00002.safetensors",
777
+ "vision_model.vision_tower.vision_model.encoder.layers.26.layer_norm2.weight": "model-00001-of-00002.safetensors",
778
+ "vision_model.vision_tower.vision_model.encoder.layers.26.mlp.fc1.bias": "model-00001-of-00002.safetensors",
779
+ "vision_model.vision_tower.vision_model.encoder.layers.26.mlp.fc1.weight": "model-00001-of-00002.safetensors",
780
+ "vision_model.vision_tower.vision_model.encoder.layers.26.mlp.fc2.bias": "model-00001-of-00002.safetensors",
781
+ "vision_model.vision_tower.vision_model.encoder.layers.26.mlp.fc2.weight": "model-00001-of-00002.safetensors",
782
+ "vision_model.vision_tower.vision_model.encoder.layers.26.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
783
+ "vision_model.vision_tower.vision_model.encoder.layers.26.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
784
+ "vision_model.vision_tower.vision_model.encoder.layers.26.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
785
+ "vision_model.vision_tower.vision_model.encoder.layers.26.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
786
+ "vision_model.vision_tower.vision_model.encoder.layers.26.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
787
+ "vision_model.vision_tower.vision_model.encoder.layers.26.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
788
+ "vision_model.vision_tower.vision_model.encoder.layers.26.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
789
+ "vision_model.vision_tower.vision_model.encoder.layers.26.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
790
+ "vision_model.vision_tower.vision_model.encoder.layers.3.layer_norm1.bias": "model-00001-of-00002.safetensors",
791
+ "vision_model.vision_tower.vision_model.encoder.layers.3.layer_norm1.weight": "model-00001-of-00002.safetensors",
792
+ "vision_model.vision_tower.vision_model.encoder.layers.3.layer_norm2.bias": "model-00001-of-00002.safetensors",
793
+ "vision_model.vision_tower.vision_model.encoder.layers.3.layer_norm2.weight": "model-00001-of-00002.safetensors",
794
+ "vision_model.vision_tower.vision_model.encoder.layers.3.mlp.fc1.bias": "model-00001-of-00002.safetensors",
795
+ "vision_model.vision_tower.vision_model.encoder.layers.3.mlp.fc1.weight": "model-00001-of-00002.safetensors",
796
+ "vision_model.vision_tower.vision_model.encoder.layers.3.mlp.fc2.bias": "model-00001-of-00002.safetensors",
797
+ "vision_model.vision_tower.vision_model.encoder.layers.3.mlp.fc2.weight": "model-00001-of-00002.safetensors",
798
+ "vision_model.vision_tower.vision_model.encoder.layers.3.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
799
+ "vision_model.vision_tower.vision_model.encoder.layers.3.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
800
+ "vision_model.vision_tower.vision_model.encoder.layers.3.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
801
+ "vision_model.vision_tower.vision_model.encoder.layers.3.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
802
+ "vision_model.vision_tower.vision_model.encoder.layers.3.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
803
+ "vision_model.vision_tower.vision_model.encoder.layers.3.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
804
+ "vision_model.vision_tower.vision_model.encoder.layers.3.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
805
+ "vision_model.vision_tower.vision_model.encoder.layers.3.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
806
+ "vision_model.vision_tower.vision_model.encoder.layers.4.layer_norm1.bias": "model-00001-of-00002.safetensors",
807
+ "vision_model.vision_tower.vision_model.encoder.layers.4.layer_norm1.weight": "model-00001-of-00002.safetensors",
808
+ "vision_model.vision_tower.vision_model.encoder.layers.4.layer_norm2.bias": "model-00001-of-00002.safetensors",
809
+ "vision_model.vision_tower.vision_model.encoder.layers.4.layer_norm2.weight": "model-00001-of-00002.safetensors",
810
+ "vision_model.vision_tower.vision_model.encoder.layers.4.mlp.fc1.bias": "model-00001-of-00002.safetensors",
811
+ "vision_model.vision_tower.vision_model.encoder.layers.4.mlp.fc1.weight": "model-00001-of-00002.safetensors",
812
+ "vision_model.vision_tower.vision_model.encoder.layers.4.mlp.fc2.bias": "model-00001-of-00002.safetensors",
813
+ "vision_model.vision_tower.vision_model.encoder.layers.4.mlp.fc2.weight": "model-00001-of-00002.safetensors",
814
+ "vision_model.vision_tower.vision_model.encoder.layers.4.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
815
+ "vision_model.vision_tower.vision_model.encoder.layers.4.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
816
+ "vision_model.vision_tower.vision_model.encoder.layers.4.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
817
+ "vision_model.vision_tower.vision_model.encoder.layers.4.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
818
+ "vision_model.vision_tower.vision_model.encoder.layers.4.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
819
+ "vision_model.vision_tower.vision_model.encoder.layers.4.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
820
+ "vision_model.vision_tower.vision_model.encoder.layers.4.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
821
+ "vision_model.vision_tower.vision_model.encoder.layers.4.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
822
+ "vision_model.vision_tower.vision_model.encoder.layers.5.layer_norm1.bias": "model-00001-of-00002.safetensors",
823
+ "vision_model.vision_tower.vision_model.encoder.layers.5.layer_norm1.weight": "model-00001-of-00002.safetensors",
824
+ "vision_model.vision_tower.vision_model.encoder.layers.5.layer_norm2.bias": "model-00001-of-00002.safetensors",
825
+ "vision_model.vision_tower.vision_model.encoder.layers.5.layer_norm2.weight": "model-00001-of-00002.safetensors",
826
+ "vision_model.vision_tower.vision_model.encoder.layers.5.mlp.fc1.bias": "model-00001-of-00002.safetensors",
827
+ "vision_model.vision_tower.vision_model.encoder.layers.5.mlp.fc1.weight": "model-00001-of-00002.safetensors",
828
+ "vision_model.vision_tower.vision_model.encoder.layers.5.mlp.fc2.bias": "model-00001-of-00002.safetensors",
829
+ "vision_model.vision_tower.vision_model.encoder.layers.5.mlp.fc2.weight": "model-00001-of-00002.safetensors",
830
+ "vision_model.vision_tower.vision_model.encoder.layers.5.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
831
+ "vision_model.vision_tower.vision_model.encoder.layers.5.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
832
+ "vision_model.vision_tower.vision_model.encoder.layers.5.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
833
+ "vision_model.vision_tower.vision_model.encoder.layers.5.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
834
+ "vision_model.vision_tower.vision_model.encoder.layers.5.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
835
+ "vision_model.vision_tower.vision_model.encoder.layers.5.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
836
+ "vision_model.vision_tower.vision_model.encoder.layers.5.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
837
+ "vision_model.vision_tower.vision_model.encoder.layers.5.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
838
+ "vision_model.vision_tower.vision_model.encoder.layers.6.layer_norm1.bias": "model-00001-of-00002.safetensors",
839
+ "vision_model.vision_tower.vision_model.encoder.layers.6.layer_norm1.weight": "model-00001-of-00002.safetensors",
840
+ "vision_model.vision_tower.vision_model.encoder.layers.6.layer_norm2.bias": "model-00001-of-00002.safetensors",
841
+ "vision_model.vision_tower.vision_model.encoder.layers.6.layer_norm2.weight": "model-00001-of-00002.safetensors",
842
+ "vision_model.vision_tower.vision_model.encoder.layers.6.mlp.fc1.bias": "model-00001-of-00002.safetensors",
843
+ "vision_model.vision_tower.vision_model.encoder.layers.6.mlp.fc1.weight": "model-00001-of-00002.safetensors",
844
+ "vision_model.vision_tower.vision_model.encoder.layers.6.mlp.fc2.bias": "model-00001-of-00002.safetensors",
845
+ "vision_model.vision_tower.vision_model.encoder.layers.6.mlp.fc2.weight": "model-00001-of-00002.safetensors",
846
+ "vision_model.vision_tower.vision_model.encoder.layers.6.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
847
+ "vision_model.vision_tower.vision_model.encoder.layers.6.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
848
+ "vision_model.vision_tower.vision_model.encoder.layers.6.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
849
+ "vision_model.vision_tower.vision_model.encoder.layers.6.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
850
+ "vision_model.vision_tower.vision_model.encoder.layers.6.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
851
+ "vision_model.vision_tower.vision_model.encoder.layers.6.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
852
+ "vision_model.vision_tower.vision_model.encoder.layers.6.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
853
+ "vision_model.vision_tower.vision_model.encoder.layers.6.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
854
+ "vision_model.vision_tower.vision_model.encoder.layers.7.layer_norm1.bias": "model-00001-of-00002.safetensors",
855
+ "vision_model.vision_tower.vision_model.encoder.layers.7.layer_norm1.weight": "model-00001-of-00002.safetensors",
856
+ "vision_model.vision_tower.vision_model.encoder.layers.7.layer_norm2.bias": "model-00001-of-00002.safetensors",
857
+ "vision_model.vision_tower.vision_model.encoder.layers.7.layer_norm2.weight": "model-00001-of-00002.safetensors",
858
+ "vision_model.vision_tower.vision_model.encoder.layers.7.mlp.fc1.bias": "model-00001-of-00002.safetensors",
859
+ "vision_model.vision_tower.vision_model.encoder.layers.7.mlp.fc1.weight": "model-00001-of-00002.safetensors",
860
+ "vision_model.vision_tower.vision_model.encoder.layers.7.mlp.fc2.bias": "model-00001-of-00002.safetensors",
861
+ "vision_model.vision_tower.vision_model.encoder.layers.7.mlp.fc2.weight": "model-00001-of-00002.safetensors",
862
+ "vision_model.vision_tower.vision_model.encoder.layers.7.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
863
+ "vision_model.vision_tower.vision_model.encoder.layers.7.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
864
+ "vision_model.vision_tower.vision_model.encoder.layers.7.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
865
+ "vision_model.vision_tower.vision_model.encoder.layers.7.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
866
+ "vision_model.vision_tower.vision_model.encoder.layers.7.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
867
+ "vision_model.vision_tower.vision_model.encoder.layers.7.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
868
+ "vision_model.vision_tower.vision_model.encoder.layers.7.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
869
+ "vision_model.vision_tower.vision_model.encoder.layers.7.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
870
+ "vision_model.vision_tower.vision_model.encoder.layers.8.layer_norm1.bias": "model-00001-of-00002.safetensors",
871
+ "vision_model.vision_tower.vision_model.encoder.layers.8.layer_norm1.weight": "model-00001-of-00002.safetensors",
872
+ "vision_model.vision_tower.vision_model.encoder.layers.8.layer_norm2.bias": "model-00001-of-00002.safetensors",
873
+ "vision_model.vision_tower.vision_model.encoder.layers.8.layer_norm2.weight": "model-00001-of-00002.safetensors",
874
+ "vision_model.vision_tower.vision_model.encoder.layers.8.mlp.fc1.bias": "model-00001-of-00002.safetensors",
875
+ "vision_model.vision_tower.vision_model.encoder.layers.8.mlp.fc1.weight": "model-00001-of-00002.safetensors",
876
+ "vision_model.vision_tower.vision_model.encoder.layers.8.mlp.fc2.bias": "model-00001-of-00002.safetensors",
877
+ "vision_model.vision_tower.vision_model.encoder.layers.8.mlp.fc2.weight": "model-00001-of-00002.safetensors",
878
+ "vision_model.vision_tower.vision_model.encoder.layers.8.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
879
+ "vision_model.vision_tower.vision_model.encoder.layers.8.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
880
+ "vision_model.vision_tower.vision_model.encoder.layers.8.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
881
+ "vision_model.vision_tower.vision_model.encoder.layers.8.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
882
+ "vision_model.vision_tower.vision_model.encoder.layers.8.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
883
+ "vision_model.vision_tower.vision_model.encoder.layers.8.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
884
+ "vision_model.vision_tower.vision_model.encoder.layers.8.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
885
+ "vision_model.vision_tower.vision_model.encoder.layers.8.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
886
+ "vision_model.vision_tower.vision_model.encoder.layers.9.layer_norm1.bias": "model-00001-of-00002.safetensors",
887
+ "vision_model.vision_tower.vision_model.encoder.layers.9.layer_norm1.weight": "model-00001-of-00002.safetensors",
888
+ "vision_model.vision_tower.vision_model.encoder.layers.9.layer_norm2.bias": "model-00001-of-00002.safetensors",
889
+ "vision_model.vision_tower.vision_model.encoder.layers.9.layer_norm2.weight": "model-00001-of-00002.safetensors",
890
+ "vision_model.vision_tower.vision_model.encoder.layers.9.mlp.fc1.bias": "model-00001-of-00002.safetensors",
891
+ "vision_model.vision_tower.vision_model.encoder.layers.9.mlp.fc1.weight": "model-00001-of-00002.safetensors",
892
+ "vision_model.vision_tower.vision_model.encoder.layers.9.mlp.fc2.bias": "model-00001-of-00002.safetensors",
893
+ "vision_model.vision_tower.vision_model.encoder.layers.9.mlp.fc2.weight": "model-00001-of-00002.safetensors",
894
+ "vision_model.vision_tower.vision_model.encoder.layers.9.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
895
+ "vision_model.vision_tower.vision_model.encoder.layers.9.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
896
+ "vision_model.vision_tower.vision_model.encoder.layers.9.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
897
+ "vision_model.vision_tower.vision_model.encoder.layers.9.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
898
+ "vision_model.vision_tower.vision_model.encoder.layers.9.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
899
+ "vision_model.vision_tower.vision_model.encoder.layers.9.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
900
+ "vision_model.vision_tower.vision_model.encoder.layers.9.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
901
+ "vision_model.vision_tower.vision_model.encoder.layers.9.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
902
+ "vision_model.vision_tower.vision_model.head.attention.in_proj_bias": "model-00001-of-00002.safetensors",
903
+ "vision_model.vision_tower.vision_model.head.attention.in_proj_weight": "model-00001-of-00002.safetensors",
904
+ "vision_model.vision_tower.vision_model.head.attention.out_proj.bias": "model-00001-of-00002.safetensors",
905
+ "vision_model.vision_tower.vision_model.head.attention.out_proj.weight": "model-00001-of-00002.safetensors",
906
+ "vision_model.vision_tower.vision_model.head.layernorm.bias": "model-00001-of-00002.safetensors",
907
+ "vision_model.vision_tower.vision_model.head.layernorm.weight": "model-00001-of-00002.safetensors",
908
+ "vision_model.vision_tower.vision_model.head.mlp.fc1.bias": "model-00001-of-00002.safetensors",
909
+ "vision_model.vision_tower.vision_model.head.mlp.fc1.weight": "model-00001-of-00002.safetensors",
910
+ "vision_model.vision_tower.vision_model.head.mlp.fc2.bias": "model-00001-of-00002.safetensors",
911
+ "vision_model.vision_tower.vision_model.head.mlp.fc2.weight": "model-00001-of-00002.safetensors",
912
+ "vision_model.vision_tower.vision_model.head.probe": "model-00001-of-00002.safetensors",
913
+ "vision_model.vision_tower.vision_model.post_layernorm.bias": "model-00001-of-00002.safetensors",
914
+ "vision_model.vision_tower.vision_model.post_layernorm.weight": "model-00001-of-00002.safetensors"
915
+ }
916
+ }
modeling_llava.py ADDED
@@ -0,0 +1,1789 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ import math
3
+ from dataclasses import dataclass
4
+ from typing import List, Optional, Tuple, Union
5
+
6
+ import torch
7
+ import torch.nn.functional as F
8
+ import torch.utils.checkpoint
9
+ from torch import nn
10
+ from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
11
+ from transformers import PreTrainedModel, SiglipVisionModel
12
+ from transformers.activations import ACT2FN
13
+ from transformers.cache_utils import Cache, DynamicCache
14
+ from transformers.modeling_attn_mask_utils import _prepare_4d_causal_attention_mask
15
+ from transformers.modeling_outputs import (
16
+ BaseModelOutputWithPast,
17
+ CausalLMOutputWithPast,
18
+ ModelOutput,
19
+ SequenceClassifierOutputWithPast,
20
+ TokenClassifierOutput,
21
+ )
22
+ from transformers.utils import (
23
+ is_flash_attn_2_available,
24
+ is_flash_attn_greater_or_equal_2_10,
25
+ logging,
26
+ )
27
+
28
+ try:
29
+ from flash_attn import flash_attn_func, flash_attn_varlen_func
30
+ from flash_attn.bert_padding import index_first_axis, pad_input, unpad_input # noqa
31
+ except Exception as exp:
32
+ print(exp)
33
+
34
+
35
+ from transformers.configuration_utils import PretrainedConfig
36
+ from transformers import SiglipVisionConfig
37
+
38
+
39
+ logger = logging.get_logger(__name__)
40
+
41
+
42
+ class PhiConfig(PretrainedConfig):
43
+ model_type = "phi"
44
+ keys_to_ignore_at_inference = ["past_key_values"]
45
+
46
+ def __init__(
47
+ self,
48
+ vocab_size=51200,
49
+ hidden_size=2048,
50
+ intermediate_size=8192,
51
+ num_hidden_layers=24,
52
+ num_attention_heads=32,
53
+ num_key_value_heads=None,
54
+ resid_pdrop=0.0,
55
+ embd_pdrop=0.0,
56
+ attention_dropout=0.0,
57
+ hidden_act="gelu_new",
58
+ max_position_embeddings=2048,
59
+ initializer_range=0.02,
60
+ layer_norm_eps=1e-5,
61
+ use_cache=True,
62
+ tie_word_embeddings=False,
63
+ rope_theta=10000.0,
64
+ rope_scaling=None,
65
+ partial_rotary_factor=0.5,
66
+ qk_layernorm=False,
67
+ bos_token_id=1,
68
+ eos_token_id=2,
69
+ **kwargs,
70
+ ):
71
+ self.vocab_size = vocab_size
72
+ self.hidden_size = hidden_size
73
+ self.intermediate_size = intermediate_size
74
+ self.num_hidden_layers = num_hidden_layers
75
+ self.num_attention_heads = num_attention_heads
76
+
77
+ if num_key_value_heads is None:
78
+ num_key_value_heads = num_attention_heads
79
+
80
+ self.num_key_value_heads = num_key_value_heads
81
+ self.resid_pdrop = resid_pdrop
82
+ self.embd_pdrop = embd_pdrop
83
+ self.attention_dropout = attention_dropout
84
+ self.hidden_act = hidden_act
85
+ self.max_position_embeddings = max_position_embeddings
86
+ self.initializer_range = initializer_range
87
+ self.layer_norm_eps = layer_norm_eps
88
+ self.use_cache = use_cache
89
+ self.rope_theta = rope_theta
90
+ self.rope_scaling = rope_scaling
91
+ self.partial_rotary_factor = partial_rotary_factor
92
+ self.qk_layernorm = qk_layernorm
93
+ self._rope_scaling_validation()
94
+
95
+ super().__init__(
96
+ bos_token_id=bos_token_id,
97
+ eos_token_id=eos_token_id,
98
+ tie_word_embeddings=tie_word_embeddings,
99
+ **kwargs,
100
+ )
101
+
102
+ def _rope_scaling_validation(self):
103
+ """
104
+ Validate the `rope_scaling` configuration.
105
+ """
106
+ if self.rope_scaling is None:
107
+ return
108
+
109
+ if not isinstance(self.rope_scaling, dict) or len(self.rope_scaling) != 2:
110
+ raise ValueError(
111
+ "`rope_scaling` must be a dictionary with with two fields, `type` and `factor`, "
112
+ f"got {self.rope_scaling}"
113
+ )
114
+ rope_scaling_type = self.rope_scaling.get("type", None)
115
+ rope_scaling_factor = self.rope_scaling.get("factor", None)
116
+ if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic"]:
117
+ raise ValueError(
118
+ f"`rope_scaling`'s type field must be one of ['linear', 'dynamic'], got {rope_scaling_type}"
119
+ )
120
+ if (
121
+ rope_scaling_factor is None
122
+ or not isinstance(rope_scaling_factor, float)
123
+ or rope_scaling_factor <= 1.0
124
+ ):
125
+ raise ValueError(
126
+ f"`rope_scaling`'s factor field must be a float > 1, got {rope_scaling_factor}"
127
+ )
128
+
129
+
130
+ class LlavaConfig(PretrainedConfig):
131
+ model_type = "mc-llava"
132
+ is_composition = False
133
+
134
+ def __init__(
135
+ self,
136
+ text_config=None,
137
+ vision_config=None,
138
+ ignore_index=-100,
139
+ image_token_index=50297,
140
+ projector_hidden_act="gelu",
141
+ projector_tokens_num=1,
142
+ vocab_size=51200,
143
+ **kwargs,
144
+ ):
145
+ self.ignore_index = ignore_index
146
+ self.image_token_index = image_token_index
147
+ self.projector_hidden_act = projector_hidden_act
148
+ self.projector_tokens_num = projector_tokens_num
149
+ self.vocab_size = vocab_size
150
+
151
+ self.text_config = text_config
152
+ if isinstance(self.text_config, dict):
153
+ text_config["model_type"] = (
154
+ text_config["model_type"] if "model_type" in text_config else "phi"
155
+ )
156
+ self.text_config = PhiConfig(**text_config)
157
+ self.vocab_size = self.text_config.vocab_size
158
+
159
+ self.vision_config = vision_config
160
+ if isinstance(self.vision_config, dict):
161
+ self.vision_config = SiglipVisionConfig(**vision_config)
162
+ self.vision_embed_dim = self.vision_config.hidden_size
163
+
164
+ super().__init__(**kwargs)
165
+
166
+
167
+ # Copied from transformers.models.llama.modeling_llama._get_unpad_data
168
+ def _get_unpad_data(attention_mask):
169
+ seqlens_in_batch = attention_mask.sum(dim=-1, dtype=torch.int32)
170
+ indices = torch.nonzero(attention_mask.flatten(), as_tuple=False).flatten()
171
+ max_seqlen_in_batch = seqlens_in_batch.max().item()
172
+ cu_seqlens = F.pad(
173
+ torch.cumsum(seqlens_in_batch, dim=0, dtype=torch.torch.int32), (1, 0)
174
+ )
175
+ return (
176
+ indices,
177
+ cu_seqlens,
178
+ max_seqlen_in_batch,
179
+ )
180
+
181
+
182
+ # Copied from transformers.models.llama.modeling_llama.LlamaRotaryEmbedding with Llama->Phi
183
+ class PhiRotaryEmbedding(nn.Module):
184
+ def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None):
185
+ super().__init__()
186
+
187
+ self.dim = dim
188
+ self.max_position_embeddings = max_position_embeddings
189
+ self.base = base
190
+ inv_freq = 1.0 / (
191
+ self.base ** (torch.arange(0, self.dim, 2).float().to(device) / self.dim)
192
+ )
193
+ self.register_buffer("inv_freq", inv_freq, persistent=False)
194
+
195
+ # Build here to make `torch.jit.trace` work.
196
+ self._set_cos_sin_cache(
197
+ seq_len=max_position_embeddings,
198
+ device=self.inv_freq.device,
199
+ dtype=torch.get_default_dtype(),
200
+ )
201
+
202
+ def _set_cos_sin_cache(self, seq_len, device, dtype):
203
+ self.max_seq_len_cached = seq_len
204
+ t = torch.arange(
205
+ self.max_seq_len_cached, device=device, dtype=self.inv_freq.dtype
206
+ )
207
+
208
+ freqs = torch.outer(t, self.inv_freq)
209
+ # Different from paper, but it uses a different permutation in order to obtain the same calculation
210
+ emb = torch.cat((freqs, freqs), dim=-1)
211
+ self.register_buffer("cos_cached", emb.cos().to(dtype), persistent=False)
212
+ self.register_buffer("sin_cached", emb.sin().to(dtype), persistent=False)
213
+
214
+ def forward(self, x, seq_len=None):
215
+ # x: [bs, num_attention_heads, seq_len, head_size]
216
+ if seq_len > self.max_seq_len_cached:
217
+ self._set_cos_sin_cache(seq_len=seq_len, device=x.device, dtype=x.dtype)
218
+
219
+ return (
220
+ self.cos_cached[:seq_len].to(dtype=x.dtype),
221
+ self.sin_cached[:seq_len].to(dtype=x.dtype),
222
+ )
223
+
224
+
225
+ # Copied from transformers.models.llama.modeling_llama.LlamaLinearScalingRotaryEmbedding with Llama->Phi
226
+ class PhiLinearScalingRotaryEmbedding(PhiRotaryEmbedding):
227
+ """PhiRotaryEmbedding extended with linear scaling. Credits to the Reddit user /u/kaiokendev"""
228
+
229
+ def __init__(
230
+ self,
231
+ dim,
232
+ max_position_embeddings=2048,
233
+ base=10000,
234
+ device=None,
235
+ scaling_factor=1.0,
236
+ ):
237
+ self.scaling_factor = scaling_factor
238
+ super().__init__(dim, max_position_embeddings, base, device)
239
+
240
+ def _set_cos_sin_cache(self, seq_len, device, dtype):
241
+ self.max_seq_len_cached = seq_len
242
+ t = torch.arange(
243
+ self.max_seq_len_cached, device=device, dtype=self.inv_freq.dtype
244
+ )
245
+ t = t / self.scaling_factor
246
+
247
+ freqs = torch.outer(t, self.inv_freq)
248
+ # Different from paper, but it uses a different permutation in order to obtain the same calculation
249
+ emb = torch.cat((freqs, freqs), dim=-1)
250
+ self.register_buffer("cos_cached", emb.cos().to(dtype), persistent=False)
251
+ self.register_buffer("sin_cached", emb.sin().to(dtype), persistent=False)
252
+
253
+
254
+ # Copied from transformers.models.llama.modeling_llama.LlamaDynamicNTKScalingRotaryEmbedding with Llama->Phi
255
+ class PhiDynamicNTKScalingRotaryEmbedding(PhiRotaryEmbedding):
256
+ """PhiRotaryEmbedding extended with Dynamic NTK scaling. Credits to the Reddit users /u/bloc97 and /u/emozilla"""
257
+
258
+ def __init__(
259
+ self,
260
+ dim,
261
+ max_position_embeddings=2048,
262
+ base=10000,
263
+ device=None,
264
+ scaling_factor=1.0,
265
+ ):
266
+ self.scaling_factor = scaling_factor
267
+ super().__init__(dim, max_position_embeddings, base, device)
268
+
269
+ def _set_cos_sin_cache(self, seq_len, device, dtype):
270
+ self.max_seq_len_cached = seq_len
271
+
272
+ if seq_len > self.max_position_embeddings:
273
+ base = self.base * (
274
+ (self.scaling_factor * seq_len / self.max_position_embeddings)
275
+ - (self.scaling_factor - 1)
276
+ ) ** (self.dim / (self.dim - 2))
277
+ inv_freq = 1.0 / (
278
+ base ** (torch.arange(0, self.dim, 2).float().to(device) / self.dim)
279
+ )
280
+ self.register_buffer("inv_freq", inv_freq, persistent=False)
281
+
282
+ t = torch.arange(
283
+ self.max_seq_len_cached, device=device, dtype=self.inv_freq.dtype
284
+ )
285
+
286
+ freqs = torch.outer(t, self.inv_freq)
287
+ # Different from paper, but it uses a different permutation in order to obtain the same calculation
288
+ emb = torch.cat((freqs, freqs), dim=-1)
289
+ self.register_buffer("cos_cached", emb.cos().to(dtype), persistent=False)
290
+ self.register_buffer("sin_cached", emb.sin().to(dtype), persistent=False)
291
+
292
+
293
+ # Copied from transformers.models.llama.modeling_llama.rotate_half
294
+ def rotate_half(x):
295
+ """Rotates half the hidden dims of the input."""
296
+ x1 = x[..., : x.shape[-1] // 2]
297
+ x2 = x[..., x.shape[-1] // 2 :]
298
+ return torch.cat((-x2, x1), dim=-1)
299
+
300
+
301
+ # Copied from transformers.models.llama.modeling_llama.apply_rotary_pos_emb
302
+ def apply_rotary_pos_emb(q, k, cos, sin, position_ids, unsqueeze_dim=1):
303
+ cos = cos[position_ids].unsqueeze(unsqueeze_dim)
304
+ sin = sin[position_ids].unsqueeze(unsqueeze_dim)
305
+ q_embed = (q * cos) + (rotate_half(q) * sin)
306
+ k_embed = (k * cos) + (rotate_half(k) * sin)
307
+ return q_embed, k_embed
308
+
309
+
310
+ # Copied from transformers.models.clip.modeling_clip.CLIPMLP with CLIP->Phi
311
+ class PhiMLP(nn.Module):
312
+ def __init__(self, config):
313
+ super().__init__()
314
+ self.config = config
315
+ self.activation_fn = ACT2FN[config.hidden_act]
316
+ self.fc1 = nn.Linear(config.hidden_size, config.intermediate_size)
317
+ self.fc2 = nn.Linear(config.intermediate_size, config.hidden_size)
318
+
319
+ def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
320
+ hidden_states = self.fc1(hidden_states)
321
+ hidden_states = self.activation_fn(hidden_states)
322
+ hidden_states = self.fc2(hidden_states)
323
+ return hidden_states
324
+
325
+
326
+ # Copied from transformers.models.llama.modeling_llama.repeat_kv with llama->phi
327
+ def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
328
+ """
329
+ This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
330
+ num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
331
+ """
332
+ batch, num_key_value_heads, slen, head_dim = hidden_states.shape
333
+ if n_rep == 1:
334
+ return hidden_states
335
+ hidden_states = hidden_states[:, :, None, :, :].expand(
336
+ batch, num_key_value_heads, n_rep, slen, head_dim
337
+ )
338
+ return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
339
+
340
+
341
+ class PhiAttention(nn.Module):
342
+ """Multi-headed attention from 'Attention Is All You Need' paper"""
343
+
344
+ def __init__(self, config: PhiConfig, layer_idx: Optional[int] = None):
345
+ super().__init__()
346
+ self.config = config
347
+ self.layer_idx = layer_idx
348
+ if layer_idx is None:
349
+ logger.warning_once(
350
+ f"Instantiating {self.__class__.__name__} without passing `layer_idx` is not recommended and will "
351
+ "to errors during the forward call, if caching is used. Please make sure to provide a `layer_idx` "
352
+ "when creating this class."
353
+ )
354
+
355
+ self.attention_dropout = config.attention_dropout
356
+ self.hidden_size = config.hidden_size
357
+ self.num_heads = config.num_attention_heads
358
+ self.head_dim = self.hidden_size // self.num_heads
359
+ self.num_key_value_heads = config.num_key_value_heads
360
+ self.num_key_value_groups = self.num_heads // self.num_key_value_heads
361
+ self.max_position_embeddings = config.max_position_embeddings
362
+ self.rope_theta = config.rope_theta
363
+ self.partial_rotary_factor = config.partial_rotary_factor
364
+ self.is_causal = True
365
+
366
+ if (self.head_dim * self.num_heads) != self.hidden_size:
367
+ raise ValueError(
368
+ f"hidden_size must be divisible by num_heads (got `hidden_size`: {self.hidden_size}"
369
+ f" and `num_heads`: {self.num_heads})."
370
+ )
371
+
372
+ self.q_proj = nn.Linear(
373
+ self.hidden_size, self.num_heads * self.head_dim, bias=True
374
+ )
375
+ self.k_proj = nn.Linear(
376
+ self.hidden_size, self.num_key_value_heads * self.head_dim, bias=True
377
+ )
378
+ self.v_proj = nn.Linear(
379
+ self.hidden_size, self.num_key_value_heads * self.head_dim, bias=True
380
+ )
381
+ self.dense = nn.Linear(
382
+ self.num_heads * self.head_dim, self.hidden_size, bias=True
383
+ )
384
+
385
+ self.qk_layernorm = config.qk_layernorm
386
+ if self.qk_layernorm:
387
+ self.q_layernorm = nn.LayerNorm(
388
+ config.hidden_size // self.num_heads,
389
+ eps=config.layer_norm_eps,
390
+ elementwise_affine=True,
391
+ )
392
+ self.k_layernorm = nn.LayerNorm(
393
+ config.hidden_size // self.num_heads,
394
+ eps=config.layer_norm_eps,
395
+ elementwise_affine=True,
396
+ )
397
+
398
+ self._init_rope()
399
+
400
+ def _init_rope(self):
401
+ if self.config.rope_scaling is None:
402
+ self.rotary_emb = PhiRotaryEmbedding(
403
+ int(self.partial_rotary_factor * self.head_dim),
404
+ max_position_embeddings=self.max_position_embeddings,
405
+ base=self.rope_theta,
406
+ )
407
+ else:
408
+ scaling_type = self.config.rope_scaling["type"]
409
+ scaling_factor = self.config.rope_scaling["factor"]
410
+ if scaling_type == "linear":
411
+ self.rotary_emb = PhiLinearScalingRotaryEmbedding(
412
+ int(self.partial_rotary_factor * self.head_dim),
413
+ max_position_embeddings=self.max_position_embeddings,
414
+ scaling_factor=scaling_factor,
415
+ base=self.rope_theta,
416
+ )
417
+ elif scaling_type == "dynamic":
418
+ self.rotary_emb = PhiDynamicNTKScalingRotaryEmbedding(
419
+ int(self.partial_rotary_factor * self.head_dim),
420
+ max_position_embeddings=self.max_position_embeddings,
421
+ scaling_factor=scaling_factor,
422
+ base=self.rope_theta,
423
+ )
424
+ else:
425
+ raise ValueError(f"Unknown RoPE scaling type {scaling_type}")
426
+
427
+ # Phi-2 has an attention overflow issue (with FP16) and requires autocast to be disabled
428
+ @torch.autocast("cpu", enabled=False)
429
+ @torch.autocast("cuda", enabled=False)
430
+ def forward(
431
+ self,
432
+ hidden_states: torch.Tensor,
433
+ attention_mask: Optional[torch.Tensor] = None,
434
+ position_ids: Optional[torch.LongTensor] = None,
435
+ past_key_value: Optional[Cache] = None,
436
+ output_attentions: bool = False,
437
+ use_cache: bool = False,
438
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
439
+ bsz, q_len, _ = hidden_states.size()
440
+
441
+ query_states = self.q_proj(hidden_states)
442
+ key_states = self.k_proj(hidden_states)
443
+ value_states = self.v_proj(hidden_states)
444
+
445
+ if self.qk_layernorm:
446
+ query_states = self.q_layernorm(query_states)
447
+ key_states = self.k_layernorm(key_states)
448
+
449
+ query_states = query_states.view(
450
+ bsz, q_len, self.num_heads, self.head_dim
451
+ ).transpose(1, 2)
452
+ key_states = key_states.view(
453
+ bsz, q_len, self.num_key_value_heads, self.head_dim
454
+ ).transpose(1, 2)
455
+ value_states = value_states.view(
456
+ bsz, q_len, self.num_key_value_heads, self.head_dim
457
+ ).transpose(1, 2)
458
+
459
+ kv_seq_len = key_states.shape[-2]
460
+ if past_key_value is not None:
461
+ if self.layer_idx is None:
462
+ raise ValueError(
463
+ f"The cache structure has changed since version v4.36. If you are using {self.__class__.__name__} "
464
+ "for auto-regressive decoding with k/v caching, please make sure to initialize the attention class "
465
+ "with a layer index."
466
+ )
467
+ kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
468
+ cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len)
469
+
470
+ # Partial rotary embedding
471
+ query_rot, query_pass = (
472
+ query_states[..., : self.rotary_emb.dim],
473
+ query_states[..., self.rotary_emb.dim :],
474
+ )
475
+ key_rot, key_pass = (
476
+ key_states[..., : self.rotary_emb.dim],
477
+ key_states[..., self.rotary_emb.dim :],
478
+ )
479
+ # [batch_size, seq_length, num_heads, head_dim // config.partial_rotary_factor]
480
+ query_rot, key_rot = apply_rotary_pos_emb(
481
+ query_rot, key_rot, cos, sin, position_ids
482
+ )
483
+
484
+ # [batch_size, seq_length, num_heads, head_dim]
485
+ query_states = torch.cat((query_rot, query_pass), dim=-1)
486
+ key_states = torch.cat((key_rot, key_pass), dim=-1)
487
+
488
+ if past_key_value is not None:
489
+ cache_kwargs = {
490
+ "sin": sin,
491
+ "cos": cos,
492
+ "partial_rotation_size": self.rotary_emb.dim,
493
+ }
494
+ key_states, value_states = past_key_value.update(
495
+ key_states, value_states, self.layer_idx, cache_kwargs
496
+ )
497
+
498
+ key_states = repeat_kv(key_states, self.num_key_value_groups)
499
+ value_states = repeat_kv(value_states, self.num_key_value_groups)
500
+
501
+ # Queries and keys upcast to fp32 is required by Phi-2 to avoid overflow
502
+ attn_weights = torch.matmul(
503
+ query_states.to(torch.float32), key_states.to(torch.float32).transpose(2, 3)
504
+ ) / math.sqrt(self.head_dim)
505
+
506
+ if attn_weights.size() != (bsz, self.num_heads, q_len, kv_seq_len):
507
+ raise ValueError(
508
+ f"Attention weights should be of size {(bsz, self.num_heads, q_len, kv_seq_len)}, but is"
509
+ f" {attn_weights.size()}"
510
+ )
511
+
512
+ if attention_mask is not None:
513
+ if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
514
+ raise ValueError(
515
+ f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
516
+ )
517
+ attn_weights = attn_weights + attention_mask
518
+
519
+ # upcast attention to fp32
520
+ attn_weights = nn.functional.softmax(
521
+ attn_weights, dim=-1, dtype=torch.float32
522
+ ).to(value_states.dtype)
523
+ attn_weights = nn.functional.dropout(
524
+ attn_weights, p=self.attention_dropout, training=self.training
525
+ )
526
+
527
+ attn_output = torch.matmul(attn_weights, value_states)
528
+
529
+ if attn_output.size() != (bsz, self.num_heads, q_len, self.head_dim):
530
+ raise ValueError(
531
+ f"`attn_output` should be of size {(bsz, self.num_heads, q_len, self.head_dim)}, but is"
532
+ f" {attn_output.size()}"
533
+ )
534
+
535
+ attn_output = attn_output.transpose(1, 2).contiguous()
536
+ attn_output = attn_output.reshape(bsz, q_len, self.hidden_size)
537
+
538
+ attn_output = self.dense(attn_output)
539
+
540
+ if not output_attentions:
541
+ attn_weights = None
542
+
543
+ return attn_output, attn_weights, past_key_value
544
+
545
+
546
+ class PhiFlashAttention2(PhiAttention):
547
+ # Copied from transformers.models.llama.modeling_llama.LlamaFlashAttention2.__init__
548
+ def __init__(self, *args, **kwargs):
549
+ super().__init__(*args, **kwargs)
550
+
551
+ # TODO: Should be removed once Flash Attention for RoCm is bumped to 2.1.
552
+ # flash_attn<2.1 generates top-left aligned causal mask, while what is needed here is bottom-right alignement, that was made default for flash_attn>=2.1. This attribute is used to handle this difference. Reference: https://github.com/Dao-AILab/flash-attention/releases/tag/v2.1.0.
553
+ # Beware that with flash_attn<2.1, using q_seqlen != k_seqlen (except for the case q_seqlen == 1) produces a wrong mask (top-left).
554
+ self._flash_attn_uses_top_left_mask = not is_flash_attn_greater_or_equal_2_10()
555
+
556
+ def forward(
557
+ self,
558
+ hidden_states: torch.Tensor,
559
+ attention_mask: Optional[torch.LongTensor] = None,
560
+ position_ids: Optional[torch.LongTensor] = None,
561
+ past_key_value: Optional[Cache] = None,
562
+ output_attentions: bool = False,
563
+ use_cache: bool = False,
564
+ **kwargs,
565
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
566
+ # PhiFlashAttention2 attention does not support output_attentions
567
+
568
+ output_attentions = False
569
+
570
+ bsz, q_len, _ = hidden_states.size()
571
+
572
+ query_states = self.q_proj(hidden_states)
573
+ key_states = self.k_proj(hidden_states)
574
+ value_states = self.v_proj(hidden_states)
575
+
576
+ if self.qk_layernorm:
577
+ query_states = self.q_layernorm(query_states)
578
+ key_states = self.k_layernorm(key_states)
579
+
580
+ # Flash attention requires the input to have the shape
581
+ # batch_size x seq_length x head_dim x hidden_dim
582
+ # therefore we just need to keep the original shape
583
+ query_states = query_states.view(
584
+ bsz, q_len, self.num_heads, self.head_dim
585
+ ).transpose(1, 2)
586
+ key_states = key_states.view(
587
+ bsz, q_len, self.num_key_value_heads, self.head_dim
588
+ ).transpose(1, 2)
589
+ value_states = value_states.view(
590
+ bsz, q_len, self.num_key_value_heads, self.head_dim
591
+ ).transpose(1, 2)
592
+
593
+ kv_seq_len = key_states.shape[-2]
594
+ if past_key_value is not None:
595
+ kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
596
+ cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len)
597
+
598
+ # Partial rotary embedding
599
+ query_rot, query_pass = (
600
+ query_states[..., : self.rotary_emb.dim],
601
+ query_states[..., self.rotary_emb.dim :],
602
+ )
603
+ key_rot, key_pass = (
604
+ key_states[..., : self.rotary_emb.dim],
605
+ key_states[..., self.rotary_emb.dim :],
606
+ )
607
+ # [batch_size, seq_length, num_heads, head_dim // config.partial_rotary_factor]
608
+ query_rot, key_rot = apply_rotary_pos_emb(
609
+ query_rot, key_rot, cos, sin, position_ids
610
+ )
611
+
612
+ # [batch_size, seq_length, num_heads, head_dim]
613
+ query_states = torch.cat((query_rot, query_pass), dim=-1)
614
+ key_states = torch.cat((key_rot, key_pass), dim=-1)
615
+
616
+ if past_key_value is not None:
617
+ cache_kwargs = {
618
+ "sin": sin,
619
+ "cos": cos,
620
+ "partial_rotation_size": self.rotary_emb.dim,
621
+ }
622
+ key_states, value_states = past_key_value.update(
623
+ key_states, value_states, self.layer_idx, cache_kwargs
624
+ )
625
+
626
+ # TODO: These transpose are quite inefficient but Flash Attention requires the layout [batch_size, sequence_length, num_heads, head_dim]. We would need to refactor the KV cache
627
+ # to be able to avoid many of these transpose/reshape/view.
628
+ query_states = query_states.transpose(1, 2)
629
+ key_states = key_states.transpose(1, 2)
630
+ value_states = value_states.transpose(1, 2)
631
+
632
+ attn_dropout = self.attention_dropout if self.training else 0.0
633
+
634
+ # In PEFT, usually we cast the layer norms in float32 for training stability reasons
635
+ # therefore the input hidden states gets silently casted in float32. Hence, we need
636
+ # cast them back in the correct dtype just to be sure everything works as expected.
637
+ # This might slowdown training & inference so it is recommended to not cast the LayerNorms
638
+ # in fp32.
639
+
640
+ if query_states.dtype == torch.float32:
641
+ if torch.is_autocast_enabled():
642
+ target_dtype = torch.get_autocast_gpu_dtype()
643
+ # Handle the case where the model is quantized
644
+ elif hasattr(self.config, "_pre_quantization_dtype"):
645
+ target_dtype = self.config._pre_quantization_dtype
646
+ else:
647
+ target_dtype = self.q_proj.weight.dtype
648
+
649
+ logger.warning_once(
650
+ f"The input hidden states seems to be silently casted in float32, this might be related to"
651
+ f" the fact you have upcasted embedding or layer norm layers in float32. We will cast back the input in"
652
+ f" {target_dtype}."
653
+ )
654
+
655
+ query_states = query_states.to(target_dtype)
656
+ key_states = key_states.to(target_dtype)
657
+ value_states = value_states.to(target_dtype)
658
+
659
+ attn_output = self._flash_attention_forward(
660
+ query_states,
661
+ key_states,
662
+ value_states,
663
+ attention_mask,
664
+ q_len,
665
+ dropout=attn_dropout,
666
+ softmax_scale=None,
667
+ )
668
+
669
+ attn_output = attn_output.reshape(bsz, q_len, self.hidden_size).contiguous()
670
+ attn_output = self.dense(attn_output)
671
+
672
+ if not output_attentions:
673
+ attn_weights = None
674
+
675
+ return attn_output, attn_weights, past_key_value
676
+
677
+ # Copied from transformers.models.llama.modeling_llama.LlamaFlashAttention2._flash_attention_forward
678
+ def _flash_attention_forward(
679
+ self,
680
+ query_states,
681
+ key_states,
682
+ value_states,
683
+ attention_mask,
684
+ query_length,
685
+ dropout=0.0,
686
+ softmax_scale=None,
687
+ ):
688
+ if not self._flash_attn_uses_top_left_mask:
689
+ causal = self.is_causal
690
+ else:
691
+ # TODO: Remove the `query_length != 1` check once Flash Attention for RoCm is bumped to 2.1. For details, please see the comment in LlamaFlashAttention2 __init__.
692
+ causal = self.is_causal and query_length != 1
693
+
694
+ # Contains at least one padding token in the sequence
695
+ if attention_mask is not None:
696
+ batch_size = query_states.shape[0]
697
+ (
698
+ query_states,
699
+ key_states,
700
+ value_states,
701
+ indices_q,
702
+ cu_seq_lens,
703
+ max_seq_lens,
704
+ ) = self._upad_input(
705
+ query_states, key_states, value_states, attention_mask, query_length
706
+ )
707
+
708
+ cu_seqlens_q, cu_seqlens_k = cu_seq_lens
709
+ max_seqlen_in_batch_q, max_seqlen_in_batch_k = max_seq_lens
710
+
711
+ attn_output_unpad = flash_attn_varlen_func(
712
+ query_states,
713
+ key_states,
714
+ value_states,
715
+ cu_seqlens_q=cu_seqlens_q,
716
+ cu_seqlens_k=cu_seqlens_k,
717
+ max_seqlen_q=max_seqlen_in_batch_q,
718
+ max_seqlen_k=max_seqlen_in_batch_k,
719
+ dropout_p=dropout,
720
+ softmax_scale=softmax_scale,
721
+ causal=causal,
722
+ )
723
+
724
+ attn_output = pad_input(
725
+ attn_output_unpad, indices_q, batch_size, query_length
726
+ )
727
+ else:
728
+ attn_output = flash_attn_func(
729
+ query_states,
730
+ key_states,
731
+ value_states,
732
+ dropout,
733
+ softmax_scale=softmax_scale,
734
+ causal=causal,
735
+ )
736
+
737
+ return attn_output
738
+
739
+ # Copied from transformers.models.llama.modeling_llama.LlamaFlashAttention2._upad_input
740
+ def _upad_input(
741
+ self, query_layer, key_layer, value_layer, attention_mask, query_length
742
+ ):
743
+ indices_k, cu_seqlens_k, max_seqlen_in_batch_k = _get_unpad_data(attention_mask)
744
+ batch_size, kv_seq_len, num_key_value_heads, head_dim = key_layer.shape
745
+
746
+ key_layer = index_first_axis(
747
+ key_layer.reshape(batch_size * kv_seq_len, num_key_value_heads, head_dim),
748
+ indices_k,
749
+ )
750
+ value_layer = index_first_axis(
751
+ value_layer.reshape(batch_size * kv_seq_len, num_key_value_heads, head_dim),
752
+ indices_k,
753
+ )
754
+ if query_length == kv_seq_len:
755
+ query_layer = index_first_axis(
756
+ query_layer.reshape(batch_size * kv_seq_len, self.num_heads, head_dim),
757
+ indices_k,
758
+ )
759
+ cu_seqlens_q = cu_seqlens_k
760
+ max_seqlen_in_batch_q = max_seqlen_in_batch_k
761
+ indices_q = indices_k
762
+ elif query_length == 1:
763
+ max_seqlen_in_batch_q = 1
764
+ cu_seqlens_q = torch.arange(
765
+ batch_size + 1, dtype=torch.int32, device=query_layer.device
766
+ ) # There is a memcpy here, that is very bad.
767
+ indices_q = cu_seqlens_q[:-1]
768
+ query_layer = query_layer.squeeze(1)
769
+ else:
770
+ # The -q_len: slice assumes left padding.
771
+ attention_mask = attention_mask[:, -query_length:]
772
+ query_layer, indices_q, cu_seqlens_q, max_seqlen_in_batch_q = unpad_input(
773
+ query_layer, attention_mask
774
+ )
775
+
776
+ return (
777
+ query_layer,
778
+ key_layer,
779
+ value_layer,
780
+ indices_q,
781
+ (cu_seqlens_q, cu_seqlens_k),
782
+ (max_seqlen_in_batch_q, max_seqlen_in_batch_k),
783
+ )
784
+
785
+
786
+ PHI_ATTENTION_CLASSES = {
787
+ "flash_attention_2": PhiFlashAttention2,
788
+ "eager": PhiAttention,
789
+ }
790
+
791
+
792
+ class PhiDecoderLayer(nn.Module):
793
+ def __init__(self, config: PhiConfig, layer_idx: int):
794
+ super().__init__()
795
+ if is_flash_attn_2_available():
796
+ config._attn_implementation = "flash_attention_2"
797
+ self.self_attn = PHI_ATTENTION_CLASSES[config._attn_implementation](
798
+ config, layer_idx=layer_idx
799
+ )
800
+ self.mlp = PhiMLP(config)
801
+ self.input_layernorm = nn.LayerNorm(
802
+ config.hidden_size, eps=config.layer_norm_eps
803
+ )
804
+ self.resid_dropout = nn.Dropout(config.resid_pdrop)
805
+
806
+ def forward(
807
+ self,
808
+ hidden_states: torch.Tensor,
809
+ attention_mask: Optional[torch.Tensor] = None,
810
+ position_ids: Optional[torch.LongTensor] = None,
811
+ output_attentions: Optional[bool] = False,
812
+ use_cache: Optional[bool] = False,
813
+ past_key_value: Optional[Tuple[torch.Tensor]] = None,
814
+ ) -> Tuple[
815
+ torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]
816
+ ]:
817
+ residual = hidden_states
818
+
819
+ hidden_states = self.input_layernorm(hidden_states)
820
+
821
+ # Self Attention
822
+ attn_outputs, self_attn_weights, present_key_value = self.self_attn(
823
+ hidden_states=hidden_states,
824
+ attention_mask=attention_mask,
825
+ position_ids=position_ids,
826
+ past_key_value=past_key_value,
827
+ output_attentions=output_attentions,
828
+ use_cache=use_cache,
829
+ )
830
+ attn_outputs = self.resid_dropout(attn_outputs)
831
+
832
+ feed_forward_hidden_states = self.resid_dropout(self.mlp(hidden_states))
833
+ hidden_states = attn_outputs + feed_forward_hidden_states + residual
834
+ outputs = (hidden_states,)
835
+
836
+ if output_attentions:
837
+ outputs += (self_attn_weights,)
838
+
839
+ if use_cache:
840
+ outputs += (present_key_value,)
841
+
842
+ return outputs
843
+
844
+
845
+ class PhiPreTrainedModel(PreTrainedModel):
846
+ config_class = PhiConfig
847
+ base_model_prefix = "model"
848
+ supports_gradient_checkpointing = True
849
+ _no_split_modules = ["PhiDecoderLayer"]
850
+ _skip_keys_device_placement = "past_key_values"
851
+ _supports_flash_attn_2 = True
852
+ _supports_cache_class = True
853
+
854
+
855
+ class PhiModel(PhiPreTrainedModel):
856
+ """
857
+ Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`PhiDecoderLayer`]
858
+
859
+ Args:
860
+ config: PhiConfig
861
+ """
862
+
863
+ def __init__(self, config: PhiConfig):
864
+ super().__init__(config)
865
+ self.padding_idx = config.pad_token_id
866
+ self.vocab_size = config.vocab_size
867
+
868
+ self.embed_tokens = nn.Embedding(
869
+ config.vocab_size, config.hidden_size, self.padding_idx
870
+ )
871
+ self.embed_dropout = nn.Dropout(config.embd_pdrop)
872
+ self.layers = nn.ModuleList(
873
+ [
874
+ PhiDecoderLayer(config, layer_idx)
875
+ for layer_idx in range(config.num_hidden_layers)
876
+ ]
877
+ )
878
+ self.final_layernorm = nn.LayerNorm(
879
+ config.hidden_size, eps=config.layer_norm_eps
880
+ )
881
+ self._use_flash_attention_2 = config._attn_implementation == "flash_attention_2"
882
+
883
+ self.gradient_checkpointing = False
884
+ # Initialize weights and apply final processing
885
+ self.post_init()
886
+
887
+ def get_input_embeddings(self):
888
+ return self.embed_tokens
889
+
890
+ def set_input_embeddings(self, value):
891
+ self.embed_tokens = value
892
+
893
+ def forward(
894
+ self,
895
+ input_ids: torch.LongTensor = None,
896
+ attention_mask: Optional[torch.Tensor] = None,
897
+ position_ids: Optional[torch.LongTensor] = None,
898
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
899
+ inputs_embeds: Optional[torch.FloatTensor] = None,
900
+ use_cache: Optional[bool] = None,
901
+ output_attentions: Optional[bool] = None,
902
+ output_hidden_states: Optional[bool] = None,
903
+ return_dict: Optional[bool] = None,
904
+ ) -> Union[Tuple, BaseModelOutputWithPast]:
905
+ output_attentions = (
906
+ output_attentions
907
+ if output_attentions is not None
908
+ else self.config.output_attentions
909
+ )
910
+ output_hidden_states = (
911
+ output_hidden_states
912
+ if output_hidden_states is not None
913
+ else self.config.output_hidden_states
914
+ )
915
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
916
+
917
+ return_dict = (
918
+ return_dict if return_dict is not None else self.config.use_return_dict
919
+ )
920
+
921
+ # retrieve input_ids and inputs_embeds
922
+ if input_ids is not None and inputs_embeds is not None:
923
+ raise ValueError(
924
+ "You cannot specify both input_ids and inputs_embeds at the same time"
925
+ )
926
+ elif input_ids is not None:
927
+ batch_size, seq_length = input_ids.shape[:2]
928
+ elif inputs_embeds is not None:
929
+ batch_size, seq_length = inputs_embeds.shape[:2]
930
+ else:
931
+ raise ValueError("You have to specify either input_ids or inputs_embeds")
932
+
933
+ past_key_values_length = 0
934
+
935
+ if self.gradient_checkpointing and self.training:
936
+ if use_cache:
937
+ logger.warning_once(
938
+ "`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..."
939
+ )
940
+ use_cache = False
941
+
942
+ if use_cache:
943
+ use_legacy_cache = not isinstance(past_key_values, Cache)
944
+ if use_legacy_cache:
945
+ past_key_values = DynamicCache.from_legacy_cache(past_key_values)
946
+ past_key_values_length = past_key_values.get_usable_length(seq_length)
947
+
948
+ if position_ids is None:
949
+ device = input_ids.device if input_ids is not None else inputs_embeds.device
950
+ position_ids = torch.arange(
951
+ past_key_values_length,
952
+ seq_length + past_key_values_length,
953
+ dtype=torch.long,
954
+ device=device,
955
+ )
956
+ position_ids = position_ids.unsqueeze(0)
957
+
958
+ if inputs_embeds is None:
959
+ inputs_embeds = self.embed_tokens(input_ids)
960
+
961
+ inputs_embeds = self.embed_dropout(inputs_embeds)
962
+
963
+ # Attention mask.
964
+ if self._use_flash_attention_2:
965
+ # 2d mask is passed through the layers
966
+ attention_mask = (
967
+ attention_mask
968
+ if (attention_mask is not None and 0 in attention_mask)
969
+ else None
970
+ )
971
+ else:
972
+ # 4d mask is passed through the layers
973
+ attention_mask = _prepare_4d_causal_attention_mask(
974
+ attention_mask,
975
+ (batch_size, seq_length),
976
+ inputs_embeds,
977
+ past_key_values_length,
978
+ )
979
+
980
+ hidden_states = inputs_embeds
981
+
982
+ # decoder layers
983
+ all_hidden_states = () if output_hidden_states else None
984
+ all_self_attns = () if output_attentions else None
985
+ next_decoder_cache = None
986
+
987
+ for decoder_layer in self.layers:
988
+ if output_hidden_states:
989
+ all_hidden_states += (hidden_states,)
990
+
991
+ if self.gradient_checkpointing and self.training:
992
+ layer_outputs = self._gradient_checkpointing_func(
993
+ decoder_layer.__call__,
994
+ hidden_states,
995
+ attention_mask,
996
+ position_ids,
997
+ past_key_values,
998
+ output_attentions,
999
+ )
1000
+ else:
1001
+ layer_outputs = decoder_layer(
1002
+ hidden_states,
1003
+ attention_mask=attention_mask,
1004
+ position_ids=position_ids,
1005
+ past_key_value=past_key_values,
1006
+ output_attentions=output_attentions,
1007
+ use_cache=use_cache,
1008
+ )
1009
+
1010
+ hidden_states = layer_outputs[0]
1011
+
1012
+ if use_cache:
1013
+ next_decoder_cache = layer_outputs[2 if output_attentions else 1]
1014
+
1015
+ if output_attentions:
1016
+ all_self_attns += (layer_outputs[1],)
1017
+
1018
+ hidden_states = self.final_layernorm(hidden_states)
1019
+
1020
+ # add hidden states from the last decoder layer
1021
+ if output_hidden_states:
1022
+ all_hidden_states += (hidden_states,)
1023
+
1024
+ next_cache = None
1025
+ if use_cache:
1026
+ next_cache = (
1027
+ next_decoder_cache.to_legacy_cache()
1028
+ if use_legacy_cache
1029
+ else next_decoder_cache
1030
+ )
1031
+ if not return_dict:
1032
+ return tuple(
1033
+ v
1034
+ for v in [hidden_states, next_cache, all_hidden_states, all_self_attns]
1035
+ if v is not None
1036
+ )
1037
+ return BaseModelOutputWithPast(
1038
+ last_hidden_state=hidden_states,
1039
+ past_key_values=next_cache,
1040
+ hidden_states=all_hidden_states,
1041
+ attentions=all_self_attns,
1042
+ )
1043
+
1044
+
1045
+ class PhiForCausalLM(PhiPreTrainedModel):
1046
+ _tied_weights_keys = ["lm_head.weight"]
1047
+
1048
+ # Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.__init__ with Llama->Phi,bias=False->bias=True
1049
+ def __init__(self, config):
1050
+ super().__init__(config)
1051
+ self.model = PhiModel(config)
1052
+ self.vocab_size = config.vocab_size
1053
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=True)
1054
+
1055
+ # Initialize weights and apply final processing
1056
+ self.post_init()
1057
+
1058
+ # Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.get_input_embeddings
1059
+ def get_input_embeddings(self):
1060
+ return self.model.embed_tokens
1061
+
1062
+ # Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.set_input_embeddings
1063
+ def set_input_embeddings(self, value):
1064
+ self.model.embed_tokens = value
1065
+
1066
+ # Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.get_output_embeddings
1067
+ def get_output_embeddings(self):
1068
+ return self.lm_head
1069
+
1070
+ # Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.set_output_embeddings
1071
+ def set_output_embeddings(self, new_embeddings):
1072
+ self.lm_head = new_embeddings
1073
+
1074
+ # Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.set_decoder
1075
+ def set_decoder(self, decoder):
1076
+ self.model = decoder
1077
+
1078
+ # Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.get_decoder
1079
+ def get_decoder(self):
1080
+ return self.model
1081
+
1082
+ def forward(
1083
+ self,
1084
+ input_ids: torch.LongTensor = None,
1085
+ attention_mask: Optional[torch.Tensor] = None,
1086
+ position_ids: Optional[torch.LongTensor] = None,
1087
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
1088
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1089
+ labels: Optional[torch.LongTensor] = None,
1090
+ use_cache: Optional[bool] = None,
1091
+ output_attentions: Optional[bool] = None,
1092
+ output_hidden_states: Optional[bool] = None,
1093
+ return_dict: Optional[bool] = None,
1094
+ ) -> Union[Tuple, CausalLMOutputWithPast]:
1095
+ output_attentions = (
1096
+ output_attentions
1097
+ if output_attentions is not None
1098
+ else self.config.output_attentions
1099
+ )
1100
+ output_hidden_states = (
1101
+ output_hidden_states
1102
+ if output_hidden_states is not None
1103
+ else self.config.output_hidden_states
1104
+ )
1105
+ return_dict = (
1106
+ return_dict if return_dict is not None else self.config.use_return_dict
1107
+ )
1108
+
1109
+ # decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
1110
+ outputs = self.model(
1111
+ input_ids=input_ids,
1112
+ attention_mask=attention_mask,
1113
+ position_ids=position_ids,
1114
+ past_key_values=past_key_values,
1115
+ inputs_embeds=inputs_embeds,
1116
+ use_cache=use_cache,
1117
+ output_attentions=output_attentions,
1118
+ output_hidden_states=output_hidden_states,
1119
+ return_dict=return_dict,
1120
+ )
1121
+
1122
+ hidden_states = outputs[0]
1123
+ logits = self.lm_head(hidden_states)
1124
+ logits = logits.float()
1125
+
1126
+ loss = None
1127
+ if labels is not None:
1128
+ # Shift so that tokens < n predict n
1129
+ shift_logits = logits[..., :-1, :].contiguous()
1130
+ shift_labels = labels[..., 1:].contiguous()
1131
+ # Flatten the tokens
1132
+ loss_fct = CrossEntropyLoss()
1133
+ shift_logits = shift_logits.view(-1, self.config.vocab_size)
1134
+ shift_labels = shift_labels.view(-1)
1135
+ # Enable model parallelism
1136
+ shift_labels = shift_labels.to(shift_logits.device)
1137
+ loss = loss_fct(shift_logits, shift_labels)
1138
+
1139
+ if not return_dict:
1140
+ output = (logits,) + outputs[1:]
1141
+ return (loss,) + output if loss is not None else output
1142
+
1143
+ return CausalLMOutputWithPast(
1144
+ loss=loss,
1145
+ logits=logits,
1146
+ past_key_values=outputs.past_key_values,
1147
+ hidden_states=outputs.hidden_states,
1148
+ attentions=outputs.attentions,
1149
+ )
1150
+
1151
+ @staticmethod
1152
+ # Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM._reorder_cache
1153
+ def _reorder_cache(past_key_values, beam_idx):
1154
+ reordered_past = ()
1155
+ for layer_past in past_key_values:
1156
+ reordered_past += (
1157
+ tuple(
1158
+ past_state.index_select(0, beam_idx.to(past_state.device))
1159
+ for past_state in layer_past
1160
+ ),
1161
+ )
1162
+ return reordered_past
1163
+
1164
+
1165
+ class PhiForSequenceClassification(PhiPreTrainedModel):
1166
+ def __init__(self, config):
1167
+ super().__init__(config)
1168
+ self.num_labels = config.num_labels
1169
+ self.model = PhiModel(config)
1170
+ self.score = nn.Linear(config.hidden_size, self.num_labels, bias=False)
1171
+
1172
+ # Initialize weights and apply final processing
1173
+ self.post_init()
1174
+
1175
+ def get_input_embeddings(self):
1176
+ return self.model.embed_tokens
1177
+
1178
+ def set_input_embeddings(self, value):
1179
+ self.model.embed_tokens = value
1180
+
1181
+ def forward(
1182
+ self,
1183
+ input_ids: torch.LongTensor = None,
1184
+ attention_mask: Optional[torch.Tensor] = None,
1185
+ position_ids: Optional[torch.LongTensor] = None,
1186
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
1187
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1188
+ labels: Optional[torch.LongTensor] = None,
1189
+ use_cache: Optional[bool] = None,
1190
+ output_attentions: Optional[bool] = None,
1191
+ output_hidden_states: Optional[bool] = None,
1192
+ return_dict: Optional[bool] = None,
1193
+ ) -> Union[Tuple, SequenceClassifierOutputWithPast]:
1194
+ r"""
1195
+ labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
1196
+ Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
1197
+ config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
1198
+ `config.num_labels > 1` a classification loss is computed (Cross-Entropy).
1199
+ """
1200
+ return_dict = (
1201
+ return_dict if return_dict is not None else self.config.use_return_dict
1202
+ )
1203
+
1204
+ model_outputs = self.model(
1205
+ input_ids,
1206
+ attention_mask=attention_mask,
1207
+ position_ids=position_ids,
1208
+ past_key_values=past_key_values,
1209
+ inputs_embeds=inputs_embeds,
1210
+ use_cache=use_cache,
1211
+ output_attentions=output_attentions,
1212
+ output_hidden_states=output_hidden_states,
1213
+ return_dict=return_dict,
1214
+ )
1215
+ hidden_states = model_outputs[0]
1216
+ logits = self.score(hidden_states)
1217
+
1218
+ if input_ids is not None:
1219
+ batch_size = input_ids.shape[0]
1220
+ else:
1221
+ batch_size = inputs_embeds.shape[0]
1222
+
1223
+ if self.config.pad_token_id is None and batch_size != 1:
1224
+ raise ValueError(
1225
+ "Cannot handle batch sizes > 1 if no padding token is defined."
1226
+ )
1227
+ if self.config.pad_token_id is None:
1228
+ sequence_lengths = -1
1229
+ else:
1230
+ if input_ids is not None:
1231
+ # if no pad token found, use modulo instead of reverse indexing for ONNX compatibility
1232
+ sequence_lengths = (
1233
+ torch.eq(input_ids, self.config.pad_token_id).int().argmax(-1) - 1
1234
+ )
1235
+ sequence_lengths = sequence_lengths % input_ids.shape[-1]
1236
+ sequence_lengths = sequence_lengths.to(logits.device)
1237
+ else:
1238
+ sequence_lengths = -1
1239
+
1240
+ pooled_logits = logits[
1241
+ torch.arange(batch_size, device=logits.device), sequence_lengths
1242
+ ]
1243
+
1244
+ loss = None
1245
+ if labels is not None:
1246
+ labels = labels.to(logits.device)
1247
+ if self.config.problem_type is None:
1248
+ if self.num_labels == 1:
1249
+ self.config.problem_type = "regression"
1250
+ elif self.num_labels > 1 and (
1251
+ labels.dtype == torch.long or labels.dtype == torch.int
1252
+ ):
1253
+ self.config.problem_type = "single_label_classification"
1254
+ else:
1255
+ self.config.problem_type = "multi_label_classification"
1256
+
1257
+ if self.config.problem_type == "regression":
1258
+ loss_fct = MSELoss()
1259
+ if self.num_labels == 1:
1260
+ loss = loss_fct(pooled_logits.squeeze(), labels.squeeze())
1261
+ else:
1262
+ loss = loss_fct(pooled_logits, labels)
1263
+ elif self.config.problem_type == "single_label_classification":
1264
+ loss_fct = CrossEntropyLoss()
1265
+ loss = loss_fct(
1266
+ pooled_logits.view(-1, self.num_labels), labels.view(-1)
1267
+ )
1268
+ elif self.config.problem_type == "multi_label_classification":
1269
+ loss_fct = BCEWithLogitsLoss()
1270
+ loss = loss_fct(pooled_logits, labels)
1271
+ if not return_dict:
1272
+ output = (pooled_logits,) + model_outputs[1:]
1273
+ return ((loss,) + output) if loss is not None else output
1274
+
1275
+ return SequenceClassifierOutputWithPast(
1276
+ loss=loss,
1277
+ logits=pooled_logits,
1278
+ past_key_values=model_outputs.past_key_values,
1279
+ hidden_states=model_outputs.hidden_states,
1280
+ attentions=model_outputs.attentions,
1281
+ )
1282
+
1283
+
1284
+ class PhiForTokenClassification(PhiPreTrainedModel):
1285
+ def __init__(self, config: PhiConfig):
1286
+ super().__init__(config)
1287
+ self.num_labels = config.num_labels
1288
+
1289
+ self.model = PhiModel(config)
1290
+ if (
1291
+ hasattr(config, "classifier_dropout")
1292
+ and config.classifier_dropout is not None
1293
+ ):
1294
+ classifier_dropout = config.classifier_dropout
1295
+ elif hasattr(config, "hidden_dropout") and config.hidden_dropout is not None:
1296
+ classifier_dropout = config.hidden_dropout
1297
+ else:
1298
+ classifier_dropout = 0.1
1299
+ self.dropout = nn.Dropout(classifier_dropout)
1300
+ self.classifier = nn.Linear(config.hidden_size, config.num_labels)
1301
+
1302
+ # Initialize weights and apply final processing
1303
+ self.post_init()
1304
+
1305
+ def forward(
1306
+ self,
1307
+ input_ids: Optional[torch.LongTensor] = None,
1308
+ past_key_values: Optional[Tuple[Tuple[torch.Tensor, torch.Tensor], ...]] = None,
1309
+ attention_mask: Optional[torch.Tensor] = None,
1310
+ inputs_embeds: Optional[torch.Tensor] = None,
1311
+ labels: Optional[torch.Tensor] = None,
1312
+ use_cache: Optional[bool] = None,
1313
+ output_attentions: Optional[bool] = None,
1314
+ output_hidden_states: Optional[bool] = None,
1315
+ return_dict: Optional[bool] = None,
1316
+ **deprecated_arguments,
1317
+ ) -> Union[Tuple[torch.Tensor], TokenClassifierOutput]:
1318
+ r"""
1319
+ labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
1320
+ Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
1321
+ config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
1322
+ `config.num_labels > 1` a classification loss is computed (Cross-Entropy).
1323
+ """
1324
+ return_dict = (
1325
+ return_dict if return_dict is not None else self.config.use_return_dict
1326
+ )
1327
+
1328
+ model_outputs = self.model(
1329
+ input_ids,
1330
+ past_key_values=past_key_values,
1331
+ attention_mask=attention_mask,
1332
+ inputs_embeds=inputs_embeds,
1333
+ use_cache=use_cache,
1334
+ output_attentions=output_attentions,
1335
+ output_hidden_states=output_hidden_states,
1336
+ return_dict=return_dict,
1337
+ )
1338
+
1339
+ hidden_states = model_outputs[0]
1340
+ hidden_states = self.dropout(hidden_states)
1341
+ logits = self.classifier(hidden_states)
1342
+
1343
+ loss = None
1344
+ if labels is not None:
1345
+ # move labels to correct device to enable model parallelism
1346
+ labels = labels.to(logits.device)
1347
+ batch_size, seq_length = labels.shape
1348
+ loss_fct = CrossEntropyLoss()
1349
+ loss = loss_fct(
1350
+ logits.view(batch_size * seq_length, self.num_labels),
1351
+ labels.view(batch_size * seq_length),
1352
+ )
1353
+
1354
+ if not return_dict:
1355
+ output = (logits,) + model_outputs[2:]
1356
+ return ((loss,) + output) if loss is not None else output
1357
+
1358
+ return TokenClassifierOutput(
1359
+ loss=loss,
1360
+ logits=logits,
1361
+ hidden_states=model_outputs.hidden_states,
1362
+ attentions=model_outputs.attentions,
1363
+ )
1364
+
1365
+
1366
+ @dataclass
1367
+ class LlavaCausalLMOutputWithPast(ModelOutput):
1368
+ loss: Optional[torch.FloatTensor] = None
1369
+ logits: torch.FloatTensor = None
1370
+ past_key_values: Optional[List[torch.FloatTensor]] = None
1371
+ hidden_states: Optional[Tuple[torch.FloatTensor]] = None
1372
+ attentions: Optional[Tuple[torch.FloatTensor]] = None
1373
+ image_features: Optional[torch.FloatTensor] = None
1374
+
1375
+
1376
+ class SiglipVisionEncoder(nn.Module):
1377
+ def __init__(self, config: LlavaConfig):
1378
+ super().__init__()
1379
+ self.vision_tower = SiglipVisionModel(config.vision_config)
1380
+
1381
+ self.coord_embed = nn.Sequential(
1382
+ nn.Linear(2, config.vision_embed_dim),
1383
+ nn.GELU(),
1384
+ nn.Linear(config.vision_embed_dim, config.vision_embed_dim),
1385
+ )
1386
+
1387
+ self.num_tokens = 728
1388
+
1389
+ def feature_select(self, image_forward_outs, coord_feature, num_tokens=None):
1390
+ image_features = image_forward_outs
1391
+ image_features = image_features[:, 1:]
1392
+ if num_tokens is None:
1393
+ num_tokens = self.num_tokens
1394
+ split_size = int(num_tokens / image_features.shape[0])
1395
+ sum = 0
1396
+ output_list = []
1397
+ for i in range(image_features.shape[0]):
1398
+ if i == image_features.shape[0] - 1:
1399
+ size = num_tokens - sum
1400
+ else:
1401
+ size = split_size
1402
+ sum += size
1403
+ chunk_output = image_features[i, -size:, :]
1404
+ chunk_output = chunk_output + coord_feature[i]
1405
+ output_list.append(chunk_output)
1406
+ image_features = torch.cat(output_list)
1407
+ return image_features
1408
+
1409
+ def process_image_chunks(self, image_tensor, coord_tensor, num_tokens=None):
1410
+ if image_tensor.shape[0] > 50:
1411
+ image_forward_out = []
1412
+ for i in range(0, image_tensor.shape[0], 50):
1413
+ part_forward_out = self.vision_tower(
1414
+ image_tensor[i : i + 50], output_hidden_states=True
1415
+ ).hidden_states[-1]
1416
+ image_forward_out.append(part_forward_out)
1417
+ image_forward_out = torch.cat(image_forward_out, dim=0)
1418
+ else:
1419
+ image_forward_out = self.vision_tower(
1420
+ image_tensor, output_hidden_states=True
1421
+ ).hidden_states[-1]
1422
+ coord_feature = self.coord_embed(coord_tensor)
1423
+ if len(coord_feature.shape) == 1:
1424
+ coord_feature = coord_feature.unsqueeze(0)
1425
+ image_feature = self.feature_select(
1426
+ image_forward_out, coord_feature, num_tokens
1427
+ ).to(image_tensor.dtype)
1428
+ return image_feature
1429
+
1430
+ def forward(
1431
+ self, images: List[torch.Tensor], coords: List[torch.Tensor], num_tokens=None
1432
+ ):
1433
+ image_features = []
1434
+ for i, image in enumerate(images):
1435
+ image_feature = self.process_image_chunks(image, coords[i], num_tokens)
1436
+ image_features.append(image_feature)
1437
+ image_features = torch.stack(image_features)
1438
+ return image_features
1439
+
1440
+
1441
+ class LlavaMultiModalProjector(nn.Module):
1442
+ def __init__(self, config: LlavaConfig):
1443
+ super().__init__()
1444
+
1445
+ self.linear_1 = nn.Linear(
1446
+ config.vision_embed_dim,
1447
+ config.text_config.hidden_size,
1448
+ bias=True,
1449
+ )
1450
+ self.act = nn.GELU()
1451
+ self.linear_2 = nn.Linear(
1452
+ config.text_config.hidden_size,
1453
+ config.text_config.hidden_size,
1454
+ bias=True,
1455
+ )
1456
+
1457
+ def forward(self, image_features):
1458
+ hidden_states = self.linear_1(image_features)
1459
+ hidden_states = self.act(hidden_states)
1460
+ hidden_states = self.linear_2(hidden_states)
1461
+ return hidden_states
1462
+
1463
+
1464
+ class LlavaPreTrainedModel(PreTrainedModel):
1465
+ config_class = LlavaConfig
1466
+ base_model_prefix = "model"
1467
+ supports_gradient_checkpointing = True
1468
+ _no_split_modules = ["LlavaVisionAttention"]
1469
+ _skip_keys_device_placement = "past_key_values"
1470
+ _supports_flash_attn_2 = True
1471
+
1472
+ def __init__(self, config):
1473
+ super().__init__(config)
1474
+
1475
+ def _init_weights(self, module):
1476
+ return
1477
+
1478
+ @property
1479
+ def _supports_sdpa(self):
1480
+ """
1481
+ Retrieve language_model's attribute to check whether the model supports
1482
+ SDPA or not.
1483
+ """
1484
+ return self.language_model._supports_sdpa
1485
+
1486
+
1487
+ class LlavaForCausalLM(LlavaPreTrainedModel):
1488
+ def __init__(self, config: LlavaConfig):
1489
+ super().__init__(config)
1490
+ self.vision_model = SiglipVisionEncoder(config)
1491
+
1492
+ self.multi_modal_projector = LlavaMultiModalProjector(config)
1493
+ self.vocab_size = config.vocab_size
1494
+ self.language_model = PhiForCausalLM(config.text_config)
1495
+ self.pad_token_id = (
1496
+ self.config.pad_token_id if self.config.pad_token_id is not None else -1
1497
+ )
1498
+ self.post_init()
1499
+
1500
+ def get_input_embeddings(self):
1501
+ return self.language_model.get_input_embeddings()
1502
+
1503
+ def set_input_embeddings(self, value):
1504
+ self.language_model.set_input_embeddings(value)
1505
+
1506
+ def get_output_embeddings(self):
1507
+ return self.language_model.get_output_embeddings()
1508
+
1509
+ def set_output_embeddings(self, new_embeddings):
1510
+ self.language_model.set_output_embeddings(new_embeddings)
1511
+
1512
+ def set_decoder(self, decoder):
1513
+ self.language_model.transformer = decoder
1514
+
1515
+ def get_decoder(self):
1516
+ return self.language_model.transformer
1517
+
1518
+ def tie_weights(self):
1519
+ return self.language_model.tie_weights()
1520
+
1521
+ def resize_token_embeddings(
1522
+ self, new_num_tokens: Optional[int] = None, pad_to_multiple_of=None
1523
+ ) -> nn.Embedding:
1524
+ model_embeds = self.language_model.resize_token_embeddings(
1525
+ new_num_tokens, pad_to_multiple_of
1526
+ )
1527
+ # update vocab size
1528
+ self.config.text_config.vocab_size = model_embeds.num_embeddings
1529
+ self.config.vocab_size = model_embeds.num_embeddings
1530
+ self.vocab_size = model_embeds.num_embeddings
1531
+ return model_embeds
1532
+
1533
+ def _merge_input_ids_with_image_features(
1534
+ self, image_features, inputs_embeds, input_ids, attention_mask, position_ids
1535
+ ):
1536
+ num_images, num_image_patches, embed_dim = image_features.shape
1537
+ batch_size, sequence_length = input_ids.shape
1538
+ left_padding = not torch.sum(
1539
+ input_ids[:, -1] == torch.tensor(self.pad_token_id)
1540
+ )
1541
+ # 1. Create a mask to know where special image tokens are
1542
+ special_image_token_mask = input_ids == self.config.image_token_index
1543
+ num_special_image_tokens = torch.sum(special_image_token_mask, dim=-1)
1544
+ # Compute the maximum embed dimension
1545
+ max_embed_dim = (
1546
+ num_special_image_tokens.max() * (num_image_patches - 1)
1547
+ ) + sequence_length
1548
+ batch_indices, non_image_indices = torch.where(
1549
+ input_ids != self.config.image_token_index
1550
+ )
1551
+
1552
+ # 2. Compute the positions where text should be written
1553
+ # Calculate new positions for text tokens in merged image-text sequence.
1554
+ # `special_image_token_mask` identifies image tokens. Each image token will be replaced by `nb_text_tokens_per_images - 1` text tokens.
1555
+ # `torch.cumsum` computes how each image token shifts subsequent text token positions.
1556
+ # - 1 to adjust for zero-based indexing, as `cumsum` inherently increases indices by one.
1557
+ new_token_positions = (
1558
+ torch.cumsum((special_image_token_mask * (num_image_patches - 1) + 1), -1)
1559
+ - 1
1560
+ )
1561
+ nb_image_pad = max_embed_dim - 1 - new_token_positions[:, -1]
1562
+ if left_padding:
1563
+ new_token_positions += nb_image_pad[:, None] # offset for left padding
1564
+ text_to_overwrite = new_token_positions[batch_indices, non_image_indices]
1565
+
1566
+ # 3. Create the full embedding, already padded to the maximum position
1567
+ final_embedding = torch.zeros(
1568
+ batch_size,
1569
+ max_embed_dim,
1570
+ embed_dim,
1571
+ dtype=inputs_embeds.dtype,
1572
+ device=inputs_embeds.device,
1573
+ )
1574
+ final_attention_mask = torch.zeros(
1575
+ batch_size,
1576
+ max_embed_dim,
1577
+ dtype=attention_mask.dtype,
1578
+ device=inputs_embeds.device,
1579
+ )
1580
+ # In case the Vision model or the Language model has been offloaded to CPU, we need to manually
1581
+ # set the corresponding tensors into their correct target device.
1582
+ target_device = inputs_embeds.device
1583
+ batch_indices, non_image_indices, text_to_overwrite = (
1584
+ batch_indices.to(target_device),
1585
+ non_image_indices.to(target_device),
1586
+ text_to_overwrite.to(target_device),
1587
+ )
1588
+ attention_mask = attention_mask.to(target_device)
1589
+
1590
+ # 4. Fill the embeddings based on the mask. If we have ["hey" "<image>", "how", "are"]
1591
+ # we need to index copy on [0, 577, 578, 579] for the text and [1:576] for the image features
1592
+ final_embedding[batch_indices, text_to_overwrite] = inputs_embeds[
1593
+ batch_indices, non_image_indices
1594
+ ]
1595
+ final_attention_mask[batch_indices, text_to_overwrite] = attention_mask[
1596
+ batch_indices, non_image_indices
1597
+ ]
1598
+
1599
+ # 5. Fill the embeddings corresponding to the images. Anything that is still zeros needs filling
1600
+ image_to_overwrite = torch.all(final_embedding == 0, dim=-1)
1601
+ image_to_overwrite &= image_to_overwrite.cumsum(-1) - 1 >= nb_image_pad[
1602
+ :, None
1603
+ ].to(target_device)
1604
+
1605
+ if image_to_overwrite.sum() != image_features.shape[:-1].numel():
1606
+ raise ValueError(
1607
+ f"The input provided to the model are wrong. The number of image tokens is {torch.sum(special_image_token_mask)} while"
1608
+ f" the number of image given to the model is {num_images}. This prevents correct indexing and breaks batch generation."
1609
+ )
1610
+
1611
+ final_embedding[image_to_overwrite] = (
1612
+ image_features.contiguous().reshape(-1, embed_dim).to(target_device)
1613
+ )
1614
+ final_attention_mask |= image_to_overwrite
1615
+ position_ids = (final_attention_mask.cumsum(-1) - 1).masked_fill_(
1616
+ (final_attention_mask == 0), 1
1617
+ )
1618
+ return final_embedding, final_attention_mask, position_ids
1619
+
1620
+ def forward(
1621
+ self,
1622
+ input_ids: torch.LongTensor = None,
1623
+ image_features: torch.FloatTensor = None,
1624
+ attention_mask: Optional[torch.Tensor] = None,
1625
+ position_ids: Optional[torch.LongTensor] = None,
1626
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
1627
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1628
+ use_cache: Optional[bool] = None,
1629
+ output_attentions: Optional[bool] = None,
1630
+ output_hidden_states: Optional[bool] = None,
1631
+ return_dict: Optional[bool] = None,
1632
+ ) -> Union[Tuple, LlavaCausalLMOutputWithPast]:
1633
+ output_attentions = (
1634
+ output_attentions
1635
+ if output_attentions is not None
1636
+ else self.config.output_attentions
1637
+ )
1638
+ output_hidden_states = (
1639
+ output_hidden_states
1640
+ if output_hidden_states is not None
1641
+ else self.config.output_hidden_states
1642
+ )
1643
+ return_dict = (
1644
+ return_dict if return_dict is not None else self.config.use_return_dict
1645
+ )
1646
+
1647
+ if inputs_embeds is None:
1648
+ inputs_embeds = self.get_input_embeddings()(input_ids)
1649
+ if image_features is not None and input_ids.shape[1] != 1:
1650
+ (
1651
+ inputs_embeds,
1652
+ attention_mask,
1653
+ position_ids,
1654
+ ) = self._merge_input_ids_with_image_features(
1655
+ image_features,
1656
+ inputs_embeds,
1657
+ input_ids,
1658
+ attention_mask,
1659
+ position_ids,
1660
+ )
1661
+ else:
1662
+ # In case input_ids.shape[1] == 1 & pixel_values==None & past_key_values != None, we are in the case of
1663
+ # generation with cache
1664
+ if past_key_values is not None and image_features is not None and input_ids.shape[1] == 1:
1665
+ # Retrieve the first layer to inspect the logits and mask out the hidden states
1666
+ # that are set to 0
1667
+ first_layer_past_key_value = past_key_values[0][0][:, :, :, 0]
1668
+
1669
+ # Sum all dimensions of head_dim (-2) to avoid random errors such as: https://github.com/huggingface/transformers/pull/28032#issuecomment-1863691941
1670
+ batch_index, non_attended_tokens = torch.where(first_layer_past_key_value.float().sum(-2) == 0)
1671
+
1672
+ # Get the target length
1673
+ target_seqlen = first_layer_past_key_value.shape[-1] + 1
1674
+
1675
+ extended_attention_mask = torch.ones(
1676
+ (attention_mask.shape[0], target_seqlen - attention_mask.shape[1]),
1677
+ dtype=attention_mask.dtype,
1678
+ device=attention_mask.device,
1679
+ )
1680
+
1681
+ # Filter out only the tokens that can be un-attended, this can happen
1682
+ # if one uses Llava + Fused modules where the cache on the
1683
+ # first iteration is already big enough, or if one passes custom cache
1684
+ valid_indices = non_attended_tokens < extended_attention_mask.size(-1)
1685
+ new_batch_index = batch_index[valid_indices]
1686
+ new_non_attended_tokens = non_attended_tokens[valid_indices]
1687
+
1688
+ # Zero-out the places where we don't need to attend
1689
+ extended_attention_mask[new_batch_index, new_non_attended_tokens] = 0
1690
+
1691
+ attention_mask = torch.cat((attention_mask, extended_attention_mask), dim=1)
1692
+ position_ids = torch.sum(attention_mask, dim=1).unsqueeze(-1) - 1
1693
+
1694
+ outputs = self.language_model(
1695
+ input_ids=None,
1696
+ attention_mask=attention_mask,
1697
+ position_ids=position_ids,
1698
+ past_key_values=past_key_values,
1699
+ inputs_embeds=inputs_embeds,
1700
+ use_cache=use_cache,
1701
+ output_attentions=output_attentions,
1702
+ output_hidden_states=output_hidden_states,
1703
+ return_dict=return_dict,
1704
+ )
1705
+
1706
+ logits = outputs[0]
1707
+
1708
+ if not return_dict:
1709
+ output = (logits,) + outputs[1:]
1710
+ return output
1711
+
1712
+ return LlavaCausalLMOutputWithPast(
1713
+ logits=logits,
1714
+ past_key_values=outputs.past_key_values,
1715
+ hidden_states=outputs.hidden_states,
1716
+ attentions=outputs.attentions,
1717
+ image_features=image_features,
1718
+ )
1719
+
1720
+ def prepare_inputs_for_generation(
1721
+ self,
1722
+ input_ids,
1723
+ past_key_values=None,
1724
+ inputs_embeds=None,
1725
+ attention_mask=None,
1726
+ image_features=None,
1727
+ **kwargs,
1728
+ ):
1729
+ if past_key_values is not None:
1730
+ if isinstance(past_key_values, Cache):
1731
+ cache_length = past_key_values.get_seq_length()
1732
+ past_length = past_key_values.seen_tokens
1733
+ max_cache_length = past_key_values.get_max_length()
1734
+ else:
1735
+ cache_length = past_length = past_key_values[0][0].shape[2]
1736
+ max_cache_length = None
1737
+
1738
+ # Keep only the unprocessed tokens:
1739
+ # 1 - If the length of the attention_mask exceeds the length of input_ids, then we are in a setting where
1740
+ # some of the inputs are exclusively passed as part of the cache (e.g. when passing input_embeds as
1741
+ # input)
1742
+ if (
1743
+ attention_mask is not None
1744
+ and attention_mask.shape[1] > input_ids.shape[1]
1745
+ ):
1746
+ input_ids = input_ids[:, -(attention_mask.shape[1] - past_length) :]
1747
+ # 2 - If the past_length is smaller than input_ids', then input_ids holds all input tokens. We can discard
1748
+ # input_ids based on the past_length.
1749
+ elif past_length < input_ids.shape[1]+image_features.shape[1]-1:
1750
+ past_length -= image_features.shape[1]-1
1751
+ input_ids = input_ids[:, past_length:]
1752
+ attention_mask = attention_mask[:, past_length:]
1753
+ # 3 - Otherwise (past_length >= input_ids.shape[1]), let's assume input_ids only has unprocessed tokens.
1754
+
1755
+ # If we are about to go beyond the maximum cache length, we need to crop the input attention mask.
1756
+ if (
1757
+ max_cache_length is not None
1758
+ and attention_mask is not None
1759
+ and cache_length + input_ids.shape[1] > max_cache_length
1760
+ ):
1761
+ attention_mask = attention_mask[:, -max_cache_length:]
1762
+
1763
+ position_ids = kwargs.get("position_ids", None)
1764
+ if attention_mask is not None and position_ids is None:
1765
+ # create position_ids on the fly for batch generation
1766
+ position_ids = attention_mask.long().cumsum(-1) - 1
1767
+ position_ids.masked_fill_(attention_mask == 0, 1)
1768
+ if past_key_values:
1769
+ position_ids = position_ids[:, -input_ids.shape[1] :]
1770
+
1771
+ # if `inputs_embeds` are passed, we only want to use them in the 1st generation step
1772
+ if inputs_embeds is not None and past_key_values is None:
1773
+ model_inputs = {"inputs_embeds": inputs_embeds}
1774
+ else:
1775
+ model_inputs = {"input_ids": input_ids}
1776
+
1777
+ model_inputs.update(
1778
+ {
1779
+ "position_ids": position_ids,
1780
+ "past_key_values": past_key_values,
1781
+ "use_cache": kwargs.get("use_cache"),
1782
+ "attention_mask": attention_mask,
1783
+ "image_features": image_features,
1784
+ }
1785
+ )
1786
+ return model_inputs
1787
+
1788
+ def _reorder_cache(self, *args, **kwargs):
1789
+ return self.language_model._reorder_cache(*args, **kwargs)
modeling_phi.py ADDED
@@ -0,0 +1,988 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Microsoft Corporation.
2
+ # Licensed under the MIT license.
3
+ #
4
+ # Copyright (c) 2022, Tri Dao, trid@cs.stanford.edu.
5
+ # Licensed under the BSD 3-Clause License.
6
+
7
+ from __future__ import annotations
8
+
9
+ import math
10
+ from dataclasses import dataclass, field
11
+ from typing import Any, Dict, Optional, Tuple, Union
12
+
13
+ import torch
14
+ import torch.nn as nn
15
+ from einops import rearrange, repeat
16
+ from transformers import PretrainedConfig, PreTrainedModel
17
+ from transformers.activations import ACT2FN
18
+ from transformers.modeling_outputs import CausalLMOutputWithPast
19
+
20
+ from configuration_phi import PhiConfig
21
+
22
+ try:
23
+ from flash_attn.bert_padding import pad_input, unpad_input
24
+ from flash_attn.layers.rotary import RotaryEmbedding as FlashRotaryEmbedding
25
+ from flash_attn.modules.mha import FlashCrossAttention, FlashSelfAttention
26
+ from flash_attn.ops.fused_dense import FusedDense
27
+ print("Using Flash Attention!")
28
+ except Exception as exc:
29
+ print(exc)
30
+ pad_input, unpad_input = None, None
31
+ FlashRotaryEmbedding = None
32
+ FlashSelfAttention, FlashCrossAttention = None, None
33
+ FusedDense = None
34
+ print("Not using Flash Attention!")
35
+
36
+
37
+ @dataclass
38
+ class InferenceParams:
39
+ """Inference parameters passed to model to efficiently calculate
40
+ and store context during inference.
41
+
42
+ Reference:
43
+ https://github.com/Dao-AILab/flash-attention/blob/main/flash_attn/utils/generation.py.
44
+
45
+ Args:
46
+ max_seqlen: Maximum sequence length.
47
+ max_batch_size: Maximum batch size.
48
+ seqlen_offset: Sequence length offset.
49
+ batch_size_offset: Batch size offset.
50
+ key_value_memory_dict: Key value memory dictionary.
51
+ lengths_per_sample: Lengths per sample.
52
+
53
+ """
54
+
55
+ max_seqlen: int = field(metadata={"help": "Maximum sequence length."})
56
+
57
+ max_batch_size: int = field(metadata={"help": "Maximum batch size."})
58
+
59
+ seqlen_offset: int = field(default=0, metadata={"help": "Sequence length offset."})
60
+
61
+ batch_size_offset: int = field(default=0, metadata={"help": "Batch size offset."})
62
+
63
+ key_value_memory_dict: Dict[str, Any] = field(
64
+ default_factory=dict, metadata={"help": "Key value memory dictionary."}
65
+ )
66
+
67
+ lengths_per_sample: torch.Tensor = field(default=None, metadata={"help": "Lengths per sample."})
68
+
69
+
70
+ class Embedding(nn.Module):
71
+ """Token embedding with dropout."""
72
+
73
+ def __init__(self, config: PretrainedConfig) -> None:
74
+ super().__init__()
75
+
76
+ self.wte = nn.Embedding(config.vocab_size, config.n_embd)
77
+ self.drop = nn.Dropout(config.embd_pdrop)
78
+
79
+ def forward(self, input_ids: torch.LongTensor) -> torch.FloatTensor:
80
+ input_shape = input_ids.size()
81
+ input_ids = input_ids.view(-1, input_shape[-1])
82
+
83
+ hidden_states = self.wte(input_ids)
84
+ hidden_states = self.drop(hidden_states)
85
+
86
+ return hidden_states
87
+
88
+
89
+ def _apply_rotary_emb(
90
+ x: torch.FloatTensor,
91
+ cos: torch.FloatTensor,
92
+ sin: torch.FloatTensor,
93
+ ) -> torch.FloatTensor:
94
+ _, seqlen, _, _ = x.shape
95
+ _, rotary_dim = cos.shape
96
+ rotary_dim *= 2
97
+
98
+ x_rot = x[:, :, :, :rotary_dim]
99
+ x_pass = x[:, :, :, rotary_dim:]
100
+
101
+ x1, x2 = x_rot.chunk(2, dim=-1)
102
+ c, s = rearrange(cos[:seqlen], "s d -> s 1 d"), rearrange(sin[:seqlen], "s d -> s 1 d")
103
+ x1, x2, c, s = [t.to(dtype=torch.float32) for t in [x1, x2, c, s]]
104
+
105
+ x_rot = torch.cat([x1 * c - x2 * s, x1 * s + x2 * c], axis=-1).to(x.dtype)
106
+
107
+ return torch.cat([x_rot, x_pass], axis=-1)
108
+
109
+
110
+ def _apply_rotary_emb_kv(
111
+ kv: torch.FloatTensor,
112
+ cos: torch.FloatTensor,
113
+ sin: torch.FloatTensor,
114
+ cos_k: Optional[torch.FloatTensor] = None,
115
+ sin_k: Optional[torch.FloatTensor] = None,
116
+ ) -> torch.FloatTensor:
117
+ _, seqlen, _, _, _ = kv.shape
118
+ _, rotary_dim = cos.shape
119
+ rotary_dim *= 2
120
+
121
+ k_rot = kv[:, :, 0, :, :rotary_dim]
122
+ k_pass = kv[:, :, 0, :, rotary_dim:]
123
+
124
+ k1, k2 = k_rot.chunk(2, dim=-1)
125
+ c, s = rearrange(cos[:seqlen], "s d -> s 1 d"), rearrange(sin[:seqlen], "s d -> s 1 d")
126
+ k1, k2, c, s = [t.to(dtype=torch.float32) for t in [k1, k2, c, s]]
127
+
128
+ k_rot = torch.cat([k1 * c - k2 * s, k1 * s + k2 * c], axis=-1).to(kv.dtype)
129
+
130
+ return torch.cat(
131
+ [
132
+ torch.cat([k_rot, k_pass], axis=-1).unsqueeze(2),
133
+ kv[:, :, 1:2, :, :],
134
+ ],
135
+ axis=2,
136
+ )
137
+
138
+
139
+ def _apply_rotary_emb_qkv(
140
+ qkv: torch.FloatTensor,
141
+ cos: torch.FloatTensor,
142
+ sin: torch.FloatTensor,
143
+ cos_k: Optional[torch.FloatTensor] = None,
144
+ sin_k: Optional[torch.FloatTensor] = None,
145
+ ) -> torch.FloatTensor:
146
+ _, seqlen, _, _, _ = qkv.shape
147
+ _, rotary_dim = cos.shape
148
+ rotary_dim *= 2
149
+
150
+ q_rot = qkv[:, :, 0, :, :rotary_dim]
151
+ q_pass = qkv[:, :, 0, :, rotary_dim:]
152
+
153
+ k_rot = qkv[:, :, 1, :, :rotary_dim]
154
+ k_pass = qkv[:, :, 1, :, rotary_dim:]
155
+
156
+ q1, q2 = q_rot.chunk(2, dim=-1)
157
+ k1, k2 = k_rot.chunk(2, dim=-1)
158
+ c, s = rearrange(cos[:seqlen], "s d -> s 1 d"), rearrange(sin[:seqlen], "s d -> s 1 d")
159
+ q1, q2, k1, k2, c, s = [t.to(dtype=torch.float32) for t in [q1, q2, k1, k2, c, s]]
160
+
161
+ q_rot = torch.cat([q1 * c - q2 * s, q1 * s + q2 * c], axis=-1).to(qkv.dtype)
162
+ k_rot = torch.cat([k1 * c - k2 * s, k1 * s + k2 * c], axis=-1).to(qkv.dtype)
163
+
164
+ return torch.cat(
165
+ [
166
+ torch.cat([q_rot, q_pass], axis=-1).unsqueeze(2),
167
+ torch.cat([k_rot, k_pass], axis=-1).unsqueeze(2),
168
+ qkv[:, :, 2:3, :, :],
169
+ ],
170
+ axis=2,
171
+ )
172
+
173
+
174
+ class RotaryEmbedding(nn.Module):
175
+ """Rotary positional embedding (RoPE).
176
+
177
+ Reference:
178
+ RoFormer: Enhanced Transformer with Rotary Position Embedding.
179
+ https://arxiv.org/pdf/2104.09864.pdf.
180
+
181
+ """
182
+
183
+ def __init__(
184
+ self,
185
+ dim: int,
186
+ base: int = 10000,
187
+ scale_base: Optional[float] = None,
188
+ pos_idx_in_fp32: bool = True,
189
+ max_position_embeddings: int = 2048,
190
+ device: Optional[str] = None,
191
+ **kwargs,
192
+ ) -> None:
193
+ super().__init__()
194
+
195
+ if scale_base is not None:
196
+ raise NotImplementedError
197
+
198
+ self.dim = dim
199
+ self.base = float(base)
200
+ self.scale_base = scale_base
201
+ self.pos_idx_in_fp32 = pos_idx_in_fp32
202
+ self.max_position_embeddings = max_position_embeddings
203
+ self.device = device
204
+
205
+ # Generate and save the inverse frequency buffer (non-trainable)
206
+ inv_freq = self._compute_inv_freq(device)
207
+ self.register_buffer("inv_freq", inv_freq, persistent=False)
208
+
209
+ # Generate and save the scale buffer (non-trainable)
210
+ scale = (
211
+ (torch.arange(0, dim, 2, device=device, dtype=torch.float32) + 0.4 * dim) / (1.4 * dim)
212
+ if scale_base is not None
213
+ else None
214
+ )
215
+ self.register_buffer("scale", scale, persistent=False)
216
+
217
+ # Initialize cached attributes since ONNX can't rely on dynamic initialization
218
+ self._update_cos_sin_cache(max_position_embeddings, device=device, dtype=torch.float32)
219
+
220
+ def _compute_inv_freq(self, device: Optional[str] = None) -> torch.FloatTensor:
221
+ return 1.0 / (self.base ** (torch.arange(0, self.dim, 2, device=device, dtype=torch.float32) / self.dim))
222
+
223
+ def _update_cos_sin_cache(
224
+ self,
225
+ seqlen: int,
226
+ device: Optional[str] = None,
227
+ dtype: Optional[torch.dtype] = None,
228
+ ) -> None:
229
+ self._seq_len_cached = seqlen
230
+
231
+ # fp32 is preferred since the output of `torch.arange` can be quite large
232
+ # and bf16 would lose a lot of precision
233
+ if self.pos_idx_in_fp32:
234
+ t = torch.arange(seqlen, device=device, dtype=torch.float32)
235
+ if self.inv_freq.dtype != torch.float32:
236
+ inv_freq = self._compute_inv_freq(device=device)
237
+ else:
238
+ inv_freq = self.inv_freq
239
+ else:
240
+ t = torch.arange(seqlen, device=device, dtype=self.inv_freq.dtype)
241
+ inv_freq = self.inv_freq
242
+
243
+ # `torch.outer` is preferred since `torch.einsum` converts from fp32 to fp16 if used with AMP
244
+ freqs = torch.outer(t, inv_freq)
245
+ if self.scale is None:
246
+ self._cos_cached = torch.cos(freqs).to(dtype)
247
+ self._sin_cached = torch.sin(freqs).to(dtype)
248
+ else:
249
+ power = (
250
+ torch.arange(seqlen, dtype=self.scale.dtype, device=self.scale.device) - seqlen // 2
251
+ ) / self.scale_base
252
+ scale = self.scale.to(device=power.device) ** rearrange(power, "s -> s 1")
253
+
254
+ # Force the scale multiplication to happen in fp32
255
+ self._cos_cached = (torch.cos(freqs) * scale).to(dtype)
256
+ self._sin_cached = (torch.sin(freqs) * scale).to(dtype)
257
+ self._cos_k_cached = (torch.cos(freqs) / scale).to(dtype)
258
+ self._sin_k_cached = (torch.sin(freqs) / scale).to(dtype)
259
+
260
+ def forward(
261
+ self,
262
+ qkv: torch.Tensor,
263
+ kv: Optional[torch.Tensor] = None,
264
+ seqlen_offset: int = 0,
265
+ **kwargs,
266
+ ) -> Tuple[torch.Tensor, torch.Tensor]:
267
+ if (
268
+ self._seq_len_cached < qkv.shape[1] + seqlen_offset
269
+ or self._cos_cached.device != qkv.device
270
+ or self._cos_cached.dtype != qkv.dtype
271
+ or (self.training and self._cos_cached.is_inference())
272
+ ):
273
+ self._update_cos_sin_cache(qkv.shape[1] + seqlen_offset, device=qkv.device, dtype=qkv.dtype)
274
+
275
+ if kv is None:
276
+ return _apply_rotary_emb_qkv(
277
+ qkv,
278
+ self._cos_cached[seqlen_offset:],
279
+ self._sin_cached[seqlen_offset:],
280
+ )
281
+ else:
282
+ q = _apply_rotary_emb(
283
+ qkv,
284
+ self._cos_cached[seqlen_offset:],
285
+ self._sin_cached[seqlen_offset:],
286
+ )
287
+ kv = _apply_rotary_emb_kv(
288
+ kv,
289
+ self._cos_cached[seqlen_offset:],
290
+ self._sin_cached[seqlen_offset:],
291
+ )
292
+
293
+ return q, kv
294
+
295
+
296
+ class MLP(nn.Module):
297
+ """Multi-Layer Perceptron.
298
+
299
+ Reference:
300
+ Attention Is All You Need.
301
+ https://arxiv.org/pdf/1706.03762.pdf.
302
+
303
+ """
304
+
305
+ def __init__(
306
+ self,
307
+ config: PretrainedConfig,
308
+ n_inner: Optional[int] = None,
309
+ act_fn: Optional[str] = None,
310
+ ) -> None:
311
+ super().__init__()
312
+
313
+ act_fn = config.activation_function if act_fn is None else act_fn
314
+
315
+ n_inner = getattr(config, "n_inner", None) if n_inner is None else n_inner
316
+ n_inner = n_inner if n_inner is not None else 4 * config.n_embd
317
+
318
+ self.fc1 = nn.Linear(config.n_embd, n_inner)
319
+ self.fc2 = nn.Linear(n_inner, config.n_embd)
320
+ self.act = ACT2FN[act_fn]
321
+
322
+ def forward(self, hidden_states: torch.FloatTensor) -> torch.FloatTensor:
323
+ hidden_states = self.fc1(hidden_states)
324
+ hidden_states = self.act(hidden_states)
325
+ hidden_states = self.fc2(hidden_states)
326
+
327
+ return hidden_states
328
+
329
+
330
+ class SelfAttention(nn.Module):
331
+ """Self-attention layer (compatible with PyTorch).
332
+
333
+ Reference:
334
+ https://github.com/Dao-AILab/flash-attention/blob/main/flash_attn/modules/mha.py.
335
+
336
+ """
337
+
338
+ def __init__(
339
+ self,
340
+ causal: bool = True,
341
+ softmax_scale: Optional[float] = None,
342
+ attention_dropout: float = 0.0,
343
+ ) -> None:
344
+ super().__init__()
345
+
346
+ self.causal = causal
347
+ self.softmax_scale = softmax_scale
348
+ self.drop = nn.Dropout(attention_dropout)
349
+
350
+ @torch.autocast("cpu", enabled=False)
351
+ @torch.autocast("cuda", enabled=False)
352
+ def forward(
353
+ self,
354
+ qkv: torch.FloatTensor,
355
+ causal: bool = None,
356
+ key_padding_mask: Optional[torch.BoolTensor] = None,
357
+ **kwargs,
358
+ ) -> torch.FloatTensor:
359
+ batch_size, seqlen = qkv.shape[0], qkv.shape[1]
360
+ q, k, v = qkv.unbind(dim=2)
361
+
362
+ q = q.to(torch.float32)
363
+ k = k.to(torch.float32)
364
+
365
+ causal = self.causal if causal is None else causal
366
+ softmax_scale = self.softmax_scale or 1.0 / math.sqrt(q.shape[-1])
367
+
368
+ # Autocast is manually disabled to avoid `torch.einsum` performing the operation
369
+ # using float16, which might lead to overflow
370
+ scores = torch.einsum("bthd,bshd->bhts", q, k * softmax_scale)
371
+
372
+ if key_padding_mask is not None:
373
+ padding_mask = torch.full((batch_size, seqlen), -10000.0, dtype=scores.dtype, device=scores.device)
374
+ padding_mask.masked_fill_(key_padding_mask, 0.0)
375
+
376
+ scores = scores + rearrange(padding_mask, "b s -> b 1 1 s")
377
+
378
+ if causal:
379
+ causal_mask = torch.triu(torch.full((seqlen, seqlen), -10000.0, device=scores.device), 1)
380
+ scores = scores + causal_mask.to(dtype=scores.dtype)
381
+
382
+ attention = torch.softmax(scores, dim=-1).to(v.dtype)
383
+ attention = self.drop(attention)
384
+
385
+ output = torch.einsum("bhts,bshd->bthd", attention, v)
386
+
387
+ return output
388
+
389
+
390
+ class CrossAttention(nn.Module):
391
+ """Cross-attention layer (compatible with PyTorch).
392
+
393
+ Reference:
394
+ https://github.com/Dao-AILab/flash-attention/blob/main/flash_attn/modules/mha.py.
395
+
396
+ """
397
+
398
+ def __init__(
399
+ self,
400
+ causal: bool = True,
401
+ softmax_scale: Optional[float] = None,
402
+ attention_dropout: float = 0.0,
403
+ ) -> None:
404
+ super().__init__()
405
+
406
+ self.causal = causal
407
+ self.softmax_scale = softmax_scale
408
+ self.drop = nn.Dropout(attention_dropout)
409
+
410
+ @torch.autocast("cpu", enabled=False)
411
+ @torch.autocast("cuda", enabled=False)
412
+ def forward(
413
+ self,
414
+ q: torch.FloatTensor,
415
+ kv: torch.FloatTensor,
416
+ causal: bool = None,
417
+ key_padding_mask: Optional[torch.BoolTensor] = None,
418
+ **kwargs,
419
+ ) -> torch.FloatTensor:
420
+ batch_size, seqlen_q = q.shape[0], q.shape[1]
421
+ seqlen_k = kv.shape[1]
422
+
423
+ if kv.shape[3] != q.shape[2]:
424
+ kv = repeat(kv, "... hkv d -> ... (hkv g) d", g=q.shape[2] // kv.shape[3])
425
+ k, v = kv.unbind(dim=2)
426
+
427
+ q = q.to(torch.float32)
428
+ k = k.to(torch.float32)
429
+
430
+ causal = self.causal if causal is None else causal
431
+ softmax_scale = self.softmax_scale or 1.0 / math.sqrt(q.shape[-1])
432
+
433
+ # Autocast is manually disabled to avoid `torch.einsum` performing the operation
434
+ # using float16, which might lead to overflow
435
+ scores = torch.einsum("bthd,bshd->bhts", q, k * softmax_scale)
436
+
437
+ if key_padding_mask is not None:
438
+ padding_mask = torch.full(
439
+ (batch_size, seqlen_k),
440
+ -10000.0,
441
+ dtype=scores.dtype,
442
+ device=scores.device,
443
+ )
444
+ padding_mask.masked_fill_(key_padding_mask, 0.0)
445
+
446
+ scores = scores + rearrange(padding_mask, "b s -> b 1 1 s")
447
+
448
+ if causal:
449
+ rows = rearrange(torch.arange(seqlen_q, device=q.device, dtype=torch.long), "s -> s 1")
450
+ cols = torch.arange(seqlen_k, device=k.device, dtype=torch.long)
451
+ causal_mask = cols > rows + seqlen_k - seqlen_q
452
+
453
+ scores = scores.masked_fill(causal_mask, -10000.0)
454
+
455
+ attention = torch.softmax(scores, dim=-1).to(v.dtype)
456
+ attention = self.drop(attention)
457
+
458
+ output = torch.einsum("bhts,bshd->bthd", attention, v)
459
+
460
+ return output
461
+
462
+
463
+ def _find_mha_dims(
464
+ config: PretrainedConfig,
465
+ n_head: Optional[int] = None,
466
+ n_head_kv: Optional[int] = None,
467
+ head_dim: Optional[int] = None,
468
+ ) -> Tuple[int, int]:
469
+ if n_head is None and head_dim is None:
470
+ head_dim = config.n_embd // config.n_head
471
+ n_head = config.n_head
472
+ elif n_head is None or head_dim is None:
473
+ raise ValueError("`n_head` and `head_dim` must be both specified or `None`.")
474
+
475
+ if n_head_kv is None:
476
+ n_head_kv = getattr(config, "n_head_kv", None) or n_head
477
+
478
+ return n_head, n_head_kv, head_dim
479
+
480
+
481
+ def _update_kv_cache(kv: torch.FloatTensor, inference_params: InferenceParams, layer_idx: int) -> torch.FloatTensor:
482
+ num_heads, head_dim = kv.shape[-2:]
483
+
484
+ if layer_idx not in inference_params.key_value_memory_dict:
485
+ inference_params.key_value_memory_dict[layer_idx] = torch.empty(
486
+ inference_params.max_batch_size,
487
+ inference_params.max_seqlen,
488
+ 2,
489
+ num_heads,
490
+ head_dim,
491
+ dtype=kv.dtype,
492
+ device=kv.device,
493
+ )
494
+
495
+ batch_start = inference_params.batch_size_offset
496
+ batch_end = batch_start + kv.shape[0]
497
+
498
+ sequence_start = inference_params.seqlen_offset
499
+ sequence_end = sequence_start + kv.shape[1]
500
+
501
+ # When the current sequence length is equal to or larger than the maximum sequence length,
502
+ # we need to concatenate the current `kv` with the cached `kv` to expand its length
503
+ if sequence_end >= inference_params.max_seqlen:
504
+ inference_params.key_value_memory_dict[layer_idx] = torch.concatenate((inference_params.key_value_memory_dict[layer_idx], kv), dim=1)
505
+
506
+ inference_params.key_value_memory_dict[layer_idx][batch_start:batch_end, sequence_start:sequence_end, ...] = kv
507
+ kv = inference_params.key_value_memory_dict[layer_idx][batch_start:batch_end, :sequence_end, ...]
508
+
509
+ return kv
510
+
511
+
512
+ class MHA(nn.Module):
513
+ """Multi-head attention layer."""
514
+
515
+ def __init__(
516
+ self,
517
+ config: PretrainedConfig,
518
+ dtype: Optional[torch.dtype] = None,
519
+ device: Optional[str] = None,
520
+ rotary_dim: Optional[int] = None,
521
+ rotary_base: float = 10000.0,
522
+ rotary_scale_base: Optional[float] = None,
523
+ n_head: Optional[int] = None,
524
+ n_head_kv: Optional[int] = None,
525
+ head_dim: Optional[int] = None,
526
+ bias: bool = True,
527
+ causal: bool = True,
528
+ softmax_scale: Optional[float] = None,
529
+ layer_idx: Optional[int] = None,
530
+ return_residual: bool = False,
531
+ checkpointing: bool = True,
532
+ ) -> None:
533
+ super().__init__()
534
+
535
+ # Rotary embedding
536
+ self.rotary_dim = rotary_dim if rotary_dim is not None else getattr(config, "rotary_dim", 0)
537
+ if self.rotary_dim > 0:
538
+ rotary_cls = FlashRotaryEmbedding if config.flash_rotary else RotaryEmbedding
539
+ if rotary_cls is None:
540
+ rotary_cls = RotaryEmbedding
541
+
542
+ rotary_kwargs = {}
543
+ if rotary_cls is RotaryEmbedding:
544
+ rotary_kwargs["max_position_embeddings"] = config.n_positions
545
+
546
+ self.rotary_emb = rotary_cls(
547
+ self.rotary_dim,
548
+ base=rotary_base,
549
+ scale_base=rotary_scale_base,
550
+ device=device,
551
+ **rotary_kwargs,
552
+ )
553
+
554
+ # MLP
555
+ self.n_head, self.n_head_kv, self.head_dim = _find_mha_dims(
556
+ config, n_head=n_head, n_head_kv=n_head_kv, head_dim=head_dim
557
+ )
558
+ op_size = self.head_dim * (self.n_head + 2 * self.n_head_kv)
559
+ hidden_size = config.n_embd
560
+
561
+ linear_cls = FusedDense if config.fused_dense else nn.Linear
562
+ if linear_cls is None:
563
+ linear_cls = nn.Linear
564
+
565
+ self.Wqkv = linear_cls(hidden_size, op_size, bias=bias, device=device, dtype=dtype)
566
+ self.out_proj = linear_cls(hidden_size, hidden_size, bias=bias, device=device, dtype=dtype)
567
+
568
+ # Attention
569
+ attn_cls = FlashSelfAttention if config.flash_attn else SelfAttention
570
+ if attn_cls is None:
571
+ attn_cls = SelfAttention
572
+
573
+ cross_attn_cls = FlashCrossAttention if config.flash_attn else CrossAttention
574
+ if cross_attn_cls is None:
575
+ cross_attn_cls = CrossAttention
576
+
577
+ self.inner_attn = attn_cls(
578
+ causal=causal,
579
+ softmax_scale=softmax_scale,
580
+ attention_dropout=config.attn_pdrop,
581
+ )
582
+ self.inner_cross_attn = cross_attn_cls(
583
+ causal=causal,
584
+ softmax_scale=softmax_scale,
585
+ attention_dropout=config.attn_pdrop,
586
+ )
587
+
588
+ self.flash_attn = config.flash_attn and attn_cls is FlashSelfAttention
589
+ self.layer_idx = layer_idx
590
+ self.return_residual = return_residual
591
+ self.checkpointing = checkpointing
592
+
593
+ def _forward_self_attn(
594
+ self, x: torch.FloatTensor, key_padding_mask: Optional[torch.BoolTensor]
595
+ ) -> torch.FloatTensor:
596
+ qkv = self.Wqkv(x)
597
+ qkv = rearrange(qkv, "... (three h d) -> ... three h d", three=3, d=self.head_dim)
598
+
599
+ if self.rotary_dim > 0:
600
+ qkv = self.rotary_emb(qkv)
601
+
602
+ if self.flash_attn:
603
+ batch_size, seqlen = qkv.shape[0], qkv.shape[1]
604
+
605
+ cu_seqlens, max_seqlen = None, None
606
+ if key_padding_mask is not None:
607
+ # If `key_padding_mask` is supplied, we need to unpad the input and retrieve
608
+ # the `cu_seqlens` and `max_seqlen` to be used by `flash-attn`
609
+ qkv, indices, cu_seqlens, max_seqlen = unpad_input(qkv, key_padding_mask)
610
+
611
+ if self.checkpointing:
612
+ attn_output = torch.utils.checkpoint.checkpoint(
613
+ self.inner_attn, qkv, None, cu_seqlens, max_seqlen, use_reentrant=False
614
+ )
615
+ else:
616
+ attn_output = self.inner_attn(qkv, cu_seqlens=cu_seqlens, max_seqlen=max_seqlen).to(qkv.device)
617
+
618
+ # If `key_padding_mask` is supplied, we need to pad the output back to the original shape
619
+ return pad_input(attn_output, indices, batch_size, seqlen) if key_padding_mask is not None else attn_output
620
+
621
+ if self.checkpointing:
622
+ return torch.utils.checkpoint.checkpoint(self.inner_attn, qkv, None, key_padding_mask, use_reentrant=False)
623
+
624
+ return self.inner_attn(qkv, key_padding_mask=key_padding_mask)
625
+
626
+ def _forward_cross_attn(
627
+ self,
628
+ x: torch.FloatTensor,
629
+ past_key_values: Optional[InferenceParams],
630
+ key_padding_mask: Optional[torch.BoolTensor],
631
+ ) -> torch.FloatTensor:
632
+ batch_size = x.shape[0]
633
+
634
+ qkv = self.Wqkv(x)
635
+
636
+ q = qkv[..., : self.n_head * self.head_dim]
637
+ q = rearrange(q, "... (h d) -> ... h d", d=self.head_dim)
638
+
639
+ kv = qkv[..., self.n_head * self.head_dim :]
640
+ kv = rearrange(kv, "... (two hkv d) -> ... two hkv d", two=2, d=self.head_dim)
641
+
642
+ seqlen_offset = past_key_values.seqlen_offset if past_key_values is not None else 0
643
+ causal = None if seqlen_offset == 0 else False
644
+ if self.rotary_dim > 0:
645
+ q, kv = self.rotary_emb(q, kv=kv, seqlen_offset=seqlen_offset)
646
+
647
+ if past_key_values is not None:
648
+ kv = _update_kv_cache(kv, past_key_values, self.layer_idx)
649
+
650
+ if self.flash_attn:
651
+ batch_size, seqlen_q = q.shape[0], q.shape[1]
652
+ seqlen_k = kv.shape[1]
653
+
654
+ cu_seqlens_q, cu_seqlens_k, max_seqlen_q, max_seqlen_k = (
655
+ None,
656
+ None,
657
+ None,
658
+ None,
659
+ )
660
+ if key_padding_mask is not None:
661
+ kv, _, cu_seqlens_k, max_seqlen_k = unpad_input(kv, key_padding_mask)
662
+
663
+ if seqlen_q == 1:
664
+ key_padding_mask = torch.ones(batch_size, 1, device=q.device)
665
+ elif seqlen_q != seqlen_k:
666
+ key_padding_mask = key_padding_mask[:, -seqlen_q:]
667
+
668
+ q, indices_q, cu_seqlens_q, max_seqlen_q = unpad_input(q, key_padding_mask)
669
+
670
+ if self.checkpointing:
671
+ attn_output = torch.utils.checkpoint.checkpoint(
672
+ self.inner_cross_attn,
673
+ q,
674
+ kv,
675
+ causal,
676
+ cu_seqlens_q,
677
+ max_seqlen_q,
678
+ cu_seqlens_k,
679
+ max_seqlen_k,
680
+ use_reentrant=False,
681
+ )
682
+ else:
683
+ attn_output = self.inner_cross_attn(
684
+ q,
685
+ kv,
686
+ causal=causal,
687
+ cu_seqlens=cu_seqlens_q,
688
+ max_seqlen=max_seqlen_q,
689
+ cu_seqlens_k=cu_seqlens_k,
690
+ max_seqlen_k=max_seqlen_k,
691
+ )
692
+
693
+ return (
694
+ pad_input(attn_output, indices_q, batch_size, max_seqlen_q)
695
+ if key_padding_mask is not None
696
+ else attn_output
697
+ )
698
+
699
+ if self.checkpointing:
700
+ return torch.utils.checkpoint.checkpoint(
701
+ self.inner_cross_attn,
702
+ q,
703
+ kv,
704
+ causal,
705
+ key_padding_mask,
706
+ use_reentrant=False,
707
+ )
708
+
709
+ return self.inner_cross_attn(q, kv, key_padding_mask=key_padding_mask, causal=causal)
710
+
711
+ def forward(
712
+ self,
713
+ x: torch.FloatTensor,
714
+ past_key_values: Optional[InferenceParams] = None,
715
+ attention_mask: Optional[Union[torch.LongTensor, torch.BoolTensor]] = None,
716
+ **kwargs,
717
+ ) -> Tuple[torch.FloatTensor, torch.FloatTensor]:
718
+ if attention_mask is not None:
719
+ attention_mask = attention_mask.bool()
720
+ else:
721
+ attention_mask = None
722
+
723
+ # MHA
724
+ if self.n_head == self.n_head_kv:
725
+ if past_key_values is None:
726
+ # If `past_key_values` are not supplied, we run self-attention
727
+ attn_output = self._forward_self_attn(x, attention_mask)
728
+ else:
729
+ # If `past_key_values` are supplied, it means that we might have cached values and
730
+ # could take advantage of cross-attention
731
+ attn_output = self._forward_cross_attn(x, past_key_values, attention_mask)
732
+ # MQA / GQA
733
+ else:
734
+ # Regardless of `past_key_values` being supplied or not, it always use cross-attention
735
+ # because `q` and `kv` lengths might be different
736
+ attn_output = self._forward_cross_attn(x, past_key_values, attention_mask)
737
+
738
+ output = rearrange(attn_output, "... h d -> ... (h d)")
739
+ output = self.out_proj(output)
740
+
741
+ return output if not self.return_residual else (output, x)
742
+
743
+
744
+ class ParallelBlock(nn.Module):
745
+ """Parallel block.
746
+
747
+ This block applies parallel mixer and MLP layers to the input (used in GPT-J and CodeGen).
748
+
749
+ """
750
+
751
+ def __init__(
752
+ self,
753
+ config: PretrainedConfig,
754
+ block_idx: Optional[int] = None,
755
+ ) -> None:
756
+ super().__init__()
757
+
758
+ self.ln = nn.LayerNorm(config.n_embd, eps=config.layer_norm_epsilon)
759
+ self.resid_dropout = nn.Dropout(config.resid_pdrop)
760
+ self.block_idx = block_idx
761
+
762
+ self.mixer = MHA(config, layer_idx=block_idx)
763
+ self.mlp = MLP(config)
764
+
765
+ def forward(
766
+ self,
767
+ hidden_states: torch.FloatTensor,
768
+ past_key_values: Optional[Union[torch.FloatTensor, InferenceParams]] = None,
769
+ attention_mask: Optional[torch.BoolTensor] = None,
770
+ **kwargs,
771
+ ) -> torch.FloatTensor:
772
+ residual = hidden_states
773
+ hidden_states = self.ln(hidden_states)
774
+
775
+ attn_outputs = self.mixer(
776
+ hidden_states,
777
+ past_key_values=past_key_values,
778
+ attention_mask=attention_mask,
779
+ )
780
+ if isinstance(attn_outputs, tuple):
781
+ attn_outputs = attn_outputs[0]
782
+
783
+ attn_outputs = self.resid_dropout(attn_outputs)
784
+ feed_forward_hidden_states = self.resid_dropout(self.mlp(hidden_states))
785
+
786
+ hidden_states = attn_outputs + feed_forward_hidden_states + residual
787
+
788
+ return hidden_states
789
+
790
+
791
+ class CausalLMHead(nn.Module):
792
+ """Causal Language Modeling head.
793
+
794
+ Reference:
795
+ Improving Language Understanding by Generative Pre-Training.
796
+ https://cdn.openai.com/research-covers/language-unsupervised/language_understanding_paper.pdf.
797
+
798
+ """
799
+
800
+ def __init__(self, config: PretrainedConfig) -> None:
801
+ super().__init__()
802
+
803
+ self.ln = nn.LayerNorm(config.n_embd, eps=config.layer_norm_epsilon)
804
+ self.linear = nn.Linear(config.n_embd, config.vocab_size)
805
+
806
+ def forward(self, hidden_states: torch.FloatTensor) -> torch.FloatTensor:
807
+ hidden_states = self.ln(hidden_states)
808
+ logits = self.linear(hidden_states).to(torch.float32)
809
+
810
+ return logits
811
+
812
+
813
+ class CausalLMLoss(nn.Module):
814
+ """Causal Language Modeling loss.
815
+
816
+ Reference:
817
+ Improving Language Understanding by Generative Pre-Training.
818
+ https://cdn.openai.com/research-covers/language-unsupervised/language_understanding_paper.pdf.
819
+
820
+ """
821
+
822
+ def __init__(self, shift_labels: bool = True) -> None:
823
+ super().__init__()
824
+
825
+ self.shift_labels = shift_labels
826
+ self.loss_fct = nn.CrossEntropyLoss()
827
+
828
+ def forward(self, logits: torch.FloatTensor, labels: torch.LongTensor) -> torch.FloatTensor:
829
+ if self.shift_labels:
830
+ logits = logits[..., :-1, :].contiguous()
831
+ labels = labels[..., 1:].contiguous()
832
+
833
+ loss = self.loss_fct(logits.view(-1, logits.size(-1)), labels.view(-1))
834
+
835
+ return loss
836
+
837
+
838
+ class PhiPreTrainedModel(PreTrainedModel):
839
+ """Phi pre-trained model."""
840
+
841
+ config_class = PhiConfig
842
+ base_model_prefix = "transformer"
843
+ supports_gradient_checkpointing = True
844
+ _no_split_modules = ["ParallelBlock"]
845
+
846
+ def __init__(self, *inputs, **kwargs) -> None:
847
+ super().__init__(*inputs, **kwargs)
848
+
849
+ def _init_weights(self, module: nn.Module) -> None:
850
+ if isinstance(module, (nn.Linear,)):
851
+ module.weight.data.normal_(mean=0.0, std=self.config.initializer_range)
852
+ if module.bias is not None:
853
+ module.bias.data.zero_()
854
+ elif isinstance(module, nn.Embedding):
855
+ module.weight.data.normal_(mean=0.0, std=self.config.initializer_range)
856
+ if module.padding_idx is not None:
857
+ module.weight.data[module.padding_idx].zero_()
858
+ elif isinstance(module, nn.LayerNorm):
859
+ if module.bias is not None:
860
+ module.bias.data.zero_()
861
+ module.weight.data.fill_(1.0)
862
+
863
+ def prepare_inputs_for_generation(
864
+ self,
865
+ input_ids: torch.LongTensor,
866
+ past_key_values: Optional[Union[torch.FloatTensor, InferenceParams]] = None,
867
+ attention_mask: Optional[Union[torch.LongTensor, torch.BoolTensor]] = None,
868
+ **kwargs,
869
+ ) -> Dict[str, Any]:
870
+ # if past_key_values is None or not (isinstance(past_key_values, InferenceParams)):
871
+ # past_key_values = InferenceParams(
872
+ # max_seqlen=self.config.n_positions,
873
+ # max_batch_size=input_ids.shape[0],
874
+ # seqlen_offset=0,
875
+ # batch_size_offset=0,
876
+ # key_value_memory_dict={},
877
+ # lengths_per_sample=None,
878
+ # )
879
+ # else:
880
+ # # Assume that `past_key_values` has cached all tokens up to the last token in `input_ids`
881
+ # past_key_values.seqlen_offset = input_ids.shape[1] - 1
882
+ # input_ids = input_ids[:, -1].unsqueeze(-1)
883
+ # attention_mask = attention_mask[:, -1].unsqueeze(-1)
884
+
885
+ return {
886
+ "input_ids": input_ids,
887
+ "past_key_values": past_key_values,
888
+ "attention_mask": attention_mask,
889
+ }
890
+
891
+
892
+ class PhiModel(PhiPreTrainedModel):
893
+ """Phi model."""
894
+
895
+ _keys_to_ignore_on_load_missing = [""]
896
+ _keys_to_ignore_on_load_unexpected = [r"h\.\d+\.mlp.(fc_in|fc_out)\.(weight|bias)"]
897
+
898
+ def __init__(self, config: PhiConfig) -> None:
899
+ config.flash_attn = True
900
+ config.flash_rotary = True
901
+ super().__init__(config)
902
+
903
+ self.embd = Embedding(config)
904
+ self.h = nn.ModuleList([ParallelBlock(config, block_idx=i) for i in range(config.n_layer)])
905
+ self.gradient_checkpointing = True
906
+ self.post_init()
907
+
908
+ def get_input_embeddings(self) -> nn.Embedding:
909
+ return self.embd.wte
910
+
911
+ def set_input_embeddings(self, new_embeddings: nn.Embedding) -> None:
912
+ self.embd.wte = new_embeddings
913
+
914
+ def forward(
915
+ self,
916
+ input_ids: torch.LongTensor,
917
+ inputs_embeds: Optional[torch.FloatTensor] = None,
918
+ past_key_values: Optional[Union[torch.FloatTensor, InferenceParams]] = None,
919
+ attention_mask: Optional[torch.BoolTensor] = None,
920
+ ) -> torch.FloatTensor:
921
+ if input_ids is not None:
922
+ hidden_states = self.embd(input_ids)
923
+ elif inputs_embeds is not None:
924
+ hidden_states = inputs_embeds
925
+ else:
926
+ raise ValueError("You have to specify either input_ids or inputs_embeds")
927
+
928
+ for layer in self.h:
929
+ if self.gradient_checkpointing:
930
+ hidden_states = torch.utils.checkpoint.checkpoint(
931
+ layer.__call__,
932
+ hidden_states,
933
+ past_key_values,
934
+ attention_mask,
935
+ use_reentrant=False,
936
+ )
937
+ else:
938
+ hidden_states = layer(
939
+ hidden_states,
940
+ past_key_values=past_key_values,
941
+ attention_mask=attention_mask,
942
+ )
943
+
944
+ return hidden_states
945
+
946
+
947
+ class PhiForCausalLM(PhiPreTrainedModel):
948
+ """Phi for Causal Language Modeling."""
949
+
950
+ _keys_to_ignore_on_load_missing = [""]
951
+ _keys_to_ignore_on_load_unexpected = [r"transformer\.h\.\d+\.mlp.(fc_in|fc_out)\.(weight|bias)"]
952
+
953
+ supports_gradient_checkpointing = True
954
+ _no_split_modules = ["ParallelBlock"]
955
+ _skip_keys_device_placement = "past_key_values"
956
+
957
+ def __init__(self, config: PhiConfig) -> None:
958
+ super().__init__(config)
959
+
960
+ self.transformer = PhiModel(config)
961
+ self.lm_head = CausalLMHead(config)
962
+ self.loss = CausalLMLoss()
963
+
964
+ self.post_init()
965
+
966
+ def get_output_embeddings(self) -> nn.Linear:
967
+ return self.lm_head.linear
968
+
969
+ def set_output_embeddings(self, new_embeddings: nn.Linear) -> None:
970
+ self.lm_head.linear = new_embeddings
971
+
972
+ def forward(
973
+ self,
974
+ input_ids: torch.LongTensor,
975
+ inputs_embeds: Optional[torch.FloatTensor] = None,
976
+ past_key_values: Optional[Union[torch.FloatTensor, InferenceParams]] = None,
977
+ attention_mask: Optional[torch.BoolTensor] = None,
978
+ labels: Optional[torch.LongTensor] = None,
979
+ **kwargs,
980
+ ) -> CausalLMOutputWithPast:
981
+ hidden_states = self.transformer(input_ids, inputs_embeds=inputs_embeds, past_key_values=past_key_values, attention_mask=attention_mask)
982
+ lm_logits = self.lm_head(hidden_states)
983
+
984
+ loss = None
985
+ if labels is not None:
986
+ loss = self.loss(lm_logits, labels)
987
+
988
+ return CausalLMOutputWithPast(loss=loss, logits=lm_logits, past_key_values=past_key_values)
preprocessor_config.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "auto_map": {
3
+ "AutoProcessor": "processing_llava.LlavaProcessor",
4
+ "AutoImageProcessor": "processing_llava.MultiCropImageProcessor"
5
+ },
6
+ "do_normalize": true,
7
+ "do_rescale": true,
8
+ "do_resize": true,
9
+ "image_mean": [
10
+ 0.5,
11
+ 0.5,
12
+ 0.5
13
+ ],
14
+ "image_std": [
15
+ 0.5,
16
+ 0.5,
17
+ 0.5
18
+ ],
19
+ "resample": 3,
20
+ "rescale_factor": 0.00392156862745098,
21
+ "size": {
22
+ "height": 384,
23
+ "width": 384
24
+ }
25
+ }
processing_llava.py ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import math
2
+ from typing import List, Optional, Union
3
+
4
+ import torch
5
+ from PIL import Image
6
+ from transformers import ImageProcessingMixin, ProcessorMixin, SiglipImageProcessor, AutoTokenizer, AutoImageProcessor
7
+ from transformers.feature_extraction_utils import BatchFeature
8
+ from transformers.image_utils import ImageInput
9
+ from transformers.tokenization_utils_base import (
10
+ PaddingStrategy,
11
+ PreTokenizedInput,
12
+ TextInput,
13
+ TruncationStrategy,
14
+ )
15
+ from transformers.utils import TensorType
16
+
17
+
18
+ class MultiCropImageProcessor(ImageProcessingMixin):
19
+ def __init__(self, model_name, max_crops=0, **kwargs):
20
+ self.processor = SiglipImageProcessor.from_pretrained(model_name)
21
+ self.crop_size = 384
22
+ self.max_crops = max_crops
23
+ self.stride_ratio = 2
24
+
25
+ def __call__(
26
+ self,
27
+ images: List[Image.Image],
28
+ max_crops: int = -1,
29
+ ):
30
+ res = {
31
+ "pixel_values": [],
32
+ "coords": [],
33
+ }
34
+ if max_crops < 0:
35
+ max_crops = self.max_crops
36
+ for image in images:
37
+ outputs, output_coords = self.process_image(image, max_crops)
38
+ res["pixel_values"].append(outputs)
39
+ res["coords"].append(output_coords)
40
+ return res
41
+
42
+ def process_image(
43
+ self,
44
+ image: Image.Image,
45
+ max_crops: int
46
+ ):
47
+ outputs = []
48
+ output_coords = []
49
+ outputs.append(self.processor(image, return_tensors="pt").pixel_values)
50
+ output_coords.append(torch.tensor([0.5, 0.5]))
51
+ width, height = image.size
52
+ crop_size = self.crop_size
53
+ stride = crop_size // self.stride_ratio
54
+ if (
55
+ max_crops == 0
56
+ or width <= (crop_size + stride)
57
+ and height <= (crop_size + stride)
58
+ ):
59
+ outputs = torch.cat(outputs, dim=0)
60
+ output_coords = torch.cat(output_coords, dim=0)
61
+ return outputs, output_coords
62
+ total_tokens = math.inf
63
+ while total_tokens > max_crops:
64
+ total_tokens = (
65
+ math.floor((width - crop_size) / stride) + 1
66
+ ) * (
67
+ math.floor((height - crop_size) / stride) + 1
68
+ )
69
+ if total_tokens > max_crops:
70
+ crop_size += 10
71
+ stride = crop_size // self.stride_ratio
72
+ stride = crop_size // self.stride_ratio
73
+ x_steps = int(math.floor((width - crop_size) / stride) + 1)
74
+ if x_steps < 1:
75
+ x_steps = 1
76
+ y_steps = int(math.floor((height - crop_size) / stride) + 1)
77
+ if y_steps < 1:
78
+ y_steps = 1
79
+ if x_steps == 1 and y_steps == 1:
80
+ outputs = torch.cat(outputs, dim=0)
81
+ output_coords = torch.cat(output_coords, dim=0)
82
+ return outputs, output_coords
83
+ x_coords = []
84
+ y_coords = []
85
+ for i in range(x_steps):
86
+ x_coords.append([i * stride, i * stride + crop_size])
87
+ if x_coords[-1][1] != width:
88
+ x_coords[-1][1] = width
89
+ for i in range(y_steps):
90
+ y_coords.append([i * stride, i * stride + crop_size])
91
+ if y_coords[-1][1] != height:
92
+ y_coords[-1][1] = height
93
+ image_parts = []
94
+ part_coords = []
95
+ for i in range(len(x_coords)):
96
+ for j in range(len(y_coords)):
97
+ image_parts.append(
98
+ image.crop(
99
+ (x_coords[i][0], y_coords[j][0], x_coords[i][1], y_coords[j][1])
100
+ )
101
+ )
102
+ part_coords.append(
103
+ torch.tensor(
104
+ [
105
+ (x_coords[i][0] + x_coords[i][1]) / 2 / width,
106
+ (y_coords[j][0] + y_coords[j][1]) / 2 / height,
107
+ ]
108
+ )
109
+ )
110
+ for image_part in image_parts:
111
+ outputs.append(self.processor(image_part, return_tensors="pt").pixel_values)
112
+ for part_coord in part_coords:
113
+ output_coords.append(part_coord)
114
+ outputs = torch.cat(outputs, dim=0)
115
+ output_coords = torch.stack(output_coords, dim=0)
116
+ return outputs, output_coords
117
+
118
+
119
+ class LlavaProcessor(ProcessorMixin):
120
+ attributes = ["image_processor", "tokenizer"]
121
+ image_processor_class = MultiCropImageProcessor
122
+ tokenizer_class = "SiglipTokenizer"
123
+
124
+ def __init__(self, image_processor: MultiCropImageProcessor, tokenizer):
125
+ self.image_processor = image_processor
126
+ self.tokenizer = tokenizer
127
+ self.search_model = None
128
+
129
+ @classmethod
130
+ def from_pretrained(cls, path, trust_remote_code=True, **kwargs):
131
+ tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=trust_remote_code)
132
+ image_processor = MultiCropImageProcessor(path, trust_remote_code=trust_remote_code)
133
+ return LlavaProcessor(image_processor, tokenizer)
134
+
135
+ def __call__(
136
+ self,
137
+ text: Union[
138
+ TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]
139
+ ] = None,
140
+ images: ImageInput = None,
141
+ model = None,
142
+ max_crops: int = 0,
143
+ num_tokens = None,
144
+ padding: Union[bool, str, PaddingStrategy] = False,
145
+ truncation: Union[bool, str, TruncationStrategy] = None,
146
+ max_length=None,
147
+ return_tensors: Optional[Union[str, TensorType]] = TensorType.PYTORCH,
148
+ ) -> BatchFeature:
149
+ if images is not None:
150
+ processor_outputs = self.image_processor(images, max_crops)
151
+ pixel_values = processor_outputs["pixel_values"]
152
+ pixel_values = [
153
+ value.to(model.device).to(model.dtype) for value in pixel_values
154
+ ]
155
+ coords = processor_outputs["coords"]
156
+ coords = [value.to(model.device).to(model.dtype) for value in coords]
157
+ image_outputs = model.vision_model(pixel_values, coords, num_tokens)
158
+ image_features = model.multi_modal_projector(image_outputs)
159
+ else:
160
+ image_features = None
161
+ text_inputs = self.tokenizer(
162
+ text,
163
+ return_tensors=return_tensors,
164
+ padding=padding,
165
+ truncation=truncation,
166
+ max_length=max_length,
167
+ )
168
+ text_inputs['input_ids'] = text_inputs['input_ids'].to(model.device)
169
+ text_inputs['attention_mask'] = text_inputs['attention_mask'].to(model.device)
170
+ return BatchFeature(data={**text_inputs, "image_features": image_features})
171
+
172
+ def batch_decode(self, *args, **kwargs):
173
+ return self.tokenizer.batch_decode(*args, **kwargs)
174
+
175
+ def decode(self, *args, **kwargs):
176
+ return self.tokenizer.decode(*args, **kwargs)
177
+
178
+ @property
179
+ def model_input_names(self):
180
+ tokenizer_input_names = self.tokenizer.model_input_names
181
+ image_processor_input_names = self.image_processor.model_input_names
182
+ return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names))
special_tokens_map.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<|endoftext|>",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "eos_token": {
10
+ "content": "<|im_end|>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": {
17
+ "content": "<pad>",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "unk_token": {
24
+ "content": "<|endoftext|>",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ }
30
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,356 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "added_tokens_decoder": {
4
+ "50256": {
5
+ "content": "<|endoftext|>",
6
+ "lstrip": false,
7
+ "normalized": false,
8
+ "rstrip": false,
9
+ "single_word": false,
10
+ "special": true
11
+ },
12
+ "50257": {
13
+ "content": " ",
14
+ "lstrip": false,
15
+ "normalized": true,
16
+ "rstrip": false,
17
+ "single_word": false,
18
+ "special": false
19
+ },
20
+ "50258": {
21
+ "content": " ",
22
+ "lstrip": false,
23
+ "normalized": true,
24
+ "rstrip": false,
25
+ "single_word": false,
26
+ "special": false
27
+ },
28
+ "50259": {
29
+ "content": " ",
30
+ "lstrip": false,
31
+ "normalized": true,
32
+ "rstrip": false,
33
+ "single_word": false,
34
+ "special": false
35
+ },
36
+ "50260": {
37
+ "content": " ",
38
+ "lstrip": false,
39
+ "normalized": true,
40
+ "rstrip": false,
41
+ "single_word": false,
42
+ "special": false
43
+ },
44
+ "50261": {
45
+ "content": " ",
46
+ "lstrip": false,
47
+ "normalized": true,
48
+ "rstrip": false,
49
+ "single_word": false,
50
+ "special": false
51
+ },
52
+ "50262": {
53
+ "content": " ",
54
+ "lstrip": false,
55
+ "normalized": true,
56
+ "rstrip": false,
57
+ "single_word": false,
58
+ "special": false
59
+ },
60
+ "50263": {
61
+ "content": " ",
62
+ "lstrip": false,
63
+ "normalized": true,
64
+ "rstrip": false,
65
+ "single_word": false,
66
+ "special": false
67
+ },
68
+ "50264": {
69
+ "content": " ",
70
+ "lstrip": false,
71
+ "normalized": true,
72
+ "rstrip": false,
73
+ "single_word": false,
74
+ "special": false
75
+ },
76
+ "50265": {
77
+ "content": " ",
78
+ "lstrip": false,
79
+ "normalized": true,
80
+ "rstrip": false,
81
+ "single_word": false,
82
+ "special": false
83
+ },
84
+ "50266": {
85
+ "content": " ",
86
+ "lstrip": false,
87
+ "normalized": true,
88
+ "rstrip": false,
89
+ "single_word": false,
90
+ "special": false
91
+ },
92
+ "50267": {
93
+ "content": " ",
94
+ "lstrip": false,
95
+ "normalized": true,
96
+ "rstrip": false,
97
+ "single_word": false,
98
+ "special": false
99
+ },
100
+ "50268": {
101
+ "content": " ",
102
+ "lstrip": false,
103
+ "normalized": true,
104
+ "rstrip": false,
105
+ "single_word": false,
106
+ "special": false
107
+ },
108
+ "50269": {
109
+ "content": " ",
110
+ "lstrip": false,
111
+ "normalized": true,
112
+ "rstrip": false,
113
+ "single_word": false,
114
+ "special": false
115
+ },
116
+ "50270": {
117
+ "content": " ",
118
+ "lstrip": false,
119
+ "normalized": true,
120
+ "rstrip": false,
121
+ "single_word": false,
122
+ "special": false
123
+ },
124
+ "50271": {
125
+ "content": " ",
126
+ "lstrip": false,
127
+ "normalized": true,
128
+ "rstrip": false,
129
+ "single_word": false,
130
+ "special": false
131
+ },
132
+ "50272": {
133
+ "content": " ",
134
+ "lstrip": false,
135
+ "normalized": true,
136
+ "rstrip": false,
137
+ "single_word": false,
138
+ "special": false
139
+ },
140
+ "50273": {
141
+ "content": " ",
142
+ "lstrip": false,
143
+ "normalized": true,
144
+ "rstrip": false,
145
+ "single_word": false,
146
+ "special": false
147
+ },
148
+ "50274": {
149
+ "content": " ",
150
+ "lstrip": false,
151
+ "normalized": true,
152
+ "rstrip": false,
153
+ "single_word": false,
154
+ "special": false
155
+ },
156
+ "50275": {
157
+ "content": " ",
158
+ "lstrip": false,
159
+ "normalized": true,
160
+ "rstrip": false,
161
+ "single_word": false,
162
+ "special": false
163
+ },
164
+ "50276": {
165
+ "content": " ",
166
+ "lstrip": false,
167
+ "normalized": true,
168
+ "rstrip": false,
169
+ "single_word": false,
170
+ "special": false
171
+ },
172
+ "50277": {
173
+ "content": " ",
174
+ "lstrip": false,
175
+ "normalized": true,
176
+ "rstrip": false,
177
+ "single_word": false,
178
+ "special": false
179
+ },
180
+ "50278": {
181
+ "content": " ",
182
+ "lstrip": false,
183
+ "normalized": true,
184
+ "rstrip": false,
185
+ "single_word": false,
186
+ "special": false
187
+ },
188
+ "50279": {
189
+ "content": " ",
190
+ "lstrip": false,
191
+ "normalized": true,
192
+ "rstrip": false,
193
+ "single_word": false,
194
+ "special": false
195
+ },
196
+ "50280": {
197
+ "content": " ",
198
+ "lstrip": false,
199
+ "normalized": true,
200
+ "rstrip": false,
201
+ "single_word": false,
202
+ "special": false
203
+ },
204
+ "50281": {
205
+ "content": " ",
206
+ "lstrip": false,
207
+ "normalized": true,
208
+ "rstrip": false,
209
+ "single_word": false,
210
+ "special": false
211
+ },
212
+ "50282": {
213
+ "content": " ",
214
+ "lstrip": false,
215
+ "normalized": true,
216
+ "rstrip": false,
217
+ "single_word": false,
218
+ "special": false
219
+ },
220
+ "50283": {
221
+ "content": " ",
222
+ "lstrip": false,
223
+ "normalized": true,
224
+ "rstrip": false,
225
+ "single_word": false,
226
+ "special": false
227
+ },
228
+ "50284": {
229
+ "content": " ",
230
+ "lstrip": false,
231
+ "normalized": true,
232
+ "rstrip": false,
233
+ "single_word": false,
234
+ "special": false
235
+ },
236
+ "50285": {
237
+ "content": " ",
238
+ "lstrip": false,
239
+ "normalized": true,
240
+ "rstrip": false,
241
+ "single_word": false,
242
+ "special": false
243
+ },
244
+ "50286": {
245
+ "content": " ",
246
+ "lstrip": false,
247
+ "normalized": true,
248
+ "rstrip": false,
249
+ "single_word": false,
250
+ "special": false
251
+ },
252
+ "50287": {
253
+ "content": "\t\t\t\t\t\t\t\t\t",
254
+ "lstrip": false,
255
+ "normalized": true,
256
+ "rstrip": false,
257
+ "single_word": false,
258
+ "special": false
259
+ },
260
+ "50288": {
261
+ "content": "\t\t\t\t\t\t\t\t",
262
+ "lstrip": false,
263
+ "normalized": true,
264
+ "rstrip": false,
265
+ "single_word": false,
266
+ "special": false
267
+ },
268
+ "50289": {
269
+ "content": "\t\t\t\t\t\t\t",
270
+ "lstrip": false,
271
+ "normalized": true,
272
+ "rstrip": false,
273
+ "single_word": false,
274
+ "special": false
275
+ },
276
+ "50290": {
277
+ "content": "\t\t\t\t\t\t",
278
+ "lstrip": false,
279
+ "normalized": true,
280
+ "rstrip": false,
281
+ "single_word": false,
282
+ "special": false
283
+ },
284
+ "50291": {
285
+ "content": "\t\t\t\t\t",
286
+ "lstrip": false,
287
+ "normalized": true,
288
+ "rstrip": false,
289
+ "single_word": false,
290
+ "special": false
291
+ },
292
+ "50292": {
293
+ "content": "\t\t\t\t",
294
+ "lstrip": false,
295
+ "normalized": true,
296
+ "rstrip": false,
297
+ "single_word": false,
298
+ "special": false
299
+ },
300
+ "50293": {
301
+ "content": "\t\t\t",
302
+ "lstrip": false,
303
+ "normalized": true,
304
+ "rstrip": false,
305
+ "single_word": false,
306
+ "special": false
307
+ },
308
+ "50294": {
309
+ "content": "\t\t",
310
+ "lstrip": false,
311
+ "normalized": true,
312
+ "rstrip": false,
313
+ "single_word": false,
314
+ "special": false
315
+ },
316
+ "50295": {
317
+ "content": "<|im_end|>",
318
+ "lstrip": false,
319
+ "normalized": false,
320
+ "rstrip": false,
321
+ "single_word": false,
322
+ "special": true
323
+ },
324
+ "50296": {
325
+ "content": "<|im_start|>",
326
+ "lstrip": false,
327
+ "normalized": false,
328
+ "rstrip": false,
329
+ "single_word": false,
330
+ "special": false
331
+ },
332
+ "50297": {
333
+ "content": "<image>",
334
+ "lstrip": false,
335
+ "normalized": false,
336
+ "rstrip": false,
337
+ "single_word": false,
338
+ "special": true
339
+ },
340
+ "50298": {
341
+ "content": "<pad>",
342
+ "lstrip": false,
343
+ "normalized": false,
344
+ "rstrip": false,
345
+ "single_word": false,
346
+ "special": true
347
+ }
348
+ },
349
+ "bos_token": "<|endoftext|>",
350
+ "clean_up_tokenization_spaces": true,
351
+ "eos_token": "<|im_end|>",
352
+ "model_max_length": 2048,
353
+ "pad_token": "<pad>",
354
+ "tokenizer_class": "CodeGenTokenizer",
355
+ "unk_token": "<|endoftext|>"
356
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff