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
  
  ::
  
                                     PatchEmbed
                                         ↓
                                 PositionalEncoding
                                         ↓
                                      Dropout
                                         ↓
                                   Normalization
                                         ↓
                                       Block 1
                                         ↓
                                         .
                                         .
                                         .
                                         ↓
                                       Block N
                                         ↓
                                   Normalization
                                         ↓
                                        Head
  
  
  The builder can be found in `create_mvit`.
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",":",":","PatchEmbed","\u2193","PositionalEncoding","\u2193","Dropout","\u2193","Normalization","\u2193","Block","1","\u2193",".",".",".","\u2193","Block","N","\u2193","Normalization","\u2193","Head","The","builder","can","be","found","in","`","create_mvit","`","."]
code: def fuse_bn(self):
      assert not self.training
      for blk in self.blocks:
          # fuse self.norm1
          if blk.attn.separate_qkv:
              blk.attn.q = self.fuse_norm_before_linear(
                  blk.norm1, blk.attn.q
              )
              blk.attn.k = self.fuse_norm_before_linear(
                  blk.norm1, blk.attn.k
              )
              blk.attn.v = self.fuse_norm_before_linear(
                  blk.norm1, blk.attn.v
              )
          else:
              blk.attn.qkv = self.fuse_norm_before_linear(
                  blk.norm1, blk.attn.qkv
              )
          blk.norm1 = nn.Identity()
  
          # fuse the bn in attention
          if blk.attn.separate_qkv:
              blk.attn.q = self.fuse_norm_after_linear(
                  blk.attn.q, blk.attn.norm_q
              )
              blk.attn.k = self.fuse_norm_after_linear(
                  blk.attn.k, blk.attn.norm_k
              )
              blk.attn.v = self.fuse_norm_after_linear(
                  blk.attn.v, blk.attn.norm_v
              )
          else:
              w_q, w_k, w_v = blk.attn.qkv.weight.chunk(3)
              b_q, b_k, b_v = blk.attn.qkv.bias.chunk(3)
              tmp_q = nn.Linear(w_q.shape[1], w_q.shape[0], bias=True)
              tmp_k = nn.Linear(w_k.shape[1], w_k.shape[0], bias=True)
              tmp_v = nn.Linear(w_v.shape[1], w_v.shape[0], bias=True)
              tmp_q.weight.data[:] = w_q
              tmp_k.weight.data[:] = w_k
              tmp_v.weight.data[:] = w_v
              tmp_q.bias.data[:] = b_q
              tmp_k.bias.data[:] = b_k
              tmp_v.bias.data[:] = b_v
              tmp_q = self.fuse_norm_after_linear(
                  tmp_q, blk.attn.norm_q
              )
              tmp_k = self.fuse_norm_after_linear(
                  tmp_k, blk.attn.norm_k
              )
              tmp_v = self.fuse_norm_after_linear(
                  tmp_v, blk.attn.norm_v
              )
              blk.attn.qkv.weight.data[:] = torch.cat(
                  [
                      tmp_q.weight.data,
                      tmp_k.weight.data,
                      tmp_v.weight.data,
                  ],
                  dim=0,
              )
              blk.attn.qkv.bias.data[:] = torch.cat(
                  [tmp_q.bias.data, tmp_k.bias.data, tmp_v.bias.data],
                  dim=0,
              )
  
          blk.attn.norm_q = nn.Identity()
          blk.attn.norm_k = nn.Identity()
          blk.attn.norm_v = nn.Identity()
  
          # fuse self.norm2
          blk.mlp.fc1 = self.fuse_norm_before_linear(
              blk.norm2, blk.mlp.fc1
          )
          if blk.dim != blk.dim_out:
              blk.proj = self.fuse_norm_before_linear(
                  blk.norm2, blk.proj
              )
          blk.norm2 = nn.Identity()
  
file_path: pytorchvideo/pytorchvideo/models/vision_transformers.py
imports: import warnings
  from functools import partial
  from typing import Callable, List, Optional, Tuple
  import torch
  import torch.nn
  from pytorchvideo.layers import MultiScaleBlock, SpatioTemporalClsPositionalEncoding
  from pytorchvideo.layers.utils import round_width, set_attributes
  from pytorchvideo.models.head import create_vit_basic_head
  from pytorchvideo.models.weight_init import init_net_weights
  from torch.nn.common_types import _size_2_t, _size_3_t
  from .stem import create_conv_patch_embed
label_desc: Use image node_id 5 for calling the MultiscaleVisionTransformers obj's underlying member method code with example usage: obj.fuse_bn() without return types