TRLX是一个从头开始设计的分布式培训框架,专注于使用提供的奖励功能或奖励标记的数据集,通过增强学习的大型语言模型。
培训支持?拥抱面部模型由加速支持的培训师提供,使用户可以微调可因果关系和最多20b参数的基于T5的语言模型,例如facebook/opt-6.7b , EleutherAI/gpt-neox-20b和google/flan-t5-xxl 。对于20B参数以上的模型,TRLX提供了NVIDIA NEMO支持的培训师,可利用有效的并行性技术有效地扩展。
目前实施了以下RL算法:
| 算法 | 加速培训师 | Nemo培训师 |
|---|---|---|
| 近端策略优化(PPO) | ✅ | ✅ |
| 隐式语言q学习(ILQL) | ✅ | ✅ |
文档
?奶酪通过我们的人类数据收集库为您的RL应用收集人类注释。
git clone https://github.com/CarperAI/trlx.git
cd trlx
pip install torch --extra-index-url https://download.pytorch.org/whl/cu118
pip install -e . 有关更多用法,请参见示例。您还可以尝试以下COLAB笔记本:
| 描述 | 关联 |
|---|---|
| Simulacra(GPT2,ILQL) | |
| 情感(GPT2,ILQL) |
这些示例的最新运行是我们的体重和偏见
您可以使用奖励功能或奖励标记的数据集训练模型。
trainer = trlx . train ( 'gpt2' , reward_fn = lambda samples , ** kwargs : [ sample . count ( 'cats' ) for sample in samples ])有关奖励模型培训,请参阅我们的独裁图书馆。
trainer = trlx . train ( 'EleutherAI/gpt-j-6B' , samples = [ 'dolphins' , 'geese' ], rewards = [ 1.0 , 100.0 ]) trainer = trlx . train ( 'gpt2' , samples = [[ 'Question: 1 + 2 Answer:' , '3' ], [ 'Question: Solve this equation: ∀n>0, s=2, sum(n ** -s). Answer:' , '(pi ** 2)/ 6' ]]) trainer . generate ( ** tokenizer ( 'Q: Who rules the world? A:' , return_tensors = 'pt' ), do_sample = True ) from trlx . data . default_configs import default_ppo_config
config = default_ppo_config ()
config . model . model_path = 'EleutherAI/gpt-neox-20b'
config . tokenizer . tokenizer_path = 'EleutherAI/gpt-neox-20b'
config . train . seq_length = 2048
trainer = trlx . train ( config = config , reward_fn = lambda samples , ** kwargs : [ len ( sample ) for sample in samples ])为了减少内存使用量(如果您遇到的CUDA出现在内存错误中),请首先尝试以下超参数的最低设置,并最终增加它们:
# micro batch size per gpu
config . train . batch_size = 1
# freeze all transformer layers
config . model . num_layers_unfrozen = 0
# maximum sample length, prompts or samples longer than that will be truncated
config . train . seq_length = 128
# micro batch size for sampling (specific for PPO)
config . method . chunk_size = 1
# use an additional Q-head (specific for ILQL)
config . method . two_qs = False trainer . save_pretrained ( '/path/to/output/folder/' )accelerate config # choose DeepSpeed option
accelerate launch examples/simulacra.py按照Nemo Readme中的设置说明。
python examples/nemo_ilql_sentiments.py有关更多用法,请参阅Nemo Readme
ray start --head --port=6379
python -m trlx.sweep --config configs/sweeps/ppo_sweep.yml --accelerate_config configs/accelerate/ddp.yaml --num_gpus 4 examples/ppo_sentiments.pymain分支python -m trlx.reference octocat/trlx-fork:fix-branchTRLX使用标准Python logging库将培训信息记录到控制台。默认记录器设置为INFO级别,这意味着将将INFO , WARNING , ERROR和CRITICAL级别消息打印到标准输出。
要直接更改日志级别,您可以使用详细的设置器。例如,将日志级别设置为WARNING使用:
import trlx
trlx . logging . set_verbosity ( trlx . logging . WARNING )这将抑制INFO级消息,但仍会打印WARNING , ERROR和CRITICAL级别消息。
您还可以通过将TRLX_VERBOSITY环境变量设置为标准记录级别的名称之一来控制记录的冗长:
CRITICAL ( trlx.logging.CRITICAL )ERROR ( trlx.logging.ERROR )WARNING ( trlx.logging.WARNING )INFO ( trlx.logging.INFO )DEBUG ( trlx.logging.DEBUG ) export TRLX_VERBOSITY=WARNING默认情况下, tqdm进度条用于显示训练进度。您可以通过调用trlx.logging.disable_progress_bar()来禁用它们,否则trlx.logging.enable_progress_bar()启用。
可以通过设置trlx.logging.enable_explicit_format()来更详细地格式化消息。这将向每个日志注入呼叫点信息,这可能有助于调试。
[2023-01-01 05:00:00,000] [INFO] [ppo_orchestrator.py:63:make_experience] [RANK 0] Message...提示:为了减少日志记录输出的量,您可能会发现更改TRLX使用的第三方库的日志级别。例如,尝试将
transformers.logging.set_verbosity_error()添加到trlx脚本的顶部,以从transformers库中沉默冗长的消息(有关更多详细信息,请参见其记录文档)。
为了开发查看这些准则,还可以阅读我们的文档
@inproceedings{havrilla-etal-2023-trlx,
title = "trl{X}: A Framework for Large Scale Reinforcement Learning from Human Feedback",
author = "Havrilla, Alexander and
Zhuravinskyi, Maksym and
Phung, Duy and
Tiwari, Aman and
Tow, Jonathan and
Biderman, Stella and
Anthony, Quentin and
Castricato, Louis",
booktitle = "Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing",
month = dec,
year = "2023",
address = "Singapore",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2023.emnlp-main.530",
doi = "10.18653/v1/2023.emnlp-main.530",
pages = "8578--8595",
}
非常感谢Leandro von Werra与TRL一起贡献的图书馆,该图书馆最初启发了此仓库。