Skip to content

Instantly share code, notes, and snippets.

View strangeloopcanon's full-sized avatar
💭
thinking

Rohit strangeloopcanon

💭
thinking
View GitHub Profile
import os
import re
import json
import time
import pathlib
from typing import Dict, Any, Tuple
from dotenv import load_dotenv
from jsonschema import validate
from google import genai
import json
import pathlib
import os
import re
from jsonschema import validate
from mlx_lm import load
USE_MLX_LM = os.getenv("MLX_BACKEND", "mlx_lm").lower() == "mlx_lm"
if not USE_MLX_LM:
try:
from mlx_genkit import GenerationConfig, generate as gk_generate
import os
import re
import json
import time
import pathlib
from typing import Dict, Any, Tuple
from jsonschema import validate
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
@strangeloopcanon
strangeloopcanon / skeetsimilarity.py
Last active August 25, 2025 05:34
rl_walter_env
# general_refsim_env.py
# env = load_environment(
# data_dir="training/data",
# schema={
# "articles_path": "articles_rows.csv",
# "article_id": "url",
# "article_title": "title",
# "refs_path": "skeets_rows.csv",
# "ref_group_key": "article_url",
# vf_poker_env.py
# One-file Verifiers Environment for poker action selection.
# Entry point: load_environment(**kwargs) -> vf.Environment
from __future__ import annotations
import json
import math
import random
from typing import Any, Dict, List
import geopandas as gpd
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import pandas as pd
country_name_map = {
"Russia": "Russian Federation",
"United Kingdom": "United Kingdom",
"United States": "United States of America",
"Iran": "Iran (Islamic Republic of)",
# How It Works
# Data Format
# Each “day” has a list of posts; each post is a dict with "prompt" and "answer".
# Instead of an exact textual “answer,” here "answer" is itself a dict containing "likes", "comments", and "quotes". You can add any other engagement metrics you have.
# Reward Calculation
# The interaction_based_reward function simply extracts these integers and calculates a weighted sum as the reward (e.g., likes + 2*comments + 3*quotes).
# You can alter those weights (or the entire reward scheme) however you want.
# GRPO Training
# --- GRPO to teach poker (using llm-poker) ---
from llm_poker.environment import PokerTable
from llm_poker.llm_player import LLMPlayer
from datasets import Dataset
from trl import GRPOConfig, GRPOTrainer
import re
import json
class GRPOPlayer(LLMPlayer):
"""
@strangeloopcanon
strangeloopcanon / sampler.py
Last active February 10, 2025 01:13 — forked from vgel/r1.py
script to run deepseek-r1 with a min-thinking-tokens parameter, replacing </think> with a random continuation string to extend the model's chain of thought
# Updated from voooogel's r1.py sampler. Looks to see if the tokens are of high confidence, and if not forces a resample.
import argparse
import random
import sys
from transformers import AutoModelForCausalLM, AutoTokenizer, DynamicCache
import torch
parser = argparse.ArgumentParser()
parser.add_argument("question", type=str)
# 1. Import Packages
import time
import numpy as np
import pandas as pd
import spacy
from sklearn.feature_extraction.text import CountVectorizer
import os
# 2. AWS Credentials (assuming necessary environment setup for boto3 or S3 access)
os.environ["AWS_ACCESS_KEY_ID"] = "your_aws_access_key_id"