Skip to content

Instantly share code, notes, and snippets.

View lapp0's full-sized avatar

Andrew Lapp lapp0

View GitHub Profile
from datasets import Dataset, load_from_disk
from transformers import TrainingArguments
from transformers.trainer_utils import EvalLoopOutput
from unsloth import FastLanguageModel
import random
from huggingface_hub import create_repo
from scipy.spatial.distance import cosine
from sentence_transformers import SentenceTransformer
import statistics
@lapp0
lapp0 / gist:ee9e1035945a838868805e941f73bb25
Created March 31, 2024 20:26
Regex Pattern for Dates between 0001-01-01 and 9999-12-31, Accounting for All Leap Year Rules
# Huge Pattern
`0(0(0([1235679]-(0(2-(0[1-9]|1\\d|2[0-8])|[13578]-(0[1-9]|3[01]|[12]\\d)|[469]-(0[1-9]|30|[12]\\d))|1(1-(0[1-9]|30|[12]\\d)|[02]-(0[1-9]|3[01]|[12]\\d)))|[48]-(0(2-(0[1-9]|[12]\\d)|[13578]-(0[1-9]|3[01]|[12]\\d)|[469]-(0[1-9]|30|[12]\\d))|1(1-(0[1-9]|30|[12]\\d)|[02]-(0[1-9]|3[01]|[12]\\d))))|[13579]([01345789]-(0(2-(0[1-9]|1\\d|2[0-8])|[13578]-(0[1-9]|3[01]|[12]\\d)|[469]-(0[1-9]|30|[12]\\d))|1(1-(0[1-9]|30|[12]\\d)|[02]-(0[1-9]|3[01]|[12]\\d)))|[26]-(0(2-(0[1-9]|[12]\\d)|[13578]-(0[1-9]|3[01]|[12]\\d)|[469]-(0[1-9]|30|[12]\\d))|1(1-(0[1-9]|30|[12]\\d)|[02]-(0[1-9]|3[01]|[12]\\d))))|[2468]([048]-(0(2-(0[1-9]|[12]\\d)|[13578]-(0[1-9]|3[01]|[12]\\d)|[469]-(0[1-9]|30|[12]\\d))|1(1-(0[1-9]|30|[12]\\d)|[02]-(0[1-9]|3[01]|[12]\\d)))|[1235679]-(0(2-(0[1-9]|1\\d|2[0-8])|[13578]-(0[1-9]|3[01]|[12]\\d)|[469]-(0[1-9]|30|[12]\\d))|1(1-(0[1-9]|30|[12]\\d)|[02]-(0[1-9]|3[01]|[12]\\d)))))|[1235679](0([0-35679]-(0(2-(0[1-9]|1\\d|2[0-8])|[13578]-(0[1-9]|3[01]|[12]\\d)|[469]-(0[1-9]|30|[12]\\d))|1(1-(0[1-9]|30
2024-01-19T13:51:10.557605895-08:00 (RayWorkerVllm pid=3381) (28750, 28725, 28770, 28725, 28782, 28725, 28787, 28725, 28740, 28740, 28725, 28740, 28770, 28725, 28740, 28787, 28725, 28740, 28774, 28725, 28750, 28770, 28725, 28750, 28774, 13, 13, 13, 13)
2024-01-19T13:51:10.557632935-08:00 (RayWorkerVllm pid=3381) (28750, 28725, 28770, 28725, 28782, 28725, 28787, 28725, 28740, 28740, 28725, 28740, 28770, 28725, 28740, 28787, 28725, 28740, 28774, 28725, 28750, 28770, 28725, 28750, 28774, 13, 13, 13)
2024-01-19T13:51:10.557642055-08:00 (RayWorkerVllm pid=3381) (28750, 28725, 28770, 28725, 28782, 28725, 28787, 28725, 28740, 28740, 28725, 28740, 28770, 28725, 28740, 28787, 28725, 28740, 28774, 28725, 28750, 28770, 28725, 28750, 28774, 13, 13)
2024-01-19T13:51:10.557645405-08:00 (RayWorkerVllm pid=3381) (28750, 28725, 28770, 28725, 28782, 28725, 28787, 28725, 28740, 28740, 28725, 28740, 28770, 28725, 28740, 28787, 28725, 28740, 28774, 28725, 28750, 28770, 28725, 28750, 28774, 13)
2024-01-19T13:51:10.557681445-08:00
import ray
import torch
import time
import random
import numpy as np
import os
# Initialize Ray
ray.init()
@lapp0
lapp0 / calc_vram.py
Last active March 2, 2024 23:18
LLM Memory Requirement Calculator Script (Full Finetune and Inference)
import urllib.request
import json
def bits_to_gb(bits):
return bits / (8 * 1024**3)
def calculate_train_vram_requirements(
batch_size, seq_len, params, precision, num_layers, num_attn_heads, hidden_size, **ignored
libfreenect2 = with pkgs; stdenv.mkDerivation rec {
pname = "freenect2";
version = "0.2.1";
src = fetchFromGitHub {
owner = "OpenKinect";
repo = "libfreenect2";
rev = "v${version}";
sha256 = "sha256-v+NQiR9LTQOwr1kgVpGmFSSemiPw4rmdQE/B6ycoLpU=";
};