Poplar and PopLibs
|
Functions used in neural networks. More...
Namespaces | |
namespace | pooling |
Functions for pooling operations. | |
namespace | rnn |
Functions for Recurrent Neural Networks (RNN) | |
Enumerations | |
enum class | NonLinearityType { SIGMOID , HARD_SIGMOID , RELU , TANH , GELU , SWISH , SOFTMAX , SOFTMAX_STABLE , SOFTMAX_SCALED } |
enum class | PoolingType |
Pooling types. | |
Functions | |
void | logSoftmaxInPlace (poplar::Graph &graph, poplar::Tensor t, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext={}) |
Update tensor t by computing log of softmax in-place. More... | |
poplar::Tensor | logSoftmax (poplar::Graph &graph, poplar::Tensor t, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext={}) |
Compute the log of the softmax to tensor t and return the result. More... | |
std::uint64_t | getNormFwdFlops (std::size_t statisticsSize, std::size_t numActsElements, bool computeStats=true) |
Calculate the floating point operations required for the forward pass of a norm layer. More... | |
std::uint64_t | getNormBwdFlops (std::size_t statisticsSize, std::size_t numActsElements) |
Calculate the floating point operations required for computation of the gradient with respect to the activations for a norm layer. More... | |
std::uint64_t | getNormWuFlops (std::size_t paramsSize, std::size_t numActsElements) |
Calculate the floating point operations required for parameter update for a norm layer. More... | |
poplar::Tensor | createNormGamma (poplar::Graph &graph, const poplar::Tensor &acts, const poplar::DebugContext &debugContext={}) |
poplar::Tensor | createNormBeta (poplar::Graph &graph, const poplar::Tensor &acts, const poplar::DebugContext &debugContext={}) |
std::pair< poplar::Tensor, poplar::Tensor > | createNormParams (poplar::Graph &graph, const poplar::Tensor acts, const poplar::DebugContext &debugContext={}) |
std::pair< poplar::Tensor, poplar::Tensor > | spatialSoftMax2D (poplar::Graph &graph, poplar::program::Sequence &prog, const poplar::Tensor &fields, float temperature, bool disableSoftmax=false, const poplar::DebugContext &debugContext={}) |
Implements a spatial softmax specialised for 2D input fields. More... | |
Functions used in neural networks.
|
strong |
poplar::Tensor popnn::createNormBeta | ( | poplar::Graph & | graph, |
const poplar::Tensor & | acts, | ||
const poplar::DebugContext & | debugContext = {} |
||
) |
graph | The graph that the normalisation operation is added to. |
acts | Activations that are inputs to the norm. |
debugContext | Optional debug information. |
poplar::Tensor popnn::createNormGamma | ( | poplar::Graph & | graph, |
const poplar::Tensor & | acts, | ||
const poplar::DebugContext & | debugContext = {} |
||
) |
graph | The graph that the normalisation operation is added to. |
acts | Activations that are inputs to the norm. |
debugContext | Optional debug information. |
std::pair< poplar::Tensor, poplar::Tensor > popnn::createNormParams | ( | poplar::Graph & | graph, |
const poplar::Tensor | acts, | ||
const poplar::DebugContext & | debugContext = {} |
||
) |
graph | The graph that the normalisation operation is added to. |
acts | Activations that are inputs to the norm. |
debugContext | Optional debug information. |
std::uint64_t popnn::getNormBwdFlops | ( | std::size_t | statisticsSize, |
std::size_t | numActsElements | ||
) |
Calculate the floating point operations required for computation of the gradient with respect to the activations for a norm layer.
statisticsSize | The size of the statistics vector. |
numActsElements | The number of elements in the activation inputs. |
std::uint64_t popnn::getNormFwdFlops | ( | std::size_t | statisticsSize, |
std::size_t | numActsElements, | ||
bool | computeStats = true |
||
) |
Calculate the floating point operations required for the forward pass of a norm layer.
For inference with batchNormalise(), computeStats
should be set to false if the batch statistics are not computed. This is because averaged batch statistics may be combined with the norm parameters.
statisticsSize | The size of the statistics vector. |
numActsElements | The number of elements in the activation inputs. |
computeStats | Set to false for inference with batch norm. |
std::uint64_t popnn::getNormWuFlops | ( | std::size_t | paramsSize, |
std::size_t | numActsElements | ||
) |
Calculate the floating point operations required for parameter update for a norm layer.
paramsSize | The size of the parameter vector. |
numActsElements | The number of elements in the activation inputs. |
poplar::Tensor popnn::logSoftmax | ( | poplar::Graph & | graph, |
poplar::Tensor | t, | ||
poplar::program::Sequence & | prog, | ||
const poplar::DebugContext & | debugContext = {} |
||
) |
Compute the log of the softmax to tensor t
and return the result.
graph | The graph to add the operation to. |
t | The tensor to apply the non-linearity to. |
prog | The sequence to add the operation to. |
debugContext | Optional debug information. |
t
with the given log of the softmax applied. void popnn::logSoftmaxInPlace | ( | poplar::Graph & | graph, |
poplar::Tensor | t, | ||
poplar::program::Sequence & | prog, | ||
const poplar::DebugContext & | debugContext = {} |
||
) |
Update tensor t
by computing log of softmax in-place.
graph | The graph to add the operation to. |
t | The tensor to apply the log of softmax to. |
prog | The sequence to add the operation to. |
debugContext | Optional debug information. |
std::pair< poplar::Tensor, poplar::Tensor > popnn::spatialSoftMax2D | ( | poplar::Graph & | graph, |
poplar::program::Sequence & | prog, | ||
const poplar::Tensor & | fields, | ||
float | temperature, | ||
bool | disableSoftmax = false , |
||
const poplar::DebugContext & | debugContext = {} |
||
) |
Implements a spatial softmax specialised for 2D input fields.
This computes the expected coordinates (normalised to be in [-1.0, 1.0]) for every 2D field in the input tensor. A (trainable) temperature scalar is added which normalises the softmax across the fields.
The output of the spatial softmax (first tensor in the returned pair) is a set of expected x and y coordinates for the maximum activation in each field. This result has shape {F, 2} where F is the number of fields. Y-coordinates run down the first column and X-coordinates down the second column to preserve (row,column) indexing order into the original fields.
graph | Graph to which variables and vertices will be added. |
prog | Program to which operations will be added. |
fields | The input Tensor. Must have rank 3. Interpretation is a set of 2D scalar fields of identical height (H) and width (W) given by the two inner dimensions (so shape is {F, H, W} where F is the number of fields). |
temperature | Initial value for the softmax scaling/normalisation parameter. |
debugContext | Optional debug information. |
disableSoftmax | Turns off softmax computation in this function. This is useful if you have already computed a softmax over all the fields due to other processing or for test/debug. |