Code Monkey home page Code Monkey logo

trlx's Introduction

DOI

Transformer Reinforcement Learning X

trlX allows you to fine-tune ๐Ÿค— Hugging Face supported language models of up to 20B parameters (such as gpt2, gpt-j, and gpt-neox, as well as T5 based models, including google/t5-v1_1 and google/flan-t5) using reinforcement learning via either a provided reward function or reward-labeled dataset. Proximal Policy Optimization (PPO) and Implicit Language Q-Learning (ILQL) are implemented.

You can read more about trlX in our documentation.

Want to collect human annotations for your RL application? Check out CHEESE!, our library for HiTL data collection.

Installation

git clone https://github.com/CarperAI/trlx.git
cd trlx
pip install torch --extra-index-url https://download.pytorch.org/whl/cu116 # for cuda
pip install -e .

Examples

For more usage see examples. You can also try the colab notebooks below:

Description Link
Simulacra Example Open In Colab

How to Train

You can train a model using a reward function or a reward-labeled dataset.

Using a reward function

trainer = trlx.train('gpt2', reward_fn=lambda samples, **kwargs: [sample.count('cats') for sample in samples])

Using a reward-labeled dataset

trainer = trlx.train('EleutherAI/gpt-j-6B', dataset=[('dolphins', 'geese'), (1.0, 100.0)])

Trainers provide a wrapper over their underlying model

trainer.generate(**tokenizer('Q: Who rules the world? A:', return_tensors='pt'), do_sample=True)

Save the resulting model to a Hugging Face pretrained language model. (Ready to upload to the Hub!)

trainer.save_pretrained('/path/to/output/folder/')

๐Ÿฉน Warning: Only the AcceleratePPOTrainer can write HuggingFace transformers to disk with save_pretrained at the moment, as ILQL trainers require inference behavior currently unsupported by available transformers architectures.

Use ๐Ÿค— Accelerate to launch distributed training

accelerate config # choose DeepSpeed option
accelerate launch examples/simulacra.py

Use Ray Tune to launch hyperparameter sweep

python -m trlx.sweep --config configs/sweeps/ppo_sweep.yml examples/ppo_sentiments.py

Contributing

For development check out these guidelines and also read our docs

Acknowledgements

Many thanks to Leandro von Werra for contributing with trl, a library that initially inspired this repo.

trlx's People

Contributors

aaronrmm avatar aicrumb avatar alan-cooney avatar ayulockin avatar cat-state avatar dahoas avatar dependabot[bot] avatar dongs0104 avatar ethankim00 avatar jon-tow avatar justinawei avatar leshanbog avatar louiscastricato avatar lvwerra avatar marcobellagente93 avatar maxreciprocate avatar mistobaan avatar mrm8488 avatar nickypro avatar osanseviero avatar phungvanduy avatar reshinthadithyan avatar shahbuland avatar shermansiu avatar simoninithomas avatar smellslikeml avatar thedch avatar thomfoster avatar vblagoje avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.