TRL 文档
情感调优示例
加入 Hugging Face 社区
并获取增强的文档体验
开始使用
情感调优示例
本示例中的 notebook 和脚本展示了如何使用情感分类器(例如 lvwerra/distilbert-imdb
)微调模型。
以下是 trl 仓库中 notebook 和脚本的概述
文件 | 描述 |
---|---|
examples/scripts/ppo.py | 此脚本展示了如何使用 PPOTrainer 微调使用 IMDB 数据集的情感分析模型 |
examples/notebooks/gpt2-sentiment.ipynb | 此 notebook 演示了如何在 jupyter notebook 上重现 GPT2 imdb 情感调优示例。 |
examples/notebooks/gpt2-control.ipynb | 此 notebook 演示了如何在 jupyter notebook 上重现 GPT2 情感控制示例。 |
用法
# 1. run directly
python examples/scripts/ppo.py
# 2. run via `accelerate` (recommended), enabling more features (e.g., multiple GPUs, deepspeed)
accelerate config # will prompt you to define the training configuration
accelerate launch examples/scripts/ppo.py # launches training
# 3. get help text and documentation
python examples/scripts/ppo.py --help
# 4. configure logging with wandb and, say, mini_batch_size=1 and gradient_accumulation_steps=16
python examples/scripts/ppo.py --log_with wandb --mini_batch_size 1 --gradient_accumulation_steps 16
注意:如果您不想使用 wandb
进行日志记录,请在 scripts/notebooks 中删除 log_with="wandb"
。您也可以将其替换为您喜欢的实验跟踪器,该跟踪器受 accelerate
支持。
关于多 GPU 的一些注意事项
要在使用 DDP(分布式数据并行)的多 GPU 设置中运行,请将 device_map
值更改为 device_map={"": Accelerator().process_index}
,并确保使用 accelerate launch yourscript.py
运行脚本。如果您想应用朴素的流水线并行,可以使用 device_map="auto"
。