docstr: Overriding the test_attention_outputs test as the attention outputs of Rwkv are different from other models
  it has a shape `batch_size, seq_len, hidden_size`.
docstr_tok: ["Overriding","the","test_attention_outputs","test","as","the","attention","outputs","of","Rwkv","are","different","from","other","models","it","has","a","shape","`","batch_size",",","seq_len",",","hidden_size","`","."]
code: def test_attention_outputs(self):
      r"""
      Overriding the test_attention_outputs test as the attention outputs of Rwkv are different from other models
      it has a shape `batch_size, seq_len, hidden_size`.
      """
      (
          config,
          inputs_dict,
      ) = self.model_tester.prepare_config_and_inputs_for_common()
      config.return_dict = True
  
      seq_len = getattr(self.model_tester, "seq_length", None)
  
      for model_class in self.all_model_classes:
          inputs_dict["output_attentions"] = True
          inputs_dict["output_hidden_states"] = False
          config.return_dict = True
          model = model_class(config)
          model.to(torch_device)
          model.eval()
  
          inputs = self._prepare_for_class(inputs_dict, model_class)
          batch_size = inputs["input_ids"].shape[0]
          with torch.no_grad():
              outputs = model(**inputs)
          attentions = outputs.attentions
          self.assertEqual(
              len(attentions), self.model_tester.num_hidden_layers
          )
  
          # check that output_attentions also work using config
          del inputs_dict["output_attentions"]
          config.output_attentions = True
          model = model_class(config)
          model.to(torch_device)
          model.eval()
  
          inputs = self._prepare_for_class(inputs_dict, model_class)
          batch_size = inputs["input_ids"].shape[0]
          with torch.no_grad():
              outputs = model(**inputs)
          attentions = outputs.attentions
          self.assertEqual(
              len(attentions), self.model_tester.num_hidden_layers
          )
  
          self.assertListEqual(
              list(attentions[0].shape[-3:]),
              [batch_size, seq_len, config.hidden_size],
          )
          out_len = len(outputs)
  
          # 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()
  
          inputs = self._prepare_for_class(inputs_dict, model_class)
          batch_size = inputs["input_ids"].shape[0]
          with torch.no_grad():
              outputs = model(**inputs)
  
          added_hidden_states = 1
          self.assertEqual(out_len + added_hidden_states, len(outputs))
  
          self_attentions = outputs.attentions
  
          self.assertEqual(
              len(self_attentions), self.model_tester.num_hidden_layers
          )
          self.assertListEqual(
              list(self_attentions[0].shape[-3:]),
              [batch_size, seq_len, config.hidden_size],
          )
  
imports: import unittest
  from unittest.util import safe_repr
  from transformers import AutoTokenizer, RwkvConfig, is_torch_available
  from transformers.testing_utils import require_torch, slow, torch_device
  from ...generation.test_utils import GenerationTesterMixin
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
  from ...test_pipeline_mixin import PipelineTesterMixin
label_desc: Use image node_id 8 for calling the RwkvModelTest obj's underlying member method code with example usage: obj.test_attention_outputs() without return types