Transformers documentation
Nanotron
快速入门
基类
模型
预处理器
推理
Pipeline API
生成 API
优化
与模型对话
服务
训练
硬件
量化
生态系统集成
资源
API
You are viewing main version, which requires installation from source. If you'd like
regular pip install, checkout the latest stable version (v5.24.0).
Nanotron
Nanotron 是一个支持张量并行、流水线并行和数据并行(3D 并行)的分布式训练框架。它专为跨数百块 GPU 的大规模训练任务而设计。
使用 convert_hf_to_nanotron.py 脚本,将任意 Transformers 模型转换为用于预训练的优化版 Nanotron 变换器模型实现。
torchrun --nproc_per_node=1 examples/llama/convert_hf_to_nanotron.py \
--checkpoint_path=meta-llama/Llama-2-7b-hf \
--save_path=./llama-7b-nanotronTransformers 集成
- 使用 from_pretrained() 函数加载受支持的 Transformers 模型,例如
Llama。该函数会从检查点目录中读取config.json文件,并创建一个 LlamaConfig。 - Nanotron 会将 LlamaConfig 映射为其自身的配置格式,并创建一个 Nanotron 模型。
- 将 Transformers 权重转换为 Nanotron。权重映射用于指导如何将 Nanotron 参数名称映射到 Transformers 参数名称。这包括处理诸如融合 QKV 投影和 gate/up 投影等转换。
Nanotron 还依赖 AutoTokenizer 在预处理和生成阶段将文本转换为 token id。
资源
- Nanotron 仓库
- Ultrascale Playbook 介绍了如何使用 Nanotron 高效扩展训练