Skip to content

Instantly share code, notes, and snippets.

View KohakuBlueleaf's full-sized avatar

Kohaku-Blueleaf KohakuBlueleaf

View GitHub Profile
@KohakuBlueleaf
KohakuBlueleaf / cloudSettings
Last active April 3, 2021 07:50
Visual Studio Code Settings Sync Gist
{"lastUpload":"2021-04-03T07:50:27.292Z","extensionVersion":"v3.4.3"}
@KohakuBlueleaf
KohakuBlueleaf / README.md
Last active November 26, 2021 14:29
Xmrig benchmark script

Benchmark for Xmrig

This is a python script that run a customized stratum server to specific the algorigthm combinations of 6 CN algos(used in ghostrider) And it calculate the Expected Average Hashrate automatically(All the weights are as same as cpuminer-gr's)

How to run

You need to install python3.8↑ with pip first! And download the script to xmrig's path

linux

@KohakuBlueleaf
KohakuBlueleaf / pytorch_test.py
Created May 19, 2022 18:06
PyTorch basic benchmark
import torch
import numpy as np
import timeit
#could be "cpu" "cuda" "opencl" "mps"...
DEVICE = "mps"
ROUNDS = 500
NUM = (2048, 2048)
# Input for benchmarking
@KohakuBlueleaf
KohakuBlueleaf / sbucaptions_download.py
Created December 22, 2022 07:07
A very simple asyncio downloader for sbucaptions
import os, sys
from time import time_ns
from json import load
from io import BytesIO
import math
from PIL import Image
import asyncio
@KohakuBlueleaf
KohakuBlueleaf / retention.py
Created July 20, 2023 09:36
A simple implementation of retention (from https://arxiv.org/pdf/2307.08621.pdf)
import torch
import torch.nn as nn
import torch.nn.functional as F
from einops import rearrange
def parallel_retention(
q, k, v, # bsz, heads, seq_len, dim
decay_mask = None # heads, seq_len, seq_len
@KohakuBlueleaf
KohakuBlueleaf / danbooru_downloader.py
Created August 29, 2023 05:02
A danbooru crawler for making large datasets
import asyncio
import cv2
import json
import traceback
from concurrent.futures import ProcessPoolExecutor
from pathlib import Path
import numpy as np
from httpx import AsyncClient, HTTPError, Timeout
from tqdm import tqdm
@KohakuBlueleaf
KohakuBlueleaf / decoder.py
Created November 7, 2023 12:08
A transcript of Consistency Decoder
import torch
import torch.nn as nn
import torch.nn.functional as F
class TimestepEmbedding(nn.Module):
def __init__(self, n_time=1024, n_emb=320, n_out=1280) -> None:
super().__init__()
self.emb = nn.Embedding(n_time, n_emb)
@KohakuBlueleaf
KohakuBlueleaf / README.md
Created November 11, 2023 17:55
A standalone scripts to run img generating in stable-diffusion-webui

Sd-WebUI standalone script

just throw the script into the root folder of sd-webui. and then modify the content to what you want to run. And then run it.

If you want to use some extension, just use my implementation as example (to modify the args for extensions)

@KohakuBlueleaf
KohakuBlueleaf / grpo.py
Last active February 17, 2025 03:25
10% gsm-8k acc gain within 15min
## Note
## if use vllm in same gpu, remember to set a low gpu_memory_utilization to avoid OOM
## For larger model please consider to use multi-GPU or CPU offloading
## AnySchedule: https://github.com/KohakuBlueleaf/AnySchedule
## LyCORIS: https://github.com/KohakuBlueleaf/LyCORIS
## Following code can perform reasonable training on Llama-3.2-1B-Instruct model with GSM8K dataset
## With noticable improvement on each reward function
from itertools import chain
import re
@KohakuBlueleaf
KohakuBlueleaf / imm.py
Created March 12, 2025 08:36
A simple implementation of IMM https://arxiv.org/pdf/2503.07565
"""
An Minimal Implementation of IMM (Inductive Moment Matching)
"""
import math
import torch
import torch.nn.functional as F
def compute_mmd_loss_fully_vectorized(