class_docstr: This layer applies a self-attention with linear complexity, as described in `https://arxiv.org/abs/2206.02680`
  This layer can be used for self- as well as cross-attention.
  Args:
      embed_dim (int): :math:`C` from an expected input of size :math:`(N, C, H, W)`
      attn_drop (float): Dropout value for context scores. Default: 0.0
      bias (bool): Use bias in learnable layers. Default: True
  Shape:
      - Input: :math:`(N, C, P, N)` where :math:`N` is the batch size, :math:`C` is the input channels,
      :math:`P` is the number of pixels in the patch, and :math:`N` is the number of patches
      - Output: same as the input
  .. note::
      For MobileViTv2, we unfold the feature map [B, C, H, W] into [B, C, P, N] where P is the number of pixels
      in a patch and N is the number of patches. Because channel is the first dimension in this unfolded tensor,
      we use point-wise convolution (instead of a linear layer). This avoids a transpose operation (which may be
      expensive on resource-constrained devices) that may be required to convert the unfolded tensor from
      channel-first to channel-last format in case of a linear layer.
class_docstr_tok: ["This","layer","applies","a","self-attention","with","linear","complexity",",","as","described","in","`","https",":","\/\/arxiv.org\/abs\/2206.02680","`","This","layer","can","be","used","for","self-","as","well","as","cross-attention",".","Args",":","embed_dim","(","int",")",":",":","math",":","`","C","`","from","an","expected","input","of","size",":","math",":","`","(","N",",","C",",","H",",","W",")","`","attn_drop","(","float",")",":","Dropout","value","for","context","scores",".","Default",":","0.0","bias","(","bool",")",":","Use","bias","in","learnable","layers",".","Default",":","True","Shape",":","-","Input",":",":","math",":","`","(","N",",","C",",","P",",","N",")","`","where",":","math",":","`","N","`","is","the","batch","size",",",":","math",":","`","C","`","is","the","input","channels",",",":","math",":","`","P","`","is","the","number","of","pixels","in","the","patch",",","and",":","math",":","`","N","`","is","the","number","of","patches","-","Output",":","same","as","the","input","..","note",":",":","For","MobileViTv2",",","we","unfold","the","feature","map","[","B",",","C",",","H",",","W","]","into","[","B",",","C",",","P",",","N","]","where","P","is","the","number","of","pixels","in","a","patch","and","N","is","the","number","of","patches",".","Because","channel","is","the","first","dimension","in","this","unfolded","tensor",",","we","use","point-wise","convolution","(","instead","of","a","linear","layer",")",".","This","avoids","a","transpose","operation","(","which","may","be","expensive","on","resource-constrained","devices",")","that","may","be","required","to","convert","the","unfolded","tensor","from","channel-first","to","channel-last","format","in","case","of","a","linear","layer","."]
code: def __init__(
      self,
      embed_dim: int,
      attn_drop: float = 0.0,
      proj_drop: float = 0.0,
      bias: bool = True,
  ) -> None:
      super().__init__()
      self.embed_dim = embed_dim
  
      self.qkv_proj = nn.Conv2d(
          in_channels=embed_dim,
          out_channels=1 + (2 * embed_dim),
          bias=bias,
          kernel_size=1,
      )
      self.attn_drop = nn.Dropout(attn_drop)
      self.out_proj = nn.Conv2d(
          in_channels=embed_dim,
          out_channels=embed_dim,
          bias=bias,
          kernel_size=1,
      )
      self.out_drop = nn.Dropout(proj_drop)
  
imports: import math
  from typing import Callable, Tuple, Optional
  import torch
  import torch.nn.functional
  from torch import nn
  from timm.layers import to_2tuple, make_divisible, GroupNorm1, ConvMlp, DropPath, is_exportable
  from ._builder import build_model_with_cfg
  from ._features_fx import register_notrace_module
  from ._registry import register_model, generate_default_cfgs, register_model_deprecations
  from .byobnet import register_block, ByoBlockCfg, ByoModelCfg, ByobNet, LayerFn, num_groups
  from .vision_transformer import Block
label_desc: Use image node_id 1 to create a new LinearSelfAttention object from inherited base classes: nn with example: obj = LinearSelfAttention(embed_dim, attn_drop, proj_drop, bias)