Skip to content

Instantly share code, notes, and snippets.

@glinscott
glinscott / perplexity.py
Last active April 18, 2023 01:49
GPU Perplexity for Llama to match llama.cpp implementation
import sys
import torch
device = "cuda"
"""
from transformers import GPT2LMHeadModel, GPT2TokenizerFast
model_id = "gpt2-large"
model = GPT2LMHeadModel.from_pretrained(model_id).to(device)
tokenizer = GPT2TokenizerFast.from_pretrained(model_id)
import sqlite3
from flask import Flask, jsonify, request
app = Flask(__name__)
# Connect to the database
conn = sqlite3.connect("twitter.db")
cursor = conn.cursor()
# Create the tweets table if it doesn't already exist
float sdPlane( vec3 p ) {
return p.y;
}
float sdSphere( in vec3 p, in vec4 s ) {
return length(p-s.xyz) - s.w;
}
float sdBox( vec3 p, vec3 b )
{
@glinscott
glinscott / gist:8814218
Created February 4, 2014 23:02
Eval tuning
#!/usr/bin/python
import math
import numpy
import subprocess
from scipy.optimize import fmin_cg
bestv = 9999999
def sferror(x):
use std::str;
pub struct S2<'self> {
priv iter: std::str::StrCharIterator<'self>,
}
@glinscott
glinscott / analyze.py
Created May 24, 2013 04:59
Analyze fen list with Stockfish
#!/usr/bin/python
import time
import sh
import sys
from multiprocessing import Pool
def get_fens():
with open('pgn_fen') as f:
next = False
for line in f.read().split('\n'):
@glinscott
glinscott / BishopPin.clop
Created March 31, 2013 22:39
Example of CLOP on Stockfish
Script ./clop-cutechess-cli.py
Name BishopPin
IntegerParameter pin_open -100 100
IntegerParameter pin_end -100 100
Processor machine1
Processor machine2
Processor machine3
Replications 2
DrawElo 100
@glinscott
glinscott / gist:3763682
Created September 21, 2012 20:20
Example clop-cutechess-cli.sh for Stockfish tests
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Usage: clop-cutechess-cli.py CPU_ID SEED [PARAM_NAME PARAM_VALUE]...
Run cutechess-cli with CLOP_PARAM(s).
CPU_ID Symbolic name of the CPU or machine that should run the game
SEED Running number for the game to be played
PARAM_NAME Name of a parameter that's being optimized
@glinscott
glinscott / gist:3762136
Created September 21, 2012 15:21
Simple LOS/Elo calculator
#!/usr/bin/python
import math
def los(n1, n0):
pi = [1.0] * (n1 + 3)
pi[0] = 0
for j in xrange(n0 + 1, 0, -1):
for i in xrange(0, n1 + 1):
pi[i + 1] = (pi[i + 1] + pi[i]) * 0.5