Skip to content

Instantly share code, notes, and snippets.

View 152334H's full-sized avatar
💤

152334H 152334H

💤
View GitHub Profile
@152334H
152334H / move_from_hf_cache.sh
Created February 18, 2024 08:27
move out a model file from the hf cache to an external folder
#!/bin/bash
# Determine the HUBDIR based on the environment variables
if [[ -n "$HF_HUB_CACHE" ]]
then HUBDIR="$HF_HUB_CACHE"
elif [[ -n "$HF_HOME" ]]
then HUBDIR="$HF_HOME/hub"
else HUBDIR="$HOME/.cache/huggingface/hub/"
fi
@152334H
152334H / miqu-upload-hf.py
Created January 30, 2024 16:33
upload miqu ckpt to hf
from transformers import LlamaConfig as LC, LlamaForCausalLM as LLM, LlamaTokenizer as LT
from accelerate import init_empty_weights, load_checkpoint_and_dispatch
import torch
lt = LT.from_pretrained("NousResearch/Llama-2-7b-hf")
c = LC.from_pretrained("NousResearch/Llama-2-70b-hf")
c.max_position_embeddings = 32764
c.rope_theta = 1000000
with init_empty_weights(): m = LLM(c)
m = m.half().eval()
m.requires_grad_(False)
@152334H
152334H / a.patch
Created January 30, 2024 16:31
llama.cpp (fbe7dfa53caff0a7e830b676e6e949917a5c71b4) patch for miqu
diff --git a/gguf-py/scripts/gguf-dump.py b/gguf-py/scripts/gguf-dump.py
index dbf89150..eeea947f 100755
--- a/gguf-py/scripts/gguf-dump.py
+++ b/gguf-py/scripts/gguf-dump.py
@@ -24,6 +24,56 @@ def get_file_host_endian(reader: GGUFReader) -> tuple[str, str]:
file_endian = host_endian
return (host_endian, file_endian)
+from tqdm import tqdm
+import gguf.tensor_mapping as tm
@152334H
152334H / triton_fp16_accum.py
Created January 2, 2024 08:32
Demonstrating the 2x FLOPs in gamer GPUs when FP16 accumulators are used.
from pathlib import Path
savepath = Path('mm')
savepath.mkdir(exist_ok=True)
import torch
import triton
from triton.ops.matmul import matmul as triton_matmul
#matmul = lambda a,b: _matmul.forward(a,b, acc_dtype=torch.float16, allow_tf32=True, output_dtype=torch.float16) # nightly
matmul = lambda a,b: triton_matmul(a,b, torch.float16) # stable
@152334H
152334H / dpo_unsloth.py
Last active December 27, 2023 23:24
neuralhermes with unsloth lora. requires base model to be hacked from mistral -> llama
import torch
from unsloth import FastLlamaModel
from transformers import TrainingArguments
from datasets import load_dataset
from trl import DPOTrainer
model_name = "teknium/OpenHermes-2.5-Mistral-7B"
model_name = "./OpenHermes-2.5-Mistral-7B"
new_model = "NeuralHermes-2.5-Mistral-7B"
@152334H
152334H / config.json
Created December 2, 2023 16:35
openhermes-2.5-mistral-7b config patched to run as a llamaforcausallm (with ctx len 4k)
$ cat OpenHermes-2.5-Mistral-7B/config.json
{
"_name_or_path": "mistralai/Mistral-7B-v0.1",
"architectures": [
"LlamaForCausalLM"
],
"bos_token_id": 1,
"eos_token_id": 32000,
"hidden_act": "silu",
"hidden_size": 4096,
@152334H
152334H / tech_company.py
Created October 1, 2022 03:29
hacked out script made in <1hr to look at the tech interview spreadsheet data a bit better for my purposes
''' NOTE:
0. install pandas and numpy to run this
1. Download the data at https://docs.google.com/spreadsheets/d/1QtC8efWw0mVkGXW4QA9bX4f0nJhGbmFqCfVLSumMZ0I/edit **AS A CSV FILE**
2. **REMOVE THE FIRST LINE FROM THE CSV FILE BEFORE RUNNING THIS**
'''
import pandas as pd
import numpy as np
import re
@152334H
152334H / example.js
Created February 10, 2022 12:29
chrome webview issue
This file has been truncated, but you can view the full file.
const tests = ["data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEA8ADwAAD/4RaQRXhpZgAATU0AKgAAAAgACQEPAAIAAAAGAAAAegEQAAIAAAAUAAAAgAESAAMAAAABAAEAAAEaAAUAAAABAAAAlAEbAAUAAAABAAAAnAEoAAMAAAABAAIAAAExAAIAAAAnAAAApAEyAAIAAAAUAAAAzIdpAAQAAAABAAAA4AAAApxDYW5vbgBDYW5vbiBFT1MgUkVCRUwgVDFpAAAknwAAACcQACSfAAAAJxBBZG9iZSBQaG90b3Nob3AgRWxlbWVudHMgOC4wIE1hY2ludG9zaAAAMjAxMDowNzoyNCAxNTo0MjoxNAAAG4KaAAUAAAABAAACKoKdAAUAAAABAAACMogiAAMAAAABAAEAAIgnAAMAAAABAMgAAJAAAAcAAAAEMDIyMZADAAIAAAAUAAACOpAEAAIAAAAUAAACTpIBAAoAAAABAAACYpICAAUAAAABAAACapIEAAoAAAABAAACcpIFAAUAAAABAAACepIHAAMAAAABAAUAAJIJAAMAAAABABAAAJIKAAUAAAABAAACgpKQAAIAAAADNTEAAJKRAAIAAAADNTEAAJKSAAIAAAADNTEAAKABAAMAAAABAAEAAKACAAQAAAABAABEeaADAAQAAAABAAAQ+6IOAAUAAAABAAACiqIPAAUAAAABAAACkqIQAAMAAAABAAIAAKQBAAMAAAABAAAAAKQCAAMAAAABAAEAAKQDAAMAAAABAAAAAKQGAAMAAAABAAAAAAAAAAAAAAABAAAAPAAAABYAAAABMjAxMDowNzoyMiAxNjoxMjo0MAAyMDEwOjA3OjIyIDE2OjEyOjQwAABaIcsAD0JAAIgXTwAPQkAAAAAAAAAAAQAADikAAAPoAAAAEgAAAAEASIKAAAADfgAwVwAAAAJRAAAABgEDAAMAAAABAAYAAAEaAAUAAAABAAAC6gEbAAUAAAABAAAC8gEoA
@152334H
152334H / GOT_restore.py
Created December 12, 2020 12:17
Labelling the GOT with IDAPython+gdb-gef. Run in IDA with Alt+f7
# -*- coding: utf-8 -*-
import idaapi
import idautils
import idc
import ida_kernwin
'''SAMPLE INPUT:
0x0000555555557f18│+0x0018: 0x00007ffff7f93500 → <seccomp_init+0> endbr64
0x0000555555557f20│+0x0020: 0x00007ffff7da0430 → <__errno_location+0> endbr64
'''
@152334H
152334H / triple_nc.sh
Created August 9, 2020 06:17
Using RsaCtfTool for Håstad's Broadcast Attack
#!/bin/bash
script=/path/to/RsaCtfTool/RsaCtfTool.py
n=()
c=()
echo 'paste all n:'
for i in `seq 0 2`
do read
n[$i]=$REPLY
done
echo 'paste all c:'