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","."]
docstr: Initialize positional self-attention layer to be local (i.e.
  equivalent to convolution).
  Args:
      locality_strength: Controls strength of locality. See explanation
      above.
docstr_tok: ["Initialize","positional","self-attention","layer","to","be","local","(","i.e",".","equivalent","to","convolution",")",".","Args",":","locality_strength",":","Controls","strength","of","locality",".","See","explanation","above","."]
code: def init_local(self, locality_strength=1.0):
      """
      Initialize positional self-attention layer to be local (i.e.
      equivalent to convolution).
      Args:
          locality_strength: Controls strength of locality. See explanation
          above.
      """
  
      self.v.weight.data.copy_(torch.eye(self.dim))
      locality_distance = 1
  
      kernel_size = int(self.num_heads**0.5)
      if kernel_size % 2 == 0:
          center = (kernel_size - 1) / 2
      else:
          center = kernel_size // 2
      for h1 in range(kernel_size):
          for h2 in range(kernel_size):
              position = h1 + kernel_size * h2
              self.pos_proj.weight.data[
                  position, : 3 * self.locality_dim
              ] = -1
              self.pos_proj.weight.data[
                  position, : 2 * self.locality_dim
              ] = (2 * (h1 - center) * locality_distance)
              self.pos_proj.weight.data[
                  position, : 1 * self.locality_dim
              ] = (2 * (h2 - center) * locality_distance)
      self.pos_proj.weight.data *= locality_strength
  
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 6 for calling the GPSA obj's underlying member method code with example usage: obj.init_local(locality_strength) without return types