docstr: Custom `test_attention_outputs` since FastSpeech2Conformer does not output cross attentions, has variable
  decoder attention shape, and uniquely outputs energy, pitch, and durations.
docstr_tok: ["Custom","`","test_attention_outputs","`","since","FastSpeech2Conformer","does","not","output","cross","attentions",",","has","variable","decoder","attention","shape",",","and","uniquely","outputs","energy",",","pitch",",","and","durations","."]
code: def test_attention_outputs(self):
      """
      Custom `test_attention_outputs` since FastSpeech2Conformer does not output cross attentions, has variable
      decoder attention shape, and uniquely outputs energy, pitch, and durations.
      """
      (
          config,
          inputs_dict,
      ) = self.model_tester.prepare_config_and_inputs_for_common()
      config.model_config.return_dict = True
  
      seq_len = self.model_tester.seq_length
  
      for model_class in self.all_model_classes:
          inputs_dict["output_attentions"] = True
          inputs_dict["output_hidden_states"] = False
          config.model_config.return_dict = True
          model = model_class(config)
          model.to(torch_device)
          model.eval()
          with torch.no_grad():
              outputs = model(
                  **self._prepare_for_class(inputs_dict, model_class)
              )
          self.assertEqual(
              len(outputs.encoder_attentions),
              self.model_tester.num_hidden_layers,
          )
  
          # check that output_attentions also work using config
          del inputs_dict["output_attentions"]
          config.model_config.output_attentions = True
          model = model_class(config)
          model.to(torch_device)
          model.eval()
  
          with torch.no_grad():
              outputs = model(
                  **self._prepare_for_class(inputs_dict, model_class)
              )
          encoder_attentions = outputs.encoder_attentions
          self.assertEqual(
              len(encoder_attentions),
              self.model_tester.num_hidden_layers,
          )
          self.assertListEqual(
              list(encoder_attentions[0].shape[-3:]),
              [self.model_tester.num_attention_heads, seq_len, seq_len],
          )
          out_len = len(outputs)
  
          correct_outlen = 8
          self.assertEqual(out_len, correct_outlen)
  
          # Check attention is always last and order is fine
          inputs_dict["output_attentions"] = True
          inputs_dict["output_hidden_states"] = True
          model = model_class(config)
          model.to(torch_device)
          model.eval()
          with torch.no_grad():
              outputs = model(
                  **self._prepare_for_class(inputs_dict, model_class)
              )
  
          added_hidden_states = 2
          self.assertEqual(out_len + added_hidden_states, len(outputs))
  
          self_attentions = outputs.encoder_attentions
          self.assertEqual(
              len(self_attentions), self.model_tester.num_hidden_layers
          )
          self.assertListEqual(
              list(self_attentions[0].shape[-3:]),
              [self.model_tester.num_attention_heads, seq_len, seq_len],
          )
  
imports: import inspect
  import tempfile
  import unittest
  from transformers import FastSpeech2ConformerConfig, FastSpeech2ConformerHifiGanConfig, FastSpeech2ConformerTokenizer, FastSpeech2ConformerWithHifiGanConfig, is_torch_available
  from transformers.testing_utils import require_g2p_en, require_torch, slow, torch_device
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_common import ModelTesterMixin, _config_zero_init, ids_tensor
label_desc: Use image node_id 10 for calling the FastSpeech2ConformerWithHifiGanTest obj's underlying member method code with example usage: obj.test_attention_outputs() without return types