






"""simple docstring"""
import collections
import inspect
import unittest

from transformers import FocalNetConfig
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 (
			    FocalNetBackbone,
			    FocalNetForImageClassification,
			    FocalNetForMaskedImageModeling,
			    FocalNetModel,
			)
			from transformers.models.focalnet.modeling_focalnet import FOCALNET_PRETRAINED_MODEL_ARCHIVE_LIST

if is_vision_available():
			from PIL import Image

			from transformers import AutoImageProcessor







class 			UpperCamelCase_       :





	def __init__(      self					: Union[str, Any]	,	lowerCAmelCase_					: Union[str, Any]	,	lowerCAmelCase_					: List[Any]=13	,	lowerCAmelCase_					: List[Any]=32	,	lowerCAmelCase_					: Tuple=2	,	lowerCAmelCase_					: List[Any]=3	,	lowerCAmelCase_					: Any=16	,	lowerCAmelCase_					: int=[32, 64, 128]	,	lowerCAmelCase_					: str=[1, 2, 1]	,	lowerCAmelCase_					: Optional[Any]=[2, 2, 4]	,	lowerCAmelCase_					: Dict=2	,	lowerCAmelCase_					: int=2.0	,	lowerCAmelCase_					: Dict=True	,	lowerCAmelCase_					: Union[str, Any]=0.0	,	lowerCAmelCase_					: Any=0.0	,	lowerCAmelCase_					: Optional[Any]=0.1	,	lowerCAmelCase_					: str="gelu"	,	lowerCAmelCase_					: List[Any]=False	,	lowerCAmelCase_					: int=True	,	lowerCAmelCase_					: int=0.0_2	,	lowerCAmelCase_					: Optional[int]=1e-5	,	lowerCAmelCase_					: Dict=True	,	lowerCAmelCase_					: Optional[Any]=None	,	lowerCAmelCase_					: List[str]=True	,	lowerCAmelCase_					: Any=10	,	lowerCAmelCase_					: Dict=8	,	lowerCAmelCase_					: Optional[Any]=["stage1", "stage2"]	,	lowerCAmelCase_					: Optional[Any]=[1, 2]	,	)						->			int:
				UpperCAmelCase_     : List[str]			     =					parent
				UpperCAmelCase_     : Optional[Any]			     =					batch_size
				UpperCAmelCase_     : Tuple			     =					image_size
				UpperCAmelCase_     : Optional[Any]			     =					patch_size
				UpperCAmelCase_     : Dict			     =					num_channels
				UpperCAmelCase_     : Union[str, Any]			     =					embed_dim
				UpperCAmelCase_     : Tuple			     =					hidden_sizes
				UpperCAmelCase_     : Dict			     =					depths
				UpperCAmelCase_     : Union[str, Any]			     =					num_heads
				UpperCAmelCase_     : str			     =					window_size
				UpperCAmelCase_     : List[str]			     =					mlp_ratio
				UpperCAmelCase_     : int			     =					qkv_bias
				UpperCAmelCase_     : int			     =					hidden_dropout_prob
				UpperCAmelCase_     : int			     =					attention_probs_dropout_prob
				UpperCAmelCase_     : Optional[Any]			     =					drop_path_rate
				UpperCAmelCase_     : List[str]			     =					hidden_act
				UpperCAmelCase_     : List[Any]			     =					use_absolute_embeddings
				UpperCAmelCase_     : Union[str, Any]			     =					patch_norm
				UpperCAmelCase_     : str			     =					layer_norm_eps
				UpperCAmelCase_     : List[Any]			     =					initializer_range
				UpperCAmelCase_     : Optional[int]			     =					is_training
				UpperCAmelCase_     : str			     =					scope
				UpperCAmelCase_     : Tuple			     =					use_labels
				UpperCAmelCase_     : int			     =					type_sequence_label_size
				UpperCAmelCase_     : int			     =					encoder_stride
				UpperCAmelCase_     : List[str]			     =					out_features
				UpperCAmelCase_     : Any			     =					out_indices





	def      _SCREAMING_SNAKE_CASE      (      self					: Optional[int]						)						->			Optional[int]:
				UpperCAmelCase_     : int			     =					floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

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

				UpperCAmelCase_     : int			     =					self.get_config()

				return config, pixel_values, labels





	def      _SCREAMING_SNAKE_CASE      (      self					: int						)						->			Optional[int]:
				return FocalNetConfig(
				    image_size=self.image_size	,	patch_size=self.patch_size	,	num_channels=self.num_channels	,	embed_dim=self.embed_dim	,	hidden_sizes=self.hidden_sizes	,	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      _SCREAMING_SNAKE_CASE      (      self					: int	,	lowerCAmelCase_					: Any	,	lowerCAmelCase_					: Union[str, Any]	,	lowerCAmelCase_					: str						)						->			Tuple:
				UpperCAmelCase_     : Any			     =					FocalNetModel(config=lowerCAmelCase_						)
				model.to(lowerCAmelCase_						)
				model.eval()
				UpperCAmelCase_     : Tuple			     =					model(lowerCAmelCase_						)

				UpperCAmelCase_     : Dict			     =					((config.image_size // config.patch_size) ** 2) // (4 ** (len(config.depths						) - 1))
				UpperCAmelCase_     : List[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      _SCREAMING_SNAKE_CASE      (      self					: Optional[Any]	,	lowerCAmelCase_					: Optional[int]	,	lowerCAmelCase_					: str	,	lowerCAmelCase_					: Union[str, Any]						)						->			Dict:
				UpperCAmelCase_     : List[str]			     =					FocalNetBackbone(config=lowerCAmelCase_						)
				model.to(lowerCAmelCase_						)
				model.eval()
				UpperCAmelCase_     : Tuple			     =					model(lowerCAmelCase_						)

				# verify feature maps
				self.parent.assertEqual(len(result.feature_maps						)	,	len(config.out_features						)						)
				self.parent.assertListEqual(list(result.feature_maps[0].shape						)	,	[self.batch_size, self.image_size, 8, 8]						)

				# verify channels
				self.parent.assertEqual(len(model.channels						)	,	len(config.out_features						)						)
				self.parent.assertListEqual(model.channels	,	config.hidden_sizes[:-1]						)

				# verify backbone works with out_features=None
				UpperCAmelCase_     : Tuple			     =					None
				UpperCAmelCase_     : Optional[Any]			     =					FocalNetBackbone(config=lowerCAmelCase_						)
				model.to(lowerCAmelCase_						)
				model.eval()
				UpperCAmelCase_     : List[Any]			     =					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, self.image_size * 2, 4, 4]						)

				# verify channels
				self.parent.assertEqual(len(model.channels						)	,	1						)
				self.parent.assertListEqual(model.channels	,	[config.hidden_sizes[-1]]						)





	def      _SCREAMING_SNAKE_CASE      (      self					: List[str]	,	lowerCAmelCase_					: int	,	lowerCAmelCase_					: Tuple	,	lowerCAmelCase_					: List[Any]						)						->			Optional[Any]:
				UpperCAmelCase_     : str			     =					FocalNetForMaskedImageModeling(config=lowerCAmelCase_						)
				model.to(lowerCAmelCase_						)
				model.eval()
				UpperCAmelCase_     : Optional[Any]			     =					model(lowerCAmelCase_						)
				self.parent.assertEqual(
				    result.reconstruction.shape	,	(self.batch_size, self.num_channels, self.image_size, self.image_size)						)

				# test greyscale images
				UpperCAmelCase_     : Optional[int]			     =					1
				UpperCAmelCase_     : int			     =					FocalNetForMaskedImageModeling(lowerCAmelCase_						)
				model.to(lowerCAmelCase_						)
				model.eval()

				UpperCAmelCase_     : List[Any]			     =					floats_tensor([self.batch_size, 1, self.image_size, self.image_size]						)
				UpperCAmelCase_     : Optional[Any]			     =					model(lowerCAmelCase_						)
				self.parent.assertEqual(result.reconstruction.shape	,	(self.batch_size, 1, self.image_size, self.image_size)						)





	def      _SCREAMING_SNAKE_CASE      (      self					: List[str]	,	lowerCAmelCase_					: Tuple	,	lowerCAmelCase_					: Dict	,	lowerCAmelCase_					: Dict						)						->			Optional[Any]:
				UpperCAmelCase_     : Dict			     =					self.type_sequence_label_size
				UpperCAmelCase_     : Dict			     =					FocalNetForImageClassification(lowerCAmelCase_						)
				model.to(lowerCAmelCase_						)
				model.eval()
				UpperCAmelCase_     : Optional[int]			     =					model(lowerCAmelCase_	,	labels=lowerCAmelCase_						)
				self.parent.assertEqual(result.logits.shape	,	(self.batch_size, self.type_sequence_label_size)						)

				# test greyscale images
				UpperCAmelCase_     : Dict			     =					1
				UpperCAmelCase_     : Any			     =					FocalNetForImageClassification(lowerCAmelCase_						)
				model.to(lowerCAmelCase_						)
				model.eval()

				UpperCAmelCase_     : str			     =					floats_tensor([self.batch_size, 1, self.image_size, self.image_size]						)
				UpperCAmelCase_     : Union[str, Any]			     =					model(lowerCAmelCase_						)
				self.parent.assertEqual(result.logits.shape	,	(self.batch_size, self.type_sequence_label_size)						)





	def      _SCREAMING_SNAKE_CASE      (      self					: Optional[int]						)						->			Optional[Any]:
				UpperCAmelCase_     : List[str]			     =					self.prepare_config_and_inputs()

				UpperCAmelCase_     ,	UpperCAmelCase_     ,	UpperCAmelCase_     : Any			     =					config_and_inputs
				UpperCAmelCase_     : int			     =					{"pixel_values": pixel_values}
				return config, inputs_dict







@require_torch
class 			UpperCamelCase_       (__A				,						__A				,						unittest.TestCase     ):
	__magic_name__	      =				(
	    (
	        FocalNetModel,
	        FocalNetForImageClassification,
	        FocalNetForMaskedImageModeling,
	        FocalNetBackbone,
	    )
	    if is_torch_available()
	    else ()
	)
	__magic_name__	      =				(
	    {'''feature-extraction''': FocalNetModel, '''image-classification''': FocalNetForImageClassification}
	    if is_torch_available()
	    else {}
	)
	__magic_name__	      =				False

	__magic_name__	      =				False
	__magic_name__	      =				False
	__magic_name__	      =				False
	__magic_name__	      =				False





	def      _SCREAMING_SNAKE_CASE      (      self					: Tuple						)						->			Optional[Any]:
				UpperCAmelCase_     : Union[str, Any]			     =					FocalNetModelTester(self						)
				UpperCAmelCase_     : Union[str, Any]			     =					ConfigTester(self	,	config_class=lowerCAmelCase_	,	embed_dim=37	,	has_text_modality=lowerCAmelCase_						)





	def      _SCREAMING_SNAKE_CASE      (      self					: Dict						)						->			List[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      _SCREAMING_SNAKE_CASE      (      self					: Union[str, Any]						)						->			Optional[int]:
				return





	def      _SCREAMING_SNAKE_CASE      (      self					: List[Any]						)						->			str:
				UpperCAmelCase_     : str			     =					self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_model(*lowerCAmelCase_						)





	def      _SCREAMING_SNAKE_CASE      (      self					: Tuple						)						->			Optional[Any]:
				UpperCAmelCase_     : List[str]			     =					self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_backbone(*lowerCAmelCase_						)





	def      _SCREAMING_SNAKE_CASE      (      self					: Dict						)						->			Any:
				UpperCAmelCase_     : Optional[int]			     =					self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_masked_image_modeling(*lowerCAmelCase_						)





	def      _SCREAMING_SNAKE_CASE      (      self					: Dict						)						->			Optional[Any]:
				UpperCAmelCase_     : str			     =					self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_image_classification(*lowerCAmelCase_						)





	@unittest.skip(reason="FocalNet does not use inputs_embeds"						)
	def      _SCREAMING_SNAKE_CASE      (      self					: Any						)						->			List[str]:
				pass





	@unittest.skip(reason="FocalNet does not use feedforward chunking"						)
	def      _SCREAMING_SNAKE_CASE      (      self					: Optional[int]						)						->			Union[str, Any]:
				pass





	def      _SCREAMING_SNAKE_CASE      (      self					: Union[str, Any]						)						->			int:
				UpperCAmelCase_     ,	UpperCAmelCase_     : List[str]			     =					self.model_tester.prepare_config_and_inputs_for_common()

				for model_class in self.all_model_classes[:-1]:
							UpperCAmelCase_     : Optional[int]			     =					model_class(lowerCAmelCase_						)
							self.assertIsInstance(model.get_input_embeddings()	,	(nn.Module)						)
							UpperCAmelCase_     : Dict			     =					model.get_output_embeddings()
							self.assertTrue(x is None or isinstance(lowerCAmelCase_	,	nn.Linear						)						)





	def      _SCREAMING_SNAKE_CASE      (      self					: Tuple						)						->			List[Any]:
				UpperCAmelCase_     ,	UpperCAmelCase_     : Union[str, Any]			     =					self.model_tester.prepare_config_and_inputs_for_common()

				for model_class in self.all_model_classes[:-1]:
							UpperCAmelCase_     : Optional[int]			     =					model_class(lowerCAmelCase_						)
							UpperCAmelCase_     : Optional[int]			     =					inspect.signature(model.forward						)
							# signature.parameters is an OrderedDict => so arg_names order is deterministic
							UpperCAmelCase_     : int			     =					[*signature.parameters.keys()]

							UpperCAmelCase_     : List[str]			     =					["pixel_values"]
							self.assertListEqual(arg_names[:1]	,	lowerCAmelCase_						)





	def      _SCREAMING_SNAKE_CASE      (      self					: Optional[int]	,	lowerCAmelCase_					: Dict	,	lowerCAmelCase_					: List[str]	,	lowerCAmelCase_					: Dict	,	lowerCAmelCase_					: Any						)						->			Dict:
				UpperCAmelCase_     : List[str]			     =					model_class(lowerCAmelCase_						)
				model.to(lowerCAmelCase_						)
				model.eval()

				with torch.no_grad():
							UpperCAmelCase_     : int			     =					model(**self._prepare_for_class(lowerCAmelCase_	,	lowerCAmelCase_						)						)

				UpperCAmelCase_     : Optional[Any]			     =					outputs.hidden_states

				UpperCAmelCase_     : Tuple			     =					getattr(
				    self.model_tester	,	"expected_num_hidden_layers"	,	len(self.model_tester.depths						) + 1						)
				self.assertEqual(len(lowerCAmelCase_						)	,	lowerCAmelCase_						)

				# FocalNet has a different seq_length
				UpperCAmelCase_     : str			     =					(
				    config.patch_size
				    if isinstance(config.patch_size	,	collections.abc.Iterable						)
				    else (config.patch_size, config.patch_size)
				)

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

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

				UpperCAmelCase_     : Any			     =					outputs.reshaped_hidden_states
				self.assertEqual(len(lowerCAmelCase_						)	,	lowerCAmelCase_						)

				UpperCAmelCase_     ,	UpperCAmelCase_     ,	UpperCAmelCase_     ,	UpperCAmelCase_     : Any			     =					reshaped_hidden_states[0].shape
				UpperCAmelCase_     : Union[str, Any]			     =					(
				    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      _SCREAMING_SNAKE_CASE      (      self					: List[Any]						)						->			int:
				UpperCAmelCase_     ,	UpperCAmelCase_     : str			     =					self.model_tester.prepare_config_and_inputs_for_common()

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

				for model_class in self.all_model_classes[:-1]:
							UpperCAmelCase_     : Tuple			     =					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"]
							UpperCAmelCase_     : int			     =					True

							self.check_hidden_states_output(lowerCAmelCase_	,	lowerCAmelCase_	,	lowerCAmelCase_	,	lowerCAmelCase_						)





	def      _SCREAMING_SNAKE_CASE      (      self					: Any						)						->			int:
				UpperCAmelCase_     ,	UpperCAmelCase_     : Optional[int]			     =					self.model_tester.prepare_config_and_inputs_for_common()
				UpperCAmelCase_     : List[Any]			     =					3

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

				UpperCAmelCase_     : Any			     =					image_size[0] + patch_size[0] - (image_size[0] % patch_size[0])
				UpperCAmelCase_     : Optional[int]			     =					image_size[1] + patch_size[1] - (image_size[1] % patch_size[1])

				for model_class in self.all_model_classes[:-1]:
							UpperCAmelCase_     : int			     =					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"]
							UpperCAmelCase_     : Optional[int]			     =					True
							self.check_hidden_states_output(lowerCAmelCase_	,	lowerCAmelCase_	,	lowerCAmelCase_	,	(padded_height, padded_width)						)





	@slow
	def      _SCREAMING_SNAKE_CASE      (      self					: Optional[Any]						)						->			str:
				for model_name in FOCALNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							UpperCAmelCase_     : Tuple			     =					FocalNetModel.from_pretrained(lowerCAmelCase_						)
							self.assertIsNotNone(lowerCAmelCase_						)





	def      _SCREAMING_SNAKE_CASE      (      self					: str						)						->			str:
				UpperCAmelCase_     ,	UpperCAmelCase_     : Any			     =					self.model_tester.prepare_config_and_inputs_for_common()

				UpperCAmelCase_     : str			     =					_config_zero_init(lowerCAmelCase_						)
				for model_class in self.all_model_classes:
							UpperCAmelCase_     : List[Any]			     =					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 			UpperCamelCase_       (unittest.TestCase     ):





	@cached_property
	def      _SCREAMING_SNAKE_CASE      (      self					: Optional[int]						)						->			Dict:
				# TODO update organization
				return AutoImageProcessor.from_pretrained("microsoft/focalnet-tiny"						) if is_vision_available() else None





	@slow
	def      _SCREAMING_SNAKE_CASE      (      self					: List[Any]						)						->			int:
				UpperCAmelCase_     : Tuple			     =					FocalNetForImageClassification.from_pretrained("microsoft/focalnet-tiny"						).to(lowerCAmelCase_						)
				UpperCAmelCase_     : str			     =					self.default_image_processor

				UpperCAmelCase_     : Dict			     =					Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"						)
				UpperCAmelCase_     : List[Any]			     =					image_processor(images=lowerCAmelCase_	,	return_tensors="pt"						).to(lowerCAmelCase_						)

				# forward pass
				with torch.no_grad():
							UpperCAmelCase_     : List[str]			     =					model(**lowerCAmelCase_						)

				# verify the logits
				UpperCAmelCase_     : Optional[int]			     =					torch.Size((1, 1_000)						)
				self.assertEqual(outputs.logits.shape	,	lowerCAmelCase_						)
				UpperCAmelCase_     : Any			     =					torch.tensor([0.2_1_6_6, -0.4_3_6_8, 0.2_1_9_1]						).to(lowerCAmelCase_						)
				self.assertTrue(torch.allclose(outputs.logits[0, :3]	,	lowerCAmelCase_	,	atol=1e-4						)						)
				self.assertTrue(outputs.logits.argmax(dim=-1						).item()	,	281						)







@require_torch
class 			UpperCamelCase_       (__A				,						unittest.TestCase     ):
	__magic_name__	      =				(FocalNetBackbone,) if is_torch_available() else ()
	__magic_name__	      =				FocalNetConfig

	__magic_name__	      =				False





	def      _SCREAMING_SNAKE_CASE      (      self					: Any						)						->			List[Any]:
				UpperCAmelCase_     : List[str]			     =					FocalNetModelTester(self						)











"""simple docstring"""
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxSeqaSeqConfigWithPast
from ...utils import logging


lowerCamelCase_					=      logging.get_logger(__name__)

lowerCamelCase_					=      {
    '''t5-small''': '''https://huggingface.co/t5-small/resolve/main/config.json''',
    '''t5-base''': '''https://huggingface.co/t5-base/resolve/main/config.json''',
    '''t5-large''': '''https://huggingface.co/t5-large/resolve/main/config.json''',
    '''t5-3b''': '''https://huggingface.co/t5-3b/resolve/main/config.json''',
    '''t5-11b''': '''https://huggingface.co/t5-11b/resolve/main/config.json''',
}







class 			UpperCamelCase_       (__A     ):
	__magic_name__	      =				'''t5'''
	__magic_name__	      =				['''past_key_values''']
	__magic_name__	      =				{'''hidden_size''': '''d_model''', '''num_attention_heads''': '''num_heads''', '''num_hidden_layers''': '''num_layers'''}





	def __init__(      self					: str	,	lowerCAmelCase_					: List[Any]=32_128	,	lowerCAmelCase_					: Tuple=512	,	lowerCAmelCase_					: Optional[int]=64	,	lowerCAmelCase_					: List[str]=2_048	,	lowerCAmelCase_					: Tuple=6	,	lowerCAmelCase_					: Dict=None	,	lowerCAmelCase_					: str=8	,	lowerCAmelCase_					: Optional[int]=32	,	lowerCAmelCase_					: Dict=128	,	lowerCAmelCase_					: Optional[Any]=0.1	,	lowerCAmelCase_					: str=1e-6	,	lowerCAmelCase_					: Dict=1.0	,	lowerCAmelCase_					: str="relu"	,	lowerCAmelCase_					: List[Any]=True	,	lowerCAmelCase_					: List[str]=True	,	lowerCAmelCase_					: Any=0	,	lowerCAmelCase_					: Tuple=1	,	**lowerCAmelCase_					: Optional[int]	,	)						->			int:
				UpperCAmelCase_     : int			     =					vocab_size
				UpperCAmelCase_     : Optional[Any]			     =					d_model
				UpperCAmelCase_     : str			     =					d_kv
				UpperCAmelCase_     : Any			     =					d_ff
				UpperCAmelCase_     : int			     =					num_layers
				UpperCAmelCase_     : Union[str, Any]			     =					(
				    num_decoder_layers if num_decoder_layers is not None else self.num_layers
				)  # default = symmetry
				UpperCAmelCase_     : Optional[Any]			     =					num_heads
				UpperCAmelCase_     : Any			     =					relative_attention_num_buckets
				UpperCAmelCase_     : Optional[Any]			     =					relative_attention_max_distance
				UpperCAmelCase_     : Optional[Any]			     =					dropout_rate
				UpperCAmelCase_     : Tuple			     =					layer_norm_epsilon
				UpperCAmelCase_     : int			     =					initializer_factor
				UpperCAmelCase_     : int			     =					feed_forward_proj
				UpperCAmelCase_     : str			     =					use_cache

				UpperCAmelCase_     : Tuple			     =					self.feed_forward_proj.split("-"						)
				UpperCAmelCase_     : List[Any]			     =					act_info[-1]
				UpperCAmelCase_     : Optional[int]			     =					act_info[0] == "gated"

				if len(lowerCAmelCase_						) > 1 and act_info[0] != "gated" or len(lowerCAmelCase_						) > 2:
							raise ValueError(
							    f"""`feed_forward_proj`: {feed_forward_proj} is not a valid activation function of the dense layer."""
							    "Please make sure `feed_forward_proj` is of the format `gated-{ACT_FN}` or `{ACT_FN}`, e.g. "
							    "'gated-gelu' or 'relu'"						)

				# for backwards compatibility
				if feed_forward_proj == "gated-gelu":
							UpperCAmelCase_     : int			     =					"gelu_new"

				super().__init__(
				    pad_token_id=lowerCAmelCase_	,	eos_token_id=lowerCAmelCase_	,	is_encoder_decoder=lowerCAmelCase_	,	**lowerCAmelCase_	,	)







class 			UpperCamelCase_       (__A     ):





	@property
	def      _SCREAMING_SNAKE_CASE      (      self					: Dict						)						->			Mapping[str, Mapping[int, str]]:
				UpperCAmelCase_     : Any			     =					{
				    "input_ids": {0: "batch", 1: "encoder_sequence"},
				    "attention_mask": {0: "batch", 1: "encoder_sequence"},
				}
				if self.use_past:
							UpperCAmelCase_     : List[Any]			     =					"past_encoder_sequence + sequence"
							UpperCAmelCase_     : Union[str, Any]			     =					{0: "batch"}
							UpperCAmelCase_     : Optional[Any]			     =					{0: "batch", 1: "past_decoder_sequence + sequence"}
				else:
							UpperCAmelCase_     : List[Any]			     =					{0: "batch", 1: "decoder_sequence"}
							UpperCAmelCase_     : Tuple			     =					{0: "batch", 1: "decoder_sequence"}

				if self.use_past:
							self.fill_with_past_key_values_(lowerCAmelCase_	,	direction="inputs"						)

				return common_inputs





	@property
	def      _SCREAMING_SNAKE_CASE      (      self					: Any						)						->			int:
				return 13



