



'''simple docstring'''



import collections
import inspect
import unittest

from transformers import SwinvaConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, 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 SwinvaForImageClassification, SwinvaForMaskedImageModeling, SwinvaModel
       from transformers.models.swinva.modeling_swinva import SWINV2_PRETRAINED_MODEL_ARCHIVE_LIST

if is_vision_available():
       from PIL import Image

       from transformers import AutoImageProcessor
class 	lowerCamelCase_							:







      def __init__(  self   :      List[str]				,    lowerCAmelCase__   :      Optional[Any]				,    lowerCAmelCase__   :      Optional[int]=13				,    lowerCAmelCase__   :      Tuple=32				,    lowerCAmelCase__   :      Union[str, Any]=2				,    lowerCAmelCase__   :      Optional[Any]=3				,    lowerCAmelCase__   :      Any=16				,    lowerCAmelCase__   :      List[str]=[1, 2, 1]				,    lowerCAmelCase__   :      Union[str, Any]=[2, 2, 4]				,    lowerCAmelCase__   :      Dict=2				,    lowerCAmelCase__   :      Optional[Any]=2.0				,    lowerCAmelCase__   :      List[str]=True				,    lowerCAmelCase__   :      Optional[Any]=0.0				,    lowerCAmelCase__   :      str=0.0				,    lowerCAmelCase__   :      Tuple=0.1				,    lowerCAmelCase__   :      Optional[int]="gelu"				,    lowerCAmelCase__   :      Tuple=False				,    lowerCAmelCase__   :      Any=True				,    lowerCAmelCase__   :      Union[str, Any]=0.02				,    lowerCAmelCase__   :      List[str]=1e-5				,    lowerCAmelCase__   :      Dict=True				,    lowerCAmelCase__   :      int=None				,    lowerCAmelCase__   :      int=True				,    lowerCAmelCase__   :      List[str]=10				,    lowerCAmelCase__   :      Any=8				,    ):

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







      def 					__lowercase    (  self   :      List[Any]				):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					:      Dict     					=			floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]				)

             SCREAMING_SNAKE_CASE					:      Dict     					=			None
             if self.use_labels:
                    SCREAMING_SNAKE_CASE					:      int     					=			ids_tensor([self.batch_size]				,    self.type_sequence_label_size				)

             SCREAMING_SNAKE_CASE					:      List[Any]     					=			self.get_config()

             return config, pixel_values, labels







      def 					__lowercase    (  self   :      Optional[int]				):

             """simple docstring"""
             return SwinvaConfig(
                 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				,    encoder_stride=self.encoder_stride				,    )







      def 					__lowercase    (  self   :      str				,    lowerCAmelCase__   :      List[str]				,    lowerCAmelCase__   :      Tuple				,    lowerCAmelCase__   :      Any				):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					:      Any     					=			SwinvaModel(config=__UpperCamelCase				)
             model.to(__UpperCamelCase				)
             model.eval()
             SCREAMING_SNAKE_CASE					:      List[Any]     					=			model(__UpperCamelCase				)

             SCREAMING_SNAKE_CASE					:      str     					=			((config.image_size // config.patch_size) ** 2) // (4 ** (len(config.depths				) - 1))
             SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			int(config.embed_dim * 2 ** (len(config.depths				) - 1)				)

             self.parent.assertEqual(result.last_hidden_state.shape				,    (self.batch_size, expected_seq_len, expected_dim)				)







      def 					__lowercase    (  self   :      Dict				,    lowerCAmelCase__   :      Union[str, Any]				,    lowerCAmelCase__   :      str				,    lowerCAmelCase__   :      Dict				):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					:      Tuple     					=			SwinvaForMaskedImageModeling(config=__UpperCamelCase				)
             model.to(__UpperCamelCase				)
             model.eval()
             SCREAMING_SNAKE_CASE					:      str     					=			model(__UpperCamelCase				)
             self.parent.assertEqual(
                 result.logits.shape				,    (self.batch_size, self.num_channels, self.image_size, self.image_size)				)

             # test greyscale images
             SCREAMING_SNAKE_CASE					:      Tuple     					=			1
             SCREAMING_SNAKE_CASE					:      List[str]     					=			SwinvaForMaskedImageModeling(__UpperCamelCase				)
             model.to(__UpperCamelCase				)
             model.eval()

             SCREAMING_SNAKE_CASE					:      str     					=			floats_tensor([self.batch_size, 1, self.image_size, self.image_size]				)
             SCREAMING_SNAKE_CASE					:      List[str]     					=			model(__UpperCamelCase				)
             self.parent.assertEqual(result.logits.shape				,    (self.batch_size, 1, self.image_size, self.image_size)				)







      def 					__lowercase    (  self   :      Dict				,    lowerCAmelCase__   :      Any				,    lowerCAmelCase__   :      Any				,    lowerCAmelCase__   :      Optional[int]				):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					:      int     					=			self.type_sequence_label_size
             SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			SwinvaForImageClassification(__UpperCamelCase				)
             model.to(__UpperCamelCase				)
             model.eval()
             SCREAMING_SNAKE_CASE					:      Any     					=			model(__UpperCamelCase				,    labels=__UpperCamelCase				)
             self.parent.assertEqual(result.logits.shape				,    (self.batch_size, self.type_sequence_label_size)				)







      def 					__lowercase    (  self   :      Tuple				):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					:      Tuple     					=			self.prepare_config_and_inputs()
             SCREAMING_SNAKE_CASE					,SCREAMING_SNAKE_CASE					,SCREAMING_SNAKE_CASE					:      Any     					=			config_and_inputs
             SCREAMING_SNAKE_CASE					:      Dict     					=			{'''pixel_values''': pixel_values}
             return config, inputs_dict


@require_torch
class 	lowerCamelCase_							(					__snake_case    ,				__snake_case    ,				unittest.TestCase			):
      _lowerCAmelCase     :   str	     =				(
          (SwinvaModel, SwinvaForImageClassification, SwinvaForMaskedImageModeling) if is_torch_available() else ()
      )
      _lowerCAmelCase     :   str	     =				(
          {'feature-extraction': SwinvaModel, 'image-classification': SwinvaForImageClassification}
          if is_torch_available()
          else {}
      )

      _lowerCAmelCase     :   int	     =				False
      _lowerCAmelCase     :   Dict	     =				False
      _lowerCAmelCase     :   Optional[int]	     =				False
      _lowerCAmelCase     :   Union[str, Any]	     =				False







      def 					__lowercase    (  self   :      Tuple				):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					:      int     					=			SwinvaModelTester(self				)
             SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			ConfigTester(self				,    config_class=__UpperCamelCase				,    embed_dim=37				)







      def 					__lowercase    (  self   :      List[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 					__lowercase    (  self   :      Optional[Any]				):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					:      Dict     					=			self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_model(*__UpperCamelCase				)







      @unittest.skip(reason='''Got `CUDA error: misaligned address` with PyTorch 2.0.0.'''				)
      def 					__lowercase    (  self   :      Union[str, Any]				):

             """simple docstring"""
             pass







      @unittest.skip(reason='''Swinv2 does not use inputs_embeds'''				)
      def 					__lowercase    (  self   :      Optional[Any]				):

             """simple docstring"""
             pass







      def 					__lowercase    (  self   :      Tuple				):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					,SCREAMING_SNAKE_CASE					:      Tuple     					=			self.model_tester.prepare_config_and_inputs_for_common()

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







      def 					__lowercase    (  self   :      List[str]				):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					,SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			self.model_tester.prepare_config_and_inputs_for_common()

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

                    SCREAMING_SNAKE_CASE					:      int     					=			['''pixel_values''']
                    self.assertListEqual(arg_names[:1]				,    __UpperCamelCase				)







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

             """simple docstring"""
             SCREAMING_SNAKE_CASE					,SCREAMING_SNAKE_CASE					:      int     					=			self.model_tester.prepare_config_and_inputs_for_common()
             SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			True

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

                    # check that output_attentions also work using config
                    del inputs_dict["output_attentions"]
                    SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			True
                    SCREAMING_SNAKE_CASE					:      int     					=			config.window_size**2
                    SCREAMING_SNAKE_CASE					:      List[str]     					=			model_class(__UpperCamelCase				)
                    model.to(__UpperCamelCase				)
                    model.eval()
                    with torch.no_grad():
                           SCREAMING_SNAKE_CASE					:      Dict     					=			model(**self._prepare_for_class(__UpperCamelCase				,    __UpperCamelCase				)				)
                    SCREAMING_SNAKE_CASE					:      List[Any]     					=			outputs.attentions
                    self.assertEqual(len(__UpperCamelCase				)				,    __UpperCamelCase				)

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

                    # Check attention is always last and order is fine
                    SCREAMING_SNAKE_CASE					:      int     					=			True
                    SCREAMING_SNAKE_CASE					:      Optional[int]     					=			True
                    SCREAMING_SNAKE_CASE					:      str     					=			model_class(__UpperCamelCase				)
                    model.to(__UpperCamelCase				)
                    model.eval()
                    with torch.no_grad():
                           SCREAMING_SNAKE_CASE					:      int     					=			model(**self._prepare_for_class(__UpperCamelCase				,    __UpperCamelCase				)				)

                    if hasattr(self.model_tester				,    '''num_hidden_states_types'''				):
                           SCREAMING_SNAKE_CASE					:      Dict     					=			self.model_tester.num_hidden_states_types
                    else:
                           # also another +1 for reshaped_hidden_states
                           SCREAMING_SNAKE_CASE					:      Dict     					=			2
                    self.assertEqual(out_len + added_hidden_states				,    len(__UpperCamelCase				)				)

                    SCREAMING_SNAKE_CASE					:      Any     					=			outputs.attentions

                    self.assertEqual(len(__UpperCamelCase				)				,    __UpperCamelCase				)

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







      def 					__lowercase    (  self   :      Dict				,    lowerCAmelCase__   :      str				,    lowerCAmelCase__   :      str				,    lowerCAmelCase__   :      Optional[Any]				,    lowerCAmelCase__   :      Tuple				):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					:      str     					=			model_class(__UpperCamelCase				)
             model.to(__UpperCamelCase				)
             model.eval()

             with torch.no_grad():
                    SCREAMING_SNAKE_CASE					:      List[str]     					=			model(**self._prepare_for_class(__UpperCamelCase				,    __UpperCamelCase				)				)

             SCREAMING_SNAKE_CASE					:      List[Any]     					=			outputs.hidden_states

             SCREAMING_SNAKE_CASE					:      Dict     					=			getattr(
                 self.model_tester				,    '''expected_num_hidden_layers'''				,    len(self.model_tester.depths				) + 1				)
             self.assertEqual(len(__UpperCamelCase				)				,    __UpperCamelCase				)

             # Swinv2 has a different seq_length
             SCREAMING_SNAKE_CASE					:      Tuple     					=			(
                 config.patch_size
                 if isinstance(config.patch_size				,    collections.abc.Iterable				)
                 else (config.patch_size, config.patch_size)
             )

             SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			(image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])

             self.assertListEqual(
                 list(hidden_states[0].shape[-2:]				)				,    [num_patches, self.model_tester.embed_dim]				,    )

             SCREAMING_SNAKE_CASE					:      int     					=			outputs.reshaped_hidden_states
             self.assertEqual(len(__UpperCamelCase				)				,    __UpperCamelCase				)

             SCREAMING_SNAKE_CASE					,SCREAMING_SNAKE_CASE					,SCREAMING_SNAKE_CASE					,SCREAMING_SNAKE_CASE					:      Optional[int]     					=			reshaped_hidden_states[0].shape
             SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			(
                 reshaped_hidden_states[0].view(__UpperCamelCase				,    __UpperCamelCase				,    height * width				).permute(0				,    2				,    1				)
             )
             self.assertListEqual(
                 list(reshaped_hidden_states.shape[-2:]				)				,    [num_patches, self.model_tester.embed_dim]				,    )







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

             """simple docstring"""
             SCREAMING_SNAKE_CASE					,SCREAMING_SNAKE_CASE					:      List[str]     					=			self.model_tester.prepare_config_and_inputs_for_common()

             SCREAMING_SNAKE_CASE					:      Tuple     					=			(
                 self.model_tester.image_size
                 if isinstance(self.model_tester.image_size				,    collections.abc.Iterable				)
                 else (self.model_tester.image_size, self.model_tester.image_size)
             )

             for model_class in self.all_model_classes:
                    SCREAMING_SNAKE_CASE					:      List[str]     					=			True
                    self.check_hidden_states_output(__UpperCamelCase				,    __UpperCamelCase				,    __UpperCamelCase				,    __UpperCamelCase				)

                    # check that output_hidden_states also work using config
                    del inputs_dict["output_hidden_states"]
                    SCREAMING_SNAKE_CASE					:      str     					=			True

                    self.check_hidden_states_output(__UpperCamelCase				,    __UpperCamelCase				,    __UpperCamelCase				,    __UpperCamelCase				)







      def 					__lowercase    (  self   :      int				):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					,SCREAMING_SNAKE_CASE					:      int     					=			self.model_tester.prepare_config_and_inputs_for_common()
             SCREAMING_SNAKE_CASE					:      Optional[int]     					=			3

             SCREAMING_SNAKE_CASE					:      List[str]     					=			(
                 self.model_tester.image_size
                 if isinstance(self.model_tester.image_size				,    collections.abc.Iterable				)
                 else (self.model_tester.image_size, self.model_tester.image_size)
             )
             SCREAMING_SNAKE_CASE					:      List[str]     					=			(
                 config.patch_size
                 if isinstance(config.patch_size				,    collections.abc.Iterable				)
                 else (config.patch_size, config.patch_size)
             )

             SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			image_size[0] + patch_size[0] - (image_size[0] % patch_size[0])
             SCREAMING_SNAKE_CASE					:      List[Any]     					=			image_size[1] + patch_size[1] - (image_size[1] % patch_size[1])

             for model_class in self.all_model_classes:
                    SCREAMING_SNAKE_CASE					:      Dict     					=			True
                    self.check_hidden_states_output(__UpperCamelCase				,    __UpperCamelCase				,    __UpperCamelCase				,    (padded_height, padded_width)				)

                    # check that output_hidden_states also work using config
                    del inputs_dict["output_hidden_states"]
                    SCREAMING_SNAKE_CASE					:      List[Any]     					=			True
                    self.check_hidden_states_output(__UpperCamelCase				,    __UpperCamelCase				,    __UpperCamelCase				,    (padded_height, padded_width)				)







      def 					__lowercase    (  self   :      List[str]				):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_masked_image_modeling(*__UpperCamelCase				)







      def 					__lowercase    (  self   :      Tuple				):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					:      Optional[int]     					=			self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_image_classification(*__UpperCamelCase				)







      @slow
      def 					__lowercase    (  self   :      Tuple				):

             """simple docstring"""


             for model_name in SWINV2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                    SCREAMING_SNAKE_CASE					:      List[str]     					=			SwinvaModel.from_pretrained(__UpperCamelCase				)
                    self.assertIsNotNone(__UpperCamelCase				)







      def 					__lowercase    (  self   :      Tuple				):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					,SCREAMING_SNAKE_CASE					:      List[Any]     					=			self.model_tester.prepare_config_and_inputs_for_common()

             SCREAMING_SNAKE_CASE					:      int     					=			_config_zero_init(__UpperCamelCase				)
             for model_class in self.all_model_classes:
                    SCREAMING_SNAKE_CASE					:      Tuple     					=			model_class(config=__UpperCamelCase				)
                    for name, param in model.named_parameters():
                           if "embeddings" not in name and "logit_scale" not in name and 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"""				,    )


@require_vision
@require_torch
class 	lowerCamelCase_							(					unittest.TestCase			):







      @cached_property
      def 					__lowercase    (  self   :      List[str]				):

             """simple docstring"""
             return (
                 AutoImageProcessor.from_pretrained('''microsoft/swinv2-tiny-patch4-window8-256'''				)
                 if is_vision_available()
                 else None
             )







      @slow
      def 					__lowercase    (  self   :      List[Any]				):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					:      str     					=			SwinvaForImageClassification.from_pretrained('''microsoft/swinv2-tiny-patch4-window8-256'''				).to(
                 __UpperCamelCase				)
             SCREAMING_SNAKE_CASE					:      str     					=			self.default_image_processor

             SCREAMING_SNAKE_CASE					:      List[Any]     					=			Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''				)
             SCREAMING_SNAKE_CASE					:      Tuple     					=			image_processor(images=__UpperCamelCase				,    return_tensors='''pt'''				).to(__UpperCamelCase				)

             # forward pass
             with torch.no_grad():
                    SCREAMING_SNAKE_CASE					:      Dict     					=			model(**__UpperCamelCase				)

             # verify the logits
             SCREAMING_SNAKE_CASE					:      str     					=			torch.Size((1, 10_00)				)
             self.assertEqual(outputs.logits.shape				,    __UpperCamelCase				)
             SCREAMING_SNAKE_CASE					:      Optional[int]     					=			torch.tensor([-0.3947, -0.4306, 0.0026]				).to(__UpperCamelCase				)
             self.assertTrue(torch.allclose(outputs.logits[0, :3]				,    __UpperCamelCase				,    atol=1e-4				)				)









'''simple docstring'''



from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCAmelCase_     :       Optional[int]								=						logging.get_logger(__name__)

lowerCAmelCase_     :       Optional[Any]								=						{
    'microsoft/swinv2-tiny-patch4-window8-256': (
        'https://huggingface.co/microsoft/swinv2-tiny-patch4-window8-256/resolve/main/config.json'
    ),
}
class 	lowerCamelCase_							(					snake_case_			):
						_lowerCAmelCase     :   str	     =				'swinv2'

						_lowerCAmelCase     :   Optional[int]	     =				{
						    'num_attention_heads': 'num_heads',
						    'num_hidden_layers': 'num_layers',
						}







						def __init__(  self   :      Optional[int]				,    lowerCAmelCase__   :      Any=2_24				,    lowerCAmelCase__   :      Optional[Any]=4				,    lowerCAmelCase__   :      Tuple=3				,    lowerCAmelCase__   :      Tuple=96				,    lowerCAmelCase__   :      Optional[int]=[2, 2, 6, 2]				,    lowerCAmelCase__   :      Tuple=[3, 6, 12, 24]				,    lowerCAmelCase__   :      List[str]=7				,    lowerCAmelCase__   :      Tuple=4.0				,    lowerCAmelCase__   :      Dict=True				,    lowerCAmelCase__   :      Any=0.0				,    lowerCAmelCase__   :      Optional[int]=0.0				,    lowerCAmelCase__   :      Optional[Any]=0.1				,    lowerCAmelCase__   :      int="gelu"				,    lowerCAmelCase__   :      Tuple=False				,    lowerCAmelCase__   :      Tuple=0.02				,    lowerCAmelCase__   :      Dict=1e-5				,    lowerCAmelCase__   :      List[str]=32				,    **lowerCAmelCase__   :      Union[str, Any]				,    ):

													"""simple docstring"""
													super().__init__(**lowerCAmelCase__				)

													SCREAMING_SNAKE_CASE					:      int     					=			image_size
													SCREAMING_SNAKE_CASE					:      Optional[int]     					=			patch_size
													SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			num_channels
													SCREAMING_SNAKE_CASE					:      int     					=			embed_dim
													SCREAMING_SNAKE_CASE					:      List[Any]     					=			depths
													SCREAMING_SNAKE_CASE					:      str     					=			len(lowerCAmelCase__				)
													SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			num_heads
													SCREAMING_SNAKE_CASE					:      Tuple     					=			window_size
													SCREAMING_SNAKE_CASE					:      Any     					=			mlp_ratio
													SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			qkv_bias
													SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			hidden_dropout_prob
													SCREAMING_SNAKE_CASE					:      int     					=			attention_probs_dropout_prob
													SCREAMING_SNAKE_CASE					:      List[str]     					=			drop_path_rate
													SCREAMING_SNAKE_CASE					:      Any     					=			hidden_act
													SCREAMING_SNAKE_CASE					:      List[Any]     					=			use_absolute_embeddings
													SCREAMING_SNAKE_CASE					:      List[str]     					=			layer_norm_eps
													SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			initializer_range
													SCREAMING_SNAKE_CASE					:      Dict     					=			encoder_stride
													# we set the hidden_size attribute in order to make Swinv2 work with VisionEncoderDecoderModel
													# this indicates the channel dimension after the last stage of the model
													SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			int(embed_dim * 2 ** (len(lowerCAmelCase__				) - 1)				)
													SCREAMING_SNAKE_CASE					:      int     					=			(0, 0, 0, 0)




