code: 
  
  
  '''simple docstring'''
  
  
  
  
  
  import json
  from typing import List, Optional, Tuple
  
  from tokenizers import normalizers
  
  from ...tokenization_utils_fast import PreTrainedTokenizerFast
  from ...utils import logging
  from .tokenization_layoutlm import LayoutLMTokenizer
  
  
  UpperCAmelCase__      =							logging.get_logger(__name__)
  
  UpperCAmelCase__      =							{'''vocab_file''': '''vocab.txt''', '''tokenizer_file''': '''tokenizer.json'''}
  
  UpperCAmelCase__      =							{
      '''vocab_file''': {
          '''microsoft/layoutlm-base-uncased''': (
              '''https://huggingface.co/microsoft/layoutlm-base-uncased/resolve/main/vocab.txt'''
          ),
          '''microsoft/layoutlm-large-uncased''': (
              '''https://huggingface.co/microsoft/layoutlm-large-uncased/resolve/main/vocab.txt'''
          ),
      },
      '''tokenizer_file''': {
          '''microsoft/layoutlm-base-uncased''': (
              '''https://huggingface.co/microsoft/layoutlm-base-uncased/resolve/main/tokenizer.json'''
          ),
          '''microsoft/layoutlm-large-uncased''': (
              '''https://huggingface.co/microsoft/layoutlm-large-uncased/resolve/main/tokenizer.json'''
          ),
      },
  }
  
  UpperCAmelCase__      =							{
      '''microsoft/layoutlm-base-uncased''': 5_1_2,
      '''microsoft/layoutlm-large-uncased''': 5_1_2,
  }
  
  UpperCAmelCase__      =							{
      '''microsoft/layoutlm-base-uncased''': {'''do_lower_case''': True},
      '''microsoft/layoutlm-large-uncased''': {'''do_lower_case''': True},
  }
  class 	a__				(				a_      ):
  
  
  
  
  
  							'''simple docstring'''
  
  							A	:							Optional[Any]							= VOCAB_FILES_NAMES
  							A	:							Tuple							= PRETRAINED_VOCAB_FILES_MAP
  							A	:							int							= PRETRAINED_INIT_CONFIGURATION
  							A	:							Any							= PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
  							A	:							List[str]							= LayoutLMTokenizer
  							def __init__(     self       : Optional[Any] ,						lowerCAmelCase_       : Union[str, Any]=None ,						lowerCAmelCase_       : List[Any]=None ,						lowerCAmelCase_       : int=True ,						lowerCAmelCase_       : Optional[int]="[UNK]" ,						lowerCAmelCase_       : str="[SEP]" ,						lowerCAmelCase_       : str="[PAD]" ,						lowerCAmelCase_       : List[str]="[CLS]" ,						lowerCAmelCase_       : Union[str, Any]="[MASK]" ,						lowerCAmelCase_       : Dict=True ,						lowerCAmelCase_       : Any=None ,						**lowerCAmelCase_       : Union[str, Any] ,						)			->		Optional[Any]:
  										super().__init__(
  										    lowerCAmelCase_ ,						tokenizer_file=lowerCAmelCase_ ,						do_lower_case=lowerCAmelCase_ ,						unk_token=lowerCAmelCase_ ,						sep_token=lowerCAmelCase_ ,						pad_token=lowerCAmelCase_ ,						cls_token=lowerCAmelCase_ ,						mask_token=lowerCAmelCase_ ,						tokenize_chinese_chars=lowerCAmelCase_ ,						strip_accents=lowerCAmelCase_ ,						**lowerCAmelCase_ ,						)
  
  										__A=  json.loads(self.backend_tokenizer.normalizer.__getstate__()  )
  										if (
  										    normalizer_state.get('lowercase' ,						lowerCAmelCase_  ) != do_lower_case
  										    or normalizer_state.get('strip_accents' ,						lowerCAmelCase_  ) != strip_accents
  										    or normalizer_state.get('handle_chinese_chars' ,						lowerCAmelCase_  ) != tokenize_chinese_chars
  										):
  													__A=  getattr(lowerCAmelCase_ ,						normalizer_state.pop('type'  )  )
  													__A=  do_lower_case
  													__A=  strip_accents
  													__A=  tokenize_chinese_chars
  													__A=  normalizer_class(**lowerCAmelCase_  )
  
  										__A=  do_lower_case
  							def 				lowerCAmelCase    (     self       : Tuple ,						lowerCAmelCase_       : Union[str, Any] ,						lowerCAmelCase_       : Any=None  )			->		int:
  										__A=  [self.cls_token_id] + token_ids_a + [self.sep_token_id]
  
  										if token_ids_a:
  													output += token_ids_a + [self.sep_token_id]
  
  										return output
  							def 				lowerCAmelCase    (     self       : str ,						lowerCAmelCase_       : List[int] ,						lowerCAmelCase_       : Optional[List[int]] = None  )			->		List[int]:
  										__A=  [self.sep_token_id]
  										__A=  [self.cls_token_id]
  										if token_ids_a is None:
  													return len(cls + token_ids_a + sep  ) * [0]
  										return len(cls + token_ids_a + sep  ) * [0] + len(token_ids_a + sep  ) * [1]
  
  							def 				lowerCAmelCase    (     self       : List[str] ,						lowerCAmelCase_       : str ,						lowerCAmelCase_       : Optional[str] = None  )			->		Tuple[str]:
  										__A=  self._tokenizer.model.save(lowerCAmelCase_ ,						name=lowerCAmelCase_  )
  										return tuple(lowerCAmelCase_  )
  
  
  
  
style_context: 
  
  
  '''simple docstring'''
  
  
  
  
  
  import collections
  import inspect
  import unittest
  
  from transformers import SwinConfig
  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_backbone_common import BackboneTesterMixin
  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 SwinBackbone, SwinForImageClassification, SwinForMaskedImageModeling, SwinModel
  					from transformers.models.swin.modeling_swin import SWIN_PRETRAINED_MODEL_ARCHIVE_LIST
  
  
  if is_vision_available():
  					from PIL import Image
  
  					from transformers import AutoImageProcessor
  class 	a__				:
  
  
  
  
  
  			'''simple docstring'''
  
  			def __init__(     self       : Union[str, Any] ,						lowerCAmelCase_       : int ,						lowerCAmelCase_       : List[str]=13 ,						lowerCAmelCase_       : Dict=32 ,						lowerCAmelCase_       : Optional[Any]=2 ,						lowerCAmelCase_       : Optional[int]=3 ,						lowerCAmelCase_       : Optional[Any]=16 ,						lowerCAmelCase_       : int=[1, 2, 1] ,						lowerCAmelCase_       : List[str]=[2, 2, 4] ,						lowerCAmelCase_       : Tuple=2 ,						lowerCAmelCase_       : List[str]=2.0 ,						lowerCAmelCase_       : List[Any]=True ,						lowerCAmelCase_       : str=0.0 ,						lowerCAmelCase_       : str=0.0 ,						lowerCAmelCase_       : str=0.1 ,						lowerCAmelCase_       : Optional[int]="gelu" ,						lowerCAmelCase_       : Union[str, Any]=False ,						lowerCAmelCase_       : Union[str, Any]=True ,						lowerCAmelCase_       : List[Any]=0.02 ,						lowerCAmelCase_       : Union[str, Any]=1E-5 ,						lowerCAmelCase_       : Optional[Any]=True ,						lowerCAmelCase_       : str=None ,						lowerCAmelCase_       : List[str]=True ,						lowerCAmelCase_       : Tuple=10 ,						lowerCAmelCase_       : Any=8 ,						lowerCAmelCase_       : int=["stage1", "stage2"] ,						lowerCAmelCase_       : Optional[int]=[1, 2] ,						)			->		Union[str, Any]:
  						__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=  type_sequence_label_size
  						__A=  encoder_stride
  						__A=  out_features
  						__A=  out_indices
  			def 				lowerCAmelCase    (     self       : Optional[int]  )			->		Optional[int]:
  						__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       : List[Any]  )			->		Optional[int]:
  						return SwinConfig(
  						    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 ,						out_features=self.out_features ,						out_indices=self.out_indices ,						)
  			def 				lowerCAmelCase    (     self       : List[Any] ,						lowerCAmelCase_       : List[str] ,						lowerCAmelCase_       : int ,						lowerCAmelCase_       : List[Any]  )			->		str:
  						__A=  SwinModel(config=lowerCAmelCase_  )
  						model.to(lowerCAmelCase_  )
  						model.eval()
  						__A=  model(lowerCAmelCase_  )
  
  						__A=  ((config.image_size // config.patch_size) ** 2) // (4 ** (len(config.depths  ) - 1))
  						__A=  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 				lowerCAmelCase    (     self       : str ,						lowerCAmelCase_       : Optional[Any] ,						lowerCAmelCase_       : List[Any] ,						lowerCAmelCase_       : List[Any]  )			->		Optional[int]:
  						__A=  SwinBackbone(config=lowerCAmelCase_  )
  						model.to(lowerCAmelCase_  )
  						model.eval()
  						__A=  model(lowerCAmelCase_  )
  
  						# verify hidden states
  						self.parent.assertEqual(len(result.feature_maps  ) ,						len(config.out_features  )  )
  						self.parent.assertListEqual(list(result.feature_maps[0].shape  ) ,						[self.batch_size, model.channels[0], 16, 16]  )
  
  						# verify channels
  						self.parent.assertEqual(len(model.channels  ) ,						len(config.out_features  )  )
  
  						# verify backbone works with out_features=None
  						__A=  None
  						__A=  SwinBackbone(config=lowerCAmelCase_  )
  						model.to(lowerCAmelCase_  )
  						model.eval()
  						__A=  model(lowerCAmelCase_  )
  
  						# verify feature maps
  						self.parent.assertEqual(len(result.feature_maps  ) ,						1  )
  						self.parent.assertListEqual(list(result.feature_maps[0].shape  ) ,						[self.batch_size, model.channels[-1], 4, 4]  )
  
  						# verify channels
  						self.parent.assertEqual(len(model.channels  ) ,						1  )
  			def 				lowerCAmelCase    (     self       : Any ,						lowerCAmelCase_       : List[Any] ,						lowerCAmelCase_       : List[str] ,						lowerCAmelCase_       : Dict  )			->		Optional[int]:
  						__A=  SwinForMaskedImageModeling(config=lowerCAmelCase_  )
  						model.to(lowerCAmelCase_  )
  						model.eval()
  						__A=  model(lowerCAmelCase_  )
  						self.parent.assertEqual(
  						    result.logits.shape ,						(self.batch_size, self.num_channels, self.image_size, self.image_size)  )
  
  						# test greyscale images
  						__A=  1
  						__A=  SwinForMaskedImageModeling(lowerCAmelCase_  )
  						model.to(lowerCAmelCase_  )
  						model.eval()
  
  						__A=  floats_tensor([self.batch_size, 1, self.image_size, self.image_size]  )
  						__A=  model(lowerCAmelCase_  )
  						self.parent.assertEqual(result.logits.shape ,						(self.batch_size, 1, self.image_size, self.image_size)  )
  			def 				lowerCAmelCase    (     self       : Union[str, Any] ,						lowerCAmelCase_       : List[str] ,						lowerCAmelCase_       : int ,						lowerCAmelCase_       : Dict  )			->		str:
  						__A=  self.type_sequence_label_size
  						__A=  SwinForImageClassification(lowerCAmelCase_  )
  						model.to(lowerCAmelCase_  )
  						model.eval()
  						__A=  model(lowerCAmelCase_ ,						labels=lowerCAmelCase_  )
  						self.parent.assertEqual(result.logits.shape ,						(self.batch_size, self.type_sequence_label_size)  )
  
  						# test greyscale images
  						__A=  1
  						__A=  SwinForImageClassification(lowerCAmelCase_  )
  						model.to(lowerCAmelCase_  )
  						model.eval()
  
  						__A=  floats_tensor([self.batch_size, 1, self.image_size, self.image_size]  )
  						__A=  model(lowerCAmelCase_  )
  						self.parent.assertEqual(result.logits.shape ,						(self.batch_size, self.type_sequence_label_size)  )
  
  			def 				lowerCAmelCase    (     self       : List[Any]  )			->		Any:
  						__A=  self.prepare_config_and_inputs()
  						(
  						    (
  						    __A
  						),  (
  						    __A
  						),  (
  						    __A
  						),  
  						)=  config_and_inputs
  						__A=  {'pixel_values': pixel_values}
  						return config, inputs_dict
  
  
  @require_torch
  class 	a__				(				a_			,     a_			,     unittest.TestCase      ):
  
  
  
  
  
  			'''simple docstring'''
  
  			A	:							Optional[int]							= (
  			    (
  			        SwinModel,
  			        SwinBackbone,
  			        SwinForImageClassification,
  			        SwinForMaskedImageModeling,
  			    )
  			    if is_torch_available()
  			    else ()
  			)
  			A	:							Tuple							= (
  			    {'''feature-extraction''': SwinModel, '''image-classification''': SwinForImageClassification}
  			    if is_torch_available()
  			    else {}
  			)
  			A	:							str							= True
  
  			A	:							int							= False
  			A	:							str							= False
  			A	:							Any							= False
  			def 				lowerCAmelCase    (     self       : List[str]  )			->		str:
  						__A=  SwinModelTester(self  )
  						__A=  ConfigTester(self ,						config_class=lowerCAmelCase_ ,						embed_dim=37  )
  			def 				lowerCAmelCase    (     self       : Union[str, Any]  )			->		Optional[Any]:
  						self.create_and_test_config_common_properties()
  						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       : str  )			->		List[str]:
  						return
  			def 				lowerCAmelCase    (     self       : str  )			->		Optional[int]:
  						__A=  self.model_tester.prepare_config_and_inputs()
  						self.model_tester.create_and_check_model(*lowerCAmelCase_  )
  			@unittest.skip(reason='Got `CUDA error: misaligned address` with PyTorch 2.0.0.'  )
  			def 				lowerCAmelCase    (     self       : List[str]  )			->		Dict:
  						pass
  			def 				lowerCAmelCase    (     self       : Any  )			->		Optional[int]:
  						super().test_training_gradient_checkpointing()
  			def 				lowerCAmelCase    (     self       : Tuple  )			->		int:
  						__A=  self.model_tester.prepare_config_and_inputs()
  						self.model_tester.create_and_check_backbone(*lowerCAmelCase_  )
  			def 				lowerCAmelCase    (     self       : List[Any]  )			->		int:
  						__A=  self.model_tester.prepare_config_and_inputs()
  						self.model_tester.create_and_check_for_masked_image_modeling(*lowerCAmelCase_  )
  			def 				lowerCAmelCase    (     self       : List[str]  )			->		int:
  						__A=  self.model_tester.prepare_config_and_inputs()
  						self.model_tester.create_and_check_for_image_classification(*lowerCAmelCase_  )
  			@unittest.skip(reason='Swin does not use inputs_embeds'  )
  			def 				lowerCAmelCase    (     self       : List[str]  )			->		Tuple:
  						pass
  			@unittest.skip(reason='Swin Transformer does not use feedforward chunking'  )
  			def 				lowerCAmelCase    (     self       : str  )			->		str:
  						pass
  			def 				lowerCAmelCase    (     self       : Optional[int]  )			->		Tuple:
  						__A,  __A=  self.model_tester.prepare_config_and_inputs_for_common()
  
  						for model_class in self.all_model_classes:
  									__A=  model_class(lowerCAmelCase_  )
  									self.assertIsInstance(model.get_input_embeddings() ,						(nn.Module)  )
  									__A=  model.get_output_embeddings()
  									self.assertTrue(x is None or isinstance(lowerCAmelCase_ ,						nn.Linear  )  )
  			def 				lowerCAmelCase    (     self       : Any  )			->		Any:
  						__A,  __A=  self.model_tester.prepare_config_and_inputs_for_common()
  
  						for model_class in self.all_model_classes:
  									__A=  model_class(lowerCAmelCase_  )
  									__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] ,						lowerCAmelCase_  )
  			def 				lowerCAmelCase    (     self       : Any  )			->		Union[str, Any]:
  						__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(lowerCAmelCase_  )
  									model.to(lowerCAmelCase_  )
  									model.eval()
  									with torch.no_grad():
  												__A=  model(**self._prepare_for_class(lowerCAmelCase_ ,						lowerCAmelCase_  )  )
  									__A=  outputs.attentions
  									__A=  len(self.model_tester.depths  )
  									self.assertEqual(len(lowerCAmelCase_  ) ,						lowerCAmelCase_  )
  
  									# check that output_attentions also work using config
  									del inputs_dict["output_attentions"]
  									__A=  True
  									__A=  config.window_size**2
  									__A=  model_class(lowerCAmelCase_  )
  									model.to(lowerCAmelCase_  )
  									model.eval()
  									with torch.no_grad():
  												__A=  model(**self._prepare_for_class(lowerCAmelCase_ ,						lowerCAmelCase_  )  )
  									__A=  outputs.attentions
  									self.assertEqual(len(lowerCAmelCase_  ) ,						lowerCAmelCase_  )
  
  									self.assertListEqual(
  									    list(attentions[0].shape[-3:]  ) ,						[self.model_tester.num_heads[0], window_size_squared, window_size_squared] ,						)
  									__A=  len(lowerCAmelCase_  )
  
  									# Check attention is always last and order is fine
  									__A=  True
  									__A=  True
  									__A=  model_class(lowerCAmelCase_  )
  									model.to(lowerCAmelCase_  )
  									model.eval()
  									with torch.no_grad():
  												__A=  model(**self._prepare_for_class(lowerCAmelCase_ ,						lowerCAmelCase_  )  )
  
  									# also another +1 for reshaped_hidden_states
  									__A=  1 if model_class.__name__ == 'SwinBackbone' else 2
  									self.assertEqual(out_len + added_hidden_states ,						len(lowerCAmelCase_  )  )
  
  									__A=  outputs.attentions
  
  									self.assertEqual(len(lowerCAmelCase_  ) ,						lowerCAmelCase_  )
  
  									self.assertListEqual(
  									    list(self_attentions[0].shape[-3:]  ) ,						[self.model_tester.num_heads[0], window_size_squared, window_size_squared] ,						)
  			def 				lowerCAmelCase    (     self       : str ,						lowerCAmelCase_       : List[str] ,						lowerCAmelCase_       : List[str] ,						lowerCAmelCase_       : List[Any] ,						lowerCAmelCase_       : int  )			->		Dict:
  						__A=  model_class(lowerCAmelCase_  )
  						model.to(lowerCAmelCase_  )
  						model.eval()
  
  						with torch.no_grad():
  									__A=  model(**self._prepare_for_class(lowerCAmelCase_ ,						lowerCAmelCase_  )  )
  
  						__A=  outputs.hidden_states
  
  						__A=  getattr(
  						    self.model_tester ,						'expected_num_hidden_layers' ,						len(self.model_tester.depths  ) + 1  )
  						self.assertEqual(len(lowerCAmelCase_  ) ,						lowerCAmelCase_  )
  
  						# Swin has a different seq_length
  						__A=  (
  						    config.patch_size
  						    if isinstance(config.patch_size ,						collections.abc.Iterable  )
  						    else (config.patch_size, config.patch_size)
  						)
  
  						__A=  (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] ,						)
  
  						if not model_class.__name__ == "SwinBackbone":
  									__A=  outputs.reshaped_hidden_states
  									self.assertEqual(len(lowerCAmelCase_  ) ,						lowerCAmelCase_  )
  
  									__A,  __A,  __A,  __A=  reshaped_hidden_states[0].shape
  									__A=  (
  									    reshaped_hidden_states[0].view(lowerCAmelCase_ ,						lowerCAmelCase_ ,						height * width  ).permute(0 ,						2 ,						1  )
  									)
  									self.assertListEqual(
  									    list(reshaped_hidden_states.shape[-2:]  ) ,						[num_patches, self.model_tester.embed_dim] ,						)
  			def 				lowerCAmelCase    (     self       : Optional[Any]  )			->		str:
  						__A,  __A=  self.model_tester.prepare_config_and_inputs_for_common()
  
  						__A=  (
  						    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:
  									__A=  True
  									self.check_hidden_states_output(lowerCAmelCase_ ,						lowerCAmelCase_ ,						lowerCAmelCase_ ,						lowerCAmelCase_  )
  
  									# check that output_hidden_states also work using config
  									del inputs_dict["output_hidden_states"]
  									__A=  True
  
  									self.check_hidden_states_output(lowerCAmelCase_ ,						lowerCAmelCase_ ,						lowerCAmelCase_ ,						lowerCAmelCase_  )
  			def 				lowerCAmelCase    (     self       : str  )			->		str:
  						__A,  __A=  self.model_tester.prepare_config_and_inputs_for_common()
  						__A=  3
  
  						__A=  (
  						    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)
  						)
  						__A=  (
  						    config.patch_size
  						    if isinstance(config.patch_size ,						collections.abc.Iterable  )
  						    else (config.patch_size, config.patch_size)
  						)
  
  						__A=  image_size[0] + patch_size[0] - (image_size[0] % patch_size[0])
  						__A=  image_size[1] + patch_size[1] - (image_size[1] % patch_size[1])
  
  						for model_class in self.all_model_classes:
  									__A=  True
  									self.check_hidden_states_output(lowerCAmelCase_ ,						lowerCAmelCase_ ,						lowerCAmelCase_ ,						(padded_height, padded_width)  )
  
  									# check that output_hidden_states also work using config
  									del inputs_dict["output_hidden_states"]
  									__A=  True
  									self.check_hidden_states_output(lowerCAmelCase_ ,						lowerCAmelCase_ ,						lowerCAmelCase_ ,						(padded_height, padded_width)  )
  			@slow
  			def 				lowerCAmelCase    (     self       : Any  )			->		Any:
  						for model_name in SWIN_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
  									__A=  SwinModel.from_pretrained(lowerCAmelCase_  )
  									self.assertIsNotNone(lowerCAmelCase_  )
  
  			def 				lowerCAmelCase    (     self       : Union[str, Any]  )			->		Union[str, Any]:
  						__A,  __A=  self.model_tester.prepare_config_and_inputs_for_common()
  
  						__A=  _config_zero_init(lowerCAmelCase_  )
  						for model_class in self.all_model_classes:
  									__A=  model_class(config=lowerCAmelCase_  )
  									for name, param in model.named_parameters():
  												if "embeddings" 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 	a__				(				unittest.TestCase      ):
  
  
  
  
  
  			'''simple docstring'''
  
  			@cached_property
  			def 				lowerCAmelCase    (     self       : int  )			->		Dict:
  						return (
  						    AutoImageProcessor.from_pretrained('microsoft/swin-tiny-patch4-window7-224'  )
  						    if is_vision_available()
  						    else None
  						)
  
  			@slow
  			def 				lowerCAmelCase    (     self       : str  )			->		Any:
  						__A=  SwinForImageClassification.from_pretrained('microsoft/swin-tiny-patch4-window7-224'  ).to(lowerCAmelCase_  )
  						__A=  self.default_image_processor
  
  						__A=  Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'  )
  						__A=  image_processor(images=lowerCAmelCase_ ,						return_tensors='pt'  ).to(lowerCAmelCase_  )
  
  						# forward pass
  						with torch.no_grad():
  									__A=  model(**lowerCAmelCase_  )
  
  						# verify the logits
  						__A=  torch.Size((1, 1_000)  )
  						self.assertEqual(outputs.logits.shape ,						lowerCAmelCase_  )
  						__A=  torch.tensor([-0.09_48, -0.64_54, -0.09_21]  ).to(lowerCAmelCase_  )
  						self.assertTrue(torch.allclose(outputs.logits[0, :3] ,						lowerCAmelCase_ ,						atol=1E-4  )  )
  
  
  @require_torch
  class 	a__				(				unittest.TestCase			,     a_      ):
  
  
  
  
  
  			'''simple docstring'''
  
  			A	:							List[str]							= (SwinBackbone,) if is_torch_available() else ()
  			A	:							List[Any]							= SwinConfig
  			def 				lowerCAmelCase    (     self       : Tuple  )			->		Dict:
  						__A=  SwinModelTester(self  )
  
  
  
  