code: def cumulative_average_mask(
      batch_size: int, t_len: int, device: Optional[torch.device] = None
  ) -> Tensor:
      """
      Builds the mask to compute the cumulative average as described in
      :cite:`DBLP:journals/corr/abs-1805-00631` -- Figure 3
      Args:
          batch_size (int): batch size
          t_len (int): length of the layer_in
  
      Returns:
          (Tensor):
          * A Tensor of shape ``(batch_size, t_len, t_len)``
      """
  
      triangle = torch.tril(
          torch.ones(t_len, t_len, dtype=torch.float, device=device)
      )
      weights = torch.ones(
          1, t_len, dtype=torch.float, device=device
      ) / torch.arange(1, t_len + 1, dtype=torch.float, device=device)
      mask = triangle * weights.transpose(0, 1)
  
      return mask.unsqueeze(0).expand(batch_size, t_len, t_len)
  
file_path: OpenNMT-py/onmt/modules/average_attn.py
imports: import torch
  import torch.nn
  from torch import Tensor
  from typing import Optional
  from onmt.modules.position_ffn import PositionwiseFeedForward
  from onmt.modules.position_ffn import ActivationFunction
label_desc: Use image node_id 1 for calling a global function with example usage: cumulative_average_mask(batch_size, t_len, device) and returns: mask