Skip to content
fn

bernoulli_mask_storage

→Storage
int bernoulli_mask_storage(double keep_prob, int numel, Dtype dt, Device device, Generator & gen)

Generate a Bernoulli dropout mask as a flat 1-D storage.

Each element is independently set to 1.0 with probability keep_prob and to 0.0 otherwise. The mask is generated on CPU using gen and then transferred to device via Dispatcher::from_cpu to keep the random number stream deterministic regardless of where the consuming op runs.

Parameters

keep_probdouble
Probability of keeping each element (1 - dropout_rate).
numelstd::size_t
Number of mask elements.
dtDtype
Output dtype; F32 or F64 only.
deviceDevice
Target device.
Random-number generator owning the PRNG state.

Returns

Storage

New 1-D storage holding the dropout mask.