alexa4cg commited on
Commit
811b9c5
·
verified ·
1 Parent(s): e171823

(Trained with Unsloth)

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
chat_template.jinja ADDED
@@ -0,0 +1,206 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {# Unsloth template fixes #}
2
+ {% macro render_extra_keys(json_dict, handled_keys) %}
3
+ {%- if json_dict is mapping %}
4
+ {%- for json_key in json_dict if json_key not in handled_keys %}
5
+ {%- if json_dict[json_key] is mapping or (json_dict[json_key] is sequence and json_dict[json_key] is not string) %}
6
+ {{- '\n<' ~ json_key ~ '>' ~ (json_dict[json_key] | tojson | safe) ~ '</' ~ json_key ~ '>' }}
7
+ {%- else %}
8
+ {{-'\n<' ~ json_key ~ '>' ~ (json_dict[json_key] | string) ~ '</' ~ json_key ~ '>' }}
9
+ {%- endif %}
10
+ {%- endfor %}
11
+ {%- endif %}
12
+ {% endmacro %}
13
+ {%- set enable_thinking = enable_thinking if enable_thinking is defined else True %}
14
+ {%- set truncate_history_thinking = truncate_history_thinking if truncate_history_thinking is defined else True %}
15
+
16
+ {%- set ns = namespace(last_user_idx = -1) %}
17
+ {%- set loop_messages = messages %}
18
+ {%- for m in loop_messages %}
19
+ {%- if m["role"] == "user" %}
20
+ {%- set ns.last_user_idx = loop.index0 %}
21
+ {%- endif %}
22
+ {%- endfor %}
23
+
24
+ {%- if messages[0]["role"] == "system" %}
25
+ {%- set system_message = messages[0]["content"] %}
26
+ {%- set loop_messages = messages[1:] %}
27
+ {%- else %}
28
+ {%- set system_message = "" %}
29
+ {%- set loop_messages = messages %}
30
+ {%- endif %}
31
+ {%- if not tools is defined %}
32
+ {%- set tools = [] %}
33
+ {%- endif %}
34
+ {# Recompute last_user_idx relative to loop_messages after handling system #}
35
+ {%- set ns = namespace(last_user_idx = -1) %}
36
+ {%- for m in loop_messages %}
37
+ {%- if m["role"] == "user" %}
38
+ {%- set ns.last_user_idx = loop.index0 %}
39
+ {%- endif %}
40
+ {%- endfor %}
41
+ {%- if system_message is defined %}
42
+ {{- "<|im_start|>system\n" + system_message }}
43
+ {%- else %}
44
+ {%- if tools is iterable and tools | length > 0 %}
45
+ {{- "<|im_start|>system\n" }}
46
+ {%- endif %}
47
+ {%- endif %}
48
+ {%- if tools is iterable and tools | length > 0 %}
49
+ {%- if system_message is defined and system_message | length > 0 %}
50
+ {{- "\n\n" }}
51
+ {%- endif %}
52
+ {{- "# Tools\n\nYou have access to the following functions:\n\n" }}
53
+ {{- "<tools>" }}
54
+ {%- for tool in tools %}
55
+ {%- if tool.function is defined %}
56
+ {%- set tool = tool.function %}
57
+ {%- endif %}
58
+ {{- "\n<function>\n<name>" ~ tool.name ~ "</name>" }}
59
+ {%- if tool.description is defined %}
60
+ {{- '\n<description>' ~ (tool.description | trim) ~ '</description>' }}
61
+ {%- endif %}
62
+ {{- '\n<parameters>' }}
63
+ {%- if tool.parameters is defined and tool.parameters is mapping and tool.parameters.properties is defined and tool.parameters.properties is mapping %}
64
+ {%- for param_name, param_fields in tool.parameters.properties|items %}
65
+ {{- '\n<parameter>' }}
66
+ {{- '\n<name>' ~ param_name ~ '</name>' }}
67
+ {%- if param_fields.type is defined %}
68
+ {{- '\n<type>' ~ (param_fields.type | string) ~ '</type>' }}
69
+ {%- endif %}
70
+ {%- if param_fields.description is defined %}
71
+ {{- '\n<description>' ~ (param_fields.description | trim) ~ '</description>' }}
72
+ {%- endif %}
73
+ {%- if param_fields.enum is defined %}
74
+ {{- '\n<enum>' ~ (param_fields.enum | tojson | safe) ~ '</enum>' }}
75
+ {%- endif %}
76
+ {%- set handled_keys = ['name', 'type', 'description', 'enum'] %}
77
+ {{- render_extra_keys(param_fields, handled_keys) }}
78
+ {{- '\n</parameter>' }}
79
+ {%- endfor %}
80
+ {%- endif %}
81
+ {% set handled_keys = ['type', 'properties', 'required'] %}
82
+ {{- render_extra_keys(tool.parameters, handled_keys) }}
83
+ {%- if tool.parameters is defined and tool.parameters.required is defined %}
84
+ {{- '\n<required>' ~ (tool.parameters.required | tojson | safe) ~ '</required>' }}
85
+ {%- endif %}
86
+ {{- '\n</parameters>' }}
87
+ {%- set handled_keys = ['type', 'name', 'description', 'parameters'] %}
88
+ {{- render_extra_keys(tool, handled_keys) }}
89
+ {{- '\n</function>' }}
90
+ {%- endfor %}
91
+ {{- "\n</tools>" }}
92
+
93
+ {{- '\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n<tool_call>\n<function=example_function_name>\n<parameter=example_parameter_1>\nvalue_1\n</parameter>\n<parameter=example_parameter_2>\nThis is the value for the second parameter\nthat can span\nmultiple lines\n</parameter>\n</function>\n</tool_call>\n\n<IMPORTANT>\nReminder:\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\n- Required parameters MUST be specified\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\n</IMPORTANT>' }}
94
+ {%- endif %}
95
+
96
+
97
+ {%- if system_message is defined %}
98
+ {{- '<|im_end|>\n' }}
99
+ {%- else %}
100
+ {%- if tools is iterable and tools | length > 0 %}
101
+ {{- '<|im_end|>\n' }}
102
+ {%- endif %}
103
+ {%- endif %}
104
+
105
+ {%- for message in loop_messages %}
106
+ {%- if message.role == "assistant" %}
107
+ {# Add reasoning content in to content field for unified processing below. #}
108
+ {%- if message.reasoning_content is defined and message.reasoning_content is string and message.reasoning_content | trim | length > 0 %}
109
+ {%- set content = "<think>\n" ~ message.reasoning_content ~ "\n</think>\n" ~ (message.content | default('', true)) %}
110
+ {%- else %}
111
+ {%- set content = message.content | default('', true) %}
112
+ {%- if content is string -%}
113
+ {# Allow downstream logic to to take care of broken thought, only handle coherent reasoning here. #}
114
+ {%- if '<think>' not in content and '</think>' not in content -%}
115
+ {%- set content = "<think></think>" ~ content -%}
116
+ {%- endif -%}
117
+ {%- else -%}
118
+ {%- set content = content -%}
119
+ {%- endif -%}
120
+ {%- endif %}
121
+ {%- if message.tool_calls is defined and message.tool_calls is iterable and message.tool_calls | length > 0 %}
122
+ {# Assistant message has tool calls. #}
123
+ {{- '<|im_start|>assistant\n' }}
124
+ {%- set include_content = not (truncate_history_thinking and loop.index0 < ns.last_user_idx) %}
125
+ {%- if content is string and content | trim | length > 0 %}
126
+ {%- if include_content %}
127
+ {{- (content | trim) ~ '\n' -}}
128
+ {%- else %}
129
+ {%- set c = (content | string) %}
130
+ {%- if '</think>' in c %}
131
+ {# Keep only content after the last closing think. Also generation prompt causes this. #}
132
+ {%- set c = (c.split('</think>')|last) %}
133
+ {%- elif '<think>' in c %}
134
+ {# If <think> was opened but never closed, drop the trailing think segment #}
135
+ {%- set c = (c.split('<think>')|first) %}
136
+ {%- endif %}
137
+ {%- set c = "<think></think>" ~ c | trim %}
138
+ {%- if c | length > 0 %}
139
+ {{- c ~ '\n' -}}
140
+ {%- endif %}
141
+ {%- endif %}
142
+ {%- else %}
143
+ {{- "<think></think>" -}}
144
+ {%- endif %}
145
+ {%- for tool_call in message.tool_calls %}
146
+ {%- if tool_call.function is defined %}
147
+ {%- set tool_call = tool_call.function %}
148
+ {%- endif %}
149
+ {{- '<tool_call>\n<function=' ~ tool_call.name ~ '>\n' -}}
150
+ {%- if tool_call.arguments is defined %}{%- if tool_call.arguments is mapping %}
151
+ {%- for args_name, args_value in tool_call.arguments|items %}
152
+ {{- '<parameter=' ~ args_name ~ '>\n' -}}
153
+ {%- set args_value = args_value | tojson | safe if args_value is mapping or (args_value is sequence and args_value is not string) else args_value | string %}
154
+ {{- args_value ~ '\n</parameter>\n' -}}
155
+ {%- endfor %}{%- endif %}
156
+ {%- endif %}
157
+ {{- '</function>\n</tool_call>\n' -}}
158
+ {%- endfor %}
159
+ {{- '<|im_end|>\n' }}
160
+ {%- else %}
161
+ {# Assistant message doesn't have tool calls. #}
162
+ {%- if not (truncate_history_thinking and loop.index0 < ns.last_user_idx) %}
163
+ {{- '<|im_start|>assistant\n' ~ (content | default('', true) | string | trim) ~ '<|im_end|>\n' }}
164
+ {%- else %}
165
+ {%- set c = (content | default('', true) | string) %}
166
+ {%- if '<think>' in c and '</think>' in c %}
167
+ {%- set c = "<think></think>" ~ (c.split('</think>')|last) %}
168
+ {%- endif %}
169
+ {%- set c = c | trim %}
170
+ {%- if c | length > 0 %}
171
+ {{- '<|im_start|>assistant\n' ~ c ~ '<|im_end|>\n' }}
172
+ {%- else %}
173
+ {{- '<|im_start|>assistant\n<|im_end|>\n' }}
174
+ {%- endif %}
175
+ {%- endif %}
176
+ {%- endif %}
177
+ {%- elif message.role == "user" or message.role == "system" %}
178
+ {{- '<|im_start|>' + message.role + '\n' }}
179
+ {%- set content = message.content | string %}
180
+ {{- content }}
181
+ {{- '<|im_end|>\n' }}
182
+ {%- elif message.role == "tool" %}
183
+ {%- if loop.previtem and loop.previtem.role != "tool" %}
184
+ {{- '<|im_start|>user\n' }}
185
+ {%- endif %}
186
+ {{- '<tool_response>\n' }}
187
+ {{- message.content }}
188
+ {{- '\n</tool_response>\n' }}
189
+ {%- if not loop.last and loop.nextitem.role != "tool" %}
190
+ {{- '<|im_end|>\n' }}
191
+ {%- elif loop.last %}
192
+ {{- '<|im_end|>\n' }}
193
+ {%- endif %}
194
+ {%- else %}
195
+ {{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>\n' }}
196
+ {%- endif %}
197
+ {%- endfor %}
198
+
199
+ {%- if add_generation_prompt %}
200
+ {%- if enable_thinking %}
201
+ {{- '<|im_start|>assistant\n<think>\n' }}
202
+ {%- else %}
203
+ {{- '<|im_start|>assistant\n<think></think>' }}
204
+ {%- endif %}
205
+ {%- endif %}
206
+ {# Copyright 2025-present Unsloth. Apache 2.0 License. #}
config.json ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "NemotronHForCausalLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "auto_map": {
8
+ "AutoConfig": "configuration_nemotron_h.NemotronHConfig",
9
+ "AutoModel": "modeling_nemotron_h.NemotronHForCausalLM",
10
+ "AutoModelForCausalLM": "modeling_nemotron_h.NemotronHForCausalLM"
11
+ },
12
+ "bos_token_id": 1,
13
+ "chunk_size": 128,
14
+ "conv_kernel": 4,
15
+ "torch_dtype": "bfloat16",
16
+ "eos_token_id": 11,
17
+ "expand": 2,
18
+ "head_dim": 128,
19
+ "hidden_dropout": 0.0,
20
+ "hidden_size": 2688,
21
+ "hybrid_override_pattern": "MEMEM*EMEMEM*EMEMEM*EMEMEM*EMEMEM*EMEMEMEM*EMEMEMEME",
22
+ "initializer_range": 0.02,
23
+ "intermediate_size": 1856,
24
+ "layer_norm_epsilon": 1e-05,
25
+ "mamba_head_dim": 64,
26
+ "mamba_hidden_act": "silu",
27
+ "mamba_num_heads": 64,
28
+ "mamba_proj_bias": false,
29
+ "mamba_ssm_cache_dtype": "float32",
30
+ "max_position_embeddings": 262144,
31
+ "mlp_bias": false,
32
+ "mlp_hidden_act": "relu2",
33
+ "model_type": "nemotron_h",
34
+ "moe_intermediate_size": 1856,
35
+ "moe_shared_expert_intermediate_size": 3712,
36
+ "n_group": 1,
37
+ "n_groups": 8,
38
+ "n_routed_experts": 128,
39
+ "n_shared_experts": 1,
40
+ "norm_eps": 1e-05,
41
+ "norm_topk_prob": true,
42
+ "num_attention_heads": 32,
43
+ "num_experts_per_tok": 6,
44
+ "num_hidden_layers": 52,
45
+ "num_key_value_heads": 2,
46
+ "num_logits_to_keep": 1,
47
+ "pad_token_id": 999,
48
+ "partial_rotary_factor": 1.0,
49
+ "rescale_prenorm_residual": true,
50
+ "residual_in_fp32": false,
51
+ "rope_theta": 10000,
52
+ "routed_scaling_factor": 2.5,
53
+ "sliding_window": null,
54
+ "ssm_state_size": 128,
55
+ "tie_word_embeddings": false,
56
+ "time_step_floor": 0.0001,
57
+ "time_step_limit": [
58
+ 0.0,
59
+ Infinity
60
+ ],
61
+ "time_step_max": 0.1,
62
+ "time_step_min": 0.001,
63
+ "topk_group": 1,
64
+ "transformers_version": "4.57.1",
65
+ "unsloth_fixed": true,
66
+ "unsloth_version": "2025.12.4",
67
+ "use_bias": false,
68
+ "use_cache": true,
69
+ "use_conv_bias": true,
70
+ "use_mamba_kernels": true,
71
+ "vocab_size": 131072
72
+ }
configuration_nemotron_h.py ADDED
@@ -0,0 +1,262 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ 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
+ 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=128,
176
+ rescale_prenorm_residual=True,
177
+ n_routed_experts=8,
178
+ n_shared_experts=1,
179
+ moe_intermediate_size=7688,
180
+ moe_shared_expert_intermediate_size=7688,
181
+ num_experts_per_tok=2,
182
+ routed_scaling_factor=1.0,
183
+ n_group=1,
184
+ topk_group=1,
185
+ norm_topk_prob=True,
186
+ **kwargs,
187
+ ):
188
+ self.vocab_size = vocab_size
189
+ self.tie_word_embeddings = tie_word_embeddings
190
+ self.hidden_size = hidden_size
191
+ self.intermediate_size = intermediate_size
192
+ self.num_hidden_layers = num_hidden_layers
193
+ self.hybrid_override_pattern = hybrid_override_pattern
194
+ self.num_attention_heads = num_attention_heads
195
+ self.head_dim = head_dim
196
+ self.sliding_window = sliding_window
197
+ self.max_position_embeddings = max_position_embeddings
198
+ self.attention_dropout = attention_dropout
199
+ self.hidden_dropout = hidden_dropout
200
+
201
+ # Validate hybrid_override_pattern
202
+ # M: Mamba2, *: Attention, -: MLP
203
+ assert len(self.hybrid_override_pattern) == self.num_hidden_layers, "hybrid_override_pattern must have the same length as num_hidden_layers"
204
+ assert re.match(r"^[*-M]+$", self.hybrid_override_pattern), "hybrid_override_pattern must only contain characters 'M', '*', or '-'"
205
+
206
+ # for backward compatibility
207
+ if num_key_value_heads is None:
208
+ num_key_value_heads = num_attention_heads
209
+
210
+ self.num_key_value_heads = num_key_value_heads
211
+ self.mlp_hidden_act = mlp_hidden_act
212
+ self.attention_bias = attention_bias
213
+ self.mlp_bias = mlp_bias
214
+ self.use_bias = use_bias
215
+ self.initializer_range = initializer_range
216
+ self.layer_norm_epsilon = layer_norm_epsilon
217
+ self.residual_in_fp32 = residual_in_fp32
218
+
219
+ self.use_cache = use_cache
220
+ self.num_logits_to_keep = num_logits_to_keep
221
+
222
+ self.use_mamba_kernels = use_mamba_kernels
223
+ self.n_groups = mamba_n_groups
224
+ self.mamba_head_dim = mamba_head_dim
225
+ self.ssm_state_size = ssm_state_size
226
+ self.mamba_num_heads = mamba_num_heads
227
+ self.conv_kernel = mamba_d_conv
228
+ self.expand = mamba_expand
229
+ self.mamba_hidden_act = mamba_hidden_act
230
+ self.time_step_min = mamba_dt_min
231
+ self.time_step_max = mamba_dt_max
232
+ self.time_step_limit = mamba_dt_limit
233
+ self.time_step_floor = mamba_dt_init_floor
234
+ self.use_conv_bias = mamba_conv_bias
235
+ self.mamba_proj_bias = mamba_proj_bias
236
+ self.chunk_size = mamba_chunk_size
237
+ self.rescale_prenorm_residual = rescale_prenorm_residual
238
+ self.n_routed_experts = n_routed_experts
239
+ self.n_shared_experts = n_shared_experts
240
+ self.moe_intermediate_size = moe_intermediate_size
241
+ self.moe_shared_expert_intermediate_size = moe_shared_expert_intermediate_size
242
+ self.num_experts_per_tok = num_experts_per_tok
243
+ self.routed_scaling_factor = routed_scaling_factor
244
+ self.n_group = n_group
245
+ self.topk_group = topk_group
246
+ self.norm_topk_prob = norm_topk_prob
247
+
248
+ super().__init__(
249
+ pad_token_id=pad_token_id,
250
+ bos_token_id=bos_token_id,
251
+ eos_token_id=eos_token_id,
252
+ tie_word_embeddings=tie_word_embeddings,
253
+ **kwargs,
254
+ )
255
+
256
+ @property
257
+ def layers_block_type(self):
258
+ return [
259
+ "mamba" if self.hybrid_override_pattern[i] == "M" else
260
+ "attention" if self.hybrid_override_pattern[i] == "*" else
261
+ "mlp" if self.hybrid_override_pattern[i] == "-" else "moe"
262
+ for i in range(self.num_hidden_layers)]
special_tokens_map.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": "<SPECIAL_999>",
17
+ "unk_token": {
18
+ "content": "<unk>",
19
+ "lstrip": false,
20
+ "normalized": false,
21
+ "rstrip": false,
22
+ "single_word": false
23
+ }
24
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:623c34567aebb18582765289fbe23d901c62704d6518d71866e0e58db892b5b7
3
+ size 17077484
tokenizer_config.json ADDED
The diff for this file is too large to render. See raw diff