code: def efficient_causal_attention_seq(x, y, z):
      """
      efficient causal attention operation
      Args:
          x (Tensor): Tensor with shape `(batch, n, d1)`
          y (Tensor): Tensor with shape `(batch, n, d1)`
          z (Tensor): Tensor with shape '(batch, n, d2)`
      return:
      """
      n = x.size(1)
      rets = []
      accum_mat = 0
      for i in range(n):
          xx = x[:, i : i + 1]  # B x 1 x d1
          yy = y[:, i : i + 1]  # B x 1 x d1
          zz = z[:, i : i + 1]  # B x 1 x d2
  
          # B x d1 x d2
          accum_mat = accum_mat + torch.bmm(yy.transpose(1, 2), zz)
          # B x 1 x d2
          rets.append(torch.bmm(xx, accum_mat).div(i + 1.0))
      # B x N x d2
      return torch.cat(rets, dim=1)
  
imports: import math
  from typing import Dict, Optional, Tuple, Union
  import torch
  import torch.nn.functional
  from fairseq import utils
  from fairseq.incremental_decoding_utils import with_incremental_state
  from fairseq.modules.fairseq_dropout import FairseqDropout
  from torch import nn, Tensor
label_desc: Use image node_id 1 for calling a global function with example usage: efficient_causal_attention_seq(x, y, z) and returns: torch