A library to make neural networks lighter and faster with fastai
Project description
Features • Installation • Tutorials • Community • Citing • License
Overview
fasterAI is a PyTorch-based library that makes neural networks smaller, faster, and more efficient through state-of-the-art compression techniques. The library provides simple but powerful implementations of pruning, knowledge distillation, quantization, and other network optimization methods that can be applied with just a few lines of code.
Why compress your models with fasterai?
- Reduce model size by up to 90% with minimal accuracy loss
- Speed up inference for deployment on edge devices
- Lower energy consumption for more sustainable AI
- Simplify architectures while maintaining performance
Features
1. Sparsification
Make your model sparse by replacing selected weights with zeros using Sparsifier or SparsifyCallback.
| Parameter | Description | Options |
|---|---|---|
sparsity |
Percentage of weights to zero out | 0-100% |
granularity |
Level at which to apply sparsity | 'weight', 'vector', 'kernel', 'filter' |
context |
Scope of sparsification | 'local' (per layer), 'global' (whole model) |
criteria |
Method to select weights | 'magnitude', 'movement', 'gradient', etc. |
schedule |
How sparsity evolves during training | 'one_shot', 'iterative', 'gradual', etc. |
2. Pruning
Remove zero-weight nodes from your network structure using Pruner or PruneCallback.
| Parameter | Description | Options |
|---|---|---|
pruning_ratio |
Percentage of weights to remove | 0-100% |
context |
Scope of sparsification | 'local' (per layer), 'global' (whole model) |
criteria |
Method to select weights | 'magnitude', 'movement', 'gradient', etc. |
schedule |
How sparsity evolves during training | 'one_shot', 'iterative', 'gradual', etc. |
3. Knowledge Distillation
Transfer knowledge from a large teacher to a smaller student using KnowledgeDistillationCallback.
| Parameter | Description | Options |
|---|---|---|
teacher |
Teacher model | Any PyTorch model |
loss |
Distillation loss function | 'SoftTarget', 'Logits', 'Attention', etc. |
activations_student |
Student layers to match | Layer names as strings |
activations_teacher |
Teacher layers to match | Layer names as strings |
weight |
Balancing weight for distillation | 0.0-1.0 |
4. Regularization
Push weights toward zero during training using RegularizeCallback.
| Parameter | Description | Options |
|---|---|---|
criteria |
Regularization criteria | Same as sparsification criteria |
granularity |
Level of regularization | Same as sparsification granularity |
weight |
Regularization strength | Floating point value |
schedule |
How sparsity evolves during training | 'one_shot', 'iterative', 'gradual', etc. |
layer_types |
Layer types to regularize | 'nn.Conv2d', 'nn.Linear', etc. |
5. Quantization
Reduce the precision of weights and activations using Quantizer or QuantizeCallback.
| Parameter | Description | Options |
|---|---|---|
backend |
Target backend | 'x86', 'qnnpack' |
method |
Quantization method | 'static', 'dynamic', 'qat' |
use_per_tensor |
Force per-tensor quantization | True/False |
Quick Start
This is how easy it is to induce Sparsification in your PyTorch model:
from fasterai.sparse.all import *
learn = vision_learner(dls, model)
learn.fit_one_cycle(n_epochs, cbs=SparsifyCallback(sparsity, granularity, context, criteria, schedule))
Installation
pip install git+https://github.com/FasterAI-Labs/fasterai.git
or
pip install fasterai
Tutorials
- Get Started with FasterAI
- Create your own pruning schedule
- Find winning tickets using the Lottery Ticket Hypothesis
- Use Knowledge Distillation to help a student model to reach higher performance
- Sparsify Transformers
- Many more !
Join the community
Join our discord server to meet other FasterAI users and share your projects!
Citing
@software{Hubens,
author = {Nathan Hubens},
title = {fasterai},
year = 2022,
publisher = {Zenodo},
version = {v0.3.0},
doi = {10.5281/zenodo.6469868},
url = {https://doi.org/10.5281/zenodo.6469868}
}
License
Apache-2.0 License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fasterai-0.3.1.tar.gz.
File metadata
- Download URL: fasterai-0.3.1.tar.gz
- Upload date:
- Size: 48.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
64cd4ffc09cb812fd86aa3148a1d0293db5e5f9ae70d89f4e7e68c3ddec74068
|
|
| MD5 |
78cf18f36ae1ca7fd0e58a7e7d166456
|
|
| BLAKE2b-256 |
af2b35cb05289ce3f50ab6f5b482c380b12c03dc65875825505f65505667df6d
|
File details
Details for the file fasterai-0.3.1-py3-none-any.whl.
File metadata
- Download URL: fasterai-0.3.1-py3-none-any.whl
- Upload date:
- Size: 55.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ff7a63c2da79d0f2db758483861a289b5490997b5489ccbbcdbfd2bbca3185b
|
|
| MD5 |
190f1da433eeb43f1c95116d4747546d
|
|
| BLAKE2b-256 |
cfc09145b885deb0317baf666fa99c39b4215a47e3944f6f95a350d7120d156f
|