Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
P

PaLM-rlhf-pytorch

> 数据库
Open source

Implementation of RLHF (Reinforcement Learning with Human Feedback) on top of the PaLM architecture. Basically ChatGPT but with PaLM

7.9K stars0 likes1 views
WebsiteGitHub

About

Implementation of RLHF (Reinforcement Learning with Human Feedback) on top of the PaLM architecture. Basically ChatGPT but with PaLM

official chatgpt blogpost

PaLM + RLHF - Pytorch (wip)

Implementation of RLHF (Reinforcement Learning with Human Feedback) on top of the PaLM architecture. Maybe I'll add retrieval functionality too, à la RETRO

If you are interested in replicating something like ChatGPT out in the open, please consider joining Laion

Potential successor: Direct Preference Optimization - all the code in this repo becomes ~ binary cross entropy loss, < 5 loc. So much for Reward models and PPO

FAQ

  • Does this contain a model for inference?

There is no trained model. This is just the ship and overall map. We still need millions of dollars of compute + data to sail to the correct point in high dimensional parameter space. Even then, you need professional sailors (like Robin Rombach of Stable Diffusion fame) to actually guide the ship through turbulent times to that point.

Community

CarperAI had been working on an RLHF framework for large language models for many months prior to the release of ChatGPT.

Yannic Kilcher is also working on an open sourced implementation

AI Coffeebreak w/ Letitia | Code Emporium | Code Emporium Part 2

Appreciation

  • Stability.ai for the generous sponsorship to work on cutting edge artificial intelligence research

  • Hugging Face and CarperAI for penning the blog post Illustrating Reinforcement Learning from Human Feedback (RLHF), and the former also for their accelerate library

  • @kisseternity and @taynoel84 for the code review and finding bugs

  • Enrico for integrating Flash Attention from Pytorch 2.0

  • bycloud for his educational video for Reasoning with Exploration

Install

bash
$ pip install palm-rlhf-pytorch

Usage

First train PaLM, like any other autoregressive transformer

python
import torch
from palm_rlhf_pytorch import PaLM

palm = PaLM(
    num_tokens = 20000,
    dim = 512,
    depth = 12,
    flash_attn = True # https://arxiv.org/abs/2205.14135
).cuda()

seq = torch.randint(0, 20000, (1, 2048)).cuda()

loss = palm(seq, return_loss = True)
loss.backward()

# after much training, you can now generate sequences

generated = palm.generate(2048) # (1, 2048)

Then train your reward model, with the curated human feedback. In the original paper, they could not get reward model to be finetuned from a pretrained transformer without overfitting, but I gave the option to finetune with LoRA anyways, since it is still open research.

…

Then you will pass your transformer and the rewards model to the RLHFTrainer

…

Todo

  • clone base transformer with separate lora for critic

  • also allow for non-LoRA based finetuning

  • redo normalize to be able to have a masked version, not sure if anyone will ever use per token rewards / values, but good practice to implement

  • equip with the best attention

  • add Hugging Face accelerate and test out wandb instrumentation

  • search literature to figure out what is the latest SOTA for PPO, assuming RL field is still making progress.

  • test the system using a pretrained sentiment network as reward model

  • write the memory in PPO to memmapped numpy file

  • get sampling with variable lengthed prompts working, even if it is not needed given bottleneck is human feedback

  • allow for finetuning penultimate N layers only in either actor or critic, assuming if pretrained

  • incorporate some learning points from Sparrow, given Letitia's video

  • simple web interface with django + htmx for collecting human feedback

  • consider RLAIF

Citations

bibtex
@article{Stiennon2020LearningTS,
    title   = {Learning to summarize from human feedback},
    author  = {Nisan Stiennon and Long Ouyang and Jeff Wu and Daniel M. Ziegler and Ryan J. Lowe and Chelsea Voss and Alec Radford and Dario Amodei and Paul Christiano},
    journal = {ArXiv},
    year    = {2020},
    volume  = {abs/2009.01325}
}
…
bibtex
@article{Hu2021LoRALA,
    title   = {LoRA: Low-Rank Adaptation of Large Language Models},
    author  = {Edward J. Hu and Yelong Shen and Phillip Wallis and Zeyuan Allen-Zhu and Yuanzhi Li and Shean Wang and Weizhu Chen},
    journal = {ArXiv},
    year    = {2021},
    volume  = {abs/2106.09685}
}
bibtex
@inproceedings{Sun2022ALT,
    title     = {A Length-Extrapolatable Transformer},
    author    = {Yutao Sun and Li Dong and Barun Patra and Shuming Ma and Shaohan Huang and Alon Benhaim and Vishrav Chaudhary and Xia Song and Furu Wei},
    year      = {2022}
}
bibtex
@misc{gilmer2023intriguing
    title  = {Intriguing Properties of Transformer Training Instabilities},
    author = {Justin Gilmer, Andrea Schioppa, and Jeremy Cohen},
    year   = {2023},
    status = {to be published - one attention stabilization technique is circulating within Google Brain, being used by multiple teams}
}
bibtex
@inproceedings{dao2022flashattention,
    title   = {Flash{A}ttention: Fast and Memory-Efficient Exact Attention with {IO}-Awareness},
    author  = {Dao, Tri and Fu, Daniel Y. and Ermon, Stefano and Rudra, Atri and R{\'e}, Christopher},
    booktitle = {Advances in Neural Information Processing Systems},
    year    = {2022}
}
bibtex
@misc{Rubin2024,
    author  = {Ohad Rubin},
    url     = {https://medium.com/@ohadrubin/exploring-weight-decay-in-layer-normalization-challenges-and-a-reparameterization-solution-ad4d12c24950}
}
bibtex
@inproceedings{Yuan2024FreePR,
    title   = {Free Process Rewards without Process Labels},
    author  = {Lifan Yuan and Wendi Li and Huayu Chen and Ganqu Cui and Ning Ding and Kaiyan Zhang and Bowen Zhou and Zhiyuan Liu and Hao Peng},
    year    = {2024},
    url     = {https://api.semanticscholar.org/CorpusID:274445748}
}
bibtex
@article{Shao2024DeepSeekMathPT,
    title   = {DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models},
    author  = {Zhihong Shao and Peiyi Wang and Qihao Zhu and Runxin Xu and Jun-Mei Song and Mingchuan Zhang and Y. K. Li and Yu Wu and Daya Guo},
    journal = {ArXiv},
    year    = {2024},
    volume  = {abs/2402.03300},
    url     = {https://api.semanticscholar.org/CorpusID:267412607}
}
bibtex
@article{Farebrother2024StopRT,
    title   = {Stop Regressing: Training Value Functions via Classification for Scalable Deep RL},
    author  = {Jesse Farebrother and Jordi Orbay and Quan Ho Vuong and Adrien Ali Taiga and Yevgen Chebotar and Ted Xiao and Alex Irpan and Sergey Levine and Pablo Samuel Castro and Aleksandra Faust and Aviral Kumar and Rishabh Agarwal},
    journal = {ArXiv},
    year   = {2024},
    volume = {abs/2403.03950},
    url    = {https://api.semanticscholar.org/CorpusID:268253088}
}
bibtex
@misc{Liu2025,
    title   = {Understanding R1-Zero-Like Training: A Critical Perspective},
    author  = {Zichen Liu, Changyu Chen, Wenjun Li, Penghui Qi, Tianyu Pang, Chao Du, Wee Sun Lee, Min Lin},
    url     = {https://github.com/sail-sg/understand-r1-zero/blob/main/understand-r1-zero.pdf}
}
bibtex
@inproceedings{Yue2025DoesRL,
    title   = {Does Reinforcement Learning Really Incentivize Reasoning Capacity in LLMs Beyond the Base Model?},
    author  = {Yang Yue and Zhiqi Chen and Rui Lu and Andrew Zhao and Zhaokai Wang and Shiji Song and Gao Huang},
    year    = {2025},
    url     = {https://api.semanticscholar.org/CorpusID:277940134}
}
bibtex
@misc{xie2025simplepolicyoptimization,
    title   = {Simple Policy Optimization},
    author  = {Zhengpeng Xie and Qiang Zhang and Fan Yang and Marco Hutter and Renjing Xu},
    year    = {2025},
    eprint  = {2401.16025},
    archivePrefix = {arXiv},
    primaryClass = {cs.LG},
    url = {https://arxiv.org/abs/2401.16025},
}
bibtex
@misc{cheng2025reasoningexplorationentropyperspective,
    title   = {Reasoning with Exploration: An Entropy Perspective on Reinforcement Learning for LLMs},
    author  = {Daixuan Cheng and Shaohan Huang and Xuekai Zhu and Bo Dai and Wayne Xin Zhao and Zhenliang Zhang and Furu Wei},
    year    = {2025},
    eprint  = {2506.14758},
    archivePrefix = {arXiv},
    primaryClass = {cs.CL},
    url     = {https://arxiv.org/abs/2506.14758},
}
…
bibtex
@misc{kaddour2026targetpolicyoptimization,
    title   = {Target Policy Optimization},
    author  = {Jean Kaddour},
    year    = {2026},
    eprint  = {2604.06159},
    archivePrefix = {arXiv},
    primaryClass = {cs.LG},
    url     = {https://arxiv.org/abs/2604.06159},
}
bibtex
@misc{tajwar2026maximumlikelihoodreinforcementlearning,
    title   = {Maximum Likelihood Reinforcement Learning},
    author  = {Fahim Tajwar and Guanning Zeng and Yueer Zhou and Yuda Song and Daman Arora and Yiding Jiang and Jeff Schneider and Ruslan Salakhutdinov and Haiwen Feng and Andrea Zanette},
    year    = {2026},
    eprint  = {2602.02710},
    archivePrefix = {arXiv},
    primaryClass = {cs.LG},
    url     = {https://arxiv.org/abs/2602.02710},
}

Issues· 20 open

View all issuesOpen on GitHub
  • #69

    あ

    Updated Sep 20, 2025
  • #65

    Edge Case 17

    Updated Jul 27, 2025
  • #35

    Value function

    Updated Jan 17, 2025
  • #61

    Do you need to set `retain_graph=True`?

    Updated Dec 6, 2024
  • #60

    A bug in the implementation of the top-p sampling

    Updated Sep 27, 2024
  • #59

    Is there any documentation to train this on my own data ?

    Updated Feb 28, 2024
  • #58

    How to use lora?

    Updated Feb 16, 2024
  • #57

    Should critic's input be prompt only?

    Updated Nov 27, 2023
  • #23

    ✨ Is possibale to use the ChatGPT of OpenAI to train this ChatGPT?

    Updated Nov 5, 2023
  • #51

    I looked at the llama source code and there is an intermedie layer

    Updated Jun 10, 2023

> Tags

Pythonartificial-intelligenceattention-mechanismsdeep-learninghuman-feedback

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedOct 1, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库