Skip to content

Instantly share code, notes, and snippets.

View proger's full-sized avatar
🎯
Focusing

Volodymyr Kyrylov proger

🎯
Focusing
View GitHub Profile
@proger
proger / abv.py
Last active April 26, 2024 07:53
# prompt: https://twitter.com/francoisfleuret/status/1783479122418716805
import os
os.environ['TORCH_LOGS'] = 'output_code' # shows all the bmms
import torch
torch.set_float32_matmul_precision('high')
N, T, D, U, C = 3, 128, 5, 32, 32 # batch, time, heads, head_dim, dim
S = T
A = torch.randn(N, T, D, U) / U**0.5
@proger
proger / xor.py
Last active April 22, 2024 13:36
tensor network that can learn xor
#%%
import torch
import torch.nn as nn
import torch.nn.functional as F
import matplotlib.pyplot as plt
X = torch.tensor([[0, 0], [0, 1], [1, 0], [1, 1]]).float()
y = torch.logical_xor(X[:, 0], X[:, 1]).float()
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
"""
# download the model
huggingface-cli download google/gemma-2b-it
# run the server (set the model name here and in the prompt function below)
# notice --kv_cache_dtype fp8_e5m2
docker run --gpus all -p 8000:8000 -e HF_HOME=/hf -e CUDA_VISIBLE_DEVICES=1 -v ~/.cache/huggingface:/hf vllm/vllm-openai:latest:latest --host 0.0.0.0 --model google/gemma-2b-it --kv-cache-dtype fp8_e5m2
# ask one question
echo 'what is python?' | python -m prompt | jq -r '.choices[].text'
import torch
def binary(digits: int) -> torch.IntTensor:
"Make a basis of powers of two of dimension `digits`, lowest bits to the right"
return 1 << torch.arange(digits).flip(-1)
def sbt(x: torch.IntTensor) -> torch.IntTensor:
"""Slow Binary Transform.
@proger
proger / decode.py
Last active January 20, 2024 19:46
import argparse
from itertools import islice
import logging
from pathlib import Path
import evaluate
from datasets import load_dataset
from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
from transformers.generation import BeamSearchDecoderOnlyOutput
from peft import PeftModel
@proger
proger / scan3.ptx
Last active December 31, 2023 16:59
scan3 PTX from nanokitchen. Why is it numerically unstable? Is that the gate multiplication? Something else?
//
// Generated by LLVM NVPTX Back-End
// See scan3 in https://github.com/proger/nanokitchen/blob/main/triscan.py
//
.version 8.1
.target sm_86
.address_size 64
// .globl scan3_0d1d2d
import sys
import requests
import json
context = """[INST] They are planning to host a party next weekend. [/INST] Вони планують провести вечірку наступного вікенду.
[INST] I enjoy swimming in the ocean and feeling the salty breeze. [/INST] Мені подобається плавати в океані та відчувати солоний вітер.
[INST]"""
# docker run --gpus all -p 8000:8000 -e HF_HOME=/hf -e CUDA_VISIBLE_DEVICES=1 -v ~/.cache/huggingface:/hf ghcr.io/mistralai/mistral-src/vllm:latest --host 0.0.0.0 --model mistralai/Mistral-7B-v0.1
def prompt(input, url="http://localhost:8000/v1/completions"):
@proger
proger / mkm.py
Last active December 7, 2023 13:37
import torch
from torch import nn
from torch.utils.data import DataLoader, TensorDataset
import gzip
import numpy as np
torch.set_float32_matmul_precision('high')
def read(filename):
import gzip
import numpy as np
from sklearn.cluster import MiniBatchKMeans
def read(filename):
with gzip.open(filename, 'rb') as file:
compressed_data = file.read()
data = np.frombuffer(compressed_data, dtype=np.float32)
return data