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一起貢獻的圖書館,該圖書館最初啟發了此倉庫。