Transformers documentation

Nanotron

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).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

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-nanotron

Transformers 集成

  1. 使用 from_pretrained() 函数加载受支持的 Transformers 模型,例如 Llama。该函数会从检查点目录中读取 config.json 文件,并创建一个 LlamaConfig。
  2. Nanotron 会将 LlamaConfig 映射为其自身的配置格式,并创建一个 Nanotron 模型。
  3. 将 Transformers 权重转换为 Nanotron。权重映射用于指导如何将 Nanotron 参数名称映射到 Transformers 参数名称。这包括处理诸如融合 QKV 投影和 gate/up 投影等转换。

Nanotron 还依赖 AutoTokenizer 在预处理和生成阶段将文本转换为 token id。

资源

Update on GitHub