Skip to content

Instantly share code, notes, and snippets.

View JoaoLages's full-sized avatar
🐛
Probably fixing bugs

João Lages JoaoLages

🐛
Probably fixing bugs
View GitHub Profile
@JoaoLages
JoaoLages / with_and_without_kv_caching_comparison.py
Last active October 8, 2023 17:21
Comparing generation speed with and without KV caching
import numpy as np
import time
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
device = "cuda" if torch.cuda.is_available() else "cpu"
tokenizer = AutoTokenizer.from_pretrained("gpt2")
model = AutoModelForCausalLM.from_pretrained("gpt2").to(device)
for use_cache in (True, False):
@JoaoLages
JoaoLages / RLHF.md
Last active March 26, 2024 18:51
Reinforcement Learning from Human Feedback (RLHF) - a simplified explanation

Maybe you've heard about this technique but you haven't completely understood it, especially the PPO part. This explanation might help.

We will focus on text-to-text language models 📝, such as GPT-3, BLOOM, and T5. Models like BERT, which are encoder-only, are not addressed.

Reinforcement Learning from Human Feedback (RLHF) has been successfully applied in ChatGPT, hence its major increase in popularity. 📈

RLHF is especially useful in two scenarios 🌟:

  • You can’t create a good loss function
    • Example: how do you calculate a metric to measure if the model’s output was funny?
  • You want to train with production data, but you can’t easily label your production data
@JoaoLages
JoaoLages / mahalanobis_distance_for_outlier_detection.html
Last active March 25, 2022 13:08
Mahalanobis distance: Measure the distance of your datapoint to a list of datapoints!
<!DOCTYPE html>
<html>
<head><meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>mahalanobis_distance_for_outlier_detection</title><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.10/require.min.js"></script>