





import unittest

import torch

from diffusers import UNetaDModel
from diffusers.utils import floats_tensor, slow, torch_device

from .test_modeling_common import ModelTesterMixin, UNetTesterMixin



class 				_lowerCAmelCase			(	UpperCAmelCase_							,			UpperCAmelCase_							,			unittest.TestCase							):


  '''simple docstring'''
  a_							:				str					    =UNetaDModel
  a_							:				Union[str, Any]					    ="""sample"""







  @property
  def UpperCamelCase_       (					self					:    str							):


    '''simple docstring'''





    _snake_case      : Union[str, Any]														=		4
    _snake_case      : List[Any]														=		14
    _snake_case      : str														=		16

    _snake_case      : int														=		floats_tensor((batch_size, num_features, seq_len)							).to(UpperCamelCase							)
    _snake_case      : Union[str, Any]														=		torch.tensor([10] * batch_size							).to(UpperCamelCase							)

    return {"sample": noise, "timestep": time_step}







  @property
  def UpperCamelCase_       (					self					:    Optional[int]							):


    '''simple docstring'''





    return (4, 14, 16)







  @property
  def UpperCamelCase_       (					self					:    List[str]							):


    '''simple docstring'''





    return (4, 14, 16)







  def UpperCamelCase_       (					self					:    Dict							):


    '''simple docstring'''





    pass







  def UpperCamelCase_       (					self					:    Optional[Any]							):


    '''simple docstring'''





    pass







  @unittest.skipIf(torch_device == 'mps'					, 'mish op not supported in MPS'							)
  def UpperCamelCase_       (					self					:    Any							):


    '''simple docstring'''





    super().test_determinism()







  @unittest.skipIf(torch_device == 'mps'					, 'mish op not supported in MPS'							)
  def UpperCamelCase_       (					self					:    str							):


    '''simple docstring'''





    super().test_outputs_equivalence()







  @unittest.skipIf(torch_device == 'mps'					, 'mish op not supported in MPS'							)
  def UpperCamelCase_       (					self					:    Optional[int]							):


    '''simple docstring'''





    super().test_from_save_pretrained()







  @unittest.skipIf(torch_device == 'mps'					, 'mish op not supported in MPS'							)
  def UpperCamelCase_       (					self					:    int							):


    '''simple docstring'''





    super().test_from_save_pretrained_variant()







  @unittest.skipIf(torch_device == 'mps'					, 'mish op not supported in MPS'							)
  def UpperCamelCase_       (					self					:    Dict							):


    '''simple docstring'''





    super().test_model_from_pretrained()







  @unittest.skipIf(torch_device == 'mps'					, 'mish op not supported in MPS'							)
  def UpperCamelCase_       (					self					:    List[str]							):


    '''simple docstring'''





    super().test_output()







  def UpperCamelCase_       (					self					:    Optional[int]							):


    '''simple docstring'''





    _snake_case      : Dict														=		{
        'block_out_channels': (32, 64, 1_28, 2_56),
        'in_channels': 14,
        'out_channels': 14,
        'time_embedding_type': 'positional',
        'use_timestep_embedding': True,
        'flip_sin_to_cos': False,
        'freq_shift': 1.0,
        'out_block_type': 'OutConv1DBlock',
        'mid_block_type': 'MidResTemporalBlock1D',
        'down_block_types': ('DownResnetBlock1D', 'DownResnetBlock1D', 'DownResnetBlock1D', 'DownResnetBlock1D'),
        'up_block_types': ('UpResnetBlock1D', 'UpResnetBlock1D', 'UpResnetBlock1D'),
        'act_fn': 'mish',
    }
    _snake_case      : int														=		self.dummy_input
    return init_dict, inputs_dict







  @unittest.skipIf(torch_device == 'mps'					, 'mish op not supported in MPS'							)
  def UpperCamelCase_       (					self					:    Union[str, Any]							):


    '''simple docstring'''





    _snake_case							,    _snake_case      : Any														=		UNetaDModel.from_pretrained(
        'bglick13/hopper-medium-v2-value-function-hor32'					, output_loading_info=UpperCamelCase					, subfolder='unet'							)
    self.assertIsNotNone(UpperCamelCase							)
    self.assertEqual(len(loading_info['missing_keys']							)					, 0							)

    model.to(UpperCamelCase							)
    _snake_case      : Optional[Any]														=		model(**self.dummy_input							)

    assert image is not None, "Make sure output is not None"







  @unittest.skipIf(torch_device == 'mps'					, 'mish op not supported in MPS'							)
  def UpperCamelCase_       (					self					:    List[str]							):


    '''simple docstring'''





    _snake_case      : int														=		UNetaDModel.from_pretrained('bglick13/hopper-medium-v2-value-function-hor32'					, subfolder='unet'							)
    torch.manual_seed(0							)
    if torch.cuda.is_available():
      torch.cuda.manual_seed_all(0							)

    _snake_case      : Optional[Any]														=		model.config.in_channels
    _snake_case      : List[str]														=		16
    _snake_case      : int														=		torch.randn((1, seq_len, num_features)							).permute(
        0					, 2					, 1							)  # match original, we can update values and remove
    _snake_case      : str														=		torch.full((num_features,)					, 0							)

    with torch.no_grad():
      _snake_case      : List[Any]														=		model(UpperCamelCase					, UpperCamelCase							).sample.permute(0					, 2					, 1							)

    _snake_case      : Tuple														=		output[0, -3:, -3:].flatten()
    # fmt: off
    _snake_case      : Tuple														=		torch.tensor([-2.13_71_72, 1.1_42_60_16, 0.3_68_86_87, -0.76_69_22, 0.7_30_31_46, 0.11_03_88_64, -0.4_76_06_33, 0.13_27_01_72, 0.02_59_13_48]							)
    # fmt: on
    self.assertTrue(torch.allclose(UpperCamelCase					, UpperCamelCase					, rtol=1e-3							)							)







  def UpperCamelCase_       (					self					:    Union[str, Any]							):


    '''simple docstring'''





    pass







  @slow
  def UpperCamelCase_       (					self					:    str							):


    '''simple docstring'''





    _snake_case      : Tuple														=		'harmonai/maestro-150k'
    _snake_case      : Dict														=		UNetaDModel.from_pretrained(UpperCamelCase					, subfolder='unet'							)
    model.to(UpperCamelCase							)

    _snake_case      : str														=		6_55_36
    _snake_case      : int														=		torch.sin(torch.arange(UpperCamelCase							)[None, None, :].repeat(1					, 2					, 1							)							).to(UpperCamelCase							)
    _snake_case      : str														=		torch.tensor([1]							).to(UpperCamelCase							)

    with torch.no_grad():
      _snake_case      : str														=		model(UpperCamelCase					, UpperCamelCase							).sample

    _snake_case      : str														=		output.abs().sum()
    _snake_case      : Tuple														=		output.abs().max()

    assert (output_sum - 2_24.08_96).abs() < 0.5
    assert (output_max - 0.06_07).abs() < 4e-4




class 				_lowerCAmelCase			(	UpperCAmelCase_							,			UpperCAmelCase_							,			unittest.TestCase							):


  '''simple docstring'''
  a_							:				Dict					    =UNetaDModel
  a_							:				str					    ="""sample"""







  @property
  def UpperCamelCase_       (					self					:    Dict							):


    '''simple docstring'''





    _snake_case      : Tuple														=		4
    _snake_case      : Optional[int]														=		14
    _snake_case      : Optional[int]														=		16

    _snake_case      : Union[str, Any]														=		floats_tensor((batch_size, num_features, seq_len)							).to(UpperCamelCase							)
    _snake_case      : str														=		torch.tensor([10] * batch_size							).to(UpperCamelCase							)

    return {"sample": noise, "timestep": time_step}







  @property
  def UpperCamelCase_       (					self					:    str							):


    '''simple docstring'''





    return (4, 14, 16)







  @property
  def UpperCamelCase_       (					self					:    Tuple							):


    '''simple docstring'''





    return (4, 14, 1)







  @unittest.skipIf(torch_device == 'mps'					, 'mish op not supported in MPS'							)
  def UpperCamelCase_       (					self					:    Union[str, Any]							):


    '''simple docstring'''





    super().test_determinism()







  @unittest.skipIf(torch_device == 'mps'					, 'mish op not supported in MPS'							)
  def UpperCamelCase_       (					self					:    Optional[Any]							):


    '''simple docstring'''





    super().test_outputs_equivalence()







  @unittest.skipIf(torch_device == 'mps'					, 'mish op not supported in MPS'							)
  def UpperCamelCase_       (					self					:    Optional[Any]							):


    '''simple docstring'''





    super().test_from_save_pretrained()







  @unittest.skipIf(torch_device == 'mps'					, 'mish op not supported in MPS'							)
  def UpperCamelCase_       (					self					:    List[Any]							):


    '''simple docstring'''





    super().test_from_save_pretrained_variant()







  @unittest.skipIf(torch_device == 'mps'					, 'mish op not supported in MPS'							)
  def UpperCamelCase_       (					self					:    Any							):


    '''simple docstring'''





    super().test_model_from_pretrained()







  @unittest.skipIf(torch_device == 'mps'					, 'mish op not supported in MPS'							)
  def UpperCamelCase_       (					self					:    int							):


    '''simple docstring'''





    _snake_case							,    _snake_case      : Optional[int]														=		self.prepare_init_args_and_inputs_for_common()
    _snake_case      : Tuple														=		self.model_class(**UpperCamelCase							)
    model.to(UpperCamelCase							)
    model.eval()

    with torch.no_grad():
      _snake_case      : List[Any]														=		model(**UpperCamelCase							)

      if isinstance(UpperCamelCase					, UpperCamelCase							):
        _snake_case      : Any														=		output.sample

    self.assertIsNotNone(UpperCamelCase							)
    _snake_case      : Optional[int]														=		torch.Size((inputs_dict['sample'].shape[0], 1)							)
    self.assertEqual(output.shape					, UpperCamelCase					, 'Input and output shapes do not match'							)







  def UpperCamelCase_       (					self					:    str							):


    '''simple docstring'''





    pass







  def UpperCamelCase_       (					self					:    List[Any]							):


    '''simple docstring'''





    pass







  def UpperCamelCase_       (					self					:    int							):


    '''simple docstring'''





    _snake_case      : Any														=		{
        'in_channels': 14,
        'out_channels': 14,
        'down_block_types': ['DownResnetBlock1D', 'DownResnetBlock1D', 'DownResnetBlock1D', 'DownResnetBlock1D'],
        'up_block_types': [],
        'out_block_type': 'ValueFunction',
        'mid_block_type': 'ValueFunctionMidBlock1D',
        'block_out_channels': [32, 64, 1_28, 2_56],
        'layers_per_block': 1,
        'downsample_each_block': True,
        'use_timestep_embedding': True,
        'freq_shift': 1.0,
        'flip_sin_to_cos': False,
        'time_embedding_type': 'positional',
        'act_fn': 'mish',
    }
    _snake_case      : Any														=		self.dummy_input
    return init_dict, inputs_dict







  @unittest.skipIf(torch_device == 'mps'					, 'mish op not supported in MPS'							)
  def UpperCamelCase_       (					self					:    str							):


    '''simple docstring'''





    _snake_case							,    _snake_case      : List[str]														=		UNetaDModel.from_pretrained(
        'bglick13/hopper-medium-v2-value-function-hor32'					, output_loading_info=UpperCamelCase					, subfolder='value_function'							)
    self.assertIsNotNone(UpperCamelCase							)
    self.assertEqual(len(vf_loading_info['missing_keys']							)					, 0							)

    value_function.to(UpperCamelCase							)
    _snake_case      : Any														=		value_function(**self.dummy_input							)

    assert image is not None, "Make sure output is not None"







  @unittest.skipIf(torch_device == 'mps'					, 'mish op not supported in MPS'							)
  def UpperCamelCase_       (					self					:    Dict							):


    '''simple docstring'''





    _snake_case							,    _snake_case      : int														=		UNetaDModel.from_pretrained(
        'bglick13/hopper-medium-v2-value-function-hor32'					, output_loading_info=UpperCamelCase					, subfolder='value_function'							)
    torch.manual_seed(0							)
    if torch.cuda.is_available():
      torch.cuda.manual_seed_all(0							)

    _snake_case      : str														=		value_function.config.in_channels
    _snake_case      : Any														=		14
    _snake_case      : Any														=		torch.randn((1, seq_len, num_features)							).permute(
        0					, 2					, 1							)  # match original, we can update values and remove
    _snake_case      : List[Any]														=		torch.full((num_features,)					, 0							)

    with torch.no_grad():
      _snake_case      : List[str]														=		value_function(UpperCamelCase					, UpperCamelCase							).sample

    # fmt: off
    _snake_case      : Union[str, Any]														=		torch.tensor([1_65.25] * seq_len							)
    # fmt: on
    self.assertTrue(torch.allclose(UpperCamelCase					, UpperCamelCase					, rtol=1e-3							)							)







  def UpperCamelCase_       (					self					:    List[str]							):


    '''simple docstring'''





    pass












"""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 						snake_case  :





    def __init__(							self	:					Tuple				,		A	:					Any				,		A	:					List[Any]=1_3				,		A	:					Union[str, Any]=3_2				,		A	:					Optional[Any]=1				,		A	:					Union[str, Any]=3				,		A	:					List[str]=1_6				,		A	:					Optional[Any]=[1, 2, 1]				,		A	:					Any=[2, 2, 4]				,		A	:					int=2				,		A	:					List[str]=2.0				,		A	:					Dict=True				,		A	:					Union[str, Any]=0.0				,		A	:					Union[str, Any]=0.0				,		A	:					Optional[int]=0.1				,		A	:					Optional[int]="gelu"				,		A	:					Any=False				,		A	:					Dict=True				,		A	:					int=0.02				,		A	:					Tuple=1E-5				,		A	:					List[str]=True				,		A	:					List[str]=None				,		A	:					str=False				,		A	:					Any=2				,		):


      '''simple docstring'''




      a     :			Tuple				=   parent
      a     :			Union[str, Any]				=   batch_size
      a     :			Tuple				=   image_size
      a     :			List[str]				=   patch_size
      a     :			Union[str, Any]				=   num_channels
      a     :			str				=   embed_dim
      a     :			int				=   depths
      a     :			Tuple				=   num_heads
      a     :			Any				=   window_size
      a     :			List[Any]				=   mlp_ratio
      a     :			str				=   qkv_bias
      a     :			Any				=   hidden_dropout_prob
      a     :			List[Any]				=   attention_probs_dropout_prob
      a     :			int				=   drop_path_rate
      a     :			List[Any]				=   hidden_act
      a     :			Union[str, Any]				=   use_absolute_embeddings
      a     :			Dict				=   patch_norm
      a     :			Optional[Any]				=   layer_norm_eps
      a     :			Dict				=   initializer_range
      a     :			Optional[Any]				=   is_training
      a     :			str				=   scope
      a     :			List[Any]				=   use_labels
      a     :			Union[str, Any]				=   upscale

      # here we set some attributes to make tests pass
      a     :			str				=   len(A			)
      a     :			List[Any]				=   embed_dim
      a     :			List[Any]				=   (image_size // patch_size) ** 2





    def 				lowerCamelCase__      (							self	:					str			):


      '''simple docstring'''




      a     :			List[Any]				=   floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]			)

      a     :			List[str]				=   None
      if self.use_labels:
        a     :			Tuple				=   ids_tensor([self.batch_size]				,		self.type_sequence_label_size			)

      a     :			Any				=   self.get_config()

      return config, pixel_values, labels





    def 				lowerCamelCase__      (							self	:					str			):


      '''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	:					Union[str, Any]				,		A	:					Dict				,		A	:					Union[str, Any]				,		A	:					List[str]			):


      '''simple docstring'''




      a     :			List[Any]				=   SwinaSRModel(config=A			)
      model.to(A			)
      model.eval()
      a     :			Optional[int]				=   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	:					List[str]				,		A	:					Tuple				,		A	:					str				,		A	:					Tuple			):


      '''simple docstring'''




      a     :			Optional[Any]				=   SwinaSRForImageSuperResolution(A			)
      model.to(A			)
      model.eval()
      a     :			List[str]				=   model(A			)

      a     :			Any				=   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	:					Union[str, Any]			):


      '''simple docstring'''




      a     :			Tuple				=   self.prepare_config_and_inputs()
      a,     a,     a     :			Union[str, Any]				=   config_and_inputs
      a     :			List[str]				=   {'pixel_values': pixel_values}
      return config, inputs_dict






@require_torch
class 						snake_case  (  UpperCAmelCase   , UpperCAmelCase   , unittest.TestCase       ):
    __magic_name__         =     (SwinaSRModel, SwinaSRForImageSuperResolution) if is_torch_available() else ()
    __magic_name__         =     {'''feature-extraction''': SwinaSRModel} if is_torch_available() else {}

    __magic_name__         =     False
    __magic_name__         =     False
    __magic_name__         =     False
    __magic_name__         =     False
    __magic_name__         =     False





    def 				lowerCamelCase__      (							self	:					Optional[int]			):


      '''simple docstring'''




      a     :			List[str]				=   SwinaSRModelTester(self			)
      a     :			int				=   ConfigTester(self				,		config_class=A				,		embed_dim=3_7			)





    def 				lowerCamelCase__      (							self	:					Optional[int]			):


      '''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	:					List[Any]			):


      '''simple docstring'''




      a     :			str				=   self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*A			)





    def 				lowerCamelCase__      (							self	:					Tuple			):


      '''simple docstring'''




      a     :			Any				=   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	:					str			):


      '''simple docstring'''




      pass





    @unittest.skip(reason='Swin2SR does not use inputs_embeds'			)
    def 				lowerCamelCase__      (							self	:					Tuple			):


      '''simple docstring'''




      pass





    @unittest.skip(reason='Swin2SR does not support training yet'			)
    def 				lowerCamelCase__      (							self	:					Optional[int]			):


      '''simple docstring'''




      pass





    @unittest.skip(reason='Swin2SR does not support training yet'			)
    def 				lowerCamelCase__      (							self	:					int			):


      '''simple docstring'''




      pass





    def 				lowerCamelCase__      (							self	:					int			):


      '''simple docstring'''




      a,     a     :			Optional[int]				=   self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
        a     :			Union[str, Any]				=   model_class(A			)
        self.assertIsInstance(model.get_input_embeddings()				,		(nn.Module)			)
        a     :			Optional[int]				=   model.get_output_embeddings()
        self.assertTrue(x is None or isinstance(A				,		nn.Linear			)			)





    def 				lowerCamelCase__      (							self	:					Optional[int]			):


      '''simple docstring'''




      a,     a     :			int				=   self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
        a     :			Dict				=   model_class(A			)
        a     :			Union[str, Any]				=   inspect.signature(model.forward			)
        # signature.parameters is an OrderedDict => so arg_names order is deterministic
        a     :			Any				=   [*signature.parameters.keys()]

        a     :			Tuple				=   ['pixel_values']
        self.assertListEqual(arg_names[:1]				,		A			)





    @slow
    def 				lowerCamelCase__      (							self	:					List[str]			):


      '''simple docstring'''




      for model_name in SWIN2SR_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
        a     :			Optional[int]				=   SwinaSRModel.from_pretrained(A			)
        self.assertIsNotNone(A			)





    def 				lowerCamelCase__      (							self	:					Dict			):


      '''simple docstring'''




      a,     a     :			str				=   self.model_tester.prepare_config_and_inputs_for_common()

      a     :			int				=   _config_zero_init(A			)
      for model_class in self.all_model_classes:
        a     :			List[str]				=   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	:					List[str]			):


      '''simple docstring'''




      a,     a     :			Union[str, Any]				=   self.model_tester.prepare_config_and_inputs_for_common()
      a     :			List[str]				=   True

      for model_class in self.all_model_classes:
        a     :			Dict				=   True
        a     :			int				=   False
        a     :			str				=   True
        a     :			Optional[int]				=   model_class(A			)
        model.to(A			)
        model.eval()
        with torch.no_grad():
          a     :			Tuple				=   model(**self._prepare_for_class(A				,		A			)			)
        a     :			Optional[Any]				=   outputs.attentions
        a     :			int				=   len(self.model_tester.depths			)
        self.assertEqual(len(A			)				,		A			)

        # check that output_attentions also work using config
        del inputs_dict["output_attentions"]
        a     :			List[str]				=   True
        a     :			List[Any]				=   config.window_size**2
        a     :			List[str]				=   model_class(A			)
        model.to(A			)
        model.eval()
        with torch.no_grad():
          a     :			str				=   model(**self._prepare_for_class(A				,		A			)			)
        a     :			int				=   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     :			int				=   len(A			)

        # Check attention is always last and order is fine
        a     :			List[str]				=   True
        a     :			List[Any]				=   True
        a     :			str				=   model_class(A			)
        model.to(A			)
        model.eval()
        with torch.no_grad():
          a     :			List[Any]				=   model(**self._prepare_for_class(A				,		A			)			)

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

        a     :			Tuple				=   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 						snake_case  (  unittest.TestCase       ):





    def 				lowerCamelCase__      (							self	:					Optional[int]			):


      '''simple docstring'''




      a     :			Optional[int]				=   SwinaSRImageProcessor()
      a     :			Optional[int]				=   SwinaSRForImageSuperResolution.from_pretrained('caidas/swin2SR-classical-sr-x2-64'			).to(A			)

      a     :			str				=   Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'			)
      a     :			Union[str, Any]				=   processor(images=A				,		return_tensors='pt'			).to(A			)

      # forward pass
      with torch.no_grad():
        a     :			Tuple				=   model(**A			)

      # verify the logits
      a     :			Optional[int]				=   torch.Size([1, 3, 9_7_6, 1_2_9_6]			)
      self.assertEqual(outputs.reconstruction.shape				,		A			)
      a     :			Tuple				=   torch.tensor(
          [[0.54_58, 0.55_46, 0.56_38], [0.55_26, 0.55_65, 0.56_51], [0.53_96, 0.54_26, 0.56_21]]			).to(A			)
      self.assertTrue(torch.allclose(outputs.reconstruction[0, 0, :3, :3]				,		A				,		atol=1E-4			)			)




