Add files using upload-large-folder tool
Browse files- .gitattributes +1 -0
- config.json +58 -0
- configuration_nemotron_h.py +242 -0
- generation_config.json +7 -0
- model-00001-of-00020.safetensors +3 -0
- model-00002-of-00020.safetensors +3 -0
- model-00003-of-00020.safetensors +3 -0
- model-00004-of-00020.safetensors +3 -0
- model-00005-of-00020.safetensors +3 -0
- model-00006-of-00020.safetensors +3 -0
- model-00007-of-00020.safetensors +3 -0
- model-00008-of-00020.safetensors +3 -0
- model-00009-of-00020.safetensors +3 -0
- model-00010-of-00020.safetensors +3 -0
- model-00011-of-00020.safetensors +3 -0
- model-00012-of-00020.safetensors +3 -0
- model-00013-of-00020.safetensors +3 -0
- model-00014-of-00020.safetensors +3 -0
- model-00015-of-00020.safetensors +3 -0
- model-00016-of-00020.safetensors +3 -0
- model-00017-of-00020.safetensors +3 -0
- model-00018-of-00020.safetensors +3 -0
- model-00019-of-00020.safetensors +3 -0
- model-00020-of-00020.safetensors +3 -0
- model.safetensors.index.json +584 -0
- modeling_nemotron_h.py +1632 -0
- special_tokens_map.json +23 -0
- tokenizer.json +3 -0
- tokenizer_config.json +0 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
config.json
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architectures": [
|
3 |
+
"NemotronHForCausalLM"
|
4 |
+
],
|
5 |
+
"attention_bias": false,
|
6 |
+
"attention_dropout": 0.0,
|
7 |
+
"attention_head_dim": 128,
|
8 |
+
"auto_map": {
|
9 |
+
"AutoConfig": "configuration_nemotron_h.NemotronHConfig",
|
10 |
+
"AutoModelForCausalLM": "modeling_nemotron_h.NemotronHForCausalLM"
|
11 |
+
},
|
12 |
+
"bos_token_id": 1,
|
13 |
+
"chunk_size": 256,
|
14 |
+
"conv_kernel": 4,
|
15 |
+
"eos_token_id": 2,
|
16 |
+
"expand": 2,
|
17 |
+
"hidden_dropout": 0.0,
|
18 |
+
"hidden_size": 8192,
|
19 |
+
"hybrid_override_pattern": "M-M-M-M-M-M-M-M-M*-M-M-M-M-M-M-M-M-M-M*-M-M-M-M-M*-M-M-M-M-M*-M-M-M-M-M-M-M---MM---M-M*-M-M-M-M-M-",
|
20 |
+
"initializer_range": 0.02,
|
21 |
+
"intermediate_size": 30720,
|
22 |
+
"layer_norm_epsilon": 1e-05,
|
23 |
+
"mamba_head_dim": 64,
|
24 |
+
"mamba_hidden_act": "silu",
|
25 |
+
"mamba_num_heads": 256,
|
26 |
+
"mamba_proj_bias": false,
|
27 |
+
"max_position_embeddings": 8192,
|
28 |
+
"mlp_bias": false,
|
29 |
+
"mlp_hidden_act": "relu2",
|
30 |
+
"model_type": "nemotron_h",
|
31 |
+
"n_groups": 8,
|
32 |
+
"num_attention_heads": 64,
|
33 |
+
"num_hidden_layers": 98,
|
34 |
+
"num_key_value_heads": 8,
|
35 |
+
"num_logits_to_keep": 1,
|
36 |
+
"pad_token_id": 0,
|
37 |
+
"rescale_prenorm_residual": true,
|
38 |
+
"residual_in_fp32": false,
|
39 |
+
"rms_norm_eps": 1e-05,
|
40 |
+
"sliding_window": null,
|
41 |
+
"ssm_state_size": 256,
|
42 |
+
"tie_word_embeddings": false,
|
43 |
+
"time_step_floor": 0.0001,
|
44 |
+
"time_step_limit": [
|
45 |
+
0.0,
|
46 |
+
Infinity
|
47 |
+
],
|
48 |
+
"time_step_max": 0.1,
|
49 |
+
"time_step_min": 0.001,
|
50 |
+
"time_step_rank": 512,
|
51 |
+
"torch_dtype": "bfloat16",
|
52 |
+
"transformers_version": "4.48.0.dev0",
|
53 |
+
"use_bias": false,
|
54 |
+
"use_cache": true,
|
55 |
+
"use_conv_bias": true,
|
56 |
+
"use_mamba_kernels": true,
|
57 |
+
"vocab_size": 131072
|
58 |
+
}
|
configuration_nemotron_h.py
ADDED
@@ -0,0 +1,242 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2024 AI21 Labs Ltd. and the HuggingFace Inc. team. All rights reserved.
|
3 |
+
#
|
4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
+
# you may not use this file except in compliance with the License.
|
6 |
+
# You may obtain a copy of the License at
|
7 |
+
#
|
8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
+
#
|
10 |
+
# Unless required by applicable law or agreed to in writing, software
|
11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
+
# See the License for the specific language governing permissions and
|
14 |
+
# limitations under the License.
|
15 |
+
"""NemotronH model configuration"""
|
16 |
+
|
17 |
+
import re
|
18 |
+
|
19 |
+
from transformers.configuration_utils import PretrainedConfig
|
20 |
+
from transformers.utils import logging
|
21 |
+
|
22 |
+
|
23 |
+
logger = logging.get_logger(__name__)
|
24 |
+
|
25 |
+
|
26 |
+
class NemotronHConfig(PretrainedConfig):
|
27 |
+
r"""
|
28 |
+
This is the configuration class to store the configuration of a [`NemotronHModel`]. It is used to instantiate a
|
29 |
+
NemotronH model according to the specified arguments, defining the model architecture. Instantiating a configuration
|
30 |
+
with the defaults will yield a similar configuration to that of the NemotronH-v0.1 model.
|
31 |
+
|
32 |
+
[todo](todo)
|
33 |
+
|
34 |
+
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
35 |
+
documentation from [`PretrainedConfig`] for more information.
|
36 |
+
|
37 |
+
|
38 |
+
Args:
|
39 |
+
vocab_size (`int`, *optional*, defaults to 131072):
|
40 |
+
Vocabulary size of the NemotronH model. Defines the number of different tokens that can be represented by the
|
41 |
+
`inputs_ids` passed when calling [`NemotronHModel`]
|
42 |
+
tie_word_embeddings (`bool`, *optional*, defaults to `False`):
|
43 |
+
Whether the model's input and output word embeddings should be tied. Note that this is only relevant if the
|
44 |
+
model has a output word embedding layer.
|
45 |
+
hidden_size (`int`, *optional*, defaults to 4096):
|
46 |
+
Dimension of the hidden representations.
|
47 |
+
intermediate_size (`int`, *optional*, defaults to 21504):
|
48 |
+
Dimension of the MLP representations.
|
49 |
+
num_hidden_layers (`int`, *optional*, defaults to 52):
|
50 |
+
Number of hidden layers in the Transformer encoder.
|
51 |
+
hybrid_override_pattern (`str`, *optional*, defaults to `"M-M-M-M*-M-M-M-M-M*-M-M-M-M-M*-M-M-M-M-M*-M-M-M-M-M-"`):
|
52 |
+
The pattern of the hybrid model. The pattern is a string of characters where each character represents M: Mamba2, *: Attention, -: MLP
|
53 |
+
num_attention_heads (`int`, *optional*, defaults to 32):
|
54 |
+
Number of attention heads for each attention layer in the Transformer encoder.
|
55 |
+
attention_head_dim (`int`, *optional*, defaults to 128):
|
56 |
+
Dimension of each attention head.
|
57 |
+
num_key_value_heads (`int`, *optional*, defaults to 8):
|
58 |
+
This is the number of key_value heads that should be used to implement Grouped Query Attention. If
|
59 |
+
`num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
|
60 |
+
`num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used.
|
61 |
+
mlp_hidden_act (`str`, *optional*, defaults to "relu2"):
|
62 |
+
The non-linear activation function in the MLP layers.
|
63 |
+
attention_bias (`bool`, *optional*, defaults to `False`):
|
64 |
+
Whether to use bias in attention layers.
|
65 |
+
mlp_bias (`bool`, *optional*, defaults to `False`):
|
66 |
+
Whether to use bias in MLP layers.
|
67 |
+
use_bias (`bool`, *optional*, defaults to `False`):
|
68 |
+
Whether to use bias in the model.
|
69 |
+
initializer_range (`float`, *optional*, defaults to 0.02):
|
70 |
+
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
71 |
+
layer_norm_epsilon (`float`, *optional*, defaults to 1e-5):
|
72 |
+
The epsilon used by the layer normalization layers.
|
73 |
+
residual_in_fp32 (`bool`, *optional*, defaults to `False`):
|
74 |
+
Whether or not residuals should be in `float32`. If set to `False` residuals will keep the same `dtype` as the rest of the model.
|
75 |
+
use_cache (`bool`, *optional*, defaults to `True`):
|
76 |
+
Whether or not the model should return the last key/values attentions (not used by all models). Only
|
77 |
+
relevant if `config.is_decoder=True`.
|
78 |
+
num_logits_to_keep (`int` or `None`, *optional*, defaults to 1):
|
79 |
+
Number of prompt logits to calculate during generation. If `None`, all logits will be calculated. If an
|
80 |
+
integer value, only last `num_logits_to_keep` logits will be calculated.
|
81 |
+
pad_token_id (`int`, *optional*, defaults to 0):
|
82 |
+
The id of the padding token.
|
83 |
+
bos_token_id (`int`, *optional*, defaults to 1):
|
84 |
+
The id of the "beginning-of-sequence" token.
|
85 |
+
eos_token_id (`int`, *optional*, defaults to 2):
|
86 |
+
The id of the "end-of-sequence" token.
|
87 |
+
sliding_window (`int`, *optional*, defaults to None):
|
88 |
+
Sliding window attention window size.
|
89 |
+
max_position_embeddings (`int`, *optional*, defaults to 4096):
|
90 |
+
The maximum sequence length that this model might ever be used with.
|
91 |
+
attention_dropout (`float`, *optional*, defaults to 0.0):
|
92 |
+
The dropout ratio for the attention probabilities.
|
93 |
+
hidden_dropout (`float`, *optional*, defaults to 0.0):
|
94 |
+
The dropout ratio for the hidden states.
|
95 |
+
use_mamba_kernels (`bool`, *optional*, defaults to `True`):
|
96 |
+
Flag indicating whether or not to use the fast mamba kernels. These are available only if `mamba-ssm` and
|
97 |
+
`causal-conv1d` are installed, and the mamba modules are running on a CUDA device.
|
98 |
+
ssm_state_size (`int`, *optional*, defaults to 128):
|
99 |
+
The dimension of the mamba state space latents.
|
100 |
+
mamba_num_heads (`int`, *optional*, defaults to 128):
|
101 |
+
Number of heads in Mamba layers.
|
102 |
+
mamba_n_groups (`int`, *optional*, defaults to 8):
|
103 |
+
Number of groups in Mamba layers.
|
104 |
+
mamba_head_dim (`int`, *optional*, defaults to 64):
|
105 |
+
Dimension of each Mamba head.
|
106 |
+
mamba_d_conv (`int`, *optional*, defaults to 4):
|
107 |
+
The size of the mamba convolution kernel.
|
108 |
+
mamba_expand (`int`, *optional*, defaults to 2):
|
109 |
+
Expanding factor used to determine the mamba intermediate size.
|
110 |
+
mamba_hidden_act (`str`, *optional*, defaults to "silu"):
|
111 |
+
The non-linear activation function in the Mamba layers.
|
112 |
+
mamba_dt_min (`float`, *optional*, defaults to 0.001):
|
113 |
+
Minimum value for the time step in Mamba.
|
114 |
+
mamba_dt_max (`float`, *optional*, defaults to 0.1):
|
115 |
+
Maximum value for the time step in Mamba.
|
116 |
+
mamba_dt_limit (`tuple`, *optional*, defaults to (0.0, float("inf"))):
|
117 |
+
Limits for the time step in Mamba.
|
118 |
+
mamba_dt_init_floor (`float`, *optional*, defaults to 1e-4):
|
119 |
+
Floor value for time step initialization in Mamba.
|
120 |
+
mamba_conv_bias (`bool`, *optional*, defaults to `True`):
|
121 |
+
Whether to use bias in the convolution layer of the mamba mixer block.
|
122 |
+
mamba_proj_bias (`bool`, *optional*, defaults to `False`):
|
123 |
+
Whether to use bias in the input and output projections of the mamba mixer block.
|
124 |
+
mamba_chunk_size (`int`, *optional*, defaults to 256):
|
125 |
+
Size of chunks for Mamba processing.
|
126 |
+
rescale_prenorm_residual (`bool`, *optional*, defaults to `True`):
|
127 |
+
Whether to rescale the pre-normalization residual connections.
|
128 |
+
"""
|
129 |
+
|
130 |
+
model_type = "nemotron_h"
|
131 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
132 |
+
|
133 |
+
def __init__(
|
134 |
+
self,
|
135 |
+
vocab_size=131072,
|
136 |
+
tie_word_embeddings=False,
|
137 |
+
hidden_size=4096,
|
138 |
+
intermediate_size=21504,
|
139 |
+
num_hidden_layers=52,
|
140 |
+
hybrid_override_pattern="M-M-M-M*-M-M-M-M-M*-M-M-M-M-M*-M-M-M-M-M*-M-M-M-M-M-",
|
141 |
+
num_attention_heads=32,
|
142 |
+
attention_head_dim=128,
|
143 |
+
num_key_value_heads=8, # nemo: num_query_groups
|
144 |
+
mlp_hidden_act="relu2",
|
145 |
+
attention_bias=False,
|
146 |
+
mlp_bias=False,
|
147 |
+
use_bias=False,
|
148 |
+
initializer_range=0.02, # nemo: init_method_std
|
149 |
+
layer_norm_epsilon=1e-5, # nemo: layernorm_epsilon
|
150 |
+
residual_in_fp32=False, # Megatron Core default value
|
151 |
+
use_cache=True,
|
152 |
+
num_logits_to_keep=1,
|
153 |
+
pad_token_id=0,
|
154 |
+
bos_token_id=1,
|
155 |
+
eos_token_id=2,
|
156 |
+
sliding_window=None,
|
157 |
+
max_position_embeddings=4096,
|
158 |
+
attention_dropout=0.0,
|
159 |
+
hidden_dropout=0.0, # * ADDED
|
160 |
+
use_mamba_kernels=True,
|
161 |
+
ssm_state_size=128, # mamba_state_size
|
162 |
+
mamba_num_heads=128,
|
163 |
+
mamba_n_groups=8, # nemo: mamba_ssm_ngroups = num_heads
|
164 |
+
mamba_head_dim=64,
|
165 |
+
mamba_d_conv=4,
|
166 |
+
mamba_expand=2,
|
167 |
+
mamba_hidden_act="silu",
|
168 |
+
mamba_dt_min=0.001,
|
169 |
+
mamba_dt_max=0.1,
|
170 |
+
mamba_dt_limit=(0.0, float("inf")),
|
171 |
+
mamba_dt_init_floor=1e-4,
|
172 |
+
mamba_conv_bias=True,
|
173 |
+
mamba_proj_bias=False,
|
174 |
+
mamba_chunk_size=256,
|
175 |
+
rescale_prenorm_residual=True,
|
176 |
+
**kwargs,
|
177 |
+
):
|
178 |
+
self.vocab_size = vocab_size
|
179 |
+
self.tie_word_embeddings = tie_word_embeddings
|
180 |
+
self.hidden_size = hidden_size
|
181 |
+
self.intermediate_size = intermediate_size
|
182 |
+
self.num_hidden_layers = num_hidden_layers
|
183 |
+
self.hybrid_override_pattern = hybrid_override_pattern
|
184 |
+
self.num_attention_heads = num_attention_heads
|
185 |
+
self.attention_head_dim = attention_head_dim
|
186 |
+
self.sliding_window = sliding_window
|
187 |
+
self.max_position_embeddings = max_position_embeddings
|
188 |
+
self.attention_dropout = attention_dropout
|
189 |
+
self.hidden_dropout = hidden_dropout
|
190 |
+
|
191 |
+
# Validate hybrid_override_pattern
|
192 |
+
# M: Mamba2, *: Attention, -: MLP
|
193 |
+
assert len(self.hybrid_override_pattern) == self.num_hidden_layers, "hybrid_override_pattern must have the same length as num_hidden_layers"
|
194 |
+
assert re.match(r"^[*-M]+$", self.hybrid_override_pattern), "hybrid_override_pattern must only contain characters 'M', '*', or '-'"
|
195 |
+
|
196 |
+
# for backward compatibility
|
197 |
+
if num_key_value_heads is None:
|
198 |
+
num_key_value_heads = num_attention_heads
|
199 |
+
|
200 |
+
self.num_key_value_heads = num_key_value_heads
|
201 |
+
self.mlp_hidden_act = mlp_hidden_act
|
202 |
+
self.attention_bias = attention_bias
|
203 |
+
self.mlp_bias = mlp_bias
|
204 |
+
self.use_bias = use_bias
|
205 |
+
self.initializer_range = initializer_range
|
206 |
+
self.layer_norm_epsilon = layer_norm_epsilon
|
207 |
+
self.residual_in_fp32 = residual_in_fp32
|
208 |
+
|
209 |
+
self.use_cache = use_cache
|
210 |
+
self.num_logits_to_keep = num_logits_to_keep
|
211 |
+
|
212 |
+
self.use_mamba_kernels = use_mamba_kernels
|
213 |
+
self.n_groups = mamba_n_groups
|
214 |
+
self.mamba_head_dim = mamba_head_dim
|
215 |
+
self.ssm_state_size = ssm_state_size
|
216 |
+
self.mamba_num_heads = mamba_num_heads
|
217 |
+
self.conv_kernel = mamba_d_conv
|
218 |
+
self.expand = mamba_expand
|
219 |
+
self.mamba_hidden_act = mamba_hidden_act
|
220 |
+
self.time_step_min = mamba_dt_min
|
221 |
+
self.time_step_max = mamba_dt_max
|
222 |
+
self.time_step_limit = mamba_dt_limit
|
223 |
+
self.time_step_floor = mamba_dt_init_floor
|
224 |
+
self.use_conv_bias = mamba_conv_bias
|
225 |
+
self.mamba_proj_bias = mamba_proj_bias
|
226 |
+
self.chunk_size = mamba_chunk_size
|
227 |
+
self.rescale_prenorm_residual = rescale_prenorm_residual
|
228 |
+
|
229 |
+
super().__init__(
|
230 |
+
pad_token_id=pad_token_id,
|
231 |
+
bos_token_id=bos_token_id,
|
232 |
+
eos_token_id=eos_token_id,
|
233 |
+
tie_word_embeddings=tie_word_embeddings,
|
234 |
+
**kwargs,
|
235 |
+
)
|
236 |
+
|
237 |
+
@property
|
238 |
+
def layers_block_type(self):
|
239 |
+
return [
|
240 |
+
"mamba" if self.hybrid_override_pattern[i] == "M" else
|
241 |
+
"attention" if self.hybrid_override_pattern[i] == "*" else "mlp"
|
242 |
+
for i in range(self.num_hidden_layers)]
|
generation_config.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_from_model_config": true,
|
3 |
+
"bos_token_id": 1,
|
4 |
+
"eos_token_id": [2, 11, 6250],
|
5 |
+
"pad_token_id": 0,
|
6 |
+
"transformers_version": "4.48.0.dev0"
|
7 |
+
}
|
model-00001-of-00020.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ee12526ce592696c83dee2f2ce1f3ba4a4eb9cb0c888b84e0bf14e864b44267a
|
3 |
+
size 4907881968
|
model-00002-of-00020.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f86fdb0d59f464e8642b09902f8fad0afcc31ffd43d4cdde4f47bbc4c1017b39
|
3 |
+
size 4773887960
|
model-00003-of-00020.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:871ed0cc60821fcd003ee022c6c6f1bd6668e7354a096b310f05387b11113e9c
|
3 |
+
size 4643690512
|
model-00004-of-00020.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1938ab662ef99120529a5f46b576dec3d1852cb89c9cd5525d7d72c840bbe74d
|
3 |
+
size 4572354880
|
model-00005-of-00020.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ec50a683261306667317750925b331e092d1af3417452cb4e27e7f9f41b10bb9
|
3 |
+
size 4878778464
|
model-00006-of-00020.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e3e8e530fc54dafb47c1882f0c6d31528d5c43fe036882614b30e8147b0c4fa0
|
3 |
+
size 4538800096
|
model-00007-of-00020.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:04c7c534d9970adfd7a207aa6ccebe78f91308ee1b8639c769663d197b8659cd
|
3 |
+
size 4878778464
|
model-00008-of-00020.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e4b083f46b345149c2b054ba7499c8041d831711620ed41bc84fa723ead20ac6
|
3 |
+
size 4840806936
|
model-00009-of-00020.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:13759a54a7bc9c346618d0e673f7f5de458fbcd5a3f80d6d034cf986c7500a77
|
3 |
+
size 4878778464
|
model-00010-of-00020.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8e726da14d657fbd6a1ba5982e3cbd60b6ab81ec19a4346a79b4d744fb8cad17
|
3 |
+
size 4840806936
|
model-00011-of-00020.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:78d4bad4b7cf0d9df376ee35911a49e6e920f1fd101d231c18ccc5c822ff1932
|
3 |
+
size 4878778464
|
model-00012-of-00020.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:23d8e9fa492c35ca9f2757becf797c4eb8ae5726307dc4c3e813791d620c7fd2
|
3 |
+
size 4840806936
|
model-00013-of-00020.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:64a1159adabc1219e541de2cbcc2f81552c026d59b211648b194e4cb869ccea0
|
3 |
+
size 4878778464
|
model-00014-of-00020.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b705abfd774daa855c9c9f6e0fe8e0b27d27a19ae62fedfa5ff54cbba260d23a
|
3 |
+
size 4538800096
|
model-00015-of-00020.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:2edfadd560412f94e22356e91ffccd85103ee38152e63a00e085fca5274d0227
|
3 |
+
size 4773681112
|
model-00016-of-00020.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ae0f0e660e7e6286d42502ca67c8f32982df6ab57bd3f6baf2b34dc6669cdf43
|
3 |
+
size 4773681120
|
model-00017-of-00020.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9d09feccc7cb89afdd75f6d5de033509f5379b48016f694d08e49297feec3176
|
3 |
+
size 4572371368
|
model-00018-of-00020.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:28ed58a4f22c3560e3b14dcdeb0c60b1e9063f675c5024d7352cff255b202f6e
|
3 |
+
size 4773887992
|
model-00019-of-00020.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b825999e4390588b064a24d289b78f570b80966fc76db7de5de5a2c596084711
|
3 |
+
size 4643690576
|
model-00020-of-00020.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ce25b4e4fb698f740d150c6e482025ffc1134d748fbc73348f3a535bd18b6d48
|
3 |
+
size 3154133456
|
model.safetensors.index.json
ADDED
@@ -0,0 +1,584 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"metadata": {
|
3 |
+
"total_size": 93583109632
|
4 |
+
},
|
5 |
+
"weight_map": {
|
6 |
+
"backbone.embeddings.weight": "model-00001-of-00020.safetensors",
|
7 |
+
"backbone.layers.0.mixer.A_log": "model-00001-of-00020.safetensors",
|
8 |
+
"backbone.layers.0.mixer.D": "model-00001-of-00020.safetensors",
|
9 |
+
"backbone.layers.0.mixer.conv1d.bias": "model-00001-of-00020.safetensors",
|
10 |
+
"backbone.layers.0.mixer.conv1d.weight": "model-00001-of-00020.safetensors",
|
11 |
+
"backbone.layers.0.mixer.dt_bias": "model-00001-of-00020.safetensors",
|
12 |
+
"backbone.layers.0.mixer.in_proj.weight": "model-00001-of-00020.safetensors",
|
13 |
+
"backbone.layers.0.mixer.norm.weight": "model-00001-of-00020.safetensors",
|
14 |
+
"backbone.layers.0.mixer.out_proj.weight": "model-00001-of-00020.safetensors",
|
15 |
+
"backbone.layers.0.norm.weight": "model-00001-of-00020.safetensors",
|
16 |
+
"backbone.layers.1.mixer.down_proj.weight": "model-00001-of-00020.safetensors",
|
17 |
+
"backbone.layers.1.mixer.up_proj.weight": "model-00001-of-00020.safetensors",
|
18 |
+
"backbone.layers.1.norm.weight": "model-00001-of-00020.safetensors",
|
19 |
+
"backbone.layers.10.mixer.A_log": "model-00003-of-00020.safetensors",
|
20 |
+
"backbone.layers.10.mixer.D": "model-00003-of-00020.safetensors",
|
21 |
+
"backbone.layers.10.mixer.conv1d.bias": "model-00003-of-00020.safetensors",
|
22 |
+
"backbone.layers.10.mixer.conv1d.weight": "model-00003-of-00020.safetensors",
|
23 |
+
"backbone.layers.10.mixer.dt_bias": "model-00003-of-00020.safetensors",
|
24 |
+
"backbone.layers.10.mixer.in_proj.weight": "model-00003-of-00020.safetensors",
|
25 |
+
"backbone.layers.10.mixer.norm.weight": "model-00003-of-00020.safetensors",
|
26 |
+
"backbone.layers.10.mixer.out_proj.weight": "model-00003-of-00020.safetensors",
|
27 |
+
"backbone.layers.10.norm.weight": "model-00003-of-00020.safetensors",
|
28 |
+
"backbone.layers.11.mixer.down_proj.weight": "model-00003-of-00020.safetensors",
|
29 |
+
"backbone.layers.11.mixer.up_proj.weight": "model-00003-of-00020.safetensors",
|
30 |
+
"backbone.layers.11.norm.weight": "model-00003-of-00020.safetensors",
|
31 |
+
"backbone.layers.12.mixer.A_log": "model-00003-of-00020.safetensors",
|
32 |
+
"backbone.layers.12.mixer.D": "model-00003-of-00020.safetensors",
|
33 |
+
"backbone.layers.12.mixer.conv1d.bias": "model-00003-of-00020.safetensors",
|
34 |
+
"backbone.layers.12.mixer.conv1d.weight": "model-00003-of-00020.safetensors",
|
35 |
+
"backbone.layers.12.mixer.dt_bias": "model-00003-of-00020.safetensors",
|
36 |
+
"backbone.layers.12.mixer.in_proj.weight": "model-00003-of-00020.safetensors",
|
37 |
+
"backbone.layers.12.mixer.norm.weight": "model-00003-of-00020.safetensors",
|
38 |
+
"backbone.layers.12.mixer.out_proj.weight": "model-00003-of-00020.safetensors",
|
39 |
+
"backbone.layers.12.norm.weight": "model-00003-of-00020.safetensors",
|
40 |
+
"backbone.layers.13.mixer.down_proj.weight": "model-00004-of-00020.safetensors",
|
41 |
+
"backbone.layers.13.mixer.up_proj.weight": "model-00004-of-00020.safetensors",
|
42 |
+
"backbone.layers.13.norm.weight": "model-00003-of-00020.safetensors",
|
43 |
+
"backbone.layers.14.mixer.A_log": "model-00004-of-00020.safetensors",
|
44 |
+
"backbone.layers.14.mixer.D": "model-00004-of-00020.safetensors",
|
45 |
+
"backbone.layers.14.mixer.conv1d.bias": "model-00004-of-00020.safetensors",
|
46 |
+
"backbone.layers.14.mixer.conv1d.weight": "model-00004-of-00020.safetensors",
|
47 |
+
"backbone.layers.14.mixer.dt_bias": "model-00004-of-00020.safetensors",
|
48 |
+
"backbone.layers.14.mixer.in_proj.weight": "model-00004-of-00020.safetensors",
|
49 |
+
"backbone.layers.14.mixer.norm.weight": "model-00004-of-00020.safetensors",
|
50 |
+
"backbone.layers.14.mixer.out_proj.weight": "model-00004-of-00020.safetensors",
|
51 |
+
"backbone.layers.14.norm.weight": "model-00004-of-00020.safetensors",
|
52 |
+
"backbone.layers.15.mixer.down_proj.weight": "model-00004-of-00020.safetensors",
|
53 |
+
"backbone.layers.15.mixer.up_proj.weight": "model-00004-of-00020.safetensors",
|
54 |
+
"backbone.layers.15.norm.weight": "model-00004-of-00020.safetensors",
|
55 |
+
"backbone.layers.16.mixer.A_log": "model-00004-of-00020.safetensors",
|
56 |
+
"backbone.layers.16.mixer.D": "model-00004-of-00020.safetensors",
|
57 |
+
"backbone.layers.16.mixer.conv1d.bias": "model-00004-of-00020.safetensors",
|
58 |
+
"backbone.layers.16.mixer.conv1d.weight": "model-00004-of-00020.safetensors",
|
59 |
+
"backbone.layers.16.mixer.dt_bias": "model-00004-of-00020.safetensors",
|
60 |
+
"backbone.layers.16.mixer.in_proj.weight": "model-00004-of-00020.safetensors",
|
61 |
+
"backbone.layers.16.mixer.norm.weight": "model-00004-of-00020.safetensors",
|
62 |
+
"backbone.layers.16.mixer.out_proj.weight": "model-00004-of-00020.safetensors",
|
63 |
+
"backbone.layers.16.norm.weight": "model-00004-of-00020.safetensors",
|
64 |
+
"backbone.layers.17.mixer.k_proj.weight": "model-00004-of-00020.safetensors",
|
65 |
+
"backbone.layers.17.mixer.o_proj.weight": "model-00004-of-00020.safetensors",
|
66 |
+
"backbone.layers.17.mixer.q_proj.weight": "model-00004-of-00020.safetensors",
|
67 |
+
"backbone.layers.17.mixer.v_proj.weight": "model-00004-of-00020.safetensors",
|
68 |
+
"backbone.layers.17.norm.weight": "model-00004-of-00020.safetensors",
|
69 |
+
"backbone.layers.18.mixer.down_proj.weight": "model-00005-of-00020.safetensors",
|
70 |
+
"backbone.layers.18.mixer.up_proj.weight": "model-00004-of-00020.safetensors",
|
71 |
+
"backbone.layers.18.norm.weight": "model-00004-of-00020.safetensors",
|
72 |
+
"backbone.layers.19.mixer.A_log": "model-00005-of-00020.safetensors",
|
73 |
+
"backbone.layers.19.mixer.D": "model-00005-of-00020.safetensors",
|
74 |
+
"backbone.layers.19.mixer.conv1d.bias": "model-00005-of-00020.safetensors",
|
75 |
+
"backbone.layers.19.mixer.conv1d.weight": "model-00005-of-00020.safetensors",
|
76 |
+
"backbone.layers.19.mixer.dt_bias": "model-00005-of-00020.safetensors",
|
77 |
+
"backbone.layers.19.mixer.in_proj.weight": "model-00005-of-00020.safetensors",
|
78 |
+
"backbone.layers.19.mixer.norm.weight": "model-00005-of-00020.safetensors",
|
79 |
+
"backbone.layers.19.mixer.out_proj.weight": "model-00005-of-00020.safetensors",
|
80 |
+
"backbone.layers.19.norm.weight": "model-00005-of-00020.safetensors",
|
81 |
+
"backbone.layers.2.mixer.A_log": "model-00001-of-00020.safetensors",
|
82 |
+
"backbone.layers.2.mixer.D": "model-00001-of-00020.safetensors",
|
83 |
+
"backbone.layers.2.mixer.conv1d.bias": "model-00001-of-00020.safetensors",
|
84 |
+
"backbone.layers.2.mixer.conv1d.weight": "model-00001-of-00020.safetensors",
|
85 |
+
"backbone.layers.2.mixer.dt_bias": "model-00001-of-00020.safetensors",
|
86 |
+
"backbone.layers.2.mixer.in_proj.weight": "model-00001-of-00020.safetensors",
|
87 |
+
"backbone.layers.2.mixer.norm.weight": "model-00001-of-00020.safetensors",
|
88 |
+
"backbone.layers.2.mixer.out_proj.weight": "model-00001-of-00020.safetensors",
|
89 |
+
"backbone.layers.2.norm.weight": "model-00001-of-00020.safetensors",
|
90 |
+
"backbone.layers.20.mixer.down_proj.weight": "model-00005-of-00020.safetensors",
|
91 |
+
"backbone.layers.20.mixer.up_proj.weight": "model-00005-of-00020.safetensors",
|
92 |
+
"backbone.layers.20.norm.weight": "model-00005-of-00020.safetensors",
|
93 |
+
"backbone.layers.21.mixer.A_log": "model-00005-of-00020.safetensors",
|
94 |
+
"backbone.layers.21.mixer.D": "model-00005-of-00020.safetensors",
|
95 |
+
"backbone.layers.21.mixer.conv1d.bias": "model-00005-of-00020.safetensors",
|
96 |
+
"backbone.layers.21.mixer.conv1d.weight": "model-00005-of-00020.safetensors",
|
97 |
+
"backbone.layers.21.mixer.dt_bias": "model-00005-of-00020.safetensors",
|
98 |
+
"backbone.layers.21.mixer.in_proj.weight": "model-00005-of-00020.safetensors",
|
99 |
+
"backbone.layers.21.mixer.norm.weight": "model-00005-of-00020.safetensors",
|
100 |
+
"backbone.layers.21.mixer.out_proj.weight": "model-00005-of-00020.safetensors",
|
101 |
+
"backbone.layers.21.norm.weight": "model-00005-of-00020.safetensors",
|
102 |
+
"backbone.layers.22.mixer.down_proj.weight": "model-00005-of-00020.safetensors",
|
103 |
+
"backbone.layers.22.mixer.up_proj.weight": "model-00005-of-00020.safetensors",
|
104 |
+
"backbone.layers.22.norm.weight": "model-00005-of-00020.safetensors",
|
105 |
+
"backbone.layers.23.mixer.A_log": "model-00005-of-00020.safetensors",
|
106 |
+
"backbone.layers.23.mixer.D": "model-00005-of-00020.safetensors",
|
107 |
+
"backbone.layers.23.mixer.conv1d.bias": "model-00005-of-00020.safetensors",
|
108 |
+
"backbone.layers.23.mixer.conv1d.weight": "model-00005-of-00020.safetensors",
|
109 |
+
"backbone.layers.23.mixer.dt_bias": "model-00005-of-00020.safetensors",
|
110 |
+
"backbone.layers.23.mixer.in_proj.weight": "model-00005-of-00020.safetensors",
|
111 |
+
"backbone.layers.23.mixer.norm.weight": "model-00005-of-00020.safetensors",
|
112 |
+
"backbone.layers.23.mixer.out_proj.weight": "model-00006-of-00020.safetensors",
|
113 |
+
"backbone.layers.23.norm.weight": "model-00005-of-00020.safetensors",
|
114 |
+
"backbone.layers.24.mixer.down_proj.weight": "model-00006-of-00020.safetensors",
|
115 |
+
"backbone.layers.24.mixer.up_proj.weight": "model-00006-of-00020.safetensors",
|
116 |
+
"backbone.layers.24.norm.weight": "model-00006-of-00020.safetensors",
|
117 |
+
"backbone.layers.25.mixer.A_log": "model-00006-of-00020.safetensors",
|
118 |
+
"backbone.layers.25.mixer.D": "model-00006-of-00020.safetensors",
|
119 |
+
"backbone.layers.25.mixer.conv1d.bias": "model-00006-of-00020.safetensors",
|
120 |
+
"backbone.layers.25.mixer.conv1d.weight": "model-00006-of-00020.safetensors",
|
121 |
+
"backbone.layers.25.mixer.dt_bias": "model-00006-of-00020.safetensors",
|
122 |
+
"backbone.layers.25.mixer.in_proj.weight": "model-00006-of-00020.safetensors",
|
123 |
+
"backbone.layers.25.mixer.norm.weight": "model-00006-of-00020.safetensors",
|
124 |
+
"backbone.layers.25.mixer.out_proj.weight": "model-00006-of-00020.safetensors",
|
125 |
+
"backbone.layers.25.norm.weight": "model-00006-of-00020.safetensors",
|
126 |
+
"backbone.layers.26.mixer.down_proj.weight": "model-00006-of-00020.safetensors",
|
127 |
+
"backbone.layers.26.mixer.up_proj.weight": "model-00006-of-00020.safetensors",
|
128 |
+
"backbone.layers.26.norm.weight": "model-00006-of-00020.safetensors",
|
129 |
+
"backbone.layers.27.mixer.A_log": "model-00006-of-00020.safetensors",
|
130 |
+
"backbone.layers.27.mixer.D": "model-00006-of-00020.safetensors",
|
131 |
+
"backbone.layers.27.mixer.conv1d.bias": "model-00006-of-00020.safetensors",
|
132 |
+
"backbone.layers.27.mixer.conv1d.weight": "model-00006-of-00020.safetensors",
|
133 |
+
"backbone.layers.27.mixer.dt_bias": "model-00006-of-00020.safetensors",
|
134 |
+
"backbone.layers.27.mixer.in_proj.weight": "model-00006-of-00020.safetensors",
|
135 |
+
"backbone.layers.27.mixer.norm.weight": "model-00006-of-00020.safetensors",
|
136 |
+
"backbone.layers.27.mixer.out_proj.weight": "model-00006-of-00020.safetensors",
|
137 |
+
"backbone.layers.27.norm.weight": "model-00006-of-00020.safetensors",
|
138 |
+
"backbone.layers.28.mixer.down_proj.weight": "model-00007-of-00020.safetensors",
|
139 |
+
"backbone.layers.28.mixer.up_proj.weight": "model-00006-of-00020.safetensors",
|
140 |
+
"backbone.layers.28.norm.weight": "model-00006-of-00020.safetensors",
|
141 |
+
"backbone.layers.29.mixer.A_log": "model-00007-of-00020.safetensors",
|
142 |
+
"backbone.layers.29.mixer.D": "model-00007-of-00020.safetensors",
|
143 |
+
"backbone.layers.29.mixer.conv1d.bias": "model-00007-of-00020.safetensors",
|
144 |
+
"backbone.layers.29.mixer.conv1d.weight": "model-00007-of-00020.safetensors",
|
145 |
+
"backbone.layers.29.mixer.dt_bias": "model-00007-of-00020.safetensors",
|
146 |
+
"backbone.layers.29.mixer.in_proj.weight": "model-00007-of-00020.safetensors",
|
147 |
+
"backbone.layers.29.mixer.norm.weight": "model-00007-of-00020.safetensors",
|
148 |
+
"backbone.layers.29.mixer.out_proj.weight": "model-00007-of-00020.safetensors",
|
149 |
+
"backbone.layers.29.norm.weight": "model-00007-of-00020.safetensors",
|
150 |
+
"backbone.layers.3.mixer.down_proj.weight": "model-00002-of-00020.safetensors",
|
151 |
+
"backbone.layers.3.mixer.up_proj.weight": "model-00002-of-00020.safetensors",
|
152 |
+
"backbone.layers.3.norm.weight": "model-00001-of-00020.safetensors",
|
153 |
+
"backbone.layers.30.mixer.down_proj.weight": "model-00007-of-00020.safetensors",
|
154 |
+
"backbone.layers.30.mixer.up_proj.weight": "model-00007-of-00020.safetensors",
|
155 |
+
"backbone.layers.30.norm.weight": "model-00007-of-00020.safetensors",
|
156 |
+
"backbone.layers.31.mixer.A_log": "model-00007-of-00020.safetensors",
|
157 |
+
"backbone.layers.31.mixer.D": "model-00007-of-00020.safetensors",
|
158 |
+
"backbone.layers.31.mixer.conv1d.bias": "model-00007-of-00020.safetensors",
|
159 |
+
"backbone.layers.31.mixer.conv1d.weight": "model-00007-of-00020.safetensors",
|
160 |
+
"backbone.layers.31.mixer.dt_bias": "model-00007-of-00020.safetensors",
|
161 |
+
"backbone.layers.31.mixer.in_proj.weight": "model-00007-of-00020.safetensors",
|
162 |
+
"backbone.layers.31.mixer.norm.weight": "model-00007-of-00020.safetensors",
|
163 |
+
"backbone.layers.31.mixer.out_proj.weight": "model-00007-of-00020.safetensors",
|
164 |
+
"backbone.layers.31.norm.weight": "model-00007-of-00020.safetensors",
|
165 |
+
"backbone.layers.32.mixer.down_proj.weight": "model-00007-of-00020.safetensors",
|
166 |
+
"backbone.layers.32.mixer.up_proj.weight": "model-00007-of-00020.safetensors",
|
167 |
+
"backbone.layers.32.norm.weight": "model-00007-of-00020.safetensors",
|
168 |
+
"backbone.layers.33.mixer.A_log": "model-00007-of-00020.safetensors",
|
169 |
+
"backbone.layers.33.mixer.D": "model-00007-of-00020.safetensors",
|
170 |
+
"backbone.layers.33.mixer.conv1d.bias": "model-00007-of-00020.safetensors",
|
171 |
+
"backbone.layers.33.mixer.conv1d.weight": "model-00007-of-00020.safetensors",
|
172 |
+
"backbone.layers.33.mixer.dt_bias": "model-00007-of-00020.safetensors",
|
173 |
+
"backbone.layers.33.mixer.in_proj.weight": "model-00007-of-00020.safetensors",
|
174 |
+
"backbone.layers.33.mixer.norm.weight": "model-00007-of-00020.safetensors",
|
175 |
+
"backbone.layers.33.mixer.out_proj.weight": "model-00008-of-00020.safetensors",
|
176 |
+
"backbone.layers.33.norm.weight": "model-00007-of-00020.safetensors",
|
177 |
+
"backbone.layers.34.mixer.down_proj.weight": "model-00008-of-00020.safetensors",
|
178 |
+
"backbone.layers.34.mixer.up_proj.weight": "model-00008-of-00020.safetensors",
|
179 |
+
"backbone.layers.34.norm.weight": "model-00008-of-00020.safetensors",
|
180 |
+
"backbone.layers.35.mixer.A_log": "model-00008-of-00020.safetensors",
|
181 |
+
"backbone.layers.35.mixer.D": "model-00008-of-00020.safetensors",
|
182 |
+
"backbone.layers.35.mixer.conv1d.bias": "model-00008-of-00020.safetensors",
|
183 |
+
"backbone.layers.35.mixer.conv1d.weight": "model-00008-of-00020.safetensors",
|
184 |
+
"backbone.layers.35.mixer.dt_bias": "model-00008-of-00020.safetensors",
|
185 |
+
"backbone.layers.35.mixer.in_proj.weight": "model-00008-of-00020.safetensors",
|
186 |
+
"backbone.layers.35.mixer.norm.weight": "model-00008-of-00020.safetensors",
|
187 |
+
"backbone.layers.35.mixer.out_proj.weight": "model-00008-of-00020.safetensors",
|
188 |
+
"backbone.layers.35.norm.weight": "model-00008-of-00020.safetensors",
|
189 |
+
"backbone.layers.36.mixer.down_proj.weight": "model-00008-of-00020.safetensors",
|
190 |
+
"backbone.layers.36.mixer.up_proj.weight": "model-00008-of-00020.safetensors",
|
191 |
+
"backbone.layers.36.norm.weight": "model-00008-of-00020.safetensors",
|
192 |
+
"backbone.layers.37.mixer.A_log": "model-00008-of-00020.safetensors",
|
193 |
+
"backbone.layers.37.mixer.D": "model-00008-of-00020.safetensors",
|
194 |
+
"backbone.layers.37.mixer.conv1d.bias": "model-00008-of-00020.safetensors",
|
195 |
+
"backbone.layers.37.mixer.conv1d.weight": "model-00008-of-00020.safetensors",
|
196 |
+
"backbone.layers.37.mixer.dt_bias": "model-00008-of-00020.safetensors",
|
197 |
+
"backbone.layers.37.mixer.in_proj.weight": "model-00008-of-00020.safetensors",
|
198 |
+
"backbone.layers.37.mixer.norm.weight": "model-00008-of-00020.safetensors",
|
199 |
+
"backbone.layers.37.mixer.out_proj.weight": "model-00008-of-00020.safetensors",
|
200 |
+
"backbone.layers.37.norm.weight": "model-00008-of-00020.safetensors",
|
201 |
+
"backbone.layers.38.mixer.k_proj.weight": "model-00008-of-00020.safetensors",
|
202 |
+
"backbone.layers.38.mixer.o_proj.weight": "model-00008-of-00020.safetensors",
|
203 |
+
"backbone.layers.38.mixer.q_proj.weight": "model-00008-of-00020.safetensors",
|
204 |
+
"backbone.layers.38.mixer.v_proj.weight": "model-00008-of-00020.safetensors",
|
205 |
+
"backbone.layers.38.norm.weight": "model-00008-of-00020.safetensors",
|
206 |
+
"backbone.layers.39.mixer.down_proj.weight": "model-00009-of-00020.safetensors",
|
207 |
+
"backbone.layers.39.mixer.up_proj.weight": "model-00008-of-00020.safetensors",
|
208 |
+
"backbone.layers.39.norm.weight": "model-00008-of-00020.safetensors",
|
209 |
+
"backbone.layers.4.mixer.A_log": "model-00002-of-00020.safetensors",
|
210 |
+
"backbone.layers.4.mixer.D": "model-00002-of-00020.safetensors",
|
211 |
+
"backbone.layers.4.mixer.conv1d.bias": "model-00002-of-00020.safetensors",
|
212 |
+
"backbone.layers.4.mixer.conv1d.weight": "model-00002-of-00020.safetensors",
|
213 |
+
"backbone.layers.4.mixer.dt_bias": "model-00002-of-00020.safetensors",
|
214 |
+
"backbone.layers.4.mixer.in_proj.weight": "model-00002-of-00020.safetensors",
|
215 |
+
"backbone.layers.4.mixer.norm.weight": "model-00002-of-00020.safetensors",
|
216 |
+
"backbone.layers.4.mixer.out_proj.weight": "model-00002-of-00020.safetensors",
|
217 |
+
"backbone.layers.4.norm.weight": "model-00002-of-00020.safetensors",
|
218 |
+
"backbone.layers.40.mixer.A_log": "model-00009-of-00020.safetensors",
|
219 |
+
"backbone.layers.40.mixer.D": "model-00009-of-00020.safetensors",
|
220 |
+
"backbone.layers.40.mixer.conv1d.bias": "model-00009-of-00020.safetensors",
|
221 |
+
"backbone.layers.40.mixer.conv1d.weight": "model-00009-of-00020.safetensors",
|
222 |
+
"backbone.layers.40.mixer.dt_bias": "model-00009-of-00020.safetensors",
|
223 |
+
"backbone.layers.40.mixer.in_proj.weight": "model-00009-of-00020.safetensors",
|
224 |
+
"backbone.layers.40.mixer.norm.weight": "model-00009-of-00020.safetensors",
|
225 |
+
"backbone.layers.40.mixer.out_proj.weight": "model-00009-of-00020.safetensors",
|
226 |
+
"backbone.layers.40.norm.weight": "model-00009-of-00020.safetensors",
|
227 |
+
"backbone.layers.41.mixer.down_proj.weight": "model-00009-of-00020.safetensors",
|
228 |
+
"backbone.layers.41.mixer.up_proj.weight": "model-00009-of-00020.safetensors",
|
229 |
+
"backbone.layers.41.norm.weight": "model-00009-of-00020.safetensors",
|
230 |
+
"backbone.layers.42.mixer.A_log": "model-00009-of-00020.safetensors",
|
231 |
+
"backbone.layers.42.mixer.D": "model-00009-of-00020.safetensors",
|
232 |
+
"backbone.layers.42.mixer.conv1d.bias": "model-00009-of-00020.safetensors",
|
233 |
+
"backbone.layers.42.mixer.conv1d.weight": "model-00009-of-00020.safetensors",
|
234 |
+
"backbone.layers.42.mixer.dt_bias": "model-00009-of-00020.safetensors",
|
235 |
+
"backbone.layers.42.mixer.in_proj.weight": "model-00009-of-00020.safetensors",
|
236 |
+
"backbone.layers.42.mixer.norm.weight": "model-00009-of-00020.safetensors",
|
237 |
+
"backbone.layers.42.mixer.out_proj.weight": "model-00009-of-00020.safetensors",
|
238 |
+
"backbone.layers.42.norm.weight": "model-00009-of-00020.safetensors",
|
239 |
+
"backbone.layers.43.mixer.down_proj.weight": "model-00009-of-00020.safetensors",
|
240 |
+
"backbone.layers.43.mixer.up_proj.weight": "model-00009-of-00020.safetensors",
|
241 |
+
"backbone.layers.43.norm.weight": "model-00009-of-00020.safetensors",
|
242 |
+
"backbone.layers.44.mixer.A_log": "model-00009-of-00020.safetensors",
|
243 |
+
"backbone.layers.44.mixer.D": "model-00009-of-00020.safetensors",
|
244 |
+
"backbone.layers.44.mixer.conv1d.bias": "model-00009-of-00020.safetensors",
|
245 |
+
"backbone.layers.44.mixer.conv1d.weight": "model-00009-of-00020.safetensors",
|
246 |
+
"backbone.layers.44.mixer.dt_bias": "model-00009-of-00020.safetensors",
|
247 |
+
"backbone.layers.44.mixer.in_proj.weight": "model-00009-of-00020.safetensors",
|
248 |
+
"backbone.layers.44.mixer.norm.weight": "model-00009-of-00020.safetensors",
|
249 |
+
"backbone.layers.44.mixer.out_proj.weight": "model-00010-of-00020.safetensors",
|
250 |
+
"backbone.layers.44.norm.weight": "model-00009-of-00020.safetensors",
|
251 |
+
"backbone.layers.45.mixer.down_proj.weight": "model-00010-of-00020.safetensors",
|
252 |
+
"backbone.layers.45.mixer.up_proj.weight": "model-00010-of-00020.safetensors",
|
253 |
+
"backbone.layers.45.norm.weight": "model-00010-of-00020.safetensors",
|
254 |
+
"backbone.layers.46.mixer.A_log": "model-00010-of-00020.safetensors",
|
255 |
+
"backbone.layers.46.mixer.D": "model-00010-of-00020.safetensors",
|
256 |
+
"backbone.layers.46.mixer.conv1d.bias": "model-00010-of-00020.safetensors",
|
257 |
+
"backbone.layers.46.mixer.conv1d.weight": "model-00010-of-00020.safetensors",
|
258 |
+
"backbone.layers.46.mixer.dt_bias": "model-00010-of-00020.safetensors",
|
259 |
+
"backbone.layers.46.mixer.in_proj.weight": "model-00010-of-00020.safetensors",
|
260 |
+
"backbone.layers.46.mixer.norm.weight": "model-00010-of-00020.safetensors",
|
261 |
+
"backbone.layers.46.mixer.out_proj.weight": "model-00010-of-00020.safetensors",
|
262 |
+
"backbone.layers.46.norm.weight": "model-00010-of-00020.safetensors",
|
263 |
+
"backbone.layers.47.mixer.down_proj.weight": "model-00010-of-00020.safetensors",
|
264 |
+
"backbone.layers.47.mixer.up_proj.weight": "model-00010-of-00020.safetensors",
|
265 |
+
"backbone.layers.47.norm.weight": "model-00010-of-00020.safetensors",
|
266 |
+
"backbone.layers.48.mixer.A_log": "model-00010-of-00020.safetensors",
|
267 |
+
"backbone.layers.48.mixer.D": "model-00010-of-00020.safetensors",
|
268 |
+
"backbone.layers.48.mixer.conv1d.bias": "model-00010-of-00020.safetensors",
|
269 |
+
"backbone.layers.48.mixer.conv1d.weight": "model-00010-of-00020.safetensors",
|
270 |
+
"backbone.layers.48.mixer.dt_bias": "model-00010-of-00020.safetensors",
|
271 |
+
"backbone.layers.48.mixer.in_proj.weight": "model-00010-of-00020.safetensors",
|
272 |
+
"backbone.layers.48.mixer.norm.weight": "model-00010-of-00020.safetensors",
|
273 |
+
"backbone.layers.48.mixer.out_proj.weight": "model-00010-of-00020.safetensors",
|
274 |
+
"backbone.layers.48.norm.weight": "model-00010-of-00020.safetensors",
|
275 |
+
"backbone.layers.49.mixer.k_proj.weight": "model-00010-of-00020.safetensors",
|
276 |
+
"backbone.layers.49.mixer.o_proj.weight": "model-00010-of-00020.safetensors",
|
277 |
+
"backbone.layers.49.mixer.q_proj.weight": "model-00010-of-00020.safetensors",
|
278 |
+
"backbone.layers.49.mixer.v_proj.weight": "model-00010-of-00020.safetensors",
|
279 |
+
"backbone.layers.49.norm.weight": "model-00010-of-00020.safetensors",
|
280 |
+
"backbone.layers.5.mixer.down_proj.weight": "model-00002-of-00020.safetensors",
|
281 |
+
"backbone.layers.5.mixer.up_proj.weight": "model-00002-of-00020.safetensors",
|
282 |
+
"backbone.layers.5.norm.weight": "model-00002-of-00020.safetensors",
|
283 |
+
"backbone.layers.50.mixer.down_proj.weight": "model-00011-of-00020.safetensors",
|
284 |
+
"backbone.layers.50.mixer.up_proj.weight": "model-00010-of-00020.safetensors",
|
285 |
+
"backbone.layers.50.norm.weight": "model-00010-of-00020.safetensors",
|
286 |
+
"backbone.layers.51.mixer.A_log": "model-00011-of-00020.safetensors",
|
287 |
+
"backbone.layers.51.mixer.D": "model-00011-of-00020.safetensors",
|
288 |
+
"backbone.layers.51.mixer.conv1d.bias": "model-00011-of-00020.safetensors",
|
289 |
+
"backbone.layers.51.mixer.conv1d.weight": "model-00011-of-00020.safetensors",
|
290 |
+
"backbone.layers.51.mixer.dt_bias": "model-00011-of-00020.safetensors",
|
291 |
+
"backbone.layers.51.mixer.in_proj.weight": "model-00011-of-00020.safetensors",
|
292 |
+
"backbone.layers.51.mixer.norm.weight": "model-00011-of-00020.safetensors",
|
293 |
+
"backbone.layers.51.mixer.out_proj.weight": "model-00011-of-00020.safetensors",
|
294 |
+
"backbone.layers.51.norm.weight": "model-00011-of-00020.safetensors",
|
295 |
+
"backbone.layers.52.mixer.down_proj.weight": "model-00011-of-00020.safetensors",
|
296 |
+
"backbone.layers.52.mixer.up_proj.weight": "model-00011-of-00020.safetensors",
|
297 |
+
"backbone.layers.52.norm.weight": "model-00011-of-00020.safetensors",
|
298 |
+
"backbone.layers.53.mixer.A_log": "model-00011-of-00020.safetensors",
|
299 |
+
"backbone.layers.53.mixer.D": "model-00011-of-00020.safetensors",
|
300 |
+
"backbone.layers.53.mixer.conv1d.bias": "model-00011-of-00020.safetensors",
|
301 |
+
"backbone.layers.53.mixer.conv1d.weight": "model-00011-of-00020.safetensors",
|
302 |
+
"backbone.layers.53.mixer.dt_bias": "model-00011-of-00020.safetensors",
|
303 |
+
"backbone.layers.53.mixer.in_proj.weight": "model-00011-of-00020.safetensors",
|
304 |
+
"backbone.layers.53.mixer.norm.weight": "model-00011-of-00020.safetensors",
|
305 |
+
"backbone.layers.53.mixer.out_proj.weight": "model-00011-of-00020.safetensors",
|
306 |
+
"backbone.layers.53.norm.weight": "model-00011-of-00020.safetensors",
|
307 |
+
"backbone.layers.54.mixer.down_proj.weight": "model-00011-of-00020.safetensors",
|
308 |
+
"backbone.layers.54.mixer.up_proj.weight": "model-00011-of-00020.safetensors",
|
309 |
+
"backbone.layers.54.norm.weight": "model-00011-of-00020.safetensors",
|
310 |
+
"backbone.layers.55.mixer.A_log": "model-00011-of-00020.safetensors",
|
311 |
+
"backbone.layers.55.mixer.D": "model-00011-of-00020.safetensors",
|
312 |
+
"backbone.layers.55.mixer.conv1d.bias": "model-00011-of-00020.safetensors",
|
313 |
+
"backbone.layers.55.mixer.conv1d.weight": "model-00011-of-00020.safetensors",
|
314 |
+
"backbone.layers.55.mixer.dt_bias": "model-00011-of-00020.safetensors",
|
315 |
+
"backbone.layers.55.mixer.in_proj.weight": "model-00011-of-00020.safetensors",
|
316 |
+
"backbone.layers.55.mixer.norm.weight": "model-00011-of-00020.safetensors",
|
317 |
+
"backbone.layers.55.mixer.out_proj.weight": "model-00012-of-00020.safetensors",
|
318 |
+
"backbone.layers.55.norm.weight": "model-00011-of-00020.safetensors",
|
319 |
+
"backbone.layers.56.mixer.down_proj.weight": "model-00012-of-00020.safetensors",
|
320 |
+
"backbone.layers.56.mixer.up_proj.weight": "model-00012-of-00020.safetensors",
|
321 |
+
"backbone.layers.56.norm.weight": "model-00012-of-00020.safetensors",
|
322 |
+
"backbone.layers.57.mixer.A_log": "model-00012-of-00020.safetensors",
|
323 |
+
"backbone.layers.57.mixer.D": "model-00012-of-00020.safetensors",
|
324 |
+
"backbone.layers.57.mixer.conv1d.bias": "model-00012-of-00020.safetensors",
|
325 |
+
"backbone.layers.57.mixer.conv1d.weight": "model-00012-of-00020.safetensors",
|
326 |
+
"backbone.layers.57.mixer.dt_bias": "model-00012-of-00020.safetensors",
|
327 |
+
"backbone.layers.57.mixer.in_proj.weight": "model-00012-of-00020.safetensors",
|
328 |
+
"backbone.layers.57.mixer.norm.weight": "model-00012-of-00020.safetensors",
|
329 |
+
"backbone.layers.57.mixer.out_proj.weight": "model-00012-of-00020.safetensors",
|
330 |
+
"backbone.layers.57.norm.weight": "model-00012-of-00020.safetensors",
|
331 |
+
"backbone.layers.58.mixer.down_proj.weight": "model-00012-of-00020.safetensors",
|
332 |
+
"backbone.layers.58.mixer.up_proj.weight": "model-00012-of-00020.safetensors",
|
333 |
+
"backbone.layers.58.norm.weight": "model-00012-of-00020.safetensors",
|
334 |
+
"backbone.layers.59.mixer.A_log": "model-00012-of-00020.safetensors",
|
335 |
+
"backbone.layers.59.mixer.D": "model-00012-of-00020.safetensors",
|
336 |
+
"backbone.layers.59.mixer.conv1d.bias": "model-00012-of-00020.safetensors",
|
337 |
+
"backbone.layers.59.mixer.conv1d.weight": "model-00012-of-00020.safetensors",
|
338 |
+
"backbone.layers.59.mixer.dt_bias": "model-00012-of-00020.safetensors",
|
339 |
+
"backbone.layers.59.mixer.in_proj.weight": "model-00012-of-00020.safetensors",
|
340 |
+
"backbone.layers.59.mixer.norm.weight": "model-00012-of-00020.safetensors",
|
341 |
+
"backbone.layers.59.mixer.out_proj.weight": "model-00012-of-00020.safetensors",
|
342 |
+
"backbone.layers.59.norm.weight": "model-00012-of-00020.safetensors",
|
343 |
+
"backbone.layers.6.mixer.A_log": "model-00002-of-00020.safetensors",
|
344 |
+
"backbone.layers.6.mixer.D": "model-00002-of-00020.safetensors",
|
345 |
+
"backbone.layers.6.mixer.conv1d.bias": "model-00002-of-00020.safetensors",
|
346 |
+
"backbone.layers.6.mixer.conv1d.weight": "model-00002-of-00020.safetensors",
|
347 |
+
"backbone.layers.6.mixer.dt_bias": "model-00002-of-00020.safetensors",
|
348 |
+
"backbone.layers.6.mixer.in_proj.weight": "model-00002-of-00020.safetensors",
|
349 |
+
"backbone.layers.6.mixer.norm.weight": "model-00002-of-00020.safetensors",
|
350 |
+
"backbone.layers.6.mixer.out_proj.weight": "model-00002-of-00020.safetensors",
|
351 |
+
"backbone.layers.6.norm.weight": "model-00002-of-00020.safetensors",
|
352 |
+
"backbone.layers.60.mixer.k_proj.weight": "model-00012-of-00020.safetensors",
|
353 |
+
"backbone.layers.60.mixer.o_proj.weight": "model-00012-of-00020.safetensors",
|
354 |
+
"backbone.layers.60.mixer.q_proj.weight": "model-00012-of-00020.safetensors",
|
355 |
+
"backbone.layers.60.mixer.v_proj.weight": "model-00012-of-00020.safetensors",
|
356 |
+
"backbone.layers.60.norm.weight": "model-00012-of-00020.safetensors",
|
357 |
+
"backbone.layers.61.mixer.down_proj.weight": "model-00013-of-00020.safetensors",
|
358 |
+
"backbone.layers.61.mixer.up_proj.weight": "model-00012-of-00020.safetensors",
|
359 |
+
"backbone.layers.61.norm.weight": "model-00012-of-00020.safetensors",
|
360 |
+
"backbone.layers.62.mixer.A_log": "model-00013-of-00020.safetensors",
|
361 |
+
"backbone.layers.62.mixer.D": "model-00013-of-00020.safetensors",
|
362 |
+
"backbone.layers.62.mixer.conv1d.bias": "model-00013-of-00020.safetensors",
|
363 |
+
"backbone.layers.62.mixer.conv1d.weight": "model-00013-of-00020.safetensors",
|
364 |
+
"backbone.layers.62.mixer.dt_bias": "model-00013-of-00020.safetensors",
|
365 |
+
"backbone.layers.62.mixer.in_proj.weight": "model-00013-of-00020.safetensors",
|
366 |
+
"backbone.layers.62.mixer.norm.weight": "model-00013-of-00020.safetensors",
|
367 |
+
"backbone.layers.62.mixer.out_proj.weight": "model-00013-of-00020.safetensors",
|
368 |
+
"backbone.layers.62.norm.weight": "model-00013-of-00020.safetensors",
|
369 |
+
"backbone.layers.63.mixer.down_proj.weight": "model-00013-of-00020.safetensors",
|
370 |
+
"backbone.layers.63.mixer.up_proj.weight": "model-00013-of-00020.safetensors",
|
371 |
+
"backbone.layers.63.norm.weight": "model-00013-of-00020.safetensors",
|
372 |
+
"backbone.layers.64.mixer.A_log": "model-00013-of-00020.safetensors",
|
373 |
+
"backbone.layers.64.mixer.D": "model-00013-of-00020.safetensors",
|
374 |
+
"backbone.layers.64.mixer.conv1d.bias": "model-00013-of-00020.safetensors",
|
375 |
+
"backbone.layers.64.mixer.conv1d.weight": "model-00013-of-00020.safetensors",
|
376 |
+
"backbone.layers.64.mixer.dt_bias": "model-00013-of-00020.safetensors",
|
377 |
+
"backbone.layers.64.mixer.in_proj.weight": "model-00013-of-00020.safetensors",
|
378 |
+
"backbone.layers.64.mixer.norm.weight": "model-00013-of-00020.safetensors",
|
379 |
+
"backbone.layers.64.mixer.out_proj.weight": "model-00013-of-00020.safetensors",
|
380 |
+
"backbone.layers.64.norm.weight": "model-00013-of-00020.safetensors",
|
381 |
+
"backbone.layers.65.mixer.down_proj.weight": "model-00013-of-00020.safetensors",
|
382 |
+
"backbone.layers.65.mixer.up_proj.weight": "model-00013-of-00020.safetensors",
|
383 |
+
"backbone.layers.65.norm.weight": "model-00013-of-00020.safetensors",
|
384 |
+
"backbone.layers.66.mixer.A_log": "model-00013-of-00020.safetensors",
|
385 |
+
"backbone.layers.66.mixer.D": "model-00013-of-00020.safetensors",
|
386 |
+
"backbone.layers.66.mixer.conv1d.bias": "model-00013-of-00020.safetensors",
|
387 |
+
"backbone.layers.66.mixer.conv1d.weight": "model-00013-of-00020.safetensors",
|
388 |
+
"backbone.layers.66.mixer.dt_bias": "model-00013-of-00020.safetensors",
|
389 |
+
"backbone.layers.66.mixer.in_proj.weight": "model-00013-of-00020.safetensors",
|
390 |
+
"backbone.layers.66.mixer.norm.weight": "model-00013-of-00020.safetensors",
|
391 |
+
"backbone.layers.66.mixer.out_proj.weight": "model-00014-of-00020.safetensors",
|
392 |
+
"backbone.layers.66.norm.weight": "model-00013-of-00020.safetensors",
|
393 |
+
"backbone.layers.67.mixer.down_proj.weight": "model-00014-of-00020.safetensors",
|
394 |
+
"backbone.layers.67.mixer.up_proj.weight": "model-00014-of-00020.safetensors",
|
395 |
+
"backbone.layers.67.norm.weight": "model-00014-of-00020.safetensors",
|
396 |
+
"backbone.layers.68.mixer.A_log": "model-00014-of-00020.safetensors",
|
397 |
+
"backbone.layers.68.mixer.D": "model-00014-of-00020.safetensors",
|
398 |
+
"backbone.layers.68.mixer.conv1d.bias": "model-00014-of-00020.safetensors",
|
399 |
+
"backbone.layers.68.mixer.conv1d.weight": "model-00014-of-00020.safetensors",
|
400 |
+
"backbone.layers.68.mixer.dt_bias": "model-00014-of-00020.safetensors",
|
401 |
+
"backbone.layers.68.mixer.in_proj.weight": "model-00014-of-00020.safetensors",
|
402 |
+
"backbone.layers.68.mixer.norm.weight": "model-00014-of-00020.safetensors",
|
403 |
+
"backbone.layers.68.mixer.out_proj.weight": "model-00014-of-00020.safetensors",
|
404 |
+
"backbone.layers.68.norm.weight": "model-00014-of-00020.safetensors",
|
405 |
+
"backbone.layers.69.mixer.down_proj.weight": "model-00014-of-00020.safetensors",
|
406 |
+
"backbone.layers.69.mixer.up_proj.weight": "model-00014-of-00020.safetensors",
|
407 |
+
"backbone.layers.69.norm.weight": "model-00014-of-00020.safetensors",
|
408 |
+
"backbone.layers.7.mixer.down_proj.weight": "model-00002-of-00020.safetensors",
|
409 |
+
"backbone.layers.7.mixer.up_proj.weight": "model-00002-of-00020.safetensors",
|
410 |
+
"backbone.layers.7.norm.weight": "model-00002-of-00020.safetensors",
|
411 |
+
"backbone.layers.70.mixer.A_log": "model-00014-of-00020.safetensors",
|
412 |
+
"backbone.layers.70.mixer.D": "model-00014-of-00020.safetensors",
|
413 |
+
"backbone.layers.70.mixer.conv1d.bias": "model-00014-of-00020.safetensors",
|
414 |
+
"backbone.layers.70.mixer.conv1d.weight": "model-00014-of-00020.safetensors",
|
415 |
+
"backbone.layers.70.mixer.dt_bias": "model-00014-of-00020.safetensors",
|
416 |
+
"backbone.layers.70.mixer.in_proj.weight": "model-00014-of-00020.safetensors",
|
417 |
+
"backbone.layers.70.mixer.norm.weight": "model-00014-of-00020.safetensors",
|
418 |
+
"backbone.layers.70.mixer.out_proj.weight": "model-00014-of-00020.safetensors",
|
419 |
+
"backbone.layers.70.norm.weight": "model-00014-of-00020.safetensors",
|
420 |
+
"backbone.layers.71.mixer.down_proj.weight": "model-00015-of-00020.safetensors",
|
421 |
+
"backbone.layers.71.mixer.up_proj.weight": "model-00014-of-00020.safetensors",
|
422 |
+
"backbone.layers.71.norm.weight": "model-00014-of-00020.safetensors",
|
423 |
+
"backbone.layers.72.mixer.A_log": "model-00015-of-00020.safetensors",
|
424 |
+
"backbone.layers.72.mixer.D": "model-00015-of-00020.safetensors",
|
425 |
+
"backbone.layers.72.mixer.conv1d.bias": "model-00015-of-00020.safetensors",
|
426 |
+
"backbone.layers.72.mixer.conv1d.weight": "model-00015-of-00020.safetensors",
|
427 |
+
"backbone.layers.72.mixer.dt_bias": "model-00015-of-00020.safetensors",
|
428 |
+
"backbone.layers.72.mixer.in_proj.weight": "model-00015-of-00020.safetensors",
|
429 |
+
"backbone.layers.72.mixer.norm.weight": "model-00015-of-00020.safetensors",
|
430 |
+
"backbone.layers.72.mixer.out_proj.weight": "model-00015-of-00020.safetensors",
|
431 |
+
"backbone.layers.72.norm.weight": "model-00015-of-00020.safetensors",
|
432 |
+
"backbone.layers.73.mixer.down_proj.weight": "model-00015-of-00020.safetensors",
|
433 |
+
"backbone.layers.73.mixer.up_proj.weight": "model-00015-of-00020.safetensors",
|
434 |
+
"backbone.layers.73.norm.weight": "model-00015-of-00020.safetensors",
|
435 |
+
"backbone.layers.74.mixer.A_log": "model-00015-of-00020.safetensors",
|
436 |
+
"backbone.layers.74.mixer.D": "model-00015-of-00020.safetensors",
|
437 |
+
"backbone.layers.74.mixer.conv1d.bias": "model-00015-of-00020.safetensors",
|
438 |
+
"backbone.layers.74.mixer.conv1d.weight": "model-00015-of-00020.safetensors",
|
439 |
+
"backbone.layers.74.mixer.dt_bias": "model-00015-of-00020.safetensors",
|
440 |
+
"backbone.layers.74.mixer.in_proj.weight": "model-00015-of-00020.safetensors",
|
441 |
+
"backbone.layers.74.mixer.norm.weight": "model-00015-of-00020.safetensors",
|
442 |
+
"backbone.layers.74.mixer.out_proj.weight": "model-00015-of-00020.safetensors",
|
443 |
+
"backbone.layers.74.norm.weight": "model-00015-of-00020.safetensors",
|
444 |
+
"backbone.layers.75.mixer.down_proj.weight": "model-00015-of-00020.safetensors",
|
445 |
+
"backbone.layers.75.mixer.up_proj.weight": "model-00015-of-00020.safetensors",
|
446 |
+
"backbone.layers.75.norm.weight": "model-00015-of-00020.safetensors",
|
447 |
+
"backbone.layers.76.mixer.down_proj.weight": "model-00016-of-00020.safetensors",
|
448 |
+
"backbone.layers.76.mixer.up_proj.weight": "model-00015-of-00020.safetensors",
|
449 |
+
"backbone.layers.76.norm.weight": "model-00015-of-00020.safetensors",
|
450 |
+
"backbone.layers.77.mixer.down_proj.weight": "model-00016-of-00020.safetensors",
|
451 |
+
"backbone.layers.77.mixer.up_proj.weight": "model-00016-of-00020.safetensors",
|
452 |
+
"backbone.layers.77.norm.weight": "model-00016-of-00020.safetensors",
|
453 |
+
"backbone.layers.78.mixer.A_log": "model-00016-of-00020.safetensors",
|
454 |
+
"backbone.layers.78.mixer.D": "model-00016-of-00020.safetensors",
|
455 |
+
"backbone.layers.78.mixer.conv1d.bias": "model-00016-of-00020.safetensors",
|
456 |
+
"backbone.layers.78.mixer.conv1d.weight": "model-00016-of-00020.safetensors",
|
457 |
+
"backbone.layers.78.mixer.dt_bias": "model-00016-of-00020.safetensors",
|
458 |
+
"backbone.layers.78.mixer.in_proj.weight": "model-00016-of-00020.safetensors",
|
459 |
+
"backbone.layers.78.mixer.norm.weight": "model-00016-of-00020.safetensors",
|
460 |
+
"backbone.layers.78.mixer.out_proj.weight": "model-00016-of-00020.safetensors",
|
461 |
+
"backbone.layers.78.norm.weight": "model-00016-of-00020.safetensors",
|
462 |
+
"backbone.layers.79.mixer.A_log": "model-00016-of-00020.safetensors",
|
463 |
+
"backbone.layers.79.mixer.D": "model-00016-of-00020.safetensors",
|
464 |
+
"backbone.layers.79.mixer.conv1d.bias": "model-00016-of-00020.safetensors",
|
465 |
+
"backbone.layers.79.mixer.conv1d.weight": "model-00016-of-00020.safetensors",
|
466 |
+
"backbone.layers.79.mixer.dt_bias": "model-00016-of-00020.safetensors",
|
467 |
+
"backbone.layers.79.mixer.in_proj.weight": "model-00016-of-00020.safetensors",
|
468 |
+
"backbone.layers.79.mixer.norm.weight": "model-00016-of-00020.safetensors",
|
469 |
+
"backbone.layers.79.mixer.out_proj.weight": "model-00016-of-00020.safetensors",
|
470 |
+
"backbone.layers.79.norm.weight": "model-00016-of-00020.safetensors",
|
471 |
+
"backbone.layers.8.mixer.A_log": "model-00002-of-00020.safetensors",
|
472 |
+
"backbone.layers.8.mixer.D": "model-00002-of-00020.safetensors",
|
473 |
+
"backbone.layers.8.mixer.conv1d.bias": "model-00002-of-00020.safetensors",
|
474 |
+
"backbone.layers.8.mixer.conv1d.weight": "model-00002-of-00020.safetensors",
|
475 |
+
"backbone.layers.8.mixer.dt_bias": "model-00002-of-00020.safetensors",
|
476 |
+
"backbone.layers.8.mixer.in_proj.weight": "model-00003-of-00020.safetensors",
|
477 |
+
"backbone.layers.8.mixer.norm.weight": "model-00003-of-00020.safetensors",
|
478 |
+
"backbone.layers.8.mixer.out_proj.weight": "model-00003-of-00020.safetensors",
|
479 |
+
"backbone.layers.8.norm.weight": "model-00002-of-00020.safetensors",
|
480 |
+
"backbone.layers.80.mixer.down_proj.weight": "model-00016-of-00020.safetensors",
|
481 |
+
"backbone.layers.80.mixer.up_proj.weight": "model-00016-of-00020.safetensors",
|
482 |
+
"backbone.layers.80.norm.weight": "model-00016-of-00020.safetensors",
|
483 |
+
"backbone.layers.81.mixer.down_proj.weight": "model-00017-of-00020.safetensors",
|
484 |
+
"backbone.layers.81.mixer.up_proj.weight": "model-00016-of-00020.safetensors",
|
485 |
+
"backbone.layers.81.norm.weight": "model-00016-of-00020.safetensors",
|
486 |
+
"backbone.layers.82.mixer.down_proj.weight": "model-00017-of-00020.safetensors",
|
487 |
+
"backbone.layers.82.mixer.up_proj.weight": "model-00017-of-00020.safetensors",
|
488 |
+
"backbone.layers.82.norm.weight": "model-00017-of-00020.safetensors",
|
489 |
+
"backbone.layers.83.mixer.A_log": "model-00017-of-00020.safetensors",
|
490 |
+
"backbone.layers.83.mixer.D": "model-00017-of-00020.safetensors",
|
491 |
+
"backbone.layers.83.mixer.conv1d.bias": "model-00017-of-00020.safetensors",
|
492 |
+
"backbone.layers.83.mixer.conv1d.weight": "model-00017-of-00020.safetensors",
|
493 |
+
"backbone.layers.83.mixer.dt_bias": "model-00017-of-00020.safetensors",
|
494 |
+
"backbone.layers.83.mixer.in_proj.weight": "model-00017-of-00020.safetensors",
|
495 |
+
"backbone.layers.83.mixer.norm.weight": "model-00017-of-00020.safetensors",
|
496 |
+
"backbone.layers.83.mixer.out_proj.weight": "model-00017-of-00020.safetensors",
|
497 |
+
"backbone.layers.83.norm.weight": "model-00017-of-00020.safetensors",
|
498 |
+
"backbone.layers.84.mixer.down_proj.weight": "model-00017-of-00020.safetensors",
|
499 |
+
"backbone.layers.84.mixer.up_proj.weight": "model-00017-of-00020.safetensors",
|
500 |
+
"backbone.layers.84.norm.weight": "model-00017-of-00020.safetensors",
|
501 |
+
"backbone.layers.85.mixer.A_log": "model-00017-of-00020.safetensors",
|
502 |
+
"backbone.layers.85.mixer.D": "model-00017-of-00020.safetensors",
|
503 |
+
"backbone.layers.85.mixer.conv1d.bias": "model-00017-of-00020.safetensors",
|
504 |
+
"backbone.layers.85.mixer.conv1d.weight": "model-00017-of-00020.safetensors",
|
505 |
+
"backbone.layers.85.mixer.dt_bias": "model-00017-of-00020.safetensors",
|
506 |
+
"backbone.layers.85.mixer.in_proj.weight": "model-00017-of-00020.safetensors",
|
507 |
+
"backbone.layers.85.mixer.norm.weight": "model-00017-of-00020.safetensors",
|
508 |
+
"backbone.layers.85.mixer.out_proj.weight": "model-00017-of-00020.safetensors",
|
509 |
+
"backbone.layers.85.norm.weight": "model-00017-of-00020.safetensors",
|
510 |
+
"backbone.layers.86.mixer.k_proj.weight": "model-00017-of-00020.safetensors",
|
511 |
+
"backbone.layers.86.mixer.o_proj.weight": "model-00017-of-00020.safetensors",
|
512 |
+
"backbone.layers.86.mixer.q_proj.weight": "model-00017-of-00020.safetensors",
|
513 |
+
"backbone.layers.86.mixer.v_proj.weight": "model-00017-of-00020.safetensors",
|
514 |
+
"backbone.layers.86.norm.weight": "model-00017-of-00020.safetensors",
|
515 |
+
"backbone.layers.87.mixer.down_proj.weight": "model-00018-of-00020.safetensors",
|
516 |
+
"backbone.layers.87.mixer.up_proj.weight": "model-00018-of-00020.safetensors",
|
517 |
+
"backbone.layers.87.norm.weight": "model-00017-of-00020.safetensors",
|
518 |
+
"backbone.layers.88.mixer.A_log": "model-00018-of-00020.safetensors",
|
519 |
+
"backbone.layers.88.mixer.D": "model-00018-of-00020.safetensors",
|
520 |
+
"backbone.layers.88.mixer.conv1d.bias": "model-00018-of-00020.safetensors",
|
521 |
+
"backbone.layers.88.mixer.conv1d.weight": "model-00018-of-00020.safetensors",
|
522 |
+
"backbone.layers.88.mixer.dt_bias": "model-00018-of-00020.safetensors",
|
523 |
+
"backbone.layers.88.mixer.in_proj.weight": "model-00018-of-00020.safetensors",
|
524 |
+
"backbone.layers.88.mixer.norm.weight": "model-00018-of-00020.safetensors",
|
525 |
+
"backbone.layers.88.mixer.out_proj.weight": "model-00018-of-00020.safetensors",
|
526 |
+
"backbone.layers.88.norm.weight": "model-00018-of-00020.safetensors",
|
527 |
+
"backbone.layers.89.mixer.down_proj.weight": "model-00018-of-00020.safetensors",
|
528 |
+
"backbone.layers.89.mixer.up_proj.weight": "model-00018-of-00020.safetensors",
|
529 |
+
"backbone.layers.89.norm.weight": "model-00018-of-00020.safetensors",
|
530 |
+
"backbone.layers.9.mixer.down_proj.weight": "model-00003-of-00020.safetensors",
|
531 |
+
"backbone.layers.9.mixer.up_proj.weight": "model-00003-of-00020.safetensors",
|
532 |
+
"backbone.layers.9.norm.weight": "model-00003-of-00020.safetensors",
|
533 |
+
"backbone.layers.90.mixer.A_log": "model-00018-of-00020.safetensors",
|
534 |
+
"backbone.layers.90.mixer.D": "model-00018-of-00020.safetensors",
|
535 |
+
"backbone.layers.90.mixer.conv1d.bias": "model-00018-of-00020.safetensors",
|
536 |
+
"backbone.layers.90.mixer.conv1d.weight": "model-00018-of-00020.safetensors",
|
537 |
+
"backbone.layers.90.mixer.dt_bias": "model-00018-of-00020.safetensors",
|
538 |
+
"backbone.layers.90.mixer.in_proj.weight": "model-00018-of-00020.safetensors",
|
539 |
+
"backbone.layers.90.mixer.norm.weight": "model-00018-of-00020.safetensors",
|
540 |
+
"backbone.layers.90.mixer.out_proj.weight": "model-00018-of-00020.safetensors",
|
541 |
+
"backbone.layers.90.norm.weight": "model-00018-of-00020.safetensors",
|
542 |
+
"backbone.layers.91.mixer.down_proj.weight": "model-00018-of-00020.safetensors",
|
543 |
+
"backbone.layers.91.mixer.up_proj.weight": "model-00018-of-00020.safetensors",
|
544 |
+
"backbone.layers.91.norm.weight": "model-00018-of-00020.safetensors",
|
545 |
+
"backbone.layers.92.mixer.A_log": "model-00018-of-00020.safetensors",
|
546 |
+
"backbone.layers.92.mixer.D": "model-00018-of-00020.safetensors",
|
547 |
+
"backbone.layers.92.mixer.conv1d.bias": "model-00018-of-00020.safetensors",
|
548 |
+
"backbone.layers.92.mixer.conv1d.weight": "model-00018-of-00020.safetensors",
|
549 |
+
"backbone.layers.92.mixer.dt_bias": "model-00018-of-00020.safetensors",
|
550 |
+
"backbone.layers.92.mixer.in_proj.weight": "model-00019-of-00020.safetensors",
|
551 |
+
"backbone.layers.92.mixer.norm.weight": "model-00019-of-00020.safetensors",
|
552 |
+
"backbone.layers.92.mixer.out_proj.weight": "model-00019-of-00020.safetensors",
|
553 |
+
"backbone.layers.92.norm.weight": "model-00018-of-00020.safetensors",
|
554 |
+
"backbone.layers.93.mixer.down_proj.weight": "model-00019-of-00020.safetensors",
|
555 |
+
"backbone.layers.93.mixer.up_proj.weight": "model-00019-of-00020.safetensors",
|
556 |
+
"backbone.layers.93.norm.weight": "model-00019-of-00020.safetensors",
|
557 |
+
"backbone.layers.94.mixer.A_log": "model-00019-of-00020.safetensors",
|
558 |
+
"backbone.layers.94.mixer.D": "model-00019-of-00020.safetensors",
|
559 |
+
"backbone.layers.94.mixer.conv1d.bias": "model-00019-of-00020.safetensors",
|
560 |
+
"backbone.layers.94.mixer.conv1d.weight": "model-00019-of-00020.safetensors",
|
561 |
+
"backbone.layers.94.mixer.dt_bias": "model-00019-of-00020.safetensors",
|
562 |
+
"backbone.layers.94.mixer.in_proj.weight": "model-00019-of-00020.safetensors",
|
563 |
+
"backbone.layers.94.mixer.norm.weight": "model-00019-of-00020.safetensors",
|
564 |
+
"backbone.layers.94.mixer.out_proj.weight": "model-00019-of-00020.safetensors",
|
565 |
+
"backbone.layers.94.norm.weight": "model-00019-of-00020.safetensors",
|
566 |
+
"backbone.layers.95.mixer.down_proj.weight": "model-00019-of-00020.safetensors",
|
567 |
+
"backbone.layers.95.mixer.up_proj.weight": "model-00019-of-00020.safetensors",
|
568 |
+
"backbone.layers.95.norm.weight": "model-00019-of-00020.safetensors",
|
569 |
+
"backbone.layers.96.mixer.A_log": "model-00019-of-00020.safetensors",
|
570 |
+
"backbone.layers.96.mixer.D": "model-00019-of-00020.safetensors",
|
571 |
+
"backbone.layers.96.mixer.conv1d.bias": "model-00019-of-00020.safetensors",
|
572 |
+
"backbone.layers.96.mixer.conv1d.weight": "model-00019-of-00020.safetensors",
|
573 |
+
"backbone.layers.96.mixer.dt_bias": "model-00019-of-00020.safetensors",
|
574 |
+
"backbone.layers.96.mixer.in_proj.weight": "model-00019-of-00020.safetensors",
|
575 |
+
"backbone.layers.96.mixer.norm.weight": "model-00019-of-00020.safetensors",
|
576 |
+
"backbone.layers.96.mixer.out_proj.weight": "model-00019-of-00020.safetensors",
|
577 |
+
"backbone.layers.96.norm.weight": "model-00019-of-00020.safetensors",
|
578 |
+
"backbone.layers.97.mixer.down_proj.weight": "model-00020-of-00020.safetensors",
|
579 |
+
"backbone.layers.97.mixer.up_proj.weight": "model-00020-of-00020.safetensors",
|
580 |
+
"backbone.layers.97.norm.weight": "model-00019-of-00020.safetensors",
|
581 |
+
"backbone.norm_f.weight": "model-00020-of-00020.safetensors",
|
582 |
+
"lm_head.weight": "model-00020-of-00020.safetensors"
|
583 |
+
}
|
584 |
+
}
|
modeling_nemotron_h.py
ADDED
@@ -0,0 +1,1632 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2024 HuggingFace Inc. team.
|
3 |
+
# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
|
4 |
+
#
|
5 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6 |
+
# you may not use this file except in compliance with the License.
|
7 |
+
# You may obtain a copy of the License at
|
8 |
+
#
|
9 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10 |
+
#
|
11 |
+
# Unless required by applicable law or agreed to in writing, software
|
12 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14 |
+
# See the License for the specific language governing permissions and
|
15 |
+
# limitations under the License.
|
16 |
+
"""PyTorch NemotronH model."""
|
17 |
+
|
18 |
+
import math
|
19 |
+
from dataclasses import dataclass
|
20 |
+
from typing import Any, Dict, Optional, Tuple, Union
|
21 |
+
|
22 |
+
import torch
|
23 |
+
import torch.utils.checkpoint
|
24 |
+
from torch import nn
|
25 |
+
from torch.nn import CrossEntropyLoss
|
26 |
+
|
27 |
+
from transformers.activations import ACT2FN
|
28 |
+
from transformers.cache_utils import DynamicCache # we need __iter__ and __len__ of pkv
|
29 |
+
from transformers.generation import GenerationMixin
|
30 |
+
from transformers.modeling_attn_mask_utils import (
|
31 |
+
AttentionMaskConverter,
|
32 |
+
)
|
33 |
+
from transformers.modeling_utils import PreTrainedModel
|
34 |
+
from transformers.utils import (
|
35 |
+
ModelOutput,
|
36 |
+
add_code_sample_docstrings,
|
37 |
+
add_start_docstrings,
|
38 |
+
add_start_docstrings_to_model_forward,
|
39 |
+
logging,
|
40 |
+
)
|
41 |
+
from transformers.utils.import_utils import (
|
42 |
+
is_causal_conv1d_available,
|
43 |
+
is_flash_attn_2_available,
|
44 |
+
is_flash_attn_greater_or_equal_2_10,
|
45 |
+
is_mamba_2_ssm_available,
|
46 |
+
)
|
47 |
+
from .configuration_nemotron_h import NemotronHConfig
|
48 |
+
|
49 |
+
|
50 |
+
logger = logging.get_logger(__name__)
|
51 |
+
|
52 |
+
|
53 |
+
# Copied from transformers.models.mamba.modeling_mamba2.modeling_mamba2.py with MAMBA2->NEMOTRONH,Mamba2->NemotronH
|
54 |
+
# For Mamba2 components Mamba2->NemotronHMamba2
|
55 |
+
if is_mamba_2_ssm_available():
|
56 |
+
from mamba_ssm.ops.triton.selective_state_update import selective_state_update
|
57 |
+
from mamba_ssm.ops.triton.ssd_combined import mamba_chunk_scan_combined, mamba_split_conv1d_scan_combined
|
58 |
+
else:
|
59 |
+
mamba_chunk_scan_combined, mamba_split_conv1d_scan_combined, selective_state_update = None, None, None
|
60 |
+
|
61 |
+
try:
|
62 |
+
#from mamba_ssm.ops.triton.layernorm_gated import RMSNorm as RMSNormGated
|
63 |
+
from mamba_ssm.ops.triton.layernorm_gated import rmsnorm_fn
|
64 |
+
except ImportError:
|
65 |
+
raise ImportError("mamba-ssm is required by the Mamba model but cannot be imported")
|
66 |
+
|
67 |
+
if is_causal_conv1d_available():
|
68 |
+
from causal_conv1d import causal_conv1d_fn, causal_conv1d_update
|
69 |
+
else:
|
70 |
+
causal_conv1d_update, causal_conv1d_fn = None, None
|
71 |
+
|
72 |
+
if is_flash_attn_2_available():
|
73 |
+
from transformers.modeling_flash_attention_utils import _flash_attention_forward
|
74 |
+
|
75 |
+
is_fast_path_available = all(
|
76 |
+
(
|
77 |
+
selective_state_update,
|
78 |
+
mamba_chunk_scan_combined,
|
79 |
+
mamba_split_conv1d_scan_combined,
|
80 |
+
causal_conv1d_fn,
|
81 |
+
causal_conv1d_update,
|
82 |
+
)
|
83 |
+
)
|
84 |
+
|
85 |
+
|
86 |
+
_CHECKPOINT_FOR_DOC = "nvidia/Nemotron-H-56B-Base-8K"
|
87 |
+
_CONFIG_FOR_DOC = "NemotronHConfig"
|
88 |
+
|
89 |
+
|
90 |
+
# Helper methods for segment sum computation
|
91 |
+
|
92 |
+
|
93 |
+
def pad_tensor_by_size(input_tensor: torch.Tensor, pad_size: int):
|
94 |
+
"""
|
95 |
+
Padding x tensor with `pad_size` on the seq_len dim (dim=1)
|
96 |
+
|
97 |
+
Assumes that we only have tensors of either size 4 or 3
|
98 |
+
"""
|
99 |
+
pad_shape = (0, 0, 0, 0, 0, pad_size, 0, 0) if len(input_tensor.shape) == 4 else (0, 0, 0, pad_size, 0, 0)
|
100 |
+
|
101 |
+
return torch.nn.functional.pad(input_tensor, pad_shape, mode="constant", value=0)
|
102 |
+
|
103 |
+
|
104 |
+
def reshape_into_chunks(input_tensor, pad_size, chunk_size):
|
105 |
+
"""
|
106 |
+
Padding input_tensor with `pad_size` on the seq_len dim (dim=1) and
|
107 |
+
simultaneously splitting it into chunk sequences.
|
108 |
+
|
109 |
+
Assumes that we only have tensors of either size 4 or 3
|
110 |
+
"""
|
111 |
+
# [bsz, seq_len, ...] -> [bsz, seq_len multiple of chunk_size, ...]
|
112 |
+
input_tensor = pad_tensor_by_size(input_tensor, pad_size)
|
113 |
+
|
114 |
+
if len(input_tensor.shape) == 3:
|
115 |
+
# [bsz, seq_len multiple of chunk_size, num_heads] -> [bsz, -1, chunk_size, num_heads]
|
116 |
+
return input_tensor.reshape(input_tensor.shape[0], -1, chunk_size, input_tensor.shape[2])
|
117 |
+
else:
|
118 |
+
# [bsz, seq_len multiple of chunk_size, num_heads, head_dim or state_size] -> [bsz, -1, chunk_size, num_heads, head_dim or state_size]
|
119 |
+
return input_tensor.reshape(
|
120 |
+
input_tensor.shape[0], -1, chunk_size, input_tensor.shape[2], input_tensor.shape[3]
|
121 |
+
)
|
122 |
+
|
123 |
+
|
124 |
+
def segment_sum(input_tensor):
|
125 |
+
"""
|
126 |
+
More stable segment sum calculation. Uses cumulative sums and masking instead of direct subtractions.
|
127 |
+
"""
|
128 |
+
chunk_size = input_tensor.size(-1)
|
129 |
+
# 1. expand input tensor to have an additional dimension and repeat along that dimension
|
130 |
+
# [..., chunk_size] -> [..., chunk_size, chunk_size]
|
131 |
+
input_tensor = input_tensor[..., None].expand(*input_tensor.size(), chunk_size)
|
132 |
+
# 2. create a lower triangular mask with the diagonal set to 0 to 0 out elements above diag
|
133 |
+
mask = torch.tril(torch.ones(chunk_size, chunk_size, device=input_tensor.device, dtype=torch.bool), diagonal=-1)
|
134 |
+
input_tensor = input_tensor.masked_fill(~mask, 0)
|
135 |
+
# 3. compute actual cumsum
|
136 |
+
tensor_segsum = torch.cumsum(input_tensor, dim=-2)
|
137 |
+
|
138 |
+
# 4. apply mask to keep only the lower triangular part of the cumulative sum result (incl diagonal this time)
|
139 |
+
mask = torch.tril(torch.ones(chunk_size, chunk_size, device=input_tensor.device, dtype=torch.bool), diagonal=0)
|
140 |
+
tensor_segsum = tensor_segsum.masked_fill(~mask, -torch.inf)
|
141 |
+
return tensor_segsum
|
142 |
+
|
143 |
+
|
144 |
+
def apply_mask_to_padding_states(hidden_states, attention_mask):
|
145 |
+
"""
|
146 |
+
Tunes out the hidden states for padding tokens, see https://github.com/state-spaces/mamba/issues/66
|
147 |
+
"""
|
148 |
+
if attention_mask is not None and attention_mask.shape[1] > 1 and attention_mask.shape[0] > 1:
|
149 |
+
dtype = hidden_states.dtype
|
150 |
+
hidden_states = (hidden_states * attention_mask[:, :, None]).to(dtype)
|
151 |
+
|
152 |
+
return hidden_states
|
153 |
+
|
154 |
+
# Copied from https://github.com/huggingface/transformers/blob/main/src/transformers/models/jamba/modeling_jamba.py
|
155 |
+
class HybridMambaAttentionDynamicCache(DynamicCache):
|
156 |
+
"""
|
157 |
+
A dynamic cache that can handle both the attention cache (which has a seq_len dimension) and the mamba cache
|
158 |
+
(which has a constant shape regardless of seq_len).
|
159 |
+
|
160 |
+
This cache has two sets of lists of tensors: `key_cache` and `value_cache` for attention cache and `conv_states`
|
161 |
+
and `ssm_states` for mamba cache. Each of these lists has `num_layers` tensors. The expected shape for each tensor
|
162 |
+
For attention layers, `key_cache` and `value_cache` have a shape of `(batch_size, num_heads, seq_len, head_dim)`,
|
163 |
+
while `conv_states` and `ssm_states` have a shape of `(batch_size, 0)` (empty tensors).
|
164 |
+
For mamba layers, `key_cache` and `value_cache` have a shape of `(batch_size, 0)` (empty tensors),
|
165 |
+
while `conv_states` represents the convolution state and has a shape of `(batch_size, d_inner, d_conv)`,
|
166 |
+
and `ssm_states` represents the ssm state and has a shape of `(batch_size, d_inner, d_state)`.
|
167 |
+
"""
|
168 |
+
|
169 |
+
def __init__(self, config, batch_size, dtype=torch.float16, device=None):
|
170 |
+
super().__init__()
|
171 |
+
self.dtype = dtype
|
172 |
+
self.hybrid_override_pattern = config.hybrid_override_pattern
|
173 |
+
self.has_previous_state = False # only used by mamba
|
174 |
+
intermediate_size = config.expand * config.hidden_size
|
175 |
+
ssm_state_size = config.ssm_state_size
|
176 |
+
conv_kernel_size = config.conv_kernel
|
177 |
+
self.conv_states = []
|
178 |
+
self.ssm_states = []
|
179 |
+
self.transformer_layers = []
|
180 |
+
for i in range(config.num_hidden_layers):
|
181 |
+
if self.hybrid_override_pattern[i] == "M":
|
182 |
+
# Mamba layer
|
183 |
+
self.conv_states += [
|
184 |
+
torch.zeros(batch_size, intermediate_size, conv_kernel_size, device=device, dtype=dtype)
|
185 |
+
]
|
186 |
+
self.ssm_states += [
|
187 |
+
torch.zeros(batch_size, intermediate_size, ssm_state_size, device=device, dtype=dtype)
|
188 |
+
]
|
189 |
+
else:
|
190 |
+
# Attention or MLP layer
|
191 |
+
self.conv_states += [torch.tensor([[]] * batch_size, device=device)]
|
192 |
+
self.ssm_states += [torch.tensor([[]] * batch_size, device=device)]
|
193 |
+
self.transformer_layers.append(i)
|
194 |
+
|
195 |
+
self.key_cache = [torch.tensor([[]] * batch_size, device=device) for _ in range(config.num_hidden_layers)]
|
196 |
+
self.value_cache = [torch.tensor([[]] * batch_size, device=device) for _ in range(config.num_hidden_layers)]
|
197 |
+
|
198 |
+
def update(
|
199 |
+
self,
|
200 |
+
key_states: torch.Tensor,
|
201 |
+
value_states: torch.Tensor,
|
202 |
+
layer_idx: int,
|
203 |
+
cache_kwargs: Optional[Dict[str, Any]] = None,
|
204 |
+
) -> Tuple[torch.Tensor, torch.Tensor]:
|
205 |
+
# Update the cache
|
206 |
+
if self.key_cache[layer_idx].shape[-1] == 0:
|
207 |
+
self.key_cache[layer_idx] = key_states
|
208 |
+
self.value_cache[layer_idx] = value_states
|
209 |
+
else:
|
210 |
+
self.key_cache[layer_idx] = torch.cat([self.key_cache[layer_idx], key_states], dim=2)
|
211 |
+
self.value_cache[layer_idx] = torch.cat([self.value_cache[layer_idx], value_states], dim=2)
|
212 |
+
|
213 |
+
return self.key_cache[layer_idx], self.value_cache[layer_idx]
|
214 |
+
|
215 |
+
def reorder_cache(self, beam_idx: torch.LongTensor):
|
216 |
+
"""Reorders the cache for beam search, given the selected beam indices."""
|
217 |
+
for layer_idx in range(len(self.key_cache)):
|
218 |
+
device = self.key_cache[layer_idx].device
|
219 |
+
self.key_cache[layer_idx] = self.key_cache[layer_idx].index_select(0, beam_idx.to(device))
|
220 |
+
device = self.value_cache[layer_idx].device
|
221 |
+
self.value_cache[layer_idx] = self.value_cache[layer_idx].index_select(0, beam_idx.to(device))
|
222 |
+
|
223 |
+
device = self.conv_states[layer_idx].device
|
224 |
+
self.conv_states[layer_idx] = self.conv_states[layer_idx].index_select(0, beam_idx.to(device))
|
225 |
+
device = self.ssm_states[layer_idx].device
|
226 |
+
self.ssm_states[layer_idx] = self.ssm_states[layer_idx].index_select(0, beam_idx.to(device))
|
227 |
+
|
228 |
+
def get_seq_length(self, layer_idx: Optional[int] = 0) -> int:
|
229 |
+
"""Returns the sequence length of the cached states. A layer index can be optionally passed."""
|
230 |
+
# take any layer that contains cache and not empty tensor
|
231 |
+
layer_idx = self.transformer_layers[0] if layer_idx not in self.transformer_layers else layer_idx
|
232 |
+
if len(self.key_cache) <= layer_idx:
|
233 |
+
return 0
|
234 |
+
return self.key_cache[layer_idx].shape[-2]
|
235 |
+
|
236 |
+
def to_legacy_cache(self) -> Tuple[Tuple[torch.Tensor], Tuple[torch.Tensor]]:
|
237 |
+
raise NotImplementedError("HybridMambaAttentionDynamicCache does not have a legacy cache equivalent.")
|
238 |
+
|
239 |
+
@classmethod
|
240 |
+
def from_legacy_cache(cls, past_key_values: Optional[Tuple[Tuple[torch.FloatTensor]]] = None) -> "DynamicCache":
|
241 |
+
raise NotImplementedError("HybridMambaAttentionDynamicCache does not have a legacy cache equivalent.")
|
242 |
+
|
243 |
+
# Copied from modeling_mamba2.py
|
244 |
+
def update_conv_state(
|
245 |
+
self, layer_idx: int, new_conv_state: torch.Tensor, cache_init: bool = False
|
246 |
+
) -> torch.Tensor:
|
247 |
+
if cache_init:
|
248 |
+
self.conv_states[layer_idx] = new_conv_state.to(self.conv_states.device)
|
249 |
+
else:
|
250 |
+
self.conv_states[layer_idx] = self.conv_states[layer_idx].roll(shifts=-1, dims=-1)
|
251 |
+
self.conv_states[layer_idx][:, :, -1] = new_conv_state[:, 0, :].to(self.conv_states.device)
|
252 |
+
return self.conv_states[layer_idx]
|
253 |
+
|
254 |
+
def update_ssm_state(self, layer_idx: int, new_ssm_state: torch.Tensor):
|
255 |
+
self.ssm_states[layer_idx] = new_ssm_state.to(self.ssm_states.device)
|
256 |
+
return self.ssm_states[layer_idx]
|
257 |
+
|
258 |
+
def reset(self):
|
259 |
+
self.conv_states.zero_()
|
260 |
+
self.ssm_states.zero_()
|
261 |
+
|
262 |
+
class MambaRMSNormGated(torch.nn.Module):
|
263 |
+
def __init__(self, hidden_size, group_size, eps=1e-5):
|
264 |
+
super().__init__()
|
265 |
+
self.weight = nn.Parameter(torch.ones(hidden_size))
|
266 |
+
self.variance_epsilon = eps
|
267 |
+
self.group_size = group_size
|
268 |
+
|
269 |
+
# jan28b version
|
270 |
+
def forward(self, hidden_states, gate=None):
|
271 |
+
return rmsnorm_fn(x=hidden_states,
|
272 |
+
weight=self.weight,
|
273 |
+
bias=None, # No bias
|
274 |
+
z=gate,
|
275 |
+
eps=self.variance_epsilon,
|
276 |
+
group_size=self.group_size,
|
277 |
+
norm_before_gate=False
|
278 |
+
)
|
279 |
+
|
280 |
+
class NemotronHMamba2Mixer(nn.Module):
|
281 |
+
"""
|
282 |
+
Compute ∆, A, B, C, and D the state space parameters and compute the `contextualized_states`.
|
283 |
+
A, D are input independent (see Mamba paper [1] Section 3.5.2 "Interpretation of A" for why A isn't selective)
|
284 |
+
∆, B, C are input-dependent (this is a key difference between Mamba and the linear time invariant S4,
|
285 |
+
and is why Mamba is called **selective** state spaces)
|
286 |
+
"""
|
287 |
+
|
288 |
+
def __init__(self, config: NemotronHConfig, layer_idx: int):
|
289 |
+
super().__init__()
|
290 |
+
self.num_heads = config.mamba_num_heads
|
291 |
+
self.hidden_size = config.hidden_size
|
292 |
+
self.ssm_state_size = config.ssm_state_size
|
293 |
+
self.conv_kernel_size = config.conv_kernel
|
294 |
+
self.intermediate_size = config.mamba_num_heads * config.mamba_head_dim
|
295 |
+
self.layer_idx = layer_idx
|
296 |
+
self.use_conv_bias = config.use_conv_bias
|
297 |
+
self.activation = config.mamba_hidden_act
|
298 |
+
self.act = ACT2FN[config.mamba_hidden_act]
|
299 |
+
|
300 |
+
self.layer_norm_epsilon = config.layer_norm_epsilon
|
301 |
+
|
302 |
+
self.n_groups = config.n_groups
|
303 |
+
self.head_dim = config.mamba_head_dim
|
304 |
+
self.chunk_size = config.chunk_size
|
305 |
+
|
306 |
+
self.time_step_limit = config.time_step_limit
|
307 |
+
self.time_step_min = config.time_step_min
|
308 |
+
self.time_step_max = config.time_step_max
|
309 |
+
|
310 |
+
self.conv_dim = self.intermediate_size + 2 * self.n_groups * self.ssm_state_size
|
311 |
+
self.conv1d = nn.Conv1d(
|
312 |
+
in_channels=self.conv_dim,
|
313 |
+
out_channels=self.conv_dim,
|
314 |
+
bias=config.use_conv_bias,
|
315 |
+
kernel_size=config.conv_kernel,
|
316 |
+
groups=self.conv_dim,
|
317 |
+
padding=config.conv_kernel - 1,
|
318 |
+
)
|
319 |
+
|
320 |
+
# projection of the input hidden states
|
321 |
+
projection_size = self.intermediate_size + self.conv_dim + self.num_heads
|
322 |
+
self.in_proj = nn.Linear(
|
323 |
+
self.hidden_size,
|
324 |
+
projection_size,
|
325 |
+
bias=config.use_bias,
|
326 |
+
)
|
327 |
+
# selective projection used to make dt, B and C input dependant
|
328 |
+
|
329 |
+
# time step projection (discretization)
|
330 |
+
# instantiate once and copy inv_dt in init_weights of PretrainedModel
|
331 |
+
self.dt_bias = nn.Parameter(torch.ones(self.num_heads))
|
332 |
+
|
333 |
+
# S4D real initialization. These are not discretized!
|
334 |
+
# The core is to load them, compute the discrete states, then write the updated state. Keeps the memory bounded
|
335 |
+
A = torch.arange(1, self.num_heads + 1)
|
336 |
+
self.A_log = nn.Parameter(torch.log(A))
|
337 |
+
self.A_log._no_weight_decay = True
|
338 |
+
self.norm = MambaRMSNormGated(self.intermediate_size, eps=self.layer_norm_epsilon, group_size=self.intermediate_size)
|
339 |
+
self.D = nn.Parameter(torch.ones(self.num_heads))
|
340 |
+
self.D._no_weight_decay = True
|
341 |
+
|
342 |
+
self.out_proj = nn.Linear(self.intermediate_size, self.hidden_size, bias=config.use_bias)
|
343 |
+
self.use_bias = config.use_bias
|
344 |
+
|
345 |
+
if not is_fast_path_available:
|
346 |
+
logger.warning_once(
|
347 |
+
"The fast path is not available because on of `(selective_state_update, causal_conv1d_fn, causal_conv1d_update)`"
|
348 |
+
" is None. Falling back to the naive implementation. To install follow https://github.com/state-spaces/mamba/#installation and"
|
349 |
+
" https://github.com/Dao-AILab/causal-conv1d"
|
350 |
+
)
|
351 |
+
|
352 |
+
def cuda_kernels_forward(
|
353 |
+
self,
|
354 |
+
hidden_states: torch.Tensor,
|
355 |
+
cache_params: Optional[HybridMambaAttentionDynamicCache] = None,
|
356 |
+
cache_position: Optional[torch.LongTensor] = None,
|
357 |
+
attention_mask: Optional[torch.Tensor] = None,
|
358 |
+
):
|
359 |
+
# 1. Gated MLP's linear projection
|
360 |
+
hidden_states = apply_mask_to_padding_states(hidden_states, attention_mask)
|
361 |
+
projected_states = self.in_proj(hidden_states)
|
362 |
+
|
363 |
+
# Set up dimensions for reshapes later
|
364 |
+
batch_size, seq_len, _ = hidden_states.shape
|
365 |
+
groups_time_state_size = self.n_groups * self.ssm_state_size
|
366 |
+
d_mlp = (
|
367 |
+
projected_states.shape[-1]
|
368 |
+
- 2 * self.intermediate_size
|
369 |
+
- 2 * self.n_groups * self.ssm_state_size
|
370 |
+
- self.num_heads
|
371 |
+
) // 2
|
372 |
+
|
373 |
+
# Single step calculations via cache
|
374 |
+
if cache_params is not None and cache_position is not None and cache_position[0] > 0:
|
375 |
+
_, _, gate, hidden_states_B_C, dt = projected_states.squeeze(1).split(
|
376 |
+
[d_mlp, d_mlp, self.intermediate_size, self.conv_dim, self.num_heads], dim=-1
|
377 |
+
)
|
378 |
+
|
379 |
+
# 2. Convolution sequence transformation
|
380 |
+
hidden_states_B_C = causal_conv1d_update(
|
381 |
+
hidden_states_B_C,
|
382 |
+
cache_params.conv_states[self.layer_idx],
|
383 |
+
self.conv1d.weight.squeeze(1),
|
384 |
+
self.conv1d.bias,
|
385 |
+
self.activation,
|
386 |
+
)
|
387 |
+
|
388 |
+
hidden_states, B, C = torch.split(
|
389 |
+
hidden_states_B_C,
|
390 |
+
[self.intermediate_size, groups_time_state_size, groups_time_state_size],
|
391 |
+
dim=-1,
|
392 |
+
)
|
393 |
+
|
394 |
+
# 3. SSM transformation
|
395 |
+
A = -torch.exp(self.A_log.float()) # (nheads,)
|
396 |
+
A = A[:, None, ...][:, :, None].expand(-1, self.head_dim, self.ssm_state_size).to(dtype=torch.float32)
|
397 |
+
dt = dt[:, :, None].expand(-1, -1, self.head_dim)
|
398 |
+
dt_bias = self.dt_bias[:, None, ...].expand(-1, self.head_dim)
|
399 |
+
D = self.D[:, None, ...].expand(-1, self.head_dim)
|
400 |
+
B = B.view(batch_size, self.n_groups, B.shape[1] // self.n_groups)
|
401 |
+
C = C.view(batch_size, self.n_groups, C.shape[1] // self.n_groups)
|
402 |
+
hidden_states_reshaped = hidden_states.view(batch_size, self.num_heads, self.head_dim)
|
403 |
+
hidden_states = selective_state_update(
|
404 |
+
cache_params.ssm_states[self.layer_idx],
|
405 |
+
hidden_states_reshaped,
|
406 |
+
dt,
|
407 |
+
A,
|
408 |
+
B,
|
409 |
+
C,
|
410 |
+
D,
|
411 |
+
z=None,
|
412 |
+
dt_bias=dt_bias,
|
413 |
+
dt_softplus=True,
|
414 |
+
)
|
415 |
+
hidden_states = hidden_states.view(batch_size, self.num_heads * self.head_dim)
|
416 |
+
breakpoint()
|
417 |
+
hidden_states = self.norm(hidden_states, gate)
|
418 |
+
|
419 |
+
# 4. Final linear projection
|
420 |
+
out = self.out_proj(hidden_states)[:, None, ...]
|
421 |
+
|
422 |
+
# Fused calculations or step by step if no initialized cache is found
|
423 |
+
else:
|
424 |
+
A = -torch.exp(self.A_log.float()) # (num_heads) or (intermediate_size, state_size)
|
425 |
+
dt_limit_kwargs = {} if self.time_step_limit == (0.0, float("inf")) else {"dt_limit": self.time_step_limit}
|
426 |
+
|
427 |
+
# 2-4. Fused kernel for conv1d, SSM, and the final projection
|
428 |
+
if self.training and cache_params is None:
|
429 |
+
out = mamba_split_conv1d_scan_combined(
|
430 |
+
projected_states,
|
431 |
+
self.conv1d.weight.squeeze(1),
|
432 |
+
self.conv1d.bias,
|
433 |
+
self.dt_bias,
|
434 |
+
A,
|
435 |
+
D=self.D,
|
436 |
+
chunk_size=self.chunk_size,
|
437 |
+
seq_idx=None, # was seq_idx
|
438 |
+
activation=self.activation,
|
439 |
+
rmsnorm_weight=self.norm.weight,
|
440 |
+
rmsnorm_eps=self.norm.variance_epsilon,
|
441 |
+
outproj_weight=self.out_proj.weight,
|
442 |
+
outproj_bias=self.out_proj.bias,
|
443 |
+
headdim=self.head_dim,
|
444 |
+
ngroups=self.n_groups,
|
445 |
+
norm_before_gate=False,
|
446 |
+
return_final_states=False,
|
447 |
+
**dt_limit_kwargs,
|
448 |
+
)
|
449 |
+
|
450 |
+
else:
|
451 |
+
_, _, gate, hidden_states_B_C, dt = projected_states.split(
|
452 |
+
[d_mlp, d_mlp, self.intermediate_size, self.conv_dim, self.num_heads], dim=-1
|
453 |
+
)
|
454 |
+
|
455 |
+
# 2. Convolution sequence transformation
|
456 |
+
# Init cache
|
457 |
+
if cache_params is not None:
|
458 |
+
hidden_states_B_C_transposed = hidden_states_B_C.transpose(1, 2)
|
459 |
+
conv_states = nn.functional.pad(
|
460 |
+
hidden_states_B_C_transposed,
|
461 |
+
(cache_params.conv_kernel_size - hidden_states_B_C_transposed.shape[-1], 0),
|
462 |
+
)
|
463 |
+
cache_params.update_conv_state(
|
464 |
+
layer_idx=self.layer_idx, new_conv_state=conv_states, cache_init=True
|
465 |
+
)
|
466 |
+
|
467 |
+
if self.activation not in ["silu", "swish"]:
|
468 |
+
hidden_states_B_C = self.act(
|
469 |
+
self.conv1d(hidden_states_B_C.transpose(1, 2))[..., :seq_len].transpose(1, 2)
|
470 |
+
)
|
471 |
+
else:
|
472 |
+
hidden_states_B_C = causal_conv1d_fn(
|
473 |
+
x=hidden_states_B_C.transpose(1, 2),
|
474 |
+
weight=self.conv1d.weight.squeeze(1),
|
475 |
+
bias=self.conv1d.bias,
|
476 |
+
activation=self.activation,
|
477 |
+
).transpose(1, 2)
|
478 |
+
|
479 |
+
hidden_states_B_C = apply_mask_to_padding_states(hidden_states_B_C, attention_mask)
|
480 |
+
hidden_states, B, C = torch.split(
|
481 |
+
hidden_states_B_C,
|
482 |
+
[self.intermediate_size, groups_time_state_size, groups_time_state_size],
|
483 |
+
dim=-1,
|
484 |
+
)
|
485 |
+
|
486 |
+
# 3. SSM transformation
|
487 |
+
scan_output, ssm_state = mamba_chunk_scan_combined(
|
488 |
+
hidden_states.view(batch_size, seq_len, -1, self.head_dim),
|
489 |
+
dt,
|
490 |
+
A,
|
491 |
+
B.view(batch_size, seq_len, self.n_groups, -1),
|
492 |
+
C.view(batch_size, seq_len, self.n_groups, -1),
|
493 |
+
chunk_size=self.chunk_size,
|
494 |
+
D=self.D,
|
495 |
+
z=None,
|
496 |
+
seq_idx=None,
|
497 |
+
return_final_states=True,
|
498 |
+
dt_bias=self.dt_bias,
|
499 |
+
dt_softplus=True,
|
500 |
+
**dt_limit_kwargs,
|
501 |
+
)
|
502 |
+
|
503 |
+
# Init cache
|
504 |
+
if ssm_state is not None and cache_params is not None:
|
505 |
+
cache_params.update_ssm_state(layer_idx=self.layer_idx, new_ssm_state=ssm_state)
|
506 |
+
|
507 |
+
scan_output = scan_output.view(batch_size, seq_len, -1)
|
508 |
+
|
509 |
+
# Multiply "gate" branch and apply extra normalization layer
|
510 |
+
scan_output = self.norm(scan_output, gate)
|
511 |
+
|
512 |
+
# 4. Final linear projection
|
513 |
+
out = self.out_proj(scan_output)
|
514 |
+
return out
|
515 |
+
|
516 |
+
# fmt: off
|
517 |
+
def torch_forward(self, input_states, cache_params: Optional[HybridMambaAttentionDynamicCache]=None, cache_position:Optional[torch.LongTensor]=None, attention_mask: Optional[torch.Tensor]=None):
|
518 |
+
batch_size, seq_len, _ = input_states.shape
|
519 |
+
dtype = input_states.dtype
|
520 |
+
|
521 |
+
# 1. Gated MLP's linear projection
|
522 |
+
input_states = apply_mask_to_padding_states(input_states, attention_mask)
|
523 |
+
projected_states = self.in_proj(input_states)
|
524 |
+
d_mlp = (projected_states.shape[-1] - 2 * self.intermediate_size - 2 * self.n_groups * self.ssm_state_size-self.num_heads) // 2
|
525 |
+
_, _, gate, hidden_states_B_C, dt = projected_states.split(
|
526 |
+
[d_mlp, d_mlp, self.intermediate_size, self.conv_dim, self.num_heads], dim=-1
|
527 |
+
)
|
528 |
+
|
529 |
+
# 2. Convolution sequence transformation
|
530 |
+
if cache_params is not None and cache_position is not None and cache_position[0] > 0:
|
531 |
+
cache_params.update_conv_state(layer_idx=self.layer_idx, new_conv_state=hidden_states_B_C, cache_init=False)
|
532 |
+
|
533 |
+
# We need to guarantee that anything regarding the cache is on the same device
|
534 |
+
conv_states = cache_params.conv_states[self.layer_idx].to(device=self.conv1d.weight.device)
|
535 |
+
|
536 |
+
hidden_states_B_C = torch.sum(
|
537 |
+
conv_states * self.conv1d.weight.squeeze(1), dim=-1
|
538 |
+
)
|
539 |
+
if self.use_conv_bias:
|
540 |
+
hidden_states_B_C = hidden_states_B_C + self.conv1d.bias
|
541 |
+
hidden_states_B_C = self.act(hidden_states_B_C)
|
542 |
+
else:
|
543 |
+
# Init cache
|
544 |
+
if cache_params is not None:
|
545 |
+
hidden_states_B_C_transposed = hidden_states_B_C.transpose(1, 2)
|
546 |
+
conv_states = nn.functional.pad(
|
547 |
+
hidden_states_B_C_transposed, (cache_params.conv_kernel_size - hidden_states_B_C_transposed.shape[-1], 0)
|
548 |
+
)
|
549 |
+
cache_params.update_conv_state(layer_idx=self.layer_idx, new_conv_state=conv_states, cache_init=True)
|
550 |
+
|
551 |
+
hidden_states_B_C = self.act(self.conv1d(hidden_states_B_C.transpose(1, 2))[..., :seq_len].transpose(1, 2))
|
552 |
+
|
553 |
+
hidden_states_B_C = apply_mask_to_padding_states(hidden_states_B_C, attention_mask)
|
554 |
+
hidden_states, B, C = torch.split(
|
555 |
+
hidden_states_B_C,
|
556 |
+
[self.intermediate_size, self.n_groups * self.ssm_state_size, self.n_groups * self.ssm_state_size],
|
557 |
+
dim=-1
|
558 |
+
)
|
559 |
+
|
560 |
+
# 3. SSM transformation
|
561 |
+
A = -torch.exp(self.A_log.float()) # [num_heads]
|
562 |
+
if cache_params is not None and cache_position is not None and cache_position[0] > 0:
|
563 |
+
# We need to guarantee that anything regarding the cache is on the same device
|
564 |
+
cache_device = cache_params.ssm_states.device
|
565 |
+
|
566 |
+
# Note: there is no need to pad parameter matrices here, as there is just one new token
|
567 |
+
# for batched generation
|
568 |
+
dt = dt[:, 0, :][:, None, ...]
|
569 |
+
dt = dt.transpose(1, 2).expand(batch_size, dt.shape[-1], self.head_dim)
|
570 |
+
# [num_heads] -> [num_heads, head_dim]
|
571 |
+
dt_bias = self.dt_bias[..., None].expand(self.dt_bias.shape[0], self.head_dim)
|
572 |
+
|
573 |
+
dt = torch.nn.functional.softplus(dt + dt_bias.to(dt.dtype))
|
574 |
+
dt = torch.clamp(dt, self.time_step_limit[0], self.time_step_limit[1])
|
575 |
+
A = A[..., None, None].expand(self.num_heads, self.head_dim, self.ssm_state_size).to(dtype=torch.float32)
|
576 |
+
# [bsz, num_heads, head_dim, state_size]
|
577 |
+
dA = (torch.exp(dt[..., None] * A)).to(device=cache_device)
|
578 |
+
|
579 |
+
# Discretize B
|
580 |
+
# [bsz, n_groups * state_size] -> [bsz, n_groups, 1, state_size] ->
|
581 |
+
# -> [bsz, n_groups, group to head repetition factor, state_size] -> [bsz, num_heads, state_size]
|
582 |
+
B = B.reshape(batch_size, self.n_groups, -1)[..., None, :]
|
583 |
+
B = B.expand(batch_size, self.n_groups, self.num_heads // self.n_groups, B.shape[-1]).contiguous()
|
584 |
+
B = B.reshape(batch_size, -1, B.shape[-1])
|
585 |
+
# [bsz, num_heads, head_dim, state_size]
|
586 |
+
dB = dt[..., None] * B[..., None, :]
|
587 |
+
|
588 |
+
# Discretize x into dB
|
589 |
+
# [bsz, intermediate_size] -> [bsz, num_heads, head_dim]
|
590 |
+
hidden_states = hidden_states.reshape(batch_size, -1, self.head_dim)
|
591 |
+
dBx = (dB * hidden_states[..., None]).to(device=cache_device)
|
592 |
+
|
593 |
+
# State calculation
|
594 |
+
cache_params.update_ssm_state(
|
595 |
+
layer_idx=self.layer_idx,
|
596 |
+
new_ssm_state=cache_params.ssm_states[self.layer_idx] * dA + dBx
|
597 |
+
)
|
598 |
+
|
599 |
+
# Subsequent output
|
600 |
+
# [bsz, n_groups * state_size] -> [bsz, num_heads, state_size]
|
601 |
+
C = C.reshape(batch_size, self.n_groups, -1)[..., None, :]
|
602 |
+
C = C.expand(batch_size, self.n_groups, self.num_heads // self.n_groups, C.shape[-1]).contiguous()
|
603 |
+
C = C.reshape(batch_size, -1, C.shape[-1])
|
604 |
+
# [bsz, num_heads, head_dim]
|
605 |
+
|
606 |
+
ssm_states = cache_params.ssm_states[self.layer_idx].to(device=C.device, dtype=C.dtype) # Shape: [b, h, d, n]
|
607 |
+
# Reshape ssm_states to merge the first two dimensions
|
608 |
+
ssm_states_reshaped = ssm_states.view(batch_size * self.num_heads, self.head_dim, self.ssm_state_size) # Shape: [b*h, d, n]
|
609 |
+
C_reshaped = C.view(batch_size * self.num_heads, self.ssm_state_size, 1) # Shape: [b*h, n, 1]
|
610 |
+
y = torch.bmm(ssm_states_reshaped, C_reshaped)
|
611 |
+
y = y.view(batch_size, self.num_heads, self.head_dim)
|
612 |
+
|
613 |
+
# D skip connection
|
614 |
+
# [num_heads] -> [num_heads, head_dim]
|
615 |
+
D = self.D[..., None].expand(self.D.shape[0], self.head_dim)
|
616 |
+
y = (y + hidden_states * D).to(y.dtype)
|
617 |
+
|
618 |
+
# [bsz, num_heads, head_dim] -> [bsz, 1, intermediate_size]
|
619 |
+
y = y.reshape(batch_size, -1)[:, None, ...]
|
620 |
+
else:
|
621 |
+
# begin ssd naive implementation without einsums
|
622 |
+
dt = nn.functional.softplus(dt + self.dt_bias)
|
623 |
+
dt = torch.clamp(dt, self.time_step_limit[0], self.time_step_limit[1])
|
624 |
+
hidden_states = hidden_states.reshape(batch_size, seq_len, -1, self.head_dim).float()
|
625 |
+
B = B.reshape(batch_size, seq_len, -1, self.ssm_state_size).float()
|
626 |
+
C = C.reshape(batch_size, seq_len, -1, self.ssm_state_size).float()
|
627 |
+
B = B.repeat(1, 1, self.num_heads // self.n_groups, 1)
|
628 |
+
C = C.repeat(1, 1, self.num_heads // self.n_groups, 1)
|
629 |
+
pad_size = (self.chunk_size - seq_len % self.chunk_size) % self.chunk_size
|
630 |
+
|
631 |
+
D_residual = self.D[..., None] * pad_tensor_by_size(hidden_states, pad_size)
|
632 |
+
|
633 |
+
# Discretize x and A
|
634 |
+
hidden_states = hidden_states * dt[..., None]
|
635 |
+
A = A.to(hidden_states.dtype) * dt
|
636 |
+
|
637 |
+
# Rearrange into blocks/chunks
|
638 |
+
hidden_states, A, B, C = [reshape_into_chunks(t, pad_size, self.chunk_size) for t in (hidden_states, A, B, C)]
|
639 |
+
|
640 |
+
# [bsz, -1, chunk_size, num_heads] -> [bsz, num_heads, -1, chunk_size]
|
641 |
+
A = A.permute(0, 3, 1, 2)
|
642 |
+
A_cumsum = torch.cumsum(A, dim=-1)
|
643 |
+
|
644 |
+
# 1. Compute the output for each intra-chunk (diagonal blocks)
|
645 |
+
# This is the analog of a causal mask
|
646 |
+
L = torch.exp(segment_sum(A))
|
647 |
+
|
648 |
+
# Contraction of C and B to get G (attention-weights like)
|
649 |
+
G_intermediate = C[:, :, :, None, :, :] * B[:, :, None, :, :, :] # shape: (b, c, l, s, h, n)
|
650 |
+
G = G_intermediate.sum(dim=-1) # shape: (b, c, l, s, h)
|
651 |
+
|
652 |
+
# Compute M, equivalent to applying attention mask to weights
|
653 |
+
M_intermediate = G[..., None] * L.permute(0, 2, 3, 4, 1)[..., None]
|
654 |
+
M = M_intermediate.sum(dim=-1)
|
655 |
+
|
656 |
+
# Compute Y_diag (apply to values)
|
657 |
+
Y_diag = (M[..., None] * hidden_states[:, :, None]).sum(dim=3)
|
658 |
+
|
659 |
+
# 2. Compute the state for each intra-chunk
|
660 |
+
# (right term of low-rank factorization of off-diagonal blocks; B terms)
|
661 |
+
decay_states = torch.exp((A_cumsum[:, :, :, -1:] - A_cumsum))
|
662 |
+
B_decay = B * decay_states.permute(0, -2, -1, 1)[..., None]
|
663 |
+
states = (B_decay[..., None, :] * hidden_states[..., None]).sum(dim=2)
|
664 |
+
|
665 |
+
# 3. Compute the inter-chunk SSM recurrence; produces correct SSM states at chunk boundaries
|
666 |
+
# (middle term of factorization of off-diag blocks; A terms)
|
667 |
+
if cache_params is not None and cache_position is not None and cache_position[0] > 0:
|
668 |
+
previous_states = cache_params.ssm_states[self.layer_idx][:, None, ...].to(device=states.device)
|
669 |
+
else:
|
670 |
+
previous_states = torch.zeros_like(states[:, :1])
|
671 |
+
states = torch.cat([previous_states, states], dim=1)
|
672 |
+
decay_chunk = torch.exp(segment_sum(nn.functional.pad(A_cumsum[:, :, :, -1], (1, 0))))
|
673 |
+
decay_chunk = decay_chunk.transpose(1, 3)
|
674 |
+
new_states = (decay_chunk[..., None, None] * states[:, :, None, ...]).sum(dim=1)
|
675 |
+
states, ssm_state = new_states[:, :-1], new_states[:, -1]
|
676 |
+
|
677 |
+
# 4. Compute state -> output conversion per chunk
|
678 |
+
# (left term of low-rank factorization of off-diagonal blocks; C terms)
|
679 |
+
state_decay_out = torch.exp(A_cumsum)
|
680 |
+
C_times_states = (C[..., None, :] * states[:, :, None, ...])
|
681 |
+
state_decay_out_permuted = state_decay_out.permute(0, 2, 3, 1)
|
682 |
+
Y_off = (C_times_states.sum(-1) * state_decay_out_permuted[..., None])
|
683 |
+
|
684 |
+
# Add output of intra-chunk and inter-chunk terms (diagonal and off-diagonal blocks)
|
685 |
+
y = Y_diag + Y_off
|
686 |
+
# [bsz, -1, self.chunk_size, num_heads, head_dim] -> [bsz, (padded) seq_len, num_heads, head_dim]
|
687 |
+
y = y.reshape(batch_size, -1, self.num_heads, self.head_dim)
|
688 |
+
|
689 |
+
y = y + D_residual
|
690 |
+
# Cutting off padded chunks
|
691 |
+
if pad_size > 0:
|
692 |
+
y = y[:, :seq_len, :, :]
|
693 |
+
y = y.reshape(batch_size, seq_len, -1)
|
694 |
+
|
695 |
+
# Init cache
|
696 |
+
if ssm_state is not None and cache_params is not None:
|
697 |
+
cache_params.update_ssm_state(layer_idx=self.layer_idx, new_ssm_state=ssm_state)
|
698 |
+
|
699 |
+
scan_output = self.norm(y, gate)
|
700 |
+
|
701 |
+
# end ssd naive
|
702 |
+
|
703 |
+
# 4. Final linear projection
|
704 |
+
contextualized_states = self.out_proj(scan_output.to(dtype)) # [batch, seq_len, hidden_size]
|
705 |
+
return contextualized_states
|
706 |
+
# fmt: on
|
707 |
+
|
708 |
+
def forward(
|
709 |
+
self,
|
710 |
+
hidden_states,
|
711 |
+
cache_params: Optional[HybridMambaAttentionDynamicCache] = None,
|
712 |
+
cache_position: Optional[torch.LongTensor] = None,
|
713 |
+
attention_mask: Optional[torch.Tensor] = None,
|
714 |
+
):
|
715 |
+
if is_fast_path_available and "cuda" in self.in_proj.weight.device.type:
|
716 |
+
return self.cuda_kernels_forward(hidden_states, cache_params, cache_position, attention_mask)
|
717 |
+
dtype = hidden_states.dtype
|
718 |
+
if attention_mask is not None and attention_mask.shape[1] > 1 and attention_mask.shape[0] > 1:
|
719 |
+
# tune out hidden states for pad tokens, see https://github.com/state-spaces/mamba/issues/66
|
720 |
+
hidden_states = (hidden_states * attention_mask[:, :, None]).to(dtype)
|
721 |
+
|
722 |
+
return self.torch_forward(hidden_states, cache_params, cache_position, attention_mask)
|
723 |
+
|
724 |
+
|
725 |
+
class NemotronHRMSNorm(nn.Module):
|
726 |
+
def __init__(self, hidden_size, eps=1e-6):
|
727 |
+
"""
|
728 |
+
NemotronHRMSNorm is equivalent to T5LayerNorm and LlamaRMSNorm
|
729 |
+
"""
|
730 |
+
super().__init__()
|
731 |
+
self.weight = nn.Parameter(torch.ones(hidden_size))
|
732 |
+
self.variance_epsilon = eps
|
733 |
+
|
734 |
+
def forward(self, hidden_states):
|
735 |
+
input_dtype = hidden_states.dtype
|
736 |
+
hidden_states = hidden_states.to(torch.float32)
|
737 |
+
variance = hidden_states.pow(2).mean(-1, keepdim=True)
|
738 |
+
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
|
739 |
+
# Weights are in float32
|
740 |
+
return (self.weight.to(torch.float32) * hidden_states).to(input_dtype)
|
741 |
+
|
742 |
+
class NemotronHBlock(nn.Module):
|
743 |
+
def __init__(self, config, layer_idx):
|
744 |
+
super().__init__()
|
745 |
+
self.config = config
|
746 |
+
self.layer_idx = layer_idx
|
747 |
+
self.residual_in_fp32 = config.residual_in_fp32
|
748 |
+
self.norm = NemotronHRMSNorm(config.hidden_size, eps=config.layer_norm_epsilon)
|
749 |
+
|
750 |
+
# M: Mamba2, *: Attention, -: MLP
|
751 |
+
self.block_type = config.layers_block_type[layer_idx]
|
752 |
+
if self.block_type == "mamba":
|
753 |
+
self.mixer = NemotronHMamba2Mixer(config, layer_idx=layer_idx)
|
754 |
+
elif self.block_type == "attention":
|
755 |
+
self.mixer = NEMOTRONH_ATTENTION_CLASSES[config._attn_implementation](config, layer_idx=layer_idx)
|
756 |
+
elif self.block_type == "mlp":
|
757 |
+
self.mixer = NemotronHMLP(config, layer_idx=layer_idx)
|
758 |
+
else:
|
759 |
+
raise ValueError(f"Invalid layer pattern {config.hybrid_override_pattern[layer_idx]}")
|
760 |
+
|
761 |
+
def forward(
|
762 |
+
self,
|
763 |
+
hidden_states,
|
764 |
+
cache_params: Optional[HybridMambaAttentionDynamicCache] = None,
|
765 |
+
cache_position: Optional[torch.LongTensor] = None,
|
766 |
+
attention_mask: Optional[torch.Tensor] = None,
|
767 |
+
):
|
768 |
+
residual = hidden_states
|
769 |
+
hidden_states = self.norm(hidden_states.to(dtype=self.norm.weight.dtype))
|
770 |
+
if self.residual_in_fp32:
|
771 |
+
residual = residual.to(torch.float32)
|
772 |
+
|
773 |
+
if self.block_type == "mamba":
|
774 |
+
hidden_states = self.mixer(
|
775 |
+
hidden_states, cache_params=cache_params, cache_position=cache_position #, attention_mask=attention_mask
|
776 |
+
)
|
777 |
+
elif self.block_type == "attention":
|
778 |
+
hidden_states = self.mixer(
|
779 |
+
hidden_states, cache_position=cache_position #, attention_mask=attention_mask
|
780 |
+
)
|
781 |
+
# hidden_states = (attn_output, attn_weights, past_key_value)
|
782 |
+
hidden_states = hidden_states[0]
|
783 |
+
elif self.block_type == "mlp":
|
784 |
+
hidden_states = self.mixer(
|
785 |
+
hidden_states
|
786 |
+
)
|
787 |
+
else:
|
788 |
+
raise ValueError(f"Invalid block_type: {self.block_type}")
|
789 |
+
|
790 |
+
hidden_states = residual + hidden_states
|
791 |
+
return hidden_states
|
792 |
+
|
793 |
+
|
794 |
+
# Copied from transformers.models.nemotron.modeling_nemotron Nemotron->NemotronH
|
795 |
+
class NemotronHMLP(nn.Module):
|
796 |
+
def __init__(self, config, layer_idx: Optional[int] = None):
|
797 |
+
super().__init__()
|
798 |
+
self.config = config
|
799 |
+
self.layer_idx = layer_idx
|
800 |
+
if layer_idx is None:
|
801 |
+
logger.warning_once(
|
802 |
+
f"Instantiating {self.__class__.__name__} without passing a `layer_idx` is not recommended and will "
|
803 |
+
"lead to errors during the forward call if caching is used. Please make sure to provide a `layer_idx` "
|
804 |
+
"when creating this class."
|
805 |
+
)
|
806 |
+
self.hidden_size = config.hidden_size
|
807 |
+
self.intermediate_size = config.intermediate_size
|
808 |
+
self.up_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=config.mlp_bias)
|
809 |
+
self.down_proj = nn.Linear(self.intermediate_size, self.hidden_size, bias=config.mlp_bias)
|
810 |
+
self.act_fn = ACT2FN[config.mlp_hidden_act]
|
811 |
+
|
812 |
+
def forward(self, x):
|
813 |
+
return self.down_proj(self.act_fn(self.up_proj(x)))
|
814 |
+
|
815 |
+
|
816 |
+
# Copied from transformers.models.llama.modeling_llama.repeat_kv
|
817 |
+
def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
|
818 |
+
"""
|
819 |
+
This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
|
820 |
+
num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
|
821 |
+
"""
|
822 |
+
batch, num_key_value_heads, slen, head_dim = hidden_states.shape
|
823 |
+
if n_rep == 1:
|
824 |
+
return hidden_states
|
825 |
+
hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
|
826 |
+
return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
|
827 |
+
|
828 |
+
|
829 |
+
class NemotronHAttention(nn.Module):
|
830 |
+
"""Multi-headed attention from 'Attention Is All You Need' paper"""
|
831 |
+
|
832 |
+
def __init__(self, config: NemotronHConfig, layer_idx: Optional[int] = None):
|
833 |
+
super().__init__()
|
834 |
+
self.config = config
|
835 |
+
self.layer_idx = layer_idx
|
836 |
+
if layer_idx is None:
|
837 |
+
logger.warning_once(
|
838 |
+
f"Instantiating {self.__class__.__name__} without passing a `layer_idx` is not recommended and will "
|
839 |
+
"lead to errors during the forward call if caching is used. Please make sure to provide a `layer_idx` "
|
840 |
+
"when creating this class."
|
841 |
+
)
|
842 |
+
|
843 |
+
self.attention_dropout = config.attention_dropout
|
844 |
+
self.hidden_size = config.hidden_size
|
845 |
+
self.num_heads = config.num_attention_heads
|
846 |
+
if config.attention_head_dim is not None:
|
847 |
+
self.head_dim = config.attention_head_dim
|
848 |
+
else:
|
849 |
+
self.head_dim = config.hidden_size // config.num_attention_heads
|
850 |
+
self.num_key_value_heads = config.num_key_value_heads
|
851 |
+
self.num_key_value_groups = self.num_heads // self.num_key_value_heads
|
852 |
+
self.max_position_embeddings = config.max_position_embeddings
|
853 |
+
self.is_causal = True
|
854 |
+
|
855 |
+
self.q_proj = nn.Linear(self.hidden_size, self.num_heads * self.head_dim, bias=config.attention_bias)
|
856 |
+
self.k_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=config.attention_bias)
|
857 |
+
self.v_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=config.attention_bias)
|
858 |
+
self.o_proj = nn.Linear(self.head_dim * self.num_heads, self.hidden_size, bias=config.attention_bias)
|
859 |
+
|
860 |
+
def forward(
|
861 |
+
self,
|
862 |
+
hidden_states: torch.Tensor,
|
863 |
+
# position_embeddings: Tuple[torch.Tensor, torch.Tensor], #TODO
|
864 |
+
attention_mask: Optional[torch.Tensor] = None,
|
865 |
+
position_ids: Optional[torch.LongTensor] = None,
|
866 |
+
past_key_value: Optional[HybridMambaAttentionDynamicCache] = None,
|
867 |
+
output_attentions: bool = False,
|
868 |
+
use_cache: bool = False,
|
869 |
+
cache_position: Optional[torch.LongTensor] = None,
|
870 |
+
) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
|
871 |
+
bsz, q_len, _ = hidden_states.size()
|
872 |
+
|
873 |
+
query_states = self.q_proj(hidden_states)
|
874 |
+
key_states = self.k_proj(hidden_states)
|
875 |
+
value_states = self.v_proj(hidden_states)
|
876 |
+
|
877 |
+
query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
|
878 |
+
key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
879 |
+
value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
880 |
+
|
881 |
+
if past_key_value is not None:
|
882 |
+
key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx)
|
883 |
+
|
884 |
+
key_states = repeat_kv(key_states, self.num_key_value_groups)
|
885 |
+
value_states = repeat_kv(value_states, self.num_key_value_groups)
|
886 |
+
|
887 |
+
causal_mask = attention_mask
|
888 |
+
if attention_mask is not None: # no matter the length, we just slice it
|
889 |
+
causal_mask = attention_mask[:, :, :, : key_states.shape[-2]]
|
890 |
+
|
891 |
+
if query_states.device.type == "cuda" and attention_mask is not None:
|
892 |
+
query_states = query_states.contiguous()
|
893 |
+
key_states = key_states.contiguous()
|
894 |
+
value_states = value_states.contiguous()
|
895 |
+
|
896 |
+
is_causal = True if causal_mask is None and q_len > 1 else False
|
897 |
+
|
898 |
+
attn_output = torch.nn.functional.scaled_dot_product_attention(
|
899 |
+
query_states,
|
900 |
+
key_states,
|
901 |
+
value_states,
|
902 |
+
attn_mask=causal_mask,
|
903 |
+
dropout_p=self.attention_dropout if self.training else 0.0,
|
904 |
+
is_causal=is_causal,
|
905 |
+
)
|
906 |
+
attn_output = attn_output.transpose(1, 2).contiguous()
|
907 |
+
#attn_output = attn_output.view(bsz, q_len, self.hidden_size)
|
908 |
+
attn_output = attn_output.view(bsz, q_len, self.num_heads * self.head_dim)
|
909 |
+
|
910 |
+
attn_output = self.o_proj(attn_output)
|
911 |
+
|
912 |
+
return attn_output, None, past_key_value
|
913 |
+
|
914 |
+
|
915 |
+
# Adapted from transformers.models.mistral.modeling_mistral.MistralFlashAttention2 with Mistral->Jamba
|
916 |
+
#class JambaFlashAttention2(JambaAttention):
|
917 |
+
class NemotronHFlashAttention2(NemotronHAttention):
|
918 |
+
"""
|
919 |
+
Jamba flash attention module. This module inherits from `JambaAttention` as the weights of the module stays
|
920 |
+
untouched. The only required change would be on the forward pass where it needs to correctly call the public API of
|
921 |
+
flash attention and deal with padding tokens in case the input contains any of them.
|
922 |
+
"""
|
923 |
+
def __init__(self, *args, **kwargs):
|
924 |
+
super().__init__(*args, **kwargs)
|
925 |
+
|
926 |
+
# TODO: Should be removed once Flash Attention for RoCm is bumped to 2.1.
|
927 |
+
# flash_attn<2.1 generates top-left aligned causal mask, while what is needed here is bottom-right alignement, that was made default for flash_attn>=2.1. This attribute is used to handle this difference. Reference: https://github.com/Dao-AILab/flash-attention/releases/tag/v2.1.0.
|
928 |
+
# Beware that with flash_attn<2.1, using q_seqlen != k_seqlen (except for the case q_seqlen == 1) produces a wrong mask (top-left).
|
929 |
+
self._flash_attn_uses_top_left_mask = not is_flash_attn_greater_or_equal_2_10()
|
930 |
+
|
931 |
+
def forward(
|
932 |
+
self,
|
933 |
+
hidden_states: torch.Tensor,
|
934 |
+
attention_mask: Optional[torch.Tensor] = None,
|
935 |
+
position_ids: Optional[torch.LongTensor] = None,
|
936 |
+
past_key_value: Optional[HybridMambaAttentionDynamicCache] = None,
|
937 |
+
output_attentions: bool = False,
|
938 |
+
use_cache: bool = False,
|
939 |
+
cache_position: Optional[torch.LongTensor] = None,
|
940 |
+
**kwargs,
|
941 |
+
):
|
942 |
+
bsz, q_len, _ = hidden_states.size()
|
943 |
+
|
944 |
+
query_states = self.q_proj(hidden_states)
|
945 |
+
key_states = self.k_proj(hidden_states)
|
946 |
+
value_states = self.v_proj(hidden_states)
|
947 |
+
|
948 |
+
# Flash attention requires the input to have the shape
|
949 |
+
# batch_size x seq_length x head_dim x hidden_dim
|
950 |
+
# therefore we just need to keep the original shape
|
951 |
+
query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim)
|
952 |
+
key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
953 |
+
value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
954 |
+
|
955 |
+
if past_key_value is not None:
|
956 |
+
key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx)
|
957 |
+
|
958 |
+
# repeat k/v heads if n_kv_heads < n_heads
|
959 |
+
key_states = repeat_kv(key_states, self.num_key_value_groups)
|
960 |
+
value_states = repeat_kv(value_states, self.num_key_value_groups)
|
961 |
+
dropout_rate = 0.0 if not self.training else self.attention_dropout
|
962 |
+
|
963 |
+
# In PEFT, usually we cast the layer norms in float32 for training stability reasons
|
964 |
+
# therefore the input hidden states gets silently casted in float32. Hence, we need
|
965 |
+
# cast them back in float16 just to be sure everything works as expected.
|
966 |
+
input_dtype = query_states.dtype
|
967 |
+
if input_dtype == torch.float32:
|
968 |
+
if torch.is_autocast_enabled():
|
969 |
+
target_dtype = torch.get_autocast_gpu_dtype()
|
970 |
+
# Handle the case where the model is quantized
|
971 |
+
elif hasattr(self.config, "_pre_quantization_dtype"):
|
972 |
+
target_dtype = self.config._pre_quantization_dtype
|
973 |
+
else:
|
974 |
+
target_dtype = self.q_proj.weight.dtype
|
975 |
+
|
976 |
+
logger.warning_once(
|
977 |
+
f"The input hidden states seems to be silently casted in float32, this might be related to"
|
978 |
+
f" the fact you have upcasted embedding or layer norm layers in float32. We will cast back the input in"
|
979 |
+
f" {target_dtype}."
|
980 |
+
)
|
981 |
+
|
982 |
+
query_states = query_states.to(target_dtype)
|
983 |
+
key_states = key_states.to(target_dtype)
|
984 |
+
value_states = value_states.to(target_dtype)
|
985 |
+
|
986 |
+
# Reashape to the expected shape for Flash Attention
|
987 |
+
key_states = key_states.transpose(1, 2)
|
988 |
+
value_states = value_states.transpose(1, 2)
|
989 |
+
|
990 |
+
attn_output = _flash_attention_forward(
|
991 |
+
query_states,
|
992 |
+
key_states,
|
993 |
+
value_states,
|
994 |
+
attention_mask,
|
995 |
+
q_len,
|
996 |
+
dropout=dropout_rate,
|
997 |
+
sliding_window=getattr(self.config, "sliding_window", None),
|
998 |
+
is_causal=self.is_causal,
|
999 |
+
use_top_left_mask=self._flash_attn_uses_top_left_mask,
|
1000 |
+
)
|
1001 |
+
|
1002 |
+
#attn_output = attn_output.reshape(bsz, q_len, self.hidden_size).contiguous()
|
1003 |
+
attn_output = attn_output.reshape(bsz, q_len, self.num_heads * self.head_dim).contiguous()
|
1004 |
+
attn_output = self.o_proj(attn_output)
|
1005 |
+
|
1006 |
+
if not output_attentions:
|
1007 |
+
attn_weights = None
|
1008 |
+
|
1009 |
+
return attn_output, attn_weights, past_key_value
|
1010 |
+
|
1011 |
+
|
1012 |
+
# Adapted from transformers.models.mistral.modeling_mistral.MistralSdpaAttention with Mistral->Jamba
|
1013 |
+
#class JambaSdpaAttention(JambaAttention):
|
1014 |
+
class NemotronHSdpaAttention(NemotronHAttention):
|
1015 |
+
"""
|
1016 |
+
Jamba attention module using torch.nn.functional.scaled_dot_product_attention. This module inherits from
|
1017 |
+
`JambaAttention` as the weights of the module stays untouched. The only changes are on the forward pass to adapt to
|
1018 |
+
SDPA API.
|
1019 |
+
"""
|
1020 |
+
|
1021 |
+
# Adapted from NemotronHAttention.forward
|
1022 |
+
def forward(
|
1023 |
+
self,
|
1024 |
+
hidden_states: torch.Tensor,
|
1025 |
+
attention_mask: Optional[torch.Tensor] = None,
|
1026 |
+
position_ids: Optional[torch.LongTensor] = None,
|
1027 |
+
past_key_value: Optional[HybridMambaAttentionDynamicCache] = None,
|
1028 |
+
output_attentions: bool = False,
|
1029 |
+
use_cache: bool = False,
|
1030 |
+
cache_position: Optional[torch.LongTensor] = None,
|
1031 |
+
) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
|
1032 |
+
if output_attentions:
|
1033 |
+
# TODO: Improve this warning with e.g. `model.config.attn_implementation = "manual"` once this is implemented.
|
1034 |
+
logger.warning_once(
|
1035 |
+
"NemotronHModel is using NemotronHSdpaAttention, but `torch.nn.functional.scaled_dot_product_attention` does not support `output_attentions=True`. Falling back to the manual attention implementation, "
|
1036 |
+
'but specifying the manual implementation will be required from Transformers version v5.0.0 onwards. This warning can be removed using the argument `attn_implementation="eager"` when loading the model.'
|
1037 |
+
)
|
1038 |
+
return super().forward(
|
1039 |
+
hidden_states=hidden_states,
|
1040 |
+
attention_mask=attention_mask,
|
1041 |
+
position_ids=position_ids,
|
1042 |
+
past_key_value=past_key_value,
|
1043 |
+
output_attentions=output_attentions,
|
1044 |
+
use_cache=use_cache,
|
1045 |
+
)
|
1046 |
+
|
1047 |
+
bsz, q_len, _ = hidden_states.size()
|
1048 |
+
|
1049 |
+
query_states = self.q_proj(hidden_states)
|
1050 |
+
key_states = self.k_proj(hidden_states)
|
1051 |
+
value_states = self.v_proj(hidden_states)
|
1052 |
+
|
1053 |
+
query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
|
1054 |
+
key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
1055 |
+
value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
1056 |
+
|
1057 |
+
if past_key_value is not None:
|
1058 |
+
key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx)
|
1059 |
+
|
1060 |
+
key_states = repeat_kv(key_states, self.num_key_value_groups)
|
1061 |
+
value_states = repeat_kv(value_states, self.num_key_value_groups)
|
1062 |
+
|
1063 |
+
causal_mask = attention_mask
|
1064 |
+
if attention_mask is not None:
|
1065 |
+
causal_mask = causal_mask[:, :, :, : key_states.shape[-2]]
|
1066 |
+
|
1067 |
+
# SDPA with memory-efficient backend is currently (torch==2.1.2) bugged with non-contiguous inputs with custom attn_mask,
|
1068 |
+
# Reference: https://github.com/pytorch/pytorch/issues/112577.
|
1069 |
+
if query_states.device.type == "cuda" and attention_mask is not None:
|
1070 |
+
query_states = query_states.contiguous()
|
1071 |
+
key_states = key_states.contiguous()
|
1072 |
+
value_states = value_states.contiguous()
|
1073 |
+
|
1074 |
+
# We dispatch to SDPA's Flash Attention or Efficient kernels via this `is_causal` if statement instead of an inline conditional assignment
|
1075 |
+
# in SDPA to support both torch.compile's dynamic shapes and full graph options. An inline conditional prevents dynamic shapes from compiling.
|
1076 |
+
# The q_len > 1 is necessary to match with AttentionMaskConverter.to_causal_4d that does not create a causal mask in case q_len == 1.
|
1077 |
+
is_causal = True if self.is_causal and causal_mask is None and q_len > 1 else False
|
1078 |
+
|
1079 |
+
attn_output = torch.nn.functional.scaled_dot_product_attention(
|
1080 |
+
query_states,
|
1081 |
+
key_states,
|
1082 |
+
value_states,
|
1083 |
+
attn_mask=causal_mask,
|
1084 |
+
dropout_p=self.attention_dropout if self.training else 0.0,
|
1085 |
+
is_causal=is_causal,
|
1086 |
+
)
|
1087 |
+
|
1088 |
+
attn_output = attn_output.transpose(1, 2).contiguous()
|
1089 |
+
attn_output = attn_output.view(bsz, q_len, self.hidden_size)
|
1090 |
+
|
1091 |
+
attn_output = self.o_proj(attn_output)
|
1092 |
+
|
1093 |
+
return attn_output, None, past_key_value
|
1094 |
+
|
1095 |
+
|
1096 |
+
NEMOTRONH_ATTENTION_CLASSES = {
|
1097 |
+
"eager": NemotronHAttention,
|
1098 |
+
"flash_attention_2": NemotronHFlashAttention2,
|
1099 |
+
"sdpa": NemotronHSdpaAttention,
|
1100 |
+
}
|
1101 |
+
|
1102 |
+
# Copied from transformers.models.mamba.modeling_mamba2.Mamba2PreTrainedModel
|
1103 |
+
class NemotronHPreTrainedModel(PreTrainedModel):
|
1104 |
+
"""
|
1105 |
+
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
|
1106 |
+
models.
|
1107 |
+
"""
|
1108 |
+
|
1109 |
+
config_class = NemotronHConfig
|
1110 |
+
base_model_prefix = "backbone"
|
1111 |
+
_no_split_modules = ["NemotronHBlock"]
|
1112 |
+
supports_gradient_checkpointing = True
|
1113 |
+
_is_stateful = True
|
1114 |
+
|
1115 |
+
def _init_weights(self, module):
|
1116 |
+
"""Initialize the weights."""
|
1117 |
+
if isinstance(module, NemotronHMamba2Mixer):
|
1118 |
+
module.A_log._no_weight_decay = True
|
1119 |
+
module.D._no_weight_decay = True
|
1120 |
+
|
1121 |
+
dt = torch.exp(
|
1122 |
+
torch.rand(self.config.mamba_num_heads)
|
1123 |
+
* (math.log(self.config.time_step_max) - math.log(self.config.time_step_min))
|
1124 |
+
+ math.log(self.config.time_step_min)
|
1125 |
+
).clamp(min=self.config.time_step_floor)
|
1126 |
+
|
1127 |
+
# # Inverse of softplus: https://github.com/pytorch/pytorch/issues/72759
|
1128 |
+
inv_dt = dt + torch.log(-torch.expm1(-dt))
|
1129 |
+
with torch.no_grad():
|
1130 |
+
module.dt_bias.copy_(inv_dt)
|
1131 |
+
module.dt_bias._no_reinit = True
|
1132 |
+
|
1133 |
+
if isinstance(module, nn.Linear):
|
1134 |
+
if module.bias is not None:
|
1135 |
+
if not getattr(module.bias, "_no_reinit", False):
|
1136 |
+
nn.init.zeros_(module.bias)
|
1137 |
+
elif isinstance(module, nn.Embedding):
|
1138 |
+
nn.init.normal_(module.weight, std=self.config.initializer_range)
|
1139 |
+
|
1140 |
+
# TODO: Check
|
1141 |
+
if self.config.rescale_prenorm_residual:
|
1142 |
+
# Reinitialize selected weights subject to the OpenAI GPT-2 Paper Scheme:
|
1143 |
+
# > A modified initialization which accounts for the accumulation on the residual path with model depth. Scale
|
1144 |
+
# > the weights of residual layers at initialization by a factor of 1/√N where N is the # of residual layers.
|
1145 |
+
# > -- GPT-2 :: https://openai.com/blog/better-language-models/
|
1146 |
+
#
|
1147 |
+
# Reference (Megatron-LM): https://github.com/NVIDIA/Megatron-LM/blob/main/megatron/model/gpt_model.py
|
1148 |
+
for name, p in module.named_parameters():
|
1149 |
+
if name in ["out_proj.weight"]:
|
1150 |
+
# Special Scaled Initialization --> There are 2 Layer Norms per Transformer Block
|
1151 |
+
# Following Pytorch init, except scale by 1/sqrt(2 * n_layer)
|
1152 |
+
# We need to reinit p since this code could be called multiple times
|
1153 |
+
# Having just p *= scale would repeatedly scale it down
|
1154 |
+
nn.init.kaiming_uniform_(p, a=math.sqrt(5))
|
1155 |
+
with torch.no_grad():
|
1156 |
+
p /= math.sqrt(self.config.num_hidden_layers)
|
1157 |
+
|
1158 |
+
|
1159 |
+
@dataclass
|
1160 |
+
# Copied from transformers.models.mamba.modeling_mamba2.Mamba2Output with MAMBA2->NemotronH,Mamba2->NemotronH
|
1161 |
+
class NemotronHOutput(ModelOutput):
|
1162 |
+
"""
|
1163 |
+
Class for the NemotronH model outputs.
|
1164 |
+
|
1165 |
+
Args:
|
1166 |
+
last_hidden_state (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
|
1167 |
+
Sequence of hidden-states at the output of the last layer of the model.
|
1168 |
+
cache_params (`HybridMambaAttentionDynamicCache`):
|
1169 |
+
The state of the model at the last time step. Can be used in a forward method with the next `input_ids` to
|
1170 |
+
avoid providing the old `input_ids`.
|
1171 |
+
|
1172 |
+
Includes both the State space model state matrices after the selective scan, and the Convolutional states
|
1173 |
+
hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
|
1174 |
+
Tuple of `torch.FloatTensor` (one for the output of the embeddings, if the model has an embedding layer, +
|
1175 |
+
one for the output of each layer) of shape `(batch_size, sequence_length, hidden_size)`.
|
1176 |
+
|
1177 |
+
Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.
|
1178 |
+
"""
|
1179 |
+
|
1180 |
+
last_hidden_state: Optional[torch.FloatTensor] = None
|
1181 |
+
cache_params: Optional[HybridMambaAttentionDynamicCache] = None
|
1182 |
+
hidden_states: Optional[Tuple[torch.FloatTensor]] = None
|
1183 |
+
attentions: Optional[Tuple[torch.FloatTensor]] = None
|
1184 |
+
|
1185 |
+
|
1186 |
+
@dataclass
|
1187 |
+
# Copied from transformers.models.mamba2.modeling_mamba2.MambaCausalLMOutput with Mamba2->NemotronH
|
1188 |
+
class NemotronHCausalLMOutput(ModelOutput):
|
1189 |
+
"""
|
1190 |
+
Base class for causal language model (or autoregressive) outputs.
|
1191 |
+
|
1192 |
+
Args:
|
1193 |
+
loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
|
1194 |
+
Language modeling loss (for next-token prediction).
|
1195 |
+
logits (`torch.FloatTensor` of shape `(batch_size, sequence_length, config.vocab_size)`):
|
1196 |
+
Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).
|
1197 |
+
cache_params (`HybridMambaAttentionDynamicCache`):
|
1198 |
+
The state of the model at the last time step. Can be used in a forward method with the next `input_ids` to
|
1199 |
+
avoid providing the old `input_ids`.
|
1200 |
+
|
1201 |
+
Includes both the State space model state matrices after the selective scan, and the Convolutional states
|
1202 |
+
hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
|
1203 |
+
Tuple of `torch.FloatTensor` (one for the output of the embeddings, if the model has an embedding layer, +
|
1204 |
+
one for the output of each layer) of shape `(batch_size, sequence_length, hidden_size)`.
|
1205 |
+
|
1206 |
+
Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.
|
1207 |
+
"""
|
1208 |
+
|
1209 |
+
loss: Optional[torch.FloatTensor] = None
|
1210 |
+
logits: Optional[torch.FloatTensor] = None
|
1211 |
+
cache_params: Optional[HybridMambaAttentionDynamicCache] = None
|
1212 |
+
hidden_states: Optional[Tuple[torch.FloatTensor]] = None
|
1213 |
+
attentions: Optional[Tuple[torch.FloatTensor]] = None
|
1214 |
+
|
1215 |
+
|
1216 |
+
NEMOTRONH_START_DOCSTRING = r"""
|
1217 |
+
|
1218 |
+
This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
|
1219 |
+
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
|
1220 |
+
etc.)
|
1221 |
+
|
1222 |
+
This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
|
1223 |
+
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
|
1224 |
+
and behavior.
|
1225 |
+
|
1226 |
+
Parameters:
|
1227 |
+
config ([`NemotronHConfig`]): Model configuration class with all the parameters of the model.
|
1228 |
+
Initializing with a config file does not load the weights associated with the model, only the
|
1229 |
+
configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.
|
1230 |
+
"""
|
1231 |
+
|
1232 |
+
NEMOTRONH_INPUTS_DOCSTRING = r"""
|
1233 |
+
Args:
|
1234 |
+
input_ids (`torch.LongTensor` of shape `(batch_size, input_ids_length)`, *optional*):
|
1235 |
+
Indices of input sequence tokens in the vocabulary.
|
1236 |
+
|
1237 |
+
If `cache_params.seqlen_offset>0`, only `input_ids` that do not have their past calculated should be passed as
|
1238 |
+
`input_ids`.
|
1239 |
+
|
1240 |
+
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
|
1241 |
+
[`PreTrainedTokenizer.__call__`] for details.
|
1242 |
+
|
1243 |
+
[What are input IDs?](../glossary#input-ids)
|
1244 |
+
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
|
1245 |
+
Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
|
1246 |
+
is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
|
1247 |
+
model's internal embedding lookup matrix.
|
1248 |
+
position_ids (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
|
1249 |
+
Indices of positions of each input sequence tokens in the position embeddings.
|
1250 |
+
cache_params (`HybridMambaAttentionDynamicCache`, *optional*):
|
1251 |
+
If passed along, the model uses the previous state in all the blocks (which will give the output for the
|
1252 |
+
`input_ids` provided as if the model add `state_input_ids + input_ids` as context).
|
1253 |
+
use_cache (`bool`, *optional*):
|
1254 |
+
If set to `True`, the `cache_params` is returned and can be used to quickly generate the next logits.
|
1255 |
+
output_attentions (`bool`, *optional*):
|
1256 |
+
Whether or not to return the attentions tensors of all attention layers.
|
1257 |
+
output_hidden_states (`bool`, *optional*):
|
1258 |
+
Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
|
1259 |
+
more detail.
|
1260 |
+
return_dict (`bool`, *optional*):
|
1261 |
+
Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
|
1262 |
+
cache_position (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
|
1263 |
+
The position of the current input in the cache. This is used to ensure that the cache is correctly updated.
|
1264 |
+
If `cache_params` is passed, `cache_position` should also be passed.
|
1265 |
+
attention_mask (`torch.FloatTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
1266 |
+
Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
|
1267 |
+
|
1268 |
+
- 1 for tokens that are **not masked**,
|
1269 |
+
- 0 for tokens that are **masked**.
|
1270 |
+
|
1271 |
+
[What are attention masks?](../glossary#attention-mask)
|
1272 |
+
"""
|
1273 |
+
|
1274 |
+
|
1275 |
+
@add_start_docstrings(
|
1276 |
+
"The bare NemotronH Model transformer outputting raw hidden-states without any specific head on top.",
|
1277 |
+
NEMOTRONH_START_DOCSTRING,
|
1278 |
+
)
|
1279 |
+
class NemotronHModel(NemotronHPreTrainedModel):
|
1280 |
+
def __init__(self, config):
|
1281 |
+
super().__init__(config)
|
1282 |
+
|
1283 |
+
self.embeddings = nn.Embedding(config.vocab_size, config.hidden_size)
|
1284 |
+
self.layers = nn.ModuleList([NemotronHBlock(config, layer_idx=idx) for idx in range(config.num_hidden_layers)])
|
1285 |
+
|
1286 |
+
self.gradient_checkpointing = False
|
1287 |
+
self.norm_f = NemotronHRMSNorm(config.hidden_size, eps=config.layer_norm_epsilon)
|
1288 |
+
# Initialize weights and apply final processing
|
1289 |
+
self._register_load_state_dict_pre_hook(self.load_hook)
|
1290 |
+
self.post_init()
|
1291 |
+
|
1292 |
+
def load_hook(self, state_dict, prefix, *args):
|
1293 |
+
for k in state_dict:
|
1294 |
+
if "embedding." in k:
|
1295 |
+
state_dict[k.replace("embedding.", "embeddings.")] = state_dict.pop(k)
|
1296 |
+
break
|
1297 |
+
|
1298 |
+
def get_input_embeddings(self):
|
1299 |
+
return self.embeddings
|
1300 |
+
|
1301 |
+
def set_input_embeddings(self, new_embeddings):
|
1302 |
+
self.embeddings = new_embeddings
|
1303 |
+
|
1304 |
+
@add_start_docstrings_to_model_forward(NEMOTRONH_INPUTS_DOCSTRING)
|
1305 |
+
@add_code_sample_docstrings(
|
1306 |
+
checkpoint=_CHECKPOINT_FOR_DOC,
|
1307 |
+
output_type=NemotronHOutput,
|
1308 |
+
config_class=_CONFIG_FOR_DOC,
|
1309 |
+
)
|
1310 |
+
def forward(
|
1311 |
+
self,
|
1312 |
+
input_ids: Optional[torch.LongTensor] = None,
|
1313 |
+
inputs_embeds: Optional[torch.LongTensor] = None,
|
1314 |
+
position_ids: Optional[torch.LongTensor] = None,
|
1315 |
+
cache_params: Optional[HybridMambaAttentionDynamicCache] = None,
|
1316 |
+
use_cache: Optional[bool] = None,
|
1317 |
+
output_attentions: Optional[bool] = None,
|
1318 |
+
output_hidden_states: Optional[bool] = None,
|
1319 |
+
return_dict: Optional[bool] = None,
|
1320 |
+
cache_position: Optional[torch.LongTensor] = None,
|
1321 |
+
attention_mask: Optional[torch.Tensor] = None,
|
1322 |
+
**kwargs,
|
1323 |
+
) -> Union[Tuple, NemotronHOutput]:
|
1324 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
1325 |
+
output_hidden_states = (
|
1326 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
1327 |
+
)
|
1328 |
+
# use_cache = use_cache if use_cache is not None else self.config.use_cache
|
1329 |
+
use_cache = use_cache if use_cache is not None else (self.config.use_cache if not self.training else False)
|
1330 |
+
|
1331 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
1332 |
+
|
1333 |
+
if (input_ids is None) ^ (inputs_embeds is not None): # ^ is python for xor
|
1334 |
+
raise ValueError("You must specify exactly one of input_ids or inputs_embeds")
|
1335 |
+
|
1336 |
+
if inputs_embeds is None:
|
1337 |
+
inputs_embeds = self.embeddings(input_ids)
|
1338 |
+
|
1339 |
+
if self.gradient_checkpointing and self.training and use_cache:
|
1340 |
+
logger.warning_once(
|
1341 |
+
"`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`."
|
1342 |
+
)
|
1343 |
+
use_cache = False
|
1344 |
+
|
1345 |
+
# From zamba_modeling.py
|
1346 |
+
if use_cache and cache_params is None:
|
1347 |
+
logger.warning_once(
|
1348 |
+
"NemotronH requires an initialized `NemotronHHybridDynamicCache` to return a cache. None was "
|
1349 |
+
"provided, so no cache will be returned."
|
1350 |
+
)
|
1351 |
+
|
1352 |
+
hidden_states = inputs_embeds
|
1353 |
+
|
1354 |
+
if cache_position is None:
|
1355 |
+
cache_position = torch.arange(hidden_states.shape[1], device=hidden_states.device)
|
1356 |
+
if position_ids is None:
|
1357 |
+
position_ids = cache_position.unsqueeze(0)
|
1358 |
+
|
1359 |
+
causal_mask = self._update_causal_mask(attention_mask, inputs_embeds, cache_position)
|
1360 |
+
mamba_mask = self._update_mamba_mask(attention_mask, cache_position)
|
1361 |
+
|
1362 |
+
all_hidden_states = () if output_hidden_states else None
|
1363 |
+
all_self_attns = () if output_attentions else None
|
1364 |
+
# Until HERE
|
1365 |
+
|
1366 |
+
for layer_idx, mixer_block in enumerate(self.layers):
|
1367 |
+
# Depending on the layer type we opt for 2D base attention mask (Mamba) or 4D causal mask (Attention)
|
1368 |
+
if mixer_block.block_type == "mamba":
|
1369 |
+
layer_mask = mamba_mask
|
1370 |
+
elif mixer_block.block_type == "attention":
|
1371 |
+
layer_mask = causal_mask
|
1372 |
+
elif mixer_block.block_type == "mlp":
|
1373 |
+
layer_mask = None
|
1374 |
+
else:
|
1375 |
+
raise ValueError(f"Invalid block_type: {self.block_type}")
|
1376 |
+
|
1377 |
+
if output_hidden_states:
|
1378 |
+
all_hidden_states += (hidden_states,)
|
1379 |
+
|
1380 |
+
if self.gradient_checkpointing and self.training:
|
1381 |
+
hidden_states = self._gradient_checkpointing_func(
|
1382 |
+
mixer_block.__call__, hidden_states, cache_params, cache_position, layer_mask
|
1383 |
+
)
|
1384 |
+
else:
|
1385 |
+
hidden_states = mixer_block(
|
1386 |
+
hidden_states,
|
1387 |
+
cache_params=cache_params,
|
1388 |
+
cache_position=cache_position,
|
1389 |
+
attention_mask=layer_mask,
|
1390 |
+
)
|
1391 |
+
|
1392 |
+
# TODO: Store attentions
|
1393 |
+
# if output_attentions:
|
1394 |
+
# if layer_outputs[1] is not None:
|
1395 |
+
# # append attentions only of attention layers. Mamba layers return `None` as the attention weights
|
1396 |
+
# all_self_attns += (layer_outputs[1],)
|
1397 |
+
|
1398 |
+
# TODO (Check): should it happen before the forward pass?
|
1399 |
+
# if output_hidden_states:
|
1400 |
+
# all_hidden_states = all_hidden_states + (hidden_states,)
|
1401 |
+
|
1402 |
+
hidden_states = self.norm_f(hidden_states)
|
1403 |
+
|
1404 |
+
if output_hidden_states:
|
1405 |
+
all_hidden_states = all_hidden_states + (hidden_states,)
|
1406 |
+
|
1407 |
+
if not return_dict:
|
1408 |
+
return tuple(v for v in [hidden_states, cache_params, all_hidden_states] if v is not None)
|
1409 |
+
|
1410 |
+
return NemotronHOutput(
|
1411 |
+
last_hidden_state=hidden_states,
|
1412 |
+
cache_params=cache_params if use_cache else None,
|
1413 |
+
hidden_states=all_hidden_states,
|
1414 |
+
attentions=all_self_attns,
|
1415 |
+
)
|
1416 |
+
|
1417 |
+
# Copied from transformers.models.jamba.modeling_jamba.JambaModel._update_causal_mask
|
1418 |
+
def _update_causal_mask(self, attention_mask, input_tensor, cache_position):
|
1419 |
+
if self.config._attn_implementation == "flash_attention_2":
|
1420 |
+
if attention_mask is not None and 0.0 in attention_mask:
|
1421 |
+
return attention_mask
|
1422 |
+
return None
|
1423 |
+
|
1424 |
+
dtype, device = input_tensor.dtype, input_tensor.device
|
1425 |
+
min_dtype = torch.finfo(dtype).min
|
1426 |
+
sequence_length = input_tensor.shape[1]
|
1427 |
+
target_length = cache_position[-1] + 1
|
1428 |
+
|
1429 |
+
causal_mask = torch.full((sequence_length, target_length), fill_value=min_dtype, dtype=dtype, device=device)
|
1430 |
+
if sequence_length != 1:
|
1431 |
+
causal_mask = torch.triu(causal_mask, diagonal=1)
|
1432 |
+
causal_mask *= torch.arange(target_length, device=device) > cache_position.reshape(-1, 1)
|
1433 |
+
causal_mask = causal_mask[None, None, :, :].expand(input_tensor.shape[0], 1, -1, -1)
|
1434 |
+
if attention_mask is not None:
|
1435 |
+
causal_mask = causal_mask.clone() # copy to contiguous memory for in-place edit
|
1436 |
+
if attention_mask.dim() == 2:
|
1437 |
+
mask_length = attention_mask.shape[-1]
|
1438 |
+
padding_mask = causal_mask[..., :mask_length].eq(0.0) * attention_mask[:, None, None, :].eq(0.0)
|
1439 |
+
causal_mask[..., :mask_length] = causal_mask[..., :mask_length].masked_fill(padding_mask, min_dtype)
|
1440 |
+
|
1441 |
+
if (
|
1442 |
+
self.config._attn_implementation == "sdpa"
|
1443 |
+
and attention_mask is not None
|
1444 |
+
and attention_mask.device.type == "cuda"
|
1445 |
+
):
|
1446 |
+
# Attend to all tokens in fully masked rows in the causal_mask, for example the relevant first rows when
|
1447 |
+
# using left padding. This is required by F.scaled_dot_product_attention memory-efficient attention path.
|
1448 |
+
# Details: https://github.com/pytorch/pytorch/issues/110213
|
1449 |
+
causal_mask = AttentionMaskConverter._unmask_unattended(causal_mask, min_dtype)
|
1450 |
+
|
1451 |
+
return causal_mask
|
1452 |
+
|
1453 |
+
def _update_mamba_mask(self, attention_mask, cache_position):
|
1454 |
+
"""
|
1455 |
+
No need for zeroing states when
|
1456 |
+
1. Cached forward
|
1457 |
+
2. Attending to all inputs
|
1458 |
+
"""
|
1459 |
+
mamba_mask = attention_mask
|
1460 |
+
if cache_position[0] > 0 or (attention_mask is not None and torch.all(attention_mask == 1)):
|
1461 |
+
mamba_mask = None
|
1462 |
+
return mamba_mask
|
1463 |
+
|
1464 |
+
|
1465 |
+
@add_start_docstrings(
|
1466 |
+
"""
|
1467 |
+
The NEMOTRONH Model transformer with a language modeling head on top (linear layer with weights not tied to the input
|
1468 |
+
embeddings).
|
1469 |
+
""",
|
1470 |
+
NEMOTRONH_START_DOCSTRING,
|
1471 |
+
)
|
1472 |
+
class NemotronHForCausalLM(NemotronHPreTrainedModel, GenerationMixin):
|
1473 |
+
_tied_weights_keys = ["lm_head.weight"]
|
1474 |
+
|
1475 |
+
def __init__(self, config):
|
1476 |
+
super().__init__(config)
|
1477 |
+
self.backbone = NemotronHModel(config)
|
1478 |
+
self.vocab_size = config.vocab_size
|
1479 |
+
self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
|
1480 |
+
|
1481 |
+
# Initialize weights and apply final processing
|
1482 |
+
self.post_init()
|
1483 |
+
|
1484 |
+
def get_input_embeddings(self):
|
1485 |
+
return self.backbone.get_input_embeddings()
|
1486 |
+
|
1487 |
+
def set_input_embeddings(self, new_embeddings):
|
1488 |
+
return self.backbone.set_input_embeddings(new_embeddings)
|
1489 |
+
|
1490 |
+
def get_output_embeddings(self):
|
1491 |
+
return self.lm_head
|
1492 |
+
|
1493 |
+
def set_output_embeddings(self, new_embeddings):
|
1494 |
+
self.lm_head = new_embeddings
|
1495 |
+
|
1496 |
+
def get_decoder(self):
|
1497 |
+
return self.model
|
1498 |
+
|
1499 |
+
def set_decoder(self, decoder):
|
1500 |
+
self.model = decoder
|
1501 |
+
|
1502 |
+
def prepare_inputs_for_generation(
|
1503 |
+
self,
|
1504 |
+
input_ids,
|
1505 |
+
past_key_values=None,
|
1506 |
+
attention_mask=None,
|
1507 |
+
inputs_embeds=None,
|
1508 |
+
cache_position=None,
|
1509 |
+
position_ids=None,
|
1510 |
+
use_cache=True,
|
1511 |
+
**kwargs,
|
1512 |
+
):
|
1513 |
+
# Copy from https://github.com/huggingface/transformers/blob/main/src/transformers/models/jamba/modeling_jamba.py
|
1514 |
+
# Overwitten -- uses `cache_params` as opposed to `past_key_values`
|
1515 |
+
empty_past_kv = past_key_values is None
|
1516 |
+
|
1517 |
+
# If we have cache: let's slice `input_ids` through `cache_position`, to keep only the unprocessed tokens
|
1518 |
+
# Exception 1: when passing input_embeds, input_ids may be missing entries
|
1519 |
+
# Exception 2: some generation methods do special slicing of input_ids, so we don't need to do it here
|
1520 |
+
# Exception 3: with synced GPUs cache_position may go out of bounds, but we only want dummy token in that case.
|
1521 |
+
# (we can't check exception 3 while compiling)
|
1522 |
+
if not empty_past_kv:
|
1523 |
+
if (
|
1524 |
+
inputs_embeds is not None # Exception 1
|
1525 |
+
or cache_position[-1] >= input_ids.shape[1] # Exception 3
|
1526 |
+
):
|
1527 |
+
input_ids = input_ids[:, -cache_position.shape[0] :]
|
1528 |
+
elif input_ids.shape[1] != cache_position.shape[0]: # Default case (the "else", a no op, is Exception 2)
|
1529 |
+
input_ids = input_ids[:, cache_position]
|
1530 |
+
else:
|
1531 |
+
past_key_values = HybridMambaAttentionDynamicCache(
|
1532 |
+
self.config, input_ids.shape[0], self.dtype, device=self.device
|
1533 |
+
)
|
1534 |
+
|
1535 |
+
if attention_mask is not None and position_ids is None:
|
1536 |
+
# create position_ids on the fly for batch generation
|
1537 |
+
position_ids = attention_mask.long().cumsum(-1) - 1
|
1538 |
+
position_ids.masked_fill_(attention_mask == 0, 1)
|
1539 |
+
if not empty_past_kv:
|
1540 |
+
position_ids = position_ids[:, -input_ids.shape[1] :]
|
1541 |
+
|
1542 |
+
# if `inputs_embeds` are passed, we only want to use them in the 1st generation step
|
1543 |
+
if inputs_embeds is not None and empty_past_kv:
|
1544 |
+
model_inputs = {"inputs_embeds": inputs_embeds}
|
1545 |
+
else:
|
1546 |
+
model_inputs = {"input_ids": input_ids.contiguous()} # `contiguous()` needed for compilation use cases
|
1547 |
+
|
1548 |
+
model_inputs.update(
|
1549 |
+
{
|
1550 |
+
"position_ids": position_ids,
|
1551 |
+
"past_key_values": past_key_values,
|
1552 |
+
"use_cache": use_cache,
|
1553 |
+
"attention_mask": attention_mask,
|
1554 |
+
"logits_to_keep": self.config.num_logits_to_keep,
|
1555 |
+
"cache_position": cache_position,
|
1556 |
+
}
|
1557 |
+
)
|
1558 |
+
return model_inputs
|
1559 |
+
|
1560 |
+
@add_start_docstrings_to_model_forward(NEMOTRONH_INPUTS_DOCSTRING)
|
1561 |
+
@add_code_sample_docstrings(
|
1562 |
+
checkpoint=_CHECKPOINT_FOR_DOC,
|
1563 |
+
output_type=NemotronHCausalLMOutput,
|
1564 |
+
config_class=_CONFIG_FOR_DOC,
|
1565 |
+
)
|
1566 |
+
def forward(
|
1567 |
+
self,
|
1568 |
+
input_ids: Optional[torch.LongTensor] = None,
|
1569 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
1570 |
+
position_ids: Optional[torch.LongTensor] = None,
|
1571 |
+
cache_params: Optional[HybridMambaAttentionDynamicCache] = None,
|
1572 |
+
labels: Optional[torch.LongTensor] = None,
|
1573 |
+
output_attentions: Optional[bool] = None,
|
1574 |
+
output_hidden_states: Optional[bool] = None,
|
1575 |
+
return_dict: Optional[bool] = None,
|
1576 |
+
use_cache: Optional[bool] = None,
|
1577 |
+
cache_position: Optional[torch.Tensor] = None,
|
1578 |
+
attention_mask: Optional[torch.Tensor] = None,
|
1579 |
+
**kwargs, # for now we need this for generation
|
1580 |
+
) -> Union[Tuple, NemotronHCausalLMOutput]:
|
1581 |
+
r"""
|
1582 |
+
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
1583 |
+
Labels for language modeling. Note that the labels **are shifted** inside the model, i.e. you can set
|
1584 |
+
`labels = input_ids` Indices are selected in `[-100, 0, ..., config.vocab_size]` All labels set to `-100`
|
1585 |
+
are ignored (masked), the loss is only computed for labels in `[0, ..., config.vocab_size]`
|
1586 |
+
"""
|
1587 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
1588 |
+
|
1589 |
+
output_hidden_states = (
|
1590 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
1591 |
+
)
|
1592 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
1593 |
+
|
1594 |
+
nemotron_h_outputs = self.backbone(
|
1595 |
+
input_ids,
|
1596 |
+
cache_params=cache_params,
|
1597 |
+
inputs_embeds=inputs_embeds,
|
1598 |
+
output_attentions=output_attentions,
|
1599 |
+
output_hidden_states=output_hidden_states,
|
1600 |
+
return_dict=return_dict,
|
1601 |
+
use_cache=use_cache,
|
1602 |
+
cache_position=cache_position,
|
1603 |
+
attention_mask=attention_mask,
|
1604 |
+
)
|
1605 |
+
hidden_states = nemotron_h_outputs[0]
|
1606 |
+
|
1607 |
+
# TODO: Check zamba_modeling.py: https://github.com/huggingface/transformers/blob/d7188ba600e36d3fd191b12e19f1b3bb81a8404f/src/transformers/models/zamba/modeling_zamba.py#L1284C1-L1286C2
|
1608 |
+
#logits = self.lm_head(hidden_states.to(self.lm_head.weight.dtype)).float()
|
1609 |
+
logits = self.lm_head(hidden_states.to(self.lm_head.weight.dtype)).float()
|
1610 |
+
|
1611 |
+
loss = None
|
1612 |
+
if labels is not None:
|
1613 |
+
# move labels to correct device to enable model parallelism
|
1614 |
+
labels = labels.to(logits.device)
|
1615 |
+
# Shift so that tokens < n predict n
|
1616 |
+
shift_logits = logits[..., :-1, :].contiguous()
|
1617 |
+
shift_labels = labels[..., 1:].contiguous()
|
1618 |
+
# Flatten the tokens
|
1619 |
+
loss_fct = CrossEntropyLoss()
|
1620 |
+
loss = loss_fct(shift_logits.view(-1, shift_logits.size(-1)), shift_labels.view(-1))
|
1621 |
+
|
1622 |
+
if not return_dict:
|
1623 |
+
output = (logits,) + nemotron_h_outputs[1:]
|
1624 |
+
return ((loss,) + output) if loss is not None else output
|
1625 |
+
|
1626 |
+
return NemotronHCausalLMOutput(
|
1627 |
+
loss=loss,
|
1628 |
+
logits=logits,
|
1629 |
+
cache_params=nemotron_h_outputs.cache_params,
|
1630 |
+
hidden_states=nemotron_h_outputs.hidden_states,
|
1631 |
+
attentions=nemotron_h_outputs.attentions,
|
1632 |
+
)
|
special_tokens_map.json
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bos_token": {
|
3 |
+
"content": "<s>",
|
4 |
+
"lstrip": false,
|
5 |
+
"normalized": false,
|
6 |
+
"rstrip": false,
|
7 |
+
"single_word": false
|
8 |
+
},
|
9 |
+
"eos_token": {
|
10 |
+
"content": "</s>",
|
11 |
+
"lstrip": false,
|
12 |
+
"normalized": false,
|
13 |
+
"rstrip": false,
|
14 |
+
"single_word": false
|
15 |
+
},
|
16 |
+
"unk_token": {
|
17 |
+
"content": "<unk>",
|
18 |
+
"lstrip": false,
|
19 |
+
"normalized": false,
|
20 |
+
"rstrip": false,
|
21 |
+
"single_word": false
|
22 |
+
}
|
23 |
+
}
|
tokenizer.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3277c00fe5fb3963b3cb7c07b7f183722d2af4d775a4aea7cfb3684d7cccbc2f
|
3 |
+
size 17078330
|
tokenizer_config.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|