text: 
  
  TITLE
  How to get cross attention for bert when config.add_cross_attention is True
  
  COMMENTS
  4
  
  REACTIONS
  +1: 0
  -1: 0
  laugh: 0
  hooray: 0
  heart: 0
  rocket: 0
  eyes: 0
  
  BODY
  # ❓ Questions & Help
  
  <!-- The GitHub issue tracker is primarly intended for bugs, feature requests,
       new models and benchmarks, and migration questions. For all other questions,
       we direct you to the Hugging Face forum: https://discuss.huggingface.co/ .
       You can also try Stack Overflow (SO) where a whole community of PyTorch and
       Tensorflow enthusiast can help you out. In this case, make sure to tag your
       question with the right deep learning framework as well as the
       huggingface-transformers tag: 
       https://stackoverflow.com/questions/tagged/huggingface-transformers 
       -->
  
  ## Details
  <!-- Description of your issue -->
  As far as I can tell, when using BERT with cross attention and output_attention is True, the returned attention only contains self attention (i.e. a tuple of length num_hidden_layers with size (batch_size, num_head, seq_length, seq_length)). How can I get the cross attention weights in that case?
  
  After digging a little bit, I saw that ModelOutput (and child classes) do not include cross attention as potential outputs. The cross attention is returned by [BertLayer](https://github.com/huggingface/transformers/blob/master/src/transformers/modeling_bert.py#L420) (at index 2) but then ignored in [BertEncoder](https://github.com/huggingface/transformers/blob/master/src/transformers/modeling_bert.py#L486). A quick look at the outputs for Encoder-Decoder models shows the same issue. Would it be possible to include cross attention in model outputs? And if yes, how can I help doing so?
  
  <!-- You should first ask your question on the forum or SO, and only if
       you didn't get an answer ask it here on GitHub. -->
  **A link to similar question on the forum/Stack Overflow**: https://discuss.huggingface.co/t/how-to-get-cross-attention-values-of-t5/970