Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# train_grpo.py | |
import re | |
from datasets import load_dataset, Dataset | |
from transformers import AutoTokenizer | |
from peft import LoraConfig | |
from trl import GRPOConfig, GRPOTrainer | |
# Load and prep dataset | |
SYSTEM_PROMPT = """ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Classify user search queries as either "Good Google Search Query" or "Bad Google Search Query" based on their likelihood of yielding relevant and helpful results from Google Search. | |
Input: User search query (text string). | |
Output: Classification label: | |
* Good Google Search Query: The query is likely to be effectively answered by Google Search. | |
* Bad Google Search Query: The query is unlikely to be effectively answered by Google Search. Further categorize "Bad" queries into subtypes for better understanding and classifier training (optional but highly recommended): | |
* Chit-Chat/Conversational/Social | |
* Personal/Subjective/Opinion-Based (Un-searchable) | |
* Vague/Ambiguous/Lacking Specificity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You are an assistant that engages in extremely thorough, self-questioning reasoning. Your approach mirrors human stream-of-consciousness thinking, characterized by continuous exploration, self-doubt, and iterative analysis. | |
## Core Principles | |
1. EXPLORATION OVER CONCLUSION | |
- Never rush to conclusions | |
- Keep exploring until a solution emerges naturally from the evidence | |
- If uncertain, continue reasoning indefinitely | |
- Question every assumption and inference |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import multiprocessing | |
manager = multiprocessing.Manager() | |
all_hashes_set = manager.dict() | |
def deduplicate(examples, all_hashes_set): | |
print(len(all_hashes_set)) | |
input_ids = examples['input_ids'] | |
hashes = [ | |
hash(tuple(input_ids[i])) | |
for i in range(len(input_ids)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Train GPT-2 in five minutes -- for free | |
# | |
# ```bash | |
# pip install modal | |
# modal setup | |
# modal run wrapper.py | |
# ``` | |
# | |
# Note that the end-to-end latency the first time is more like 25 minutes: | |
# - five minutes to install Torch (rip) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
from diffusers import FluxPipeline | |
from torch import nn | |
class ModelOffloaderV2: | |
def __init__(self, model: nn.Module, record_stream: bool = False): | |
# move model to pinned memory. keep a model copy in CPU pinned memory. | |
for p in model.parameters(): | |
p.data = p.data.cpu().pin_memory() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require("dotenv").config(); | |
const H = require("highland"); | |
const axios = require("axios"); | |
const fs = require("fs").promises; | |
const exportDirectory = "./export"; | |
const apiUrl = "https://api.intercom.io"; | |
// config axios for the authorized API request | |
const apiClient = axios.create({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var $debugHelper = $debugHelper || {}; | |
$debugHelper = function () { | |
var href = "lib/debugger.css"; | |
var addCss = function () { | |
if (styleStyleIsLoaded(href) === true) { | |
return; | |
} | |
const head = document.head; | |
const link = document.createElement("link"); | |
link.type = "text/css"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# REQUIRES torchao, torch nightly (or torch 2.5) and transformers | |
from transformers import AutoTokenizer, AutoModelForCausalLM, TorchAoConfig | |
from transformers import TextStreamer | |
import torch | |
from tqdm import tqdm | |
import os | |
os.environ["TOKENIZERS_PARALLELISM"] = "false" # To prevent long warnings :) | |
torch.set_float32_matmul_precision('high') |
NewerOlder