Skip to content

Instantly share code, notes, and snippets.

"""
Benchmark for MSE observer grid search. (results at bottom)
Profiles the grid search that finds optimal min/max ranges for quantization.
The hot path is `_calculate_error` (called once per shrink step: default 20
steps), which runs `calculate_qparams` + `fake_quantize` on the full weight
tensor each time.
Usage:
python benchmarks/bench_mse_observer.py [--device cuda] [--rows 4096] [--cols 4096]
@HDCharles
HDCharles / README.md
Last active September 11, 2026 18:49
GPTQ memory benchmarks and parity diagnostics

GPTQ Memory Characteristics

This document compares GPTQ GPU memory usage on main and the batched GPTQ PR, with and without Hessian offloading. Measurements were collected on an NVIDIA H100 using torch.cuda.max_memory_allocated() and torch.cuda.max_memory_reserved(). Process RSS was additionally sampled for the MoE experiment to show the CPU cost of Hessian offloading.

These are memory-focused, reduced-calibration experiments. Both used eight synthetic calibration samples of 256 tokens rather than the 512 samples of 2048

@HDCharles
HDCharles / repro_w2a8_large_m.py
Last active August 11, 2026 18:37
Humming SM90 bug repros: odd-bit WNA8 GEMM crash (Mode 2) and W6A8 cuFuncSetAttribute overflow at shape_m 25-32 (Mode 3)
"""Repro: W2A8 humming GEMM produces NaN at large shape_m on SM90.
The NaN only appears at shape_m >= some threshold (around 16384 in vllm's
profiling run). Smaller batch sizes used during CUDA graph capture (1-512)
pass fine, which is why earlier repros missed this.
"""
import subprocess
import sys
@HDCharles
HDCharles / gist:dc5219c44d41f82375de08eb3559b35e
Last active August 13, 2026 14:05
cast_to_fp4_benchmarks.py
import gc
import time
import torch
import triton
import triton.language as tl
SIZE = 844_000_000_0
device = "cuda:0" if torch.cuda.is_available() else "cpu"
N_RUNS = 200
@HDCharles
HDCharles / repro.py
Created July 29, 2026 20:40
repro for humming issues
#!/usr/bin/env python3
"""Repro: humming GEMM produces NaN with quantized input activations.
Run: python tests/repro_int8_nan.py
Sweeps all combinations of weight bit width (3-8), input quantization
(int8, int4, bf16), batch size, and shape. int4 inputs require weight
nbits < 4 and SM >= 80.
"""
import json
@HDCharles
HDCharles / gist:363817a9eeda410f7fef15a3a5291e1c
Created July 21, 2026 20:38
benchmark GPTQ implementations
"""
Benchmark comparing eager vs compiled vs Triton GPTQ quantize_weight.
All three implementations are fully inlined:
- quantize_weight_eager: the original loop from main
- quantize_weight_compiled: the torch.compiled block path from this branch
- quantize_weight_triton: hand-written Triton kernel for the block quantization
Generates random weights and a synthetic positive-definite Hessian,
then times all three.
import torch
from compressed_tensors.offload import init_dist
from compressed_tensors.quantization.quant_scheme import (
FP8_BLOCK,
NVFP4,
QuantizationScheme,
)
from datasets import load_dataset
from transformers import AutoTokenizer, InklingForConditionalGeneration
import gc
import time
import torch
import triton
import triton.language as tl
SIZE = 844_000_000
device = "cuda:0" if torch.cuda.is_available() else "cpu"
N_RUNS = 20
"""Minimal repro: packed integer zero-point failures for uint7/uint8.
The humming kernel handles integer ZPs correctly when tensors are
unpacked. But the packed path (packed=True in prepare_humming_weight
and prepare_humming_zero_point) — which is what vLLM uses when loading
pack-quantized checkpoints — produces wrong results for num_bits > 6.
This causes catastrophic accuracy loss for W7A16asym and W7A8asym
models (20M word perplexity vs ~10 for symmetric).
"""
@HDCharles
HDCharles / hf_download_model-py.log
Last active July 8, 2026 03:03
download_analysis
Command: python hf_download_model.py
Loading data from hf_quant_dataset.csv (use --retry for failed rows, --fetch-all to re-fetch everything)
Dataset: 452 quantized models with known base date and model size
Hubs: {'RedHatAI': 379, 'nvidia': 73}
Formats: {'fp8': 180, 'w4a16': 75, 'w8a8': 74, 'nvfp4': 65, 'w8a16': 33, 'deepsparse': 8, 'int4': 6, 'gguf': 6, 'unknown': 2, 'gptq': 1, 'fp4-qad': 1, 'fp4-eagle3': 1}
Prior variant exists: {1: 237, 0: 215}
======================================================================
Model 1: All models — hub, format, size, base popularity