code: 
  
  
  
  
  """simple docstring"""
  
  
  
  from __future__ import annotations
  
  import inspect
  import unittest
  
  import numpy as np
  
  from transformers import SwinConfig
  from transformers.testing_utils import require_tf, require_vision, slow, to_atuple
  from transformers.utils import cached_property, is_tf_available, is_vision_available
  
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor
  from ...test_pipeline_mixin import PipelineTesterMixin
  
  
  if is_tf_available():
  						import tensorflow as tf
  
  						from transformers.models.swin.modeling_tf_swin import (
  						    TF_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST,
  						    TFSwinForImageClassification,
  						    TFSwinForMaskedImageModeling,
  						    TFSwinModel,
  						)
  
  
  if is_vision_available():
  						from PIL import Image
  
  						from transformers import AutoImageProcessor
  
  
  
  
  class 			UpperCAmelCase_						:
  
  
  
  
  				def __init__(					self		: Dict			,				snake_case_		: Any			,				snake_case_		: int=13			,				snake_case_		: Union[str, Any]=32			,				snake_case_		: Union[str, Any]=2			,				snake_case_		: Any=3			,				snake_case_		: List[str]=16			,				snake_case_		: str=[1, 2, 1]			,				snake_case_		: List[str]=[2, 2, 4]			,				snake_case_		: List[Any]=2			,				snake_case_		: Tuple=2.0			,				snake_case_		: Optional[Any]=True			,				snake_case_		: List[Any]=0.0			,				snake_case_		: List[Any]=0.0			,				snake_case_		: List[str]=0.1			,				snake_case_		: Optional[Any]="gelu"			,				snake_case_		: str=False			,				snake_case_		: Tuple=True			,				snake_case_		: Optional[int]=0.02			,				snake_case_		: List[str]=1e-5			,				snake_case_		: Optional[int]=True			,				snake_case_		: Optional[int]=None			,				snake_case_		: List[Any]=True			,				snake_case_		: Optional[int]=10			,				snake_case_		: int=8			,				)   ->							Optional[int]:
  
  
  
  
  					'''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__ =       type_sequence_label_size
  					A__ =       encoder_stride
  
  
  
  
  				def 							__magic_name__							(					self		: List[str]   )   ->							List[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 							__magic_name__							(					self		: Any   )   ->							Optional[int]:
  
  
  
  
  					'''simple docstring'''
  
  					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			,				)
  
  
  
  
  				def 							__magic_name__							(					self		: List[Any]			,				snake_case_		: Dict			,				snake_case_		: Dict			,				snake_case_		: List[str]   )   ->							Any:
  
  
  
  
  					'''simple docstring'''
  
  					A__ =       TFSwinModel(config=__a   )
  					A__ =       model(__a   )
  
  					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 							__magic_name__							(					self		: Union[str, Any]			,				snake_case_		: Tuple			,				snake_case_		: List[str]			,				snake_case_		: Tuple   )   ->							str:
  
  
  
  
  					'''simple docstring'''
  
  					A__ =       TFSwinForMaskedImageModeling(config=__a   )
  					A__ =       model(__a   )
  					self.parent.assertEqual(
  					    result.logits.shape			,				(self.batch_size, self.num_channels, self.image_size, self.image_size)   )
  
  					# test greyscale images
  					A__ =       1
  					A__ =       TFSwinForMaskedImageModeling(__a   )
  
  					A__ =       floats_tensor([self.batch_size, 1, self.image_size, self.image_size]   )
  					A__ =       model(__a   )
  					self.parent.assertEqual(result.logits.shape			,				(self.batch_size, 1, self.image_size, self.image_size)   )
  
  
  
  
  				def 							__magic_name__							(					self		: Any			,				snake_case_		: Any			,				snake_case_		: Optional[int]			,				snake_case_		: Optional[int]   )   ->							Optional[Any]:
  
  
  
  
  					'''simple docstring'''
  
  					A__ =       self.type_sequence_label_size
  					A__ =       TFSwinForImageClassification(__a   )
  					A__ =       model(__a			,				labels=__a   )
  					self.parent.assertEqual(result.logits.shape			,				(self.batch_size, self.type_sequence_label_size)   )
  
  					# test greyscale images
  					A__ =       1
  					A__ =       TFSwinForImageClassification(__a   )
  					A__ =       floats_tensor([self.batch_size, 1, self.image_size, self.image_size]   )
  					A__ =       model(__a   )
  					self.parent.assertEqual(result.logits.shape			,				(self.batch_size, self.type_sequence_label_size)   )
  
  
  
  
  				def 							__magic_name__							(					self		: Optional[Any]   )   ->							Optional[Any]:
  
  
  
  
  					'''simple docstring'''
  
  					A__ =       self.prepare_config_and_inputs()
  					A__ =       config_and_inputs
  					A__ =       {'pixel_values': pixel_values}
  					return config, inputs_dict
  
  
  
  
  
  
  @require_tf
  class 			UpperCAmelCase_						(		lowerCAmelCase_,     lowerCAmelCase_,     unittest.TestCase							):
  				lowercase__		      =   (
  				    (
  				        TFSwinModel,
  				        TFSwinForImageClassification,
  				        TFSwinForMaskedImageModeling,
  				    )
  				    if is_tf_available()
  				    else ()
  				)
  				lowercase__		      =   (
  				    {'''feature-extraction''': TFSwinModel, '''image-classification''': TFSwinForImageClassification}
  				    if is_tf_available()
  				    else {}
  				)
  
  				lowercase__		      =   False
  				lowercase__		      =   False
  				lowercase__		      =   False
  				lowercase__		      =   False
  
  
  
  
  				def 							__magic_name__							(					self		: str   )   ->							List[str]:
  
  
  
  
  					'''simple docstring'''
  
  					A__ =       TFSwinModelTester(self   )
  					A__ =       ConfigTester(self			,				config_class=__a			,				embed_dim=37   )
  
  
  
  
  				def 							__magic_name__							(					self		: Optional[Any]   )   ->							Any:
  
  
  
  
  					'''simple docstring'''
  
  					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 							__magic_name__							(					self		: Union[str, Any]   )   ->							Optional[int]:
  
  
  
  
  					'''simple docstring'''
  
  					return
  
  
  
  
  				def 							__magic_name__							(					self		: Union[str, Any]   )   ->							Optional[int]:
  
  
  
  
  					'''simple docstring'''
  
  					A__ =       self.model_tester.prepare_config_and_inputs()
  					self.model_tester.create_and_check_model(*__a   )
  
  
  
  
  				def 							__magic_name__							(					self		: int   )   ->							Tuple:
  
  
  
  
  					'''simple docstring'''
  
  					A__ =       self.model_tester.prepare_config_and_inputs()
  					self.model_tester.create_and_check_for_masked_image_modeling(*__a   )
  
  
  
  
  				def 							__magic_name__							(					self		: Optional[int]   )   ->							int:
  
  
  
  
  					'''simple docstring'''
  
  					A__ =       self.model_tester.prepare_config_and_inputs()
  					self.model_tester.create_and_check_for_image_classification(*__a   )
  
  
  
  
  				@unittest.skip(reason="Swin does not use inputs_embeds"   )
  				def 							__magic_name__							(					self		: Dict   )   ->							str:
  
  
  
  
  					'''simple docstring'''
  
  					pass
  
  
  
  
  				def 							__magic_name__							(					self		: List[Any]   )   ->							Optional[Any]:
  
  
  
  
  					'''simple docstring'''
  
  					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()			,				tf.keras.layers.Layer   )
  						A__ =       model.get_output_embeddings()
  						self.assertTrue(x is None or isinstance(__a			,				tf.keras.layers.Dense   )   )
  
  
  
  
  				def 							__magic_name__							(					self		: List[str]   )   ->							Dict:
  
  
  
  
  					'''simple docstring'''
  
  					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.call   )
  						# signature.parameters is an OrderedDict => so arg_names order is deterministic
  						A__ =       [*signature.parameters.keys()]
  
  						A__ =       ['pixel_values']
  						self.assertListEqual(arg_names[:1]			,				__a   )
  
  
  
  
  				def 							__magic_name__							(					self		: Optional[int]   )   ->							Optional[int]:
  
  
  
  
  					'''simple docstring'''
  
  					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   )
  						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   )
  						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   )
  						A__ =       model(**self._prepare_for_class(__a			,				__a   )   )
  
  						if hasattr(self.model_tester			,				"num_hidden_states_types"   ):
  							A__ =       self.model_tester.num_hidden_states_types
  						else:
  							# also another +1 for reshaped_hidden_states
  							A__ =       2
  						self.assertEqual(out_len + added_hidden_states			,				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]			,				)
  
  
  
  
  				def 							__magic_name__							(					self		: Dict			,				snake_case_		: Any			,				snake_case_		: Tuple			,				snake_case_		: Dict			,				snake_case_		: List[str]   )   ->							Tuple:
  
  
  
  
  					'''simple docstring'''
  
  					A__ =       model_class(__a   )
  					A__ =       model(**self._prepare_for_class(__a			,				__a   )   )
  					A__ =       outputs.hidden_states
  
  					A__ =       getattr(
  					    self.model_tester			,				"expected_num_hidden_layers"			,				len(self.model_tester.depths   ) + 1   )
  					self.assertEqual(len(__a   )			,				__a   )
  
  					# Swin has a different seq_length
  					A__ =       to_atuple(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]			,				)
  
  					A__ =       outputs.reshaped_hidden_states
  					self.assertEqual(len(__a   )			,				__a   )
  
  					A__ =       reshaped_hidden_states[0].shape
  
  					A__ =       tf.reshape(reshaped_hidden_states[0]			,				(batch_size, num_channels, height * width)   )
  					A__ =       tf.transpose(__a			,				(0, 2, 1)   )
  
  					self.assertListEqual(
  					    list(reshaped_hidden_states.shape[-2:]   )			,				[num_patches, self.model_tester.embed_dim]			,				)
  
  
  
  
  				def 							__magic_name__							(					self		: str   )   ->							Dict:
  
  
  
  
  					'''simple docstring'''
  
  					A__ =       self.model_tester.prepare_config_and_inputs_for_common()
  
  					A__ =       to_atuple(self.model_tester.image_size   )
  
  					for model_class in self.all_model_classes:
  						A__ =       True
  						self.check_hidden_states_output(__a			,				__a			,				__a			,				__a   )
  
  						# check that output_hidden_states also work using config
  						del inputs_dict["output_hidden_states"]
  						A__ =       True
  
  						self.check_hidden_states_output(__a			,				__a			,				__a			,				__a   )
  
  
  
  
  				def 							__magic_name__							(					self		: Tuple   )   ->							Any:
  
  
  
  
  					'''simple docstring'''
  
  					A__ =       self.model_tester.prepare_config_and_inputs_for_common()
  					A__ =       3
  
  					A__ =       to_atuple(self.model_tester.image_size   )
  					A__ =       to_atuple(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(__a			,				__a			,				__a			,				(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(__a			,				__a			,				__a			,				(padded_height, padded_width)   )
  
  
  
  
  				@slow
  				def 							__magic_name__							(					self		: Dict   )   ->							Tuple:
  
  
  
  
  					'''simple docstring'''
  
  					for model_name in TF_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
  						A__ =       TFSwinModel.from_pretrained(__a   )
  						self.assertIsNotNone(__a   )
  
  
  
  
  
  
  @require_vision
  @require_tf
  class 			UpperCAmelCase_						(		unittest.TestCase							):
  
  
  
  
  				@cached_property
  				def 							__magic_name__							(					self		: Tuple   )   ->							int:
  
  
  
  
  					'''simple docstring'''
  
  					return (
  					    AutoImageProcessor.from_pretrained("microsoft/swin-tiny-patch4-window7-224"   )
  					    if is_vision_available()
  					    else None
  					)
  
  
  
  
  				@slow
  				def 							__magic_name__							(					self		: int   )   ->							List[str]:
  
  
  
  
  					'''simple docstring'''
  
  					A__ =       TFSwinForImageClassification.from_pretrained("microsoft/swin-tiny-patch4-window7-224"   )
  					A__ =       self.default_image_processor
  
  					A__ =       Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"   )
  					A__ =       image_processor(images=__a			,				return_tensors="tf"   )
  
  					# forward pass
  					A__ =       model(__a   )
  
  					# verify the logits
  					A__ =       tf.TensorShape((1, 1_000)   )
  					self.assertEqual(outputs.logits.shape			,				__a   )
  					A__ =       tf.constant([-0.0948, -0.6454, -0.0921]   )
  					self.assertTrue(np.allclose(outputs.logits[0, :3]			,				__a			,				atol=1e-4   )   )
  
  
  
  
  
  
style_context: 
  
  
  
  
  """simple docstring"""
  
  
  
  from typing import Optional, Union
  
  from ...file_utils import TensorType
  from ...processing_utils import ProcessorMixin
  from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, TruncationStrategy
  
  
  
  
  class 			UpperCAmelCase_						(		A_							):
      lowercase__		      =   '''MarkupLMFeatureExtractor'''
      lowercase__		      =   ('''MarkupLMTokenizer''', '''MarkupLMTokenizerFast''')
      lowercase__		      =   True
  
  
  
  
      def __call__(					self		: Dict			,				snake_case_		: Optional[int]=None			,				snake_case_		: Union[str, Any]=None			,				snake_case_		: Tuple=None			,				snake_case_		: str=None			,				snake_case_		: Optional[Any]=None			,				snake_case_		: bool = True			,				snake_case_		: Union[bool, str, PaddingStrategy] = False			,				snake_case_		: Union[bool, str, TruncationStrategy] = None			,				snake_case_		: Optional[int] = None			,				snake_case_		: int = 0			,				snake_case_		: Optional[int] = None			,				snake_case_		: Optional[bool] = None			,				snake_case_		: Optional[bool] = None			,				snake_case_		: bool = False			,				snake_case_		: bool = False			,				snake_case_		: bool = False			,				snake_case_		: bool = False			,				snake_case_		: bool = True			,				snake_case_		: Optional[Union[str, TensorType]] = None			,				**snake_case_		: Dict			,				)   ->							BatchEncoding:
  
  
  
  
       '''simple docstring'''
  
       if self.parse_html:
        if html_strings is None:
         raise ValueError("Make sure to pass HTML strings in case `parse_html` is set to `True`"   )
  
        if nodes is not None or xpaths is not None or node_labels is not None:
         raise ValueError(
             "Please don't pass nodes, xpaths nor node labels in case `parse_html` is set to `True`"   )
  
        A__ =       self.feature_extractor(snake_case_   )
        A__ =       features["nodes"]
        A__ =       features["xpaths"]
       else:
        if html_strings is not None:
         raise ValueError("You have passed HTML strings but `parse_html` is set to `False`."   )
        if nodes is None or xpaths is None:
         raise ValueError("Make sure to pass nodes and xpaths in case `parse_html` is set to `False`"   )
  
          # # second, apply the tokenizer
       if questions is not None and self.parse_html:
        if isinstance(snake_case_			,				snake_case_   ):
         A__ =       [questions]  # add batch dimension (as the feature extractor always adds a batch dimension)
  
       A__ =       self.tokenizer(
           text=questions if questions is not None else nodes			,				text_pair=nodes if questions is not None else None			,				xpaths=snake_case_			,				node_labels=snake_case_			,				add_special_tokens=snake_case_			,				padding=snake_case_			,				truncation=snake_case_			,				max_length=snake_case_			,				stride=snake_case_			,				pad_to_multiple_of=snake_case_			,				return_token_type_ids=snake_case_			,				return_attention_mask=snake_case_			,				return_overflowing_tokens=snake_case_			,				return_special_tokens_mask=snake_case_			,				return_offsets_mapping=snake_case_			,				return_length=snake_case_			,				verbose=snake_case_			,				return_tensors=snake_case_			,				**snake_case_			,				)
  
       return encoded_inputs
  
  
  
  
      def 							__magic_name__							(					self		: Optional[Any]			,				*snake_case_		: Any			,				**snake_case_		: Any   )   ->							int:
  
  
  
  
       '''simple docstring'''
  
       return self.tokenizer.batch_decode(*snake_case_			,				**snake_case_   )
  
  
  
  
      def 							__magic_name__							(					self		: Tuple			,				*snake_case_		: Optional[Any]			,				**snake_case_		: List[Any]   )   ->							Any:
  
  
  
  
       '''simple docstring'''
  
       return self.tokenizer.decode(*snake_case_			,				**snake_case_   )
  
  
  
  
      @property
      def 							__magic_name__							(					self		: List[Any]   )   ->							Optional[int]:
  
  
  
  
       '''simple docstring'''
  
       A__ =       self.tokenizer.model_input_names
       return tokenizer_input_names
  
  
  
  
  
  