class_docstr: A multiscale attention block.
  compare to a conventional attention block, a multiscale attention block optionally
  supports pooling (either before or after qkv projection). If pooling is not used, a
  multiscale attention block is equivalent to a conventional attention block.
  ::
                                 Input
                                   |
                  |----------------|-----------------|
                  ↓                ↓                 ↓
                Linear           Linear            Linear
                  &                &                 &
               Pool (Q)         Pool (K)          Pool (V)
                  → -------------- ←                 |
                           ↓                         |
                     MatMul & Scale                  |
                           ↓                         |
                        Softmax                      |
                           → ----------------------- ←
                                       ↓
                                 MatMul & Scale
                                       ↓
                                    DropOut
  Args:
      dim(`int`):
          Input feature dimension.
      num_heads(`int`):
          number of heads in the attention layer.
      qkv_bias(`bool`):
          If set to False, the qkv layer will not learn an additive bias.
      dropout_rate(`float`):
          Dropout rate.
      kernel_q(`_size_3_t`):
          Pooling kernel size for q. If both pooling kernel
          size and pooling stride size are 1 for all the dimensions, pooling is disabled.
      kernel_kv(`_size_3_t`):
          Pooling kernel size for kv. If both pooling kernel size and pooling stride size
          are 1 for all the dimensions, pooling is disabled.
      stride_q(`_size_3_t`):
          Pooling kernel stride for q.
      stride_kv(`_size_3_t`):
          Pooling kernel stride for kv.
      norm_layer(`nn.Module`):
          normalization layer used after pooling.
      has_cls_embed(`bool`):
          If set to True, the first token of the input tensor
          should be a cls token. Otherwise, the input tensor does not contain a cls token.
          Pooling is not applied to the cls token.
      pool_mode(`str`):
          Pooling mode. Option includes "conv" (learned pooling), "avg"
          (average pooling), and "max" (max pooling).
      pool_first(`bool`):
          If set to True, pool is applied before qkv projection.
          Otherwise, pool is applied after qkv projection.
class_docstr_tok: ["A","multiscale","attention","block",".","compare","to","a","conventional","attention","block",",","a","multiscale","attention","block","optionally","supports","pooling","(","either","before","or","after","qkv","projection",")",".","If","pooling","is","not","used",",","a","multiscale","attention","block","is","equivalent","to","a","conventional","attention","block",".",":",":","Input","|","|","--","--","--","--","--","--","--","--","|","--","--","--","--","--","--","--","--","-|","\u2193","\u2193","\u2193","Linear","Linear","Linear","&","&","&","Pool","(","Q",")","Pool","(","K",")","Pool","(","V",")","\u2192","--","--","--","--","--","--","--","\u2190","|","\u2193","|","MatMul","&","Scale","|","\u2193","|","Softmax","|","\u2192","--","--","--","--","--","--","--","--","--","--","--","-","\u2190","\u2193","MatMul","&","Scale","\u2193","DropOut","Args",":","dim","(","`","int","`",")",":","Input","feature","dimension",".","num_heads","(","`","int","`",")",":","number","of","heads","in","the","attention","layer",".","qkv_bias","(","`","bool","`",")",":","If","set","to","False",",","the","qkv","layer","will","not","learn","an","additive","bias",".","dropout_rate","(","`","float","`",")",":","Dropout","rate",".","kernel_q","(","`","_size_3_t","`",")",":","Pooling","kernel","size","for","q",".","If","both","pooling","kernel","size","and","pooling","stride","size","are","1","for","all","the","dimensions",",","pooling","is","disabled",".","kernel_kv","(","`","_size_3_t","`",")",":","Pooling","kernel","size","for","kv",".","If","both","pooling","kernel","size","and","pooling","stride","size","are","1","for","all","the","dimensions",",","pooling","is","disabled",".","stride_q","(","`","_size_3_t","`",")",":","Pooling","kernel","stride","for","q.","stride_kv","(","`","_size_3_t","`",")",":","Pooling","kernel","stride","for","kv",".","norm_layer","(","`","nn.Module","`",")",":","normalization","layer","used","after","pooling",".","has_cls_embed","(","`","bool","`",")",":","If","set","to","True",",","the","first","token","of","the","input","tensor","should","be","a","cls","token",".","Otherwise",",","the","input","tensor","does","not","contain","a","cls","token",".","Pooling","is","not","applied","to","the","cls","token",".","pool_mode","(","`","str","`",")",":","Pooling","mode",".","Option","includes","``","conv","''","(","learned","pooling",")",",","``","avg","''","(","average","pooling",")",",","and","``","max","''","(","max","pooling",")",".","pool_first","(","`","bool","`",")",":","If","set","to","True",",","pool","is","applied","before","qkv","projection",".","Otherwise",",","pool","is","applied","after","qkv","projection","."]
docstr: Args:
      q(torch.Tensor):
          q tensor.
      k(torch.Tensor):
          k tensor.
      v(torch.Tensor):
          v tensor.
      q_n(int):
          k tensor size.
      v_n(int):
          v tensor size.
      k_n(int):
          k tensor size.
      b(int):
          Reshaped size.
      c(int):
          Reshaped size.
docstr_tok: ["Args",":","q","(","torch.Tensor",")",":","q","tensor",".","k","(","torch.Tensor",")",":","k","tensor",".","v","(","torch.Tensor",")",":","v","tensor",".","q_n","(","int",")",":","k","tensor","size",".","v_n","(","int",")",":","v","tensor","size",".","k_n","(","int",")",":","k","tensor","size",".","b","(","int",")",":","Reshaped","size",".","c","(","int",")",":","Reshaped","size","."]
code: def reshape_qkv_to_seq(
      self,
      q,
      k,
      v,
      q_n,
      v_n,
      k_n,
      b,
      c,
  ) -> Tuple[int]:
      """
      Args:
          q(torch.Tensor):
              q tensor.
          k(torch.Tensor):
              k tensor.
          v(torch.Tensor):
              v tensor.
          q_n(int):
              k tensor size.
          v_n(int):
              v tensor size.
          k_n(int):
              k tensor size.
          b(int):
              Reshaped size.
          c(int):
              Reshaped size.
      """
      q = q.permute(0, 2, 1, 3).reshape(b, q_n, c)
      v = v.permute(0, 2, 1, 3).reshape(b, v_n, c)
      k = k.permute(0, 2, 1, 3).reshape(b, k_n, c)
      return q, k, v
  
file_path: towhee/towhee/models/layers/multi_scale_attention.py
imports: import torch
  from torch import nn
  from typing import List, Tuple
  import numpy
  from towhee.models.layers.pool_attention import AttentionPool
label_desc: Use image node_id 5 for calling the MultiScaleAttention obj's underlying member method code with example usage: obj.reshape_qkv_to_seq(q, k, v, q_n, v_n, k_n, b, c) and returns: q,  k,  v