Skip to main content

pykoi: Active learning in one unified interface

Project description

🎏 pykoi: RLHF/RLAIF in one unified interface

License Apache-2.0 pypi_status Commit activity Slack

pykoi is an open-source python library for improving LLMs with RLHF. We provide a unified interface including RLHF/RLAIF data and feedback collection, finetuning with reinforcement learning and reward modeling, and LLM comparisons.

Features

pykoi let you easily get real-time user feedback and continuously improve your models. Here are some common applications:

Sharable UI

Do you want to store your chat history with LLMs from OpenAI, Amazon Bedrock(:woman_technologist: building now :man_technologist:), or Huggingface? With just three lines of code, pykoi lets you to store them locally, ensuring 100% privacy. This includes launching a chatbot UI, automatically saving your chat history in your compute instance (cpu or gpu), and visualizing it on a dashboard. Explore the demos below:

Watch the video

Model comparison

Comparing models is a difficult task. pykoi makes it easy by allowing one to directly compare the performance of multiple models to each other, with just a few lines of code. If you have multiple language models that you’d like to compare to each other on a set of prompts or via an interactive session, you can use pk.Compare. Check out any of the demo below:

Watch the video

RLHF

Reinforcement Learning with Human Feedback (RLHF) is a unique training paradigm that blends reinforcement learning with human-in-the-loop training. The central idea is to use human evaluative feedback to refine a model's decision-making ability and guide the learning process towards desired outcomes. Researchers from Deepmind, OpenAI and Meta Llama2 have all demonstrated that RLHF is a game changer for large language models (LLMs) training.

pykoi allows you to easily fine-tune your model on the datasets you've collected via your pykoi chat or rank databases. Check our blog for detailed instructions on how to use it.

Installation

To get started with pykoi, you can choose from any of the installation options. The choice should be based on the features you need (e.g., RAG, RLHF or all) and the compute resources you have, such as a CPU (e.g., your laptop) or GPU (e.g., AWS EC2 or SageMaker).

Option 1: RAG (CPU)

This option allows you to run RAG on a CPU using either the OpenAI API or the Anthropic Claude2 API. Installation of RAG (CPU) is simple if you have conda. If not, install conda for your operating system.

First, create a conda environment on your terminal using:

conda create -n pykoi python=3.10 -y
conda activate pykoi  # some OS requires `source activate pykoi`

Then install pykoi and the compatible pytorch based on your os

pip3 install "pykoi[rag]"
pip3 install torch 

Option 2: RAG (GPU)

This option allows you to run RAG on a GPU using an open-source LLM from HuggingFace. Here's a quick tutorial on setting up an EC2 GPU instance for the installation below.

On your GPU instance terminal, create a conda environment using:

conda create -n pykoi python=3.10 -y && source activate pykoi

Then install pykoi and pytorch based on your cuda version. You can find your CUDA version via nvcc -V.

pip3 install "pykoi[rag, huggingface]"

pip3 install --pre torch --index-url https://download.pytorch.org/whl/nightly/cu121  # cu121 means cuda 12.1

Option 3: RLHF (GPU)

This option allows you to train LLM via RLHF on a GPU. Here's a quick tutorial on setting up an EC2 GPU instance for the installation below.

On your GPU instance terminal, create a conda environment using:

conda create -n pykoi python=3.10 -y && source activate pykoi

Then install pykoi and pytorch based on your cuda version. You can find your CUDA version via nvcc -V.

pip3 install "pykoi[rlhf]"

pip3 install --pre torch --index-url https://download.pytorch.org/whl/nightly/cu121  # cu121 means cuda 12.1

Congrats you have finished the installation!

Dev Setup

If you are interested to contribute to us, here are the preliminary development setup.

Backend Dev Setup

conda create -n pykoi python=3.10
conda activate pykoi
cd pykoi
pip3 install poetry

Then, based the feature you need to develop, run one or more installation options below. We recommend install all the options below although it may take ~3 minutes longer.

  • Option 1: RAG (CPU)
    poetry install --no-root --extras rag
    
  • Option 2: RAG (GPU)
    poetry install --no-root --extras "rag huggingface"
    
  • Option 3: RLHF (GPU)
    poetry install --no-root --extras rlhf
    

Finally, if you are on a GPU, install pytorch based on your cuda version. You can find your CUDA version via nvcc -V.

pip3 install --pre torch --index-url https://download.pytorch.org/whl/nightly/cu121  # cu121 means cuda 12.1

Frontend Dev Setup

cd pykoi/pykoi/frontend
npm install
npm run build

EC2 Dev Setup

If you are on EC2, you can launch a GPU instance with the following config:

  • EC2 g4dn.xlarge (if you want to run a pretrained LLM with 7B parameters)
  • Deep Learning AMI PyTorch GPU 2.0.1 (Ubuntu 20.04) Alt text
  • EBS: at least 100G Alt text

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pykoi-0.0.8.tar.gz (214.6 kB view details)

Uploaded Source

Built Distribution

pykoi-0.0.8-py3-none-any.whl (277.3 kB view details)

Uploaded Python 3

File details

Details for the file pykoi-0.0.8.tar.gz.

File metadata

  • Download URL: pykoi-0.0.8.tar.gz
  • Upload date:
  • Size: 214.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.12 Darwin/22.6.0

File hashes

Hashes for pykoi-0.0.8.tar.gz
Algorithm Hash digest
SHA256 c8dfe7c0803a2c5b8e8b4943164695031773107e59363e4b21c9d5fa6881bf0c
MD5 a960cf6af7f5517332d30147834f32d7
BLAKE2b-256 733836ea825b06ab9f312437b5bd442537cd75b5fa4c496e80ad04222266c64f

See more details on using hashes here.

File details

Details for the file pykoi-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: pykoi-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 277.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.12 Darwin/22.6.0

File hashes

Hashes for pykoi-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 7cff4a55a01be4f64a96b1fddc0d47e061153c7a19e10979665632db60e00896
MD5 15583872806121e292379a8c0f9ccfbc
BLAKE2b-256 754458e692c240697da5ad7f11a78d936509832983fcddb28cb1c3be915dd889

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page