


from collections import OrderedDict
from typing import Any, Mapping, Optional

from ... import PreTrainedTokenizer
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig, OnnxConfigWithPast, OnnxSeqaSeqConfigWithPast
from ...onnx.utils import compute_effective_axis_dimension
from ...utils import TensorType, is_torch_available, logging


_snake_case				=			logging.get_logger(__name__)

_snake_case				=			{
    "google/bigbird-pegasus-large-arxiv": (
        "https://huggingface.co/google/bigbird-pegasus-large-arxiv/resolve/main/config.json"
    ),
    "google/bigbird-pegasus-large-pubmed": (
        "https://huggingface.co/google/bigbird-pegasus-large-pubmed/resolve/main/config.json"
    ),
    "google/bigbird-pegasus-large-bigpatent": (
        "https://huggingface.co/google/bigbird-pegasus-large-bigpatent/resolve/main/config.json"
    ),
    # See all BigBirdPegasus models at https://huggingface.co/models?filter=bigbird_pegasus
}




class  A_ (			_UpperCAmelCase  ):







 """simple docstring"""





 _UpperCamelCase					:			str     	=       '''bigbird_pegasus'''
 _UpperCamelCase					:			str     	=       ['''past_key_values''']
 _UpperCamelCase					:			Any     	=       {
     '''num_attention_heads''': '''encoder_attention_heads''',
     '''hidden_size''': '''d_model''',
     '''attention_probs_dropout_prob''': '''attention_dropout''',
 }
 def __init__(      self       :			int							,     _a       :			Union[str, Any]=9_6_1_0_3							,     _a       :			List[Any]=4_0_9_6							,     _a       :			Dict=1_6							,     _a       :			Optional[int]=4_0_9_6							,     _a       :			Any=1_6							,     _a       :			List[str]=1_6							,     _a       :			List[Any]=4_0_9_6							,     _a       :			Any=1_6							,     _a       :			List[str]=0.0							,     _a       :			str=0.0							,     _a       :			Union[str, Any]=True							,     _a       :			Union[str, Any]=True							,     _a       :			Dict="gelu_new"							,     _a       :			Optional[int]=1_0_2_4							,     _a       :			str=0.1							,     _a       :			List[Any]=0.0							,     _a       :			Optional[Any]=0.0							,     _a       :			int=0.0_2							,     _a       :			Optional[int]=2							,     _a       :			str=0.0							,     _a       :			Optional[int]=True							,     _a       :			Tuple=0							,     _a       :			Optional[Any]=2							,     _a       :			Union[str, Any]=1							,     _a       :			str="block_sparse"							,     _a       :			List[Any]=6_4							,     _a       :			List[str]=3							,     _a       :			int=False							,     **_a       :			List[Any]							,     )     ->      List[str]:
      UpperCAmelCase    :					List[Any]			=      vocab_size
      UpperCAmelCase    :					Dict			=      max_position_embeddings
      UpperCAmelCase    :					List[Any]			=      d_model
      UpperCAmelCase    :					List[str]			=      encoder_ffn_dim
      UpperCAmelCase    :					str			=      encoder_layers
      UpperCAmelCase    :					Optional[int]			=      encoder_attention_heads
      UpperCAmelCase    :					Optional[Any]			=      decoder_ffn_dim
      UpperCAmelCase    :					Any			=      decoder_layers
      UpperCAmelCase    :					List[Any]			=      decoder_attention_heads
      UpperCAmelCase    :					Any			=      dropout
      UpperCAmelCase    :					Dict			=      attention_dropout
      UpperCAmelCase    :					List[Any]			=      activation_dropout
      UpperCAmelCase    :					Union[str, Any]			=      activation_function
      UpperCAmelCase    :					str			=      init_std
      UpperCAmelCase    :					Tuple			=      encoder_layerdrop
      UpperCAmelCase    :					List[str]			=      decoder_layerdrop
      UpperCAmelCase    :					int			=      classifier_dropout
      UpperCAmelCase    :					Optional[Any]			=      use_cache
      UpperCAmelCase    :					List[str]			=      encoder_layers
      UpperCAmelCase    :					List[Any]			=      scale_embedding  # scale factor will be sqrt(d_model) if True

      # extra config
      UpperCAmelCase    :					Tuple			=      attention_type
      UpperCAmelCase    :					Optional[int]			=      block_size
      UpperCAmelCase    :					Optional[Any]			=      num_random_blocks
      UpperCAmelCase    :					Dict			=      use_bias

      super().__init__(
          pad_token_id=a_							,     bos_token_id=a_							,     eos_token_id=a_							,     is_encoder_decoder=a_							,     decoder_start_token_id=a_							,     **a_							,     )




class  A_ (			_UpperCAmelCase  ):







 """simple docstring"""





 @property
 def 	_UpperCamelCase     (      self       :			List[Any]					)     ->      Mapping[str, Mapping[int, str]]:


      if self.task in ["default", "seq2seq-lm"]:
           UpperCAmelCase    :					List[str]			=      OrderedDict(
               [
                   ("input_ids", {0: "batch", 1: "encoder_sequence"}),
                   ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
               ]					)

           if self.use_past:
                UpperCAmelCase    :					str			=      {0: "batch"}
                UpperCAmelCase    :					str			=      {0: "batch", 1: "past_decoder_sequence + sequence"}
           else:
                UpperCAmelCase    :					Dict			=      {0: "batch", 1: "decoder_sequence"}
                UpperCAmelCase    :					str			=      {0: "batch", 1: "decoder_sequence"}

           if self.use_past:
                self.fill_with_past_key_values_(a_							,     direction="inputs"					)
      elif self.task == "causal-lm":
           # TODO: figure this case out.
           UpperCAmelCase    :					List[str]			=      OrderedDict(
               [
                   ("input_ids", {0: "batch", 1: "encoder_sequence"}),
                   ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
               ]					)
           if self.use_past:
                UpperCAmelCase	,			UpperCAmelCase    :					Union[str, Any]			=      self.num_layers
                for i in range(a_					):
                     UpperCAmelCase    :					Optional[int]			=      {0: "batch", 2: "past_sequence + sequence"}
                     UpperCAmelCase    :					int			=      {0: "batch", 2: "past_sequence + sequence"}
      else:
           UpperCAmelCase    :					Any			=      OrderedDict(
               [
                   ("input_ids", {0: "batch", 1: "encoder_sequence"}),
                   ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
                   ("decoder_input_ids", {0: "batch", 1: "decoder_sequence"}),
                   ("decoder_attention_mask", {0: "batch", 1: "decoder_sequence"}),
               ]					)

      return common_inputs
 @property
 def 	_UpperCamelCase     (      self       :			str					)     ->      Mapping[str, Mapping[int, str]]:


      if self.task in ["default", "seq2seq-lm"]:
           UpperCAmelCase    :					int			=      super().outputs
      else:
           UpperCAmelCase    :					Optional[int]			=      super(a_							,     self					).outputs
           if self.use_past:
                UpperCAmelCase	,			UpperCAmelCase    :					Optional[Any]			=      self.num_layers
                for i in range(a_					):
                     UpperCAmelCase    :					Optional[int]			=      {0: "batch", 2: "past_sequence + sequence"}
                     UpperCAmelCase    :					Dict			=      {0: "batch", 2: "past_sequence + sequence"}
      return common_outputs
 def 	_UpperCamelCase     (      self       :			Union[str, Any]							,     _a       :			Optional[int]							,     _a       :			List[Any] = -1							,     _a       :			Union[str, Any] = -1							,     _a       :			Optional[int] = False							,     _a       :			Optional[int] = None							,     )     ->      Mapping[str, Any]:
      UpperCAmelCase    :					int			=      self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
          a_							,     a_							,     a_							,     a_							,     a_					)

      # Generate decoder inputs
      UpperCAmelCase    :					List[str]			=      seq_length if not self.use_past else 1
      UpperCAmelCase    :					Optional[Any]			=      self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
          a_							,     a_							,     a_							,     a_							,     a_					)
      UpperCAmelCase    :					Dict			=      {f'decoder_{name}': tensor for name, tensor in decoder_inputs.items()}
      UpperCAmelCase    :					Optional[Any]			=      dict(**a_							,     **a_					)

      if self.use_past:
           if not is_torch_available():
                raise ValueError("Cannot generate dummy past_keys inputs without PyTorch installed."					)
           else:
                import torch
           UpperCAmelCase	,			UpperCAmelCase    :					List[Any]			=      common_inputs["input_ids"].shape
           UpperCAmelCase    :					int			=      common_inputs["decoder_input_ids"].shape[1]
           UpperCAmelCase	,			UpperCAmelCase    :					Any			=      self.num_attention_heads
           UpperCAmelCase    :					Tuple			=      (
               batch,
               num_encoder_attention_heads,
               encoder_seq_length,
               self._config.hidden_size // num_encoder_attention_heads,
           )
           UpperCAmelCase    :					Tuple			=      decoder_seq_length + 3
           UpperCAmelCase    :					Dict			=      (
               batch,
               num_decoder_attention_heads,
               decoder_past_length,
               self._config.hidden_size // num_decoder_attention_heads,
           )

           UpperCAmelCase    :					int			=      torch.cat(
               [common_inputs["decoder_attention_mask"], torch.ones(a_							,     a_					)]							,     dim=1					)

           UpperCAmelCase    :					Any			=      []
           # If the number of encoder and decoder layers are present in the model configuration, both are considered
           UpperCAmelCase	,			UpperCAmelCase    :					int			=      self.num_layers
           UpperCAmelCase    :					Tuple			=      min(a_							,     a_					)
           UpperCAmelCase    :					Union[str, Any]			=      max(a_							,     a_					) - min_num_layers
           UpperCAmelCase    :					int			=      "encoder" if num_encoder_layers > num_decoder_layers else "decoder"

           for _ in range(a_					):
                common_inputs["past_key_values"].append(
                    (
                        torch.zeros(a_					),
                        torch.zeros(a_					),
                        torch.zeros(a_					),
                        torch.zeros(a_					),
                    )					)
           # TODO: test this.
           UpperCAmelCase    :					List[Any]			=      encoder_shape if remaining_side_name == "encoder" else decoder_shape
           for _ in range(a_							,     a_					):
                common_inputs["past_key_values"].append((torch.zeros(a_					), torch.zeros(a_					))					)
      return common_inputs
 def 	_UpperCamelCase     (      self       :			List[Any]							,     _a       :			Tuple							,     _a       :			Tuple = -1							,     _a       :			Optional[Any] = -1							,     _a       :			Optional[Any] = False							,     _a       :			Optional[int] = None							,     )     ->      Mapping[str, Any]:
      UpperCAmelCase    :					str			=      self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
          a_							,     a_							,     a_							,     a_							,     a_					)

      if self.use_past:
           if not is_torch_available():
                raise ValueError("Cannot generate dummy past_keys inputs without PyTorch installed."					)
           else:
                import torch
           UpperCAmelCase	,			UpperCAmelCase    :					List[Any]			=      common_inputs["input_ids"].shape
           # Not using the same length for past_key_values
           UpperCAmelCase    :					Optional[int]			=      seqlen + 2
           UpperCAmelCase	,			UpperCAmelCase    :					str			=      self.num_layers
           UpperCAmelCase	,			UpperCAmelCase    :					List[str]			=      self.num_attention_heads
           UpperCAmelCase    :					List[Any]			=      (
               batch,
               num_encoder_attention_heads,
               past_key_values_length,
               self._config.hidden_size // num_encoder_attention_heads,
           )

           UpperCAmelCase    :					int			=      common_inputs["attention_mask"].dtype
           UpperCAmelCase    :					Any			=      torch.cat(
               [common_inputs["attention_mask"], torch.ones(a_							,     a_							,     dtype=a_					)]							,     dim=1					)
           UpperCAmelCase    :					int			=      [
               (torch.zeros(a_					), torch.zeros(a_					)) for _ in range(a_					)
           ]
      return common_inputs
 def 	_UpperCamelCase     (      self       :			Any							,     _a       :			Optional[int]							,     _a       :			int = -1							,     _a       :			List[str] = -1							,     _a       :			List[Any] = False							,     _a       :			int = None							,     )     ->      Mapping[str, Any]:
      UpperCAmelCase    :					List[Any]			=      compute_effective_axis_dimension(
          a_							,     fixed_dimension=OnnxConfig.default_fixed_batch							,     num_token_to_add=0					)

      # If dynamic axis (-1) we forward with a fixed dimension of 8 tokens to avoid optimizations made by ONNX
      UpperCAmelCase    :					Union[str, Any]			=      tokenizer.num_special_tokens_to_add(a_					)
      UpperCAmelCase    :					Tuple			=      compute_effective_axis_dimension(
          a_							,     fixed_dimension=OnnxConfig.default_fixed_sequence							,     num_token_to_add=a_					)

      # Generate dummy inputs according to compute batch and sequence
      UpperCAmelCase    :					Dict			=      [" ".join([tokenizer.unk_token]					) * seq_length] * batch_size
      UpperCAmelCase    :					Any			=      dict(tokenizer(a_							,     return_tensors=a_					)					)
      return common_inputs
 def 	_UpperCamelCase     (      self       :			Dict							,     _a       :			List[Any]							,     _a       :			List[str] = -1							,     _a       :			int = -1							,     _a       :			int = False							,     _a       :			List[Any] = None							,     )     ->      Mapping[str, Any]:


      if self.task in ["default", "seq2seq-lm"]:
           UpperCAmelCase    :					Optional[Any]			=      self._generate_dummy_inputs_for_default_and_seqaseq_lm(
               a_							,     batch_size=a_							,     seq_length=a_							,     is_pair=a_							,     framework=a_					)

      elif self.task == "causal-lm":
           UpperCAmelCase    :					Optional[Any]			=      self._generate_dummy_inputs_for_causal_lm(
               a_							,     batch_size=a_							,     seq_length=a_							,     is_pair=a_							,     framework=a_					)
      else:
           UpperCAmelCase    :					Tuple			=      self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
               a_							,     batch_size=a_							,     seq_length=a_							,     is_pair=a_							,     framework=a_					)

      return common_inputs

 def 	_UpperCamelCase     (      self       :			Any							,     _a       :			Union[str, Any]							,     _a       :			Optional[Any]							,     _a       :			Dict							,     _a       :			Dict					)     ->      str:


      if self.task in ["default", "seq2seq-lm"]:
           UpperCAmelCase    :					List[str]			=      super()._flatten_past_key_values_(a_							,     a_							,     a_							,     a_					)
      else:
           UpperCAmelCase    :					str			=      super(a_							,     self					)._flatten_past_key_values_(
               a_							,     a_							,     a_							,     a_					)











"""simple docstring"""




import inspect
import unittest

from transformers import SwinaSRConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
     import torch
     from torch import nn

     from transformers import SwinaSRForImageSuperResolution, SwinaSRModel
     from transformers.models.swinasr.modeling_swinasr import SWIN2SR_PRETRAINED_MODEL_ARCHIVE_LIST

if is_vision_available():
     from PIL import Image

     from transformers import SwinaSRImageProcessor




class  lowercase_     :






      def __init__(     self  ,  a_  ,  a_=1_3  ,  a_=3_2  ,  a_=1  ,  a_=3  ,  a_=1_6  ,  a_=[1, 2, 1]  ,  a_=[2, 2, 4]  ,  a_=2  ,  a_=2.0  ,  a_=True  ,  a_=0.0  ,  a_=0.0  ,  a_=0.1  ,  a_="gelu"  ,  a_=False  ,  a_=True  ,  a_=0.02  ,  a_=1E-5  ,  a_=True  ,  a_=None  ,  a_=False  ,  a_=2  ,  )						->str:







        '''simple docstring'''


        _a					      =						parent
        _a					      =						batch_size
        _a					      =						image_size
        _a					      =						patch_size
        _a					      =						num_channels
        _a					      =						embed_dim
        _a					      =						depths
        _a					      =						num_heads
        _a					      =						window_size
        _a					      =						mlp_ratio
        _a					      =						qkv_bias
        _a					      =						hidden_dropout_prob
        _a					      =						attention_probs_dropout_prob
        _a					      =						drop_path_rate
        _a					      =						hidden_act
        _a					      =						use_absolute_embeddings
        _a					      =						patch_norm
        _a					      =						layer_norm_eps
        _a					      =						initializer_range
        _a					      =						is_training
        _a					      =						scope
        _a					      =						use_labels
        _a					      =						upscale

        # here we set some attributes to make tests pass
        _a					      =						len(a_						)
        _a					      =						embed_dim
        _a					      =						(image_size // patch_size) ** 2






      def       lowerCamelCase__     (     self						)						->Any:







        '''simple docstring'''


        _a					      =						floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

        _a					      =						None
        if self.use_labels:
          _a					      =						ids_tensor([self.batch_size]  ,  self.type_sequence_label_size						)

        _a					      =						self.get_config()

        return config, pixel_values, labels






      def       lowerCamelCase__     (     self						)						->Union[str, Any]:







        '''simple docstring'''


        return SwinaSRConfig(
            image_size=self.image_size  ,  patch_size=self.patch_size  ,  num_channels=self.num_channels  ,  embed_dim=self.embed_dim  ,  depths=self.depths  ,  num_heads=self.num_heads  ,  window_size=self.window_size  ,  mlp_ratio=self.mlp_ratio  ,  qkv_bias=self.qkv_bias  ,  hidden_dropout_prob=self.hidden_dropout_prob  ,  attention_probs_dropout_prob=self.attention_probs_dropout_prob  ,  drop_path_rate=self.drop_path_rate  ,  hidden_act=self.hidden_act  ,  use_absolute_embeddings=self.use_absolute_embeddings  ,  path_norm=self.patch_norm  ,  layer_norm_eps=self.layer_norm_eps  ,  initializer_range=self.initializer_range  ,  upscale=self.upscale  ,  )






      def       lowerCamelCase__     (     self  ,  a_  ,  a_  ,  a_						)						->Union[str, Any]:







        '''simple docstring'''


        _a					      =						SwinaSRModel(config=a_						)
        model.to(a_						)
        model.eval()
        _a					      =						model(a_						)

        self.parent.assertEqual(
            result.last_hidden_state.shape  ,  (self.batch_size, self.embed_dim, self.image_size, self.image_size)						)






      def       lowerCamelCase__     (     self  ,  a_  ,  a_  ,  a_						)						->Optional[int]:







        '''simple docstring'''


        _a					      =						SwinaSRForImageSuperResolution(a_						)
        model.to(a_						)
        model.eval()
        _a					      =						model(a_						)

        _a					      =						self.image_size * self.upscale
        self.parent.assertEqual(
            result.reconstruction.shape  ,  (self.batch_size, self.num_channels, expected_image_size, expected_image_size)						)






      def       lowerCamelCase__     (     self						)						->Tuple:







        '''simple docstring'''


        _a					      =						self.prepare_config_and_inputs()
        _a      ,						_a      ,						_a					      =						config_and_inputs
        _a					      =						{"pixel_values": pixel_values}
        return config, inputs_dict







@require_torch
class  lowercase_     (_UpperCAmelCase,     _UpperCAmelCase,     unittest.TestCase  ):
      A__						:		str							      =					(SwinaSRModel, SwinaSRForImageSuperResolution) if is_torch_available() else ()
      A__						:		Optional[Any]							      =					{'''feature-extraction''': SwinaSRModel} if is_torch_available() else {}

      A__						:		List[str]							      =					False
      A__						:		Optional[Any]							      =					False
      A__						:		str							      =					False
      A__						:		Optional[int]							      =					False
      A__						:		List[Any]							      =					False






      def       lowerCamelCase__     (     self						)						->Union[str, Any]:







        '''simple docstring'''


        _a					      =						SwinaSRModelTester(self						)
        _a					      =						ConfigTester(self  ,  config_class=a_  ,  embed_dim=3_7						)






      def       lowerCamelCase__     (     self						)						->Union[str, Any]:







        '''simple docstring'''


        self.config_tester.create_and_test_config_to_json_string()
        self.config_tester.create_and_test_config_to_json_file()
        self.config_tester.create_and_test_config_from_and_save_pretrained()
        self.config_tester.create_and_test_config_with_num_labels()
        self.config_tester.check_config_can_be_init_without_params()
        self.config_tester.check_config_arguments_init()






      def       lowerCamelCase__     (     self						)						->int:







        '''simple docstring'''


        _a					      =						self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*a_						)






      def       lowerCamelCase__     (     self						)						->Optional[int]:







        '''simple docstring'''


        _a					      =						self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_image_super_resolution(*a_						)






      @unittest.skip(reason="Got `CUDA error: misaligned address` with PyTorch 2.0.0."						)
      def       lowerCamelCase__     (     self						)						->int:







        '''simple docstring'''


        pass






      @unittest.skip(reason="Swin2SR does not use inputs_embeds"						)
      def       lowerCamelCase__     (     self						)						->Union[str, Any]:







        '''simple docstring'''


        pass






      @unittest.skip(reason="Swin2SR does not support training yet"						)
      def       lowerCamelCase__     (     self						)						->Union[str, Any]:







        '''simple docstring'''


        pass






      @unittest.skip(reason="Swin2SR does not support training yet"						)
      def       lowerCamelCase__     (     self						)						->Any:







        '''simple docstring'''


        pass






      def       lowerCamelCase__     (     self						)						->Tuple:







        '''simple docstring'''


        _a      ,						_a					      =						self.model_tester.prepare_config_and_inputs_for_common()

        for model_class in self.all_model_classes:
          _a					      =						model_class(a_						)
          self.assertIsInstance(model.get_input_embeddings()  ,  (nn.Module)						)
          _a					      =						model.get_output_embeddings()
          self.assertTrue(x is None or isinstance(a_  ,  nn.Linear						)						)






      def       lowerCamelCase__     (     self						)						->Optional[Any]:







        '''simple docstring'''


        _a      ,						_a					      =						self.model_tester.prepare_config_and_inputs_for_common()

        for model_class in self.all_model_classes:
          _a					      =						model_class(a_						)
          _a					      =						inspect.signature(model.forward						)
          # signature.parameters is an OrderedDict => so arg_names order is deterministic
          _a					      =						[*signature.parameters.keys()]

          _a					      =						["pixel_values"]
          self.assertListEqual(arg_names[:1]  ,  a_						)






      @slow
      def       lowerCamelCase__     (     self						)						->Dict:







        '''simple docstring'''


        for model_name in SWIN2SR_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
          _a					      =						SwinaSRModel.from_pretrained(a_						)
          self.assertIsNotNone(a_						)






      def       lowerCamelCase__     (     self						)						->Dict:







        '''simple docstring'''


        _a      ,						_a					      =						self.model_tester.prepare_config_and_inputs_for_common()

        _a					      =						_config_zero_init(a_						)
        for model_class in self.all_model_classes:
          _a					      =						model_class(config=a_						)
          for name, param in model.named_parameters():
            if "logit_scale" in name:
              continue
            if param.requires_grad:
              self.assertIn(
                  ((param.data.mean() * 1E9).round() / 1E9).item()  ,  [0.0, 1.0]  ,  msg=f'''Parameter {name} of model {model_class} seems not properly initialized'''  ,  )






      def       lowerCamelCase__     (     self						)						->Tuple:







        '''simple docstring'''


        _a      ,						_a					      =						self.model_tester.prepare_config_and_inputs_for_common()
        _a					      =						True

        for model_class in self.all_model_classes:
          _a					      =						True
          _a					      =						False
          _a					      =						True
          _a					      =						model_class(a_						)
          model.to(a_						)
          model.eval()
          with torch.no_grad():
            _a					      =						model(**self._prepare_for_class(a_  ,  a_						)						)
          _a					      =						outputs.attentions
          _a					      =						len(self.model_tester.depths						)
          self.assertEqual(len(a_						)  ,  a_						)

          # check that output_attentions also work using config
          del inputs_dict["output_attentions"]
          _a					      =						True
          _a					      =						config.window_size**2
          _a					      =						model_class(a_						)
          model.to(a_						)
          model.eval()
          with torch.no_grad():
            _a					      =						model(**self._prepare_for_class(a_  ,  a_						)						)
          _a					      =						outputs.attentions
          self.assertEqual(len(a_						)  ,  a_						)

          self.assertListEqual(
              list(attentions[0].shape[-3:]						)  ,  [self.model_tester.num_heads[0], window_size_squared, window_size_squared]  ,  )
          _a					      =						len(a_						)

          # Check attention is always last and order is fine
          _a					      =						True
          _a					      =						True
          _a					      =						model_class(a_						)
          model.to(a_						)
          model.eval()
          with torch.no_grad():
            _a					      =						model(**self._prepare_for_class(a_  ,  a_						)						)

          self.assertEqual(out_len + 1  ,  len(a_						)						)

          _a					      =						outputs.attentions

          self.assertEqual(len(a_						)  ,  a_						)

          self.assertListEqual(
              list(self_attentions[0].shape[-3:]						)  ,  [self.model_tester.num_heads[0], window_size_squared, window_size_squared]  ,  )







@require_vision
@require_torch
@slow
class  lowercase_     (unittest.TestCase  ):






      def       lowerCamelCase__     (     self						)						->Optional[Any]:







        '''simple docstring'''


        _a					      =						SwinaSRImageProcessor()
        _a					      =						SwinaSRForImageSuperResolution.from_pretrained("caidas/swin2SR-classical-sr-x2-64"						).to(a_						)

        _a					      =						Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"						)
        _a					      =						processor(images=a_  ,  return_tensors="pt"						).to(a_						)

        # forward pass
        with torch.no_grad():
          _a					      =						model(**a_						)

        # verify the logits
        _a					      =						torch.Size([1, 3, 9_7_6, 1_2_9_6]						)
        self.assertEqual(outputs.reconstruction.shape  ,  a_						)
        _a					      =						torch.tensor(
            [[0.5_458, 0.5_546, 0.5_638], [0.5_526, 0.5_565, 0.5_651], [0.5_396, 0.5_426, 0.5_621]]						).to(a_						)
        self.assertTrue(torch.allclose(outputs.reconstruction[0, 0, :3, :3]  ,  a_  ,  atol=1E-4						)						)


