Jeronymous commited on
Commit
1130796
·
verified ·
1 Parent(s): bb101c0

upload Luciole-8B-Instruct-1.1-FP8

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