class_docstr: AutoCorrelation Mechanism with the following two phases:
  (1) period-based dependencies discovery
  (2) time delay aggregation
  This block can replace the self-attention family mechanism seamlessly.
class_docstr_tok: ["AutoCorrelation","Mechanism","with","the","following","two","phases",":","(","1",")","period-based","dependencies","discovery","(","2",")","time","delay","aggregation","This","block","can","replace","the","self-attention","family","mechanism","seamlessly","."]
code: def forward(self, queries, keys, values, attn_mask):
      B, L, H, E = queries.shape
      _, S, _, D = values.shape
      if L > S:
          zeros = torch.zeros_like(queries[:, : (L - S), :]).float()
          values = torch.cat([values, zeros], dim=1)
          keys = torch.cat([keys, zeros], dim=1)
      else:
          values = values[:, :L, :, :]
          keys = keys[:, :L, :, :]
  
      # period-based dependencies
      q_fft = torch.fft.rfft(
          queries.permute(0, 2, 3, 1).contiguous(), dim=-1
      )
      k_fft = torch.fft.rfft(
          keys.permute(0, 2, 3, 1).contiguous(), dim=-1
      )
      res = q_fft * torch.conj(k_fft)
      corr = torch.fft.irfft(res, dim=-1)
  
      # time delay agg
      if self.training:
          V = self.time_delay_agg_training(
              values.permute(0, 2, 3, 1).contiguous(), corr
          ).permute(0, 3, 1, 2)
      else:
          # V = self.time_delay_agg_inference(values.permute(0, 2, 3, 1)
          #                                   .contiguous(), corr).permute(0, 3, 1, 2)
          # change this to avoid the using of gather and improve the inference speed.
          V = self.time_delay_agg_training(
              values.permute(0, 2, 3, 1).contiguous(), corr
          ).permute(0, 3, 1, 2)
  
      if self.output_attention:
          return (V.contiguous(), corr.permute(0, 3, 1, 2))
      else:
          return (V.contiguous(), None)
  
file_path: BigDL/python/chronos/src/bigdl/chronos/model/autoformer/layers/AutoCorrelation.py
imports: import torch
  import torch.nn
  import torch.nn.functional
  import numpy
  import math
  from math import sqrt
  import os
label_desc: Use image node_id 5 for calling the AutoCorrelation obj's underlying member method code with example usage: obj.forward(queries, keys, values, attn_mask) and returns: V,  corr, V,  None