N:M sparsity is a structured sparsity pattern where, in every contiguous block of M weights, exactly N weights are forced to be zero. This constraint creates a predictable, regular pattern that can be exploited by specialized hardware, such as NVIDIA's Ampere architecture Sparse Tensor Cores, to perform computation only on the non-zero values, thereby accelerating matrix multiplication. The most common and well-supported format is 2:4 sparsity, where two of every four weights are zero, effectively halving the computational workload and memory traffic for the targeted layers while maintaining near-original model accuracy.
Glossary
N:M Sparsity

What is N:M Sparsity?
N:M sparsity is a hardware-friendly structured sparsity pattern designed to accelerate neural network inference on modern GPUs.
This pattern is typically induced via a pruning process after initial training, where the smallest magnitude weights in each block are set to zero. Unlike unstructured sparsity, which creates irregular patterns difficult to accelerate on general hardware, N:M's structured nature allows for efficient compression and direct hardware support. It is a key model compression technique for inference optimization, particularly in scenarios targeting high-throughput servers or power-constrained edge devices with compatible accelerators, balancing performance gains with minimal accuracy loss.
Key Characteristics of N:M Sparsity
N:M sparsity is a hardware-aligned compression pattern where, in every contiguous block of M weights, exactly N are forced to be zero. This structure enables predictable acceleration on modern tensor cores.
Hardware-Aligned Structure
Unlike unstructured pruning, which creates irregular sparsity, N:M sparsity enforces a deterministic pattern. The most common format is 2:4 sparsity, where in every block of 4 weights, 2 are zero. This 50% sparsity ratio aligns with the Sparse Tensor Core architecture in NVIDIA Ampere GPUs and later, which can skip computations on the zeroed weights and execute the dense matrix multiplication at nearly double the speed of its dense equivalent. This predictable pattern allows for efficient memory access and compute scheduling.
Compression and Memory Efficiency
The structured pattern enables efficient model compression. Instead of storing all weights and a large bitmap of zeros, the non-zero values and their positions within each block can be encoded compactly. For 2:4 sparsity, this typically involves storing:
- Two non-zero FP16 or INT8 values per block.
- A 2-bit index for each value indicating its original position (0-3). This reduces the memory footprint of the weight tensor by nearly 50% compared to its dense FP16 representation, decreasing bandwidth pressure and enabling larger models or batch sizes within fixed memory constraints.
Training and Fine-Tuning Methodology
Achieving high accuracy with N:M sparsity typically requires a prune-and-regrow training cycle, not just one-shot post-training pruning. A common algorithm is:
- Train a dense model to convergence.
- Prune to the N:M pattern by zeroing the N smallest-magnitude weights in each block.
- Regrow connections by updating the remaining non-zero weights via standard backpropagation. Steps 2 and 3 are often repeated iteratively. Frameworks like NVIDIA's Automatic Sparsity (ASP) automate this process, integrating it seamlessly into training pipelines to recover accuracy lost during pruning.
Inference Acceleration
The primary value of N:M sparsity is deterministic inference speedup on supporting hardware. Sparse Tensor Cores are designed to exploit this exact pattern. During computation, the hardware reads the compressed weight format, dynamically unpacks the non-zero values and their indices, and performs a dense multiply-accumulate only on those values. This allows a 2:4 sparse model to deliver up to 2x theoretical throughput for matrix operations compared to its dense counterpart, with minimal overhead for index processing. The speedup is consistent and predictable, unlike the variable benefits of unstructured sparsity.
Relationship to Other Compression Techniques
N:M sparsity is often combined with other compression methods in a model compression stack:
- Quantization: Sparse weights are frequently stored in INT8 format after pruning, combining the compute benefits of sparsity with the memory/bandwidth benefits of lower precision. This is known as sparse quantization.
- Knowledge Distillation: A sparse model can be trained as a student using outputs from a dense teacher to help recover accuracy post-pruning.
- Structured Pruning: N:M is a fine-grained form of structured sparsity. Coarser techniques like channel pruning remove entire filters and can be applied before or after N:M pruning for further compression.
Deployment and Framework Support
Deploying an N:M sparse model requires framework and compiler support to leverage the hardware acceleration. Key tools include:
- PyTorch with
torch.sparseand libraries like NVIDIA'sapexfor training. - TensorRT for optimizing and deploying sparse models on NVIDIA GPUs, using its
sparsitybuilder flag. - NVIDIA's Ampere/Ada/Hopper GPUs with Sparse Tensor Core support. The model must be exported in a framework-recognized sparse format (e.g., a compressed representation). The inference engine then uses specialized kernels to execute the sparse operations efficiently. Without this full-stack support, the sparse model would run at the speed of a dense model, negating the performance benefit.
How N:M Sparsity Works
N:M sparsity is a hardware-aligned model compression technique that enforces a specific pattern of zeros within weight matrices to accelerate inference on supporting accelerators.
N:M sparsity is a structured pruning pattern where, in every contiguous block of M weights, exactly N are forced to be zero. This creates a predictable, regular sparsity format that modern GPU tensor cores, like NVIDIA's Ampere architecture with 2:4 sparsity, can exploit for 2x theoretical speedup in matrix multiplication. The pattern is applied after training via a pruning algorithm that selects the N smallest-magnitude weights in each block to zero out, often followed by fine-tuning to recover accuracy.
This method bridges the efficiency of unstructured pruning, which achieves high compression ratios, with the practical runtime gains of structured pruning, which is hardware-friendly. Unlike irregular sparsity, the N:M pattern allows for dense packing of non-zero values and the use of highly optimized kernels that skip multiplications with known zeros. It is a cornerstone technique for latency-critical deployment on data center GPUs and is being adapted for next-generation edge AI accelerators seeking deterministic performance.
Common N:M Sparsity Patterns
Comparison of structured sparsity patterns commonly implemented in hardware for accelerating neural network inference. These patterns enforce that within every contiguous block of M weights, exactly N are zero.
| Pattern (N:M) | Sparsity Ratio | Primary Hardware Target | Typical Use Case | Software Support | Compression Benefit |
|---|---|---|---|---|---|
2:4 | 50% | NVIDIA Ampere/Ada/Hopper GPUs (Tensor Cores) | General-purpose DNN inference acceleration | ~2x theoretical speedup for eligible ops | |
1:4 | 75% | Research & Custom ASICs/FPGAs | Extreme compression for memory-bound models | ~4x weight memory reduction | |
2:8 | 75% | ARM Cortex-M55/AI accelerators | Ultra-low-power microcontroller inference | High compression for SRAM-constrained devices | |
4:8 | 50% | Google TPUs, Apple Neural Engine | Balanced speedup for mobile/cloud inference | ~2x speedup with simpler control logic | |
1:2 | 50% | Academic research, experimental silicon | Exploring fine-grained structured sparsity | Theoretical 2x speedup | |
N:M (variable) | Configurable | Flexible accelerators (e.g., Versal AI Engines) | Research & adaptive compression strategies | Hardware-dependent |
Hardware & Framework Support
N:M sparsity is a hardware-aligned structured sparsity pattern, most famously implemented as 2:4 sparsity in NVIDIA's Ampere architecture and beyond. Its value is unlocked only through dedicated software libraries and hardware support.
Other Hardware & Research Frontiers
While NVIDIA GPUs are the primary commercial platform, N:M sparsity is a target for other hardware and research:
- AI Accelerators: Many custom AI chips (ASICs) from companies like Groq and Tenstorrent include support for various structured sparsity patterns to maximize data reuse and minimize memory traffic.
- CPU Libraries: Sparse BLAS libraries like Intel oneMKL and Apple Accelerate can leverage N:M sparsity, though without the dedicated circuitry of GPUs, the speedups are more modest and depend on memory bandwidth savings.
- Flexible Patterns: Research explores hardware support for more flexible patterns (e.g., 1:4, 2:8) to balance flexibility and acceleration efficiency.
Software Pruning Tools & Workflow
Creating an N:M sparse model requires specific pruning tools. The typical workflow is:
- Pruning API: Use framework tools (e.g., PyTorch's
prunemodule) to apply magnitude-based pruning with an N:M constraint, often applied iteratively with fine-tuning. - Fine-Tuning: The pruned model is fine-tuned to recover accuracy lost from weight removal.
- Format Conversion: The model's sparse weights are converted to a hardware-compatible format (e.g., metadata + non-zero values).
- Deployment: The model is exported and compiled via an inference runtime like TensorRT that recognizes and accelerates the sparse pattern. Without this final step, the sparsity offers only storage benefits, not computational speedup.
Frequently Asked Questions
N:M sparsity is a structured model compression technique critical for deploying efficient neural networks on hardware accelerators. These questions address its core mechanics, benefits, and implementation.
N:M sparsity is a structured pruning pattern where, in every contiguous block of M weights, exactly N weights are forced to be zero. This creates a predictable, hardware-friendly sparsity format. For example, in a 2:4 sparsity pattern, any block of 4 consecutive weights will contain 2 zeros and 2 non-zero values. The pattern is typically enforced during training or via post-training algorithms, and the resulting sparse weight matrices can be stored and computed efficiently using specialized GPU kernels that skip the zero multiplications, leading to faster inference.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
N:M sparsity is one of several advanced techniques for reducing neural network size and computational cost. These related methods are often combined to achieve extreme efficiency for microcontroller deployment.
Structured Pruning
Structured pruning removes entire structural components from a neural network, such as filters, channels, or layers. Unlike unstructured pruning, it results in a smaller but still dense model, which is natively efficient on standard hardware without requiring specialized sparse kernels.
- Key Difference from N:M: N:M is a fine-grained, block-level sparsity pattern, while structured pruning operates at a coarser, architectural level.
- Hardware Efficiency: The resulting dense matrices maintain regular memory access patterns, making them ideal for CPUs and standard GPU/TPU matrix multiplication units.
- Common Targets: Pruning entire convolutional filters or attention heads in transformers.
Unstructured Pruning
Unstructured pruning removes individual, non-critical weights from a neural network, creating an irregularly sparse model. This can achieve very high sparsity ratios (e.g., 90% zeros) but the random sparsity pattern is not efficiently supported by most hardware.
- Contrast with N:M: N:M imposes a predictable, hardware-friendly pattern (e.g., 2 non-zeros in every block of 4). Unstructured pruning has no such constraint.
- Software Overhead: Executing unstructured sparse models typically requires expensive sparse matrix libraries, often negating theoretical speedups on general-purpose hardware.
- Use Case: Primarily for model size reduction via compression algorithms, with inference acceleration only on specialized sparse accelerators.
Quantization
Quantization reduces the numerical precision of a model's weights and activations, typically from 32-bit floating-point (FP32) to 8-bit integers (INT8) or lower. This directly reduces memory footprint and enables faster integer arithmetic on supporting hardware.
- Synergy with Sparsity: N:M sparsity and quantization are highly complementary. A 2:4 sparse INT8 model combines the memory savings of both techniques.
- Types: Post-Training Quantization (PTQ) converts a pre-trained model; Quantization-Aware Training (QAT) fine-tunes the model to recover accuracy loss from precision reduction.
- Hardware Support: Ubiquitous in modern CPUs (Intel VNNI, ARM DOT) and NPUs, making it a foundational TinyML technique.
Model Compression
Model compression is the overarching field encompassing techniques to reduce neural networks' computational and memory demands. The goal is to enable efficient deployment on resource-constrained devices like microcontrollers, mobile phones, and for scalable server inference.
- Core Techniques: Includes pruning (N:M, structured, unstructured), quantization, knowledge distillation, and low-rank factorization.
- TinyML Focus: Techniques are often combined in a compression pipeline (e.g., prune -> quantize -> compile) to achieve the extreme size reductions required for MCUs.
- Trade-off: The central challenge is balancing compression ratio against model accuracy and generalization capability.
Hardware-Aware Neural Architecture Search (HW-NAS)
Hardware-Aware Neural Architecture Search automates the design of neural network architectures optimized for specific hardware constraints like latency, memory, and energy. It can inherently discover models amenable to techniques like N:M sparsity.
- Objective: Search for a model topology that is both accurate and efficient on a target device (e.g., an ARM Cortex-M4 microcontroller).
- Integration with Sparsity: The search space can include sparsity patterns as a variable, or the search can be performed on a continuous relaxation that is later pruned to an N:M format.
- Outcome: Produces Pareto-optimal models that balance accuracy, size, and speed for a given hardware platform.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us