syzymon commited on
Commit
c4c0e44
1 Parent(s): 031dcf9
config.json ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "LongLlamaForCausalLM"
4
+ ],
5
+ "bos_token_id": 1,
6
+ "eos_token_id": 2,
7
+ "gradient_checkpoint_every_ith": 1,
8
+ "hidden_act": "silu",
9
+ "hidden_size": 4096,
10
+ "initializer_range": 0.02,
11
+ "intermediate_size": 11008,
12
+ "last_context_length": 2048,
13
+ "max_position_embeddings": 4096,
14
+ "mem_attention_grouping": null,
15
+ "mem_dtype": "bfloat16",
16
+ "mem_layers": [
17
+ 8,
18
+ 16,
19
+ 24
20
+ ],
21
+ "mem_positionals": true,
22
+ "model_type": "longllama",
23
+ "num_attention_heads": 32,
24
+ "num_hidden_layers": 32,
25
+ "pad_token_id": 0,
26
+ "rms_norm_eps": 1e-06,
27
+ "rope_scaling": null,
28
+ "rope_theta": 1000000.0,
29
+ "tie_word_embeddings": false,
30
+ "torch_attention": false,
31
+ "torch_dtype": "bfloat16",
32
+ "transformers_version": "4.30.0",
33
+ "use_cache": true,
34
+ "vocab_size": 32016,
35
+ "auto_map": {
36
+ "AutoConfig": "configuration_longllama.LongLlamaConfig",
37
+ "AutoModel": "modeling_longllama.LongLlamaModel",
38
+ "AutoModelForCausalLM": "modeling_longllama.LongLlamaForCausalLM",
39
+ "AutoModelForSequenceClassification": "modeling_longllama.LongLlamaForSequenceClassification"
40
+ }
41
+ }
configuration_longllama.py ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2023 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
+ """ LongLLaMA 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
+ LONGLLAMA_PRETRAINED_CONFIG_ARCHIVE_MAP = {
29
+ "syzymon/long_llama_3b": "https://huggingface.co/syzymon/long_llama_3b/resolve/main/config.json",
30
+ }
31
+
32
+
33
+ class LongLlamaConfig(PretrainedConfig):
34
+ r"""
35
+ This is the configuration class to store the configuration of a [`LongLlamaModel`]. It is used to instantiate an LongLLaMA
36
+ model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
37
+ defaults will yield a similar configuration to that of the LongLLaMA-7B.
38
+
39
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
40
+ documentation from [`PretrainedConfig`] for more information.
41
+
42
+
43
+ Args:
44
+ vocab_size (`int`, *optional*, defaults to 32000):
45
+ Vocabulary size of the LongLLaMA model. Defines the number of different tokens that can be represented by the
46
+ `inputs_ids` passed when calling [`LongLlamaModel`]
47
+ hidden_size (`int`, *optional*, defaults to 4096):
48
+ Dimension of the hidden representations.
49
+ intermediate_size (`int`, *optional*, defaults to 11008):
50
+ Dimension of the MLP representations.
51
+ num_hidden_layers (`int`, *optional*, defaults to 32):
52
+ Number of hidden layers in the Transformer encoder.
53
+ num_attention_heads (`int`, *optional*, defaults to 32):
54
+ Number of attention heads for each attention layer in the Transformer encoder.
55
+ hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
56
+ The non-linear activation function (function or string) in the decoder.
57
+ max_position_embeddings (`int`, *optional*, defaults to 2048):
58
+ The maximum sequence length that this model might ever be used with. Typically set this to something large
59
+ just in case (e.g., 512 or 1024 or 2048).
60
+ initializer_range (`float`, *optional*, defaults to 0.02):
61
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
62
+ rms_norm_eps (`float`, *optional*, defaults to 1e-12):
63
+ The epsilon used by the rms normalization layers.
64
+ use_cache (`bool`, *optional*, defaults to `True`):
65
+ Whether or not the model should return the last key/values attentions (not used by all models). Only
66
+ relevant if `config.is_decoder=True`.
67
+ tie_word_embeddings(`bool`, *optional*, defaults to `False`):
68
+ Whether to tie weight embeddings
69
+ mem_layers (`List[int]`, defaults to `[]`):
70
+ Layers with memory
71
+ mem_positionals (`bool`, *optional*, defaults to `True`):
72
+ Whether to use positional embeddings in memory layers
73
+ mem_dtype (`str`, *optional*, defaults to `"bfloat16"`):
74
+ Type for keys and values stored in memory
75
+ mem_attention_grouping (`Tuple[int, int]`, *optional*, defaults to `None`):
76
+ One can trade speed for memory by performing attention
77
+ in memory layers sequentially.
78
+ When equal to `(4, 2048)` the memory layers will process at most 4 heads and 2048 queries from each head at once.
79
+ That is at most 4*2048 queries at once.
80
+ torch_attention (`bool`, *optional*, defaults to `False`):
81
+ Whether to use torch scaled_dot_product_attention
82
+ gradient_checkpoint_every_ith (`int`, *optional*, defaults to `1`):
83
+ When gradient checkpointing is enabled checkpoint every ith layer
84
+
85
+ Example:
86
+
87
+ ```python
88
+ >>> from transformers import LongLlamaModel, LongLlamaConfig
89
+
90
+ >>> # Initializing a LongLLaMA longllama-7b style configuration
91
+ >>> configuration = LongLlamaConfig()
92
+
93
+ >>> # Initializing a model from the longllama-7b style configuration
94
+ >>> model = LongLlamaModel(configuration)
95
+
96
+ >>> # Accessing the model configuration
97
+ >>> configuration = model.config
98
+ ```"""
99
+ model_type = "longllama"
100
+ keys_to_ignore_at_inference = ["past_key_values"]
101
+
102
+ def __init__(
103
+ self,
104
+ vocab_size=32000,
105
+ hidden_size=4096,
106
+ intermediate_size=11008,
107
+ num_hidden_layers=32,
108
+ num_attention_heads=32,
109
+ hidden_act="silu",
110
+ max_position_embeddings=2048,
111
+ initializer_range=0.02,
112
+ rms_norm_eps=1e-6,
113
+ use_cache=True,
114
+ pad_token_id=0,
115
+ bos_token_id=1,
116
+ eos_token_id=2,
117
+ tie_word_embeddings=False,
118
+ rope_theta=10000.0,
119
+ rope_scaling=None,
120
+ last_context_length=1024,
121
+ mem_layers=[],
122
+ mem_positionals=True,
123
+ mem_dtype="bfloat16",
124
+ mem_attention_grouping=None,
125
+ torch_attention=False,
126
+ gradient_checkpoint_every_ith=1,
127
+ **kwargs,
128
+ ):
129
+ self.vocab_size = vocab_size
130
+ self.max_position_embeddings = max_position_embeddings
131
+ self.hidden_size = hidden_size
132
+ self.intermediate_size = intermediate_size
133
+ self.num_hidden_layers = num_hidden_layers
134
+ self.num_attention_heads = num_attention_heads
135
+ self.hidden_act = hidden_act
136
+ self.initializer_range = initializer_range
137
+ self.rms_norm_eps = rms_norm_eps
138
+ self.use_cache = use_cache
139
+ self.rope_theta = rope_theta
140
+ self.rope_scaling = rope_scaling
141
+ self.last_context_length = last_context_length
142
+ self.mem_layers = mem_layers
143
+ self.mem_positionals = mem_positionals
144
+ self.mem_dtype = mem_dtype
145
+ self.mem_attention_grouping = mem_attention_grouping
146
+ self.torch_attention = torch_attention
147
+ self.gradient_checkpoint_every_ith = gradient_checkpoint_every_ith
148
+
149
+ self._rope_scaling_validation()
150
+ super().__init__(
151
+ pad_token_id=pad_token_id,
152
+ bos_token_id=bos_token_id,
153
+ eos_token_id=eos_token_id,
154
+ tie_word_embeddings=tie_word_embeddings,
155
+ **kwargs,
156
+ )
157
+
158
+ def _rope_scaling_validation(self):
159
+ """
160
+ Validate the `rope_scaling` configuration.
161
+ """
162
+ if self.rope_scaling is not None:
163
+ raise ValueError("LongLLaMA does not use rope_scaling")
generation_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 1,
4
+ "eos_token_id": 2,
5
+ "transformers_version": "4.33.0.dev0"
6
+ }
longllama_utils.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from collections import namedtuple
2
+ from dataclasses import dataclass
3
+ import torch
4
+ from typing import Tuple, Optional
5
+
6
+
7
+ @dataclass
8
+ class LongLlamaMemConfig:
9
+ """
10
+ Class for configuring memory caches for LongLlama model.
11
+
12
+ Args:
13
+ positionals (`boolean`)
14
+ Whether to use positional embeddings in memory layer
15
+ cache_dtype (`torch.dtype`)
16
+ Specifies storing type for keys and values
17
+ attention_grouping (`Tuple[int, int]`, *optional*)
18
+ One can trade speed for memory by performing attention
19
+ in memory layers sequentially.
20
+ When equal to `(4, 128)` the memory layers will process at most 4 heads and 128 queries
21
+ from each head at once. That is at most 512 queries at once.
22
+ """
23
+
24
+ positionals: bool = True
25
+ cache_dtype: torch.dtype = torch.bfloat16
26
+ attention_grouping: Optional[Tuple[int, int]] = None
27
+
28
+
29
+ @dataclass
30
+ class LongLlamaMemCache:
31
+ """
32
+ Class with LongLlama's memory cache
33
+
34
+ Args:
35
+ keys (`torch.FloatTensor` of shape `(batch_size, num_heads, mem_length, embed_size_per_head)`)
36
+ values (`torch.FloatTensor` of shape `(batch_size, num_heads, mem_length, embed_size_per_head)`)
37
+ masks (`torch.FloatTensor` of shape `(batch_size, 1, mem_length, 1)`)
38
+ For masking out parts of memory
39
+ """
40
+
41
+ keys: torch.FloatTensor
42
+ values: torch.FloatTensor
43
+ masks: torch.FloatTensor
44
+
45
+
46
+ def mem_apply_update(
47
+ prev_mem_cache: LongLlamaMemCache, new_mem_content: LongLlamaMemCache, mem_config: LongLlamaMemConfig
48
+ ):
49
+ def update_one(prev, new):
50
+ if len(prev.shape) != 4 or len(new.shape) != 4:
51
+ raise ValueError(f"Memory cache content should be consistent in shape got {prev.shape} {new.shape}")
52
+
53
+ return torch.concat([prev, new], dim=-2)
54
+
55
+ insert_size = new_mem_content.keys.shape[-2]
56
+
57
+ if new_mem_content.values.shape[-2] != insert_size or new_mem_content.masks.shape[-2] != insert_size:
58
+ raise ValueError(f"Inconsistent mem_length in new_mem_content")
59
+
60
+ return LongLlamaMemCache(
61
+ keys=update_one(prev_mem_cache.keys, new_mem_content.keys),
62
+ values=update_one(prev_mem_cache.values, new_mem_content.values),
63
+ masks=update_one(prev_mem_cache.masks, new_mem_content.masks),
64
+ )
modeling_longllama.py ADDED
@@ -0,0 +1,1467 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2023 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 LongLLaMA model."""
21
+ from dataclasses import dataclass
22
+ import math
23
+ from typing import List, Optional, Tuple, Union
24
+
25
+ import torch
26
+ import torch.utils.checkpoint
27
+ from torch import nn
28
+ from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
29
+
30
+ from transformers.activations import ACT2FN
31
+ from transformers.modeling_outputs import (
32
+ BaseModelOutputWithPast,
33
+ CausalLMOutputWithPast,
34
+ SequenceClassifierOutputWithPast,
35
+ )
36
+ from transformers.modeling_utils import PreTrainedModel
37
+ from transformers.utils import (
38
+ add_start_docstrings,
39
+ add_start_docstrings_to_model_forward,
40
+ logging,
41
+ replace_return_docstrings,
42
+ )
43
+ from .configuration_longllama import LongLlamaConfig
44
+ from .longllama_utils import mem_apply_update, LongLlamaMemCache, LongLlamaMemConfig
45
+
46
+
47
+ logger = logging.get_logger(__name__)
48
+
49
+ _CONFIG_FOR_DOC = "LongLlamaConfig"
50
+
51
+
52
+ @dataclass
53
+ class LongLlamaModelOutputWithPast(BaseModelOutputWithPast):
54
+ """
55
+ Based on BaseModelOutputWithPast
56
+
57
+ Args:
58
+ last_hidden_state (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
59
+ past_key_values (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
60
+ hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
61
+ attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
62
+ mem_caches (`tuple(LongLlamaMemCache))`, *optional*, returned for layers with memory cache enabled):
63
+ For the layers without memory None is returned
64
+ """
65
+
66
+ mem_caches: Optional[LongLlamaMemCache] = None
67
+
68
+
69
+ # Copied from transformers.models.bart.modeling_bart._make_causal_mask
70
+ def _make_causal_mask(
71
+ input_ids_shape: torch.Size, dtype: torch.dtype, device: torch.device, past_key_values_length: int = 0
72
+ ):
73
+ """
74
+ Make causal mask used for bi-directional self-attention.
75
+ """
76
+ bsz, tgt_len = input_ids_shape
77
+ mask = torch.full((tgt_len, tgt_len), torch.finfo(dtype).min, device=device)
78
+ mask_cond = torch.arange(mask.size(-1), device=device)
79
+ mask.masked_fill_(mask_cond < (mask_cond + 1).view(mask.size(-1), 1), 0)
80
+ mask = mask.to(dtype)
81
+
82
+ if past_key_values_length > 0:
83
+ mask = torch.cat([torch.zeros(tgt_len, past_key_values_length, dtype=dtype, device=device), mask], dim=-1)
84
+ return mask[None, None, :, :].expand(bsz, 1, tgt_len, tgt_len + past_key_values_length)
85
+
86
+
87
+ # Copied from transformers.models.bart.modeling_bart._expand_mask
88
+ def _expand_mask(mask: torch.Tensor, dtype: torch.dtype, tgt_len: Optional[int] = None):
89
+ """
90
+ Expands attention_mask from `[bsz, seq_len]` to `[bsz, 1, tgt_seq_len, src_seq_len]`.
91
+ """
92
+ bsz, src_len = mask.size()
93
+ tgt_len = tgt_len if tgt_len is not None else src_len
94
+
95
+ expanded_mask = mask[:, None, None, :].expand(bsz, 1, tgt_len, src_len).to(dtype)
96
+
97
+ inverted_mask = 1.0 - expanded_mask
98
+
99
+ return inverted_mask.masked_fill(inverted_mask.to(torch.bool), torch.finfo(dtype).min)
100
+
101
+
102
+ # Copied from transformers.models.llama.modeling_llama.LlamaRMSNorm with Llama->LongLlama
103
+ class LongLlamaRMSNorm(nn.Module):
104
+ def __init__(self, hidden_size, eps=1e-6):
105
+ """
106
+ LongLlamaRMSNorm is equivalent to T5LayerNorm
107
+ """
108
+ super().__init__()
109
+ self.weight = nn.Parameter(torch.ones(hidden_size))
110
+ self.variance_epsilon = eps
111
+
112
+ def forward(self, hidden_states):
113
+ input_dtype = hidden_states.dtype
114
+ hidden_states = hidden_states.to(torch.float32)
115
+ variance = hidden_states.pow(2).mean(-1, keepdim=True)
116
+ hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
117
+ return self.weight * hidden_states.to(input_dtype)
118
+
119
+
120
+ # Copied from transformers.models.llama.modeling_llama.LlamaRotaryEmbedding with Llama->LongLlama
121
+ class LongLlamaRotaryEmbedding(torch.nn.Module):
122
+ def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None):
123
+ super().__init__()
124
+
125
+ self.dim = dim
126
+ self.max_position_embeddings = max_position_embeddings
127
+ self.base = base
128
+ inv_freq = 1.0 / (self.base ** (torch.arange(0, self.dim, 2).float().to(device) / self.dim))
129
+ self.register_buffer("inv_freq", inv_freq, persistent=False)
130
+
131
+ # Build here to make `torch.jit.trace` work.
132
+ self._set_cos_sin_cache(
133
+ seq_len=max_position_embeddings, device=self.inv_freq.device, dtype=torch.get_default_dtype()
134
+ )
135
+
136
+ def _set_cos_sin_cache(self, seq_len, device, dtype):
137
+ self.max_seq_len_cached = seq_len
138
+ t = torch.arange(self.max_seq_len_cached, device=device, dtype=self.inv_freq.dtype)
139
+
140
+ freqs = torch.einsum("i,j->ij", t, self.inv_freq)
141
+ # Different from paper, but it uses a different permutation in order to obtain the same calculation
142
+ emb = torch.cat((freqs, freqs), dim=-1)
143
+ self.register_buffer("cos_cached", emb.cos()[None, None, :, :].to(dtype), persistent=False)
144
+ self.register_buffer("sin_cached", emb.sin()[None, None, :, :].to(dtype), persistent=False)
145
+
146
+ def forward(self, x, seq_len=None):
147
+ # x: [bs, num_attention_heads, seq_len, head_size]
148
+ if seq_len > self.max_seq_len_cached:
149
+ self._set_cos_sin_cache(seq_len=seq_len, device=x.device, dtype=x.dtype)
150
+
151
+ return (
152
+ self.cos_cached[:, :, :seq_len, ...].to(dtype=x.dtype),
153
+ self.sin_cached[:, :, :seq_len, ...].to(dtype=x.dtype),
154
+ )
155
+
156
+
157
+ def rotate_half(x):
158
+ """Rotates half the hidden dims of the input."""
159
+ x1 = x[..., : x.shape[-1] // 2]
160
+ x2 = x[..., x.shape[-1] // 2 :]
161
+ return torch.cat((-x2, x1), dim=-1)
162
+
163
+
164
+ # Based on transformers.models.llama.modeling_llama.apply_rotary_pos_emb
165
+ def rotate_one(x, cos, sin, position_ids):
166
+ if len(position_ids.shape) != 2 or x.shape[0] != position_ids.shape[0] or x.shape[-2] != position_ids.shape[1]:
167
+ raise ValueError(f"Position ids shoud have shape [bsz, seq_len] got {position_ids.shape}")
168
+ # The first two dimensions of cos and sin are always 1, so we can `squeeze` them.
169
+ cos = cos.squeeze(1).squeeze(0) # [seq_len, dim]
170
+ sin = sin.squeeze(1).squeeze(0) # [seq_len, dim]
171
+ cos = cos[position_ids].unsqueeze(1) # [bs, 1, seq_len, dim]
172
+ sin = sin[position_ids].unsqueeze(1) # [bs, 1, seq_len, dim]
173
+ x_embed = (x * cos) + (rotate_half(x) * sin)
174
+ return x_embed
175
+
176
+
177
+ def rotate_as_if_first(x, rotary_emb):
178
+ # x: [bs, num_attention_heads, seq_len, head_size]
179
+ # apply rotary as if all elements were first in the sequence
180
+ cos, sin = rotary_emb(x, x.shape[-2])
181
+ return rotate_one(x, cos, sin, torch.zeros(x.shape[0], x.shape[-2], dtype=torch.long, device=cos.device))
182
+
183
+
184
+ # Based on an 4.30 transformers.models.llama.modeling_llama.LlamaMLP with Llama->LongLlama
185
+ class LongLlamaMLP(nn.Module):
186
+ def __init__(
187
+ self,
188
+ hidden_size: int,
189
+ intermediate_size: int,
190
+ hidden_act: str,
191
+ ):
192
+ super().__init__()
193
+ self.gate_proj = nn.Linear(hidden_size, intermediate_size, bias=False)
194
+ self.down_proj = nn.Linear(intermediate_size, hidden_size, bias=False)
195
+ self.up_proj = nn.Linear(hidden_size, intermediate_size, bias=False)
196
+ self.act_fn = ACT2FN[hidden_act]
197
+
198
+ def forward(self, x):
199
+ return self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))
200
+
201
+
202
+ # Modified transformers.models.llama.modeling_llama.LlamaAttention
203
+ class LongLlamaAttention(nn.Module):
204
+ """Multi-headed attention from 'Attention Is All You Need' paper with FoT modifications"""
205
+
206
+ def __init__(self, config: LongLlamaConfig, mem_config: Optional[LongLlamaMemConfig] = None):
207
+ super().__init__()
208
+ self.config = config
209
+ self.hidden_size = config.hidden_size
210
+ self.num_heads = config.num_attention_heads
211
+ self.head_dim = self.hidden_size // self.num_heads
212
+ self.max_position_embeddings = config.max_position_embeddings
213
+ self.max_cache = self.max_position_embeddings
214
+ self.rope_theta = config.rope_theta
215
+
216
+ if (self.head_dim * self.num_heads) != self.hidden_size:
217
+ raise ValueError(
218
+ f"hidden_size must be divisible by num_heads (got `hidden_size`: {self.hidden_size}"
219
+ f" and `num_heads`: {self.num_heads})."
220
+ )
221
+ self.q_proj = nn.Linear(self.hidden_size, self.num_heads * self.head_dim, bias=False)
222
+ self.k_proj = nn.Linear(self.hidden_size, self.num_heads * self.head_dim, bias=False)
223
+ self.v_proj = nn.Linear(self.hidden_size, self.num_heads * self.head_dim, bias=False)
224
+ self.o_proj = nn.Linear(self.num_heads * self.head_dim, self.hidden_size, bias=False)
225
+ self._init_rope()
226
+ self.mem_config = mem_config
227
+
228
+ def _init_rope(self):
229
+ assert self.config.rope_scaling is None
230
+ self.rotary_emb = LongLlamaRotaryEmbedding(
231
+ self.head_dim,
232
+ max_position_embeddings=self.max_position_embeddings,
233
+ base=self.rope_theta,
234
+ )
235
+
236
+ def _shape(self, tensor: torch.Tensor, seq_len: int, bsz: int):
237
+ return tensor.view(bsz, seq_len, self.num_heads, self.head_dim).transpose(1, 2).contiguous()
238
+
239
+ def forward(
240
+ self,
241
+ hidden_states: torch.Tensor,
242
+ attention_mask: Optional[torch.Tensor] = None,
243
+ position_ids: Optional[torch.LongTensor] = None,
244
+ past_key_value: Optional[Tuple[torch.Tensor]] = None,
245
+ output_attentions: bool = False,
246
+ use_cache: bool = False,
247
+ mem_cache: Optional[LongLlamaMemCache] = None,
248
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
249
+ if attention_mask is None:
250
+ tgt_seq_len = hidden_states.shape[-2]
251
+ if past_key_value is not None:
252
+ src_seq_len = past_key_value[0].shape[-2] + tgt_seq_len
253
+ else:
254
+ src_seq_len = tgt_seq_len
255
+
256
+ attention_mask = torch.zeros(
257
+ hidden_states.shape[0],
258
+ 1,
259
+ tgt_seq_len,
260
+ src_seq_len,
261
+ device=hidden_states.device,
262
+ dtype=hidden_states.dtype,
263
+ )
264
+ bsz, q_len, _ = hidden_states.size()
265
+
266
+ query_states = self.q_proj(hidden_states).view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
267
+ key_states = self.k_proj(hidden_states).view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
268
+ value_states = self.v_proj(hidden_states).view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
269
+ position_ids = position_ids[:, None, :, None]
270
+
271
+ if position_ids.shape != (key_states.shape[0], 1, key_states.shape[-2], 1):
272
+ raise ValueError("position_ids should match batch and seq_len of the input")
273
+
274
+ mem_no_local_cache = self.mem_config is not None and past_key_value is None and (not use_cache)
275
+ mem_and_local_cache = self.mem_config is not None and use_cache
276
+ # positonal embeddings can be disabled for memory layers
277
+ use_positionals = self.mem_config is None or self.mem_config.positionals
278
+
279
+ if mem_no_local_cache:
280
+ # the whole context window will be moved to memory cache after the attention
281
+ if use_positionals:
282
+ # positionally embedd memory content as first token in the sequence
283
+ rfst_key_states = rotate_as_if_first(key_states, self.rotary_emb)
284
+ else:
285
+ rfst_key_states = key_states
286
+ # attention_mask [bsz, 1, tgt_seq_len, src_seq_len]
287
+ # we base the mask on the last token in the context window
288
+ mem_update = LongLlamaMemCache(
289
+ keys=rfst_key_states.to(self.mem_config.cache_dtype),
290
+ values=value_states.to(self.mem_config.cache_dtype),
291
+ masks=attention_mask[..., -1, :, None],
292
+ )
293
+
294
+ if past_key_value is not None:
295
+ past_local_cache_size = past_key_value[0].shape[-2]
296
+ key_states = torch.cat([past_key_value[0], key_states], dim=-2)
297
+ value_states = torch.cat([past_key_value[1], value_states], dim=-2)
298
+ # FoT additionally stores position_ids to support long inputs
299
+ position_ids = torch.cat([past_key_value[2], position_ids], dim=-2)
300
+
301
+ if attention_mask.shape[-1] != key_states.shape[-2] and attention_mask.shape[-2] != query_states.shape[-2]:
302
+ raise ValueError("attention_mask should be provided for all key_states in local context")
303
+
304
+ # local cache is maintained so that it is <= self.max_cache
305
+ # remaining elements are either dropped or go to memory cache
306
+ if key_states.shape[-2] > self.max_cache:
307
+ num_elems_to_drop = past_local_cache_size
308
+
309
+ if mem_and_local_cache:
310
+ drop_keys = key_states[:, :, :num_elems_to_drop, :]
311
+ drop_values = value_states[:, :, :num_elems_to_drop, :]
312
+ # as memory mask use the masking of the last key in context
313
+ # attention_mask [bsz, 1, tgt_seq_len, src_seq_len]
314
+ drop_masks = attention_mask[..., -1, :, None]
315
+ drop_masks = drop_masks[:, :, :num_elems_to_drop, :]
316
+
317
+ if use_positionals:
318
+ rfst_drop_keys = rotate_as_if_first(drop_keys, self.rotary_emb)
319
+ else:
320
+ rfst_drop_keys = drop_keys
321
+ mem_update = LongLlamaMemCache(
322
+ keys=rfst_drop_keys.to(self.mem_config.cache_dtype),
323
+ values=drop_values.to(self.mem_config.cache_dtype),
324
+ masks=drop_masks,
325
+ )
326
+ if mem_cache is None:
327
+ mem_cache = mem_update
328
+ else:
329
+ mem_cache = mem_apply_update(
330
+ prev_mem_cache=mem_cache, new_mem_content=mem_update, mem_config=self.mem_config
331
+ )
332
+
333
+ key_states = key_states[:, :, num_elems_to_drop:, :]
334
+ value_states = value_states[:, :, num_elems_to_drop:, :]
335
+ position_ids = position_ids[:, :, num_elems_to_drop:, :]
336
+ attention_mask = attention_mask[..., num_elems_to_drop:]
337
+
338
+ # FoT additionally stores position_ids to support long inputs
339
+ past_key_value = (key_states, value_states, position_ids) if use_cache else None
340
+
341
+ kv_seq_len = key_states.shape[-2]
342
+
343
+ if use_positionals:
344
+ cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len)
345
+ rel_pos_ids = position_ids - torch.min(position_ids, dim=-2, keepdim=True)[0]
346
+ rel_pos_ids = rel_pos_ids.squeeze(3).squeeze(1)
347
+
348
+ query_states = rotate_one(query_states, cos, sin, rel_pos_ids[:, -query_states.shape[-2] :])
349
+ key_states = rotate_one(key_states, cos, sin, rel_pos_ids)
350
+
351
+ if self.mem_config is not None and self.mem_config.attention_grouping is not None:
352
+ attn_grouping_h, attn_grouping_q = self.mem_config.attention_grouping
353
+ if attn_grouping_h <= 0 or attn_grouping_q <= 0:
354
+ raise ValueError("Attention grouping should be positive")
355
+ else:
356
+ attn_grouping_h, attn_grouping_q = self.num_heads, q_len
357
+
358
+ attn_output_h = []
359
+ for beg_h in range(0, self.num_heads, attn_grouping_h):
360
+ end_h = min(beg_h + attn_grouping_h, self.num_heads)
361
+
362
+ attn_output_q = []
363
+ for beg_q in range(0, q_len, attn_grouping_q):
364
+ end_q = min(beg_q + attn_grouping_q, q_len)
365
+
366
+ if self.config.torch_attention:
367
+ if mem_cache is not None:
368
+ attn_keys = torch.concat(
369
+ [key_states[:, beg_h:end_h], mem_cache.keys[:, beg_h:end_h].to(key_states.dtype)], dim=-2
370
+ )
371
+ attn_values = torch.concat(
372
+ [value_states[:, beg_h:end_h], mem_cache.values[:, beg_h:end_h].to(value_states.dtype)],
373
+ dim=-2,
374
+ )
375
+ mem_mask = mem_cache.masks.squeeze(-1).unsqueeze(-2)
376
+ assert len(mem_mask.shape) == 4
377
+ assert mem_mask.shape[2] == 1
378
+ assert mem_mask.shape[3] == mem_cache.keys.shape[-2]
379
+ mem_mask = torch.broadcast_to(
380
+ mem_mask, (mem_mask.shape[0], mem_mask.shape[1], end_q - beg_q, mem_mask.shape[3])
381
+ )
382
+ attn_mask = torch.concat([attention_mask[:, :, beg_q:end_q], mem_mask], dim=-1)
383
+ assert attn_mask.shape[-1] == attn_keys.shape[-2]
384
+ else:
385
+ attn_keys = key_states[:, beg_h:end_h]
386
+ attn_values = value_states[:, beg_h:end_h]
387
+ attn_mask = attention_mask[:, :, beg_q:end_q]
388
+
389
+ attn_queries = query_states[:, beg_h:end_h, beg_q:end_q]
390
+
391
+ attn_output = torch.nn.functional.scaled_dot_product_attention(
392
+ query=attn_queries, key=attn_keys, value=attn_values, attn_mask=attn_mask
393
+ )
394
+ attn_output_q.append(attn_output)
395
+ else:
396
+ attn_weights = torch.matmul(
397
+ query_states[:, beg_h:end_h, beg_q:end_q], key_states[:, beg_h:end_h].transpose(2, 3)
398
+ ) / math.sqrt(self.head_dim)
399
+
400
+ if attn_weights.size() != (bsz, end_h - beg_h, end_q - beg_q, kv_seq_len):
401
+ raise ValueError(
402
+ f"Attention weights should be of size {(bsz, end_h - beg_h, end_q - beg_q, kv_seq_len)}, but is"
403
+ f" {attn_weights.size()}"
404
+ )
405
+
406
+ if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
407
+ raise ValueError(
408
+ f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
409
+ )
410
+ attn_weights = attn_weights + attention_mask[:, :, beg_q:end_q]
411
+ min_value = (
412
+ torch.finfo(attn_weights.dtype).min
413
+ if -1000000.0 < torch.finfo(attn_weights.dtype).min
414
+ else -1000000.0
415
+ )
416
+ attn_weights = torch.max(
417
+ attn_weights, torch.tensor(min_value, device=attn_weights.device, dtype=attn_weights.dtype)
418
+ )
419
+
420
+ if mem_cache is not None:
421
+ mem_mask = mem_cache.masks.squeeze(-1).unsqueeze(-2)
422
+ mem_attn_weights = torch.matmul(
423
+ query_states[:, beg_h:end_h, beg_q:end_q],
424
+ mem_cache.keys[:, beg_h:end_h].transpose(2, 3).to(key_states.dtype),
425
+ ) / math.sqrt(self.head_dim)
426
+
427
+ assert mem_mask.shape[2] == 1
428
+ mem_attn_weights = mem_attn_weights + mem_mask
429
+ min_value = (
430
+ torch.finfo(mem_attn_weights.dtype).min
431
+ if -1000000.0 < torch.finfo(mem_attn_weights.dtype).min
432
+ else -1000000.0
433
+ )
434
+ mem_attn_weights = torch.max(
435
+ mem_attn_weights,
436
+ torch.tensor(min_value, device=mem_attn_weights.device, dtype=mem_attn_weights.dtype),
437
+ )
438
+
439
+ attn_weights = torch.concat([attn_weights, mem_attn_weights], dim=-1)
440
+ combined_value_states = torch.concat(
441
+ [value_states[:, beg_h:end_h], mem_cache.values[:, beg_h:end_h].to(value_states.dtype)],
442
+ dim=-2,
443
+ )
444
+ else:
445
+ combined_value_states = value_states[:, beg_h:end_h]
446
+ # upcast attention to fp32
447
+ attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(
448
+ query_states.dtype
449
+ )
450
+ attn_output = torch.matmul(attn_weights, combined_value_states)
451
+ assert attn_output.shape[-2] == end_q - beg_q
452
+ attn_output_q.append(attn_output)
453
+ attn_output_h.append(torch.concat(attn_output_q, dim=-2))
454
+
455
+ attn_output = torch.concat(attn_output_h, dim=-3)
456
+
457
+ if attn_output.size() != (bsz, self.num_heads, q_len, self.head_dim):
458
+ raise ValueError(
459
+ f"`attn_output` should be of size {(bsz, self.num_heads, q_len, self.head_dim)}, but is"
460
+ f" {attn_output.size()}"
461
+ )
462
+
463
+ attn_output = attn_output.transpose(1, 2)
464
+ attn_output = attn_output.reshape(bsz, q_len, self.hidden_size)
465
+
466
+ attn_output = self.o_proj(attn_output)
467
+
468
+ if not output_attentions:
469
+ attn_weights = None
470
+
471
+ if mem_no_local_cache:
472
+ if mem_cache is not None:
473
+ mem_cache = mem_apply_update(
474
+ prev_mem_cache=mem_cache, new_mem_content=mem_update, mem_config=self.mem_config
475
+ )
476
+ else:
477
+ mem_cache = mem_update
478
+
479
+ return attn_output, attn_weights, past_key_value, mem_cache
480
+
481
+
482
+ # Modified transformers.models.llama.modeling_llama.LlamaDecoderLayer
483
+ class LongLlamaDecoderLayer(nn.Module):
484
+ def __init__(self, config: LongLlamaConfig, mem_config: Optional[LongLlamaMemConfig] = None):
485
+ super().__init__()
486
+ self.hidden_size = config.hidden_size
487
+ self.self_attn = LongLlamaAttention(config=config, mem_config=mem_config)
488
+ self.mlp = LongLlamaMLP(
489
+ hidden_size=self.hidden_size,
490
+ intermediate_size=config.intermediate_size,
491
+ hidden_act=config.hidden_act,
492
+ )
493
+ self.input_layernorm = LongLlamaRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
494
+ self.post_attention_layernorm = LongLlamaRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
495
+
496
+ def forward(
497
+ self,
498
+ hidden_states: torch.Tensor,
499
+ attention_mask: Optional[torch.Tensor] = None,
500
+ position_ids: Optional[torch.LongTensor] = None,
501
+ past_key_value: Optional[Tuple[torch.Tensor]] = None,
502
+ output_attentions: Optional[bool] = False,
503
+ use_cache: Optional[bool] = False,
504
+ mem_cache: Optional[LongLlamaMemCache] = None,
505
+ ) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]]:
506
+ """
507
+ Args:
508
+ hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
509
+ attention_mask (`torch.FloatTensor`, *optional*): attention mask of size
510
+ `(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
511
+ output_attentions (`bool`, *optional*):
512
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under
513
+ returned tensors for more detail.
514
+ use_cache (`bool`, *optional*):
515
+ If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding
516
+ (see `past_key_values`).
517
+ past_key_value (`Tuple(torch.FloatTensor)`, *optional*): cached past key and value projection states
518
+ along with information about positions
519
+ mem_cache (`LongLlamaMemCache`, *optional*): memory cache for specific layers
520
+ """
521
+
522
+ residual = hidden_states
523
+
524
+ hidden_states = self.input_layernorm(hidden_states)
525
+
526
+ # Self Attention
527
+ hidden_states, self_attn_weights, present_key_value, mem_cache = self.self_attn(
528
+ hidden_states=hidden_states,
529
+ attention_mask=attention_mask,
530
+ position_ids=position_ids,
531
+ past_key_value=past_key_value,
532
+ output_attentions=output_attentions,
533
+ use_cache=use_cache,
534
+ mem_cache=mem_cache,
535
+ )
536
+ hidden_states = residual + hidden_states
537
+
538
+ # Fully Connected
539
+ residual = hidden_states
540
+ hidden_states = self.post_attention_layernorm(hidden_states)
541
+ hidden_states = self.mlp(hidden_states)
542
+ hidden_states = residual + hidden_states
543
+
544
+ outputs = (hidden_states,)
545
+
546
+ if output_attentions:
547
+ outputs += (self_attn_weights,)
548
+
549
+ if use_cache:
550
+ outputs += (present_key_value,)
551
+
552
+ return outputs + (mem_cache,)
553
+
554
+
555
+ LONGLLAMA_START_DOCSTRING = r"""
556
+ This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
557
+ library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
558
+ etc.)
559
+
560
+ This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
561
+ Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
562
+ and behavior.
563
+
564
+ Parameters:
565
+ config ([`LongLlamaConfig`]):
566
+ Model configuration class with all the parameters of the model. Initializing with a config file does not
567
+ load the weights associated with the model, only the configuration. Check out the
568
+ [`~PreTrainedModel.from_pretrained`] method to load the model weights.
569
+ """
570
+ LONGLLAMA_MEML_DOCSTRING = r"""
571
+ mem_layers ([`int`], *optional*):
572
+ Indices of layers to be augmented with memory, if None then parameters from config will be used
573
+ mem_dtype (`str`, *optional*):
574
+ Keys and values will be casted to this type for storage.
575
+
576
+ """
577
+
578
+
579
+ @add_start_docstrings(
580
+ "The bare LongLLaMA Model outputting raw hidden-states without any specific head on top.",
581
+ LONGLLAMA_START_DOCSTRING,
582
+ )
583
+ # Copied from transformers.models.llama.modeling_llama.LlamaPreTrainedModel with Llama->LongLlama
584
+ class LongLlamaPreTrainedModel(PreTrainedModel):
585
+ config_class = LongLlamaConfig
586
+ base_model_prefix = "model"
587
+ supports_gradient_checkpointing = True
588
+ _no_split_modules = ["LongLlamaDecoderLayer"]
589
+ _skip_keys_device_placement = "past_key_values"
590
+ _keys_to_ignore_on_load_unexpected = [r"decoder\.version"]
591
+
592
+ def _init_weights(self, module):
593
+ std = self.config.initializer_range
594
+ if isinstance(module, nn.Linear):
595
+ module.weight.data.normal_(mean=0.0, std=std)
596
+ if module.bias is not None:
597
+ module.bias.data.zero_()
598
+ elif isinstance(module, nn.Embedding):
599
+ module.weight.data.normal_(mean=0.0, std=std)
600
+ if module.padding_idx is not None:
601
+ module.weight.data[module.padding_idx].zero_()
602
+
603
+ def _set_gradient_checkpointing(self, module, value=False):
604
+ if isinstance(module, LongLlamaModel):
605
+ module.gradient_checkpointing = value
606
+
607
+
608
+ LONGLLAMA_COMMON_INPUTS_DOCSTRING = r"""
609
+ Args:
610
+ input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
611
+ Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
612
+ it.
613
+
614
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
615
+ [`PreTrainedTokenizer.__call__`] for details.
616
+
617
+ [What are input IDs?](../glossary#input-ids)
618
+ attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
619
+ Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
620
+
621
+ - 1 for tokens that are **not masked**,
622
+ - 0 for tokens that are **masked**.
623
+
624
+ [What are attention masks?](../glossary#attention-mask)
625
+
626
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
627
+ [`PreTrainedTokenizer.__call__`] for details.
628
+
629
+ If `past_key_values` is used, optionally only the last `decoder_input_ids` have to be input (see
630
+ `past_key_values`).
631
+
632
+ If you want to change padding behavior, you should read [`modeling_opt._prepare_decoder_attention_mask`]
633
+ and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more
634
+ information on the default strategy.
635
+
636
+ - 1 indicates the head is **not masked**,
637
+ - 0 indicates the head is **masked**.
638
+ position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
639
+ Indices of positions of each input sequence tokens in the position embeddings.
640
+
641
+ [What are position IDs?](../glossary#position-ids)
642
+ past_key_values (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`
643
+ or memory cache is enabled):
644
+ Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of shape
645
+ `(batch_size, num_heads, sequence_length, embed_size_per_head)`) and 1 additional tensor of shape
646
+ `(batch_size, 1, sequence_length, 1)`. For memory enriched layers it also contains content of memory cache.
647
+ It is padded with empty tensors so when returned it alwyas has 6 elements.
648
+
649
+ Contains pre-computed hidden-states (key and values in the self-attention blocks)
650
+ that can be used (see `past_key_values` input) to speed up sequential decoding.
651
+
652
+ If `past_key_values` are used, the user can optionally input only the last `decoder_input_ids` (those that
653
+ don't have their past key value states given to this model) of shape `(batch_size, 1)` instead of all
654
+ `decoder_input_ids` of shape `(batch_size, sequence_length)`.
655
+ inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
656
+ Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
657
+ is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
658
+ model's internal embedding lookup matrix.
659
+ use_cache (`bool`, *optional*):
660
+ If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
661
+ `past_key_values`).
662
+ output_attentions (`bool`, *optional*):
663
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
664
+ tensors for more detail. This is NOT supported in LongLlamaForCausalLM and LongLlamaForSequenceClassification
665
+ due to the specific input processing.
666
+ output_hidden_states (`bool`, *optional*):
667
+ Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
668
+ more detail.
669
+ return_dict (`bool`, *optional*):
670
+ Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
671
+ """
672
+ LONGLLAMA_MODEL_INPUTS_DOCSTRING = r"""
673
+ mem_caches (`tuple(LongLlamaMemCache)`, *optional*)
674
+ Memory caches for specified layers, None for others
675
+ """
676
+
677
+ LONGLLAMA_ADD_INPUTS_DOCSTRING = r"""
678
+ last_context_length (`int`, *optional*)
679
+ Useful for generation, specifies number of tokens that won't be loaded to memory and
680
+ will be left for generation cache
681
+ """
682
+
683
+
684
+ def _prepare_pos_ids(past_key_values, batch_size, input_length, device):
685
+ if past_key_values is not None:
686
+ # take previous max pos_id + 1
687
+ if past_key_values[0][2].shape[0] != batch_size:
688
+ raise ValueError(
689
+ f"first dimension of past_key_values should match batch size: {batch_size}"
690
+ f"but got {past_key_values[0][2].shape[0]}"
691
+ )
692
+ next_pos = torch.max(past_key_values[0][2].view(batch_size, -1), dim=-1)[0] + 1
693
+ next_pos = next_pos.view(batch_size, 1)
694
+ else:
695
+ next_pos = torch.zeros(batch_size, 1, device=device, dtype=torch.long)
696
+
697
+ position_ids = torch.arange(0, input_length, dtype=torch.long, device=device).view(1, input_length)
698
+ position_ids = position_ids + next_pos
699
+ return position_ids
700
+
701
+
702
+ @add_start_docstrings(
703
+ "The bare LongLLaMA Model outputting raw hidden-states without any specific head on top.",
704
+ LONGLLAMA_START_DOCSTRING,
705
+ LONGLLAMA_MEML_DOCSTRING,
706
+ )
707
+ # Modified transformers.models.llama.modeling_llama.LlamaModel
708
+ class LongLlamaModel(LongLlamaPreTrainedModel):
709
+ """
710
+ Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`LongLlamaDecoderLayer`]
711
+
712
+ Args:
713
+ config: LlamaConfig
714
+ """
715
+
716
+ def __init__(self, config: LongLlamaConfig):
717
+ super().__init__(config)
718
+ self.mem_layers = config.mem_layers
719
+ self.mem_config = LongLlamaMemConfig(
720
+ positionals=config.mem_positionals,
721
+ cache_dtype=getattr(torch, config.mem_dtype),
722
+ attention_grouping=config.mem_attention_grouping,
723
+ )
724
+ self.padding_idx = config.pad_token_id
725
+ self.vocab_size = config.vocab_size
726
+
727
+ self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
728
+
729
+ for mem_layer_id in self.mem_layers:
730
+ if mem_layer_id < 0 or mem_layer_id >= config.num_hidden_layers:
731
+ raise ValueError(
732
+ f"Memory layer ids should be between 0 and {config.num_hidden_layers}, got {mem_layer_id}"
733
+ )
734
+
735
+ layers = []
736
+ for layer_id in range(config.num_hidden_layers):
737
+ if layer_id in self.mem_layers:
738
+ layer = LongLlamaDecoderLayer(config, mem_config=self.mem_config)
739
+ else:
740
+ layer = LongLlamaDecoderLayer(config, mem_config=None)
741
+ layers.append(layer)
742
+
743
+ self.layers = nn.ModuleList(layers)
744
+ self.norm = LongLlamaRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
745
+
746
+ self.gradient_checkpointing = False
747
+
748
+ # Initialize weights and apply final processing
749
+ self.post_init()
750
+
751
+ def get_input_embeddings(self):
752
+ return self.embed_tokens
753
+
754
+ def set_input_embeddings(self, value):
755
+ self.embed_tokens = value
756
+
757
+ # Copied from transformers.models.bart.modeling_bart.BartDecoder._prepare_decoder_attention_mask
758
+ def _prepare_decoder_attention_mask(self, attention_mask, input_shape, inputs_embeds, past_key_values_length):
759
+ # create causal mask
760
+ # [bsz, seq_len] -> [bsz, 1, tgt_seq_len, src_seq_len]
761
+ combined_attention_mask = None
762
+ if input_shape[-1] > 1:
763
+ combined_attention_mask = _make_causal_mask(
764
+ input_shape,
765
+ inputs_embeds.dtype,
766
+ device=inputs_embeds.device,
767
+ past_key_values_length=past_key_values_length,
768
+ )
769
+
770
+ if attention_mask is not None:
771
+ # [bsz, seq_len] -> [bsz, 1, tgt_seq_len, src_seq_len]
772
+ expanded_attn_mask = _expand_mask(attention_mask, inputs_embeds.dtype, tgt_len=input_shape[-1]).to(
773
+ inputs_embeds.device
774
+ )
775
+ combined_attention_mask = (
776
+ expanded_attn_mask if combined_attention_mask is None else expanded_attn_mask + combined_attention_mask
777
+ )
778
+
779
+ return combined_attention_mask
780
+
781
+ @add_start_docstrings_to_model_forward(LONGLLAMA_COMMON_INPUTS_DOCSTRING, LONGLLAMA_MODEL_INPUTS_DOCSTRING)
782
+ def forward(
783
+ self,
784
+ input_ids: torch.LongTensor = None,
785
+ attention_mask: Optional[torch.Tensor] = None,
786
+ position_ids: Optional[torch.LongTensor] = None,
787
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
788
+ inputs_embeds: Optional[torch.FloatTensor] = None,
789
+ use_cache: Optional[bool] = None,
790
+ output_attentions: Optional[bool] = None,
791
+ output_hidden_states: Optional[bool] = None,
792
+ return_dict: Optional[bool] = None,
793
+ mem_caches: Optional[Tuple[Optional[LongLlamaMemCache]]] = None,
794
+ ) -> Union[Tuple, LongLlamaModelOutputWithPast]:
795
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
796
+ output_hidden_states = (
797
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
798
+ )
799
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
800
+
801
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
802
+
803
+ # retrieve input_ids and inputs_embeds
804
+ if input_ids is not None and inputs_embeds is not None:
805
+ raise ValueError("You cannot specify both decoder_input_ids and decoder_inputs_embeds at the same time")
806
+ elif input_ids is not None:
807
+ batch_size, seq_length = input_ids.shape
808
+ elif inputs_embeds is not None:
809
+ batch_size, seq_length, _ = inputs_embeds.shape
810
+ else:
811
+ raise ValueError("You have to specify either decoder_input_ids or decoder_inputs_embeds")
812
+
813
+ seq_length_with_past = seq_length
814
+ past_key_values_length = 0
815
+
816
+ if past_key_values is not None:
817
+ past_key_values_length = past_key_values[0][0].shape[-2]
818
+ seq_length_with_past = seq_length_with_past + past_key_values_length
819
+
820
+ if position_ids is None:
821
+ device = input_ids.device if input_ids is not None else inputs_embeds.device
822
+ position_ids = _prepare_pos_ids(past_key_values, batch_size, seq_length, device)
823
+ else:
824
+ position_ids = position_ids.view(-1, seq_length).long()
825
+
826
+ if inputs_embeds is None:
827
+ inputs_embeds = self.embed_tokens(input_ids)
828
+ # embed positions
829
+ if attention_mask is None:
830
+ attention_mask = torch.ones(
831
+ (batch_size, seq_length_with_past), dtype=torch.bool, device=inputs_embeds.device
832
+ )
833
+ attention_mask = self._prepare_decoder_attention_mask(
834
+ attention_mask, (batch_size, seq_length), inputs_embeds, past_key_values_length
835
+ )
836
+
837
+ hidden_states = inputs_embeds
838
+
839
+ if self.gradient_checkpointing and self.training:
840
+ if use_cache:
841
+ logger.warning_once(
842
+ "`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..."
843
+ )
844
+ use_cache = False
845
+
846
+ # decoder layers
847
+ all_hidden_states = () if output_hidden_states else None
848
+ all_self_attns = () if output_attentions else None
849
+ next_decoder_cache = ()
850
+ next_mem_caches = ()
851
+ for idx, decoder_layer in enumerate(self.layers):
852
+ if output_hidden_states:
853
+ all_hidden_states += (hidden_states,)
854
+
855
+ past_key_value = past_key_values[idx] if past_key_values is not None else None
856
+ mem_cache = mem_caches[idx] if mem_caches else None
857
+
858
+ if mem_cache is not None and idx not in self.mem_layers:
859
+ raise ValueError("Memory cache provided for a non-memory leayer")
860
+
861
+ if (
862
+ self.gradient_checkpointing
863
+ and self.training
864
+ and mem_cache is None
865
+ and idx % self.config.gradient_checkpoint_every_ith == 0
866
+ ):
867
+
868
+ def create_custom_forward(module):
869
+ def custom_forward(*inputs):
870
+ # None for past_key_value
871
+ return module(*inputs, output_attentions, None, mem_cache=None)
872
+
873
+ return custom_forward
874
+
875
+ layer_outputs = torch.utils.checkpoint.checkpoint(
876
+ create_custom_forward(decoder_layer),
877
+ hidden_states,
878
+ attention_mask,
879
+ position_ids,
880
+ None,
881
+ )
882
+ else:
883
+ layer_outputs = decoder_layer(
884
+ hidden_states,
885
+ attention_mask=attention_mask,
886
+ position_ids=position_ids,
887
+ past_key_value=past_key_value,
888
+ output_attentions=output_attentions,
889
+ use_cache=use_cache,
890
+ mem_cache=mem_cache,
891
+ )
892
+
893
+ new_mem_cache = layer_outputs[-1]
894
+ layer_outputs = layer_outputs[:-1]
895
+ next_mem_caches += (new_mem_cache,)
896
+
897
+ hidden_states = layer_outputs[0]
898
+
899
+ if use_cache:
900
+ next_decoder_cache += (layer_outputs[2 if output_attentions else 1],)
901
+ else:
902
+ next_decoder_cache += (None,)
903
+
904
+ if output_attentions:
905
+ all_self_attns += (layer_outputs[1],)
906
+
907
+ hidden_states = self.norm(hidden_states)
908
+
909
+ # add hidden states from the last decoder layer
910
+ if output_hidden_states:
911
+ all_hidden_states += (hidden_states,)
912
+
913
+ next_cache = next_decoder_cache if use_cache else None
914
+
915
+ mem_cache_returned = False
916
+ for mem_cache in next_mem_caches:
917
+ if mem_cache is not None:
918
+ mem_cache_returned = True
919
+ next_mem_caches = next_mem_caches if mem_cache_returned else None
920
+
921
+ if not return_dict:
922
+ return tuple(
923
+ v
924
+ for v in [hidden_states, next_cache, all_hidden_states, all_self_attns, next_mem_caches]
925
+ if v is not None
926
+ )
927
+ return LongLlamaModelOutputWithPast(
928
+ last_hidden_state=hidden_states,
929
+ past_key_values=next_cache,
930
+ hidden_states=all_hidden_states,
931
+ attentions=all_self_attns,
932
+ mem_caches=next_mem_caches,
933
+ )
934
+
935
+
936
+ def _handle_output_of_past_key_values(outputs):
937
+ # merges local caches and memory caches into one single tuple of past_key_values
938
+ # in order to support generation
939
+ batch_size = outputs.last_hidden_state.shape[0]
940
+ if outputs.past_key_values is None and outputs.mem_caches is None:
941
+ return None
942
+
943
+ if outputs.past_key_values is None:
944
+ out_past_key_values = (None,) * len(outputs.mem_caches)
945
+ else:
946
+ out_past_key_values = outputs.past_key_values
947
+
948
+ if outputs.mem_caches is None:
949
+ out_mem_caches = (None,) * len(outputs.past_key_values)
950
+ else:
951
+ out_mem_caches = outputs.mem_caches
952
+
953
+ device = outputs.last_hidden_state.device
954
+ past_key_values = ()
955
+ for local_cache, mem_cache in zip(out_past_key_values, out_mem_caches):
956
+ layer = ()
957
+ if local_cache is not None:
958
+ assert len(local_cache) == 3
959
+ layer += local_cache
960
+ else:
961
+ layer += (torch.empty(batch_size, 0, 0, 0, device=device),) * 3
962
+
963
+ if mem_cache is not None:
964
+ layer += (mem_cache.keys, mem_cache.values, mem_cache.masks)
965
+ else:
966
+ layer += (torch.empty(batch_size, 0, 0, 0, device=device),) * 3
967
+
968
+ assert len(layer) == 6
969
+
970
+ past_key_values += (layer,)
971
+
972
+ return past_key_values
973
+
974
+
975
+ def _split_past_key_values(past_key_values):
976
+ # splits past_key_values to local cache and memory cache
977
+ local_cache_preset = False
978
+ mem_caches_present = False
979
+ if past_key_values is not None:
980
+ local_caches = ()
981
+ mem_caches = ()
982
+ for layer in past_key_values:
983
+ if len(layer) != 6:
984
+ raise ValueError(
985
+ "Expected elements of past_key_values to contain 6 elements."
986
+ "First 3 describing local cache and last 3 describing memory cache."
987
+ f"Instead got {len(layer)} elements"
988
+ )
989
+ else:
990
+ lk, lv, li, memk, memv, memm = layer
991
+ if lk.shape[-2] != 0:
992
+ local_cache_preset = True
993
+ local_caches += ((lk, lv, li),)
994
+ else:
995
+ local_caches += (None,)
996
+
997
+ if memk.shape[-2] != 0:
998
+ mem_caches_present = True
999
+ mem_caches += (LongLlamaMemCache(keys=memk, values=memv, masks=memm),)
1000
+ else:
1001
+ mem_caches += (None,)
1002
+
1003
+ local_caches = local_caches if local_cache_preset else None
1004
+ mem_caches = mem_caches if mem_caches_present else None
1005
+
1006
+ return local_caches, mem_caches
1007
+
1008
+
1009
+ def _handle_long_input(
1010
+ model,
1011
+ input_ids,
1012
+ attention_mask,
1013
+ position_ids,
1014
+ past_key_values,
1015
+ inputs_embeds,
1016
+ use_cache,
1017
+ output_attentions,
1018
+ output_hidden_states,
1019
+ return_dict,
1020
+ context_window_length,
1021
+ last_context_length,
1022
+ ):
1023
+ if output_attentions:
1024
+ logger.warning(
1025
+ f"Outputing attentions is not supported in LongLlamaForCausalLM and LongLlamaForSequenceClassification. "
1026
+ f"Attention of the last window will be returned"
1027
+ )
1028
+
1029
+ past_key_values, mem_caches = _split_past_key_values(past_key_values)
1030
+
1031
+ if past_key_values is not None and use_cache is False:
1032
+ raise ValueError("past_key_values it not None should imply use_cache == True")
1033
+
1034
+ if past_key_values is not None:
1035
+ initial_past_key_values_length = past_key_values[0][0].shape[-2]
1036
+ else:
1037
+ initial_past_key_values_length = 0
1038
+
1039
+ if input_ids is not None:
1040
+ batch_size, input_length = input_ids.shape
1041
+ else:
1042
+ batch_size, input_length, _ = inputs_embeds.shape
1043
+
1044
+ if position_ids is None:
1045
+ device = input_ids.device if input_ids is not None else inputs_embeds.device
1046
+ position_ids = _prepare_pos_ids(past_key_values, batch_size, input_length, device)
1047
+
1048
+ if position_ids.shape != (batch_size, input_length):
1049
+ raise ValueError(f"Shape of position_ids [{position_ids}] should match [{batch_size, input_length}]")
1050
+
1051
+ if attention_mask is not None:
1052
+ attention_mask = attention_mask[..., -(initial_past_key_values_length + input_length) :]
1053
+ if attention_mask is not None and (
1054
+ attention_mask.shape != (batch_size, initial_past_key_values_length + input_length)
1055
+ ):
1056
+ raise ValueError(
1057
+ "Attention mask should be provided for both the local cache and the input",
1058
+ f"Expected shape {(batch_size, initial_past_key_values_length + input_length)},"
1059
+ f"got {attention_mask.shape}.",
1060
+ )
1061
+
1062
+ # First we load prefix to memory cache
1063
+ mem_input_length = max(input_length - last_context_length, 0)
1064
+ outputs_list = []
1065
+ attn_offset = initial_past_key_values_length
1066
+ if mem_input_length > 0:
1067
+ for i in range(0, mem_input_length, context_window_length):
1068
+ beg, end = i, min(mem_input_length, i + context_window_length)
1069
+
1070
+ if attention_mask is not None:
1071
+ if past_key_values is not None:
1072
+ local_cache_size = past_key_values[0][0].shape[-2]
1073
+ else:
1074
+ local_cache_size = 0
1075
+ attn_length = attention_mask.shape[-1]
1076
+ attn_beg = beg + attn_offset - local_cache_size
1077
+ attn_end = end + attn_offset
1078
+ assert attn_end <= attn_length
1079
+ assert attn_beg >= 0 and attn_end > attn_beg
1080
+
1081
+ # decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn, mem_caches)
1082
+ outputs = model(
1083
+ input_ids=input_ids[..., beg:end] if input_ids is not None else None,
1084
+ attention_mask=attention_mask[..., attn_beg:attn_end] if attention_mask is not None else None,
1085
+ position_ids=position_ids[..., beg:end],
1086
+ past_key_values=past_key_values,
1087
+ inputs_embeds=inputs_embeds[..., beg:end, :] if inputs_embeds is not None else None,
1088
+ use_cache=False if past_key_values is None else use_cache,
1089
+ output_attentions=output_attentions,
1090
+ output_hidden_states=output_hidden_states,
1091
+ return_dict=True,
1092
+ mem_caches=mem_caches,
1093
+ )
1094
+ if i > 0:
1095
+ if mem_caches is not None and past_key_values is None:
1096
+ for mc_layer in mem_caches:
1097
+ if mc_layer is not None:
1098
+ del mc_layer.keys
1099
+ del mc_layer.values
1100
+ del mc_layer.masks
1101
+
1102
+ mem_caches = outputs.mem_caches
1103
+ outputs.mem_caches = None
1104
+ past_key_values = outputs.past_key_values
1105
+ outputs.past_key_values = None
1106
+ outputs_list.append(outputs)
1107
+
1108
+ remaining_input_length = input_length - mem_input_length
1109
+ beg = mem_input_length
1110
+ attn_length = remaining_input_length
1111
+ if past_key_values is not None:
1112
+ attn_length += past_key_values[0][0].shape[-2]
1113
+ attention_mask = attention_mask[..., -attn_length:] if attention_mask is not None else None
1114
+
1115
+ outputs = model(
1116
+ input_ids=input_ids[..., beg:] if input_ids is not None else None,
1117
+ attention_mask=attention_mask,
1118
+ position_ids=position_ids[..., beg:],
1119
+ past_key_values=past_key_values,
1120
+ inputs_embeds=inputs_embeds[..., beg:, :] if inputs_embeds is not None else None,
1121
+ use_cache=use_cache,
1122
+ output_attentions=output_attentions,
1123
+ output_hidden_states=output_hidden_states,
1124
+ return_dict=True,
1125
+ mem_caches=mem_caches,
1126
+ )
1127
+
1128
+ outputs_list.append(outputs)
1129
+
1130
+ past_key_values = _handle_output_of_past_key_values(outputs_list[-1])
1131
+
1132
+ if output_hidden_states:
1133
+ hidden_states = ()
1134
+ for hd in zip(*[x.hidden_states for x in outputs_list]):
1135
+ hidden_states += (torch.cat(hd, dim=-2),)
1136
+ else:
1137
+ hidden_states = None
1138
+
1139
+ outputs = BaseModelOutputWithPast(
1140
+ last_hidden_state=torch.concat([x.last_hidden_state for x in outputs_list], dim=-2),
1141
+ past_key_values=past_key_values,
1142
+ hidden_states=hidden_states,
1143
+ attentions=outputs_list[-1].attentions,
1144
+ )
1145
+
1146
+ if not return_dict:
1147
+ outputs = tuple(
1148
+ v
1149
+ for v in [outputs.last_hidden_state, outputs.past_key_values, outputs.hidden_states, outputs.attentions]
1150
+ if v is not None
1151
+ )
1152
+ return outputs
1153
+
1154
+
1155
+ # Modified transformers.models.llama.modeling_llama.LlamaForCausalLM
1156
+ class LongLlamaForCausalLM(LongLlamaPreTrainedModel):
1157
+ _tied_weights_keys = ["lm_head.weight"]
1158
+
1159
+ def __init__(self, config):
1160
+ super().__init__(config)
1161
+ self.context_window_length = config.max_position_embeddings
1162
+
1163
+ self.model = LongLlamaModel(config)
1164
+
1165
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
1166
+
1167
+ # Initialize weights and apply final processing
1168
+ self.post_init()
1169
+
1170
+ def get_input_embeddings(self):
1171
+ return self.model.embed_tokens
1172
+
1173
+ def set_input_embeddings(self, value):
1174
+ self.model.embed_tokens = value
1175
+
1176
+ def get_output_embeddings(self):
1177
+ return self.lm_head
1178
+
1179
+ def set_output_embeddings(self, new_embeddings):
1180
+ self.lm_head = new_embeddings
1181
+
1182
+ def set_decoder(self, decoder):
1183
+ self.model = decoder
1184
+
1185
+ def get_decoder(self):
1186
+ return self.model
1187
+
1188
+ def _has_generation_cache(self, past_key_values):
1189
+ if past_key_values is not None:
1190
+ assert len(past_key_values[0]) == 6
1191
+ return past_key_values[0][0].shape[-2] != 0
1192
+
1193
+ return False
1194
+
1195
+ @add_start_docstrings_to_model_forward(LONGLLAMA_COMMON_INPUTS_DOCSTRING, LONGLLAMA_ADD_INPUTS_DOCSTRING)
1196
+ @replace_return_docstrings(output_type=CausalLMOutputWithPast, config_class=_CONFIG_FOR_DOC)
1197
+ def forward(
1198
+ self,
1199
+ input_ids: torch.LongTensor = None,
1200
+ attention_mask: Optional[torch.Tensor] = None,
1201
+ position_ids: Optional[torch.LongTensor] = None,
1202
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
1203
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1204
+ labels: Optional[torch.LongTensor] = None,
1205
+ use_cache: Optional[bool] = None,
1206
+ output_attentions: Optional[bool] = None,
1207
+ output_hidden_states: Optional[bool] = None,
1208
+ return_dict: Optional[bool] = None,
1209
+ last_context_length: Optional[int] = None,
1210
+ ) -> Union[Tuple, CausalLMOutputWithPast]:
1211
+ r"""
1212
+ Args:
1213
+ labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
1214
+ Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
1215
+ config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
1216
+ (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
1217
+
1218
+ Returns:
1219
+
1220
+ Example:
1221
+
1222
+ ```python
1223
+ >>> from transformers import AutoTokenizer, LlamaForCausalLM
1224
+
1225
+ >>> model = LlamaForCausalLM.from_pretrained(PATH_TO_CONVERTED_WEIGHTS)
1226
+ >>> tokenizer = AutoTokenizer.from_pretrained(PATH_TO_CONVERTED_TOKENIZER)
1227
+
1228
+ >>> prompt = "Hey, are you conscious? Can you talk to me?"
1229
+ >>> inputs = tokenizer(prompt, return_tensors="pt")
1230
+
1231
+ >>> # Generate
1232
+ >>> generate_ids = model.generate(inputs.input_ids, max_length=30)
1233
+ >>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
1234
+ "Hey, are you conscious? Can you talk to me?\nI'm not conscious, but I can talk to you."
1235
+ ```"""
1236
+ last_context_length = (
1237
+ last_context_length if last_context_length is not None else self.config.last_context_length
1238
+ )
1239
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
1240
+ output_hidden_states = (
1241
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
1242
+ )
1243
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
1244
+
1245
+ outputs = _handle_long_input(
1246
+ model=self.model,
1247
+ input_ids=input_ids,
1248
+ attention_mask=attention_mask,
1249
+ position_ids=position_ids,
1250
+ past_key_values=past_key_values,
1251
+ inputs_embeds=inputs_embeds,
1252
+ use_cache=use_cache,
1253
+ output_attentions=output_attentions,
1254
+ output_hidden_states=output_hidden_states,
1255
+ return_dict=return_dict,
1256
+ context_window_length=self.context_window_length,
1257
+ last_context_length=last_context_length,
1258
+ )
1259
+
1260
+ hidden_states = outputs[0]
1261
+ logits = self.lm_head(hidden_states)
1262
+
1263
+ loss = None
1264
+ if labels is not None:
1265
+ # Shift so that tokens < n predict n
1266
+ shift_logits = logits[..., :-1, :].contiguous()
1267
+ shift_labels = labels[..., 1:].contiguous()
1268
+ # Flatten the tokens
1269
+ loss_fct = CrossEntropyLoss()
1270
+ shift_logits = shift_logits.view(-1, self.config.vocab_size)
1271
+ shift_labels = shift_labels.view(-1)
1272
+ # Enable model parallelism
1273
+ shift_labels = shift_labels.to(shift_logits.device)
1274
+ loss = loss_fct(shift_logits, shift_labels)
1275
+
1276
+ if not return_dict:
1277
+ output = (logits,) + outputs[1:]
1278
+ return (loss,) + output if loss is not None else output
1279
+
1280
+ return CausalLMOutputWithPast(
1281
+ loss=loss,
1282
+ logits=logits,
1283
+ past_key_values=outputs.past_key_values,
1284
+ hidden_states=outputs.hidden_states,
1285
+ attentions=outputs.attentions,
1286
+ )
1287
+
1288
+ def prepare_inputs_for_generation(
1289
+ self,
1290
+ input_ids,
1291
+ past_key_values=None,
1292
+ attention_mask=None,
1293
+ inputs_embeds=None,
1294
+ last_context_length=None,
1295
+ **kwargs,
1296
+ ):
1297
+ if self._has_generation_cache(past_key_values):
1298
+ input_ids = input_ids[:, -1:]
1299
+
1300
+ position_ids = kwargs.get("position_ids", None)
1301
+ if attention_mask is not None and position_ids is None:
1302
+ # create position_ids on the fly for batch generation
1303
+ position_ids = attention_mask.long().cumsum(-1) - 1
1304
+ position_ids.masked_fill(position_ids < 0, 0)
1305
+ if self._has_generation_cache(past_key_values):
1306
+ position_ids = position_ids[:, -1].unsqueeze(-1)
1307
+
1308
+ # if `inputs_embeds` are passed, we only want to use them in the 1st generation step
1309
+ if inputs_embeds is not None and past_key_values is None:
1310
+ model_inputs = {"inputs_embeds": inputs_embeds}
1311
+ else:
1312
+ model_inputs = {"input_ids": input_ids}
1313
+
1314
+ model_inputs.update(
1315
+ {
1316
+ "position_ids": position_ids,
1317
+ "past_key_values": past_key_values,
1318
+ "use_cache": kwargs.get("use_cache"),
1319
+ "attention_mask": attention_mask,
1320
+ "last_context_length": last_context_length,
1321
+ }
1322
+ )
1323
+ return model_inputs
1324
+
1325
+ @staticmethod
1326
+ def _reorder_cache(past_key_values, beam_idx):
1327
+ reordered_past = ()
1328
+ for layer_past in past_key_values:
1329
+ reordered_past += (
1330
+ tuple(past_state.index_select(0, beam_idx.to(past_state.device)) for past_state in layer_past),
1331
+ )
1332
+ return reordered_past
1333
+
1334
+
1335
+ @add_start_docstrings(
1336
+ """
1337
+ The LongLLaMA Model transformer with a sequence classification head on top (linear layer).
1338
+
1339
+ [`LongLlamaForSequenceClassification`] uses the last token in order to do the classification, as other causal models
1340
+ (e.g. GPT-2) do.
1341
+
1342
+ Since it does classification on the last token, it requires to know the position of the last token. If a
1343
+ `pad_token_id` is defined in the configuration, it finds the last token that is not a padding token in each row. If
1344
+ no `pad_token_id` is defined, it simply takes the last value in each row of the batch. Since it cannot guess the
1345
+ padding tokens when `inputs_embeds` are passed instead of `input_ids`, it does the same (take the last value in
1346
+ each row of the batch).
1347
+ """,
1348
+ LONGLLAMA_START_DOCSTRING,
1349
+ LONGLLAMA_MEML_DOCSTRING,
1350
+ )
1351
+ # Modified from transformers.models.llama.modeling_llama.LlamaForSequenceClassification
1352
+ class LongLlamaForSequenceClassification(LongLlamaPreTrainedModel):
1353
+ _keys_to_ignore_on_load_missing = [r"lm_head.weight"]
1354
+
1355
+ def __init__(self, config):
1356
+ super().__init__(config)
1357
+ self.num_labels = config.num_labels
1358
+ self.context_window_length = config.max_position_embeddings
1359
+ self.model = LongLlamaModel(config)
1360
+ self.score = nn.Linear(config.hidden_size, self.num_labels, bias=False)
1361
+
1362
+ # Initialize weights and apply final processing
1363
+ self.post_init()
1364
+
1365
+ def get_input_embeddings(self):
1366
+ return self.model.embed_tokens
1367
+
1368
+ def set_input_embeddings(self, value):
1369
+ self.model.embed_tokens = value
1370
+
1371
+ @add_start_docstrings_to_model_forward(LONGLLAMA_COMMON_INPUTS_DOCSTRING, LONGLLAMA_ADD_INPUTS_DOCSTRING)
1372
+ def forward(
1373
+ self,
1374
+ input_ids: torch.LongTensor = None,
1375
+ attention_mask: Optional[torch.Tensor] = None,
1376
+ position_ids: Optional[torch.LongTensor] = None,
1377
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
1378
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1379
+ labels: Optional[torch.LongTensor] = None,
1380
+ use_cache: Optional[bool] = None,
1381
+ output_attentions: Optional[bool] = None,
1382
+ output_hidden_states: Optional[bool] = None,
1383
+ return_dict: Optional[bool] = None,
1384
+ last_context_length: Optional[int] = None,
1385
+ ) -> Union[Tuple, SequenceClassifierOutputWithPast]:
1386
+ r"""
1387
+ labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
1388
+ Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
1389
+ config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
1390
+ `config.num_labels > 1` a classification loss is computed (Cross-Entropy).
1391
+ """
1392
+ last_context_length = (
1393
+ last_context_length if last_context_length is not None else self.config.last_context_length
1394
+ )
1395
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
1396
+ output_hidden_states = (
1397
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
1398
+ )
1399
+ transformer_outputs = _handle_long_input(
1400
+ model=self.model,
1401
+ input_ids=input_ids,
1402
+ attention_mask=attention_mask,
1403
+ position_ids=position_ids,
1404
+ past_key_values=past_key_values,
1405
+ inputs_embeds=inputs_embeds,
1406
+ use_cache=use_cache,
1407
+ output_attentions=output_attentions,
1408
+ output_hidden_states=output_hidden_states,
1409
+ return_dict=return_dict,
1410
+ context_window_length=self.context_window_length,
1411
+ last_context_length=last_context_length,
1412
+ )
1413
+
1414
+ hidden_states = transformer_outputs[0]
1415
+ logits = self.score(hidden_states)
1416
+
1417
+ if input_ids is not None:
1418
+ batch_size = input_ids.shape[0]
1419
+ else:
1420
+ batch_size = inputs_embeds.shape[0]
1421
+
1422
+ if self.config.pad_token_id is None and batch_size != 1:
1423
+ raise ValueError("Cannot handle batch sizes > 1 if no padding token is defined.")
1424
+ if self.config.pad_token_id is None:
1425
+ sequence_lengths = -1
1426
+ else:
1427
+ if input_ids is not None:
1428
+ sequence_lengths = (torch.ne(input_ids, self.config.pad_token_id).sum(-1) - 1).to(logits.device)
1429
+ else:
1430
+ sequence_lengths = -1
1431
+
1432
+ pooled_logits = logits[torch.arange(batch_size, device=logits.device), sequence_lengths]
1433
+
1434
+ loss = None
1435
+ if labels is not None:
1436
+ labels = labels.to(logits.device)
1437
+ if self.config.problem_type is None:
1438
+ if self.num_labels == 1:
1439
+ self.config.problem_type = "regression"
1440
+ elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
1441
+ self.config.problem_type = "single_label_classification"
1442
+ else:
1443
+ self.config.problem_type = "multi_label_classification"
1444
+
1445
+ if self.config.problem_type == "regression":
1446
+ loss_fct = MSELoss()
1447
+ if self.num_labels == 1:
1448
+ loss = loss_fct(pooled_logits.squeeze(), labels.squeeze())
1449
+ else:
1450
+ loss = loss_fct(pooled_logits, labels)
1451
+ elif self.config.problem_type == "single_label_classification":
1452
+ loss_fct = CrossEntropyLoss()
1453
+ loss = loss_fct(pooled_logits.view(-1, self.num_labels), labels.view(-1))
1454
+ elif self.config.problem_type == "multi_label_classification":
1455
+ loss_fct = BCEWithLogitsLoss()
1456
+ loss = loss_fct(pooled_logits, labels)
1457
+ if not return_dict:
1458
+ output = (pooled_logits,) + transformer_outputs[1:]
1459
+ return ((loss,) + output) if loss is not None else output
1460
+
1461
+ return SequenceClassifierOutputWithPast(
1462
+ loss=loss,
1463
+ logits=pooled_logits,
1464
+ past_key_values=transformer_outputs.past_key_values,
1465
+ hidden_states=transformer_outputs.hidden_states,
1466
+ attentions=transformer_outputs.attentions,
1467
+ )
pytorch_model-00001-of-00002.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:28f9c0c5432334c20fe2be8bdaa14f2562282d1f9c2e9e015b40e3de02e8c8d3
3
+ size 9976746467
pytorch_model-00002-of-00002.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:afc8f1704a67881fb1555bc9fd28d66f6e329beea2d33bda61f42ed6a4373579
3
+ size 3500439559
pytorch_model.bin.index.json ADDED
@@ -0,0 +1,298 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 13477093376
4
+ },
5
+ "weight_map": {
6
+ "lm_head.weight": "pytorch_model-00002-of-00002.bin",
7
+ "model.embed_tokens.weight": "pytorch_model-00001-of-00002.bin",
8
+ "model.layers.0.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
9
+ "model.layers.0.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
10
+ "model.layers.0.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
11
+ "model.layers.0.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
12
+ "model.layers.0.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
13
+ "model.layers.0.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
14
+ "model.layers.0.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
15
+ "model.layers.0.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
16
+ "model.layers.0.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
17
+ "model.layers.1.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
18
+ "model.layers.1.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
19
+ "model.layers.1.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
20
+ "model.layers.1.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
21
+ "model.layers.1.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
22
+ "model.layers.1.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
23
+ "model.layers.1.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
24
+ "model.layers.1.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
25
+ "model.layers.1.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
26
+ "model.layers.10.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
27
+ "model.layers.10.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
28
+ "model.layers.10.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
29
+ "model.layers.10.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
30
+ "model.layers.10.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
31
+ "model.layers.10.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
32
+ "model.layers.10.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
33
+ "model.layers.10.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
34
+ "model.layers.10.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
35
+ "model.layers.11.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
36
+ "model.layers.11.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
37
+ "model.layers.11.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
38
+ "model.layers.11.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
39
+ "model.layers.11.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
40
+ "model.layers.11.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
41
+ "model.layers.11.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
42
+ "model.layers.11.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
43
+ "model.layers.11.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
44
+ "model.layers.12.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
45
+ "model.layers.12.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
46
+ "model.layers.12.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
47
+ "model.layers.12.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
48
+ "model.layers.12.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
49
+ "model.layers.12.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
50
+ "model.layers.12.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
51
+ "model.layers.12.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
52
+ "model.layers.12.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
53
+ "model.layers.13.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
54
+ "model.layers.13.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
55
+ "model.layers.13.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
56
+ "model.layers.13.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
57
+ "model.layers.13.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
58
+ "model.layers.13.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
59
+ "model.layers.13.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
60
+ "model.layers.13.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
61
+ "model.layers.13.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
62
+ "model.layers.14.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
63
+ "model.layers.14.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
64
+ "model.layers.14.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
65
+ "model.layers.14.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
66
+ "model.layers.14.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
67
+ "model.layers.14.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
68
+ "model.layers.14.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
69
+ "model.layers.14.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
70
+ "model.layers.14.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
71
+ "model.layers.15.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
72
+ "model.layers.15.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
73
+ "model.layers.15.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
74
+ "model.layers.15.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
75
+ "model.layers.15.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
76
+ "model.layers.15.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
77
+ "model.layers.15.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
78
+ "model.layers.15.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
79
+ "model.layers.15.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
80
+ "model.layers.16.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
81
+ "model.layers.16.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
82
+ "model.layers.16.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
83
+ "model.layers.16.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
84
+ "model.layers.16.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
85
+ "model.layers.16.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
86
+ "model.layers.16.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
87
+ "model.layers.16.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
88
+ "model.layers.16.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
89
+ "model.layers.17.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
90
+ "model.layers.17.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
91
+ "model.layers.17.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
92
+ "model.layers.17.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
93
+ "model.layers.17.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
94
+ "model.layers.17.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
95
+ "model.layers.17.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
96
+ "model.layers.17.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
97
+ "model.layers.17.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
98
+ "model.layers.18.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
99
+ "model.layers.18.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
100
+ "model.layers.18.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
101
+ "model.layers.18.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
102
+ "model.layers.18.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
103
+ "model.layers.18.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
104
+ "model.layers.18.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
105
+ "model.layers.18.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
106
+ "model.layers.18.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
107
+ "model.layers.19.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
108
+ "model.layers.19.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
109
+ "model.layers.19.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
110
+ "model.layers.19.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
111
+ "model.layers.19.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
112
+ "model.layers.19.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
113
+ "model.layers.19.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
114
+ "model.layers.19.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
115
+ "model.layers.19.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
116
+ "model.layers.2.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
117
+ "model.layers.2.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
118
+ "model.layers.2.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
119
+ "model.layers.2.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
120
+ "model.layers.2.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
121
+ "model.layers.2.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
122
+ "model.layers.2.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
123
+ "model.layers.2.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
124
+ "model.layers.2.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
125
+ "model.layers.20.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
126
+ "model.layers.20.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
127
+ "model.layers.20.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
128
+ "model.layers.20.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
129
+ "model.layers.20.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
130
+ "model.layers.20.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
131
+ "model.layers.20.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
132
+ "model.layers.20.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
133
+ "model.layers.20.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
134
+ "model.layers.21.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
135
+ "model.layers.21.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
136
+ "model.layers.21.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
137
+ "model.layers.21.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
138
+ "model.layers.21.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
139
+ "model.layers.21.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
140
+ "model.layers.21.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
141
+ "model.layers.21.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
142
+ "model.layers.21.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
143
+ "model.layers.22.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
144
+ "model.layers.22.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
145
+ "model.layers.22.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
146
+ "model.layers.22.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
147
+ "model.layers.22.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
148
+ "model.layers.22.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
149
+ "model.layers.22.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
150
+ "model.layers.22.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
151
+ "model.layers.22.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
152
+ "model.layers.23.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
153
+ "model.layers.23.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
154
+ "model.layers.23.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
155
+ "model.layers.23.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
156
+ "model.layers.23.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
157
+ "model.layers.23.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
158
+ "model.layers.23.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
159
+ "model.layers.23.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
160
+ "model.layers.23.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
161
+ "model.layers.24.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
162
+ "model.layers.24.mlp.down_proj.weight": "pytorch_model-00002-of-00002.bin",
163
+ "model.layers.24.mlp.gate_proj.weight": "pytorch_model-00002-of-00002.bin",
164
+ "model.layers.24.mlp.up_proj.weight": "pytorch_model-00002-of-00002.bin",
165
+ "model.layers.24.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
166
+ "model.layers.24.self_attn.k_proj.weight": "pytorch_model-00002-of-00002.bin",
167
+ "model.layers.24.self_attn.o_proj.weight": "pytorch_model-00002-of-00002.bin",
168
+ "model.layers.24.self_attn.q_proj.weight": "pytorch_model-00002-of-00002.bin",
169
+ "model.layers.24.self_attn.v_proj.weight": "pytorch_model-00002-of-00002.bin",
170
+ "model.layers.25.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
171
+ "model.layers.25.mlp.down_proj.weight": "pytorch_model-00002-of-00002.bin",
172
+ "model.layers.25.mlp.gate_proj.weight": "pytorch_model-00002-of-00002.bin",
173
+ "model.layers.25.mlp.up_proj.weight": "pytorch_model-00002-of-00002.bin",
174
+ "model.layers.25.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
175
+ "model.layers.25.self_attn.k_proj.weight": "pytorch_model-00002-of-00002.bin",
176
+ "model.layers.25.self_attn.o_proj.weight": "pytorch_model-00002-of-00002.bin",
177
+ "model.layers.25.self_attn.q_proj.weight": "pytorch_model-00002-of-00002.bin",
178
+ "model.layers.25.self_attn.v_proj.weight": "pytorch_model-00002-of-00002.bin",
179
+ "model.layers.26.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
180
+ "model.layers.26.mlp.down_proj.weight": "pytorch_model-00002-of-00002.bin",
181
+ "model.layers.26.mlp.gate_proj.weight": "pytorch_model-00002-of-00002.bin",
182
+ "model.layers.26.mlp.up_proj.weight": "pytorch_model-00002-of-00002.bin",
183
+ "model.layers.26.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
184
+ "model.layers.26.self_attn.k_proj.weight": "pytorch_model-00002-of-00002.bin",
185
+ "model.layers.26.self_attn.o_proj.weight": "pytorch_model-00002-of-00002.bin",
186
+ "model.layers.26.self_attn.q_proj.weight": "pytorch_model-00002-of-00002.bin",
187
+ "model.layers.26.self_attn.v_proj.weight": "pytorch_model-00002-of-00002.bin",
188
+ "model.layers.27.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
189
+ "model.layers.27.mlp.down_proj.weight": "pytorch_model-00002-of-00002.bin",
190
+ "model.layers.27.mlp.gate_proj.weight": "pytorch_model-00002-of-00002.bin",
191
+ "model.layers.27.mlp.up_proj.weight": "pytorch_model-00002-of-00002.bin",
192
+ "model.layers.27.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
193
+ "model.layers.27.self_attn.k_proj.weight": "pytorch_model-00002-of-00002.bin",
194
+ "model.layers.27.self_attn.o_proj.weight": "pytorch_model-00002-of-00002.bin",
195
+ "model.layers.27.self_attn.q_proj.weight": "pytorch_model-00002-of-00002.bin",
196
+ "model.layers.27.self_attn.v_proj.weight": "pytorch_model-00002-of-00002.bin",
197
+ "model.layers.28.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
198
+ "model.layers.28.mlp.down_proj.weight": "pytorch_model-00002-of-00002.bin",
199
+ "model.layers.28.mlp.gate_proj.weight": "pytorch_model-00002-of-00002.bin",
200
+ "model.layers.28.mlp.up_proj.weight": "pytorch_model-00002-of-00002.bin",
201
+ "model.layers.28.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
202
+ "model.layers.28.self_attn.k_proj.weight": "pytorch_model-00002-of-00002.bin",
203
+ "model.layers.28.self_attn.o_proj.weight": "pytorch_model-00002-of-00002.bin",
204
+ "model.layers.28.self_attn.q_proj.weight": "pytorch_model-00002-of-00002.bin",
205
+ "model.layers.28.self_attn.v_proj.weight": "pytorch_model-00002-of-00002.bin",
206
+ "model.layers.29.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
207
+ "model.layers.29.mlp.down_proj.weight": "pytorch_model-00002-of-00002.bin",
208
+ "model.layers.29.mlp.gate_proj.weight": "pytorch_model-00002-of-00002.bin",
209
+ "model.layers.29.mlp.up_proj.weight": "pytorch_model-00002-of-00002.bin",
210
+ "model.layers.29.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
211
+ "model.layers.29.self_attn.k_proj.weight": "pytorch_model-00002-of-00002.bin",
212
+ "model.layers.29.self_attn.o_proj.weight": "pytorch_model-00002-of-00002.bin",
213
+ "model.layers.29.self_attn.q_proj.weight": "pytorch_model-00002-of-00002.bin",
214
+ "model.layers.29.self_attn.v_proj.weight": "pytorch_model-00002-of-00002.bin",
215
+ "model.layers.3.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
216
+ "model.layers.3.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
217
+ "model.layers.3.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
218
+ "model.layers.3.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
219
+ "model.layers.3.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
220
+ "model.layers.3.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
221
+ "model.layers.3.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
222
+ "model.layers.3.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
223
+ "model.layers.3.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
224
+ "model.layers.30.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
225
+ "model.layers.30.mlp.down_proj.weight": "pytorch_model-00002-of-00002.bin",
226
+ "model.layers.30.mlp.gate_proj.weight": "pytorch_model-00002-of-00002.bin",
227
+ "model.layers.30.mlp.up_proj.weight": "pytorch_model-00002-of-00002.bin",
228
+ "model.layers.30.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
229
+ "model.layers.30.self_attn.k_proj.weight": "pytorch_model-00002-of-00002.bin",
230
+ "model.layers.30.self_attn.o_proj.weight": "pytorch_model-00002-of-00002.bin",
231
+ "model.layers.30.self_attn.q_proj.weight": "pytorch_model-00002-of-00002.bin",
232
+ "model.layers.30.self_attn.v_proj.weight": "pytorch_model-00002-of-00002.bin",
233
+ "model.layers.31.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
234
+ "model.layers.31.mlp.down_proj.weight": "pytorch_model-00002-of-00002.bin",
235
+ "model.layers.31.mlp.gate_proj.weight": "pytorch_model-00002-of-00002.bin",
236
+ "model.layers.31.mlp.up_proj.weight": "pytorch_model-00002-of-00002.bin",
237
+ "model.layers.31.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
238
+ "model.layers.31.self_attn.k_proj.weight": "pytorch_model-00002-of-00002.bin",
239
+ "model.layers.31.self_attn.o_proj.weight": "pytorch_model-00002-of-00002.bin",
240
+ "model.layers.31.self_attn.q_proj.weight": "pytorch_model-00002-of-00002.bin",
241
+ "model.layers.31.self_attn.v_proj.weight": "pytorch_model-00002-of-00002.bin",
242
+ "model.layers.4.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
243
+ "model.layers.4.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
244
+ "model.layers.4.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
245
+ "model.layers.4.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
246
+ "model.layers.4.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
247
+ "model.layers.4.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
248
+ "model.layers.4.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
249
+ "model.layers.4.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
250
+ "model.layers.4.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
251
+ "model.layers.5.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
252
+ "model.layers.5.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
253
+ "model.layers.5.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
254
+ "model.layers.5.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
255
+ "model.layers.5.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
256
+ "model.layers.5.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
257
+ "model.layers.5.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
258
+ "model.layers.5.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
259
+ "model.layers.5.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
260
+ "model.layers.6.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
261
+ "model.layers.6.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
262
+ "model.layers.6.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
263
+ "model.layers.6.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
264
+ "model.layers.6.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
265
+ "model.layers.6.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
266
+ "model.layers.6.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
267
+ "model.layers.6.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
268
+ "model.layers.6.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
269
+ "model.layers.7.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
270
+ "model.layers.7.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
271
+ "model.layers.7.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
272
+ "model.layers.7.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
273
+ "model.layers.7.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
274
+ "model.layers.7.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
275
+ "model.layers.7.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
276
+ "model.layers.7.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
277
+ "model.layers.7.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
278
+ "model.layers.8.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
279
+ "model.layers.8.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
280
+ "model.layers.8.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
281
+ "model.layers.8.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
282
+ "model.layers.8.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
283
+ "model.layers.8.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
284
+ "model.layers.8.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
285
+ "model.layers.8.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
286
+ "model.layers.8.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
287
+ "model.layers.9.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
288
+ "model.layers.9.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
289
+ "model.layers.9.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
290
+ "model.layers.9.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
291
+ "model.layers.9.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
292
+ "model.layers.9.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
293
+ "model.layers.9.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
294
+ "model.layers.9.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
295
+ "model.layers.9.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
296
+ "model.norm.weight": "pytorch_model-00002-of-00002.bin"
297
+ }
298
+ }
special_tokens_map.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"bos_token": {"content": "<s>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false}, "eos_token": {"content": "</s>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false}, "unk_token": {"content": "<unk>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false}}
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:45ccb9c8b6b561889acea59191d66986d314e7cbd6a78abc6e49b139ca91c1e6
3
+ size 500058
tokenizer_config.json ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": true,
3
+ "add_eos_token": false,
4
+ "bos_token": {
5
+ "__type": "AddedToken",
6
+ "content": "<s>",
7
+ "lstrip": false,
8
+ "normalized": true,
9
+ "rstrip": false,
10
+ "single_word": false
11
+ },
12
+ "clean_up_tokenization_spaces": false,
13
+ "eos_token": {
14
+ "__type": "AddedToken",
15
+ "content": "</s>",
16
+ "lstrip": false,
17
+ "normalized": true,
18
+ "rstrip": false,
19
+ "single_word": false
20
+ },
21
+ "legacy": null,
22
+ "model_max_length": 1000000000000000019884624838656,
23
+ "pad_token": null,
24
+ "sp_model_kwargs": {},
25
+ "tokenizer_class": "CodeLlamaTokenizer",
26
+ "unk_token": {
27
+ "__type": "AddedToken",
28
+ "content": "<unk>",
29
+ "lstrip": false,
30
+ "normalized": true,
31
+ "rstrip": false,
32
+ "single_word": false
33
+ }
34
+ }