Skip to main content

Package containing utilities for implementing RSN2/MANN

Project description

MANN

MANN, which stands for Multitask Artificial Neural Networks, is a Python package which enables creating sparse multitask models compatible with TensorFlow. This package contains custom layers and utilities to facilitate the training and optimization of models using the Reduction of Sub-Network Neuroplasticity (RSN2) training procedure developed by AI Squared, Inc.

Installation

This package is available through PyPi and can be installed via the following command:

pip install mann

To install the current version directly from GitHub without cloning, run the following command:

pip install git+https://github.com/AISquaredInc/mann.git

Alternatively, you can install the package by cloning the repository from GitHub using the following commands:

# clone the repository and cd into it
git clone https://github.com/AISquaredInc/mann
cd mann

# install the package
pip install .

Mac M1 Users

For those with a Mac with the M1 processor, this package can be installed, but the standard version of TensorFlow is not compatible with the M1 SOC. In order to install a compatible version of TensorFlow, please install the Miniforge conda environment, which utilizes the conda-forge channel only. Once you are using Miniforge, using conda to install TensorFlow in that environment should install the correct version. After installing TensorFlow, the command pip install mann will install the MANN package.

Capabilities

The MANN package includes two subpackages, the mann.utils package and the mann.layers package. As the name implies, the mann.utils package includes utilities which assist in model training. The mann.layers package includes custom Keras-compatible layers which can be used to train sparse multitask models.

Utils

The mann.utils subpackage contains helper functions for performing training and conversion of models using masking layers.

In addition to the functions just mentioned, there is also an ActiveSparsification callback object which enables active sparsification during training rather than solely one-shot sparsification. Note that this callback currently only supports simultaneous training. We are working to support iterative training with this callback as well.

  1. mask_model
    • The mask_model function is central to the RSN2 training procedure and enables masking/pruning a model so a large percentage of the weights are inactive.
    • Inputs to the mask_model function are a TensorFlow model, a percentile in integer form, a method - either one of 'gradients' or 'magnitude', input data, and target data.
  2. get_custom_objects
    • The get_custom_objects function takes no parameters and returns a dictionary of all custom objects required to load a model trained using this package.
  3. remove_layer_masks
    • The remove_layer_masks function takes a trained model with masked layers and converts it to a model without masking layers.
  4. add_layer_masks
    • The add_layer_masks function takes an existing model that has non-MANN layers and converts it so that all layers which have an analog in the MANN package. This enables pretrained models to be converted and sparsified.
  5. quantize_model
    • The quantize_model function takes in a model and a datatype to quantize the model to.
  6. build_transformer_block
    • The build_transformer_block function can be used to build a block in a transformer architecture.
  7. build_token_position_embedding
    • The build_token_position_embedding function can be used to build a token and position embedding block for use in a transformer architecture model.

Layers

The mann.layers subpackage contains custom Keras-compatible layers which can be used to train sparse multitask models. The layers contained in this package are as follows:

  1. MaskedDense
    • This layer is nearly identical to the Keras Dense layer, but it supports masking and pruning to reduce the number of active weights.
  2. MaskedConv2D
    • This layer is nearly identical to the Keras Conv2D layer, but it supports masking and pruning to reduce the number of active weights.
  3. MultiMaskedDense
    • This layer supports isolating pathways within the network and dedicating them for individual tasks and performing fully-connected operations on the input data.
  4. MultiMaskedConv2D
    • This layer supports isolating pathways within the network and dedicating them for individual tasks and performing convolutional operations on the input data.
  5. MultiDense
    • This layer supports multitask inference using a fully-connected architecture and is not designed for training. Once a model is trained with the MultiMaskedDense layer, that layer can be converted into this layer for inference by using the mann.utils.remove_layer_masks function.
  6. MultiConv2D
    • This layer supports multitask inference using a convolutional architecture and is not designed for training. Once a model is trained with the MultiMaskedConv2D layer, that layer can be converted to this layer for inference by using the mann.utils.remove_layer_masks function.
  7. SelectorLayer
    • This layer selects which of the multiple inputs fed into it is returned as a result. This layer is designed to be used specifically with multitask layers.
  8. SumLayer
    • This layer returns the element-wise sum of all of the inputs.
  9. FilterLayer
    • This layer can be turned on or off, and indicates whether the single input passed to it should be output or if all zeros should be returned.
  10. MultiMaxPool2D
    • This layer implements Max Pool operations on multitask inputs.

Additional Documentation and Training Materials

Additional documentation and training materials will be added to the BeyondML Documentation Website as we continue to develop this project and its capabilities.

Feature Roadmap

  • Transformers
    • We currently support basic functionality for the Transformer architecture with this package. We are working to expand our capabilities with this architecture to further support greater use cases with it, including pruning.
  • Per-task pruning
    • Currently, pruning occurs for all tasks instead of on a per-task basis. Enabling per-task pruning is very high on our priority list

Changes

Below are a list of additional features, bug fixes, and other changes made for each version.

Version 0.2.2

  • Small documentation changes
  • Added quantize_model function
  • Added build_transformer_block and build_token_position_embedding_block functions for transformer functionality
  • Removed unnecessary imports breaking imports in minimal environments

Version 0.2.3 (in development)

  • Per-task pruning
    • Functionality for this feature is implemented, but usage is expected to be incomplete. Note that task gradients have to be passed retrieved and passed to the function directly (helper function available), and that the model has to initially be compiled using a compatible loss function (recommended 'mse') to identify gradients.
    • Note also that this functionality does not support cases where layers of an individual model are other TensorFlow models, but supporting this functionality is on the roadmap.
  • Iterative training using per-task pruning
    • Functionality for this feature is implemented and is currently being tested. Bugs and inconsistent results are expected

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

mann-0.2.3.dev1.tar.gz (23.9 kB view details)

Uploaded Source

Built Distribution

mann-0.2.3.dev1-py3-none-any.whl (30.9 kB view details)

Uploaded Python 3

File details

Details for the file mann-0.2.3.dev1.tar.gz.

File metadata

  • Download URL: mann-0.2.3.dev1.tar.gz
  • Upload date:
  • Size: 23.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/1.5.0 colorama/0.4.4 CPython/3.9.12

File hashes

Hashes for mann-0.2.3.dev1.tar.gz
Algorithm Hash digest
SHA256 b4f60666333e3d8dceff834bf224d14dbacaa15fb115e275b5e4c414c9253518
MD5 881c6b52dd6b3fc188d07d7a68e0bc93
BLAKE2b-256 1fcec2832aa188192fc9153909fdaceda9abf106934528ae566a64a212dc96d3

See more details on using hashes here.

File details

Details for the file mann-0.2.3.dev1-py3-none-any.whl.

File metadata

  • Download URL: mann-0.2.3.dev1-py3-none-any.whl
  • Upload date:
  • Size: 30.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/1.5.0 colorama/0.4.4 CPython/3.9.12

File hashes

Hashes for mann-0.2.3.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 e2f8bc98e2397b204c7534a3ef54aa67f06c8c7f0539c6afbc88872ec8b04d4d
MD5 0aef96fa4cc78de3a7732bd7018afa20
BLAKE2b-256 960c8edaa82290c508763b667be33732ad9e49e2126d5be07baa081f63dfdf95

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