Removing the least important weights or channels to cut model size and computation, and the difference between structured and unstructured pruning.
Intermediate10 min read
Educational draft content that needs expert review before it is used as an academic reference. Specifications, versions and licences change; check the official source. No experimental result is shown here unless it was actually run.
Learning objectives
Define and compute sparsity
Distinguish structured from unstructured pruning and their effect on speed
Explain the role of fine-tuning
Pruning removes parts of the network thought to be unimportant. The simplest method is magnitude pruning, which zeroes the weights with the smallest absolute values by threshold or ratio. Sparsity is the fraction of zero weights.
Unstructured pruning removes individual weights and yields sparse matrices; it saves space if stored in a sparse format but speeds up execution only if the hardware and kernels support sparsity. Structured pruning removes whole neurons, channels or heads so dimensions really shrink and execution speeds up on ordinary hardware, but accuracy loss can be larger.
Pruning is usually followed by fine-tuning to recover accuracy and may be repeated in stages. The “lottery ticket” hypothesis suggests that small sub-networks exist that train as well; it is an active research topic.
Diagram
Schematic, not a real network.
Terminology (with Arabic equivalents)
Sparsity
التخلخل
Magnitude pruning
التقليم بالمقدار
Structured pruning
التقليم المهيكل
Fine-tuning
إعادة تدريب دقيقة
Lottery ticket hypothesis
فرضية تذكرة اليانصيب
Worked example
A weight matrix of 1000 elements with 70% pruned: 700 zeros and 300 non-zeros. If stored as an ordinary dense matrix the size stays 1000 elements; the saving is realised only in a sparse format (values + indices).
Code snippet
PythonNumPy, illustrative
import numpy as np
def magnitude_prune(w, sparsity):
k = int(w.size * sparsity)
thr = np.partition(np.abs(w).ravel(), k)[k]
mask = np.abs(w) >= thr
return w * mask
w = np.random.default_rng(0).normal(size=(10, 100))
wp = magnitude_prune(w, 0.7)
print('sparsity', float((wp == 0).mean()))
An illustrative snippet that was not executed in the lab environment; check library versions in their official documentation before use.
Check yourself
Unstructured pruning speeds up execution on ordinary hardware:
Always
Only if the hardware and kernels support sparsity
Never
Only on phones
Answer and explanation
Only if the hardware and kernels support sparsity — Scattered zeros save no time without specialised kernels.
What does structured pruning remove?
Scattered weights
Whole channels or neurons
Training data
Layer names
Answer and explanation
Whole channels or neurons — It actually shrinks the dimensions.
What is sparsity?
The number of layers
The fraction of zero weights
Training speed
Batch size
Answer and explanation
The fraction of zero weights — The ratio of zeros to all weights.
Blalock et al. (2020). What is the State of Neural Network Pruning? MLSys 2020Not verified
Image and audio processing in the experiments runs inside your browser. Your images and audio are never uploaded and conversations are not stored. Privacy
Assistant Professor of Artificial Intelligence and Deep Learning
University of Al-Qadisiyah
About
Researcher and academic specialising in artificial intelligence (AI), deep learning, computer vision and natural language processing (NLP). The “Deep Learning in Arabic” project aims to enrich Arabic scientific and technical content with sound, free references and software for researchers and learners across the Arab world.
Edge AI Assistant
I am the Edge AI Assistant. Ask about a concept, technology, board or project and I will answer from the lab content with links.
Edge AI Assistant
Local Database Mode
Answers from the lab knowledge base only, without sending your question to any external party. Conversations are not stored.
Smart assistant
Answers from the site’s content
The assistant can make mistakes, so check the attached sources.
Welcome! I am Dr. Alaa Taima, and this is my smart assistant on “Deep Learning in Arabic”. Ask it about any term or topic in artificial intelligence, and it will answer from the site's content with links to the sources.
DL Bot
Your smart assistant · Connecting…
Enter to send · Shift + Enter for a new line · The assistant can make mistakes, so check the sources.