beyondml.pt

PyTorch compatibility for building MANN models

The beyondml.pt subpackage contains layers and utilities for creating and pruning models using PyTorch. The package contains two subpackages, the beyondml.pt.layers package, and the beyondml.pt.utils package.

Within the layers package, there is current functionality for the the following layers:

Within the beyondml.pt.utils package, there is currently only one function, the prune_model function. Because of the openness of developing with PyTorch in comparison to TensorFlow, there is far less functionality that can be supplied directly via BeyondML. Instead, for converting models from training to inference, the user is left to devise the best way to do so by building his or her own classes.

Best Practices for Pruning

In order to use the utils.prune_model function, the model itself must have a .layers property. This property is used to determine which layers can be pruned. Only layers which support pruning and which are included in the .layers property are pruned, meaning the user can determine which exact layers in the model he or she wants pruned. Alternatively, the user can create their own pruning function or method on the class itself and prune that way, utilizing each of the .prune() methods of the layers provided.

 1"""
 2## PyTorch compatibility for building MANN models
 3
 4The `beyondml.pt` subpackage contains layers and utilities for creating and pruning models using [PyTorch](https://pytorch.org).
 5The package contains two subpackages, the `beyondml.pt.layers` package, and the `beyondml.pt.utils` package.
 6
 7Within the `layers` package, there is current functionality for the the following layers:
 8- `beyondml.pt.layers.Conv2D`
 9- `beyondml.pt.layers.Dense`
10- `beyondml.pt.layers.FilterLayer`
11- `beyondml.pt.layers.MaskedConv2D`
12- `beyondml.pt.layers.MaskedDense`
13- `beyondml.pt.layers.MultiConv2D`
14- `beyondml.pt.layers.MultiDense`
15- `beyondml.pt.layers.MultiMaskedConv2D`
16- `beyondml.pt.layers.MultiMaskedDense`
17- `beyondml.pt.layers.SelectorLayer`
18- `beyondml.pt.layers.SparseConv2D`
19- `beyondml.pt.layers.SparseDense`
20- `beyondml.pt.layers.SparseMultiConv2D`
21- `beyondml.pt.layers.SparseMultiDense`
22
23Within the `beyondml.pt.utils` package, there is currently only one function, the `prune_model` function. Because of
24the openness of developing with PyTorch in comparison to TensorFlow, there is far less functionality that
25can be supplied directly via BeyondML. Instead, for converting models from training to inference, the user
26is left to devise the best way to do so by building his or her own classes.
27
28### Best Practices for Pruning
29In order to use the `utils.prune_model` function, the model itself must have a `.layers` property. This property
30is used to determine which layers can be pruned. **Only layers which support pruning and which are included in the
31`.layers` property are pruned,** meaning the user can determine which exact layers in the model he or she wants
32pruned. Alternatively, the user can create their own pruning function or method on the class itself and prune that way,
33utilizing each of the `.prune()` methods of the layers provided.
34"""
35
36import beyondml.pt.layers
37import beyondml.pt.utils