Package: pykoi
🎏 pykoi: RLHF/RLAIF in one unified interfacepykoiis 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.Featurespykoilet you easily get real-time user feedback and continuously improve your models. Here are some common applications:Sharable UIDo 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:If you're using a CPU instance, check outdemo_launch_app_cpu.ipynbIf you're using a GPU instance, check outdemo_launch_app_gpu.ipynbAlternatively, read ourblogfor more information!Model comparisonComparing models is a difficult task.pykoimakes 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 usepk.Compare. Check out any of the demo below:If you're using a CPU instance, check outdemo_launch_app_cpu.ipynbIf you're using a GPU instance, check outdemo_launch_app_gpu.ipynbAlternatively, read ourblogfor more information!RLHFReinforcement 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 fromDeepmind,OpenAIandMeta Llama2have all demonstrated that RLHF is a game changer for large language models (LLMs) training.pykoiallows you to easily fine-tune your model on the datasets you've collected via yourpykoichat or rank databases. Check ourblogfor detailed instructions on how to use it.RAGImplement a Retrieval-Augmented Generation (RAG) Chatbot quickly withpykoi. Upload your own documents to create context-aware responses on top of a pretrained LLM, such as from OpenAI or Huggingface.Then chat with the RAG Chatbot, where you can select specific sources for the text generation, as well as see which sources the model used to generate the response.Finally, you can save a modified response to help improve the model. This is a great way to collect data for RLHF.InstallationTo 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, installcondafor 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 installpykoiand the compatiblepytorch based on your ospip3 install "pykoi[rag]"
pip3 install torchOption 2: RAG (GPU)This option allows you to run RAG on a GPU using an open-source LLM from HuggingFace. Here's a quicktutorialon 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 pykoiThen installpykoiandpytorch based on your cuda version. You can find your CUDA version vianvcc -V.pip3 install "pykoi[rag, huggingface]"

pip3 install --pre torch --index-url https://download.pytorch.org/whl/nightly/cu121  # cu121 means cuda 12.1Option 3: RLHF (GPU)This option allows you to train LLM via RLHF on a GPU. Here's a quicktutorialon 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 pykoiThen installpykoiandpytorch based on your cuda version. You can find your CUDA version vianvcc -V.pip3 install "pykoi[rlhf]"

pip3 install --pre torch --index-url https://download.pytorch.org/whl/nightly/cu121  # cu121 means cuda 12.1Congrats you have finished the installation!Dev SetupIf you are interested to contribute to us, here are the preliminary development setup.Backend Dev Setupconda create -n pykoi python=3.10
conda activate pykoi
cd pykoi
pip3 install poetryThen, 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 ragOption 2: RAG (GPU)poetry install --no-root --extras "rag huggingface"Option 3: RLHF (GPU)poetry install --no-root --extras rlhfFinally, if you are on a GPU, installpytorch based on your cuda version. You can find your CUDA version vianvcc -V.pip3 uninstall -y torch
pip3 install --pre torch --index-url https://download.pytorch.org/whl/nightly/cu121  # cu121 means cuda 12.1Now you are done with installing, try to modify one of the examples and run the below command!python -m example.retrieval_qa.retrieval_qa_huggingface_demoFrontend Dev Setupcd pykoi/pykoi/frontend
npm install
npm run buildEC2 Dev SetupIf you are on EC2, you can launch a GPU instance with the following config:EC2g5.2xlarge(if you want to run a pretrained LLM with 7B parameters)Deep Learning AMI PyTorch GPU 2.0.1 (Ubuntu 20.04)EBS: at least 100G