code: 
  
  
  '''simple docstring'''
  
  
  
  from __future__ import annotations
  
  import unittest
  
  from transformers import is_tf_available
  from transformers.testing_utils import require_tf, slow
  
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
  from ...test_pipeline_mixin import PipelineTesterMixin
  
  
  if is_tf_available():
  	import tensorflow as tf
  
  	from transformers import (
  	    TF_XLM_PRETRAINED_MODEL_ARCHIVE_LIST,
  	    TFXLMForMultipleChoice,
  	    TFXLMForQuestionAnsweringSimple,
  	    TFXLMForSequenceClassification,
  	    TFXLMForTokenClassification,
  	    TFXLMModel,
  	    TFXLMWithLMHeadModel,
  	    XLMConfig,
  	)
  
  
  
  
  
  class 							__UpperCamelCase       :
  
  
  
  
  	def __init__(     self		,       __a		,       ):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Optional[Any]      					=						parent
  						__a    : Optional[int]      					=						13
  						__a    : int      					=						7
  						__a    : Optional[int]      					=						True
  						__a    : Any      					=						True
  						__a    : str      					=						True
  						__a    : Any      					=						True
  						__a    : Optional[int]      					=						True
  						__a    : List[Any]      					=						False
  						__a    : int      					=						False
  						__a    : List[str]      					=						False
  						__a    : List[Any]      					=						2
  						__a    : str      					=						99
  						__a    : Optional[int]      					=						0
  						__a    : str      					=						32
  						__a    : str      					=						2
  						__a    : Optional[Any]      					=						4
  						__a    : Any      					=						0.1
  						__a    : List[Any]      					=						0.1
  						__a    : List[Any]      					=						512
  						__a    : List[str]      					=						16
  						__a    : Optional[int]      					=						2
  						__a    : Dict      					=						0.02
  						__a    : Tuple      					=						3
  						__a    : Dict      					=						4
  						__a    : Dict      					=						'last'
  						__a    : Dict      					=						True
  						__a    : Optional[int]      					=						None
  						__a    : Tuple      					=						0
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Any      					=						ids_tensor([self.batch_size, self.seq_length]		,       self.vocab_size							)
  						__a    : Tuple      					=						random_attention_mask([self.batch_size, self.seq_length]		,       dtype=tf.floataa							)
  
  						__a    : Tuple      					=						None
  						if self.use_input_lengths:
  											__a    : str      					=						(
  											    ids_tensor([self.batch_size]		,       vocab_size=2							) + self.seq_length - 2
  											)  # small variation of seq_length
  
  						__a    : Optional[Any]      					=						None
  						if self.use_token_type_ids:
  											__a    : Union[str, Any]      					=						ids_tensor([self.batch_size, self.seq_length]		,       self.n_langs							)
  
  						__a    : Optional[int]      					=						None
  						__a    : Optional[int]      					=						None
  						__a    : Dict      					=						None
  						if self.use_labels:
  											__a    : Tuple      					=						ids_tensor([self.batch_size]		,       self.type_sequence_label_size							)
  											__a    : Any      					=						ids_tensor([self.batch_size, self.seq_length]		,       self.num_labels							)
  											__a    : Optional[Any]      					=						ids_tensor([self.batch_size]		,       2		,       dtype=tf.floataa							)
  											__a    : Tuple      					=						ids_tensor([self.batch_size]		,       self.num_choices							)
  
  						__a    : Union[str, Any]      					=						XLMConfig(
  						    vocab_size=self.vocab_size		,       n_special=self.n_special		,       emb_dim=self.hidden_size		,       n_layers=self.num_hidden_layers		,       n_heads=self.num_attention_heads		,       dropout=self.hidden_dropout_prob		,       attention_dropout=self.attention_probs_dropout_prob		,       gelu_activation=self.gelu_activation		,       sinusoidal_embeddings=self.sinusoidal_embeddings		,       asm=self.asm		,       causal=self.causal		,       n_langs=self.n_langs		,       max_position_embeddings=self.max_position_embeddings		,       initializer_range=self.initializer_range		,       summary_type=self.summary_type		,       use_proj=self.use_proj		,       bos_token_id=self.bos_token_id		,       )
  
  						return (
  						    config,
  						    input_ids,
  						    token_type_ids,
  						    input_lengths,
  						    sequence_labels,
  						    token_labels,
  						    is_impossible_labels,
  						    choice_labels,
  						    input_mask,
  						)
  
  
  
  
  	def    __UpperCAmelCase							(     self		,       __a		,       __a		,       __a		,       __a		,       __a		,       __a		,       __a		,       __a		,       __a		,       ):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Union[str, Any]      					=						TFXLMModel(config=__a							)
  						__a    : Optional[int]      					=						{'input_ids': input_ids, 'lengths': input_lengths, 'langs': token_type_ids}
  						__a    : int      					=						model(__a							)
  
  						__a    : Tuple      					=						[input_ids, input_mask]
  						__a    : Union[str, Any]      					=						model(__a							)
  						self.parent.assertEqual(result.last_hidden_state.shape		,       (self.batch_size, self.seq_length, self.hidden_size)							)
  
  
  
  
  	def    __UpperCAmelCase							(     self		,       __a		,       __a		,       __a		,       __a		,       __a		,       __a		,       __a		,       __a		,       __a		,       ):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Any      					=						TFXLMWithLMHeadModel(__a							)
  
  						__a    : List[str]      					=						{'input_ids': input_ids, 'lengths': input_lengths, 'langs': token_type_ids}
  						__a    : Dict      					=						model(__a							)
  
  						__a    : Tuple      					=						outputs
  
  						self.parent.assertEqual(result.logits.shape		,       (self.batch_size, self.seq_length, self.vocab_size)							)
  
  
  
  
  	def    __UpperCAmelCase							(     self		,       __a		,       __a		,       __a		,       __a		,       __a		,       __a		,       __a		,       __a		,       __a		,       ):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Optional[Any]      					=						TFXLMForQuestionAnsweringSimple(__a							)
  
  						__a    : Any      					=						{'input_ids': input_ids, 'lengths': input_lengths}
  
  						__a    : List[str]      					=						model(__a							)
  
  						self.parent.assertEqual(result.start_logits.shape		,       (self.batch_size, self.seq_length)							)
  						self.parent.assertEqual(result.end_logits.shape		,       (self.batch_size, self.seq_length)							)
  
  
  
  
  	def    __UpperCAmelCase							(     self		,       __a		,       __a		,       __a		,       __a		,       __a		,       __a		,       __a		,       __a		,       __a		,       ):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Union[str, Any]      					=						TFXLMForSequenceClassification(__a							)
  
  						__a    : int      					=						{'input_ids': input_ids, 'lengths': input_lengths}
  
  						__a    : Dict      					=						model(__a							)
  
  						self.parent.assertEqual(result.logits.shape		,       (self.batch_size, self.type_sequence_label_size)							)
  
  
  
  
  	def    __UpperCAmelCase							(     self		,       __a		,       __a		,       __a		,       __a		,       __a		,       __a		,       __a		,       __a		,       __a		,       ):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Union[str, Any]      					=						self.num_labels
  						__a    : int      					=						TFXLMForTokenClassification(config=__a							)
  						__a    : Optional[Any]      					=						{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
  						__a    : Tuple      					=						model(__a							)
  						self.parent.assertEqual(result.logits.shape		,       (self.batch_size, self.seq_length, self.num_labels)							)
  
  
  
  
  	def    __UpperCAmelCase							(     self		,       __a		,       __a		,       __a		,       __a		,       __a		,       __a		,       __a		,       __a		,       __a		,       ):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Any      					=						self.num_choices
  						__a    : Dict      					=						TFXLMForMultipleChoice(config=__a							)
  						__a    : List[Any]      					=						tf.tile(tf.expand_dims(__a		,       1							)		,       (1, self.num_choices, 1)							)
  						__a    : Tuple      					=						tf.tile(tf.expand_dims(__a		,       1							)		,       (1, self.num_choices, 1)							)
  						__a    : int      					=						tf.tile(tf.expand_dims(__a		,       1							)		,       (1, self.num_choices, 1)							)
  						__a    : Dict      					=						{
  						    'input_ids': multiple_choice_inputs_ids,
  						    'attention_mask': multiple_choice_input_mask,
  						    'token_type_ids': multiple_choice_token_type_ids,
  						}
  						__a    : List[Any]      					=						model(__a							)
  						self.parent.assertEqual(result.logits.shape		,       (self.batch_size, self.num_choices)							)
  
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Dict      					=						self.prepare_config_and_inputs()
  						(
  						    (
  						    __a
  						)					,       (
  						    __a
  						)					,       (
  						    __a
  						)					,       (
  						    __a
  						)					,       (
  						    __a
  						)					,       (
  						    __a
  						)					,       (
  						    __a
  						)					,       (
  						    __a
  						)					,       (
  						    __a
  						)					,       
  						)    : Dict      					=						config_and_inputs
  						__a    : Dict      					=						{
  						    'input_ids': input_ids,
  						    'token_type_ids': token_type_ids,
  						    'langs': token_type_ids,
  						    'lengths': input_lengths,
  						}
  						return config, inputs_dict
  
  
  
  
  
  @require_tf
  class 							__UpperCamelCase       (	lowerCAmelCase_	,   lowerCAmelCase_	,   unittest.TestCase      ):
  	A_			    =					(
  	    (
  	        TFXLMModel,
  	        TFXLMWithLMHeadModel,
  	        TFXLMForSequenceClassification,
  	        TFXLMForQuestionAnsweringSimple,
  	        TFXLMForTokenClassification,
  	        TFXLMForMultipleChoice,
  	    )
  	    if is_tf_available()
  	    else ()
  	)
  	A_			    =					(
  	    (TFXLMWithLMHeadModel,) if is_tf_available() else ()
  	)  # TODO (PVP): Check other models whether language generation is also applicable
  	A_			    =					(
  	    {
  	        "feature-extraction": TFXLMModel,
  	        "fill-mask": TFXLMWithLMHeadModel,
  	        "question-answering": TFXLMForQuestionAnsweringSimple,
  	        "text-classification": TFXLMForSequenceClassification,
  	        "text-generation": TFXLMWithLMHeadModel,
  	        "token-classification": TFXLMForTokenClassification,
  	        "zero-shot": TFXLMForSequenceClassification,
  	    }
  	    if is_tf_available()
  	    else {}
  	)
  	A_			    =					False
  	A_			    =					False
  
  
  
  
  	def    __UpperCAmelCase							(     self		,       __a		,       __a		,       __a		,       __a		,       __a							):
  
  						'''simple docstring'''
  
  
  
  
  
  						if (
  						    pipeline_test_casse_name == "QAPipelineTests"
  						    and tokenizer_name is not None
  						    and not tokenizer_name.endswith('Fast'							)
  						):
  											# `QAPipelineTests` fails for a few models when the slower tokenizer are used.
  											# (The slower tokenizers were never used for pipeline tests before the pipeline testing rework)
  											# TODO: check (and possibly fix) the `QAPipelineTests` with slower tokenizer
  											return True
  
  						return False
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Optional[Any]      					=						TFXLMModelTester(self							)
  						__a    : Optional[int]      					=						ConfigTester(self		,       config_class=__a		,       emb_dim=37							)
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						self.config_tester.run_common_tests()
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : List[str]      					=						self.model_tester.prepare_config_and_inputs()
  						self.model_tester.create_and_check_xlm_model(*__a							)
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Union[str, Any]      					=						self.model_tester.prepare_config_and_inputs()
  						self.model_tester.create_and_check_xlm_lm_head(*__a							)
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : int      					=						self.model_tester.prepare_config_and_inputs()
  						self.model_tester.create_and_check_xlm_qa(*__a							)
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Tuple      					=						self.model_tester.prepare_config_and_inputs()
  						self.model_tester.create_and_check_xlm_sequence_classif(*__a							)
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : str      					=						self.model_tester.prepare_config_and_inputs()
  						self.model_tester.create_and_check_xlm_for_token_classification(*__a							)
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Dict      					=						self.model_tester.prepare_config_and_inputs()
  						self.model_tester.create_and_check_xlm_for_multiple_choice(*__a							)
  
  
  
  
  
  	@slow
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						for model_name in TF_XLM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
  											__a    : Union[str, Any]      					=						TFXLMModel.from_pretrained(__a							)
  											self.assertIsNotNone(__a							)
  
  
  
  
  
  @require_tf
  class 							__UpperCamelCase       (	unittest.TestCase      ):
  
  
  
  
  	@slow
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Tuple      					=						TFXLMWithLMHeadModel.from_pretrained('xlm-mlm-en-2048'							)
  						__a    : Any      					=						tf.convert_to_tensor([[14, 447]]		,       dtype=tf.intaa							)  # the president
  						__a    : Optional[int]      					=						[
  						    14,
  						    447,
  						    14,
  						    447,
  						    14,
  						    447,
  						    14,
  						    447,
  						    14,
  						    447,
  						    14,
  						    447,
  						    14,
  						    447,
  						    14,
  						    447,
  						    14,
  						    447,
  						    14,
  						    447,
  						]  # the president the president the president the president the president the president the president the president the president the president
  						# TODO(PVP): this and other input_ids I tried for generation give pretty bad results. Not sure why. Model might just not be made for auto-regressive inference
  						__a    : List[str]      					=						model.generate(__a		,       do_sample=__a							)
  						self.assertListEqual(output_ids[0].numpy().tolist()		,       __a							)
  
  
  
  
style_context: 
  
  
  '''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		,       __a		,       __a=13		,       __a=32		,       __a=2		,       __a=3		,       __a=16		,       __a=[1, 2, 1]		,       __a=[2, 2, 4]		,       __a=2		,       __a=2.0		,       __a=True		,       __a=0.0		,       __a=0.0		,       __a=0.1		,       __a="gelu"		,       __a=False		,       __a=True		,       __a=0.02		,       __a=1E-5		,       __a=True		,       __a=None		,       __a=True		,       __a=10		,       __a=8		,       ):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Dict      					=						parent
  						__a    : int      					=						batch_size
  						__a    : str      					=						image_size
  						__a    : List[Any]      					=						patch_size
  						__a    : Any      					=						num_channels
  						__a    : int      					=						embed_dim
  						__a    : Optional[Any]      					=						depths
  						__a    : Optional[Any]      					=						num_heads
  						__a    : List[Any]      					=						window_size
  						__a    : Dict      					=						mlp_ratio
  						__a    : Any      					=						qkv_bias
  						__a    : Any      					=						hidden_dropout_prob
  						__a    : Union[str, Any]      					=						attention_probs_dropout_prob
  						__a    : str      					=						drop_path_rate
  						__a    : Dict      					=						hidden_act
  						__a    : List[str]      					=						use_absolute_embeddings
  						__a    : str      					=						patch_norm
  						__a    : List[str]      					=						layer_norm_eps
  						__a    : Optional[Any]      					=						initializer_range
  						__a    : str      					=						is_training
  						__a    : Any      					=						scope
  						__a    : Union[str, Any]      					=						use_labels
  						__a    : Optional[int]      					=						type_sequence_label_size
  						__a    : Optional[Any]      					=						encoder_stride
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : str      					=						floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]							)
  
  						__a    : List[Any]      					=						None
  						if self.use_labels:
  											__a    : str      					=						ids_tensor([self.batch_size]		,       self.type_sequence_label_size							)
  
  						__a    : int      					=						self.get_config()
  
  						return config, pixel_values, labels
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''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    __UpperCAmelCase							(     self		,       __a		,       __a		,       __a							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Any      					=						TFSwinModel(config=__a							)
  						__a    : List[str]      					=						model(__a							)
  
  						__a    : Dict      					=						((config.image_size // config.patch_size) ** 2) // (4 ** (len(config.depths							) - 1))
  						__a    : 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    __UpperCAmelCase							(     self		,       __a		,       __a		,       __a							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Any      					=						TFSwinForMaskedImageModeling(config=__a							)
  						__a    : Tuple      					=						model(__a							)
  						self.parent.assertEqual(
  						    result.logits.shape		,       (self.batch_size, self.num_channels, self.image_size, self.image_size)							)
  
  						# test greyscale images
  						__a    : str      					=						1
  						__a    : Union[str, Any]      					=						TFSwinForMaskedImageModeling(__a							)
  
  						__a    : Optional[int]      					=						floats_tensor([self.batch_size, 1, self.image_size, self.image_size]							)
  						__a    : Any      					=						model(__a							)
  						self.parent.assertEqual(result.logits.shape		,       (self.batch_size, 1, self.image_size, self.image_size)							)
  
  
  
  
  	def    __UpperCAmelCase							(     self		,       __a		,       __a		,       __a							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Dict      					=						self.type_sequence_label_size
  						__a    : Tuple      					=						TFSwinForImageClassification(__a							)
  						__a    : Any      					=						model(__a		,       labels=__a							)
  						self.parent.assertEqual(result.logits.shape		,       (self.batch_size, self.type_sequence_label_size)							)
  
  						# test greyscale images
  						__a    : Tuple      					=						1
  						__a    : str      					=						TFSwinForImageClassification(__a							)
  						__a    : List[Any]      					=						floats_tensor([self.batch_size, 1, self.image_size, self.image_size]							)
  						__a    : List[str]      					=						model(__a							)
  						self.parent.assertEqual(result.logits.shape		,       (self.batch_size, self.type_sequence_label_size)							)
  
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : List[Any]      					=						self.prepare_config_and_inputs()
  						__a					,       __a					,       __a    : Tuple      					=						config_and_inputs
  						__a    : Dict      					=						{'pixel_values': pixel_values}
  						return config, inputs_dict
  
  
  
  
  
  @require_tf
  class 							__UpperCamelCase       (	lowerCAmelCase_	,   lowerCAmelCase_	,   unittest.TestCase      ):
  	A_			    =					(
  	    (
  	        TFSwinModel,
  	        TFSwinForImageClassification,
  	        TFSwinForMaskedImageModeling,
  	    )
  	    if is_tf_available()
  	    else ()
  	)
  	A_			    =					(
  	    {"feature-extraction": TFSwinModel, "image-classification": TFSwinForImageClassification}
  	    if is_tf_available()
  	    else {}
  	)
  
  	A_			    =					False
  	A_			    =					False
  	A_			    =					False
  	A_			    =					False
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Optional[int]      					=						TFSwinModelTester(self							)
  						__a    : Union[str, Any]      					=						ConfigTester(self		,       config_class=__a		,       embed_dim=37							)
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''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    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						return
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : List[str]      					=						self.model_tester.prepare_config_and_inputs()
  						self.model_tester.create_and_check_model(*__a							)
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : List[Any]      					=						self.model_tester.prepare_config_and_inputs()
  						self.model_tester.create_and_check_for_masked_image_modeling(*__a							)
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Optional[Any]      					=						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    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						pass
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''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							)
  											self.assertIsInstance(model.get_input_embeddings()		,       tf.keras.layers.Layer							)
  											__a    : str      					=						model.get_output_embeddings()
  											self.assertTrue(x is None or isinstance(__a		,       tf.keras.layers.Dense							)							)
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a					,       __a    : Dict      					=						self.model_tester.prepare_config_and_inputs_for_common()
  
  						for model_class in self.all_model_classes:
  											__a    : Optional[int]      					=						model_class(__a							)
  											__a    : Union[str, Any]      					=						inspect.signature(model.call							)
  											# signature.parameters is an OrderedDict => so arg_names order is deterministic
  											__a    : Optional[int]      					=						[*signature.parameters.keys()]
  
  											__a    : str      					=						['pixel_values']
  											self.assertListEqual(arg_names[:1]		,       __a							)
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a					,       __a    : Any      					=						self.model_tester.prepare_config_and_inputs_for_common()
  						__a    : Optional[int]      					=						True
  
  						for model_class in self.all_model_classes:
  											__a    : Optional[int]      					=						True
  											__a    : Dict      					=						False
  											__a    : Any      					=						True
  											__a    : Tuple      					=						model_class(__a							)
  											__a    : List[str]      					=						model(**self._prepare_for_class(__a		,       __a							)							)
  											__a    : int      					=						outputs.attentions
  											__a    : List[Any]      					=						len(self.model_tester.depths							)
  											self.assertEqual(len(__a							)		,       __a							)
  
  											# check that output_attentions also work using config
  											del inputs_dict["output_attentions"]
  											__a    : Any      					=						True
  											__a    : List[Any]      					=						config.window_size**2
  											__a    : Optional[Any]      					=						model_class(__a							)
  											__a    : Tuple      					=						model(**self._prepare_for_class(__a		,       __a							)							)
  											__a    : str      					=						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    : Any      					=						len(__a							)
  
  											# Check attention is always last and order is fine
  											__a    : int      					=						True
  											__a    : Any      					=						True
  											__a    : str      					=						model_class(__a							)
  											__a    : str      					=						model(**self._prepare_for_class(__a		,       __a							)							)
  
  											if hasattr(self.model_tester		,       'num_hidden_states_types'							):
  																__a    : Optional[int]      					=						self.model_tester.num_hidden_states_types
  											else:
  																# also another +1 for reshaped_hidden_states
  																__a    : Union[str, Any]      					=						2
  											self.assertEqual(out_len + added_hidden_states		,       len(__a							)							)
  
  											__a    : Dict      					=						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    __UpperCAmelCase							(     self		,       __a		,       __a		,       __a		,       __a							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Optional[Any]      					=						model_class(__a							)
  						__a    : int      					=						model(**self._prepare_for_class(__a		,       __a							)							)
  						__a    : Tuple      					=						outputs.hidden_states
  
  						__a    : Any      					=						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    : Optional[int]      					=						to_atuple(config.patch_size							)
  
  						__a    : List[str]      					=						(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    : str      					=						outputs.reshaped_hidden_states
  						self.assertEqual(len(__a							)		,       __a							)
  
  						__a					,       __a					,       __a					,       __a    : str      					=						reshaped_hidden_states[0].shape
  
  						__a    : int      					=						tf.reshape(reshaped_hidden_states[0]		,       (batch_size, num_channels, height * width)							)
  						__a    : List[str]      					=						tf.transpose(__a		,       (0, 2, 1)							)
  
  						self.assertListEqual(
  						    list(reshaped_hidden_states.shape[-2:]							)		,       [num_patches, self.model_tester.embed_dim]		,       )
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a					,       __a    : Optional[Any]      					=						self.model_tester.prepare_config_and_inputs_for_common()
  
  						__a    : Union[str, Any]      					=						to_atuple(self.model_tester.image_size							)
  
  						for model_class in self.all_model_classes:
  											__a    : Optional[int]      					=						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    : Tuple      					=						True
  
  											self.check_hidden_states_output(__a		,       __a		,       __a		,       __a							)
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a					,       __a    : List[str]      					=						self.model_tester.prepare_config_and_inputs_for_common()
  						__a    : List[str]      					=						3
  
  						__a    : Any      					=						to_atuple(self.model_tester.image_size							)
  						__a    : Any      					=						to_atuple(config.patch_size							)
  
  						__a    : Any      					=						image_size[0] + patch_size[0] - (image_size[0] % patch_size[0])
  						__a    : Optional[int]      					=						image_size[1] + patch_size[1] - (image_size[1] % patch_size[1])
  
  						for model_class in self.all_model_classes:
  											__a    : Union[str, Any]      					=						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    : int      					=						True
  											self.check_hidden_states_output(__a		,       __a		,       __a		,       (padded_height, padded_width)							)
  
  
  
  
  
  	@slow
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						for model_name in TF_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
  											__a    : List[Any]      					=						TFSwinModel.from_pretrained(__a							)
  											self.assertIsNotNone(__a							)
  
  
  
  
  
  @require_vision
  @require_tf
  class 							__UpperCamelCase       (	unittest.TestCase      ):
  
  
  
  
  	@cached_property
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						return (
  						    AutoImageProcessor.from_pretrained('microsoft/swin-tiny-patch4-window7-224'							)
  						    if is_vision_available()
  						    else None
  						)
  
  
  
  
  
  	@slow
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Optional[Any]      					=						TFSwinForImageClassification.from_pretrained('microsoft/swin-tiny-patch4-window7-224'							)
  						__a    : str      					=						self.default_image_processor
  
  						__a    : Optional[Any]      					=						Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'							)
  						__a    : Optional[Any]      					=						image_processor(images=__a		,       return_tensors='tf'							)
  
  						# forward pass
  						__a    : List[Any]      					=						model(__a							)
  
  						# verify the logits
  						__a    : List[str]      					=						tf.TensorShape((1, 1000)							)
  						self.assertEqual(outputs.logits.shape		,       __a							)
  						__a    : Optional[Any]      					=						tf.constant([-0.0948, -0.6454, -0.0921]							)
  						self.assertTrue(np.allclose(outputs.logits[0, :3]		,       __a		,       atol=1E-4							)							)
  
  
  
  