模型简介
模型特点
模型能力
使用案例
库名称:transformers
许可证:其他
许可证名称:NVIDIA开放模型许可证
许可证链接:https://www.nvidia.com/en-us/agreements/enterprise-software/nvidia-open-model-license/
任务标签:文本生成
支持语言:
- 英语
标签: - NVIDIA
- Llama-3
- PyTorch
基础模型: - nvidia/Llama-3.1-Minitron-4B-Width-Base
数据集: - nvidia/Llama-Nemotron-Post-Training-Dataset
Llama-3.1-Nemotron-Nano-4B-v1.1
模型概述
Llama-3.1-Nemotron-Nano-4B-v1.1 是一个大型语言模型(LLM),基于 nvidia/Llama-3.1-Minitron-4B-Width-Base 开发,该模型通过 我们的LLM压缩技术 从 Llama 3.1 8B 压缩而来,并在模型精度和效率上有所提升。它是一个推理模型,经过后训练以增强推理能力、人类对话偏好以及任务执行能力,例如RAG(检索增强生成)和工具调用。
Llama-3.1-Nemotron-Nano-4B-v1.1 在模型精度和效率之间提供了出色的平衡。该模型可适配单张RTX显卡,支持本地部署,并支持128K的上下文长度。
该模型通过多阶段后训练流程提升其推理和非推理能力,包括针对数学、代码、推理和工具调用的监督微调(SFT)阶段,以及使用奖励感知偏好优化(RPO)算法对对话和指令跟随进行的多轮强化学习(RL)阶段。最终模型检查点是通过合并最终的SFT和RPO检查点获得的。
该模型属于Llama Nemotron系列的一部分。您可以在以下链接中找到该系列的其他模型:
该模型已准备好用于商业用途。
许可证/使用条款
管辖条款:您对该模型的使用受 NVIDIA开放模型许可证 约束。附加信息:Llama 3.1社区许可证协议。基于Llama构建。
模型开发者:NVIDIA
模型训练时间:2024年8月至2025年5月
数据新鲜度:预训练数据截止于2023年6月。
使用场景
适用于设计AI代理系统、聊天机器人、RAG系统和其他AI驱动应用的开发者。同时也适用于典型的指令跟随任务。该模型在精度和计算效率之间取得了平衡(可适配单张RTX显卡并支持本地部署)。
发布日期
2025年5月20日
参考文献
- [2408.11796] LLM剪枝与蒸馏实践:Minitron方法
- [2502.00203] 奖励感知偏好优化:模型对齐的统一数学框架
- [2505.00949] Llama-Nemotron:高效推理模型
模型架构
架构类型:密集解码器专用Transformer模型
网络架构:Llama 3.1 Minitron Width 4B基础版
预期用途
Llama-3.1-Nemotron-Nano-4B-v1.1 是一个通用推理和对话模型,主要用于英语和编程语言。同时也支持其他非英语语言(德语、法语、意大利语、葡萄牙语、印地语、西班牙语和泰语)。
输入:
- 输入类型:文本
- 输入格式:字符串
- 输入参数:一维(1D)
- 其他输入相关属性:上下文长度最高支持131,072个标记
输出:
- 输出类型:文本
- 输出格式:字符串
- 输出参数:一维(1D)
- 其他输出相关属性:上下文长度最高支持131,072个标记
模型版本:
1.1(2025年5月20日)
软件集成
- 运行时引擎:NeMo 24.12
- 推荐硬件微架构兼容性:
- NVIDIA Hopper
- NVIDIA Ampere
快速入门和使用建议:
- 推理模式(开启/关闭)通过系统提示控制,必须按照以下示例设置。所有指令应包含在用户提示中。
- 对于“推理开启”模式,建议将温度设置为
0.6
,Top P设置为0.95
。 - 对于“推理关闭”模式,建议使用贪心解码。
- 我们提供了针对每个基准测试所需的特定模板的提示列表。
以下示例展示了如何使用Hugging Face Transformers库。推理模式(开启/关闭)通过系统提示控制。请参考以下示例。
我们的代码要求transformers包版本为4.44.2
或更高。
“推理开启”示例:
import torch
import transformers
model_id = "nvidia/Llama-3.1-Nemotron-Nano-4B-v1.1"
model_kwargs = {"torch_dtype": torch.bfloat16, "device_map": "auto"}
tokenizer = transformers.AutoTokenizer.from_pretrained(model_id)
tokenizer.pad_token_id = tokenizer.eos_token_id
pipeline = transformers.pipeline(
"text-generation",
model=model_id,
tokenizer=tokenizer,
max_new_tokens=32768,
temperature=0.6,
top_p=0.95,
**model_kwargs
)
# 思考模式可设为“on”或“off”
thinking = "on"
print(pipeline([{"role": "system", "content": f"detailed thinking {thinking}"}, {"role": "user", "content": "Solve x*(sin(x)+2)=0"}]))
“推理关闭”示例:
import torch
import transformers
model_id = "nvidia/Llama-3.1-Nemotron-Nano-4B-v1"
model_kwargs = {"torch_dtype": torch.bfloat16, "device_map": "auto"}
tokenizer = transformers.AutoTokenizer.from_pretrained(model_id)
tokenizer.pad_token_id = tokenizer.eos_token_id
pipeline = transformers.pipeline(
"text-generation",
model=model_id,
tokenizer=tokenizer,
max_new_tokens=32768,
do_sample=False,
**model_kwargs
)
# 思考模式可设为“on”或“off”
thinking = "off"
print(pipeline([{"role": "system", "content": f"detailed thinking {thinking}"}, {"role": "user", "content": "Solve x*(sin(x)+2)=0"}]))
对于某些提示,即使关闭了思考模式,模型仍可能倾向于在回答前进行思考。但如果需要,用户可以通过预填充助手响应来阻止这一行为。
import torch
import transformers
model_id = "nvidia/Llama-3.1-Nemotron-Nano-4B-v1.1"
model_kwargs = {"torch_dtype": torch.bfloat16, "device_map": "auto"}
tokenizer = transformers.AutoTokenizer.from_pretrained(model_id)
tokenizer.pad_token_id = tokenizer.eos_token_id
# 思考模式可设为“on”或“off”
thinking = "off"
pipeline = transformers.pipeline(
"text-generation",
model=model_id,
tokenizer=tokenizer,
max_new_tokens=32768,
do_sample=False,
**model_kwargs
)
print(pipeline([{"role": "system", "content": f"detailed thinking {thinking}"}, {"role": "user", "content": "Solve x*(sin(x)+2)=0"}, {"role":"assistant", "content":"<think>\n</think>"}]))
运行支持工具调用的vLLM服务器
Llama-3.1-Nemotron-Nano-4B-v1.1支持工具调用。此HF仓库托管了一个工具调用解析器以及一个Jinja格式的聊天模板,可用于启动vLLM服务器。
以下是一个启动支持工具调用的vLLM服务器的Shell脚本示例。vllm/vllm-openai:v0.6.6
或更高版本应支持该模型。
#!/bin/bash
CWD=$(pwd)
PORT=5000
git clone https://huggingface.co/nvidia/Llama-3.1-Nemotron-Nano-4B-v1.1
docker run -it --rm \
--runtime=nvidia \
--gpus all \
--shm-size=16GB \
-p ${PORT}:${PORT} \
-v ${CWD}:${CWD} \
vllm/vllm-openai:v0.6.6 \
--model $CWD/Llama-3.1-Nemotron-Nano-4B-v1.1 \
--trust-remote-code \
--seed 1 \
--host "0.0.0.0" \
--port $PORT \
--served-model-name "Llama-Nemotron-Nano-4B-v1.1" \
--tensor-parallel-size 1 \
--max-model-len 131072 \
--gpu-memory-utilization 0.95 \
--enforce-eager \
--enable-auto-tool-choice \
--tool-parser-plugin "${CWD}/Llama-3.1-Nemotron-Nano-4B-v1.1/llama_nemotron_nano_toolcall_parser.py" \
--tool-call-parser "llama_nemotron_json" \
--chat-template "${CWD}/Llama-3.1-Nemotron-Nano-4B-v1.1/llama_nemotron_nano_generic_tool_calling.jinja"
或者,您可以使用虚拟环境启动vLLM服务器,如下所示。
$ git clone https://huggingface.co/nvidia/Llama-3.1-Nemotron-Nano-4B-v1.1
$ conda create -n vllm python=3.12 -y
$ conda activate vllm
$ python -m vllm.entrypoints.openai.api_server \
--model Llama-3.1-Nemotron-Nano-4B-v1.1 \
--trust-remote-code \
--seed 1 \
--host "0.0.0.0" \
--port 5000 \
--served-model-name "Llama-Nemotron-Nano-4B-v1.1" \
--tensor-parallel-size 1 \
--max-model-len 131072 \
--gpu-memory-utilization 0.95 \
--enforce-eager \
--enable-auto-tool-choice \
--tool-parser-plugin "Llama-3.1-Nemotron-Nano-4B-v1.1/llama_nemotron_nano_toolcall_parser.py" \
--tool-call-parser "llama_nemotron_json" \
--chat-template "Llama-3.1-Nemotron-Nano-4B-v1.1/llama_nemotron_nano_generic_tool_calling.jinja"
启动vLLM服务器后,您可以使用以下Python脚本调用支持工具调用的服务器。
>>> from openai import OpenAI
>>> client = OpenAI(
base_url="http://0.0.0.0:5000/v1",
api_key="dummy",
)
>>> completion = client.chat.completions.create(
model="Llama-Nemotron-Nano-4B-v1.1",
messages=[
{"role": "system", "content": "detailed thinking on"},
{"role": "user", "content": "My bill is $100. What will be the amount for 18% tip?"},
],
tools=[
{"type": "function", "function": {"name": "calculate_tip", "parameters": {"type": "object", "properties": {"bill_total": {"type": "integer", "description": "The total amount of the bill"}, "tip_percentage": {"type": "integer", "description": "The percentage of tip to be applied"}}, "required": ["bill_total", "tip_percentage"]}}},
{"type": "function", "function": {"name": "convert_currency", "parameters": {"type": "object", "properties": {"amount": {"type": "integer", "description": "The amount to be converted"}, "from_currency": {"type": "string", "description": "The currency code to convert from"}, "to_currency": {"type": "string", "description": "The currency code to convert to"}}, "required": ["from_currency", "amount", "to_currency"]}}},
],
)
>>> completion.choices[0].message.content
'<think>\nOkay, let\'s see. The user has a bill of $100 and wants to know the amount of a 18% tip. So, I need to calculate the tip amount. The available tools include calculate_tip, which requires bill_total and tip_percentage. The parameters are both integers. The bill_total is 100, and the tip percentage is 18. So, the function should multiply 100 by 18% and return 18.0. But wait, maybe the user wants the total including the tip? The question says "the amount for 18% tip," which could be interpreted as the tip amount itself. Since the function is called calculate_tip, it\'s likely that it\'s designed to compute the tip, not the total. So, using calculate_tip with bill_total=100 and tip_percentage=18 should give the correct result. The other function, convert_currency, isn\'t relevant here. So, I should call calculate_tip with those values.\n</think>\n\n'
>>> completion.choices[0].message.tool_calls
[ChatCompletionMessageToolCall(id='chatcmpl-tool-2972d86817344edc9c1e0f9cd398e999', function=Function(arguments='{"bill_total": 100, "tip_percentage": 18}', name='calculate_tip'), type='function')]
推理:
引擎:Transformers
测试硬件:
- BF16:
- 1x RTX 50系列显卡
- 1x RTX 40系列显卡
- 1x RTX 30系列显卡
- 1x H100-80GB显卡
- 1x A100-80GB显卡
推荐/支持的操作系统:Linux
训练数据集
后训练流程使用了多种训练数据,包括人工标注数据和合成数据。
针对代码、数学和推理能力提升的多阶段后训练数据是SFT和RL数据的组合,旨在提升原始Llama指导模型在数学、代码、通用推理和指令跟随方面的能力。
提示来源于公开语料库或合成生成。响应由多种模型合成生成,部分提示包含“推理开启”和“推理关闭”两种模式的响应,以训练模型区分这两种模式。
训练数据集的数据收集:
- 混合:自动化、人工、合成
训练数据集的数据标注:
- 不适用
评估数据集
我们使用以下数据集评估Llama-3.1-Nemotron-Nano-4B-v1.1。
评估数据集的数据收集:混合:人工/合成
评估数据集的数据标注:混合:人工/合成/自动
评估结果
这些结果包含“推理开启”和“推理关闭”两种模式。我们建议在“推理开启”模式下使用温度=0.6
和top_p=0.95
,在“推理关闭”模式下使用贪心解码。所有评估均在32k序列长度下完成。我们多次运行基准测试(最多16次)并取平均分以提高准确性。
注意:如适用,将提供提示模板。在完成基准测试时,请确保按照提供的提示解析正确的输出格式,以复现以下基准测试结果。
MT-Bench
推理模式 | 得分 |
---|---|
推理关闭 | 7.4 |
推理开启 | 8.0 |
MATH500
推理模式 | pass@1 |
---|---|
推理关闭 | 71.8% |
推理开启 | 96.2% |
用户提示模板:
"Below is a math question. I want you to reason through the steps and then give a final answer. Your final answer should be in \boxed{}.\nQuestion: {question}"
AIME25
推理模式 | pass@1 |
---|---|
推理关闭 | 13.3% |
推理开启 | 46.3% |
用户提示模板:
"Below is a math question. I want you to reason through the steps and then give a final answer. Your final answer should be in \boxed{}.\nQuestion: {question}"
GPQA-D
推理模式 | pass@1 |
---|---|
推理关闭 | 33.8% |
推理开启 | 55.1% |
用户提示模板:
"What is the correct answer to this question: {question}\nChoices:\nA. {option_A}\nB. {option_B}\nC. {option_C}\nD. {option_D}\nLet's think step by step, and put the final answer (should be a single letter A, B, C, or D) into a \boxed{}"
IFEval
推理模式 | 严格:提示 | 严格:指令 |
---|---|---|
推理关闭 | 70.1% | 78.5% |
推理开启 | 75.5% | 82.6% |
BFCL v2 Live
推理模式 | 得分 |
---|---|
推理关闭 | 63.6% |
推理开启 | 67.9% |
用户提示模板:
<AVAILABLE_TOOLS>{functions}</AVAILABLE_TOOLS>
{user_prompt}
MBPP 0-shot
推理模式 | pass@1 |
---|---|
推理关闭 | 61.9% |
推理开启 | 85.8% |
用户提示模板:
You are an exceptionally intelligent coding assistant that consistently delivers accurate and reliable responses to user instructions.
@@ Instruction
Here is the given problem and test examples:
{prompt}
Please use the python programming language to solve this problem.
Please make sure that your code includes the functions from the test samples and that the input and output formats of these functions match the test samples.
Please return all completed codes in one code block.
This code block should be in the following format:
```python
# Your codes here
```
伦理考量:
NVIDIA认为可信赖的AI是一项共同责任,我们已制定政策和实践以支持广泛AI应用的开发。当按照我们的服务条款下载或使用时,开发者应与其内部模型团队合作,确保该模型满足相关行业和使用场景的要求,并解决意外的产品滥用问题。
有关该模型的伦理考量的更多详细信息,请参阅Model Card++子卡:可解释性、偏见、安全与保障和隐私。
请通过此链接报告安全漏洞或NVIDIA AI相关问题。


