docstr: Perform per-sample random masking by per-sample shuffling.
  Per-sample shuffling is done by argsort random noise.
  x: [N, L, D], sequence
docstr_tok: ["Perform","per-sample","random","masking","by","per-sample","shuffling",".","Per-sample","shuffling","is","done","by","argsort","random","noise",".","x",":","[","N",",","L",",","D","]",",","sequence"]
code: def _mae_random_masking(self, x, mask_ratio, mask_in=None):
      """
      Perform per-sample random masking by per-sample shuffling.
      Per-sample shuffling is done by argsort random noise.
      x: [N, L, D], sequence
      """
      N, L, D = x.shape  # batch, length, dim
      if mask_in is None:
          if self.cfg.AUG.MASK_TUBE:
              noise = (
                  torch.rand(N, 1, self.H * self.W, device=x.device)
                  .repeat([1, self.T, 1])
                  .reshape(N, L)
              )  # noise in [0, 1]
          else:
              noise = torch.rand(
                  N, L, device=x.device
              )  # noise in [0, 1]
      else:
          noise = mask_in.flatten(1)
          mask_ratio = (
              sum(noise.flatten()) / noise.numel()
          )  # alrdy masked
      len_keep = int(L * (1 - mask_ratio))
      assert len_keep > 1
      # sort noise for each sample
      ids_shuffle = torch.argsort(
          noise, dim=1
      )  # ascend: small is keep, large is remove
      ids_restore = torch.argsort(ids_shuffle, dim=1)
      # keep the first subset
      ids_keep = ids_shuffle[:, :len_keep]
      x_masked = torch.gather(
          x, dim=1, index=ids_keep.unsqueeze(-1).repeat(1, 1, D)
      )
      # generate the binary mask: 0 is keep, 1 is remove
      mask = torch.ones([N, L], device=x.device)
      mask[:, :len_keep] = 0
      # unshuffle to get the binary mask
      mask = torch.gather(mask, dim=1, index=ids_restore)
      return x_masked, mask, ids_restore, ids_keep
  
imports: import math
  from functools import partial
  import torch
  import torch.nn
  import torch.nn.functional
  from torch.nn.init import trunc_normal_
  import slowfast.utils.logging
  import slowfast.utils.misc
  from slowfast.models import head_helper
  from slowfast.models.attention import attention_pool
  from slowfast.models.utils import calc_mvit_feature_geometry
  from slowfast.models.video_model_builder import MViT
  from .None import head_helper, operators, resnet_helper, stem_helper
  from .build import MODEL_REGISTRY
label_desc: Use image node_id 11 for calling the MaskMViT obj's underlying member method code with example usage: obj._mae_random_masking(x, mask_ratio, mask_in) and returns: x_masked,  mask,  ids_restore,  ids_keep