def compute_mask_indices_for_one(
    sz,
    mask_prob: float,
    mask_length: int,
    seed=None,
    epoch=None,
    index=None,
    min_masks=0,
):
    """
    set seed, epoch, index for deterministic masking
    """
    seed = int(hash((seed, epoch, index)) % 1e6) if seed else None
    rng = np.random.default_rng(seed)

    # decide elements to mask
    mask = np.full(sz, False)
    num_mask = int(
        # add a random number for probabilistic rounding
        mask_prob * sz / float(mask_length)
        + rng.random()
    )
    num_mask = max(min_masks, num_mask)

    # multiple masking as described in the vq-wav2vec paper (https://arxiv.org/abs/1910.05453)
    mask_idc = rng.choice(sz, num_mask, replace=False)
    mask_idc = np.concatenate([mask_idc + i for i in range(mask_length)])
    mask_idc = mask_idc[mask_idc < len(mask)]
    try:
        mask[mask_idc] = True
    except:  # something wrong
        print(f"Assigning mask indexes {mask_idc} to mask {mask} failed!")
        raise

    return mask
set seed, epoch, index for deterministic masking
fairseq/data/data_utils.py