

"""simple docstring"""






import copy
import tempfile
import unittest

from transformers import MaMaaaConfig, is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device
from transformers.utils import cached_property

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
	import torch

	from transformers import MaMaaaForConditionalGeneration, MaMaaaModel, MaMaaaTokenizer
	from transformers.models.mam_aaa.modeling_mam_aaa import MaMaaaDecoder, MaMaaaEncoder



def 	lowercase_						(     _lowercase							:		List[Any]				,   _lowercase							:		str				,   _lowercase							:		Optional[int]				,   _lowercase							:		Union[str, Any]=None				,   _lowercase							:		str=None				,   _lowercase							:		Optional[int]=None				,   _lowercase							:		List[Any]=None				,   _lowercase							:		Dict=None				,   ):




					'''simple docstring'''






					if attention_mask is None:
										UpperCAmelCase      : Dict   =					input_ids.ne(config.pad_token_id						)
					if decoder_attention_mask is None:
										UpperCAmelCase      : List[Any]   =					decoder_input_ids.ne(config.pad_token_id						)
					if head_mask is None:
										UpperCAmelCase      : Dict   =					torch.ones(config.encoder_layers				,   config.encoder_attention_heads				,   device=SCREAMING_SNAKE_CASE__						)
					if decoder_head_mask is None:
										UpperCAmelCase      : Optional[Any]   =					torch.ones(config.decoder_layers				,   config.decoder_attention_heads				,   device=SCREAMING_SNAKE_CASE__						)
					if cross_attn_head_mask is None:
										UpperCAmelCase      : Tuple   =					torch.ones(config.decoder_layers				,   config.decoder_attention_heads				,   device=SCREAMING_SNAKE_CASE__						)
					return {
					    "input_ids": input_ids,
					    "decoder_input_ids": decoder_input_ids,
					    "attention_mask": attention_mask,
					    "decoder_attention_mask": attention_mask,
					    "head_mask": head_mask,
					    "decoder_head_mask": decoder_head_mask,
					    "cross_attn_head_mask": cross_attn_head_mask,
					}







class    snake_case__	:







			def __init__(      self      :			Optional[int]      ,	lowercase      :			Any      ,	lowercase      :			List[Any]=13      ,	lowercase      :			Optional[int]=7      ,	lowercase      :			Tuple=True      ,	lowercase      :			Dict=False      ,	lowercase      :			int=99      ,	lowercase      :			Union[str, Any]=16      ,	lowercase      :			Optional[int]=2      ,	lowercase      :			Union[str, Any]=4      ,	lowercase      :			Union[str, Any]=4      ,	lowercase      :			str="relu"      ,	lowercase      :			Optional[int]=0.1      ,	lowercase      :			Tuple=0.1      ,	lowercase      :			List[Any]=0.0      ,	lowercase      :			List[Any]=0.0      ,	lowercase      :			Tuple=20      ,	lowercase      :			Any=2      ,	lowercase      :			Union[str, Any]=1      ,	lowercase      :			List[Any]=0      ,	):





								'''simple docstring'''



								UpperCAmelCase      : Union[str, Any]   =					parent
								UpperCAmelCase      : List[Any]   =					batch_size
								UpperCAmelCase      : int   =					seq_length
								UpperCAmelCase      : int   =					is_training
								UpperCAmelCase      : List[Any]   =					use_labels
								UpperCAmelCase      : List[Any]   =					vocab_size
								UpperCAmelCase      : Optional[Any]   =					hidden_size
								UpperCAmelCase      : str   =					num_hidden_layers
								UpperCAmelCase      : Optional[Any]   =					num_attention_heads
								UpperCAmelCase      : List[Any]   =					intermediate_size
								UpperCAmelCase      : str   =					hidden_act
								UpperCAmelCase      : Optional[int]   =					hidden_dropout_prob
								UpperCAmelCase      : Optional[int]   =					attention_probs_dropout_prob
								UpperCAmelCase      : Dict   =					encoder_layerdrop
								UpperCAmelCase      : Optional[Any]   =					decoder_layerdrop
								UpperCAmelCase      : Dict   =					max_position_embeddings
								UpperCAmelCase      : List[str]   =					eos_token_id
								UpperCAmelCase      : Dict   =					pad_token_id
								UpperCAmelCase      : int   =					bos_token_id







			def       __lowerCAmelCase					(      self      :			Optional[Any]	):





								'''simple docstring'''



								UpperCAmelCase      : Any   =					ids_tensor([self.batch_size, self.seq_length]      ,	self.vocab_size	)
								UpperCAmelCase      : List[Any]   =					self.eos_token_id  # Eos Token
								UpperCAmelCase      : int   =					ids_tensor([self.batch_size, self.seq_length]      ,	self.vocab_size	)

								# we need to clamp the input ids here to avoid having pad token in between
								# this is because for M2M100 the position_ids are prepared such that
								# all pad tokens have pos id = 2 and rest are between 2..seq_length
								# and the seq_length here is seq_length - num_pad_tokens
								# but when using past, there is no way of knowing if the past input ids had
								# pad tokens in them, which results in incorrect seq_lenth and which in turn results in
								# position_ids being off by num_pad_tokens in past input
								UpperCAmelCase      : str   =					input_ids.clamp(self.pad_token_id + 1	)
								UpperCAmelCase      : Optional[Any]   =					decoder_input_ids.clamp(self.pad_token_id + 1	)

								UpperCAmelCase      : Union[str, Any]   =					self.get_config()
								UpperCAmelCase      : Tuple   =					prepare_mam_aaa_inputs_dict(UpperCamelCase__      ,	UpperCamelCase__      ,	UpperCamelCase__	)
								return config, inputs_dict







			def       __lowerCAmelCase					(      self      :			int	):





								'''simple docstring'''



								return MaMaaaConfig(
								    vocab_size=self.vocab_size      ,	d_model=self.hidden_size      ,	encoder_layers=self.num_hidden_layers      ,	decoder_layers=self.num_hidden_layers      ,	encoder_attention_heads=self.num_attention_heads      ,	decoder_attention_heads=self.num_attention_heads      ,	encoder_ffn_dim=self.intermediate_size      ,	decoder_ffn_dim=self.intermediate_size      ,	dropout=self.hidden_dropout_prob      ,	attention_dropout=self.attention_probs_dropout_prob      ,	encoder_layerdrop=self.encoder_layerdrop      ,	decoder_layerdrop=self.decoder_layerdrop      ,	max_position_embeddings=self.max_position_embeddings      ,	eos_token_id=self.eos_token_id      ,	bos_token_id=self.bos_token_id      ,	pad_token_id=self.pad_token_id      ,	)







			def       __lowerCAmelCase					(      self      :			Optional[Any]	):





								'''simple docstring'''



								UpperCAmelCase      : str   =					self.prepare_config_and_inputs()
								return config, inputs_dict







			def       __lowerCAmelCase					(      self      :			Union[str, Any]      ,	lowercase      :			Union[str, Any]      ,	lowercase      :			str	):





								'''simple docstring'''



								UpperCAmelCase      : Tuple   =					MaMaaaModel(config=UpperCamelCase__	).get_decoder().to(UpperCamelCase__	).eval()
								UpperCAmelCase      : Dict   =					inputs_dict['''input_ids''']
								UpperCAmelCase      : Union[str, Any]   =					inputs_dict['''attention_mask''']
								UpperCAmelCase      : List[str]   =					inputs_dict['''head_mask''']

								# first forward pass
								UpperCAmelCase      : Any   =					model(UpperCamelCase__      ,	attention_mask=UpperCamelCase__      ,	head_mask=UpperCamelCase__      ,	use_cache=UpperCamelCase__	)

								UpperCAmelCase      : List[str]   =					outputs.to_tuple()

								# create hypothetical multiple next token and extent to next_input_ids
								UpperCAmelCase      : List[Any]   =					ids_tensor((self.batch_size, 3)      ,	config.vocab_size	)
								UpperCAmelCase      : List[Any]   =					ids_tensor((self.batch_size, 3)      ,	2	)

								# append to next input_ids and
								UpperCAmelCase      : Tuple   =					torch.cat([input_ids, next_tokens]      ,	dim=-1	)
								UpperCAmelCase      : List[str]   =					torch.cat([attention_mask, next_attn_mask]      ,	dim=-1	)

								UpperCAmelCase      : Tuple   =					model(UpperCamelCase__      ,	attention_mask=UpperCamelCase__	)['''last_hidden_state''']
								UpperCAmelCase      : Any   =					model(UpperCamelCase__      ,	attention_mask=UpperCamelCase__      ,	past_key_values=UpperCamelCase__	)[
								    '''last_hidden_state'''
								]

								# select random slice
								UpperCAmelCase      : Dict   =					ids_tensor((1,)      ,	output_from_past.shape[-1]	).item()
								UpperCAmelCase      : Any   =					output_from_no_past[:, -3:, random_slice_idx].detach()
								UpperCAmelCase      : List[str]   =					output_from_past[:, :, random_slice_idx].detach()

								self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]	)

								# test that outputs are equal for slice
								self.parent.assertTrue(torch.allclose(UpperCamelCase__      ,	UpperCamelCase__      ,	atol=1E-2	)	)







			def       __lowerCAmelCase					(      self      :			str      ,	lowercase      :			List[Any]      ,	lowercase      :			Dict	):





								'''simple docstring'''



								UpperCAmelCase      : Optional[int]   =					MaMaaaModel(config=UpperCamelCase__	).to(UpperCamelCase__	).eval()
								UpperCAmelCase      : Optional[int]   =					model(**UpperCamelCase__	)

								UpperCAmelCase      : Dict   =					outputs.encoder_last_hidden_state
								UpperCAmelCase      : List[str]   =					outputs.last_hidden_state

								with tempfile.TemporaryDirectory() as tmpdirname:
													UpperCAmelCase      : List[str]   =					model.get_encoder()
													encoder.save_pretrained(UpperCamelCase__	)
													UpperCAmelCase      : int   =					MaMaaaEncoder.from_pretrained(UpperCamelCase__	).to(UpperCamelCase__	)

								UpperCAmelCase      : Dict   =					encoder(inputs_dict["input_ids"]      ,	attention_mask=inputs_dict["attention_mask"]	)[
								    0
								]

								self.parent.assertTrue((encoder_last_hidden_state_a - encoder_last_hidden_state).abs().max().item() < 1E-3	)

								with tempfile.TemporaryDirectory() as tmpdirname:
													UpperCAmelCase      : Optional[int]   =					model.get_decoder()
													decoder.save_pretrained(UpperCamelCase__	)
													UpperCAmelCase      : Tuple   =					MaMaaaDecoder.from_pretrained(UpperCamelCase__	).to(UpperCamelCase__	)

								UpperCAmelCase      : str   =					decoder(
								    input_ids=inputs_dict["decoder_input_ids"]      ,	attention_mask=inputs_dict["decoder_attention_mask"]      ,	encoder_hidden_states=UpperCamelCase__      ,	encoder_attention_mask=inputs_dict["attention_mask"]      ,	)[0]

								self.parent.assertTrue((last_hidden_state_a - last_hidden_state).abs().max().item() < 1E-3	)







@require_torch
class    snake_case__	(			__SCREAMING_SNAKE_CASE       ,	__SCREAMING_SNAKE_CASE       ,	__SCREAMING_SNAKE_CASE       ,	unittest.TestCase  ):
			SCREAMING_SNAKE_CASE__  					=    (
			    (
			        MaMaaaModel,
			        MaMaaaForConditionalGeneration,
			    )
			    if is_torch_available()
			    else ()
			)
			SCREAMING_SNAKE_CASE__  					=    (MaMaaaForConditionalGeneration,) if is_torch_available() else ()
			SCREAMING_SNAKE_CASE__  					=    (
			    {
			        '''conversational''': MaMaaaForConditionalGeneration,
			        '''feature-extraction''': MaMaaaModel,
			        '''summarization''': MaMaaaForConditionalGeneration,
			        '''text2text-generation''': MaMaaaForConditionalGeneration,
			        '''translation''': MaMaaaForConditionalGeneration,
			    }
			    if is_torch_available()
			    else {}
			)
			SCREAMING_SNAKE_CASE__  					=    True
			SCREAMING_SNAKE_CASE__  					=    True
			SCREAMING_SNAKE_CASE__  					=    False
			SCREAMING_SNAKE_CASE__  					=    False







			def       __lowerCAmelCase					(      self      :			List[Any]      ,	lowercase      :			Tuple      ,	lowercase      :			List[Any]      ,	lowercase      :			Dict      ,	lowercase      :			List[Any]      ,	lowercase      :			int	):





								'''simple docstring'''



								if pipeline_test_casse_name == "TranslationPipelineTests":
													# Get `ValueError: Translation requires a `src_lang` and a `tgt_lang` for this model`.
													# `M2M100Config` was never used in pipeline tests: cannot create a simple tokenizer.
													return True

								return False







			def       __lowerCAmelCase					(      self      :			Tuple	):





								'''simple docstring'''



								UpperCAmelCase      : Any   =					MaMaaaModelTester(self	)
								UpperCAmelCase      : List[str]   =					ConfigTester(self      ,	config_class=UpperCamelCase__	)







			def       __lowerCAmelCase					(      self      :			Optional[int]	):





								'''simple docstring'''



								self.config_tester.run_common_tests()







			def       __lowerCAmelCase					(      self      :			List[str]	):





								'''simple docstring'''



								UpperCAmelCase      : Union[str, Any]   =					self.model_tester.prepare_config_and_inputs()
								for model_class in self.all_model_classes:
													UpperCAmelCase      : int   =					model_class(UpperCamelCase__	)

													with tempfile.TemporaryDirectory() as tmpdirname:
																		model.save_pretrained(UpperCamelCase__	)
																		UpperCAmelCase      : List[str]   =					model_class.from_pretrained(UpperCamelCase__      ,	output_loading_info=UpperCamelCase__	)
													self.assertEqual(info["missing_keys"]      ,	[]	)







			def       __lowerCAmelCase					(      self      :			int	):





								'''simple docstring'''



								UpperCAmelCase      : Optional[Any]   =					self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_decoder_model_past_large_inputs(*UpperCamelCase__	)







			def       __lowerCAmelCase					(      self      :			Optional[Any]	):





								'''simple docstring'''



								UpperCAmelCase      : Optional[Any]   =					self.model_tester.prepare_config_and_inputs_for_common()
								self.model_tester.check_encoder_decoder_model_standalone(*UpperCamelCase__	)







			def       __lowerCAmelCase					(      self      :			Optional[Any]	):





								'''simple docstring'''



								UpperCAmelCase      : Union[str, Any]   =					self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in (MaMaaaModel, MaMaaaForConditionalGeneration):
													UpperCAmelCase      : List[str]   =					model_class(UpperCamelCase__	)
													model.to(UpperCamelCase__	)
													model.eval()

													UpperCAmelCase      : Optional[int]   =					copy.deepcopy(self._prepare_for_class(UpperCamelCase__      ,	UpperCamelCase__	)	)

													if not self.is_encoder_decoder:
																		UpperCAmelCase      : str   =					inputs['''input_ids''']
																		del inputs["input_ids"]
													else:
																		UpperCAmelCase      : Any   =					inputs['''input_ids''']
																		UpperCAmelCase      : Any   =					inputs.get("decoder_input_ids"      ,	UpperCamelCase__	)
																		del inputs["input_ids"]
																		inputs.pop("decoder_input_ids"      ,	UpperCamelCase__	)

													UpperCAmelCase      : int   =					model.get_input_embeddings()
													if not self.is_encoder_decoder:
																		UpperCAmelCase      : int   =					wte(UpperCamelCase__	)
													else:
																		UpperCAmelCase      : int   =					wte(UpperCamelCase__	)
																		UpperCAmelCase      : List[Any]   =					wte(UpperCamelCase__	)

													with torch.no_grad():
																		model(**UpperCamelCase__	)[0]







			def       __lowerCAmelCase					(      self      :			int	):





								'''simple docstring'''



								UpperCAmelCase      : int   =					self.model_tester.prepare_config_and_inputs()
								UpperCAmelCase      : List[Any]   =					input_dict['''input_ids''']
								UpperCAmelCase      : int   =					input_ids.ne(1	).to(UpperCamelCase__	)
								UpperCAmelCase      : Tuple   =					MaMaaaForConditionalGeneration(UpperCamelCase__	).eval().to(UpperCamelCase__	)
								if torch_device == "cuda":
													model.half()
								model.generate(UpperCamelCase__      ,	attention_mask=UpperCamelCase__	)
								model.generate(num_beams=4      ,	do_sample=UpperCamelCase__      ,	early_stopping=UpperCamelCase__      ,	num_return_sequences=3	)



def 	lowercase_						(     _lowercase							:		Optional[Any]						):




					'''simple docstring'''






					return torch.tensor(SCREAMING_SNAKE_CASE__				,   dtype=torch.long				,   device=SCREAMING_SNAKE_CASE__						)


snake_case_ : Optional[int]   =							1E-4







@require_torch
@require_sentencepiece
@require_tokenizers
@slow
class    snake_case__	(			unittest.TestCase  ):







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





								'''simple docstring'''



								return MaMaaaTokenizer.from_pretrained("facebook/m2m100_418M"	)







			def       __lowerCAmelCase					(      self      :			Tuple	):





								'''simple docstring'''



								UpperCAmelCase      : Dict   =					MaMaaaModel.from_pretrained("facebook/m2m100_418M"	).to(UpperCamelCase__	)
								UpperCAmelCase      : List[str]   =					_long_tensor([[12_80_28, 98, 12, 3_05_27, 27_32, 1_59, 77_55, 6_19_04, 3_91_44, 38, 2]]	)
								UpperCAmelCase      : str   =					_long_tensor([[2, 12_80_28, 98, 12, 3_05_27, 27_32, 1_59, 77_55, 6_19_04, 3_91_44, 38]]	)
								UpperCAmelCase      : Optional[int]   =					prepare_mam_aaa_inputs_dict(model.config      ,	UpperCamelCase__      ,	UpperCamelCase__	)
								with torch.no_grad():
													UpperCAmelCase      : Dict   =					model(**UpperCamelCase__	)[0]
								UpperCAmelCase      : str   =					torch.Size((1, 11, 10_24)	)
								self.assertEqual(output.shape      ,	UpperCamelCase__	)
								# change to expected output here
								UpperCAmelCase      : Tuple   =					torch.tensor(
								    [[-0.7_7_8_0, -0.1_6_7_6, 0.1_0_3_8], [-6.7_5_5_6, -1.3_9_9_2, 0.0_5_6_7], [-7.5_3_8_3, -0.5_9_2_0, -0.2_7_7_9]]      ,	device=UpperCamelCase__	)
								self.assertTrue(torch.allclose(output[:, :3, :3]      ,	UpperCamelCase__      ,	atol=UpperCamelCase__	)	)







			def       __lowerCAmelCase					(      self      :			List[Any]	):





								'''simple docstring'''



								UpperCAmelCase      : Tuple   =					MaMaaaForConditionalGeneration.from_pretrained("facebook/m2m100_418M"	).to(UpperCamelCase__	)

								# change to intended input
								UpperCAmelCase      : Tuple   =					_long_tensor([[12_80_28, 98, 12, 3_05_27, 27_32, 1_59, 77_55, 6_19_04, 3_91_44, 38, 2]]	)
								UpperCAmelCase      : Union[str, Any]   =					_long_tensor([[2, 12_80_28, 98, 12, 3_05_27, 27_32, 1_59, 77_55, 6_19_04, 3_91_44, 38]]	)
								UpperCAmelCase      : Dict   =					prepare_mam_aaa_inputs_dict(model.config      ,	UpperCamelCase__      ,	UpperCamelCase__	)
								with torch.no_grad():
													UpperCAmelCase      : Tuple   =					model(**UpperCamelCase__	)[0]
								UpperCAmelCase      : Any   =					torch.Size((1, 11, model.config.vocab_size)	)
								self.assertEqual(output.shape      ,	UpperCamelCase__	)
								# change to expected output here
								UpperCAmelCase      : Optional[int]   =					torch.tensor(
								    [[-1.0_4_4_8, -1.0_4_1_1, 3.7_9_9_2], [-3.2_1_9_1, -3.2_3_8_6, -1.3_4_5_1], [-3.6_2_1_0, -3.5_9_9_3, 0.4_9_2_5]]      ,	device=UpperCamelCase__	)
								self.assertTrue(torch.allclose(output[:, :3, :3]      ,	UpperCamelCase__      ,	atol=UpperCamelCase__	)	)







			def       __lowerCAmelCase					(      self      :			Tuple	):





								'''simple docstring'''



								UpperCAmelCase      : Dict   =					MaMaaaForConditionalGeneration.from_pretrained("facebook/m2m100_418M"	).to(UpperCamelCase__	)
								UpperCAmelCase      : Optional[int]   =					MaMaaaTokenizer.from_pretrained("facebook/m2m100_418M"      ,	src_lang="fr"      ,	tgt_lang="en"	)

								UpperCAmelCase      : List[Any]   =					[
								    '''L\'affaire NSA souligne l\'absence totale de débat sur le renseignement''',
								    '''Selon moi, il y a deux niveaux de réponse de la part du gouvernement français.''',
								    '''Lorsque François Hollande téléphone à Barack Obama ou quand le ministre des affaires étrangères Laurent'''
								    ''' Fabius convoque l\'ambassadeur des Etats-Unis, ils réagissent à une vraie découverte, qui est celle de'''
								    ''' l\'ampleur de la surveillance américaine sur l\'ensemble des communications en France.''',
								]

								# The below article tests that we don't add any hypotheses outside of the top n_beams
								UpperCAmelCase      : Optional[int]   =					tokenizer(UpperCamelCase__      ,	padding=UpperCamelCase__      ,	return_tensors="pt"	)

								UpperCAmelCase      : Tuple   =					model.generate(
								    input_ids=dct["input_ids"].to(UpperCamelCase__	)      ,	attention_mask=dct["attention_mask"].to(UpperCamelCase__	)      ,	num_beams=5      ,	forced_bos_token_id=tokenizer.get_lang_id("en"	)      ,	)

								UpperCAmelCase      : Dict   =					[
								    '''The NSA case highlights the total absence of intelligence debate''',
								    '''I think there are two levels of response from the French government.''',
								    '''When François Hollande calls Barack Obama or when Foreign Minister Laurent Fabius calls the U.S.'''
								    ''' Ambassador, they respond to a real discovery, which is that of the scale of U.S. surveillance on all'''
								    ''' communications in France.''',
								]

								UpperCAmelCase      : List[str]   =					tokenizer.batch_decode(
								    hypotheses_batch.tolist()      ,	clean_up_tokenization_spaces=UpperCamelCase__      ,	skip_special_tokens=UpperCamelCase__	)
								assert generated == expected_en




'''simple docstring'''
from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


lowercase__						       =      logging.get_logger(__name__)

lowercase__						       =      {
    "microsoft/swin-tiny-patch4-window7-224": (
        "https://huggingface.co/microsoft/swin-tiny-patch4-window7-224/resolve/main/config.json"
    ),
    # See all Swin models at https://huggingface.co/models?filter=swin
}






class 	snake_case__       (      __SCREAMING_SNAKE_CASE    ,					__SCREAMING_SNAKE_CASE					):







		"""simple docstring"""

		lowerCamelCase     							=						"""swin"""

		lowerCamelCase     							=						{
		    """num_attention_heads""": """num_heads""",
		    """num_hidden_layers""": """num_layers""",
		}



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






				"""simple docstring"""







				super().__init__(**UpperCamelCase__      )

				snake_case  :       Any     			=						image_size
				snake_case  :       Optional[int]     			=						patch_size
				snake_case  :       List[Any]     			=						num_channels
				snake_case  :       Union[str, Any]     			=						embed_dim
				snake_case  :       str     			=						depths
				snake_case  :       str     			=						len(UpperCamelCase__      )
				snake_case  :       List[Any]     			=						num_heads
				snake_case  :       List[Any]     			=						window_size
				snake_case  :       Optional[int]     			=						mlp_ratio
				snake_case  :       Union[str, Any]     			=						qkv_bias
				snake_case  :       Optional[int]     			=						hidden_dropout_prob
				snake_case  :       Optional[int]     			=						attention_probs_dropout_prob
				snake_case  :       Optional[int]     			=						drop_path_rate
				snake_case  :       List[Any]     			=						hidden_act
				snake_case  :       int     			=						use_absolute_embeddings
				snake_case  :       str     			=						layer_norm_eps
				snake_case  :       Optional[Any]     			=						initializer_range
				snake_case  :       Any     			=						encoder_stride
				# we set the hidden_size attribute in order to make Swin work with VisionEncoderDecoderModel
				# this indicates the channel dimension after the last stage of the model
				snake_case  :       str     			=						int(embed_dim * 2 ** (len(UpperCamelCase__      ) - 1)      )
				snake_case  :       int     			=						['''stem'''] + [f'stage{idx}' for idx in range(1  ,	len(UpperCamelCase__      ) + 1      )]
				snake_case			,snake_case  :       List[Any]     			=						get_aligned_output_features_output_indices(
				    out_features=UpperCamelCase__  ,	out_indices=UpperCamelCase__  ,	stage_names=self.stage_names      )







class 	snake_case__       (      __SCREAMING_SNAKE_CASE					):







		"""simple docstring"""

		lowerCamelCase     							=						version.parse("""1.11"""					)



		@property
		def       lowerCAmelCase				(      self				:			List[Any]      )						->			Mapping[str, Mapping[int, str]]:






				"""simple docstring"""







				return OrderedDict(
				    [
				        ('''pixel_values''', {0: '''batch''', 1: '''num_channels''', 2: '''height''', 3: '''width'''}),
				    ]      )



		@property
		def       lowerCAmelCase				(      self				:			List[Any]      )						->			float:






				"""simple docstring"""







				return 1e-4


