class_docstr: Attention Layer as used in Vision Transformer.
class_docstr_tok: ["Attention","Layer","as","used","in","Vision","Transformer","."]
code: def forward(self, x, register_hook=False):
      B, N, C = x.shape
      qkv = (
          self.qkv(x)
          .reshape(B, N, 3, self.num_heads, C // self.num_heads)
          .permute(2, 0, 3, 1, 4)
      )
      q, k, v = (
          qkv[0],
          qkv[1],
          qkv[2],
      )  # make torchscript happy (cannot use tensor as tuple)
  
      attn = (q @ k.transpose(-2, -1)) * self.scale
      attn = attn.softmax(dim=-1)
      attn = self.attn_drop(attn)
  
      if register_hook:
          self.save_attention_map(attn)
          attn.register_hook(self.save_attn_gradients)
  
      x = (attn @ v).transpose(1, 2).reshape(B, N, C)
      x = self.proj(x)
      x = self.proj_drop(x)
      return x
  
imports: import collections.abc
  import math
  import warnings
  from dataclasses import dataclass
  from functools import partial
  from itertools import repeat
  import omegaconf
  import torch
  import torch.nn
  import torch.nn.functional
  from mmf.common.registry import registry
  from mmf.modules.encoders import Encoder
label_desc: Use image node_id 6 for calling the Attention obj's underlying member method code with example usage: obj.forward(x, register_hook) and returns: x