chenhany-nv commited on
Commit
4a21ff6
·
verified ·
1 Parent(s): a91f10d

Upload folder using huggingface_hub

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +1 -0
  2. __init__.py +0 -0
  3. chat_template.jinja +195 -0
  4. config.json +0 -0
  5. configuration_nemotron_h.py +277 -0
  6. generation_config.json +13 -0
  7. hf_quant_config.json +0 -0
  8. model-00001-of-00052.safetensors +3 -0
  9. model-00002-of-00052.safetensors +3 -0
  10. model-00003-of-00052.safetensors +3 -0
  11. model-00004-of-00052.safetensors +3 -0
  12. model-00005-of-00052.safetensors +3 -0
  13. model-00006-of-00052.safetensors +3 -0
  14. model-00007-of-00052.safetensors +3 -0
  15. model-00008-of-00052.safetensors +3 -0
  16. model-00009-of-00052.safetensors +3 -0
  17. model-00010-of-00052.safetensors +3 -0
  18. model-00011-of-00052.safetensors +3 -0
  19. model-00012-of-00052.safetensors +3 -0
  20. model-00013-of-00052.safetensors +3 -0
  21. model-00014-of-00052.safetensors +3 -0
  22. model-00015-of-00052.safetensors +3 -0
  23. model-00016-of-00052.safetensors +3 -0
  24. model-00017-of-00052.safetensors +3 -0
  25. model-00018-of-00052.safetensors +3 -0
  26. model-00019-of-00052.safetensors +3 -0
  27. model-00020-of-00052.safetensors +3 -0
  28. model-00021-of-00052.safetensors +3 -0
  29. model-00022-of-00052.safetensors +3 -0
  30. model-00023-of-00052.safetensors +3 -0
  31. model-00024-of-00052.safetensors +3 -0
  32. model-00025-of-00052.safetensors +3 -0
  33. model-00026-of-00052.safetensors +3 -0
  34. model-00027-of-00052.safetensors +3 -0
  35. model-00028-of-00052.safetensors +3 -0
  36. model-00029-of-00052.safetensors +3 -0
  37. model-00030-of-00052.safetensors +3 -0
  38. model-00031-of-00052.safetensors +3 -0
  39. model-00032-of-00052.safetensors +3 -0
  40. model-00033-of-00052.safetensors +3 -0
  41. model-00034-of-00052.safetensors +3 -0
  42. model-00035-of-00052.safetensors +3 -0
  43. model-00036-of-00052.safetensors +3 -0
  44. model-00037-of-00052.safetensors +3 -0
  45. model-00038-of-00052.safetensors +3 -0
  46. model-00039-of-00052.safetensors +3 -0
  47. model-00040-of-00052.safetensors +3 -0
  48. model-00041-of-00052.safetensors +3 -0
  49. model-00042-of-00052.safetensors +3 -0
  50. model-00043-of-00052.safetensors +3 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
__init__.py ADDED
File without changes
chat_template.jinja ADDED
@@ -0,0 +1,195 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {% macro render_extra_keys(json_dict, handled_keys) %}
2
+ {%- if json_dict is mapping %}
3
+ {%- for json_key in json_dict if json_key not in handled_keys %}
4
+ {%- if json_dict[json_key] is mapping or (json_dict[json_key] is sequence and json_dict[json_key] is not string) %}
5
+ {{- '\n<' ~ json_key ~ '>' ~ (json_dict[json_key] | tojson | safe) ~ '</' ~ json_key ~ '>' }}
6
+ {%- else %}
7
+ {{-'\n<' ~ json_key ~ '>' ~ (json_dict[json_key] | string) ~ '</' ~ json_key ~ '>' }}
8
+ {%- endif %}
9
+ {%- endfor %}
10
+ {%- endif %}
11
+ {% endmacro %}
12
+ {%- set enable_thinking = enable_thinking if enable_thinking is defined else True %}
13
+ {%- set medium_effort = medium_effort if medium_effort is defined else False %}
14
+ {%- set truncate_history_thinking = truncate_history_thinking if truncate_history_thinking is defined else True %}
15
+ {%- set ns = namespace(last_user_idx = -1) %}
16
+ {%- set loop_messages = messages %}
17
+ {%- for m in loop_messages %}
18
+ {%- if m["role"] == "user" %}
19
+ {%- set ns.last_user_idx = loop.index0 %}
20
+ {%- endif %}
21
+ {%- endfor %}
22
+ {%- if messages[0]["role"] == "system" %}
23
+ {%- set system_message = messages[0]["content"] %}
24
+ {%- set loop_messages = messages[1:] %}
25
+ {%- else %}
26
+ {%- set system_message = "" %}
27
+ {%- set loop_messages = messages %}
28
+ {%- endif %}
29
+ {%- if not tools is defined %}
30
+ {%- set tools = [] %}
31
+ {%- endif %}
32
+ {%- set ns = namespace(last_user_idx = -1) %}
33
+ {%- for m in loop_messages %}
34
+ {%- if m["role"] == "user" %}
35
+ {%- set ns.last_user_idx = loop.index0 %}
36
+ {%- endif %}
37
+ {%- endfor %}
38
+ {%- if system_message is defined %}
39
+ {{- "<|im_start|>system\n" + system_message }}
40
+ {%- else %}
41
+ {%- if tools is iterable and tools | length > 0 %}
42
+ {{- "<|im_start|>system\n" }}
43
+ {%- endif %}
44
+ {%- endif %}
45
+ {%- if tools is iterable and tools | length > 0 %}
46
+ {%- if system_message is defined and system_message | length > 0 %}
47
+ {{- "\n\n" }}
48
+ {%- endif %}
49
+ {{- "# Tools\n\nYou have access to the following functions:\n\n" }}
50
+ {{- "<tools>" }}
51
+ {%- for tool in tools %}
52
+ {%- if tool.function is defined %}
53
+ {%- set tool = tool.function %}
54
+ {%- endif %}
55
+ {{- "\n<function>\n<name>" ~ tool.name ~ "</name>" }}
56
+ {%- if tool.description is defined %}
57
+ {{- '\n<description>' ~ (tool.description | trim) ~ '</description>' }}
58
+ {%- endif %}
59
+ {{- '\n<parameters>' }}
60
+ {%- if tool.parameters is defined and tool.parameters is mapping and tool.parameters.properties is defined and tool.parameters.properties is mapping %}
61
+ {%- for param_name, param_fields in tool.parameters.properties|items %}
62
+ {{- '\n<parameter>' }}
63
+ {{- '\n<name>' ~ param_name ~ '</name>' }}
64
+ {%- if param_fields.type is defined %}
65
+ {{- '\n<type>' ~ (param_fields.type | string) ~ '</type>' }}
66
+ {%- endif %}
67
+ {%- if param_fields.description is defined %}
68
+ {{- '\n<description>' ~ (param_fields.description | trim) ~ '</description>' }}
69
+ {%- endif %}
70
+ {%- if param_fields.enum is defined %}
71
+ {{- '\n<enum>' ~ (param_fields.enum | tojson | safe) ~ '</enum>' }}
72
+ {%- endif %}
73
+ {%- set handled_keys = ['name', 'type', 'description', 'enum'] %}
74
+ {{- render_extra_keys(param_fields, handled_keys) }}
75
+ {{- '\n</parameter>' }}
76
+ {%- endfor %}
77
+ {%- endif %}
78
+ {% set handled_keys = ['type', 'properties', 'required'] %}
79
+ {{- render_extra_keys(tool.parameters, handled_keys) }}
80
+ {%- if tool.parameters is defined and tool.parameters.required is defined %}
81
+ {{- '\n<required>' ~ (tool.parameters.required | tojson | safe) ~ '</required>' }}
82
+ {%- endif %}
83
+ {{- '\n</parameters>' }}
84
+ {%- set handled_keys = ['type', 'name', 'description', 'parameters'] %}
85
+ {{- render_extra_keys(tool, handled_keys) }}
86
+ {{- '\n</function>' }}
87
+ {%- endfor %}
88
+ {{- "\n</tools>" }}
89
+ {{- '\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>' }}
90
+ {%- endif %}
91
+ {%- if system_message is defined %}
92
+ {{- '<|im_end|>\n' }}
93
+ {%- else %}
94
+ {%- if tools is iterable and tools | length > 0 %}
95
+ {{- '<|im_end|>\n' }}
96
+ {%- endif %}
97
+ {%- endif %}
98
+ {%- for message in loop_messages %}
99
+ {%- if message.role == "assistant" %}
100
+ {%- if message.reasoning_content is defined and message.reasoning_content is string and message.reasoning_content | trim | length > 0 %}
101
+ {%- set content = "<think>\n" ~ message.reasoning_content ~ "</think>" ~ (message.content | default('', true)) %}
102
+ {%- else %}
103
+ {%- set content = message.content | default('', true) %}
104
+ {%- if content is string -%}
105
+ {%- if '<think>' not in content and '</think>' not in content -%}
106
+ {%- set content = "<think></think>" ~ content -%}
107
+ {%- endif -%}
108
+ {%- else -%}
109
+ {%- set content = content -%}
110
+ {%- endif -%}
111
+ {%- endif %}
112
+ {%- if message.tool_calls is defined and message.tool_calls is iterable and message.tool_calls | length > 0 %}
113
+ {{- '<|im_start|>assistant\n' }}
114
+ {%- set include_content = not (truncate_history_thinking and loop.index0 < ns.last_user_idx) %}
115
+ {%- if content is string and content | trim | length > 0 %}
116
+ {%- if include_content %}
117
+ {{- (content | trim) ~ '\n' -}}
118
+ {%- else %}
119
+ {%- set c = (content | string) %}
120
+ {%- if '</think>' in c %}
121
+ {%- set c = c.split('</think>')[-1] %}
122
+ {%- elif '<think>' in c %}
123
+ {%- set c = c.split('<think>')[0] %}
124
+ {%- endif %}
125
+ {%- set c = "<think></think>" ~ c %}
126
+ {%- if c | length > 0 %}
127
+ {{- c ~ '\n' -}}
128
+ {%- endif %}
129
+ {%- endif %}
130
+ {%- else %}
131
+ {{- "<think></think>" -}}
132
+ {%- endif %}
133
+ {%- for tool_call in message.tool_calls %}
134
+ {%- if tool_call.function is defined %}
135
+ {%- set tool_call = tool_call.function %}
136
+ {%- endif %}
137
+ {{- '<tool_call>\n<function=' ~ tool_call.name ~ '>\n' -}}
138
+ {%- if tool_call.arguments is defined %}
139
+ {%- for args_name, args_value in tool_call.arguments|items %}
140
+ {{- '<parameter=' ~ args_name ~ '>\n' -}}
141
+ {%- 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 %}
142
+ {{- args_value ~ '\n</parameter>\n' -}}
143
+ {%- endfor %}
144
+ {%- endif %}
145
+ {{- '</function>\n</tool_call>\n' -}}
146
+ {%- endfor %}
147
+ {{- '<|im_end|>\n' }}
148
+ {%- else %}
149
+ {%- if not (truncate_history_thinking and loop.index0 < ns.last_user_idx) %}
150
+ {{- '<|im_start|>assistant\n' ~ (content | default('', true) | string | trim) ~ '<|im_end|>\n' }}
151
+ {%- else %}
152
+ {%- set c = (content | default('', true) | string) %}
153
+ {%- if '<think>' in c and '</think>' in c %}
154
+ {%- set c = "<think></think>" ~ c.split('</think>')[-1] %}
155
+ {%- endif %}
156
+ {%- set c = c | trim %}
157
+ {%- if c | length > 0 %}
158
+ {{- '<|im_start|>assistant\n' ~ c ~ '<|im_end|>\n' }}
159
+ {%- else %}
160
+ {{- '<|im_start|>assistant\n<|im_end|>\n' }}
161
+ {%- endif %}
162
+ {%- endif %}
163
+ {%- endif %}
164
+ {%- elif message.role == "user" or message.role == "system" %}
165
+ {{- '<|im_start|>' + message.role + '\n' }}
166
+ {%- set content = message.content | string %}
167
+ {%- if message.role == "user" and loop.index0 == ns.last_user_idx and medium_effort %}
168
+ {{- content + '\n\n{reasoning effort: efficient}' }}
169
+ {%- else %}
170
+ {{- content }}
171
+ {%- endif %}
172
+ {{- '<|im_end|>\n' }}
173
+ {%- elif message.role == "tool" %}
174
+ {%- if loop.previtem and loop.previtem.role != "tool" %}
175
+ {{- '<|im_start|>user\n' }}
176
+ {%- endif %}
177
+ {{- '<tool_response>\n' }}
178
+ {{- message.content }}
179
+ {{- '\n</tool_response>\n' }}
180
+ {%- if not loop.last and loop.nextitem.role != "tool" %}
181
+ {{- '<|im_end|>\n' }}
182
+ {%- elif loop.last %}
183
+ {{- '<|im_end|>\n' }}
184
+ {%- endif %}
185
+ {%- else %}
186
+ {{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>\n' }}
187
+ {%- endif %}
188
+ {%- endfor %}
189
+ {%- if add_generation_prompt %}
190
+ {%- if enable_thinking %}
191
+ {{- '<|im_start|>assistant\n<think>\n' }}
192
+ {%- else %}
193
+ {{- '<|im_start|>assistant\n<think></think>' }}
194
+ {%- endif %}
195
+ {%- endif %}
config.json ADDED
The diff for this file is too large to render. See raw diff
 
configuration_nemotron_h.py ADDED
@@ -0,0 +1,277 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ moe_latent_size=None,
182
+ moe_shared_expert_overlap=True,
183
+ num_experts_per_tok=2,
184
+ routed_scaling_factor=1.0,
185
+ n_group=1,
186
+ topk_group=1,
187
+ norm_topk_prob=True,
188
+ mamba_ssm_cache_dtype="float32",
189
+ num_nextn_predict_layers=0,
190
+ mtp_hybrid_override_pattern="*E",
191
+ **kwargs,
192
+ ):
193
+ self.vocab_size = vocab_size
194
+ self.tie_word_embeddings = tie_word_embeddings
195
+ self.hidden_size = hidden_size
196
+ self.intermediate_size = intermediate_size
197
+ self.num_hidden_layers = num_hidden_layers
198
+ self.hybrid_override_pattern = hybrid_override_pattern
199
+ self.num_attention_heads = num_attention_heads
200
+ self.head_dim = head_dim
201
+ self.sliding_window = sliding_window
202
+ self.max_position_embeddings = max_position_embeddings
203
+ self.attention_dropout = attention_dropout
204
+ self.hidden_dropout = hidden_dropout
205
+
206
+ # Validate hybrid_override_pattern
207
+ # M: Mamba2, *: Attention, -: MLP
208
+ assert len(self.hybrid_override_pattern) == self.num_hidden_layers, "hybrid_override_pattern must have the same length as num_hidden_layers"
209
+ assert re.match(r"^[ME*-]+$", self.hybrid_override_pattern), "hybrid_override_pattern must only contain characters 'M', '*', 'E',or '-'"
210
+
211
+ # for backward compatibility
212
+ if num_key_value_heads is None:
213
+ num_key_value_heads = num_attention_heads
214
+
215
+ self.num_key_value_heads = num_key_value_heads
216
+ self.mlp_hidden_act = mlp_hidden_act
217
+ self.attention_bias = attention_bias
218
+ self.mlp_bias = mlp_bias
219
+ self.use_bias = use_bias
220
+ self.initializer_range = initializer_range
221
+ self.layer_norm_epsilon = layer_norm_epsilon
222
+ self.residual_in_fp32 = residual_in_fp32
223
+
224
+ self.use_cache = use_cache
225
+ self.num_logits_to_keep = num_logits_to_keep
226
+
227
+ self.use_mamba_kernels = use_mamba_kernels
228
+ self.n_groups = mamba_n_groups
229
+ self.mamba_head_dim = mamba_head_dim
230
+ self.ssm_state_size = ssm_state_size
231
+ self.mamba_num_heads = mamba_num_heads
232
+ self.conv_kernel = mamba_d_conv
233
+ self.expand = mamba_expand
234
+ self.mamba_hidden_act = mamba_hidden_act
235
+ self.time_step_min = mamba_dt_min
236
+ self.time_step_max = mamba_dt_max
237
+ self.time_step_limit = mamba_dt_limit
238
+ self.time_step_floor = mamba_dt_init_floor
239
+ self.use_conv_bias = mamba_conv_bias
240
+ self.mamba_proj_bias = mamba_proj_bias
241
+ self.chunk_size = mamba_chunk_size
242
+ self.rescale_prenorm_residual = rescale_prenorm_residual
243
+ self.n_routed_experts = n_routed_experts
244
+ self.n_shared_experts = n_shared_experts
245
+ self.moe_intermediate_size = moe_intermediate_size
246
+ self.moe_shared_expert_intermediate_size = moe_shared_expert_intermediate_size
247
+ self.moe_latent_size = moe_latent_size
248
+ self.moe_shared_expert_overlap = moe_shared_expert_overlap
249
+ self.num_experts_per_tok = num_experts_per_tok
250
+ self.routed_scaling_factor = routed_scaling_factor
251
+ self.n_group = n_group
252
+ self.topk_group = topk_group
253
+ self.norm_topk_prob = norm_topk_prob
254
+ self.mamba_ssm_cache_dtype = mamba_ssm_cache_dtype
255
+
256
+ # MTP config
257
+ # TODO(liding):--keep-mtp-spec-in-bf16
258
+ self.num_nextn_predict_layers = num_nextn_predict_layers
259
+ self.mtp_hybrid_override_pattern = mtp_hybrid_override_pattern
260
+ if self.num_nextn_predict_layers > 0:
261
+ assert re.match(r"^[ME*-]+$", self.mtp_hybrid_override_pattern), "mtp_hybrid_override_pattern must only contain characters 'M', '*', 'E',or '-'"
262
+
263
+ super().__init__(
264
+ pad_token_id=pad_token_id,
265
+ bos_token_id=bos_token_id,
266
+ eos_token_id=eos_token_id,
267
+ tie_word_embeddings=tie_word_embeddings,
268
+ **kwargs,
269
+ )
270
+
271
+ @property
272
+ def layers_block_type(self):
273
+ return [
274
+ "mamba" if self.hybrid_override_pattern[i] == "M" else
275
+ "attention" if self.hybrid_override_pattern[i] == "*" else
276
+ "mlp" if self.hybrid_override_pattern[i] == "-" else "moe"
277
+ for i in range(self.num_hidden_layers)]
generation_config.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 1,
4
+ "do_sample": true,
5
+ "eos_token_id": [
6
+ 2,
7
+ 11
8
+ ],
9
+ "pad_token_id": 0,
10
+ "temperature": 1.0,
11
+ "top_p": 0.95,
12
+ "transformers_version": "5.8.1"
13
+ }
hf_quant_config.json ADDED
The diff for this file is too large to render. See raw diff
 
model-00001-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:672c8bda10fdec0256e0819e112d2aa3a936cc3e5d311a05fd3ff773ca9a44b9
3
+ size 743427168
model-00002-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b365ac815ea78b159c4c6b27be77f2ab24be3ce67f7f4017eb3ada2e81a27f4f
3
+ size 731109880
model-00003-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8fbad8247cd4d256a6d376259b83b06972e8d0d00eae1718c7852856343f204b
3
+ size 38783920
model-00004-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:243a94b1f2b3a3790ff53c151effe116a141539045804df20c005a8c5d0de96f
3
+ size 731109880
model-00005-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e675767a474777e76e7a3b61d30fa70812db34415f76385c17aaf25aab82d398
3
+ size 38783920
model-00006-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8f8e9623934bc82a4a2af18af83888ce79bbdee4f506cda08375d4ab3435cbd1
3
+ size 46798848
model-00007-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:306aee6514a7daf559a771ce0c29fafc6de70036c30cf6208c3844283694eff3
3
+ size 731109880
model-00008-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:31235989ff64cae4d75b73a713d1acbc5205bd050bb1aeb5e573b553d07a0b45
3
+ size 38783920
model-00009-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bcd6b2645a6b23588e721432745a1a159870087037a1f937db20f2a85e14dc7f
3
+ size 731109880
model-00010-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5fae7d86c34396c2da17f6ebd3b912c29c81370f61266d42bc88c91875a4d783
3
+ size 38783920
model-00011-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:10237b58cd289cc6dd7609e48a7606bd5a120050dc3f189621d99d23c52566ab
3
+ size 731110656
model-00012-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dfa4a2312fc9943eee6ba8558b8f4d748ed20e5032d3a04a821f29844cb4f2e4
3
+ size 38783936
model-00013-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:41feb27e33765c985a28f8aca69440a9aaa39db0bdf632c065cc49ee0f5a8fa7
3
+ size 46798856
model-00014-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:16653126b2716c7b8d402024e5fb3ce6eb052422d45d83a5f3e486f066fd30cc
3
+ size 731110656
model-00015-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1016d76b1b0dad48f5b38e97c2def67aac446a582aed849f14533d988047fe34
3
+ size 38783936
model-00016-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:70aaec01374fea7dddc0e006f4ae91e1a4cd09b9f77a36b8ba48e5189288419f
3
+ size 731110656
model-00017-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:67763384429d40a0142b4b1d02c6a171a493a4d0c57086d38e2436ac05d33a86
3
+ size 38783936
model-00018-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:252e3fb2e6c37d1b41f49463607d928e39c96fe0eb499768cc2fe42d9bfffe8e
3
+ size 731110656
model-00019-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3fd080a21df9cda2793957c3b7a3699b7356753cb6a6e519e3299303c4e004ab
3
+ size 38783936
model-00020-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:31dada97bfd50ecd0fee51aea0272fb75d6a6dc6303022cb6defb7e55dfbaf8d
3
+ size 46798856
model-00021-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:601a05eb0b228da1cbc5883f955cbb5a38f1379401501926a7576aebdfd757da
3
+ size 731110656
model-00022-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4b3eb401a3152e9a392840e56ceaf29d5fba4b952cc7a38ef5ec72849ffd45ab
3
+ size 38783936
model-00023-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1f92f9b4bc06f33f18db2cee651ffa868374b54dc3d3ad8ea88d8f222507d8d7
3
+ size 731110656
model-00024-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:64d36b45162fd22d57934962e00fa6b6c19a8ef9f36dc1fce1940d876ce28283
3
+ size 38783936
model-00025-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1d8f5436a1e7c34e8644e4db0331d58ba75c8c9997f1dfed0b1797ce5d87e9fd
3
+ size 731110656
model-00026-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:97e410e491888aa263a4a1ec42b8dd5c25b4869a209ff1da6ec2c20592db5a97
3
+ size 38783936
model-00027-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e67fb58638bf00b010323ad702be58addf95ac2c89ba4006b7d00cbf8bab2b7f
3
+ size 46798856
model-00028-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1800ab07214a1746f26a01e575e0c979d129a9bce1f3ce030e11b38d40bda72b
3
+ size 731110656
model-00029-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:045dc61dc334cad87fdd227515739ba22ea04f9e6e0f9624b40a6ff1e146553a
3
+ size 38783936
model-00030-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:794679784bde068d4d812b824595efcd87ea4fa64168af18e1295d60ad6cfa89
3
+ size 731110656
model-00031-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:727bb1bf4829360596a2845ee2730536408c4f52b322fffd8afc6bd972de5e3f
3
+ size 38783936
model-00032-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cc68cfd7f1e805422e6ab224638b115754adc3a84bdedebc71a4ee7b52159e0a
3
+ size 731110656
model-00033-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ee8d3fc76401172bdcb6fe4ad3b08ed8a9f0bc6e28a86bc6757a0998b27569a0
3
+ size 38783936
model-00034-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:90c579b134e5b929903e7c8e897970109bb11574bcf50fceb72c65884388bae1
3
+ size 46798856
model-00035-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d6b9441c3fb72f5d13dfb8dfc410c0c176d94217d2a7626d3fd96c4db31ac134
3
+ size 731110656
model-00036-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:130ee06f0ba0c8e760b7c57ae671458446ad8fd71548198d0005e8e553ba10a9
3
+ size 38783936
model-00037-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7464b7b51237bd66e5469fc4cb67f10d7b490af34d16670d57b102a3cfec6754
3
+ size 731110656
model-00038-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1a0ab61ef65a02dbf8455da1feb5eb059ff064bf04ce9d9db5216d0c849383f5
3
+ size 38783936
model-00039-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9f31f2fa95027f718a91c731b4537172576c05db6f8ac05ff3d17de7b4c27219
3
+ size 731110656
model-00040-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:407f0e74455eb7050e6125f346c8434d4341ff07730cc670bc482b47f59521dc
3
+ size 38783936
model-00041-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4e8442377f265c009f6f82cf07447cc735385db6a673507ec61e1228c6e1b324
3
+ size 731110656
model-00042-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:85ca012bff38fbbcb1171ea1d134d60db2bdeaf12e53f1b4e8cf6e36eaf319a3
3
+ size 38783936
model-00043-of-00052.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:01c56b23b7ea692675bc6f5f77b2a4959a51091435befd41428527f7128ea18f
3
+ size 46798856