code: def random_token_mask(
      size: Tuple[int, int],
      mask_ratio: float = 0.6,
      mask_class_token: bool = False,
      device: Optional[Union[torch.device, str]] = None,
  ) -> torch.Tensor:
      """Creates random token masks.
  
      Args:
          size:
              Size of the token batch for which to generate masks.
              Should be (batch_size, sequence_length).
          mask_ratio:
              Percentage of tokens to mask.
          mask_class_token:
              If False the class token is never masked. If True the class token
              might be masked.
          device:
              Device on which to create the index masks.
  
      Returns:
          A (index_keep, index_mask) tuple where each index is a tensor.
          index_keep contains the indices of the unmasked tokens and has shape
          (batch_size, num_keep). index_mask contains the indices of the masked
          tokens and has shape (batch_size, sequence_length - num_keep).
          num_keep is equal to sequence_length * (1- mask_ratio).
  
      """
      batch_size, sequence_length = size
      num_keep = int(sequence_length * (1 - mask_ratio))
  
      noise = torch.rand(batch_size, sequence_length, device=device)
      if not mask_class_token and sequence_length > 0:
          # make sure that class token is not masked
          noise[:, 0] = -1
          num_keep = max(1, num_keep)
  
      # get indices of tokens to keep
      indices = torch.argsort(noise, dim=1)
      idx_keep = indices[:, :num_keep]
      idx_mask = indices[:, num_keep:]
  
      return idx_keep, idx_mask
  
imports: import math
  import warnings
  from typing import Iterable, List, Optional, Tuple, Union
  import numpy
  import torch
  import torch.distributed
  import torch.nn
  from numpy.typing import NDArray
  from torch.nn import Module
  from torch.nn.modules.batchnorm import _BatchNorm
  from torch.nn.parameter import Parameter
label_desc: Use image node_id 18 for calling a global function with example usage: random_token_mask(size, mask_ratio, mask_class_token, device) and returns: idx_keep,  idx_mask