techlist.io

Gpu Kernels

3 posts

Cloudflare2026-04-173 min readCurated summary

Unweight: how we compressed an LLM 22% without sacrificing quality

Unweight is Cloudflare’s lossless compression system for LLM weights, reducing model size by 15–22% while preserving bit-exact outputs. It targets the memory-bandwidth bottleneck in GPU inference by compressing weights in HBM and decompressing them directly into fast on-chip memory before tensor-core computation. On Llama-3.1-8B, the approach saves roughly 3 GB of VRAM and enables more models to run per GPU. ## The GPU Memory Bottleneck - LLM inference is often limited by memory bandwidth rather than computation. - Each generated token requires reading the model’s weights from GPU high-bandwidth memory (HBM). - NVIDIA H100 tensor cores can process data far faster than HBM can supply it. - Smaller weights reduce the amount of data transferred across the memory bus. - Decompression must be carefully integrated: if it adds latency that cannot overlap with matrix multiplication, token generation becomes slower. ## Why Lossless Compression Matters - Quantization commonly converts 16-bit values into 8- or 4-bit integers. - Because quantization is lossy, it can change model behavior and response quality unpredictably. - Unweight instead preserves exact outputs and does not require specialized hardware. - Existing systems were unsuitable because they focused on CPU decompression, custom FPGA hardware, or consumer GPUs rather than Hopper-generation GPUs and production inference. ## Compressing BF16 Weights - BF16 values contain: - A sign bit - An 8-bit exponent - A 7-bit mantissa - Sign and mantissa values appear largely random and are difficult to compress. - Exponents are highly predictable: the 16 most common exponent values account for more than 99% of weights in a typical layer. - Unweight applies Huffman coding to exponent bytes while leaving sign and mantissa bits unchanged. - Rare exponents are handled by storing an entire row of 64 weights verbatim, avoiding per-element branching during decoding. ## Selective Compression of Model Layers - Unweight compresses the MLP gate, up, and down projection matrices. - These matrices represent roughly two-thirds of model parameters and generate substantial memory traffic during decoding. - Attention weights, embeddings, and layer norms remain uncompressed. - The exponent compression produces about 30% savings in the targeted streams and approximately 20% reduction in total MLP weight size. - Overall model-size reductions reach 15–22%. ## Direct GPU Decompression - Model weights normally reside in large but slower HBM and are staged into small, fast shared memory before computation. - Conventional approaches decompress full matrices back into HBM and then run standard matrix multiplication, creating additional memory traffic. - Unweight decompresses weights in shared memory and feeds them directly to tensor cores. - Different execution strategies are used depending on the weight matrix and batch size. - An autotuner selects the fastest strategy for each workload. ## Results and Availability - Tests on Llama-3.1-8B achieved: - Around 30% compression for MLP weights - 15–22% reduction in total model size - Approximately 3 GB of VRAM savings - The savings allow more models to fit on each GPU, potentially reducing inference cost and improving global deployment coverage. - Cloudflare is publishing a technical paper and open-sourcing the GPU kernels. Unweight demonstrates that lossless, inference-time compression can improve GPU utilization without changing model behavior. The practical recommendation is to compress the portions of a model that dominate memory traffic while integrating decoding directly into the GPU execution path.

OpenAI2019-04-223 min readCurated summary

Generative modeling with sparse transformers

# Generative Modeling with Sparse Transformers OpenAI's Sparse Transformer is a deep neural network that sets new benchmarks for predicting the next element in a sequence, whether text, images, or audio. By replacing standard self-attention with a sparse variant that scales as O(N√N) instead of O(N²), the model handles sequences roughly 30 times longer than previously feasible, reaching tens of thousands of elements across hundreds of layers. The authors position this as a step toward modeling the long-range, subtle dependencies that complex data like images and audio demand. ## Why Dense Attention Becomes a Bottleneck - In Transformers, every output element attends to every input element, requiring an N×N attention matrix for each layer and attention head. - For high-dimensional data, this memory cost grows quickly. A deep 64-layer, 4-head Transformer needs about 9.6 GB to store attention matrices for a 32×32 CIFAR-10 image, and about 154 GB for a 64×64 ImageNet image. Typical deep learning GPUs have 12–32 GB. - Recomputing attention matrices from checkpoints during backpropagation keeps the dominant memory cost independent of depth, which allows training networks up to 128 layers deep. These deeper models outperformed shallower ones on benchmarks like CIFAR-10. - Training at this depth required changes to the order of operations within the Transformer block and a modified initialization scheme. ## Sparse Attention Patterns - Each output position attends only to a subset of input positions, ideally about √N elements instead of N, reducing complexity to O(N√N). - Visualizing learned attention in deep image models showed many heads with structured, sparse patterns, though some layers attended across the whole image. - To preserve global reach, the authors use a two-dimensional factorization in which any position can reach any other in two sparse steps: - **Strided attention** has each position attend to its row and column, suited to images. - **Fixed attention** attends to a fixed set of column positions and all later elements, suited to data without a 2D structure, such as text. ## Results - **CIFAR-10 (bits per dim):** The 59M-parameter Sparse Transformer reached 2.80, beating PixelCNN++ (2.92), Image Transformer (2.90), and PixelSNAIL (2.85). - **Enwik8 (bits per byte):** The 95M-parameter model reached 0.99, matching the 277M-parameter Transformer-XL and outperforming the 88M version (1.03). - **ImageNet 64×64 (bits per dim):** The 152M-parameter model reached 3.44, improving on SPN 150M (3.52) and Gated PixelCNN (3.57). - Sparse attention also achieved lower loss than full attention while running significantly faster, which the authors suggest may reflect a useful inductive bias or an optimization issue with dense attention. ## Generation Capabilities - **Images:** Models trained on 64×64 ImageNet produce completions that show coherent global structure. Unconditional samples at temperature 1.0 reflect the full learned distribution, so some look unusual. - **Raw audio:** By changing the position embeddings, the same architecture generates raw waveforms. The model produced 65,000-sample sequences, about 5 seconds of classical music. - **Open-source kernels:** The team released block-sparse GPU kernels and example sparse attention functions, since implementing sparse attention by slicing query and key matrices is otherwise cumbersome. ## Limitations and Future Directions - The attention patterns introduced are preliminary. The authors see learned sparsity patterns as a promising direction for future architectures. - Autoregressive generation remains impractical for very high-resolution images or video. The optimized attention primitives may still be useful when combined with multi-scale approaches.

OpenAI2017-12-053 min readCurated summary

Block-sparse GPU kernels

# Block-Sparse GPU Kernels for Neural Networks OpenAI releases highly optimized GPU kernels for neural networks whose weight matrices are block-sparse, meaning most blocks are exactly zero. Depending on the sparsity level, these kernels run orders of magnitude faster than cuBLAS or cuSPARSE, and the authors use them to reach state-of-the-art results in text sentiment analysis and in generative modeling of text and images. The post presents the kernels as a promising but not definitive foundation, and invites the community to explore the architectures they make practical. ## Why Sparse Weights Matter - Sparse weight matrices contain a large number of entries exactly equal to zero. - Matrix multiplication and convolution with block-sparse weights cost only in proportion to the number of non-zero blocks. - For a fixed parameter and compute budget, sparsity allows much wider and deeper networks, such as LSTMs with tens of thousands of hidden units, while the largest LSTMs trained at the time had only thousands. ## The Kernels - They support block-sparse weights in both fully connected and convolutional layers. - In convolutional layers, sparsity applies to input and output feature dimensions, while spatial connectivity is unchanged. - Sparsity is defined per block, with kernels optimized for 8x8, 16x16, and 32x32 blocks. The block-level pattern is fully configurable. - Skipped zero blocks mean compute and parameter storage scale with the number of non-zero weights rather than the number of input and output features. - Benchmarks on a Titan X Pascal GPU (CUDA 8), with 12288 hidden units, 32x32 blocks, and minibatch size 32, show speed-ups over cuBLAS at various sparsity levels. Speed-ups over cuSPARSE were even larger. ## Using the Kernels - The post includes a TensorFlow example that creates a random block-level sparsity pattern, builds a `BlocksparseMatMul` object with a chosen block size, initializes block-sparse weights from `bsmm.w_shape`, and runs the multiplication as a graph operation. ## Small-World LSTMs - Small-world graphs connect any two nodes through a small number of steps, even at very large scale, and brain connectivity shows similar properties. - The authors hypothesized that small-world sparse connectivity keeps information propagating quickly despite high sparsity. - Using this structure, they trained LSTMs with nearly 20,000 hidden units, about 5 times wider than a dense network with similar parameter counts, improving results on text generation and semi-supervised sentiment classification. ## Results - **Sentiment:** Using the setup from their sentiment neuron experiment, the sparse model beat the dense model on all sentiment datasets. On the document-level IMDB dataset, error dropped from 5.91% (Miyato et al., 2016) to 5.01%, a state-of-the-art result. Previous results had only performed best on shorter sentence-level datasets. - **Text compression:** With equal parameter counts (about 100 million), bits-per-character fell from 1.059 to 1.048 using sparse, wide LSTMs. - **Images:** Replacing regular 2D convolutions with sparse kernels in PixelCNN++ on CIFAR-10, while deepening the network and keeping other hyperparameters fixed, reduced bits-per-dimension from 2.92 to 2.90, a new state of the art on that dataset. ## Open Research Directions - **Inference speed-up:** How much wall-clock speed-up can pruning after training achieve when combined with these kernels? - **Learning sparsity structure:** Can gradients learn the sparsity pattern as well as the weights, similar to how biological brains partly determine connectivity during development? Related work includes learning block-sparse RNNs and L0 regularization. - **Application domains:** Sparse layers allow huge weight matrices at the same parameter count and compute cost as smaller dense models. Which domains will benefit most?