class_docstr: Average attention with window.
  See "Accelerating Neural Transformer via an Average Attention Network"
  for more details.
code: def _forward_incremental(
      self, value, mask_trick, mask_future_timesteps, incremental_state
  ):
      if self.window_size == 1:
          return value, None
      length, batch_size = value.size()[:2]
      if mask_trick:
          saved_state = self._get_input_buffer(incremental_state)
          if "prev_vec" in saved_state:
              value = torch.cat([saved_state["prev_vec"], value], dim=0)
          saved_state["prev_vec"] = value[-self.window_size :]
          self._set_input_buffer(incremental_state, saved_state)
          attn_weights = None
          attn = value.mean(0, keepdim=True)
      else:
          saved_state = self._get_input_buffer(incremental_state)
          if "prev_sum" in saved_state:
              prev_sum = saved_state["prev_sum"]
              values = torch.cat(
                  [saved_state["prev_vec"], value], dim=0
              )
              curr_sum = prev_sum + value
              if values.size(0) > self.window_size:
                  curr_sum -= values[:1]
              avg_size = min(values.size(0), self.window_size)
              attn = curr_sum / avg_size
          else:
              curr_sum = value
              values = value
              attn = value
          saved_state["prev_vec"] = values[-self.window_size :]
          saved_state["prev_sum"] = curr_sum
          self._set_input_buffer(incremental_state, saved_state)
          attn_weights = None
      return attn, attn_weights
  
imports: import torch
  import torch.nn.functional
  from fairseq import utils
  from fairseq.incremental_decoding_utils import with_incremental_state
  from torch import nn
label_desc: Use image node_id 3 for calling the AverageWindowAttention obj's underlying member method code with example usage: obj._forward_incremental(value, mask_trick, mask_future_timesteps, incremental_state) and returns: attn,  attn_weights, value,  None