LayTextLLM commited on
Commit
7d75019
1 Parent(s): 55d63c8

Upload LlamaForCausalLM

Browse files
build_mlp.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import torch
3
+ import torch.nn as nn
4
+ import math
5
+ import re
6
+
7
+ def build_layout_projector():
8
+ projector_type = 'mlp2x_gelu'
9
+ mm_hidden_size = 4
10
+ hidden_size = 4096
11
+
12
+ mlp_gelu_match = re.match(r'^mlp(\d+)x_gelu$', projector_type)
13
+ if mlp_gelu_match:
14
+ mlp_depth = int(mlp_gelu_match.group(1))
15
+ modules = [nn.Linear(mm_hidden_size, hidden_size)]
16
+ for _ in range(1, mlp_depth):
17
+ modules.append(nn.GELU())
18
+ modules.append(nn.Linear(hidden_size, hidden_size))
19
+ return nn.Sequential(*modules)
20
+
21
+ if projector_type == 'identity':
22
+ return IdentityMap()
23
+
24
+ raise ValueError(f'Unknown projector type: {projector_type}')
25
+
26
+
27
+ class IdentityMap(nn.Module):
28
+
29
+ def __init__(self):
30
+ super().__init__()
31
+
32
+ def forward(self, x, *args, **kwargs):
33
+ return x
34
+
35
+ @property
36
+ def config(self):
37
+ return {'mm_projector_type': 'identity'}
38
+
39
+ class PLoRA(nn.Linear):
40
+
41
+ def __init__(self,
42
+ in_features: int,
43
+ out_features: int,
44
+ bias: bool = True,
45
+ device=None,
46
+ dtype=None,
47
+ lora_r=8,
48
+ lora_alpha=16,
49
+ lora_dropout=0.05,
50
+ lora_len=0,
51
+ **kwargs) -> None:
52
+ super().__init__(in_features, out_features, bias, device, dtype)
53
+ self.lora_r = lora_r
54
+ self.lora_alpha = lora_alpha
55
+ self.lora_len = lora_len
56
+ if lora_dropout > 0.:
57
+ self.lora_dropout = nn.Dropout(p=lora_dropout)
58
+ else:
59
+ self.lora_dropout = lambda x: x
60
+ self.lora_scaling = self.lora_alpha / self.lora_r
61
+
62
+ self.Plora_A = nn.Linear(
63
+ in_features, self.lora_r, bias=False, device=device, dtype=dtype)
64
+ self.Plora_B = nn.Linear(
65
+ self.lora_r, out_features, bias=False, device=device, dtype=dtype)
66
+
67
+ self.reset_parameters()
68
+
69
+ def reset_parameters(self):
70
+ if hasattr(self, 'lora_A'):
71
+ # initialize A the same way as the default for nn.Linear and B to zero
72
+ nn.init.kaiming_uniform_(self.lora_A.weight, a=math.sqrt(5))
73
+ nn.init.zeros_(self.lora_B.weight)
74
+
75
+ def forward(self, x, im_mask=None):
76
+ res = super().forward(x)
77
+ if im_mask is not None:
78
+ if torch.sum(im_mask) > 0:
79
+ part_x = x[im_mask]
80
+ res[im_mask] += self.Plora_B(
81
+ self.Plora_A(
82
+ self.lora_dropout(part_x))) * self.lora_scaling
83
+ else:
84
+ part_x = x[:, :1]
85
+ res[:, :1] += self.Plora_B(
86
+ self.Plora_A(self.lora_dropout(part_x))) * 0
87
+ return res
config.json ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "/mnt/bn/haiyang-nas-lq/laytextllm/pretrained/laytextllm_all",
3
+ "architectures": [
4
+ "LlamaForCausalLM"
5
+ ],
6
+ "attention_bias": false,
7
+ "attention_dropout": 0.0,
8
+ "auto_map": {
9
+ "AutoConfig": "configuration_llama.LlamaConfig",
10
+ "AutoModelForCausalLM": "modeling_llama.LlamaForCausalLM"
11
+ },
12
+ "bos_token_id": 1,
13
+ "eos_token_id": 2,
14
+ "hidden_act": "silu",
15
+ "hidden_size": 4096,
16
+ "initializer_range": 0.02,
17
+ "intermediate_size": 11008,
18
+ "lora_alpha": 256,
19
+ "lora_r": 256,
20
+ "max_position_embeddings": 4096,
21
+ "model_type": "llama",
22
+ "num_attention_heads": 32,
23
+ "num_hidden_layers": 32,
24
+ "num_key_value_heads": 32,
25
+ "pretraining_tp": 1,
26
+ "rms_norm_eps": 1e-05,
27
+ "rope_scaling": null,
28
+ "rope_theta": 10000.0,
29
+ "tie_word_embeddings": false,
30
+ "torch_dtype": "float32",
31
+ "transformers_version": "4.36.2",
32
+ "use_cache": true,
33
+ "vocab_size": 32000
34
+ }
configuration_llama.py ADDED
@@ -0,0 +1,191 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2022 EleutherAI and the HuggingFace Inc. team. All rights reserved.
3
+ #
4
+ # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
5
+ # and OPT implementations in this library. It has been modified from its
6
+ # original forms to accommodate minor architectural differences compared
7
+ # to GPT-NeoX and OPT used by the Meta AI team that trained the model.
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ """ LLaMA model configuration"""
21
+
22
+ from transformers.configuration_utils import PretrainedConfig
23
+ from transformers.utils import logging
24
+
25
+
26
+ logger = logging.get_logger(__name__)
27
+
28
+ LLAMA_PRETRAINED_CONFIG_ARCHIVE_MAP = {}
29
+
30
+
31
+ class LlamaConfig(PretrainedConfig):
32
+ r"""
33
+ This is the configuration class to store the configuration of a [`LlamaModel`]. It is used to instantiate an LLaMA
34
+ model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
35
+ defaults will yield a similar configuration to that of the LLaMA-7B.
36
+
37
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
38
+ documentation from [`PretrainedConfig`] for more information.
39
+
40
+
41
+ Args:
42
+ vocab_size (`int`, *optional*, defaults to 32000):
43
+ Vocabulary size of the LLaMA model. Defines the number of different tokens that can be represented by the
44
+ `inputs_ids` passed when calling [`LlamaModel`]
45
+ hidden_size (`int`, *optional*, defaults to 4096):
46
+ Dimension of the hidden representations.
47
+ intermediate_size (`int`, *optional*, defaults to 11008):
48
+ Dimension of the MLP representations.
49
+ num_hidden_layers (`int`, *optional*, defaults to 32):
50
+ Number of hidden layers in the Transformer decoder.
51
+ num_attention_heads (`int`, *optional*, defaults to 32):
52
+ Number of attention heads for each attention layer in the Transformer decoder.
53
+ num_key_value_heads (`int`, *optional*):
54
+ This is the number of key_value heads that should be used to implement Grouped Query Attention. If
55
+ `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
56
+ `num_key_value_heads=1 the model will use Multi Query Attention (MQA) otherwise GQA is used. When
57
+ converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
58
+ by meanpooling all the original heads within that group. For more details checkout [this
59
+ paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to
60
+ `num_attention_heads`.
61
+ hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
62
+ The non-linear activation function (function or string) in the decoder.
63
+ max_position_embeddings (`int`, *optional*, defaults to 2048):
64
+ The maximum sequence length that this model might ever be used with. Llama 1 supports up to 2048 tokens,
65
+ Llama 2 up to 4096, CodeLlama up to 16384.
66
+ initializer_range (`float`, *optional*, defaults to 0.02):
67
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
68
+ rms_norm_eps (`float`, *optional*, defaults to 1e-06):
69
+ The epsilon used by the rms normalization layers.
70
+ use_cache (`bool`, *optional*, defaults to `True`):
71
+ Whether or not the model should return the last key/values attentions (not used by all models). Only
72
+ relevant if `config.is_decoder=True`.
73
+ pad_token_id (`int`, *optional*):
74
+ Padding token id.
75
+ bos_token_id (`int`, *optional*, defaults to 1):
76
+ Beginning of stream token id.
77
+ eos_token_id (`int`, *optional*, defaults to 2):
78
+ End of stream token id.
79
+ pretraining_tp (`int`, *optional*, defaults to 1):
80
+ Experimental feature. Tensor parallelism rank used during pretraining. Please refer to [this
81
+ document](https://huggingface.co/docs/transformers/parallelism) to understand more about it. This value is
82
+ necessary to ensure exact reproducibility of the pretraining results. Please refer to [this
83
+ issue](https://github.com/pytorch/pytorch/issues/76232).
84
+ tie_word_embeddings (`bool`, *optional*, defaults to `False`):
85
+ Whether to tie weight embeddings
86
+ rope_theta (`float`, *optional*, defaults to 10000.0):
87
+ The base period of the RoPE embeddings.
88
+ rope_scaling (`Dict`, *optional*):
89
+ Dictionary containing the scaling configuration for the RoPE embeddings. Currently supports two scaling
90
+ strategies: linear and dynamic. Their scaling factor must be a float greater than 1. The expected format is
91
+ `{"type": strategy name, "factor": scaling factor}`. When using this flag, don't update
92
+ `max_position_embeddings` to the expected new maximum. See the following thread for more information on how
93
+ these scaling strategies behave:
94
+ https://www.reddit.com/r/LocalLLaMA/comments/14mrgpr/dynamically_scaled_rope_further_increases/. This is an
95
+ experimental feature, subject to breaking API changes in future versions.
96
+ attention_bias (`bool`, defaults to `False`, *optional*, defaults to `False`):
97
+ Whether to use a bias in the query, key, value and output projection layers during self-attention.
98
+ attention_dropout (`float`, *optional*, defaults to 0.0):
99
+ The dropout ratio for the attention probabilities.
100
+
101
+ ```python
102
+ >>> from transformers import LlamaModel, LlamaConfig
103
+
104
+ >>> # Initializing a LLaMA llama-7b style configuration
105
+ >>> configuration = LlamaConfig()
106
+
107
+ >>> # Initializing a model from the llama-7b style configuration
108
+ >>> model = LlamaModel(configuration)
109
+
110
+ >>> # Accessing the model configuration
111
+ >>> configuration = model.config
112
+ ```"""
113
+
114
+ model_type = "llama"
115
+ keys_to_ignore_at_inference = ["past_key_values"]
116
+
117
+ def __init__(
118
+ self,
119
+ vocab_size=32000,
120
+ hidden_size=4096,
121
+ intermediate_size=11008,
122
+ num_hidden_layers=32,
123
+ num_attention_heads=32,
124
+ num_key_value_heads=None,
125
+ hidden_act="silu",
126
+ max_position_embeddings=2048,
127
+ initializer_range=0.02,
128
+ rms_norm_eps=1e-6,
129
+ use_cache=True,
130
+ pad_token_id=None,
131
+ bos_token_id=1,
132
+ eos_token_id=2,
133
+ pretraining_tp=1,
134
+ tie_word_embeddings=False,
135
+ rope_theta=10000.0,
136
+ rope_scaling=None,
137
+ attention_bias=False,
138
+ attention_dropout=0.0,
139
+ **kwargs,
140
+ ):
141
+ self.vocab_size = vocab_size
142
+ self.max_position_embeddings = max_position_embeddings
143
+ self.hidden_size = hidden_size
144
+ self.intermediate_size = intermediate_size
145
+ self.num_hidden_layers = num_hidden_layers
146
+ self.num_attention_heads = num_attention_heads
147
+
148
+ # for backward compatibility
149
+ if num_key_value_heads is None:
150
+ num_key_value_heads = num_attention_heads
151
+
152
+ self.num_key_value_heads = num_key_value_heads
153
+ self.hidden_act = hidden_act
154
+ self.initializer_range = initializer_range
155
+ self.rms_norm_eps = rms_norm_eps
156
+ self.pretraining_tp = pretraining_tp
157
+ self.use_cache = use_cache
158
+ self.rope_theta = rope_theta
159
+ self.rope_scaling = rope_scaling
160
+ self._rope_scaling_validation()
161
+ self.attention_bias = attention_bias
162
+ self.attention_dropout = attention_dropout
163
+
164
+ super().__init__(
165
+ pad_token_id=pad_token_id,
166
+ bos_token_id=bos_token_id,
167
+ eos_token_id=eos_token_id,
168
+ tie_word_embeddings=tie_word_embeddings,
169
+ **kwargs,
170
+ )
171
+
172
+ def _rope_scaling_validation(self):
173
+ """
174
+ Validate the `rope_scaling` configuration.
175
+ """
176
+ if self.rope_scaling is None:
177
+ return
178
+
179
+ if not isinstance(self.rope_scaling, dict) or len(self.rope_scaling) != 2:
180
+ raise ValueError(
181
+ "`rope_scaling` must be a dictionary with with two fields, `type` and `factor`, "
182
+ f"got {self.rope_scaling}"
183
+ )
184
+ rope_scaling_type = self.rope_scaling.get("type", None)
185
+ rope_scaling_factor = self.rope_scaling.get("factor", None)
186
+ if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic"]:
187
+ raise ValueError(
188
+ f"`rope_scaling`'s type field must be one of ['linear', 'dynamic'], got {rope_scaling_type}"
189
+ )
190
+ if rope_scaling_factor is None or not isinstance(rope_scaling_factor, float) or rope_scaling_factor <= 1.0:
191
+ raise ValueError(f"`rope_scaling`'s factor field must be a float > 1, got {rope_scaling_factor}")
generation_config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 1,
3
+ "do_sample": true,
4
+ "eos_token_id": 2,
5
+ "max_length": 4096,
6
+ "pad_token_id": 0,
7
+ "temperature": 0.6,
8
+ "top_p": 0.9,
9
+ "transformers_version": "4.36.2"
10
+ }
model-00001-of-00006.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:18225b0ffc8e73de3fce92a7873447bbfe54ab0bd3b815d578b09c5260307eb8
3
+ size 4971820688
model-00002-of-00006.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:382dde302168d366c9563f3045ce5110dd12e2651535ff44dd5c00ab2e8c0d82
3
+ size 4945263736
model-00003-of-00006.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:de660ad3bfb7240ec02090982f29775e1c6c3007a79260b771e26345389c7593
3
+ size 4990123096
model-00004-of-00006.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0e3eeaa708595dd60aed8231422ee9d0763f420249f74ae67e15aecea29a2329
3
+ size 4990090088
model-00005-of-00006.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:860a1016858d80a28c8a296f9dfe9c33817abf57518f15b93c291087b7c2b76a
3
+ size 4945296840
model-00006-of-00006.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:214a8cad1db18780f1fca44cd9a2c7b6ef0c189c6ae31e848de077b7f1df2832
3
+ size 4706726320
model.safetensors.index.json ADDED
@@ -0,0 +1,750 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 29549232128
4
+ },
5
+ "weight_map": {
6
+ "layout_projector.bias": "model-00001-of-00006.safetensors",
7
+ "layout_projector.weight": "model-00001-of-00006.safetensors",
8
+ "lm_head.Plora_A.weight": "model-00006-of-00006.safetensors",
9
+ "lm_head.Plora_B.weight": "model-00006-of-00006.safetensors",
10
+ "lm_head.weight": "model-00006-of-00006.safetensors",
11
+ "model.embed_tokens.weight": "model-00001-of-00006.safetensors",
12
+ "model.layers.0.input_layernorm.weight": "model-00001-of-00006.safetensors",
13
+ "model.layers.0.mlp.down_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
14
+ "model.layers.0.mlp.down_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
15
+ "model.layers.0.mlp.down_proj.weight": "model-00001-of-00006.safetensors",
16
+ "model.layers.0.mlp.gate_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
17
+ "model.layers.0.mlp.gate_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
18
+ "model.layers.0.mlp.gate_proj.weight": "model-00001-of-00006.safetensors",
19
+ "model.layers.0.mlp.up_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
20
+ "model.layers.0.mlp.up_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
21
+ "model.layers.0.mlp.up_proj.weight": "model-00001-of-00006.safetensors",
22
+ "model.layers.0.post_attention_layernorm.weight": "model-00001-of-00006.safetensors",
23
+ "model.layers.0.self_attn.k_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
24
+ "model.layers.0.self_attn.k_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
25
+ "model.layers.0.self_attn.k_proj.weight": "model-00001-of-00006.safetensors",
26
+ "model.layers.0.self_attn.o_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
27
+ "model.layers.0.self_attn.o_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
28
+ "model.layers.0.self_attn.o_proj.weight": "model-00001-of-00006.safetensors",
29
+ "model.layers.0.self_attn.q_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
30
+ "model.layers.0.self_attn.q_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
31
+ "model.layers.0.self_attn.q_proj.weight": "model-00001-of-00006.safetensors",
32
+ "model.layers.0.self_attn.v_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
33
+ "model.layers.0.self_attn.v_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
34
+ "model.layers.0.self_attn.v_proj.weight": "model-00001-of-00006.safetensors",
35
+ "model.layers.1.input_layernorm.weight": "model-00001-of-00006.safetensors",
36
+ "model.layers.1.mlp.down_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
37
+ "model.layers.1.mlp.down_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
38
+ "model.layers.1.mlp.down_proj.weight": "model-00001-of-00006.safetensors",
39
+ "model.layers.1.mlp.gate_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
40
+ "model.layers.1.mlp.gate_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
41
+ "model.layers.1.mlp.gate_proj.weight": "model-00001-of-00006.safetensors",
42
+ "model.layers.1.mlp.up_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
43
+ "model.layers.1.mlp.up_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
44
+ "model.layers.1.mlp.up_proj.weight": "model-00001-of-00006.safetensors",
45
+ "model.layers.1.post_attention_layernorm.weight": "model-00001-of-00006.safetensors",
46
+ "model.layers.1.self_attn.k_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
47
+ "model.layers.1.self_attn.k_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
48
+ "model.layers.1.self_attn.k_proj.weight": "model-00001-of-00006.safetensors",
49
+ "model.layers.1.self_attn.o_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
50
+ "model.layers.1.self_attn.o_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
51
+ "model.layers.1.self_attn.o_proj.weight": "model-00001-of-00006.safetensors",
52
+ "model.layers.1.self_attn.q_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
53
+ "model.layers.1.self_attn.q_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
54
+ "model.layers.1.self_attn.q_proj.weight": "model-00001-of-00006.safetensors",
55
+ "model.layers.1.self_attn.v_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
56
+ "model.layers.1.self_attn.v_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
57
+ "model.layers.1.self_attn.v_proj.weight": "model-00001-of-00006.safetensors",
58
+ "model.layers.10.input_layernorm.weight": "model-00003-of-00006.safetensors",
59
+ "model.layers.10.mlp.down_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
60
+ "model.layers.10.mlp.down_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
61
+ "model.layers.10.mlp.down_proj.weight": "model-00003-of-00006.safetensors",
62
+ "model.layers.10.mlp.gate_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
63
+ "model.layers.10.mlp.gate_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
64
+ "model.layers.10.mlp.gate_proj.weight": "model-00002-of-00006.safetensors",
65
+ "model.layers.10.mlp.up_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
66
+ "model.layers.10.mlp.up_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
67
+ "model.layers.10.mlp.up_proj.weight": "model-00003-of-00006.safetensors",
68
+ "model.layers.10.post_attention_layernorm.weight": "model-00003-of-00006.safetensors",
69
+ "model.layers.10.self_attn.k_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
70
+ "model.layers.10.self_attn.k_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
71
+ "model.layers.10.self_attn.k_proj.weight": "model-00002-of-00006.safetensors",
72
+ "model.layers.10.self_attn.o_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
73
+ "model.layers.10.self_attn.o_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
74
+ "model.layers.10.self_attn.o_proj.weight": "model-00002-of-00006.safetensors",
75
+ "model.layers.10.self_attn.q_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
76
+ "model.layers.10.self_attn.q_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
77
+ "model.layers.10.self_attn.q_proj.weight": "model-00002-of-00006.safetensors",
78
+ "model.layers.10.self_attn.v_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
79
+ "model.layers.10.self_attn.v_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
80
+ "model.layers.10.self_attn.v_proj.weight": "model-00002-of-00006.safetensors",
81
+ "model.layers.11.input_layernorm.weight": "model-00003-of-00006.safetensors",
82
+ "model.layers.11.mlp.down_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
83
+ "model.layers.11.mlp.down_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
84
+ "model.layers.11.mlp.down_proj.weight": "model-00003-of-00006.safetensors",
85
+ "model.layers.11.mlp.gate_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
86
+ "model.layers.11.mlp.gate_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
87
+ "model.layers.11.mlp.gate_proj.weight": "model-00003-of-00006.safetensors",
88
+ "model.layers.11.mlp.up_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
89
+ "model.layers.11.mlp.up_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
90
+ "model.layers.11.mlp.up_proj.weight": "model-00003-of-00006.safetensors",
91
+ "model.layers.11.post_attention_layernorm.weight": "model-00003-of-00006.safetensors",
92
+ "model.layers.11.self_attn.k_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
93
+ "model.layers.11.self_attn.k_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
94
+ "model.layers.11.self_attn.k_proj.weight": "model-00003-of-00006.safetensors",
95
+ "model.layers.11.self_attn.o_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
96
+ "model.layers.11.self_attn.o_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
97
+ "model.layers.11.self_attn.o_proj.weight": "model-00003-of-00006.safetensors",
98
+ "model.layers.11.self_attn.q_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
99
+ "model.layers.11.self_attn.q_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
100
+ "model.layers.11.self_attn.q_proj.weight": "model-00003-of-00006.safetensors",
101
+ "model.layers.11.self_attn.v_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
102
+ "model.layers.11.self_attn.v_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
103
+ "model.layers.11.self_attn.v_proj.weight": "model-00003-of-00006.safetensors",
104
+ "model.layers.12.input_layernorm.weight": "model-00003-of-00006.safetensors",
105
+ "model.layers.12.mlp.down_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
106
+ "model.layers.12.mlp.down_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
107
+ "model.layers.12.mlp.down_proj.weight": "model-00003-of-00006.safetensors",
108
+ "model.layers.12.mlp.gate_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
109
+ "model.layers.12.mlp.gate_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
110
+ "model.layers.12.mlp.gate_proj.weight": "model-00003-of-00006.safetensors",
111
+ "model.layers.12.mlp.up_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
112
+ "model.layers.12.mlp.up_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
113
+ "model.layers.12.mlp.up_proj.weight": "model-00003-of-00006.safetensors",
114
+ "model.layers.12.post_attention_layernorm.weight": "model-00003-of-00006.safetensors",
115
+ "model.layers.12.self_attn.k_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
116
+ "model.layers.12.self_attn.k_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
117
+ "model.layers.12.self_attn.k_proj.weight": "model-00003-of-00006.safetensors",
118
+ "model.layers.12.self_attn.o_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
119
+ "model.layers.12.self_attn.o_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
120
+ "model.layers.12.self_attn.o_proj.weight": "model-00003-of-00006.safetensors",
121
+ "model.layers.12.self_attn.q_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
122
+ "model.layers.12.self_attn.q_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
123
+ "model.layers.12.self_attn.q_proj.weight": "model-00003-of-00006.safetensors",
124
+ "model.layers.12.self_attn.v_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
125
+ "model.layers.12.self_attn.v_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
126
+ "model.layers.12.self_attn.v_proj.weight": "model-00003-of-00006.safetensors",
127
+ "model.layers.13.input_layernorm.weight": "model-00003-of-00006.safetensors",
128
+ "model.layers.13.mlp.down_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
129
+ "model.layers.13.mlp.down_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
130
+ "model.layers.13.mlp.down_proj.weight": "model-00003-of-00006.safetensors",
131
+ "model.layers.13.mlp.gate_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
132
+ "model.layers.13.mlp.gate_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
133
+ "model.layers.13.mlp.gate_proj.weight": "model-00003-of-00006.safetensors",
134
+ "model.layers.13.mlp.up_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
135
+ "model.layers.13.mlp.up_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
136
+ "model.layers.13.mlp.up_proj.weight": "model-00003-of-00006.safetensors",
137
+ "model.layers.13.post_attention_layernorm.weight": "model-00003-of-00006.safetensors",
138
+ "model.layers.13.self_attn.k_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
139
+ "model.layers.13.self_attn.k_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
140
+ "model.layers.13.self_attn.k_proj.weight": "model-00003-of-00006.safetensors",
141
+ "model.layers.13.self_attn.o_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
142
+ "model.layers.13.self_attn.o_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
143
+ "model.layers.13.self_attn.o_proj.weight": "model-00003-of-00006.safetensors",
144
+ "model.layers.13.self_attn.q_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
145
+ "model.layers.13.self_attn.q_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
146
+ "model.layers.13.self_attn.q_proj.weight": "model-00003-of-00006.safetensors",
147
+ "model.layers.13.self_attn.v_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
148
+ "model.layers.13.self_attn.v_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
149
+ "model.layers.13.self_attn.v_proj.weight": "model-00003-of-00006.safetensors",
150
+ "model.layers.14.input_layernorm.weight": "model-00003-of-00006.safetensors",
151
+ "model.layers.14.mlp.down_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
152
+ "model.layers.14.mlp.down_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
153
+ "model.layers.14.mlp.down_proj.weight": "model-00003-of-00006.safetensors",
154
+ "model.layers.14.mlp.gate_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
155
+ "model.layers.14.mlp.gate_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
156
+ "model.layers.14.mlp.gate_proj.weight": "model-00003-of-00006.safetensors",
157
+ "model.layers.14.mlp.up_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
158
+ "model.layers.14.mlp.up_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
159
+ "model.layers.14.mlp.up_proj.weight": "model-00003-of-00006.safetensors",
160
+ "model.layers.14.post_attention_layernorm.weight": "model-00003-of-00006.safetensors",
161
+ "model.layers.14.self_attn.k_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
162
+ "model.layers.14.self_attn.k_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
163
+ "model.layers.14.self_attn.k_proj.weight": "model-00003-of-00006.safetensors",
164
+ "model.layers.14.self_attn.o_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
165
+ "model.layers.14.self_attn.o_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
166
+ "model.layers.14.self_attn.o_proj.weight": "model-00003-of-00006.safetensors",
167
+ "model.layers.14.self_attn.q_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
168
+ "model.layers.14.self_attn.q_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
169
+ "model.layers.14.self_attn.q_proj.weight": "model-00003-of-00006.safetensors",
170
+ "model.layers.14.self_attn.v_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
171
+ "model.layers.14.self_attn.v_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
172
+ "model.layers.14.self_attn.v_proj.weight": "model-00003-of-00006.safetensors",
173
+ "model.layers.15.input_layernorm.weight": "model-00003-of-00006.safetensors",
174
+ "model.layers.15.mlp.down_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
175
+ "model.layers.15.mlp.down_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
176
+ "model.layers.15.mlp.down_proj.weight": "model-00003-of-00006.safetensors",
177
+ "model.layers.15.mlp.gate_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
178
+ "model.layers.15.mlp.gate_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
179
+ "model.layers.15.mlp.gate_proj.weight": "model-00003-of-00006.safetensors",
180
+ "model.layers.15.mlp.up_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
181
+ "model.layers.15.mlp.up_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
182
+ "model.layers.15.mlp.up_proj.weight": "model-00003-of-00006.safetensors",
183
+ "model.layers.15.post_attention_layernorm.weight": "model-00003-of-00006.safetensors",
184
+ "model.layers.15.self_attn.k_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
185
+ "model.layers.15.self_attn.k_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
186
+ "model.layers.15.self_attn.k_proj.weight": "model-00003-of-00006.safetensors",
187
+ "model.layers.15.self_attn.o_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
188
+ "model.layers.15.self_attn.o_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
189
+ "model.layers.15.self_attn.o_proj.weight": "model-00003-of-00006.safetensors",
190
+ "model.layers.15.self_attn.q_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
191
+ "model.layers.15.self_attn.q_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
192
+ "model.layers.15.self_attn.q_proj.weight": "model-00003-of-00006.safetensors",
193
+ "model.layers.15.self_attn.v_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
194
+ "model.layers.15.self_attn.v_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
195
+ "model.layers.15.self_attn.v_proj.weight": "model-00003-of-00006.safetensors",
196
+ "model.layers.16.input_layernorm.weight": "model-00004-of-00006.safetensors",
197
+ "model.layers.16.mlp.down_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
198
+ "model.layers.16.mlp.down_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
199
+ "model.layers.16.mlp.down_proj.weight": "model-00004-of-00006.safetensors",
200
+ "model.layers.16.mlp.gate_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
201
+ "model.layers.16.mlp.gate_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
202
+ "model.layers.16.mlp.gate_proj.weight": "model-00004-of-00006.safetensors",
203
+ "model.layers.16.mlp.up_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
204
+ "model.layers.16.mlp.up_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
205
+ "model.layers.16.mlp.up_proj.weight": "model-00004-of-00006.safetensors",
206
+ "model.layers.16.post_attention_layernorm.weight": "model-00004-of-00006.safetensors",
207
+ "model.layers.16.self_attn.k_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
208
+ "model.layers.16.self_attn.k_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
209
+ "model.layers.16.self_attn.k_proj.weight": "model-00003-of-00006.safetensors",
210
+ "model.layers.16.self_attn.o_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
211
+ "model.layers.16.self_attn.o_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
212
+ "model.layers.16.self_attn.o_proj.weight": "model-00004-of-00006.safetensors",
213
+ "model.layers.16.self_attn.q_proj.Plora_A.weight": "model-00003-of-00006.safetensors",
214
+ "model.layers.16.self_attn.q_proj.Plora_B.weight": "model-00003-of-00006.safetensors",
215
+ "model.layers.16.self_attn.q_proj.weight": "model-00003-of-00006.safetensors",
216
+ "model.layers.16.self_attn.v_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
217
+ "model.layers.16.self_attn.v_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
218
+ "model.layers.16.self_attn.v_proj.weight": "model-00004-of-00006.safetensors",
219
+ "model.layers.17.input_layernorm.weight": "model-00004-of-00006.safetensors",
220
+ "model.layers.17.mlp.down_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
221
+ "model.layers.17.mlp.down_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
222
+ "model.layers.17.mlp.down_proj.weight": "model-00004-of-00006.safetensors",
223
+ "model.layers.17.mlp.gate_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
224
+ "model.layers.17.mlp.gate_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
225
+ "model.layers.17.mlp.gate_proj.weight": "model-00004-of-00006.safetensors",
226
+ "model.layers.17.mlp.up_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
227
+ "model.layers.17.mlp.up_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
228
+ "model.layers.17.mlp.up_proj.weight": "model-00004-of-00006.safetensors",
229
+ "model.layers.17.post_attention_layernorm.weight": "model-00004-of-00006.safetensors",
230
+ "model.layers.17.self_attn.k_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
231
+ "model.layers.17.self_attn.k_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
232
+ "model.layers.17.self_attn.k_proj.weight": "model-00004-of-00006.safetensors",
233
+ "model.layers.17.self_attn.o_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
234
+ "model.layers.17.self_attn.o_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
235
+ "model.layers.17.self_attn.o_proj.weight": "model-00004-of-00006.safetensors",
236
+ "model.layers.17.self_attn.q_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
237
+ "model.layers.17.self_attn.q_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
238
+ "model.layers.17.self_attn.q_proj.weight": "model-00004-of-00006.safetensors",
239
+ "model.layers.17.self_attn.v_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
240
+ "model.layers.17.self_attn.v_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
241
+ "model.layers.17.self_attn.v_proj.weight": "model-00004-of-00006.safetensors",
242
+ "model.layers.18.input_layernorm.weight": "model-00004-of-00006.safetensors",
243
+ "model.layers.18.mlp.down_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
244
+ "model.layers.18.mlp.down_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
245
+ "model.layers.18.mlp.down_proj.weight": "model-00004-of-00006.safetensors",
246
+ "model.layers.18.mlp.gate_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
247
+ "model.layers.18.mlp.gate_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
248
+ "model.layers.18.mlp.gate_proj.weight": "model-00004-of-00006.safetensors",
249
+ "model.layers.18.mlp.up_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
250
+ "model.layers.18.mlp.up_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
251
+ "model.layers.18.mlp.up_proj.weight": "model-00004-of-00006.safetensors",
252
+ "model.layers.18.post_attention_layernorm.weight": "model-00004-of-00006.safetensors",
253
+ "model.layers.18.self_attn.k_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
254
+ "model.layers.18.self_attn.k_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
255
+ "model.layers.18.self_attn.k_proj.weight": "model-00004-of-00006.safetensors",
256
+ "model.layers.18.self_attn.o_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
257
+ "model.layers.18.self_attn.o_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
258
+ "model.layers.18.self_attn.o_proj.weight": "model-00004-of-00006.safetensors",
259
+ "model.layers.18.self_attn.q_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
260
+ "model.layers.18.self_attn.q_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
261
+ "model.layers.18.self_attn.q_proj.weight": "model-00004-of-00006.safetensors",
262
+ "model.layers.18.self_attn.v_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
263
+ "model.layers.18.self_attn.v_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
264
+ "model.layers.18.self_attn.v_proj.weight": "model-00004-of-00006.safetensors",
265
+ "model.layers.19.input_layernorm.weight": "model-00004-of-00006.safetensors",
266
+ "model.layers.19.mlp.down_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
267
+ "model.layers.19.mlp.down_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
268
+ "model.layers.19.mlp.down_proj.weight": "model-00004-of-00006.safetensors",
269
+ "model.layers.19.mlp.gate_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
270
+ "model.layers.19.mlp.gate_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
271
+ "model.layers.19.mlp.gate_proj.weight": "model-00004-of-00006.safetensors",
272
+ "model.layers.19.mlp.up_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
273
+ "model.layers.19.mlp.up_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
274
+ "model.layers.19.mlp.up_proj.weight": "model-00004-of-00006.safetensors",
275
+ "model.layers.19.post_attention_layernorm.weight": "model-00004-of-00006.safetensors",
276
+ "model.layers.19.self_attn.k_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
277
+ "model.layers.19.self_attn.k_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
278
+ "model.layers.19.self_attn.k_proj.weight": "model-00004-of-00006.safetensors",
279
+ "model.layers.19.self_attn.o_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
280
+ "model.layers.19.self_attn.o_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
281
+ "model.layers.19.self_attn.o_proj.weight": "model-00004-of-00006.safetensors",
282
+ "model.layers.19.self_attn.q_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
283
+ "model.layers.19.self_attn.q_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
284
+ "model.layers.19.self_attn.q_proj.weight": "model-00004-of-00006.safetensors",
285
+ "model.layers.19.self_attn.v_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
286
+ "model.layers.19.self_attn.v_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
287
+ "model.layers.19.self_attn.v_proj.weight": "model-00004-of-00006.safetensors",
288
+ "model.layers.2.input_layernorm.weight": "model-00001-of-00006.safetensors",
289
+ "model.layers.2.mlp.down_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
290
+ "model.layers.2.mlp.down_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
291
+ "model.layers.2.mlp.down_proj.weight": "model-00001-of-00006.safetensors",
292
+ "model.layers.2.mlp.gate_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
293
+ "model.layers.2.mlp.gate_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
294
+ "model.layers.2.mlp.gate_proj.weight": "model-00001-of-00006.safetensors",
295
+ "model.layers.2.mlp.up_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
296
+ "model.layers.2.mlp.up_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
297
+ "model.layers.2.mlp.up_proj.weight": "model-00001-of-00006.safetensors",
298
+ "model.layers.2.post_attention_layernorm.weight": "model-00001-of-00006.safetensors",
299
+ "model.layers.2.self_attn.k_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
300
+ "model.layers.2.self_attn.k_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
301
+ "model.layers.2.self_attn.k_proj.weight": "model-00001-of-00006.safetensors",
302
+ "model.layers.2.self_attn.o_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
303
+ "model.layers.2.self_attn.o_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
304
+ "model.layers.2.self_attn.o_proj.weight": "model-00001-of-00006.safetensors",
305
+ "model.layers.2.self_attn.q_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
306
+ "model.layers.2.self_attn.q_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
307
+ "model.layers.2.self_attn.q_proj.weight": "model-00001-of-00006.safetensors",
308
+ "model.layers.2.self_attn.v_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
309
+ "model.layers.2.self_attn.v_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
310
+ "model.layers.2.self_attn.v_proj.weight": "model-00001-of-00006.safetensors",
311
+ "model.layers.20.input_layernorm.weight": "model-00004-of-00006.safetensors",
312
+ "model.layers.20.mlp.down_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
313
+ "model.layers.20.mlp.down_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
314
+ "model.layers.20.mlp.down_proj.weight": "model-00004-of-00006.safetensors",
315
+ "model.layers.20.mlp.gate_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
316
+ "model.layers.20.mlp.gate_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
317
+ "model.layers.20.mlp.gate_proj.weight": "model-00004-of-00006.safetensors",
318
+ "model.layers.20.mlp.up_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
319
+ "model.layers.20.mlp.up_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
320
+ "model.layers.20.mlp.up_proj.weight": "model-00004-of-00006.safetensors",
321
+ "model.layers.20.post_attention_layernorm.weight": "model-00004-of-00006.safetensors",
322
+ "model.layers.20.self_attn.k_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
323
+ "model.layers.20.self_attn.k_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
324
+ "model.layers.20.self_attn.k_proj.weight": "model-00004-of-00006.safetensors",
325
+ "model.layers.20.self_attn.o_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
326
+ "model.layers.20.self_attn.o_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
327
+ "model.layers.20.self_attn.o_proj.weight": "model-00004-of-00006.safetensors",
328
+ "model.layers.20.self_attn.q_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
329
+ "model.layers.20.self_attn.q_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
330
+ "model.layers.20.self_attn.q_proj.weight": "model-00004-of-00006.safetensors",
331
+ "model.layers.20.self_attn.v_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
332
+ "model.layers.20.self_attn.v_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
333
+ "model.layers.20.self_attn.v_proj.weight": "model-00004-of-00006.safetensors",
334
+ "model.layers.21.input_layernorm.weight": "model-00005-of-00006.safetensors",
335
+ "model.layers.21.mlp.down_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
336
+ "model.layers.21.mlp.down_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
337
+ "model.layers.21.mlp.down_proj.weight": "model-00005-of-00006.safetensors",
338
+ "model.layers.21.mlp.gate_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
339
+ "model.layers.21.mlp.gate_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
340
+ "model.layers.21.mlp.gate_proj.weight": "model-00004-of-00006.safetensors",
341
+ "model.layers.21.mlp.up_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
342
+ "model.layers.21.mlp.up_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
343
+ "model.layers.21.mlp.up_proj.weight": "model-00004-of-00006.safetensors",
344
+ "model.layers.21.post_attention_layernorm.weight": "model-00005-of-00006.safetensors",
345
+ "model.layers.21.self_attn.k_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
346
+ "model.layers.21.self_attn.k_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
347
+ "model.layers.21.self_attn.k_proj.weight": "model-00004-of-00006.safetensors",
348
+ "model.layers.21.self_attn.o_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
349
+ "model.layers.21.self_attn.o_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
350
+ "model.layers.21.self_attn.o_proj.weight": "model-00004-of-00006.safetensors",
351
+ "model.layers.21.self_attn.q_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
352
+ "model.layers.21.self_attn.q_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
353
+ "model.layers.21.self_attn.q_proj.weight": "model-00004-of-00006.safetensors",
354
+ "model.layers.21.self_attn.v_proj.Plora_A.weight": "model-00004-of-00006.safetensors",
355
+ "model.layers.21.self_attn.v_proj.Plora_B.weight": "model-00004-of-00006.safetensors",
356
+ "model.layers.21.self_attn.v_proj.weight": "model-00004-of-00006.safetensors",
357
+ "model.layers.22.input_layernorm.weight": "model-00005-of-00006.safetensors",
358
+ "model.layers.22.mlp.down_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
359
+ "model.layers.22.mlp.down_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
360
+ "model.layers.22.mlp.down_proj.weight": "model-00005-of-00006.safetensors",
361
+ "model.layers.22.mlp.gate_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
362
+ "model.layers.22.mlp.gate_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
363
+ "model.layers.22.mlp.gate_proj.weight": "model-00005-of-00006.safetensors",
364
+ "model.layers.22.mlp.up_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
365
+ "model.layers.22.mlp.up_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
366
+ "model.layers.22.mlp.up_proj.weight": "model-00005-of-00006.safetensors",
367
+ "model.layers.22.post_attention_layernorm.weight": "model-00005-of-00006.safetensors",
368
+ "model.layers.22.self_attn.k_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
369
+ "model.layers.22.self_attn.k_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
370
+ "model.layers.22.self_attn.k_proj.weight": "model-00005-of-00006.safetensors",
371
+ "model.layers.22.self_attn.o_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
372
+ "model.layers.22.self_attn.o_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
373
+ "model.layers.22.self_attn.o_proj.weight": "model-00005-of-00006.safetensors",
374
+ "model.layers.22.self_attn.q_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
375
+ "model.layers.22.self_attn.q_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
376
+ "model.layers.22.self_attn.q_proj.weight": "model-00005-of-00006.safetensors",
377
+ "model.layers.22.self_attn.v_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
378
+ "model.layers.22.self_attn.v_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
379
+ "model.layers.22.self_attn.v_proj.weight": "model-00005-of-00006.safetensors",
380
+ "model.layers.23.input_layernorm.weight": "model-00005-of-00006.safetensors",
381
+ "model.layers.23.mlp.down_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
382
+ "model.layers.23.mlp.down_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
383
+ "model.layers.23.mlp.down_proj.weight": "model-00005-of-00006.safetensors",
384
+ "model.layers.23.mlp.gate_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
385
+ "model.layers.23.mlp.gate_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
386
+ "model.layers.23.mlp.gate_proj.weight": "model-00005-of-00006.safetensors",
387
+ "model.layers.23.mlp.up_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
388
+ "model.layers.23.mlp.up_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
389
+ "model.layers.23.mlp.up_proj.weight": "model-00005-of-00006.safetensors",
390
+ "model.layers.23.post_attention_layernorm.weight": "model-00005-of-00006.safetensors",
391
+ "model.layers.23.self_attn.k_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
392
+ "model.layers.23.self_attn.k_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
393
+ "model.layers.23.self_attn.k_proj.weight": "model-00005-of-00006.safetensors",
394
+ "model.layers.23.self_attn.o_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
395
+ "model.layers.23.self_attn.o_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
396
+ "model.layers.23.self_attn.o_proj.weight": "model-00005-of-00006.safetensors",
397
+ "model.layers.23.self_attn.q_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
398
+ "model.layers.23.self_attn.q_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
399
+ "model.layers.23.self_attn.q_proj.weight": "model-00005-of-00006.safetensors",
400
+ "model.layers.23.self_attn.v_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
401
+ "model.layers.23.self_attn.v_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
402
+ "model.layers.23.self_attn.v_proj.weight": "model-00005-of-00006.safetensors",
403
+ "model.layers.24.input_layernorm.weight": "model-00005-of-00006.safetensors",
404
+ "model.layers.24.mlp.down_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
405
+ "model.layers.24.mlp.down_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
406
+ "model.layers.24.mlp.down_proj.weight": "model-00005-of-00006.safetensors",
407
+ "model.layers.24.mlp.gate_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
408
+ "model.layers.24.mlp.gate_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
409
+ "model.layers.24.mlp.gate_proj.weight": "model-00005-of-00006.safetensors",
410
+ "model.layers.24.mlp.up_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
411
+ "model.layers.24.mlp.up_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
412
+ "model.layers.24.mlp.up_proj.weight": "model-00005-of-00006.safetensors",
413
+ "model.layers.24.post_attention_layernorm.weight": "model-00005-of-00006.safetensors",
414
+ "model.layers.24.self_attn.k_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
415
+ "model.layers.24.self_attn.k_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
416
+ "model.layers.24.self_attn.k_proj.weight": "model-00005-of-00006.safetensors",
417
+ "model.layers.24.self_attn.o_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
418
+ "model.layers.24.self_attn.o_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
419
+ "model.layers.24.self_attn.o_proj.weight": "model-00005-of-00006.safetensors",
420
+ "model.layers.24.self_attn.q_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
421
+ "model.layers.24.self_attn.q_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
422
+ "model.layers.24.self_attn.q_proj.weight": "model-00005-of-00006.safetensors",
423
+ "model.layers.24.self_attn.v_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
424
+ "model.layers.24.self_attn.v_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
425
+ "model.layers.24.self_attn.v_proj.weight": "model-00005-of-00006.safetensors",
426
+ "model.layers.25.input_layernorm.weight": "model-00005-of-00006.safetensors",
427
+ "model.layers.25.mlp.down_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
428
+ "model.layers.25.mlp.down_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
429
+ "model.layers.25.mlp.down_proj.weight": "model-00005-of-00006.safetensors",
430
+ "model.layers.25.mlp.gate_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
431
+ "model.layers.25.mlp.gate_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
432
+ "model.layers.25.mlp.gate_proj.weight": "model-00005-of-00006.safetensors",
433
+ "model.layers.25.mlp.up_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
434
+ "model.layers.25.mlp.up_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
435
+ "model.layers.25.mlp.up_proj.weight": "model-00005-of-00006.safetensors",
436
+ "model.layers.25.post_attention_layernorm.weight": "model-00005-of-00006.safetensors",
437
+ "model.layers.25.self_attn.k_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
438
+ "model.layers.25.self_attn.k_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
439
+ "model.layers.25.self_attn.k_proj.weight": "model-00005-of-00006.safetensors",
440
+ "model.layers.25.self_attn.o_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
441
+ "model.layers.25.self_attn.o_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
442
+ "model.layers.25.self_attn.o_proj.weight": "model-00005-of-00006.safetensors",
443
+ "model.layers.25.self_attn.q_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
444
+ "model.layers.25.self_attn.q_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
445
+ "model.layers.25.self_attn.q_proj.weight": "model-00005-of-00006.safetensors",
446
+ "model.layers.25.self_attn.v_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
447
+ "model.layers.25.self_attn.v_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
448
+ "model.layers.25.self_attn.v_proj.weight": "model-00005-of-00006.safetensors",
449
+ "model.layers.26.input_layernorm.weight": "model-00005-of-00006.safetensors",
450
+ "model.layers.26.mlp.down_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
451
+ "model.layers.26.mlp.down_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
452
+ "model.layers.26.mlp.down_proj.weight": "model-00005-of-00006.safetensors",
453
+ "model.layers.26.mlp.gate_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
454
+ "model.layers.26.mlp.gate_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
455
+ "model.layers.26.mlp.gate_proj.weight": "model-00005-of-00006.safetensors",
456
+ "model.layers.26.mlp.up_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
457
+ "model.layers.26.mlp.up_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
458
+ "model.layers.26.mlp.up_proj.weight": "model-00005-of-00006.safetensors",
459
+ "model.layers.26.post_attention_layernorm.weight": "model-00005-of-00006.safetensors",
460
+ "model.layers.26.self_attn.k_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
461
+ "model.layers.26.self_attn.k_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
462
+ "model.layers.26.self_attn.k_proj.weight": "model-00005-of-00006.safetensors",
463
+ "model.layers.26.self_attn.o_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
464
+ "model.layers.26.self_attn.o_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
465
+ "model.layers.26.self_attn.o_proj.weight": "model-00005-of-00006.safetensors",
466
+ "model.layers.26.self_attn.q_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
467
+ "model.layers.26.self_attn.q_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
468
+ "model.layers.26.self_attn.q_proj.weight": "model-00005-of-00006.safetensors",
469
+ "model.layers.26.self_attn.v_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
470
+ "model.layers.26.self_attn.v_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
471
+ "model.layers.26.self_attn.v_proj.weight": "model-00005-of-00006.safetensors",
472
+ "model.layers.27.input_layernorm.weight": "model-00006-of-00006.safetensors",
473
+ "model.layers.27.mlp.down_proj.Plora_A.weight": "model-00006-of-00006.safetensors",
474
+ "model.layers.27.mlp.down_proj.Plora_B.weight": "model-00006-of-00006.safetensors",
475
+ "model.layers.27.mlp.down_proj.weight": "model-00006-of-00006.safetensors",
476
+ "model.layers.27.mlp.gate_proj.Plora_A.weight": "model-00006-of-00006.safetensors",
477
+ "model.layers.27.mlp.gate_proj.Plora_B.weight": "model-00006-of-00006.safetensors",
478
+ "model.layers.27.mlp.gate_proj.weight": "model-00006-of-00006.safetensors",
479
+ "model.layers.27.mlp.up_proj.Plora_A.weight": "model-00006-of-00006.safetensors",
480
+ "model.layers.27.mlp.up_proj.Plora_B.weight": "model-00006-of-00006.safetensors",
481
+ "model.layers.27.mlp.up_proj.weight": "model-00006-of-00006.safetensors",
482
+ "model.layers.27.post_attention_layernorm.weight": "model-00006-of-00006.safetensors",
483
+ "model.layers.27.self_attn.k_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
484
+ "model.layers.27.self_attn.k_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
485
+ "model.layers.27.self_attn.k_proj.weight": "model-00005-of-00006.safetensors",
486
+ "model.layers.27.self_attn.o_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
487
+ "model.layers.27.self_attn.o_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
488
+ "model.layers.27.self_attn.o_proj.weight": "model-00005-of-00006.safetensors",
489
+ "model.layers.27.self_attn.q_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
490
+ "model.layers.27.self_attn.q_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
491
+ "model.layers.27.self_attn.q_proj.weight": "model-00005-of-00006.safetensors",
492
+ "model.layers.27.self_attn.v_proj.Plora_A.weight": "model-00005-of-00006.safetensors",
493
+ "model.layers.27.self_attn.v_proj.Plora_B.weight": "model-00005-of-00006.safetensors",
494
+ "model.layers.27.self_attn.v_proj.weight": "model-00005-of-00006.safetensors",
495
+ "model.layers.28.input_layernorm.weight": "model-00006-of-00006.safetensors",
496
+ "model.layers.28.mlp.down_proj.Plora_A.weight": "model-00006-of-00006.safetensors",
497
+ "model.layers.28.mlp.down_proj.Plora_B.weight": "model-00006-of-00006.safetensors",
498
+ "model.layers.28.mlp.down_proj.weight": "model-00006-of-00006.safetensors",
499
+ "model.layers.28.mlp.gate_proj.Plora_A.weight": "model-00006-of-00006.safetensors",
500
+ "model.layers.28.mlp.gate_proj.Plora_B.weight": "model-00006-of-00006.safetensors",
501
+ "model.layers.28.mlp.gate_proj.weight": "model-00006-of-00006.safetensors",
502
+ "model.layers.28.mlp.up_proj.Plora_A.weight": "model-00006-of-00006.safetensors",
503
+ "model.layers.28.mlp.up_proj.Plora_B.weight": "model-00006-of-00006.safetensors",
504
+ "model.layers.28.mlp.up_proj.weight": "model-00006-of-00006.safetensors",
505
+ "model.layers.28.post_attention_layernorm.weight": "model-00006-of-00006.safetensors",
506
+ "model.layers.28.self_attn.k_proj.Plora_A.weight": "model-00006-of-00006.safetensors",
507
+ "model.layers.28.self_attn.k_proj.Plora_B.weight": "model-00006-of-00006.safetensors",
508
+ "model.layers.28.self_attn.k_proj.weight": "model-00006-of-00006.safetensors",
509
+ "model.layers.28.self_attn.o_proj.Plora_A.weight": "model-00006-of-00006.safetensors",
510
+ "model.layers.28.self_attn.o_proj.Plora_B.weight": "model-00006-of-00006.safetensors",
511
+ "model.layers.28.self_attn.o_proj.weight": "model-00006-of-00006.safetensors",
512
+ "model.layers.28.self_attn.q_proj.Plora_A.weight": "model-00006-of-00006.safetensors",
513
+ "model.layers.28.self_attn.q_proj.Plora_B.weight": "model-00006-of-00006.safetensors",
514
+ "model.layers.28.self_attn.q_proj.weight": "model-00006-of-00006.safetensors",
515
+ "model.layers.28.self_attn.v_proj.Plora_A.weight": "model-00006-of-00006.safetensors",
516
+ "model.layers.28.self_attn.v_proj.Plora_B.weight": "model-00006-of-00006.safetensors",
517
+ "model.layers.28.self_attn.v_proj.weight": "model-00006-of-00006.safetensors",
518
+ "model.layers.29.input_layernorm.weight": "model-00006-of-00006.safetensors",
519
+ "model.layers.29.mlp.down_proj.Plora_A.weight": "model-00006-of-00006.safetensors",
520
+ "model.layers.29.mlp.down_proj.Plora_B.weight": "model-00006-of-00006.safetensors",
521
+ "model.layers.29.mlp.down_proj.weight": "model-00006-of-00006.safetensors",
522
+ "model.layers.29.mlp.gate_proj.Plora_A.weight": "model-00006-of-00006.safetensors",
523
+ "model.layers.29.mlp.gate_proj.Plora_B.weight": "model-00006-of-00006.safetensors",
524
+ "model.layers.29.mlp.gate_proj.weight": "model-00006-of-00006.safetensors",
525
+ "model.layers.29.mlp.up_proj.Plora_A.weight": "model-00006-of-00006.safetensors",
526
+ "model.layers.29.mlp.up_proj.Plora_B.weight": "model-00006-of-00006.safetensors",
527
+ "model.layers.29.mlp.up_proj.weight": "model-00006-of-00006.safetensors",
528
+ "model.layers.29.post_attention_layernorm.weight": "model-00006-of-00006.safetensors",
529
+ "model.layers.29.self_attn.k_proj.Plora_A.weight": "model-00006-of-00006.safetensors",
530
+ "model.layers.29.self_attn.k_proj.Plora_B.weight": "model-00006-of-00006.safetensors",
531
+ "model.layers.29.self_attn.k_proj.weight": "model-00006-of-00006.safetensors",
532
+ "model.layers.29.self_attn.o_proj.Plora_A.weight": "model-00006-of-00006.safetensors",
533
+ "model.layers.29.self_attn.o_proj.Plora_B.weight": "model-00006-of-00006.safetensors",
534
+ "model.layers.29.self_attn.o_proj.weight": "model-00006-of-00006.safetensors",
535
+ "model.layers.29.self_attn.q_proj.Plora_A.weight": "model-00006-of-00006.safetensors",
536
+ "model.layers.29.self_attn.q_proj.Plora_B.weight": "model-00006-of-00006.safetensors",
537
+ "model.layers.29.self_attn.q_proj.weight": "model-00006-of-00006.safetensors",
538
+ "model.layers.29.self_attn.v_proj.Plora_A.weight": "model-00006-of-00006.safetensors",
539
+ "model.layers.29.self_attn.v_proj.Plora_B.weight": "model-00006-of-00006.safetensors",
540
+ "model.layers.29.self_attn.v_proj.weight": "model-00006-of-00006.safetensors",
541
+ "model.layers.3.input_layernorm.weight": "model-00001-of-00006.safetensors",
542
+ "model.layers.3.mlp.down_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
543
+ "model.layers.3.mlp.down_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
544
+ "model.layers.3.mlp.down_proj.weight": "model-00001-of-00006.safetensors",
545
+ "model.layers.3.mlp.gate_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
546
+ "model.layers.3.mlp.gate_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
547
+ "model.layers.3.mlp.gate_proj.weight": "model-00001-of-00006.safetensors",
548
+ "model.layers.3.mlp.up_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
549
+ "model.layers.3.mlp.up_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
550
+ "model.layers.3.mlp.up_proj.weight": "model-00001-of-00006.safetensors",
551
+ "model.layers.3.post_attention_layernorm.weight": "model-00001-of-00006.safetensors",
552
+ "model.layers.3.self_attn.k_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
553
+ "model.layers.3.self_attn.k_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
554
+ "model.layers.3.self_attn.k_proj.weight": "model-00001-of-00006.safetensors",
555
+ "model.layers.3.self_attn.o_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
556
+ "model.layers.3.self_attn.o_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
557
+ "model.layers.3.self_attn.o_proj.weight": "model-00001-of-00006.safetensors",
558
+ "model.layers.3.self_attn.q_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
559
+ "model.layers.3.self_attn.q_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
560
+ "model.layers.3.self_attn.q_proj.weight": "model-00001-of-00006.safetensors",
561
+ "model.layers.3.self_attn.v_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
562
+ "model.layers.3.self_attn.v_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
563
+ "model.layers.3.self_attn.v_proj.weight": "model-00001-of-00006.safetensors",
564
+ "model.layers.30.input_layernorm.weight": "model-00006-of-00006.safetensors",
565
+ "model.layers.30.mlp.down_proj.Plora_A.weight": "model-00006-of-00006.safetensors",
566
+ "model.layers.30.mlp.down_proj.Plora_B.weight": "model-00006-of-00006.safetensors",
567
+ "model.layers.30.mlp.down_proj.weight": "model-00006-of-00006.safetensors",
568
+ "model.layers.30.mlp.gate_proj.Plora_A.weight": "model-00006-of-00006.safetensors",
569
+ "model.layers.30.mlp.gate_proj.Plora_B.weight": "model-00006-of-00006.safetensors",
570
+ "model.layers.30.mlp.gate_proj.weight": "model-00006-of-00006.safetensors",
571
+ "model.layers.30.mlp.up_proj.Plora_A.weight": "model-00006-of-00006.safetensors",
572
+ "model.layers.30.mlp.up_proj.Plora_B.weight": "model-00006-of-00006.safetensors",
573
+ "model.layers.30.mlp.up_proj.weight": "model-00006-of-00006.safetensors",
574
+ "model.layers.30.post_attention_layernorm.weight": "model-00006-of-00006.safetensors",
575
+ "model.layers.30.self_attn.k_proj.Plora_A.weight": "model-00006-of-00006.safetensors",
576
+ "model.layers.30.self_attn.k_proj.Plora_B.weight": "model-00006-of-00006.safetensors",
577
+ "model.layers.30.self_attn.k_proj.weight": "model-00006-of-00006.safetensors",
578
+ "model.layers.30.self_attn.o_proj.Plora_A.weight": "model-00006-of-00006.safetensors",
579
+ "model.layers.30.self_attn.o_proj.Plora_B.weight": "model-00006-of-00006.safetensors",
580
+ "model.layers.30.self_attn.o_proj.weight": "model-00006-of-00006.safetensors",
581
+ "model.layers.30.self_attn.q_proj.Plora_A.weight": "model-00006-of-00006.safetensors",
582
+ "model.layers.30.self_attn.q_proj.Plora_B.weight": "model-00006-of-00006.safetensors",
583
+ "model.layers.30.self_attn.q_proj.weight": "model-00006-of-00006.safetensors",
584
+ "model.layers.30.self_attn.v_proj.Plora_A.weight": "model-00006-of-00006.safetensors",
585
+ "model.layers.30.self_attn.v_proj.Plora_B.weight": "model-00006-of-00006.safetensors",
586
+ "model.layers.30.self_attn.v_proj.weight": "model-00006-of-00006.safetensors",
587
+ "model.layers.31.input_layernorm.weight": "model-00006-of-00006.safetensors",
588
+ "model.layers.31.mlp.down_proj.Plora_A.weight": "model-00006-of-00006.safetensors",
589
+ "model.layers.31.mlp.down_proj.Plora_B.weight": "model-00006-of-00006.safetensors",
590
+ "model.layers.31.mlp.down_proj.weight": "model-00006-of-00006.safetensors",
591
+ "model.layers.31.mlp.gate_proj.Plora_A.weight": "model-00006-of-00006.safetensors",
592
+ "model.layers.31.mlp.gate_proj.Plora_B.weight": "model-00006-of-00006.safetensors",
593
+ "model.layers.31.mlp.gate_proj.weight": "model-00006-of-00006.safetensors",
594
+ "model.layers.31.mlp.up_proj.Plora_A.weight": "model-00006-of-00006.safetensors",
595
+ "model.layers.31.mlp.up_proj.Plora_B.weight": "model-00006-of-00006.safetensors",
596
+ "model.layers.31.mlp.up_proj.weight": "model-00006-of-00006.safetensors",
597
+ "model.layers.31.post_attention_layernorm.weight": "model-00006-of-00006.safetensors",
598
+ "model.layers.31.self_attn.k_proj.Plora_A.weight": "model-00006-of-00006.safetensors",
599
+ "model.layers.31.self_attn.k_proj.Plora_B.weight": "model-00006-of-00006.safetensors",
600
+ "model.layers.31.self_attn.k_proj.weight": "model-00006-of-00006.safetensors",
601
+ "model.layers.31.self_attn.o_proj.Plora_A.weight": "model-00006-of-00006.safetensors",
602
+ "model.layers.31.self_attn.o_proj.Plora_B.weight": "model-00006-of-00006.safetensors",
603
+ "model.layers.31.self_attn.o_proj.weight": "model-00006-of-00006.safetensors",
604
+ "model.layers.31.self_attn.q_proj.Plora_A.weight": "model-00006-of-00006.safetensors",
605
+ "model.layers.31.self_attn.q_proj.Plora_B.weight": "model-00006-of-00006.safetensors",
606
+ "model.layers.31.self_attn.q_proj.weight": "model-00006-of-00006.safetensors",
607
+ "model.layers.31.self_attn.v_proj.Plora_A.weight": "model-00006-of-00006.safetensors",
608
+ "model.layers.31.self_attn.v_proj.Plora_B.weight": "model-00006-of-00006.safetensors",
609
+ "model.layers.31.self_attn.v_proj.weight": "model-00006-of-00006.safetensors",
610
+ "model.layers.4.input_layernorm.weight": "model-00001-of-00006.safetensors",
611
+ "model.layers.4.mlp.down_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
612
+ "model.layers.4.mlp.down_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
613
+ "model.layers.4.mlp.down_proj.weight": "model-00001-of-00006.safetensors",
614
+ "model.layers.4.mlp.gate_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
615
+ "model.layers.4.mlp.gate_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
616
+ "model.layers.4.mlp.gate_proj.weight": "model-00001-of-00006.safetensors",
617
+ "model.layers.4.mlp.up_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
618
+ "model.layers.4.mlp.up_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
619
+ "model.layers.4.mlp.up_proj.weight": "model-00001-of-00006.safetensors",
620
+ "model.layers.4.post_attention_layernorm.weight": "model-00001-of-00006.safetensors",
621
+ "model.layers.4.self_attn.k_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
622
+ "model.layers.4.self_attn.k_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
623
+ "model.layers.4.self_attn.k_proj.weight": "model-00001-of-00006.safetensors",
624
+ "model.layers.4.self_attn.o_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
625
+ "model.layers.4.self_attn.o_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
626
+ "model.layers.4.self_attn.o_proj.weight": "model-00001-of-00006.safetensors",
627
+ "model.layers.4.self_attn.q_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
628
+ "model.layers.4.self_attn.q_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
629
+ "model.layers.4.self_attn.q_proj.weight": "model-00001-of-00006.safetensors",
630
+ "model.layers.4.self_attn.v_proj.Plora_A.weight": "model-00001-of-00006.safetensors",
631
+ "model.layers.4.self_attn.v_proj.Plora_B.weight": "model-00001-of-00006.safetensors",
632
+ "model.layers.4.self_attn.v_proj.weight": "model-00001-of-00006.safetensors",
633
+ "model.layers.5.input_layernorm.weight": "model-00002-of-00006.safetensors",
634
+ "model.layers.5.mlp.down_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
635
+ "model.layers.5.mlp.down_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
636
+ "model.layers.5.mlp.down_proj.weight": "model-00002-of-00006.safetensors",
637
+ "model.layers.5.mlp.gate_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
638
+ "model.layers.5.mlp.gate_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
639
+ "model.layers.5.mlp.gate_proj.weight": "model-00002-of-00006.safetensors",
640
+ "model.layers.5.mlp.up_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
641
+ "model.layers.5.mlp.up_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
642
+ "model.layers.5.mlp.up_proj.weight": "model-00002-of-00006.safetensors",
643
+ "model.layers.5.post_attention_layernorm.weight": "model-00002-of-00006.safetensors",
644
+ "model.layers.5.self_attn.k_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
645
+ "model.layers.5.self_attn.k_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
646
+ "model.layers.5.self_attn.k_proj.weight": "model-00002-of-00006.safetensors",
647
+ "model.layers.5.self_attn.o_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
648
+ "model.layers.5.self_attn.o_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
649
+ "model.layers.5.self_attn.o_proj.weight": "model-00002-of-00006.safetensors",
650
+ "model.layers.5.self_attn.q_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
651
+ "model.layers.5.self_attn.q_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
652
+ "model.layers.5.self_attn.q_proj.weight": "model-00002-of-00006.safetensors",
653
+ "model.layers.5.self_attn.v_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
654
+ "model.layers.5.self_attn.v_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
655
+ "model.layers.5.self_attn.v_proj.weight": "model-00002-of-00006.safetensors",
656
+ "model.layers.6.input_layernorm.weight": "model-00002-of-00006.safetensors",
657
+ "model.layers.6.mlp.down_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
658
+ "model.layers.6.mlp.down_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
659
+ "model.layers.6.mlp.down_proj.weight": "model-00002-of-00006.safetensors",
660
+ "model.layers.6.mlp.gate_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
661
+ "model.layers.6.mlp.gate_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
662
+ "model.layers.6.mlp.gate_proj.weight": "model-00002-of-00006.safetensors",
663
+ "model.layers.6.mlp.up_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
664
+ "model.layers.6.mlp.up_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
665
+ "model.layers.6.mlp.up_proj.weight": "model-00002-of-00006.safetensors",
666
+ "model.layers.6.post_attention_layernorm.weight": "model-00002-of-00006.safetensors",
667
+ "model.layers.6.self_attn.k_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
668
+ "model.layers.6.self_attn.k_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
669
+ "model.layers.6.self_attn.k_proj.weight": "model-00002-of-00006.safetensors",
670
+ "model.layers.6.self_attn.o_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
671
+ "model.layers.6.self_attn.o_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
672
+ "model.layers.6.self_attn.o_proj.weight": "model-00002-of-00006.safetensors",
673
+ "model.layers.6.self_attn.q_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
674
+ "model.layers.6.self_attn.q_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
675
+ "model.layers.6.self_attn.q_proj.weight": "model-00002-of-00006.safetensors",
676
+ "model.layers.6.self_attn.v_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
677
+ "model.layers.6.self_attn.v_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
678
+ "model.layers.6.self_attn.v_proj.weight": "model-00002-of-00006.safetensors",
679
+ "model.layers.7.input_layernorm.weight": "model-00002-of-00006.safetensors",
680
+ "model.layers.7.mlp.down_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
681
+ "model.layers.7.mlp.down_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
682
+ "model.layers.7.mlp.down_proj.weight": "model-00002-of-00006.safetensors",
683
+ "model.layers.7.mlp.gate_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
684
+ "model.layers.7.mlp.gate_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
685
+ "model.layers.7.mlp.gate_proj.weight": "model-00002-of-00006.safetensors",
686
+ "model.layers.7.mlp.up_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
687
+ "model.layers.7.mlp.up_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
688
+ "model.layers.7.mlp.up_proj.weight": "model-00002-of-00006.safetensors",
689
+ "model.layers.7.post_attention_layernorm.weight": "model-00002-of-00006.safetensors",
690
+ "model.layers.7.self_attn.k_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
691
+ "model.layers.7.self_attn.k_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
692
+ "model.layers.7.self_attn.k_proj.weight": "model-00002-of-00006.safetensors",
693
+ "model.layers.7.self_attn.o_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
694
+ "model.layers.7.self_attn.o_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
695
+ "model.layers.7.self_attn.o_proj.weight": "model-00002-of-00006.safetensors",
696
+ "model.layers.7.self_attn.q_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
697
+ "model.layers.7.self_attn.q_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
698
+ "model.layers.7.self_attn.q_proj.weight": "model-00002-of-00006.safetensors",
699
+ "model.layers.7.self_attn.v_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
700
+ "model.layers.7.self_attn.v_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
701
+ "model.layers.7.self_attn.v_proj.weight": "model-00002-of-00006.safetensors",
702
+ "model.layers.8.input_layernorm.weight": "model-00002-of-00006.safetensors",
703
+ "model.layers.8.mlp.down_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
704
+ "model.layers.8.mlp.down_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
705
+ "model.layers.8.mlp.down_proj.weight": "model-00002-of-00006.safetensors",
706
+ "model.layers.8.mlp.gate_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
707
+ "model.layers.8.mlp.gate_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
708
+ "model.layers.8.mlp.gate_proj.weight": "model-00002-of-00006.safetensors",
709
+ "model.layers.8.mlp.up_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
710
+ "model.layers.8.mlp.up_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
711
+ "model.layers.8.mlp.up_proj.weight": "model-00002-of-00006.safetensors",
712
+ "model.layers.8.post_attention_layernorm.weight": "model-00002-of-00006.safetensors",
713
+ "model.layers.8.self_attn.k_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
714
+ "model.layers.8.self_attn.k_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
715
+ "model.layers.8.self_attn.k_proj.weight": "model-00002-of-00006.safetensors",
716
+ "model.layers.8.self_attn.o_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
717
+ "model.layers.8.self_attn.o_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
718
+ "model.layers.8.self_attn.o_proj.weight": "model-00002-of-00006.safetensors",
719
+ "model.layers.8.self_attn.q_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
720
+ "model.layers.8.self_attn.q_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
721
+ "model.layers.8.self_attn.q_proj.weight": "model-00002-of-00006.safetensors",
722
+ "model.layers.8.self_attn.v_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
723
+ "model.layers.8.self_attn.v_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
724
+ "model.layers.8.self_attn.v_proj.weight": "model-00002-of-00006.safetensors",
725
+ "model.layers.9.input_layernorm.weight": "model-00002-of-00006.safetensors",
726
+ "model.layers.9.mlp.down_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
727
+ "model.layers.9.mlp.down_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
728
+ "model.layers.9.mlp.down_proj.weight": "model-00002-of-00006.safetensors",
729
+ "model.layers.9.mlp.gate_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
730
+ "model.layers.9.mlp.gate_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
731
+ "model.layers.9.mlp.gate_proj.weight": "model-00002-of-00006.safetensors",
732
+ "model.layers.9.mlp.up_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
733
+ "model.layers.9.mlp.up_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
734
+ "model.layers.9.mlp.up_proj.weight": "model-00002-of-00006.safetensors",
735
+ "model.layers.9.post_attention_layernorm.weight": "model-00002-of-00006.safetensors",
736
+ "model.layers.9.self_attn.k_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
737
+ "model.layers.9.self_attn.k_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
738
+ "model.layers.9.self_attn.k_proj.weight": "model-00002-of-00006.safetensors",
739
+ "model.layers.9.self_attn.o_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
740
+ "model.layers.9.self_attn.o_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
741
+ "model.layers.9.self_attn.o_proj.weight": "model-00002-of-00006.safetensors",
742
+ "model.layers.9.self_attn.q_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
743
+ "model.layers.9.self_attn.q_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
744
+ "model.layers.9.self_attn.q_proj.weight": "model-00002-of-00006.safetensors",
745
+ "model.layers.9.self_attn.v_proj.Plora_A.weight": "model-00002-of-00006.safetensors",
746
+ "model.layers.9.self_attn.v_proj.Plora_B.weight": "model-00002-of-00006.safetensors",
747
+ "model.layers.9.self_attn.v_proj.weight": "model-00002-of-00006.safetensors",
748
+ "model.norm.weight": "model-00006-of-00006.safetensors"
749
+ }
750
+ }
modeling_llama.py ADDED
@@ -0,0 +1,1439 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2022 EleutherAI and the HuggingFace Inc. team. All rights reserved.
3
+ #
4
+ # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
5
+ # and OPT implementations in this library. It has been modified from its
6
+ # original forms to accommodate minor architectural differences compared
7
+ # to GPT-NeoX and OPT used by the Meta AI team that trained the model.
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ """ PyTorch LLaMA model."""
21
+ import math
22
+ import warnings
23
+ from typing import List, Optional, Tuple, Union
24
+
25
+ import torch
26
+ import torch.nn.functional as F
27
+ import torch.utils.checkpoint
28
+ from torch import nn
29
+ from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
30
+ from .build_mlp import PLoRA
31
+ from transformers.activations import ACT2FN
32
+ from transformers.cache_utils import Cache, DynamicCache
33
+ from transformers.modeling_attn_mask_utils import (
34
+ AttentionMaskConverter,
35
+ _prepare_4d_attention_mask,
36
+ _prepare_4d_causal_attention_mask,
37
+ _prepare_4d_causal_attention_mask_for_sdpa,
38
+ )
39
+ from transformers.modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast, SequenceClassifierOutputWithPast
40
+ from transformers.modeling_utils import PreTrainedModel
41
+ from transformers.pytorch_utils import ALL_LAYERNORM_LAYERS, is_torch_greater_or_equal_than_1_13
42
+ from transformers.utils import (
43
+ add_start_docstrings,
44
+ add_start_docstrings_to_model_forward,
45
+ is_flash_attn_2_available,
46
+ is_flash_attn_greater_or_equal_2_10,
47
+ logging,
48
+ replace_return_docstrings,
49
+ )
50
+ from transformers.utils.import_utils import is_torch_fx_available
51
+ from .configuration_llama import LlamaConfig
52
+
53
+
54
+ if is_flash_attn_2_available():
55
+ from flash_attn import flash_attn_func, flash_attn_varlen_func
56
+ from flash_attn.bert_padding import index_first_axis, pad_input, unpad_input # noqa
57
+
58
+
59
+ # This makes `_prepare_4d_causal_attention_mask` a leaf function in the FX graph.
60
+ # It means that the function will not be traced through and simply appear as a node in the graph.
61
+ if is_torch_fx_available():
62
+ if not is_torch_greater_or_equal_than_1_13:
63
+ import torch.fx
64
+
65
+ _prepare_4d_causal_attention_mask = torch.fx.wrap(_prepare_4d_causal_attention_mask)
66
+
67
+
68
+ logger = logging.get_logger(__name__)
69
+
70
+ _CONFIG_FOR_DOC = "LlamaConfig"
71
+ BOX_TOKEN_ID = 0
72
+
73
+
74
+ def _get_unpad_data(attention_mask):
75
+ seqlens_in_batch = attention_mask.sum(dim=-1, dtype=torch.int32)
76
+ indices = torch.nonzero(attention_mask.flatten(), as_tuple=False).flatten()
77
+ max_seqlen_in_batch = seqlens_in_batch.max().item()
78
+ cu_seqlens = F.pad(torch.cumsum(seqlens_in_batch, dim=0, dtype=torch.torch.int32), (1, 0))
79
+ return (
80
+ indices,
81
+ cu_seqlens,
82
+ max_seqlen_in_batch,
83
+ )
84
+
85
+
86
+ def _expand_mask(mask: torch.Tensor, dtype: torch.dtype, tgt_len: Optional[int] = None):
87
+ warnings.warn(
88
+ "Calling `transformers.models.llama.modeling_llama._prepare_4d_attention_mask` is deprecated and will be removed in v4.37. Use `transformers.modeling_attn_mask_utils._prepare_4d_attention_mask"
89
+ )
90
+ return _prepare_4d_attention_mask(mask=mask, dtype=dtype, tgt_len=tgt_len)
91
+
92
+
93
+ def _make_causal_mask(
94
+ input_ids_shape: torch.Size, dtype: torch.dtype, device: torch.device, past_key_values_length: int = 0
95
+ ):
96
+ warnings.warn(
97
+ "Calling `transformers.models.llama.modeling_llama._make_causal_mask` is deprecated and will be removed in v4.37. Use `transformers.models.llama.modeling_llama.AttentionMaskConverter._make_causal_mask"
98
+ )
99
+ return AttentionMaskConverter._make_causal_mask(
100
+ input_ids_shape=input_ids_shape, dtype=dtype, device=device, past_key_values_length=past_key_values_length
101
+ )
102
+
103
+
104
+ class LlamaRMSNorm(nn.Module):
105
+ def __init__(self, hidden_size, eps=1e-6):
106
+ """
107
+ LlamaRMSNorm is equivalent to T5LayerNorm
108
+ """
109
+ super().__init__()
110
+ self.weight = nn.Parameter(torch.ones(hidden_size))
111
+ self.variance_epsilon = eps
112
+
113
+ def forward(self, hidden_states):
114
+ input_dtype = hidden_states.dtype
115
+ hidden_states = hidden_states.to(torch.float32)
116
+ variance = hidden_states.pow(2).mean(-1, keepdim=True)
117
+ hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
118
+ return self.weight * hidden_states.to(input_dtype)
119
+
120
+
121
+ ALL_LAYERNORM_LAYERS.append(LlamaRMSNorm)
122
+
123
+
124
+ class LlamaRotaryEmbedding(nn.Module):
125
+ def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None):
126
+ super().__init__()
127
+
128
+ self.dim = dim
129
+ self.max_position_embeddings = max_position_embeddings
130
+ self.base = base
131
+ inv_freq = 1.0 / (self.base ** (torch.arange(0, self.dim, 2).float().to(device) / self.dim))
132
+ self.register_buffer("inv_freq", inv_freq, persistent=False)
133
+
134
+ # Build here to make `torch.jit.trace` work.
135
+ self._set_cos_sin_cache(
136
+ seq_len=max_position_embeddings, device=self.inv_freq.device, dtype=torch.get_default_dtype()
137
+ )
138
+
139
+ def _set_cos_sin_cache(self, seq_len, device, dtype):
140
+ self.max_seq_len_cached = seq_len
141
+ t = torch.arange(self.max_seq_len_cached, device=device, dtype=self.inv_freq.dtype)
142
+
143
+ freqs = torch.outer(t, self.inv_freq)
144
+ # Different from paper, but it uses a different permutation in order to obtain the same calculation
145
+ emb = torch.cat((freqs, freqs), dim=-1)
146
+ self.register_buffer("cos_cached", emb.cos().to(dtype), persistent=False)
147
+ self.register_buffer("sin_cached", emb.sin().to(dtype), persistent=False)
148
+
149
+ def forward(self, x, seq_len=None):
150
+ # x: [bs, num_attention_heads, seq_len, head_size]
151
+ if seq_len > self.max_seq_len_cached:
152
+ self._set_cos_sin_cache(seq_len=seq_len, device=x.device, dtype=x.dtype)
153
+
154
+ return (
155
+ self.cos_cached[:seq_len].to(dtype=x.dtype),
156
+ self.sin_cached[:seq_len].to(dtype=x.dtype),
157
+ )
158
+
159
+
160
+ class LlamaLinearScalingRotaryEmbedding(LlamaRotaryEmbedding):
161
+ """LlamaRotaryEmbedding extended with linear scaling. Credits to the Reddit user /u/kaiokendev"""
162
+
163
+ def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None, scaling_factor=1.0):
164
+ self.scaling_factor = scaling_factor
165
+ super().__init__(dim, max_position_embeddings, base, device)
166
+
167
+ def _set_cos_sin_cache(self, seq_len, device, dtype):
168
+ self.max_seq_len_cached = seq_len
169
+ t = torch.arange(self.max_seq_len_cached, device=device, dtype=self.inv_freq.dtype)
170
+ t = t / self.scaling_factor
171
+
172
+ freqs = torch.outer(t, self.inv_freq)
173
+ # Different from paper, but it uses a different permutation in order to obtain the same calculation
174
+ emb = torch.cat((freqs, freqs), dim=-1)
175
+ self.register_buffer("cos_cached", emb.cos().to(dtype), persistent=False)
176
+ self.register_buffer("sin_cached", emb.sin().to(dtype), persistent=False)
177
+
178
+
179
+ class LlamaDynamicNTKScalingRotaryEmbedding(LlamaRotaryEmbedding):
180
+ """LlamaRotaryEmbedding extended with Dynamic NTK scaling. Credits to the Reddit users /u/bloc97 and /u/emozilla"""
181
+
182
+ def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None, scaling_factor=1.0):
183
+ self.scaling_factor = scaling_factor
184
+ super().__init__(dim, max_position_embeddings, base, device)
185
+
186
+ def _set_cos_sin_cache(self, seq_len, device, dtype):
187
+ self.max_seq_len_cached = seq_len
188
+
189
+ if seq_len > self.max_position_embeddings:
190
+ base = self.base * (
191
+ (self.scaling_factor * seq_len / self.max_position_embeddings) - (self.scaling_factor - 1)
192
+ ) ** (self.dim / (self.dim - 2))
193
+ inv_freq = 1.0 / (base ** (torch.arange(0, self.dim, 2).float().to(device) / self.dim))
194
+ self.register_buffer("inv_freq", inv_freq, persistent=False)
195
+
196
+ t = torch.arange(self.max_seq_len_cached, device=device, dtype=self.inv_freq.dtype)
197
+
198
+ freqs = torch.outer(t, self.inv_freq)
199
+ # Different from paper, but it uses a different permutation in order to obtain the same calculation
200
+ emb = torch.cat((freqs, freqs), dim=-1)
201
+ self.register_buffer("cos_cached", emb.cos().to(dtype), persistent=False)
202
+ self.register_buffer("sin_cached", emb.sin().to(dtype), persistent=False)
203
+
204
+
205
+ def rotate_half(x):
206
+ """Rotates half the hidden dims of the input."""
207
+ x1 = x[..., : x.shape[-1] // 2]
208
+ x2 = x[..., x.shape[-1] // 2 :]
209
+ return torch.cat((-x2, x1), dim=-1)
210
+
211
+
212
+ def apply_rotary_pos_emb(q, k, cos, sin, position_ids, unsqueeze_dim=1):
213
+ """Applies Rotary Position Embedding to the query and key tensors.
214
+
215
+ Args:
216
+ q (`torch.Tensor`): The query tensor.
217
+ k (`torch.Tensor`): The key tensor.
218
+ cos (`torch.Tensor`): The cosine part of the rotary embedding.
219
+ sin (`torch.Tensor`): The sine part of the rotary embedding.
220
+ position_ids (`torch.Tensor`):
221
+ The position indices of the tokens corresponding to the query and key tensors. For example, this can be
222
+ used to pass offsetted position ids when working with a KV-cache.
223
+ unsqueeze_dim (`int`, *optional*, defaults to 1):
224
+ The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
225
+ sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
226
+ that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
227
+ k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
228
+ cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
229
+ the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
230
+ Returns:
231
+ `tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
232
+ """
233
+ cos = cos[position_ids].unsqueeze(unsqueeze_dim)
234
+ sin = sin[position_ids].unsqueeze(unsqueeze_dim)
235
+ q_embed = (q * cos) + (rotate_half(q) * sin)
236
+ k_embed = (k * cos) + (rotate_half(k) * sin)
237
+ return q_embed, k_embed
238
+
239
+
240
+ class LlamaMLP(nn.Module):
241
+ def __init__(self, config):
242
+ super().__init__()
243
+ self.config = config
244
+ self.hidden_size = config.hidden_size
245
+ self.intermediate_size = config.intermediate_size
246
+ self.gate_proj = PLoRA(self.hidden_size, self.intermediate_size, lora_r=self.config.lora_r, lora_alpha=self.config.lora_alpha, bias=False)
247
+ self.up_proj = PLoRA(self.hidden_size, self.intermediate_size, lora_r=self.config.lora_r, lora_alpha=self.config.lora_alpha, bias=False)
248
+ self.down_proj = PLoRA(self.intermediate_size, self.hidden_size, lora_r=self.config.lora_r, lora_alpha=self.config.lora_alpha, bias=False)
249
+ self.act_fn = ACT2FN[config.hidden_act]
250
+
251
+ def forward(self, x, layout_mask):
252
+ if self.config.pretraining_tp > 1:
253
+ slice = self.intermediate_size // self.config.pretraining_tp
254
+ gate_proj_slices = self.gate_proj.weight.split(slice, dim=0)
255
+ up_proj_slices = self.up_proj.weight.split(slice, dim=0)
256
+ down_proj_slices = self.down_proj.weight.split(slice, dim=1)
257
+
258
+ gate_proj = torch.cat(
259
+ [F.linear(x, gate_proj_slices[i]) for i in range(self.config.pretraining_tp)], dim=-1
260
+ )
261
+ up_proj = torch.cat([F.linear(x, up_proj_slices[i]) for i in range(self.config.pretraining_tp)], dim=-1)
262
+
263
+ intermediate_states = (self.act_fn(gate_proj) * up_proj).split(slice, dim=2)
264
+ down_proj = [
265
+ F.linear(intermediate_states[i], down_proj_slices[i]) for i in range(self.config.pretraining_tp)
266
+ ]
267
+ down_proj = sum(down_proj)
268
+ else:
269
+ down_proj = self.down_proj(self.act_fn(self.gate_proj(x, layout_mask)) * self.up_proj(x, layout_mask), layout_mask)
270
+
271
+ return down_proj
272
+
273
+
274
+ def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
275
+ """
276
+ This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
277
+ num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
278
+ """
279
+ batch, num_key_value_heads, slen, head_dim = hidden_states.shape
280
+ if n_rep == 1:
281
+ return hidden_states
282
+ hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
283
+ return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
284
+
285
+
286
+ class LlamaAttention(nn.Module):
287
+ """Multi-headed attention from 'Attention Is All You Need' paper"""
288
+
289
+ def __init__(self, config: LlamaConfig, layer_idx: Optional[int] = None):
290
+ super().__init__()
291
+ self.config = config
292
+ self.layer_idx = layer_idx
293
+ if layer_idx is None:
294
+ logger.warning_once(
295
+ f"Instantiating {self.__class__.__name__} without passing `layer_idx` is not recommended and will "
296
+ "to errors during the forward call, if caching is used. Please make sure to provide a `layer_idx` "
297
+ "when creating this class."
298
+ )
299
+
300
+ self.attention_dropout = config.attention_dropout
301
+ self.hidden_size = config.hidden_size
302
+ self.num_heads = config.num_attention_heads
303
+ self.head_dim = self.hidden_size // self.num_heads
304
+ self.num_key_value_heads = config.num_key_value_heads
305
+ self.num_key_value_groups = self.num_heads // self.num_key_value_heads
306
+ self.max_position_embeddings = config.max_position_embeddings
307
+ self.rope_theta = config.rope_theta
308
+ self.is_causal = True
309
+
310
+ if (self.head_dim * self.num_heads) != self.hidden_size:
311
+ raise ValueError(
312
+ f"hidden_size must be divisible by num_heads (got `hidden_size`: {self.hidden_size}"
313
+ f" and `num_heads`: {self.num_heads})."
314
+ )
315
+
316
+ self.q_proj = PLoRA(self.hidden_size, self.num_heads * self.head_dim, lora_r=self.config.lora_r, lora_alpha=self.config.lora_alpha, bias=config.attention_bias)
317
+ self.k_proj = PLoRA(self.hidden_size, self.num_key_value_heads * self.head_dim, lora_r=self.config.lora_r, lora_alpha=self.config.lora_alpha, bias=config.attention_bias)
318
+ self.v_proj = PLoRA(self.hidden_size, self.num_key_value_heads * self.head_dim, lora_r=self.config.lora_r, lora_alpha=self.config.lora_alpha, bias=config.attention_bias)
319
+ self.o_proj = PLoRA(self.num_heads * self.head_dim, self.hidden_size, lora_r=self.config.lora_r, lora_alpha=self.config.lora_alpha, bias=config.attention_bias)
320
+ self._init_rope()
321
+
322
+ def _init_rope(self):
323
+ if self.config.rope_scaling is None:
324
+ self.rotary_emb = LlamaRotaryEmbedding(
325
+ self.head_dim,
326
+ max_position_embeddings=self.max_position_embeddings,
327
+ base=self.rope_theta,
328
+ )
329
+ else:
330
+ scaling_type = self.config.rope_scaling["type"]
331
+ scaling_factor = self.config.rope_scaling["factor"]
332
+ if scaling_type == "linear":
333
+ self.rotary_emb = LlamaLinearScalingRotaryEmbedding(
334
+ self.head_dim,
335
+ max_position_embeddings=self.max_position_embeddings,
336
+ scaling_factor=scaling_factor,
337
+ base=self.rope_theta,
338
+ )
339
+ elif scaling_type == "dynamic":
340
+ self.rotary_emb = LlamaDynamicNTKScalingRotaryEmbedding(
341
+ self.head_dim,
342
+ max_position_embeddings=self.max_position_embeddings,
343
+ scaling_factor=scaling_factor,
344
+ base=self.rope_theta,
345
+ )
346
+ else:
347
+ raise ValueError(f"Unknown RoPE scaling type {scaling_type}")
348
+
349
+ def _shape(self, tensor: torch.Tensor, seq_len: int, bsz: int):
350
+ return tensor.view(bsz, seq_len, self.num_heads, self.head_dim).transpose(1, 2).contiguous()
351
+
352
+ def forward(
353
+ self,
354
+ hidden_states: torch.Tensor,
355
+ attention_mask: Optional[torch.Tensor] = None,
356
+ position_ids: Optional[torch.LongTensor] = None,
357
+ past_key_value: Optional[Cache] = None,
358
+ output_attentions: bool = False,
359
+ layout_mask: Optional[Tuple[torch.Tensor]] = None,
360
+ use_cache: bool = False,
361
+ **kwargs,
362
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
363
+ if "padding_mask" in kwargs:
364
+ warnings.warn(
365
+ "Passing `padding_mask` is deprecated and will be removed in v4.37. Please make sure use `attention_mask` instead.`"
366
+ )
367
+
368
+ bsz, q_len, _ = hidden_states.size()
369
+
370
+ if self.config.pretraining_tp > 1:
371
+ key_value_slicing = (self.num_key_value_heads * self.head_dim) // self.config.pretraining_tp
372
+ query_slices = self.q_proj.weight.split(
373
+ (self.num_heads * self.head_dim) // self.config.pretraining_tp, dim=0
374
+ )
375
+ key_slices = self.k_proj.weight.split(key_value_slicing, dim=0)
376
+ value_slices = self.v_proj.weight.split(key_value_slicing, dim=0)
377
+
378
+ query_states = [F.linear(hidden_states, query_slices[i]) for i in range(self.config.pretraining_tp)]
379
+ query_states = torch.cat(query_states, dim=-1)
380
+
381
+ key_states = [F.linear(hidden_states, key_slices[i]) for i in range(self.config.pretraining_tp)]
382
+ key_states = torch.cat(key_states, dim=-1)
383
+
384
+ value_states = [F.linear(hidden_states, value_slices[i]) for i in range(self.config.pretraining_tp)]
385
+ value_states = torch.cat(value_states, dim=-1)
386
+
387
+ else:
388
+ query_states = self.q_proj(hidden_states, layout_mask)
389
+ key_states = self.k_proj(hidden_states, layout_mask)
390
+ value_states = self.v_proj(hidden_states, layout_mask)
391
+
392
+ query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
393
+ key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
394
+ value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
395
+
396
+ kv_seq_len = key_states.shape[-2]
397
+ if past_key_value is not None:
398
+ if self.layer_idx is None:
399
+ raise ValueError(
400
+ f"The cache structure has changed since version v4.36. If you are using {self.__class__.__name__} "
401
+ "for auto-regressive decoding with k/v caching, please make sure to initialize the attention class "
402
+ "with a layer index."
403
+ )
404
+ kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
405
+ cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len)
406
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
407
+
408
+ if past_key_value is not None:
409
+ cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
410
+ key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
411
+
412
+ key_states = repeat_kv(key_states, self.num_key_value_groups)
413
+ value_states = repeat_kv(value_states, self.num_key_value_groups)
414
+
415
+ attn_weights = torch.matmul(query_states, key_states.transpose(2, 3)) / math.sqrt(self.head_dim)
416
+
417
+ if attn_weights.size() != (bsz, self.num_heads, q_len, kv_seq_len):
418
+ raise ValueError(
419
+ f"Attention weights should be of size {(bsz, self.num_heads, q_len, kv_seq_len)}, but is"
420
+ f" {attn_weights.size()}"
421
+ )
422
+
423
+ if attention_mask is not None:
424
+ if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
425
+ raise ValueError(
426
+ f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
427
+ )
428
+ attn_weights = attn_weights + attention_mask
429
+
430
+ # upcast attention to fp32
431
+ attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query_states.dtype)
432
+ attn_weights = nn.functional.dropout(attn_weights, p=self.attention_dropout, training=self.training)
433
+ attn_output = torch.matmul(attn_weights, value_states)
434
+
435
+ if attn_output.size() != (bsz, self.num_heads, q_len, self.head_dim):
436
+ raise ValueError(
437
+ f"`attn_output` should be of size {(bsz, self.num_heads, q_len, self.head_dim)}, but is"
438
+ f" {attn_output.size()}"
439
+ )
440
+
441
+ attn_output = attn_output.transpose(1, 2).contiguous()
442
+
443
+ attn_output = attn_output.reshape(bsz, q_len, self.hidden_size)
444
+
445
+ if self.config.pretraining_tp > 1:
446
+ attn_output = attn_output.split(self.hidden_size // self.config.pretraining_tp, dim=2)
447
+ o_proj_slices = self.o_proj.weight.split(self.hidden_size // self.config.pretraining_tp, dim=1)
448
+ attn_output = sum([F.linear(attn_output[i], o_proj_slices[i]) for i in range(self.config.pretraining_tp)])
449
+ else:
450
+ attn_output = self.o_proj(attn_output, layout_mask)
451
+
452
+ if not output_attentions:
453
+ attn_weights = None
454
+
455
+ return attn_output, attn_weights, past_key_value
456
+
457
+
458
+ class LlamaFlashAttention2(LlamaAttention):
459
+ """
460
+ Llama flash attention module. This module inherits from `LlamaAttention` as the weights of the module stays
461
+ untouched. The only required change would be on the forward pass where it needs to correctly call the public API of
462
+ flash attention and deal with padding tokens in case the input contains any of them.
463
+ """
464
+
465
+ def __init__(self, *args, **kwargs):
466
+ super().__init__(*args, **kwargs)
467
+
468
+ # TODO: Should be removed once Flash Attention for RoCm is bumped to 2.1.
469
+ # 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.
470
+ # 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).
471
+ self._flash_attn_uses_top_left_mask = not is_flash_attn_greater_or_equal_2_10()
472
+
473
+ def forward(
474
+ self,
475
+ hidden_states: torch.Tensor,
476
+ attention_mask: Optional[torch.LongTensor] = None,
477
+ position_ids: Optional[torch.LongTensor] = None,
478
+ past_key_value: Optional[Cache] = None,
479
+ output_attentions: bool = False,
480
+ use_cache: bool = False,
481
+ layout_mask: Optional[Tuple[torch.Tensor]] = None,
482
+ **kwargs,
483
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
484
+ # LlamaFlashAttention2 attention does not support output_attentions
485
+ if "padding_mask" in kwargs:
486
+ warnings.warn(
487
+ "Passing `padding_mask` is deprecated and will be removed in v4.37. Please make sure use `attention_mask` instead.`"
488
+ )
489
+
490
+ # overwrite attention_mask with padding_mask
491
+ attention_mask = kwargs.pop("padding_mask")
492
+
493
+ output_attentions = False
494
+
495
+ bsz, q_len, _ = hidden_states.size()
496
+
497
+ query_states = self.q_proj(hidden_states, layout_mask)
498
+ key_states = self.k_proj(hidden_states, layout_mask)
499
+ value_states = self.v_proj(hidden_states, layout_mask)
500
+
501
+ # Flash attention requires the input to have the shape
502
+ # batch_size x seq_length x head_dim x hidden_dim
503
+ # therefore we just need to keep the original shape
504
+ query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
505
+ key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
506
+ value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
507
+
508
+ kv_seq_len = key_states.shape[-2]
509
+ if past_key_value is not None:
510
+ kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
511
+ cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len)
512
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
513
+
514
+ if past_key_value is not None:
515
+ cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
516
+ key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
517
+
518
+ # 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
519
+ # to be able to avoid many of these transpose/reshape/view.
520
+ query_states = query_states.transpose(1, 2)
521
+ key_states = key_states.transpose(1, 2)
522
+ value_states = value_states.transpose(1, 2)
523
+
524
+ dropout_rate = self.attention_dropout if self.training else 0.0
525
+
526
+ # In PEFT, usually we cast the layer norms in float32 for training stability reasons
527
+ # therefore the input hidden states gets silently casted in float32. Hence, we need
528
+ # cast them back in the correct dtype just to be sure everything works as expected.
529
+ # This might slowdown training & inference so it is recommended to not cast the LayerNorms
530
+ # in fp32. (LlamaRMSNorm handles it correctly)
531
+
532
+ input_dtype = query_states.dtype
533
+ if input_dtype == torch.float32:
534
+ # Handle the case where the model is quantized
535
+ if hasattr(self.config, "_pre_quantization_dtype"):
536
+ target_dtype = self.config._pre_quantization_dtype
537
+ else:
538
+ target_dtype = self.q_proj.weight.dtype
539
+
540
+ logger.warning_once(
541
+ f"The input hidden states seems to be silently casted in float32, this might be related to"
542
+ f" the fact you have upcasted embedding or layer norm layers in float32. We will cast back the input in"
543
+ f" {target_dtype}."
544
+ )
545
+
546
+ query_states = query_states.to(target_dtype)
547
+ key_states = key_states.to(target_dtype)
548
+ value_states = value_states.to(target_dtype)
549
+
550
+ attn_output = self._flash_attention_forward(
551
+ query_states, key_states, value_states, attention_mask, q_len, dropout=dropout_rate
552
+ )
553
+
554
+ attn_output = attn_output.reshape(bsz, q_len, self.hidden_size).contiguous()
555
+ attn_output = self.o_proj(attn_output, layout_mask)
556
+
557
+ if not output_attentions:
558
+ attn_weights = None
559
+
560
+ return attn_output, attn_weights, past_key_value
561
+
562
+ def _flash_attention_forward(
563
+ self, query_states, key_states, value_states, attention_mask, query_length, dropout=0.0, softmax_scale=None
564
+ ):
565
+ """
566
+ Calls the forward method of Flash Attention - if the input hidden states contain at least one padding token
567
+ first unpad the input, then computes the attention scores and pad the final attention scores.
568
+
569
+ Args:
570
+ query_states (`torch.Tensor`):
571
+ Input query states to be passed to Flash Attention API
572
+ key_states (`torch.Tensor`):
573
+ Input key states to be passed to Flash Attention API
574
+ value_states (`torch.Tensor`):
575
+ Input value states to be passed to Flash Attention API
576
+ attention_mask (`torch.Tensor`):
577
+ The padding mask - corresponds to a tensor of size `(batch_size, seq_len)` where 0 stands for the
578
+ position of padding tokens and 1 for the position of non-padding tokens.
579
+ dropout (`int`, *optional*):
580
+ Attention dropout
581
+ softmax_scale (`float`, *optional*):
582
+ The scaling of QK^T before applying softmax. Default to 1 / sqrt(head_dim)
583
+ """
584
+ if not self._flash_attn_uses_top_left_mask:
585
+ causal = self.is_causal
586
+ else:
587
+ # 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__.
588
+ causal = self.is_causal and query_length != 1
589
+
590
+ # Contains at least one padding token in the sequence
591
+ if attention_mask is not None:
592
+ batch_size = query_states.shape[0]
593
+ query_states, key_states, value_states, indices_q, cu_seq_lens, max_seq_lens = self._upad_input(
594
+ query_states, key_states, value_states, attention_mask, query_length
595
+ )
596
+
597
+ cu_seqlens_q, cu_seqlens_k = cu_seq_lens
598
+ max_seqlen_in_batch_q, max_seqlen_in_batch_k = max_seq_lens
599
+
600
+ attn_output_unpad = flash_attn_varlen_func(
601
+ query_states,
602
+ key_states,
603
+ value_states,
604
+ cu_seqlens_q=cu_seqlens_q,
605
+ cu_seqlens_k=cu_seqlens_k,
606
+ max_seqlen_q=max_seqlen_in_batch_q,
607
+ max_seqlen_k=max_seqlen_in_batch_k,
608
+ dropout_p=dropout,
609
+ softmax_scale=softmax_scale,
610
+ causal=causal,
611
+ )
612
+
613
+ attn_output = pad_input(attn_output_unpad, indices_q, batch_size, query_length)
614
+ else:
615
+ attn_output = flash_attn_func(
616
+ query_states, key_states, value_states, dropout, softmax_scale=softmax_scale, causal=causal
617
+ )
618
+
619
+ return attn_output
620
+
621
+ def _upad_input(self, query_layer, key_layer, value_layer, attention_mask, query_length):
622
+ indices_k, cu_seqlens_k, max_seqlen_in_batch_k = _get_unpad_data(attention_mask)
623
+ batch_size, kv_seq_len, num_key_value_heads, head_dim = key_layer.shape
624
+
625
+ key_layer = index_first_axis(
626
+ key_layer.reshape(batch_size * kv_seq_len, num_key_value_heads, head_dim), indices_k
627
+ )
628
+ value_layer = index_first_axis(
629
+ value_layer.reshape(batch_size * kv_seq_len, num_key_value_heads, head_dim), indices_k
630
+ )
631
+ if query_length == kv_seq_len:
632
+ query_layer = index_first_axis(
633
+ query_layer.reshape(batch_size * kv_seq_len, self.num_heads, head_dim), indices_k
634
+ )
635
+ cu_seqlens_q = cu_seqlens_k
636
+ max_seqlen_in_batch_q = max_seqlen_in_batch_k
637
+ indices_q = indices_k
638
+ elif query_length == 1:
639
+ max_seqlen_in_batch_q = 1
640
+ cu_seqlens_q = torch.arange(
641
+ batch_size + 1, dtype=torch.int32, device=query_layer.device
642
+ ) # There is a memcpy here, that is very bad.
643
+ indices_q = cu_seqlens_q[:-1]
644
+ query_layer = query_layer.squeeze(1)
645
+ else:
646
+ # The -q_len: slice assumes left padding.
647
+ attention_mask = attention_mask[:, -query_length:]
648
+ query_layer, indices_q, cu_seqlens_q, max_seqlen_in_batch_q = unpad_input(query_layer, attention_mask)
649
+
650
+ return (
651
+ query_layer,
652
+ key_layer,
653
+ value_layer,
654
+ indices_q,
655
+ (cu_seqlens_q, cu_seqlens_k),
656
+ (max_seqlen_in_batch_q, max_seqlen_in_batch_k),
657
+ )
658
+
659
+
660
+ class LlamaSdpaAttention(LlamaAttention):
661
+ """
662
+ Llama attention module using torch.nn.functional.scaled_dot_product_attention. This module inherits from
663
+ `LlamaAttention` as the weights of the module stays untouched. The only changes are on the forward pass to adapt to
664
+ SDPA API.
665
+ """
666
+
667
+ # Adapted from LlamaAttention.forward
668
+ def forward(
669
+ self,
670
+ hidden_states: torch.Tensor,
671
+ attention_mask: Optional[torch.Tensor] = None,
672
+ position_ids: Optional[torch.LongTensor] = None,
673
+ past_key_value: Optional[Cache] = None,
674
+ output_attentions: bool = False,
675
+ layout_mask: Optional[Tuple[torch.Tensor]] = None,
676
+ use_cache: bool = False,
677
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
678
+ if output_attentions:
679
+ # TODO: Improve this warning with e.g. `model.config.attn_implementation = "manual"` once this is implemented.
680
+ logger.warning_once(
681
+ "LlamaModel is using LlamaSdpaAttention, but `torch.nn.functional.scaled_dot_product_attention` does not support `output_attentions=True`. Falling back to the manual attention implementation, "
682
+ 'but specifying the manual implementation will be required from Transformers version v5.0.0 onwards. This warning can be removed using the argument `attn_implementation="eager"` when loading the model.'
683
+ )
684
+ return super().forward(
685
+ hidden_states=hidden_states,
686
+ attention_mask=attention_mask,
687
+ position_ids=position_ids,
688
+ past_key_value=past_key_value,
689
+ output_attentions=output_attentions,
690
+ use_cache=use_cache,
691
+ )
692
+
693
+ bsz, q_len, _ = hidden_states.size()
694
+
695
+ query_states = self.q_proj(hidden_states,layout_mask)
696
+ key_states = self.k_proj(hidden_states,layout_mask)
697
+ value_states = self.v_proj(hidden_states,layout_mask)
698
+
699
+ query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
700
+ key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
701
+ value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
702
+
703
+ kv_seq_len = key_states.shape[-2]
704
+ if past_key_value is not None:
705
+ kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
706
+ cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len)
707
+
708
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
709
+
710
+ if past_key_value is not None:
711
+ cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
712
+ key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
713
+
714
+ key_states = repeat_kv(key_states, self.num_key_value_groups)
715
+ value_states = repeat_kv(value_states, self.num_key_value_groups)
716
+
717
+ if attention_mask is not None:
718
+ if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
719
+ raise ValueError(
720
+ f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
721
+ )
722
+
723
+ # SDPA with memory-efficient backend is currently (torch==2.1.2) bugged with non-contiguous inputs with custom attn_mask,
724
+ # Reference: https://github.com/pytorch/pytorch/issues/112577.
725
+ if query_states.device.type == "cuda" and attention_mask is not None:
726
+ query_states = query_states.contiguous()
727
+ key_states = key_states.contiguous()
728
+ value_states = value_states.contiguous()
729
+
730
+ attn_output = torch.nn.functional.scaled_dot_product_attention(
731
+ query_states,
732
+ key_states,
733
+ value_states,
734
+ attn_mask=attention_mask,
735
+ dropout_p=self.attention_dropout if self.training else 0.0,
736
+ # The q_len > 1 is necessary to match with AttentionMaskConverter.to_causal_4d that does not create a causal mask in case q_len == 1.
737
+ is_causal=self.is_causal and attention_mask is None and q_len > 1,
738
+ )
739
+
740
+ attn_output = attn_output.transpose(1, 2).contiguous()
741
+ attn_output = attn_output.reshape(bsz, q_len, self.hidden_size)
742
+
743
+ attn_output = self.o_proj(attn_output,layout_mask)
744
+
745
+ return attn_output, None, past_key_value
746
+
747
+
748
+ LLAMA_ATTENTION_CLASSES = {
749
+ "eager": LlamaAttention,
750
+ "flash_attention_2": LlamaFlashAttention2,
751
+ "sdpa": LlamaSdpaAttention,
752
+ }
753
+
754
+
755
+ class LlamaDecoderLayer(nn.Module):
756
+ def __init__(self, config: LlamaConfig, layer_idx: int):
757
+ super().__init__()
758
+ self.hidden_size = config.hidden_size
759
+
760
+ self.self_attn = LLAMA_ATTENTION_CLASSES[config._attn_implementation](config=config, layer_idx=layer_idx)
761
+
762
+ self.mlp = LlamaMLP(config)
763
+ self.input_layernorm = LlamaRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
764
+ self.post_attention_layernorm = LlamaRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
765
+
766
+ def forward(
767
+ self,
768
+ hidden_states: torch.Tensor,
769
+ layout_mask: Optional[Tuple[torch.Tensor]] = None,
770
+ attention_mask: Optional[torch.Tensor] = None,
771
+ position_ids: Optional[torch.LongTensor] = None,
772
+ past_key_value: Optional[Tuple[torch.Tensor]] = None,
773
+ output_attentions: Optional[bool] = False,
774
+ use_cache: Optional[bool] = False,
775
+ **kwargs,
776
+ ) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]]:
777
+ """
778
+ Args:
779
+ hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
780
+ attention_mask (`torch.FloatTensor`, *optional*):
781
+ attention mask of size `(batch_size, sequence_length)` if flash attention is used or `(batch_size, 1,
782
+ query_sequence_length, key_sequence_length)` if default attention is used.
783
+ output_attentions (`bool`, *optional*):
784
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under
785
+ returned tensors for more detail.
786
+ use_cache (`bool`, *optional*):
787
+ If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding
788
+ (see `past_key_values`).
789
+ past_key_value (`Tuple(torch.FloatTensor)`, *optional*): cached past key and value projection states
790
+ """
791
+ if "padding_mask" in kwargs:
792
+ warnings.warn(
793
+ "Passing `padding_mask` is deprecated and will be removed in v4.37. Please make sure use `attention_mask` instead.`"
794
+ )
795
+
796
+ residual = hidden_states
797
+
798
+ hidden_states = self.input_layernorm(hidden_states)
799
+
800
+ # Self Attention
801
+ hidden_states, self_attn_weights, present_key_value = self.self_attn(
802
+ hidden_states=hidden_states,
803
+ attention_mask=attention_mask,
804
+ position_ids=position_ids,
805
+ past_key_value=past_key_value,
806
+ output_attentions=output_attentions,
807
+ layout_mask=layout_mask,
808
+ use_cache=use_cache,
809
+ **kwargs,
810
+ )
811
+ hidden_states = residual + hidden_states
812
+
813
+ # Fully Connected
814
+ residual = hidden_states
815
+ hidden_states = self.post_attention_layernorm(hidden_states)
816
+ hidden_states = self.mlp(hidden_states, layout_mask)
817
+ hidden_states = residual + hidden_states
818
+
819
+ outputs = (hidden_states,)
820
+
821
+ if output_attentions:
822
+ outputs += (self_attn_weights,)
823
+
824
+ if use_cache:
825
+ outputs += (present_key_value,)
826
+
827
+ return outputs
828
+
829
+
830
+ LLAMA_START_DOCSTRING = r"""
831
+ This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
832
+ library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
833
+ etc.)
834
+
835
+ This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
836
+ Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
837
+ and behavior.
838
+
839
+ Parameters:
840
+ config ([`LlamaConfig`]):
841
+ Model configuration class with all the parameters of the model. Initializing with a config file does not
842
+ load the weights associated with the model, only the configuration. Check out the
843
+ [`~PreTrainedModel.from_pretrained`] method to load the model weights.
844
+ """
845
+
846
+
847
+ @add_start_docstrings(
848
+ "The bare LLaMA Model outputting raw hidden-states without any specific head on top.",
849
+ LLAMA_START_DOCSTRING,
850
+ )
851
+ class LlamaPreTrainedModel(PreTrainedModel):
852
+ config_class = LlamaConfig
853
+ base_model_prefix = "model"
854
+ supports_gradient_checkpointing = True
855
+ _no_split_modules = ["LlamaDecoderLayer"]
856
+ _skip_keys_device_placement = "past_key_values"
857
+ _supports_flash_attn_2 = True
858
+ _supports_sdpa = True
859
+ _supports_cache_class = True
860
+
861
+ def _init_weights(self, module):
862
+ std = self.config.initializer_range
863
+ if isinstance(module, nn.Linear):
864
+ module.weight.data.normal_(mean=0.0, std=std)
865
+ if module.bias is not None:
866
+ module.bias.data.zero_()
867
+ elif isinstance(module, nn.Embedding):
868
+ module.weight.data.normal_(mean=0.0, std=std)
869
+ if module.padding_idx is not None:
870
+ module.weight.data[module.padding_idx].zero_()
871
+
872
+
873
+ LLAMA_INPUTS_DOCSTRING = r"""
874
+ Args:
875
+ input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
876
+ Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
877
+ it.
878
+
879
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
880
+ [`PreTrainedTokenizer.__call__`] for details.
881
+
882
+ [What are input IDs?](../glossary#input-ids)
883
+ attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
884
+ Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
885
+
886
+ - 1 for tokens that are **not masked**,
887
+ - 0 for tokens that are **masked**.
888
+
889
+ [What are attention masks?](../glossary#attention-mask)
890
+
891
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
892
+ [`PreTrainedTokenizer.__call__`] for details.
893
+
894
+ If `past_key_values` is used, optionally only the last `input_ids` have to be input (see
895
+ `past_key_values`).
896
+
897
+ If you want to change padding behavior, you should read [`modeling_opt._prepare_decoder_attention_mask`]
898
+ and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more
899
+ information on the default strategy.
900
+
901
+ - 1 indicates the head is **not masked**,
902
+ - 0 indicates the head is **masked**.
903
+ position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
904
+ Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
905
+ config.n_positions - 1]`.
906
+
907
+ [What are position IDs?](../glossary#position-ids)
908
+ past_key_values (`Cache` or `tuple(tuple(torch.FloatTensor))`, *optional*):
909
+ Pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
910
+ blocks) that can be used to speed up sequential decoding. This typically consists in the `past_key_values`
911
+ returned by the model at a previous stage of decoding, when `use_cache=True` or `config.use_cache=True`.
912
+
913
+ Two formats are allowed:
914
+ - a [`~cache_utils.Cache`] instance;
915
+ - Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of
916
+ shape `(batch_size, num_heads, sequence_length, embed_size_per_head)`). This is also known as the legacy
917
+ cache format.
918
+
919
+ The model will output the same cache format that is fed as input. If no `past_key_values` are passed, the
920
+ legacy cache format will be returned.
921
+
922
+ If `past_key_values` are used, the user can optionally input only the last `input_ids` (those that don't
923
+ have their past key value states given to this model) of shape `(batch_size, 1)` instead of all `input_ids`
924
+ of shape `(batch_size, sequence_length)`.
925
+ inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
926
+ Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
927
+ is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
928
+ model's internal embedding lookup matrix.
929
+ use_cache (`bool`, *optional*):
930
+ If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
931
+ `past_key_values`).
932
+ output_attentions (`bool`, *optional*):
933
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
934
+ tensors for more detail.
935
+ output_hidden_states (`bool`, *optional*):
936
+ Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
937
+ more detail.
938
+ return_dict (`bool`, *optional*):
939
+ Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
940
+ """
941
+
942
+
943
+ @add_start_docstrings(
944
+ "The bare LLaMA Model outputting raw hidden-states without any specific head on top.",
945
+ LLAMA_START_DOCSTRING,
946
+ )
947
+ class LlamaModel(LlamaPreTrainedModel):
948
+ """
949
+ Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`LlamaDecoderLayer`]
950
+
951
+ Args:
952
+ config: LlamaConfig
953
+ """
954
+
955
+ def __init__(self, config: LlamaConfig):
956
+ super().__init__(config)
957
+ self.padding_idx = config.pad_token_id
958
+ self.vocab_size = config.vocab_size
959
+
960
+ self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
961
+ self.layers = nn.ModuleList(
962
+ [LlamaDecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
963
+ )
964
+ self._use_sdpa = config._attn_implementation == "sdpa"
965
+ self._use_flash_attention_2 = config._attn_implementation == "flash_attention_2"
966
+ self.norm = LlamaRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
967
+
968
+ self.gradient_checkpointing = False
969
+ # Initialize weights and apply final processing
970
+ self.post_init()
971
+
972
+ def get_input_embeddings(self):
973
+ return self.embed_tokens
974
+
975
+ def set_input_embeddings(self, value):
976
+ self.embed_tokens = value
977
+
978
+ @add_start_docstrings_to_model_forward(LLAMA_INPUTS_DOCSTRING)
979
+ def forward(
980
+ self,
981
+ input_ids: torch.LongTensor = None,
982
+ layout_mask: Optional[Tuple[torch.Tensor]] = None,
983
+ attention_mask: Optional[torch.Tensor] = None,
984
+ position_ids: Optional[torch.LongTensor] = None,
985
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
986
+ inputs_embeds: Optional[torch.FloatTensor] = None,
987
+ use_cache: Optional[bool] = None,
988
+ output_attentions: Optional[bool] = None,
989
+ output_hidden_states: Optional[bool] = None,
990
+ return_dict: Optional[bool] = None,
991
+ ) -> Union[Tuple, BaseModelOutputWithPast]:
992
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
993
+ output_hidden_states = (
994
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
995
+ )
996
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
997
+
998
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
999
+
1000
+ # retrieve input_ids and inputs_embeds
1001
+ if input_ids is not None and inputs_embeds is not None:
1002
+ raise ValueError("You cannot specify both input_ids and inputs_embeds at the same time")
1003
+ elif input_ids is not None:
1004
+ batch_size, seq_length = input_ids.shape[:2]
1005
+ elif inputs_embeds is not None:
1006
+ batch_size, seq_length = inputs_embeds.shape[:2]
1007
+ else:
1008
+ raise ValueError("You have to specify either input_ids or inputs_embeds")
1009
+
1010
+ if self.gradient_checkpointing and self.training:
1011
+ if use_cache:
1012
+ logger.warning_once(
1013
+ "`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..."
1014
+ )
1015
+ use_cache = False
1016
+
1017
+ past_key_values_length = 0
1018
+ if use_cache:
1019
+ use_legacy_cache = not isinstance(past_key_values, Cache)
1020
+ if use_legacy_cache:
1021
+ past_key_values = DynamicCache.from_legacy_cache(past_key_values)
1022
+ past_key_values_length = past_key_values.get_usable_length(seq_length)
1023
+
1024
+ if position_ids is None:
1025
+ device = input_ids.device if input_ids is not None else inputs_embeds.device
1026
+ position_ids = torch.arange(
1027
+ past_key_values_length, seq_length + past_key_values_length, dtype=torch.long, device=device
1028
+ )
1029
+ position_ids = position_ids.unsqueeze(0)
1030
+
1031
+ if inputs_embeds is None:
1032
+ inputs_embeds = self.embed_tokens(input_ids)
1033
+
1034
+ if self._use_flash_attention_2:
1035
+ # 2d mask is passed through the layers
1036
+ attention_mask = attention_mask if (attention_mask is not None and 0 in attention_mask) else None
1037
+ elif self._use_sdpa and not output_attentions:
1038
+ # output_attentions=True can not be supported when using SDPA, and we fall back on
1039
+ # the manual implementation that requires a 4D causal mask in all cases.
1040
+ attention_mask = _prepare_4d_causal_attention_mask_for_sdpa(
1041
+ attention_mask,
1042
+ (batch_size, seq_length),
1043
+ inputs_embeds,
1044
+ past_key_values_length,
1045
+ )
1046
+ else:
1047
+ # 4d mask is passed through the layers
1048
+ attention_mask = _prepare_4d_causal_attention_mask(
1049
+ attention_mask, (batch_size, seq_length), inputs_embeds, past_key_values_length
1050
+ )
1051
+
1052
+ # embed positions
1053
+ hidden_states = inputs_embeds
1054
+
1055
+ # decoder layers
1056
+ all_hidden_states = () if output_hidden_states else None
1057
+ all_self_attns = () if output_attentions else None
1058
+ next_decoder_cache = None
1059
+
1060
+ for decoder_layer in self.layers:
1061
+ if output_hidden_states:
1062
+ all_hidden_states += (hidden_states,)
1063
+
1064
+ if self.gradient_checkpointing and self.training:
1065
+ layer_outputs = self._gradient_checkpointing_func(
1066
+ decoder_layer.__call__,
1067
+ hidden_states,
1068
+ layout_mask,
1069
+ attention_mask,
1070
+ position_ids,
1071
+ past_key_values,
1072
+ output_attentions,
1073
+ use_cache,
1074
+ )
1075
+ else:
1076
+ layer_outputs = decoder_layer(
1077
+ hidden_states,
1078
+ layout_mask=layout_mask,
1079
+ attention_mask=attention_mask,
1080
+ position_ids=position_ids,
1081
+ past_key_value=past_key_values,
1082
+ output_attentions=output_attentions,
1083
+ use_cache=use_cache,
1084
+ )
1085
+
1086
+ hidden_states = layer_outputs[0]
1087
+
1088
+ if use_cache:
1089
+ next_decoder_cache = layer_outputs[2 if output_attentions else 1]
1090
+
1091
+ if output_attentions:
1092
+ all_self_attns += (layer_outputs[1],)
1093
+
1094
+ hidden_states = self.norm(hidden_states)
1095
+
1096
+ # add hidden states from the last decoder layer
1097
+ if output_hidden_states:
1098
+ all_hidden_states += (hidden_states,)
1099
+
1100
+ next_cache = None
1101
+ if use_cache:
1102
+ next_cache = next_decoder_cache.to_legacy_cache() if use_legacy_cache else next_decoder_cache
1103
+ if not return_dict:
1104
+ return tuple(v for v in [hidden_states, next_cache, all_hidden_states, all_self_attns] if v is not None)
1105
+ return BaseModelOutputWithPast(
1106
+ last_hidden_state=hidden_states,
1107
+ past_key_values=next_cache,
1108
+ hidden_states=all_hidden_states,
1109
+ attentions=all_self_attns,
1110
+ )
1111
+
1112
+
1113
+ class LlamaForCausalLM(LlamaPreTrainedModel):
1114
+ _tied_weights_keys = ["lm_head.weight"]
1115
+
1116
+ def __init__(self, config):
1117
+ super().__init__(config)
1118
+ self.layout_projector = nn.Linear(4, config.hidden_size)
1119
+ self.model = LlamaModel(config)
1120
+ self.vocab_size = config.vocab_size
1121
+ self.lm_head = PLoRA(config.hidden_size, config.vocab_size, lora_r=config.lora_r, lora_alpha=config.lora_alpha, bias=False)
1122
+
1123
+ # Initialize weights and apply final processing
1124
+ self.post_init()
1125
+
1126
+ def get_input_embeddings(self):
1127
+ return self.model.embed_tokens
1128
+
1129
+ def set_input_embeddings(self, value):
1130
+ self.model.embed_tokens = value
1131
+
1132
+ def get_output_embeddings(self):
1133
+ return self.lm_head
1134
+
1135
+ def set_output_embeddings(self, new_embeddings):
1136
+ self.lm_head = new_embeddings
1137
+
1138
+ def set_decoder(self, decoder):
1139
+ self.model = decoder
1140
+
1141
+ def get_decoder(self):
1142
+ return self.model
1143
+
1144
+ @add_start_docstrings_to_model_forward(LLAMA_INPUTS_DOCSTRING)
1145
+ @replace_return_docstrings(output_type=CausalLMOutputWithPast, config_class=_CONFIG_FOR_DOC)
1146
+ def forward(
1147
+ self,
1148
+ laytout_input: Optional[Tuple[torch.Tensor]] = None,
1149
+ input_ids: torch.LongTensor = None,
1150
+ attention_mask: Optional[torch.Tensor] = None,
1151
+ position_ids: Optional[torch.LongTensor] = None,
1152
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
1153
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1154
+ labels: Optional[torch.LongTensor] = None,
1155
+ use_cache: Optional[bool] = None,
1156
+ output_attentions: Optional[bool] = None,
1157
+ output_hidden_states: Optional[bool] = None,
1158
+ return_dict: Optional[bool] = None,
1159
+ ) -> Union[Tuple, CausalLMOutputWithPast]:
1160
+ r"""
1161
+ Args:
1162
+ labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
1163
+ Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
1164
+ config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
1165
+ (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
1166
+
1167
+ Returns:
1168
+
1169
+ Example:
1170
+
1171
+ ```python
1172
+ >>> from transformers import AutoTokenizer, LlamaForCausalLM
1173
+
1174
+ >>> model = LlamaForCausalLM.from_pretrained(PATH_TO_CONVERTED_WEIGHTS)
1175
+ >>> tokenizer = AutoTokenizer.from_pretrained(PATH_TO_CONVERTED_TOKENIZER)
1176
+
1177
+ >>> prompt = "Hey, are you conscious? Can you talk to me?"
1178
+ >>> inputs = tokenizer(prompt, return_tensors="pt")
1179
+
1180
+ >>> # Generate
1181
+ >>> generate_ids = model.generate(inputs.input_ids, max_length=30)
1182
+ >>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
1183
+ "Hey, are you conscious? Can you talk to me?\nI'm not conscious, but I can talk to you."
1184
+ ```"""
1185
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
1186
+ output_hidden_states = (
1187
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
1188
+ )
1189
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
1190
+
1191
+ inputs_embeds = self.get_input_embeddings()(input_ids.abs())
1192
+ layout_mask = None
1193
+ if laytout_input is not None:
1194
+ layout_embeds = self.layout_projector(laytout_input)
1195
+
1196
+ # interleave layout and text embeddings
1197
+ # Replace positions where mask is True with corresponding layout embedding
1198
+ layout_mask = (input_ids == BOX_TOKEN_ID)
1199
+
1200
+ for i in range(len(inputs_embeds)):
1201
+ true_indices = layout_mask[i].nonzero().squeeze(1)
1202
+ inputs_embeds[i][true_indices] = layout_embeds[i][:len(true_indices)]
1203
+
1204
+ # decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
1205
+ outputs = self.model(
1206
+ input_ids=None,
1207
+ layout_mask=layout_mask,
1208
+ attention_mask=attention_mask,
1209
+ position_ids=position_ids,
1210
+ past_key_values=past_key_values,
1211
+ inputs_embeds=inputs_embeds,
1212
+ use_cache=use_cache,
1213
+ output_attentions=output_attentions,
1214
+ output_hidden_states=output_hidden_states,
1215
+ return_dict=return_dict,
1216
+ )
1217
+
1218
+ hidden_states = outputs[0]
1219
+ if self.config.pretraining_tp > 1:
1220
+ lm_head_slices = self.lm_head.weight.split(self.vocab_size // self.config.pretraining_tp, dim=0)
1221
+ logits = [F.linear(hidden_states, lm_head_slices[i]) for i in range(self.config.pretraining_tp)]
1222
+ logits = torch.cat(logits, dim=-1)
1223
+ else:
1224
+ logits = self.lm_head(hidden_states, layout_mask)
1225
+ logits = logits.float()
1226
+
1227
+ loss = None
1228
+ if labels is not None:
1229
+ # Shift so that tokens < n predict n
1230
+ shift_logits = logits[..., :-1, :].contiguous()
1231
+ shift_labels = labels[..., 1:].contiguous()
1232
+ # Flatten the tokens
1233
+ loss_fct = CrossEntropyLoss()
1234
+ shift_logits = shift_logits.view(-1, self.config.vocab_size)
1235
+ shift_labels = shift_labels.view(-1)
1236
+ # Enable model parallelism
1237
+ shift_labels = shift_labels.to(shift_logits.device)
1238
+ loss = loss_fct(shift_logits, shift_labels)
1239
+
1240
+ if not return_dict:
1241
+ output = (logits,) + outputs[1:]
1242
+ return (loss,) + output if loss is not None else output
1243
+
1244
+ return CausalLMOutputWithPast(
1245
+ loss=loss,
1246
+ logits=logits,
1247
+ past_key_values=outputs.past_key_values,
1248
+ hidden_states=outputs.hidden_states,
1249
+ attentions=outputs.attentions,
1250
+ )
1251
+
1252
+ def prepare_inputs_for_generation(
1253
+ self, input_ids, past_key_values=None, attention_mask=None, inputs_embeds=None, **kwargs
1254
+ ):
1255
+ if past_key_values is not None:
1256
+ if isinstance(past_key_values, Cache):
1257
+ cache_length = past_key_values.get_seq_length()
1258
+ past_length = past_key_values.seen_tokens
1259
+ max_cache_length = past_key_values.get_max_length()
1260
+ else:
1261
+ cache_length = past_length = past_key_values[0][0].shape[2]
1262
+ max_cache_length = None
1263
+
1264
+ # Keep only the unprocessed tokens:
1265
+ # 1 - If the length of the attention_mask exceeds the length of input_ids, then we are in a setting where
1266
+ # some of the inputs are exclusivelly passed as part of the cache (e.g. when passing input_embeds as
1267
+ # input)
1268
+ if attention_mask is not None and attention_mask.shape[1] > input_ids.shape[1]:
1269
+ input_ids = input_ids[:, -(attention_mask.shape[1] - past_length) :]
1270
+ # 2 - If the past_length is smaller than input_ids', then input_ids holds all input tokens. We can discard
1271
+ # input_ids based on the past_length.
1272
+ elif past_length < input_ids.shape[1]:
1273
+ input_ids = input_ids[:, past_length:]
1274
+ # 3 - Otherwise (past_length >= input_ids.shape[1]), let's assume input_ids only has unprocessed tokens.
1275
+
1276
+ # If we are about to go beyond the maximum cache length, we need to crop the input attention mask.
1277
+ if (
1278
+ max_cache_length is not None
1279
+ and attention_mask is not None
1280
+ and cache_length + input_ids.shape[1] > max_cache_length
1281
+ ):
1282
+ attention_mask = attention_mask[:, -max_cache_length:]
1283
+
1284
+ position_ids = kwargs.get("position_ids", None)
1285
+ if attention_mask is not None and position_ids is None:
1286
+ # create position_ids on the fly for batch generation
1287
+ position_ids = attention_mask.long().cumsum(-1) - 1
1288
+ position_ids.masked_fill_(attention_mask == 0, 1)
1289
+ if past_key_values:
1290
+ position_ids = position_ids[:, -input_ids.shape[1] :]
1291
+
1292
+ # if `inputs_embeds` are passed, we only want to use them in the 1st generation step
1293
+ if inputs_embeds is not None and past_key_values is None:
1294
+ model_inputs = {"inputs_embeds": inputs_embeds}
1295
+ else:
1296
+ model_inputs = {"input_ids": input_ids}
1297
+
1298
+ model_inputs.update(
1299
+ {
1300
+ "position_ids": position_ids,
1301
+ "laytout_input": kwargs.get("laytout_input") if not past_key_values else None,
1302
+ "past_key_values": past_key_values,
1303
+ "use_cache": kwargs.get("use_cache"),
1304
+ "attention_mask": attention_mask,
1305
+ }
1306
+ )
1307
+ return model_inputs
1308
+
1309
+ @staticmethod
1310
+ def _reorder_cache(past_key_values, beam_idx):
1311
+ reordered_past = ()
1312
+ for layer_past in past_key_values:
1313
+ reordered_past += (
1314
+ tuple(past_state.index_select(0, beam_idx.to(past_state.device)) for past_state in layer_past),
1315
+ )
1316
+ return reordered_past
1317
+
1318
+
1319
+ @add_start_docstrings(
1320
+ """
1321
+ The LLaMa Model transformer with a sequence classification head on top (linear layer).
1322
+
1323
+ [`LlamaForSequenceClassification`] uses the last token in order to do the classification, as other causal models
1324
+ (e.g. GPT-2) do.
1325
+
1326
+ Since it does classification on the last token, it requires to know the position of the last token. If a
1327
+ `pad_token_id` is defined in the configuration, it finds the last token that is not a padding token in each row. If
1328
+ no `pad_token_id` is defined, it simply takes the last value in each row of the batch. Since it cannot guess the
1329
+ padding tokens when `inputs_embeds` are passed instead of `input_ids`, it does the same (take the last value in
1330
+ each row of the batch).
1331
+ """,
1332
+ LLAMA_START_DOCSTRING,
1333
+ )
1334
+ class LlamaForSequenceClassification(LlamaPreTrainedModel):
1335
+ def __init__(self, config):
1336
+ super().__init__(config)
1337
+ self.num_labels = config.num_labels
1338
+ self.model = LlamaModel(config)
1339
+ self.score = PLoRA(config.hidden_size, self.num_labels, lora_r=config.lora_r, lora_alpha=config.lora_alpha, bias=False)
1340
+
1341
+ # Initialize weights and apply final processing
1342
+ self.post_init()
1343
+
1344
+ def get_input_embeddings(self):
1345
+ return self.model.embed_tokens
1346
+
1347
+ def set_input_embeddings(self, value):
1348
+ self.model.embed_tokens = value
1349
+
1350
+ @add_start_docstrings_to_model_forward(LLAMA_INPUTS_DOCSTRING)
1351
+ def forward(
1352
+ self,
1353
+ input_ids: torch.LongTensor = None,
1354
+ attention_mask: Optional[torch.Tensor] = None,
1355
+ position_ids: Optional[torch.LongTensor] = None,
1356
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
1357
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1358
+ labels: Optional[torch.LongTensor] = None,
1359
+ use_cache: Optional[bool] = None,
1360
+ output_attentions: Optional[bool] = None,
1361
+ output_hidden_states: Optional[bool] = None,
1362
+ return_dict: Optional[bool] = None,
1363
+ layout_mask: Optional[Tuple[torch.Tensor]] = None,
1364
+ ) -> Union[Tuple, SequenceClassifierOutputWithPast]:
1365
+ r"""
1366
+ labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
1367
+ Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
1368
+ config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
1369
+ `config.num_labels > 1` a classification loss is computed (Cross-Entropy).
1370
+ """
1371
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
1372
+
1373
+ transformer_outputs = self.model(
1374
+ input_ids,
1375
+ attention_mask=attention_mask,
1376
+ position_ids=position_ids,
1377
+ past_key_values=past_key_values,
1378
+ inputs_embeds=inputs_embeds,
1379
+ use_cache=use_cache,
1380
+ output_attentions=output_attentions,
1381
+ output_hidden_states=output_hidden_states,
1382
+ return_dict=return_dict,
1383
+ )
1384
+ hidden_states = transformer_outputs[0]
1385
+ logits = self.score(hidden_states, layout_mask)
1386
+
1387
+ if input_ids is not None:
1388
+ batch_size = input_ids.shape[0]
1389
+ else:
1390
+ batch_size = inputs_embeds.shape[0]
1391
+
1392
+ if self.config.pad_token_id is None and batch_size != 1:
1393
+ raise ValueError("Cannot handle batch sizes > 1 if no padding token is defined.")
1394
+ if self.config.pad_token_id is None:
1395
+ sequence_lengths = -1
1396
+ else:
1397
+ if input_ids is not None:
1398
+ sequence_lengths = (torch.eq(input_ids, self.config.pad_token_id).int().argmax(-1) - 1).to(
1399
+ logits.device
1400
+ )
1401
+ else:
1402
+ sequence_lengths = -1
1403
+
1404
+ pooled_logits = logits[torch.arange(batch_size, device=logits.device), sequence_lengths]
1405
+
1406
+ loss = None
1407
+ if labels is not None:
1408
+ labels = labels.to(logits.device)
1409
+ if self.config.problem_type is None:
1410
+ if self.num_labels == 1:
1411
+ self.config.problem_type = "regression"
1412
+ elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
1413
+ self.config.problem_type = "single_label_classification"
1414
+ else:
1415
+ self.config.problem_type = "multi_label_classification"
1416
+
1417
+ if self.config.problem_type == "regression":
1418
+ loss_fct = MSELoss()
1419
+ if self.num_labels == 1:
1420
+ loss = loss_fct(pooled_logits.squeeze(), labels.squeeze())
1421
+ else:
1422
+ loss = loss_fct(pooled_logits, labels)
1423
+ elif self.config.problem_type == "single_label_classification":
1424
+ loss_fct = CrossEntropyLoss()
1425
+ loss = loss_fct(pooled_logits.view(-1, self.num_labels), labels.view(-1))
1426
+ elif self.config.problem_type == "multi_label_classification":
1427
+ loss_fct = BCEWithLogitsLoss()
1428
+ loss = loss_fct(pooled_logits, labels)
1429
+ if not return_dict:
1430
+ output = (pooled_logits,) + transformer_outputs[1:]
1431
+ return ((loss,) + output) if loss is not None else output
1432
+
1433
+ return SequenceClassifierOutputWithPast(
1434
+ loss=loss,
1435
+ logits=pooled_logits,
1436
+ past_key_values=transformer_outputs.past_key_values,
1437
+ hidden_states=transformer_outputs.hidden_states,
1438
+ attentions=transformer_outputs.attentions,
1439
+ )