Skip to content

Instantly share code, notes, and snippets.

View pszemraj's full-sized avatar

Peter pszemraj

View GitHub Profile
@pszemraj
pszemraj / ul2.py
Created November 15, 2025 00:39
UL2 Data Collator for PyTorch + Transformers
"""
UL2 Data Collator for PyTorch + Transformers
==============================================
Standalone implementation of UL2 (Unified Language Learner) denoising objectives
for encoder-decoder models (T5, UL2, Flan-T5, etc.).
Based on: "Unifying Language Learning Paradigms" (Tay et al., 2022)
https://arxiv.org/abs/2205.05131
@pszemraj
pszemraj / clipboard_helper_xclip.sh
Last active November 18, 2025 16:22
cz() two letter clipboard helper for linux/xclip
# Copy file contents or stdin to clipboard
# Usage: cz [file]
# cz file.txt - copy file to clipboard
# cmd | cz - copy stdin to clipboard
# Fails on: binary files, files >10MB, non-existent files
cz() {
if [ -z "$1" ]; then
xclip -selection clipboard
elif [ -f "$1" ]; then
# Check if it's a text file
@amazingvince
amazingvince / Build_commands.md
Created June 28, 2025 21:15
setup_nano_ocr_vllm

Install essential build tools

sudo apt update sudo apt install -y build-essential gcc g++

Verify installation

gcc --version which gcc

Set the CC environment variable

export CC=/usr/bin/gcc

@gvanem
gvanem / cmatrix.c
Created March 16, 2025 16:54
Matrix clone in C
/*
* "Bleh" -- a "potato-friendly" cmatrix clone.
*
* Screenshot: https://i.imgur.com/dt6RmU7.png
*
* Adapted to Windows from:
* https://www.reddit.com/r/commandline/comments/1jcnyht/bleh_a_potatofriendly_cmatrix_clone/
*/
#include <stdio.h>
#include <stdlib.h>
@pszemraj
pszemraj / domain_classifier_inference.py
Last active September 1, 2024 21:00
inference with nvidia's domain classifier
import logging
import os
import fire
import torch
from datasets import load_dataset
from huggingface_hub import PyTorchModelHubMixin
from torch import nn
from transformers import AutoConfig, AutoModel, AutoTokenizer
import logging
import os
import fire
import torch
from datasets import load_dataset
from huggingface_hub import PyTorchModelHubMixin
from torch import nn
from transformers import AutoConfig, AutoModel, AutoTokenizer
@pszemraj
pszemraj / recursive_model_summary.py
Created July 23, 2024 04:19
print out a summary of a pytorch model
from typing import List, Tuple, Optional, Set
import torch.nn as nn
from transformers import PreTrainedModel
def model_summary(
model: PreTrainedModel, max_depth: int = 4, show_input_size: bool = False
) -> None:
"""
Prints an accurate summary of the model, avoiding double-counting of parameters.
@bartowski1182
bartowski1182 / calibration_datav3.txt
Last active November 19, 2025 03:23
Calibration data provided by Dampf, combines his own efforts on top of Kalomaze's. Used for calibrating GGUF imatrix files
In addition to a significant decrease in hepatic lipid accumulation in the IOE group, which inhibited energy intake by propionate enrichment, hepatic lipids were also significantly reduced in the mice in the IOP group, which was largely enriched with butyrate. Compared with the IOE group, IOP had a stronger regulatory effect on hepatic metabolism and triglyceride metabolism and higher levels of TCA cycle in the host. In addition, butyrate has the ability to promote browning of white adipose tissue (WAT) to brown adipose tissue (BAT).^[@ref39],[@ref40]^ WAT stores energy, whereas BAT uses energy for heating and consequently host energy expenditure increases.^[@ref41],[@ref42]^ However, adipose tissue weight does not change after WAT browning.^[@ref43]^ Therefore, the weight of adipose tissue of mice in the IOP group dominated by butyrate was greater than that of the mice in the IOE group dominated by propionate.
In conclusion ([Figure [7](#fig7){ref-type="fig"}](#fig7){ref-type="fig"}C), the improvement of ob
@pszemraj
pszemraj / USAGE.md
Last active July 28, 2025 09:26
how to use unsloth grad checkpointing

usage

Credit/source: here

how to use unsloth grad checkpointing

steps

To integrate the provided monkey patch for offloading gradient checkpointing into the Hugging Face transformers library, you need to follow these steps:

@pszemraj
pszemraj / datasets_split.py
Created March 12, 2024 07:03
hf datasets train_test_split with stratify_by_column for any type (by tricking it)
import os
import numpy as np
from datasets import ClassLabel, Dataset, DatasetDict
def split_dataset(
dataset: Dataset,
test_size=0.025,