🚀 Nemotron-UltraLong-8B模型
Nemotron-UltraLong-8B 是一系列超长上下文语言模型,旨在处理大量文本序列(最多可达100万、200万和400万个标记),同时在标准基准测试中保持有竞争力的性能。该模型基于Llama-3.1构建,采用了系统的训练方法,将高效的持续预训练与指令调优相结合,以增强长上下文理解和指令遵循能力。这种方法使模型能够在不牺牲整体性能的情况下,有效扩展其上下文窗口。
🚀 快速开始
从 transformers >= 4.43.0
版本开始,你可以使用Transformers的 pipeline
抽象或借助 generate()
函数的Auto类来运行对话推理。
请确保通过 pip install --upgrade transformers
更新你的transformers库。
import transformers
import torch
model_id = "nvidia/Llama-3.1-Nemotron-8B-UltraLong-4M-Instruct"
pipeline = transformers.pipeline(
"text-generation",
model=model_id,
model_kwargs={"torch_dtype": torch.bfloat16},
device_map="auto",
)
messages = [
{"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
{"role": "user", "content": "Who are you?"},
]
outputs = pipeline(
messages,
max_new_tokens=256,
)
print(outputs[0]["generated_text"][-1])
✨ 主要特性
- 超长上下文处理能力:能够处理最多400万个标记的文本序列。
- 高效训练方法:结合持续预训练和指令调优,提升长上下文理解和指令遵循能力。
- 多领域适应性:在长上下文任务和标准任务中均表现出色。
📦 安装指南
通过以下命令更新transformers库:
pip install --upgrade transformers
💻 使用示例
基础用法
import transformers
import torch
model_id = "nvidia/Llama-3.1-Nemotron-8B-UltraLong-4M-Instruct"
pipeline = transformers.pipeline(
"text-generation",
model=model_id,
model_kwargs={"torch_dtype": torch.bfloat16},
device_map="auto",
)
messages = [
{"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
{"role": "user", "content": "Who are you?"},
]
outputs = pipeline(
messages,
max_new_tokens=256,
)
print(outputs[0]["generated_text"][-1])
📚 详细文档
模型卡片
属性 |
详情 |
基础模型 |
meta-llama/Llama-3.1-8B-Instruct |
持续预训练 |
训练数据由10亿个标记组成,这些标记来自预训练语料库,采用基于样本长度的按领域上采样方法。模型在序列长度为400万、全局批次大小为2的情况下训练了150次迭代。 |
监督微调(SFT) |
在通用、数学和代码领域的开源指令数据集上使用10亿个标记进行微调。我们从 AceMath-Instruct 的 ‘general_sft_stage2’ 中对数据进行子采样。 |
最大上下文窗口 |
400万个标记 |
评估结果
我们在一系列多样化的基准测试中对Nemotron-UltraLong-8B进行了评估,包括长上下文任务(如RULER、LV-Eval和InfiniteBench)和标准任务(如MMLU、MATH、GSM-8K和HumanEval)。UltraLong-8B在超长上下文任务中表现出色,同时在标准基准测试中也保持了有竞争力的结果。
大海捞针测试

长上下文评估

标准能力评估

🔧 技术细节
- 模型架构:基于Llama-3.1架构构建。
- 训练方法:结合持续预训练和监督微调,以提升模型性能。
- 数据处理:在持续预训练和监督微调阶段采用不同的数据处理策略。
📄 许可证
本模型采用CC BY-NC 4.0许可证。
对应信息
- Chejian Xu (chejian2@illinois.edu)
- Wei Ping (wping@nvidia.com)
引用信息
@article{ulralong2025,
title={From 128K to 4M: Efficient Training of Ultra-Long Context Large Language Models},
author={Xu, Chejian and Ping, Wei and Xu, Peng and Liu, Zihan and Wang, Boxin and Shoeybi, Mohammad and Catanzaro, Bryan},
journal={arXiv preprint},
year={2025}
}