Skip to content
fn

random_mask

→Tensor
random_mask(base_layer: nn.Module, r: int, random_seed: int | None = None)

A random sparse mask for base_layer's weight with r (dout+din)r\,(d_{out} + d_{in}) ones.

Parameters

base_layernn.Module
The module whose weight the mask is for.
rint
The rank the number of ones is sized after.
random_seedint= None
Seed of the permutation; None is the reference's default seed.

Returns

Tensor

(d_out, d_in) float tensor of 0 and 1, on the weight's device.

Raises

ValueError
r (d_out + d_in) exceeds the number of weight entries.

Used by 2