class_docstr: Gated positional self-attention. This is what makes a ConViT a ConViT.
  The "gating" refers to lambda, the parameter that controls the relative
  contribution (i.e. gating) of positional vs. content-based attention in
  each head.
class_docstr_tok: ["Gated","positional","self-attention",".","This","is","what","makes","a","ConViT","a","ConViT",".","The","``","gating","''","refers","to","lambda",",","the","parameter","that","controls","the","relative","contribution","(","i.e",".","gating",")","of","positional","vs.","content-based","attention","in","each","head","."]
code: def set_rel_indices(self, num_patches):
      # Set relative position embeddings
      img_size = int(num_patches**0.5)
      rel_indices = torch.zeros(
          1, num_patches, num_patches, 3 * self.locality_dim
      )
      ind = torch.arange(img_size).view(1, -1) - torch.arange(
          img_size
      ).view(-1, 1)
      indx = ind.repeat(img_size, img_size)
      indy = ind.repeat_interleave(img_size, dim=0).repeat_interleave(
          img_size, dim=1
      )
      indd = indx**2 + indy**2
      rel_indices[:, :, :, : 3 * self.locality_dim] = indd.unsqueeze(-1)
      rel_indices[:, :, :, : 2 * self.locality_dim] = indy.unsqueeze(-1)
      rel_indices[:, :, :, : 1 * self.locality_dim] = indx.unsqueeze(-1)
      self.register_buffer("rel_indices", rel_indices, persistent=False)
      # Hacky way of setting device
      device = list(self.parameters())[0].device
      self.rel_indices = self.rel_indices.to(device)
  
imports: import copy
  import logging
  import math
  import torch
  import torch.nn
  from vissl.models.model_helpers import DropPath, to_2tuple, trunc_normal_
  from vissl.models.trunks import register_model_trunk
  from vissl.utils.hydra_config import AttrDict
label_desc: Use image node_id 7 for calling the GPSA obj's underlying member method code with example usage: obj.set_rel_indices(num_patches) without return types