Skip to content

Instantly share code, notes, and snippets.

View lapp0's full-sized avatar

Andrew Lapp lapp0

View GitHub Profile
import os
import sys
with open(sys.argv[0]) as f:
code = f.read() # read the code of this file ASAP, for logging
import uuid
import glob
import time
import contextlib
from dataclasses import dataclass
from typing import Optional
Running pytorch 2.6.0.dev20241126+cu124 compiled for CUDA 12.4
nvidia-smi:
Fri Nov 29 00:54:16 2024
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.76 Driver Version: 550.76 CUDA Version: 12.4 |
|-----------------------------------------+------------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+========================+======================|

Remove evil parts of answer.

Code

import outlines

qwen_model = outlines.models.transformers("Qwen/Qwen2.5-14B-Instruct", model_kwargs=dict(load_in_8bit=True))


def ask_non_evil_question(prompt, pattern, model=qwen_model, max_tokens=100):
import random
import collections
def trial(first_to=2):
flips = [random.choice([True, False]) for _ in range(100)]
alice_flip_checks = flips
bob_flip_checks = [flips[i] for i in range(1, len(flips), 2)] + [flips[i] for i in range(0, len(flips), 2)]
# get second_head
try:
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 September 18, 2024 01:54
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=";
};