code: def _generate_mask(indices: Tensor, max_row_len: int) -> Tensor:
      """Generate a boolean mask by setting ``indices`` to ``True``."""
      float_mask = torch.zeros(
          (indices.size(0), max_row_len), device=indices.device
      )
  
      # Set elements corresponding to masked indices to 1.
      float_mask.scatter_(1, indices, 1.0)
  
      # Since mask spans may overlap, rows might have varying number of masked
      # elements; therefore, we have to randomly unmask some of the elements to
      # ensure that all rows have the same amount of masking.
      min_num_masked = int(
          torch.count_nonzero(float_mask, dim=-1).min()
      )
  
      # We randomly pick `min_num_masked` masked elements from each row, which
      # effectively unmasks the remaining elements.
      indices = torch.multinomial(
          float_mask, num_samples=min_num_masked
      )
  
      # Now we construct the actual boolean mask which has the same number of
      # masked elements in each row.
      bool_mask = torch.full_like(float_mask, False, dtype=torch.bool)
  
      return bool_mask.scatter_(1, indices, True)
  
file_path: fairseq2/src/fairseq2/nn/utils/mask.py
imports: from typing import Optional, Tuple
  import torch
  from torch import Tensor
  from fairseq2.nn.ops import repeat_interleave
  from fairseq2.typing import DataType, Device
label_desc: Use image node_id 4 for calling a global function with example usage: _generate_mask(indices, max_row_len) and returns: bool_mask