Skip to content

Instantly share code, notes, and snippets.

View pszemraj's full-sized avatar

Peter pszemraj

View GitHub Profile
sudo apt-get update && sudo apt upgrade -y
sudo apt-get install -y poppler-utils ttf-mscorefonts-installer msttcorefonts fonts-crosextra-caladea fonts-crosextra-carlito gsfonts lcdf-typetools
git clone https://github.com/allenai/olmocr.git --depth 1
cd olmocr
pip install -q ninja
pip install -e .[gpu] --find-links https://flashinfer.ai/whl/cu124/torch2.4/flashinfer/
# clean up
pip cache purge && apt autoremove -y
@pszemraj
pszemraj / layernorm_scaling.py
Last active March 26, 2025 03:08
LayerNorm Scaling implementation to mitigate the Curse of Depth in LLMs.
import math
import torch
import torch.nn as nn
import torch.nn.functional as F
class LayerNormScaling(nn.Module):
"""
LayerNorm Scaling implementation to mitigate the Curse of Depth in LLMs.
Model Average CR⬆️ AGIEval Mean (Min, Max) AGIEval CR MMLU-Pro Mean (Min, Max) MMLU-Pro CR Math Mean (Min, Max) Math CR #Params (B)
meta-llama/Llama-3.1-70B-Instruct 72.39 72.43, (65.34, 74.66) 81.79 66.63, (55.16, 70.68) 73.19 65.88, (64.58, 67.86) 62.18 0
mistralai/Mistral-Large-Instruct-2407 71.93 68.78, (61.41, 74.49) 75.77 65.1, (50.28, 69.23) 72.31 71.04, (69.66, 72.72) 67.71 0
meta-llama/Meta-Llama-3-70B-Instruct 69.11 69.71, (60.77, 71.2) 83.13 58.75, (49.3, 63.16) 75.24 51.29, (49.66, 54.2) 48.96 0
01-ai/Yi-1.5-34B-Chat 58.43 63.89
@pszemraj
pszemraj / tensorboard_inspect.py
Last active March 11, 2025 00:33
CLI utility to quickly inspect the latest scalar values from TensorBoard logs.
#!/usr/bin/env python
"""
CLI utility to quickly inspect the latest scalar values from TensorBoard logs.
Dependencies:
pip install tbparse pandas fire tqdm
Usage:
python tensorboard_inspect.py --logdir ./path/to/logs
"""

bash/zsh util for readerlm-v2

Warning

Using this will send the data of your (public URL) to jina ai, and the license for readerlm-v2 is cc-by-nc

Here's the improved version of your smart_curl function that better handles filename extraction and works in Zsh:

function smart_curl() {
@pszemraj
pszemraj / rag_search_localllama.py
Last active January 22, 2025 17:18
basic rag search system for top_k posts w gte-modernbert-base
import logging
from typing import Dict, List
import faiss
import numpy as np
from datasets import load_dataset
from sentence_transformers import CrossEncoder, SentenceTransformer
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
@pszemraj
pszemraj / push_reddit_articshift.py
Last active June 30, 2025 03:29
util script for loading, basic processing, converting reddit posts -> hf dataset
"""
util script for loading, basic processing, converting reddit posts -> hf dataset
https://arctic-shift.photon-reddit.com/download-tool
"""
import pandas as pd
from datasets import Dataset, load_dataset
src = "./r_LocalLLaMA_posts.jsonl" # update with relevant path
df = pd.read_json(src, lines=True).convert_dtypes()
@pszemraj
pszemraj / cautious_adamw.py
Last active November 27, 2024 03:53
Implements Cautious AdamW optimizer by subclassing AdamW https://github.com/kyleliang919/C-Optim
import math
import torch
from torch.optim.adamw import AdamW
class CautiousAdamW(AdamW):
"""
Implements Cautious AdamW optimizer by subclassing AdamW.
All hyperparameters remain identical to AdamW.
@pszemraj
pszemraj / chibihash64.py
Created November 18, 2024 16:38
Compute the 64-bit hash of the input bytes object using the chibihash64 algorithm.
def chibihash64__load64le(p, offset=0):
"""Load 8 bytes from the input bytes object as a little-endian 64-bit integer."""
return int.from_bytes(p[offset : offset + 8], "little", signed=False)
def chibihash64(key, seed=0):
"""
Compute the 64-bit hash of the input bytes object using the chibihash64 algorithm.
Parameters: