Skip to main content

A library to make neural networks lighter and faster with fastai

Project description

Fasterai

header

FeaturesInstallationTutorialsCommunityCitingLicense

fasterai is a library created to make neural network smaller and faster. It essentially relies on common compression techniques for networks such as pruning, knowledge distillation, Lottery Ticket Hypothesis, ...

The core feature of fasterai is its Sparsifying capabilities, constructed on 4 main modules: granularity, context, criteria, schedule. Each of these modules is highly customizable, allowing you to change them according to your needs or even to come up with your own !

Project Documentation

Visit Read The Docs Project Page or read following README to know more about using fasterai.


Features

1. Sparsifying

alt text

Make your model sparse (i.e. prune it) according to a:

  • Sparsity: the percentage of weights that will be replaced by 0
  • Granularity: the granularity at which you operate the pruning (removing weights, vectors, kernels, filters)
  • Context: prune either each layer independantly (local pruning) or the whole model (global pruning)
  • Criteria: the criteria used to select the weights to remove (magnitude, movement, ...)
  • Schedule: which schedule you want to use for pruning (one shot, iterative, gradual, ...)

This can be achieved by using the SparsifyCallback(sparsity, granularity, context, criteria, schedule)

2. Pruning

alt text

Once your model has useless nodes due to zero-weights, they can be removed to not be a part of the network anymore.

This can be achieved by using the Pruner() method

3. Regularization

alt text

Instead of explicitely make your network sparse, let it train towards sparse connections by pushing the weights to be as small as possible.

Regularization can be applied to groups of weights, following the same granularities as for sparsifying, i.e.:

  • Granularity: the granularity at which you operate the regularization (weights, vectors, kernels, filters, ...)

This can be achieved by using the RegularizationCallback(granularity)

4. Knowledge Distillation

alt text

Distill the knowledge acquired by a big model into a smaller one, by using the KnowledgeDistillation callback.

5. Lottery Ticket Hypothesis

alt text

Find the winning ticket in you network, i.e. the initial subnetwork able to attain at least similar performances than the network as a whole.


Quick Start

0. Import fasterai

from fasterai.sparse.all import *

1. Create your model with fastai

learn = cnn_learner(dls, model)

2. Get you Fasterai Callback

sp_cb=SparsifyCallback(sparsity, granularity, context, criteria, schedule)

3. Train you model to make it sparse !

learn.fit_one_cycle(n_epochs, cbs=sp_cb)

Installation

pip install git+https://github.com/nathanhubens/fasterai.git

or

pip install fasterai

Tutorials


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.1.6},
  doi          = {10.5281/zenodo.6469868},
  url          = {https://doi.org/10.5281/zenodo.6469868}
}

License

Apache-2.0 License.

footer

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fasterai-0.2.4.tar.gz (25.9 kB view details)

Uploaded Source

Built Distribution

fasterai-0.2.4-py3-none-any.whl (27.2 kB view details)

Uploaded Python 3

File details

Details for the file fasterai-0.2.4.tar.gz.

File metadata

  • Download URL: fasterai-0.2.4.tar.gz
  • Upload date:
  • Size: 25.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.0

File hashes

Hashes for fasterai-0.2.4.tar.gz
Algorithm Hash digest
SHA256 0a922cd2655bd365e8e1b7532484e0fe17a52f1998cde331e01ebfbe3877a940
MD5 c8739b0746596b0c5bdb6bf86a1dcaa0
BLAKE2b-256 dff2ed3b1fceba2b6d685d5e1a979c7b2bfb556cd2c737c155f3c28b847adeb5

See more details on using hashes here.

File details

Details for the file fasterai-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: fasterai-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 27.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.0

File hashes

Hashes for fasterai-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 111a30c47f5431cde1d40bc853f39c28834784615513f465f217446425de35f5
MD5 3eee2a3daf5959e13db033f8d2c6a897
BLAKE2b-256 7671a7f172de681f6c503bb9b0028621ff1123122f8690606596ea8d90fc87eb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page