Text Generation
Transformers
Safetensors
PyTorch
nemotron_labs_diffusion
feature-extraction
nvidia
conversational
custom_code
Instructions to use nvidia/Nemotron-Labs-Diffusion-8B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use nvidia/Nemotron-Labs-Diffusion-8B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="nvidia/Nemotron-Labs-Diffusion-8B", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("nvidia/Nemotron-Labs-Diffusion-8B", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use nvidia/Nemotron-Labs-Diffusion-8B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "nvidia/Nemotron-Labs-Diffusion-8B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nvidia/Nemotron-Labs-Diffusion-8B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/nvidia/Nemotron-Labs-Diffusion-8B
- SGLang
How to use nvidia/Nemotron-Labs-Diffusion-8B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "nvidia/Nemotron-Labs-Diffusion-8B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nvidia/Nemotron-Labs-Diffusion-8B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "nvidia/Nemotron-Labs-Diffusion-8B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nvidia/Nemotron-Labs-Diffusion-8B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use nvidia/Nemotron-Labs-Diffusion-8B with Docker Model Runner:
docker model run hf.co/nvidia/Nemotron-Labs-Diffusion-8B
Add a response template and generation tags
#4
by Rocketknight1 HF Staff - opened
- chat_template.jinja +27 -5
- tokenizer_config.json +39 -1
chat_template.jinja
CHANGED
|
@@ -111,9 +111,10 @@
|
|
| 111 |
{%- set content = content -%}
|
| 112 |
{%- endif -%}
|
| 113 |
{%- endif %}
|
|
|
|
|
|
|
| 114 |
{%- if message.tool_calls is defined and message.tool_calls is iterable and message.tool_calls | length > 0 %}
|
| 115 |
{# Assistant message has tool calls. #}
|
| 116 |
-
{{- '<|im_start|>assistant\n' }}
|
| 117 |
{%- set include_content = not (truncate_history_thinking and loop.index0 < ns.last_user_idx) %}
|
| 118 |
{%- if content is string and content | trim | length > 0 %}
|
| 119 |
{%- if include_content %}
|
|
@@ -149,11 +150,11 @@
|
|
| 149 |
{%- endif %}
|
| 150 |
{{- '</function>\n</tool_call>\n' -}}
|
| 151 |
{%- endfor %}
|
| 152 |
-
{{- '<|im_end|>
|
| 153 |
{%- else %}
|
| 154 |
{# Assistant message doesn't have tool calls. #}
|
| 155 |
{%- if not (truncate_history_thinking and loop.index0 < ns.last_user_idx) %}
|
| 156 |
-
{{-
|
| 157 |
{%- else %}
|
| 158 |
{%- set c = (content | default('', true) | string) %}
|
| 159 |
{%- if '<think>' in c and '</think>' in c %}
|
|
@@ -161,12 +162,33 @@
|
|
| 161 |
{%- endif %}
|
| 162 |
{%- set c = c | trim %}
|
| 163 |
{%- if c | length > 0 %}
|
| 164 |
-
{{-
|
| 165 |
{%- else %}
|
| 166 |
-
{{- '<|
|
| 167 |
{%- endif %}
|
| 168 |
{%- endif %}
|
| 169 |
{%- endif %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
{%- elif message.role == "user" or message.role == "system" %}
|
| 171 |
{{- '<|im_start|>' + message.role + '\n' }}
|
| 172 |
{%- set content = message.content | string %}
|
|
|
|
| 111 |
{%- set content = content -%}
|
| 112 |
{%- endif -%}
|
| 113 |
{%- endif %}
|
| 114 |
+
{{- '<|im_start|>assistant\n' }}
|
| 115 |
+
{%- set turn %}
|
| 116 |
{%- if message.tool_calls is defined and message.tool_calls is iterable and message.tool_calls | length > 0 %}
|
| 117 |
{# Assistant message has tool calls. #}
|
|
|
|
| 118 |
{%- set include_content = not (truncate_history_thinking and loop.index0 < ns.last_user_idx) %}
|
| 119 |
{%- if content is string and content | trim | length > 0 %}
|
| 120 |
{%- if include_content %}
|
|
|
|
| 150 |
{%- endif %}
|
| 151 |
{{- '</function>\n</tool_call>\n' -}}
|
| 152 |
{%- endfor %}
|
| 153 |
+
{{- '<|im_end|>' }}
|
| 154 |
{%- else %}
|
| 155 |
{# Assistant message doesn't have tool calls. #}
|
| 156 |
{%- if not (truncate_history_thinking and loop.index0 < ns.last_user_idx) %}
|
| 157 |
+
{{- (content | default('', true) | string | trim) ~ '<|im_end|>' }}
|
| 158 |
{%- else %}
|
| 159 |
{%- set c = (content | default('', true) | string) %}
|
| 160 |
{%- if '<think>' in c and '</think>' in c %}
|
|
|
|
| 162 |
{%- endif %}
|
| 163 |
{%- set c = c | trim %}
|
| 164 |
{%- if c | length > 0 %}
|
| 165 |
+
{{- c ~ '<|im_end|>' }}
|
| 166 |
{%- else %}
|
| 167 |
+
{{- '<|im_end|>' }}
|
| 168 |
{%- endif %}
|
| 169 |
{%- endif %}
|
| 170 |
{%- endif %}
|
| 171 |
+
{%- endset %}
|
| 172 |
+
{#- What the generation prompt pre-fills stays out of the generation block: the model never generates it #}
|
| 173 |
+
{%- set prefill = '<think>\n' if enable_thinking else '<think></think>' %}
|
| 174 |
+
{%- if turn.startswith(prefill) %}
|
| 175 |
+
{%- set lead = prefill %}
|
| 176 |
+
{%- elif not turn.startswith('<think>') %}
|
| 177 |
+
{%- set lead = '' %}
|
| 178 |
+
{%- elif enable_thinking or '</think>' not in turn %}
|
| 179 |
+
{%- set lead = '<think>' %}
|
| 180 |
+
{%- else %}
|
| 181 |
+
{#- Reasoning with thinking off: the prompt pre-fills an empty block, so the whole block stays out #}
|
| 182 |
+
{%- set lead = turn.split('</think>')[0] ~ '</think>' %}
|
| 183 |
+
{%- if turn[lead | length:].startswith('\n') %}
|
| 184 |
+
{%- set lead = lead ~ '\n' %}
|
| 185 |
+
{%- endif %}
|
| 186 |
+
{%- endif %}
|
| 187 |
+
{{- lead }}
|
| 188 |
+
{%- generation %}
|
| 189 |
+
{{- turn[lead | length:] }}
|
| 190 |
+
{%- endgeneration %}
|
| 191 |
+
{{- '\n' }}
|
| 192 |
{%- elif message.role == "user" or message.role == "system" %}
|
| 193 |
{{- '<|im_start|>' + message.role + '\n' }}
|
| 194 |
{%- set content = message.content | string %}
|
tokenizer_config.json
CHANGED
|
@@ -8014,5 +8014,43 @@
|
|
| 8014 |
],
|
| 8015 |
"model_max_length": 262144,
|
| 8016 |
"tokenizer_class": "PreTrainedTokenizerFast",
|
| 8017 |
-
"unk_token": "<unk>"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8018 |
}
|
|
|
|
| 8014 |
],
|
| 8015 |
"model_max_length": 262144,
|
| 8016 |
"tokenizer_class": "PreTrainedTokenizerFast",
|
| 8017 |
+
"unk_token": "<unk>",
|
| 8018 |
+
"response_template": {
|
| 8019 |
+
"defaults": {
|
| 8020 |
+
"role": "assistant"
|
| 8021 |
+
},
|
| 8022 |
+
"start_anchor": "<|im_start|>assistant\n",
|
| 8023 |
+
"fields": {
|
| 8024 |
+
"reasoning_content": {
|
| 8025 |
+
"open": "<think>",
|
| 8026 |
+
"close": "</think>",
|
| 8027 |
+
"content": "text"
|
| 8028 |
+
},
|
| 8029 |
+
"tool_calls": {
|
| 8030 |
+
"open_pattern": "<tool_call>\\s*<function=(?P<name>[^>\\n]+)>",
|
| 8031 |
+
"close_pattern": "</tool_call>|(?=<tool_call>)",
|
| 8032 |
+
"repeats": true,
|
| 8033 |
+
"content": "xml-inline",
|
| 8034 |
+
"content_args": {
|
| 8035 |
+
"tag_pattern": "<parameter=(?P<key>[^>\\n]+)>\\n?(?P<value>.*?)\\n?(?:</parameter>|(?=<parameter=)|(?=</function>))"
|
| 8036 |
+
},
|
| 8037 |
+
"transform": {
|
| 8038 |
+
"type": "function",
|
| 8039 |
+
"function": {
|
| 8040 |
+
"name": "{name}",
|
| 8041 |
+
"arguments": "{content}"
|
| 8042 |
+
}
|
| 8043 |
+
}
|
| 8044 |
+
},
|
| 8045 |
+
"content": {
|
| 8046 |
+
"close": [
|
| 8047 |
+
"<|im_end|>",
|
| 8048 |
+
"<|endoftext|>"
|
| 8049 |
+
],
|
| 8050 |
+
"content": "text",
|
| 8051 |
+
"repeats": true,
|
| 8052 |
+
"join": ""
|
| 8053 |
+
}
|
| 8054 |
+
}
|
| 8055 |
+
}
|
| 8056 |
}
|