class_docstr: Efficient Additive Attention module for SwiftFormer.
  
  Input: tensor of shape `[batch_size, channels, height, width]`
  
  Output: tensor of shape `[batch_size, channels, height, width]`
class_docstr_tok: ["Efficient","Additive","Attention","module","for","SwiftFormer",".","Input",":","tensor","of","shape","`","[","batch_size",",","channels",",","height",",","width","]","`","Output",":","tensor","of","shape","`","[","batch_size",",","channels",",","height",",","width","]","`"]
code: def forward(self, x):
      query = self.to_query(x)
      key = self.to_key(x)
  
      query = torch.nn.functional.normalize(query, dim=-1)
      key = torch.nn.functional.normalize(key, dim=-1)
  
      query_weight = query @ self.w_g
      scaled_query_weight = query_weight * self.scale_factor
      scaled_query_weight = scaled_query_weight.softmax(dim=-1)
  
      global_queries = torch.sum(scaled_query_weight * query, dim=1)
      global_queries = global_queries.unsqueeze(1).repeat(
          1, key.shape[1], 1
      )
  
      out = self.proj(global_queries * key) + query
      out = self.final(out)
  
      return out
  
imports: import collections.abc
  from typing import Optional, Tuple, Union
  import torch
  import torch.utils.checkpoint
  from torch import nn
  from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
  from ...activations import ACT2CLS
  from ...modeling_outputs import BaseModelOutputWithNoAttention, ImageClassifierOutputWithNoAttention
  from ...modeling_utils import PreTrainedModel
  from ...utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, logging
  from .configuration_swiftformer import SwiftFormerConfig
label_desc: Use image node_id 2 for calling the SwiftFormerEfficientAdditiveAttention obj's underlying member method code with example usage: obj.forward(x) and returns: out