class_docstr: Multiscale Vision Transformers
  Haoqi Fan, Bo Xiong, Karttikeya Mangalam, Yanghao Li, Zhicheng Yan, Jitendra Malik, Christoph Feichtenhofer
  https://arxiv.org/abs/2104.11227
class_docstr_tok: ["Multiscale","Vision","Transformers","Haoqi","Fan",",","Bo","Xiong",",","Karttikeya","Mangalam",",","Yanghao","Li",",","Zhicheng","Yan",",","Jitendra","Malik",",","Christoph","Feichtenhofer","https",":","\/\/arxiv.org\/abs\/2104.11227"]
code: def relprop(
      self,
      cam: torch.Tensor,
      method: str = "rollout",
      start_layer: int = 0,
      **kwargs,
  ) -> torch.Tensor:
      cam = self.head.relprop(cam, **kwargs)
      if self.cls_embed_on:
          cam = cam.unsqueeze(1)
          cam = self.index_select.relprop(cam, **kwargs)
      cam = self.norm.relprop(cam, **kwargs)
      thw = self.out_thw
      for blk in reversed(self.blocks):
          cam, thw = blk.relprop(cam, thw=thw, **kwargs)
  
      if method == "full":
          (cam, _) = self.add.relprop(cam, **kwargs)
          if self.cls_embed_on:
              cam = cam[:, 1:]
          cam = self.patch_embed.relprop(cam, **kwargs)
          # sum on channels
          cam = cam.sum(dim=1)
          return cam
      elif method == "rollout":
          # cam rollout
          attn_cams = []
          for blk in self.blocks:
              attn_heads = blk.attn.get_attn_cam().clamp(min=0)
              avg_heads = (
                  attn_heads.sum(dim=1) / attn_heads.shape[1]
              ).detach()
              attn_cams.append(avg_heads)
          cam = compute_rollout_attention(
              attn_cams, start_layer=start_layer
          )
          cam = cam[:, 0, 1:]
          return cam
  
      elif method in ("transformer_attribution", "grad"):
          cams = []
          for blk in self.blocks:
              grad = blk.attn.get_attn_gradients()
              cam = blk.attn.get_attn_cam()
              cam = cam[0].reshape(-1, cam.shape[-2], cam.shape[-1])
              grad = grad[0].reshape(-1, grad.shape[-2], grad.shape[-1])
              cam = grad * cam
              cam = cam.clamp(min=0).mean(dim=0)
              cams.append(cam.unsqueeze(0))
          rollout = compute_rollout_attention(
              cams, start_layer=start_layer
          )
          cam = rollout[:, 0, 1:]
          return cam
  
imports: import math
  from functools import partial
  from typing import Tuple, List
  import numpy
  import torch
  from torch import nn
  from torch.nn.init import trunc_normal_
  from einops import rearrange
  from towhee.models.layers.layers_with_relprop import GELU, Linear, Dropout, Conv2d, Conv3d, Softmax, Sigmoid, LayerNorm, Einsum, Add, Clone, MaxPool3d, IndexSelect
label_desc: Use image node_id 4 for calling the MViT obj's underlying member method code with example usage: obj.relprop(cam, method, start_layer) and returns: cam, cam, cam