Poplar and PopLibs
Norms.hpp
Go to the documentation of this file.
1// Copyright (c) 2019 Graphcore Ltd. All rights reserved.
8#ifndef poplin_Norms_hpp
9#define poplin_Norms_hpp
10#include <functional>
11#include <poplar/Graph.hpp>
12#include <poplar/Program.hpp>
13#include <tuple>
14
15namespace poplin {
16
17// Note that the functionality here should move to popnn once operations on
18// broadcasting some of the dimensions is added. Currently these operations are
19// optimised for tensors produced by convolutions/matrix multiplications.
20// (see T6054)
21
34 const poplar::Type &type,
35 const poplar::DebugContext &debugContext = {});
36
48 const poplar::DebugContext &debugContext = {});
49
62 const poplar::Type &type,
63 const poplar::DebugContext &debugContext = {});
64
76 const poplar::DebugContext &debugContext = {});
77
88std::pair<poplar::Tensor, poplar::Tensor>
90 const poplar::DebugContext &debugContext = {});
91
115// slower than when set to false.
120std::pair<poplar::Tensor, poplar::Tensor>
121normStatistics(poplar::Graph &graph, const poplar::Tensor &actsUngrouped,
122 float eps, poplar::program::Sequence &prog,
123 bool unbiasedVarEstimate, bool stableAlgo = false,
124 const poplar::Type &partialsType = poplar::FLOAT,
125 const poplar::DebugContext &debugContext = {});
126
145using DistributedNormReduceCallback = std::function<std::vector<poplar::Tensor>(
146 poplar::Graph &replicatedGraph,
147 const std::vector<poplar::Tensor> &inputsToReduce,
148 poplar::program::Sequence &prog, unsigned groupSize,
149 const poplar::DebugContext &debugContext,
150 const poplar::OptionFlags &options)>;
151
179// slower than when set to false.
190std::pair<poplar::Tensor, poplar::Tensor> distributedNormStatistics(
191 poplar::Graph &replicatedGraph, const poplar::Tensor &actsUngrouped,
192 float eps, poplar::program::Sequence &prog, bool unbiasedVarEstimate,
193 DistributedNormReduceCallback allReduceCallback, unsigned normSize,
194 bool stableAlgo = false, const poplar::Type &partialsType = poplar::FLOAT,
195 const poplar::DebugContext &debugContext = {});
196
213 const poplar::Tensor &mean,
214 const poplar::Tensor &iStdDev,
216 const poplar::DebugContext &debugContext = {});
217
230 const poplar::Tensor &actsWhitened,
231 const poplar::Tensor &gamma,
232 const poplar::Tensor &beta,
234 const poplar::DebugContext &debugContext = {});
235
249std::pair<poplar::Tensor, poplar::Tensor>
251 const poplar::Tensor &gradsIn,
253 const poplar::Type &partialsType = poplar::FLOAT,
254 const poplar::DebugContext &debugContext = {});
255
267 const poplar::Tensor &gradsIn,
268 const poplar::Tensor &gamma,
270 const poplar::DebugContext &debugContext = {});
271
289 poplar::Graph &graph, const poplar::Tensor &actsWhitened,
290 const poplar::Tensor &gradsIn, const poplar::Tensor &invStdDev,
292 const poplar::Type &partialsType = poplar::FLOAT,
293 const poplar::DebugContext &debugContext = {});
294
323 poplar::Graph &replicatedGraph, const poplar::Tensor &actsWhitened,
324 const poplar::Tensor &gradsIn, const poplar::Tensor &invStdDev,
326 poplin::DistributedNormReduceCallback reduceCallback, unsigned normSize,
327 const poplar::Type &partialsType = poplar::FLOAT,
328 const poplar::DebugContext &debugContext = {});
329
330} // namespace poplin
331
332#endif // poplin_Norms_hpp
DebugContext gathers the common external parameters of the context of an operation.
Definition: DebugContext.hpp:221
This class represents a graph program to be executed on the IPU.
Definition: Graph.hpp:52
A set of option/value string flags to be used in various APIs.
Definition: OptionFlags.hpp:24
A reference to a subset of tensor elements.
Definition: Tensor.hpp:38
Class representing device data types.
Definition: Type.hpp:42
Program that executes a sequence of programs.
Definition: Program.hpp:77
Type FLOAT
Device type: float
Linear algebra functions.
Definition: Cholesky.hpp:14
poplar::Tensor normalise(poplar::Graph &graph, const poplar::Tensor &actsWhitened, const poplar::Tensor &gamma, const poplar::Tensor &beta, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext={})
Computes the normalised output from whitened activations.
poplar::Tensor distributedNormStatisticsGradients(poplar::Graph &replicatedGraph, const poplar::Tensor &actsWhitened, const poplar::Tensor &gradsIn, const poplar::Tensor &invStdDev, poplar::program::Sequence &prog, poplin::DistributedNormReduceCallback reduceCallback, unsigned normSize, const poplar::Type &partialsType=poplar::FLOAT, const poplar::DebugContext &debugContext={})
Propagate the gradients through the norm statistics layer where equal sized batch elements are distri...
poplar::Tensor normGradients(poplar::Graph &graph, const poplar::Tensor &gradsIn, const poplar::Tensor &gamma, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext={})
Propagate the gradients through the normalisation layer.
std::pair< poplar::Tensor, poplar::Tensor > createNormParams(poplar::Graph &graph, const poplar::Tensor &acts, const poplar::DebugContext &debugContext={})
Creates a tensor pair of normalisation parameters (gamma, beta).
std::pair< poplar::Tensor, poplar::Tensor > distributedNormStatistics(poplar::Graph &replicatedGraph, const poplar::Tensor &actsUngrouped, float eps, poplar::program::Sequence &prog, bool unbiasedVarEstimate, DistributedNormReduceCallback allReduceCallback, unsigned normSize, bool stableAlgo=false, const poplar::Type &partialsType=poplar::FLOAT, const poplar::DebugContext &debugContext={})
Compute the normalisation statistics for a part of the activations tensor which is distributed over m...
std::pair< poplar::Tensor, poplar::Tensor > normParamGradients(poplar::Graph &graph, const poplar::Tensor &actsWhitened, const poplar::Tensor &gradsIn, poplar::program::Sequence &prog, const poplar::Type &partialsType=poplar::FLOAT, const poplar::DebugContext &debugContext={})
Compute gradients with respect to parameters required for parameter update.
poplar::Tensor normStatisticsGradients(poplar::Graph &graph, const poplar::Tensor &actsWhitened, const poplar::Tensor &gradsIn, const poplar::Tensor &invStdDev, poplar::program::Sequence &prog, const poplar::Type &partialsType=poplar::FLOAT, const poplar::DebugContext &debugContext={})
Propagate the gradients through the norm statistics layer.
poplar::Tensor createNormBeta(poplar::Graph &graph, const poplar::Tensor &acts, const poplar::Type &type, const poplar::DebugContext &debugContext={})
Create and map the per-channel additive beta parameter tensor used for normalisation in convolution l...
poplar::Tensor createNormGamma(poplar::Graph &graph, const poplar::Tensor &acts, const poplar::Type &type, const poplar::DebugContext &debugContext={})
Create and map the per-channel multiplicative gamma parameter tensor used for normalisation in convol...
poplar::Tensor normWhiten(poplar::Graph &graph, const poplar::Tensor &acts, const poplar::Tensor &mean, const poplar::Tensor &iStdDev, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext={})
Compute the whitened activations using the supplied mean and inverse standard deviation.
std::function< std::vector< poplar::Tensor >(poplar::Graph &replicatedGraph, const std::vector< poplar::Tensor > &inputsToReduce, poplar::program::Sequence &prog, unsigned groupSize, const poplar::DebugContext &debugContext, const poplar::OptionFlags &options)> DistributedNormReduceCallback
Callback to reduce statistics and gradients.
Definition: Norms.hpp:150
std::pair< poplar::Tensor, poplar::Tensor > normStatistics(poplar::Graph &graph, const poplar::Tensor &actsUngrouped, float eps, poplar::program::Sequence &prog, bool unbiasedVarEstimate, bool stableAlgo=false, const poplar::Type &partialsType=poplar::FLOAT, const poplar::DebugContext &debugContext={})
Compute the normalisation statistics from the activations tensor.