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.1.tar.gz (24.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fasterai-0.2.1-py3-none-any.whl (25.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for fasterai-0.2.1.tar.gz
Algorithm Hash digest
SHA256 695ad30f6ca1de18abfea25b1a5c734730ee280eb8023232cd81e0ee7e3956a4
MD5 3d3362d0a394713769ae0163a8f52cc4
BLAKE2b-256 ab4049b82e712ef98e3dcafd0765604acc943365c81df3bd5f26fe3cd053cca0

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for fasterai-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 726620f3945605e4ca52300cc623e8482309b7afa3ea61fc8526283c22938c37
MD5 d777b6cc0484758673b11262d5ca824f
BLAKE2b-256 5e46f77bef4c9668814d118b627a9f1c4fc4f4afae2fed0765152a5b9cd26858

See more details on using hashes here.

Supported by

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