qgallouedec HF Staff commited on
Commit
7c6d4c7
·
verified ·
1 Parent(s): 2810991

Upload NemotronHForCausalLM

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
README.md ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ tags:
4
+ - trl
5
+ ---
6
+
7
+ # Tiny NemotronHForCausalLM
8
+
9
+ This is a minimal model built for unit tests in the [TRL](https://github.com/huggingface/trl) library.
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
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "NemotronHForCausalLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 1,
8
+ "chunk_size": 128,
9
+ "conv_kernel": 4,
10
+ "dtype": "bfloat16",
11
+ "eos_token_id": 2,
12
+ "expand": 2,
13
+ "head_dim": 128,
14
+ "hidden_dropout": 0.0,
15
+ "hidden_size": 16,
16
+ "initializer_range": 0.02,
17
+ "intermediate_size": 32,
18
+ "layer_norm_epsilon": 1e-05,
19
+ "layers_block_type": [
20
+ "mamba",
21
+ "attention",
22
+ "moe"
23
+ ],
24
+ "mamba_head_dim": 4,
25
+ "mamba_hidden_act": "silu",
26
+ "mamba_num_heads": 8,
27
+ "mamba_proj_bias": false,
28
+ "mamba_ssm_cache_dtype": "float32",
29
+ "max_position_embeddings": 4096,
30
+ "mlp_bias": false,
31
+ "mlp_hidden_act": "relu2",
32
+ "model_type": "nemotron_h",
33
+ "moe_intermediate_size": 32,
34
+ "moe_latent_size": null,
35
+ "moe_shared_expert_intermediate_size": 32,
36
+ "moe_shared_expert_overlap": true,
37
+ "mtp_layers_block_type": [
38
+ "attention",
39
+ "moe"
40
+ ],
41
+ "n_group": 1,
42
+ "n_groups": 1,
43
+ "n_routed_experts": 4,
44
+ "n_shared_experts": 1,
45
+ "norm_topk_prob": true,
46
+ "num_attention_heads": 4,
47
+ "num_experts_per_tok": 2,
48
+ "num_key_value_heads": 2,
49
+ "num_logits_to_keep": 1,
50
+ "num_nextn_predict_layers": 0,
51
+ "pad_token_id": 0,
52
+ "rescale_prenorm_residual": true,
53
+ "residual_in_fp32": false,
54
+ "routed_scaling_factor": 1.0,
55
+ "sliding_window": null,
56
+ "ssm_state_size": 16,
57
+ "tie_word_embeddings": false,
58
+ "time_step_floor": 0.0001,
59
+ "time_step_limit": [
60
+ 0.0,
61
+ {
62
+ "__float__": "Infinity"
63
+ }
64
+ ],
65
+ "time_step_max": 0.1,
66
+ "time_step_min": 0.001,
67
+ "topk_group": 1,
68
+ "transformers_version": "5.3.0",
69
+ "use_bias": false,
70
+ "use_cache": true,
71
+ "use_conv_bias": true,
72
+ "use_mamba_kernels": false,
73
+ "vocab_size": 131072
74
+ }
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.3.0"
13
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:68dace295f27e8084127df1aae430249547f3e762bc5dbbfbeacb66689603d89
3
+ size 8456608
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
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "backend": "tokenizers",
4
+ "bos_token": "<s>",
5
+ "clean_up_tokenization_spaces": false,
6
+ "eos_token": "<|im_end|>",
7
+ "is_local": false,
8
+ "model_input_names": [
9
+ "input_ids",
10
+ "attention_mask"
11
+ ],
12
+ "model_max_length": 262144,
13
+ "pad_token": "<|im_end|>",
14
+ "tokenizer_class": "TokenizersBackend",
15
+ "unk_token": "<unk>"
16
+ }