class_docstr: Sparse Multi-Headed Attention.
  
  "Generating Long Sequences with Sparse Transformers". Implements
  fixed factorized self attention, where l=stride and c=expressivity.
  A(1) includes all words in the stride window and A(2) takes a summary of c
  words from the end of each stride window.
  If is_bidirectional=False, we do not include any words past the current word,
  as in the paper.
class_docstr_tok: ["Sparse","Multi-Headed","Attention",".","``","Generating","Long","Sequences","with","Sparse","Transformers","''",".","Implements","fixed","factorized","self","attention",",","where","l=stride","and","c=expressivity",".","A","(","1",")","includes","all","words","in","the","stride","window","and","A","(","2",")","takes","a","summary","of","c","words","from","the","end","of","each","stride","window",".","If","is_bidirectional=False",",","we","do","not","include","any","words","past","the","current","word",",","as","in","the","paper","."]
code: def buffered_sparse_mask(self, tensor, tgt_len, src_len):
      assert tgt_len > self.stride
      sparse_mask = (
          torch.empty((tgt_len, src_len)).float().fill_(float("-inf"))
      )
  
      # If bidirectional, subset 2 is the same for every index
      subset_summaries = set()
      if self.is_bidirectional:
          subset_summaries = self.compute_subset_summaries(tgt_len)
  
      for i in range(tgt_len):
          fixed_attention_subset = self.compute_fixed_attention_subset(
              i, tgt_len
          )
          fixed_attention_subset = fixed_attention_subset.union(
              subset_summaries
          )
          included_word_indices = torch.LongTensor(
              list(fixed_attention_subset)
          )
          sparse_mask[i].index_fill_(0, included_word_indices, 0)
      return sparse_mask.type_as(tensor)
  
file_path: fairseq/fairseq/modules/sparse_multihead_attention.py
imports: import math
  import torch
  from .multihead_attention import MultiheadAttention
label_desc: Use image node_id 5 for calling the SparseMultiheadAttention obj's underlying member method code with example usage: obj.buffered_sparse_mask(tensor, tgt_len, src_len) and returns: sparse_mask