Poplar and PopLibs
poprand Namespace Reference

Pseudo-random number generator (PRNG) functions. More...

Functions

poplar::Tensor dropout (poplar::Graph &graph, const poplar::Tensor *seed, const uint32_t seedModifier, const poplar::Tensor &input, const poplar::Tensor &reference, double keepProbability, double scale, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext={})
 Apply dropout to a tensor. More...
 
poplar::Tensor dropout (poplar::Graph &graph, const poplar::Tensor *seed, const uint32_t seedModifier, const poplar::Tensor &input, const poplar::Tensor &reference, double keepProbability, double scale, bool outputClonesRef, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext={})
 Apply dropout to a tensor. More...
 
poplar::Tensor shapedDropout (poplar::Graph &graph, const poplar::Tensor *seed, const uint32_t seedModifier, const poplar::Tensor &input, const poplar::Tensor &reference, double keepProbability, double scale, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext={})
 Apply shaped dropout to a tensor. More...
 
poplar::Tensor uniform (poplar::Graph &graph, const poplar::Tensor *seed, uint32_t seedModifier, const poplar::Tensor &reference, const poplar::Type &outType, double minVal, double maxVal, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext={})
 Uniform distribution in a given interval with maxVal > minVal. More...
 
poplar::Tensor logUniform (poplar::Graph &graph, const poplar::Tensor *seed, uint32_t seedModifier, const poplar::Tensor &reference, const poplar::Type &outType, double minVal, double maxVal, poplar::program::Sequence &prog, double base=M_E, const poplar::DebugContext &debugContext={})
 Log-uniform distribution over a closed interval [minVal, maxVal]. More...
 
poplar::Tensor bernoulli (poplar::Graph &graph, const poplar::Tensor *seed, uint32_t seedModifier, const poplar::Tensor &reference, const poplar::Type &outType, double prob, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext={})
 Bernoulli distribution which has the value 1 with the specified probability. More...
 
poplar::Tensor normal (poplar::Graph &graph, const poplar::Tensor *seed, uint32_t seedModifier, const poplar::Tensor &reference, const poplar::Type &outType, double mean, double stdDev, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext={})
 Normal distribution with given mean and standard deviation. More...
 
poplar::Tensor truncatedNormal (poplar::Graph &graph, const poplar::Tensor *seed, uint32_t seedModifier, const poplar::Tensor &reference, const poplar::Type &outType, double mean, double stdDev, double alpha, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext={})
 Truncated normal distribution. More...
 
void setSeed (poplar::Graph &graph, const poplar::Tensor &masterSeed, uint32_t seedModifier, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext={})
 Sets the random number generator seed on all tiles. More...
 

Detailed Description

Pseudo-random number generator (PRNG) functions.

Function Documentation

◆ bernoulli()

poplar::Tensor poprand::bernoulli ( poplar::Graph graph,
const poplar::Tensor seed,
uint32_t  seedModifier,
const poplar::Tensor reference,
const poplar::Type outType,
double  prob,
poplar::program::Sequence prog,
const poplar::DebugContext debugContext = {} 
)

Bernoulli distribution which has the value 1 with the specified probability.

Generates a tensor with random values of 0 and 1, determined by prob.

Parameters
graphThe graph to add this operation to.
seedIf not null, this is a pair of 32-bit integers used to seed the random number generator that generates the distribution.
seedModifierProvides a further modification of the seed value. Ignored if seed is null.
referenceA tensor that specifies the layout of the output tensor.
outTypeThe type of the output tensor. One of float, half or int.
probProbability of an element being 1.
progThe program to add this operation to.
debugContextOptional debug information.
Returns
A tensor with elements set to either 0 or 1. The value 1 occurs with probablility prob.

◆ dropout() [1/2]

poplar::Tensor poprand::dropout ( poplar::Graph graph,
const poplar::Tensor seed,
const uint32_t  seedModifier,
const poplar::Tensor input,
const poplar::Tensor reference,
double  keepProbability,
double  scale,
bool  outputClonesRef,
poplar::program::Sequence prog,
const poplar::DebugContext debugContext = {} 
)

Apply dropout to a tensor.

The elements of tensor input are multiplied by a mask consisting of a sequence of randomly generated 1 or 0. The keep probability of the dropout P(1) = keepProbability. The contents of the mask depend on the keep probability, seed, seed modifier and layout of the reference tensor.

Parameters
graphThe graph to add this operation to.
seedIf not null, this is a pair of 32-bit integers used to seed the random number generator that generates the dropout mask.
seedModifierProvides a further modification of the seed value. Ignored if seed is null.
inputThe input tensor to be masked.
referenceA tensor that specifies the layout of the output tensor. Must be the same shape as the input.
keepProbabilityThe probability of keeping an input value.
scaleScales the output tensor. This is typically the inverse of the dropout probability, (1 / P(1)).
outputClonesRefWhen true, the output tensor is a clone of the reference tensors. When false, the output tensor is a clone of the input tensor.
progThe program to add this operation to.
debugContextOptional debug information.
Returns
A tensor with elements randomly set to either zero or the scaled input value.

◆ dropout() [2/2]

poplar::Tensor poprand::dropout ( poplar::Graph graph,
const poplar::Tensor seed,
const uint32_t  seedModifier,
const poplar::Tensor input,
const poplar::Tensor reference,
double  keepProbability,
double  scale,
poplar::program::Sequence prog,
const poplar::DebugContext debugContext = {} 
)

Apply dropout to a tensor.

The elements of tensor input are multiplied by a mask consisting of a sequence of randomly generated 1 or 0. The keep probability of the dropout P(1) = keepProbability. The contents of the mask depend on the keep probability, seed, seed modifier and layout of the reference tensor.

Parameters
graphThe graph to add this operation to.
seedIf not null, this is a pair of 32-bit integers used to seed the random number generator that generates the dropout mask.
seedModifierProvides a further modification of the seed value. Ignored if seed is null.
inputThe input tensor to be masked.
referenceA tensor that specifies the layout of the output tensor. Must be the same shape as the input.
keepProbabilityThe probability of keeping an input value.
scaleScales the output tensor. This is typically the inverse of the dropout probability, (1 / P(1)).
progThe program to add this operation to.
debugContextOptional debug information.
Returns
A tensor with elements randomly set to either zero or the scaled input value.

◆ logUniform()

poplar::Tensor poprand::logUniform ( poplar::Graph graph,
const poplar::Tensor seed,
uint32_t  seedModifier,
const poplar::Tensor reference,
const poplar::Type outType,
double  minVal,
double  maxVal,
poplar::program::Sequence prog,
double  base = M_E,
const poplar::DebugContext debugContext = {} 
)

Log-uniform distribution over a closed interval [minVal, maxVal].

Generates random data log-uniformly distributed in the closed interval [minVal, maxVal]. The output may be of type float, half or int. The base of the log can be specified, but defaults to the natural base.

The actual interval of the samples depends on the representable values of the outType and is a subset of the initial interval; the interval will be squeezed inward to the next representable values of outType. For example, for half, the interval [2049.0, 4098.0] would be squeezed to [2050.0, 4096.0]. Depending on the interval's representability, this may cause spikes in the distribution at the boundaries - careful choice of interval is suggested.

Parameters
graphThe graph to add this operation to.
seedIf not null, this is a pair of 32-bit integers used to seed the random number generator that generates the distribution.
seedModifierProvides a further modification of the seed value. Ignored if seed is null.
referenceA tensor that specifies the layout of the output tensor.
outTypeThe type of the output tensor. One of float, half or int.
minValThe minimum value of the distribution.
maxValThe maximum value of the distribution.
progThe program to add this operation to.
baseOptional base of the log / exponent of the underlying uniform distribution. Defaults to Euler's number (natural base).
debugContextOptional debug information.
Returns
A tensor the same size as reference with elements having a log-uniform distribution of random values of type outType.
Exceptions
poputil::poplibs_errorIf minVal < 1
poputil::poplibs_errorIf maxVal <= minVal
poputil::poplibs_errorIf minVal and maxVal are not suitable for the outType (for example the range is too narrow)

◆ normal()

poplar::Tensor poprand::normal ( poplar::Graph graph,
const poplar::Tensor seed,
uint32_t  seedModifier,
const poplar::Tensor reference,
const poplar::Type outType,
double  mean,
double  stdDev,
poplar::program::Sequence prog,
const poplar::DebugContext debugContext = {} 
)

Normal distribution with given mean and standard deviation.

Generates random data with a normal (Gaussian) distribution. The mean is given by mean and the standard deviation by stdDev.

Parameters
graphThe graph to add this operation to.
seedIf not null, this is a pair of 32-bit integers used to seed the random number generator that generates the distribution.
seedModifierProvides a further modification of the seed value. Ignored if seed is null.
referenceA tensor that specifies the layout of the output tensor.
outTypeThe type of the output tensor. One of float or half.
meanThe mean value of the distribution.
stdDevThe standard deviation of the distribution.
progThe program to add this operation to.
debugContextOptional debug information.
Returns
A tensor with elements having a normal (Gaussian) distribution of random values.

◆ setSeed()

void poprand::setSeed ( poplar::Graph graph,
const poplar::Tensor masterSeed,
uint32_t  seedModifier,
poplar::program::Sequence prog,
const poplar::DebugContext debugContext = {} 
)

Sets the random number generator seed on all tiles.

Parameters
graphThe graph to add this operation to.
masterSeedA 64-bit integer to seed the random number on every tile.
seedModifierProvides a further modification of the seed value.
progThe program to add this operation to.
debugContextOptional debug information.

◆ shapedDropout()

poplar::Tensor poprand::shapedDropout ( poplar::Graph graph,
const poplar::Tensor seed,
const uint32_t  seedModifier,
const poplar::Tensor input,
const poplar::Tensor reference,
double  keepProbability,
double  scale,
poplar::program::Sequence prog,
const poplar::DebugContext debugContext = {} 
)

Apply shaped dropout to a tensor.

The elements of tensor input are multiplied by a mask consisting of a sequence of randomly generated 1 or 0. The keep probability of the dropout P(1) = keepProbability.

Shaped dropout allows row, column and dimension wise dropout, versus element-wise standard dropout. The shape of the dropout must be compatible (broadcastable) to input.

The contents of the mask depend on the keep probability, seed, seed modifier and layout of the reference tensor.

Parameters
graphThe graph to add this operation to.
seedIf not null, this is a pair of 32-bit integers used to seed the random number generator that generates the dropout mask.
seedModifierProvides a further modification of the seed value. Ignored if seed is null.
inputThe input tensor to be masked.
referenceA tensor that specifies the shape and layout of the dropout. Must be broadcastable to the input.
keepProbabilityThe probability of keeping an input value.
scaleScales the output tensor. This is typically the inverse of the dropout probability, (1 / P(1)).
progThe program to add this operation to.
debugContextOptional debug information.
Returns
A tensor with elements randomly set to either zero or the scaled input value.

◆ truncatedNormal()

poplar::Tensor poprand::truncatedNormal ( poplar::Graph graph,
const poplar::Tensor seed,
uint32_t  seedModifier,
const poplar::Tensor reference,
const poplar::Type outType,
double  mean,
double  stdDev,
double  alpha,
poplar::program::Sequence prog,
const poplar::DebugContext debugContext = {} 
)

Truncated normal distribution.

Generates random data with a distribution derived from a normal distribution with mean mean and standard deviation stdDev. This normal distribution is truncated symmetrically about the mean at (mean - alpha * stdDev) and (mean + alpha * stdDev)

Parameters
graphThe graph to add this operation to.
seedIf not null, this is a pair of 32-bit integers used to seed the random number generator that generates the distribution.
seedModifierProvides a further modification of the seed value. Ignored if seed is null.
referenceA tensor that specifies the layout of the output tensor.
outTypeThe type of the output tensor. One of float or half.
meanThe mean value of the distribution.
stdDevThe standard deviation of the distribution.
alphaDefines the minimum and maximum values of the distribution.
progThe program to add this operation to.
debugContextOptional debug information.
Returns
A tensor with elements having a truncated normal (Gaussian) distribution of random values.

◆ uniform()

poplar::Tensor poprand::uniform ( poplar::Graph graph,
const poplar::Tensor seed,
uint32_t  seedModifier,
const poplar::Tensor reference,
const poplar::Type outType,
double  minVal,
double  maxVal,
poplar::program::Sequence prog,
const poplar::DebugContext debugContext = {} 
)

Uniform distribution in a given interval with maxVal > minVal.

Generates random data with uniform distribution in the interval [minVal, maxVal]. The output may be of type float, half or int.

For type int, data is generated in the interval [minVal, maxVal] with uniform probability if (maxVal - minVal) is a power of 2. Otherwise there will be a small bias in the probability generated, with the bias directly proportional to the ratio (maxVal - minVal + 1 ) / 2^32.

Parameters
graphThe graph to add this operation to.
seedIf not null, this is a pair of 32-bit integers used to seed the random number generator that generates the distribution.
seedModifierProvides a further modification of the seed value. Ignored if seed is null.
referenceA tensor that specifies the layout of the output tensor.
outTypeThe type of the output tensor. One of float, half or int.
minValThe minimum value of the distribution.
maxValThe maximum value of the distribution.
progThe program to add this operation to.
debugContextOptional debug information.
Returns
A tensor with elements having a uniform distribution of random values.