Fairseq 是一个用PyTorch编写的序列建模工具包,允许研究人员和开发人员训练用于翻译、摘要、语言建模和其他文本生成任务的自定义模型。
特征:
- 在一台机器或多台机器上进行多 GPU 训练(数据和模型并行)
- 在 CPU 和 GPU 上快速生成,并实现多种搜索算法:波束搜索多样化波束搜索 ( Vijayakumar et al., 2016 )采样(无约束、top-k 和 top-p/nucleus)词法约束解码(Post & Vilar,2018)
- 即使在单个 GPU 上,梯度累积也能实现大批量训练
- 混合精度训练(在NVIDIA 张量核心上使用更少的 GPU 内存训练得更快)
- 可扩展:轻松注册新模型、标准、任务、优化器和学习率调度器
- 基于Hydra 的灵活配置,允许组合代码、命令行和基于文件的配置
- 全参数和优化器状态分片
- 将参数卸载到 CPU
我们还通过方便的界面提供用于翻译和语言建模的预训练模型torch.hub:
en2de = torch.hub.load('pytorch/fairseq', 'transformer.wmt19.en-de.single_model')
en2de.translate('Hello world', beam=5)
# 'Hallo Welt'
请参阅 PyTorch Hub翻译教程 和RoBERTa了解更多示例。
要求和安装
- PyTorch版本 >= 1.10.0
- Python 版本 >= 3.8
- 为了训练新模型,您还需要 NVIDIA GPU 和NCCL
- 安装 fairseq并在本地开发:
git clone https://github.com/pytorch/fairseq
cd fairseq
pip install --editable ./
# on MacOS:
# CFLAGS="-stdlib=libc++" pip install --editable ./
# to install the latest stable release (0.10.x)
# pip install fairseq
- 为了更快地训练,请安装 NVIDIA 的apex库:
git clone https://github.com/NVIDIA/apex
cd apex
pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" \
--global-option="--deprecated_fused_adam" --global-option="--xentropy" \
--global-option="--fast_multihead_attn" ./
- 对于大型数据集,安装PyArrow:pip install pyarrow
- --ipc=host如果您使用 Docker,请确保使用或--shm-size 作为命令行选项来增加共享内存大小nvidia-docker run。
项目文档:https://github.com/facebookresearch/fairseq#features
本文暂时没有评论,来添加一个吧(●'◡'●)