




import copy
import inspect

from transformers.testing_utils import require_torch, torch_device
from transformers.utils.backbone_utils import BackboneType





@require_torch
class 		A__				:
	lowerCamelCase__		: Tuple				    =()
	lowerCamelCase__		: Tuple				    =True






	def  lowercase      (	self						)      ->   str:




						"""simple docstring"""






						__magic_name__					:							int		   =							self.config_class

						# test default config
						__magic_name__					:							Optional[int]		   =							config_class()
						self.assertIsNotNone(lowerCamelCase						)
						__magic_name__					:							Optional[int]		   =							['''stem'''] + [F'''stage{idx}''' for idx in range(1				,     len(config.depths						) + 1						)]
						self.assertEqual(config.stage_names				,     lowerCamelCase						)
						self.assertTrue(set(config.out_features						).issubset(set(config.stage_names						)						)						)

						# Test out_features and out_indices are correctly set
						# out_features and out_indices both None
						__magic_name__					:							List[Any]		   =							config_class(out_features=lowerCamelCase				,     out_indices=lowerCamelCase						)
						self.assertEqual(config.out_features				,     [config.stage_names[-1]]						)
						self.assertEqual(config.out_indices				,     [len(config.stage_names						) - 1]						)

						# out_features and out_indices both set
						__magic_name__					:							Union[str, Any]		   =							config_class(out_features=['''stem''', '''stage1''']				,     out_indices=[0, 1]						)
						self.assertEqual(config.out_features				,     ['''stem''', '''stage1''']						)
						self.assertEqual(config.out_indices				,     [0, 1]						)

						# Only out_features set
						__magic_name__					:							int		   =							config_class(out_features=['''stage1''', '''stage3''']						)
						self.assertEqual(config.out_features				,     ['''stage1''', '''stage3''']						)
						self.assertEqual(config.out_indices				,     [1, 3]						)

						# Only out_indices set
						__magic_name__					:							Optional[Any]		   =							config_class(out_indices=[0, 2]						)
						self.assertEqual(config.out_features				,     [config.stage_names[0], config.stage_names[2]]						)
						self.assertEqual(config.out_indices				,     [0, 2]						)

						# Error raised when out_indices do not correspond to out_features
						with self.assertRaises(lowerCamelCase						):
											__magic_name__					:							int		   =							config_class(out_features=['''stage1''', '''stage2''']				,     out_indices=[0, 2]						)






	def  lowercase      (	self						)      ->   Optional[int]:




						"""simple docstring"""






						__magic_name__   , __magic_name__					:							Any		   =							self.model_tester.prepare_config_and_inputs_for_common()

						for model_class in self.all_model_classes:
											__magic_name__					:							List[str]		   =							model_class(lowerCamelCase						)
											__magic_name__					:							Tuple		   =							inspect.signature(model.forward						)
											# signature.parameters is an OrderedDict => so arg_names order is deterministic
											__magic_name__					:							str		   =							[*signature.parameters.keys()]
											__magic_name__					:							Any		   =							['''pixel_values''']
											self.assertListEqual(arg_names[:1]				,     lowerCamelCase						)






	def  lowercase      (	self						)      ->   str:




						"""simple docstring"""






						__magic_name__   , __magic_name__					:							Any		   =							self.model_tester.prepare_config_and_inputs_for_common()

						for model_class in self.all_model_classes:
											__magic_name__					:							str		   =							model_class(lowerCamelCase						)
											self.assertEqual(len(model.channels						)				,     len(config.out_features						)						)
											__magic_name__					:							str		   =							model.num_features
											__magic_name__					:							Optional[Any]		   =							[config.stage_names.index(lowerCamelCase						) for feat in config.out_features]
											__magic_name__					:							Any		   =							[num_features[idx] for idx in out_indices]
											self.assertListEqual(model.channels				,     lowerCamelCase						)

											__magic_name__					:							List[Any]		   =							copy.deepcopy(lowerCamelCase						)
											__magic_name__					:							List[str]		   =							None
											__magic_name__					:							Dict		   =							model_class(lowerCamelCase						)
											self.assertEqual(len(model.channels						)				,     1						)
											self.assertListEqual(model.channels				,     [num_features[-1]]						)

											__magic_name__					:							Dict		   =							copy.deepcopy(lowerCamelCase						)
											__magic_name__					:							List[Any]		   =							None
											__magic_name__					:							List[str]		   =							model_class(lowerCamelCase						)
											self.assertEqual(len(model.channels						)				,     1						)
											self.assertListEqual(model.channels				,     [num_features[-1]]						)






	def  lowercase      (	self						)      ->   Optional[int]:




						"""simple docstring"""






						__magic_name__   , __magic_name__					:							List[Any]		   =							self.model_tester.prepare_config_and_inputs_for_common()

						for model_class in self.all_model_classes:
											__magic_name__					:							Optional[Any]		   =							model_class(lowerCamelCase						)
											model.to(lowerCamelCase						)
											model.eval()
											__magic_name__					:							Tuple		   =							model(**lowerCamelCase						)

											self.assertEqual(len(result.feature_maps						)				,     len(config.out_features						)						)
											self.assertEqual(len(model.channels						)				,     len(config.out_features						)						)
											self.assertEqual(len(result.feature_maps						)				,     len(config.out_indices						)						)
											self.assertEqual(len(model.channels						)				,     len(config.out_indices						)						)

											# Check output of last stage is taken if out_features=None, out_indices=None
											__magic_name__					:							Optional[int]		   =							copy.deepcopy(lowerCamelCase						)
											__magic_name__					:							Optional[int]		   =							None
											__magic_name__					:							List[Any]		   =							model_class(lowerCamelCase						)
											model.to(lowerCamelCase						)
											model.eval()
											__magic_name__					:							List[Any]		   =							model(**lowerCamelCase						)

											self.assertEqual(len(result.feature_maps						)				,     1						)
											self.assertEqual(len(model.channels						)				,     1						)

											__magic_name__					:							Dict		   =							copy.deepcopy(lowerCamelCase						)
											__magic_name__					:							List[str]		   =							None
											__magic_name__					:							str		   =							model_class(lowerCamelCase						)
											model.to(lowerCamelCase						)
											model.eval()
											__magic_name__					:							int		   =							model(**lowerCamelCase						)

											self.assertEqual(len(result.feature_maps						)				,     1						)
											self.assertEqual(len(model.channels						)				,     1						)

											# Check backbone can be initialized with fresh weights
											__magic_name__					:							List[str]		   =							copy.deepcopy(lowerCamelCase						)
											__magic_name__					:							List[str]		   =							False
											__magic_name__					:							Optional[Any]		   =							model_class(lowerCamelCase						)
											model.to(lowerCamelCase						)
											model.eval()
											__magic_name__					:							List[str]		   =							model(**lowerCamelCase						)






	def  lowercase      (	self						)      ->   List[Any]:




						"""simple docstring"""






						__magic_name__   , __magic_name__					:							List[str]		   =							self.model_tester.prepare_config_and_inputs_for_common()

						for backbone_class in self.all_model_classes:
											__magic_name__					:							Tuple		   =							backbone_class(lowerCamelCase						)

											self.assertTrue(hasattr(lowerCamelCase				,     '''backbone_type'''						)						)
											self.assertTrue(hasattr(lowerCamelCase				,     '''stage_names'''						)						)
											self.assertTrue(hasattr(lowerCamelCase				,     '''num_features'''						)						)
											self.assertTrue(hasattr(lowerCamelCase				,     '''out_indices'''						)						)
											self.assertTrue(hasattr(lowerCamelCase				,     '''out_features'''						)						)
											self.assertTrue(hasattr(lowerCamelCase				,     '''out_feature_channels'''						)						)
											self.assertTrue(hasattr(lowerCamelCase				,     '''channels'''						)						)

											self.assertIsInstance(backbone.backbone_type				,     lowerCamelCase						)
											# Verify num_features has been initialized in the backbone init
											self.assertIsNotNone(backbone.num_features						)
											self.assertTrue(len(backbone.channels						) == len(backbone.out_indices						)						)
											self.assertTrue(len(backbone.stage_names						) == len(backbone.num_features						)						)
											self.assertTrue(len(backbone.channels						) <= len(backbone.num_features						)						)
											self.assertTrue(len(backbone.out_feature_channels						) == len(backbone.stage_names						)						)






	def  lowercase      (	self						)      ->   Any:




						"""simple docstring"""






						__magic_name__   , __magic_name__					:							Dict		   =							self.model_tester.prepare_config_and_inputs_for_common()
						__magic_name__					:							Any		   =							inputs_dict['''pixel_values'''].shape[0]

						for backbone_class in self.all_model_classes:
											__magic_name__					:							Any		   =							backbone_class(lowerCamelCase						)
											backbone.to(lowerCamelCase						)
											backbone.eval()

											__magic_name__					:							str		   =							backbone(**lowerCamelCase						)

											# Test default outputs and verify feature maps
											self.assertIsInstance(outputs.feature_maps				,     lowerCamelCase						)
											self.assertTrue(len(outputs.feature_maps						) == len(backbone.channels						)						)
											for feature_map, n_channels in zip(outputs.feature_maps				,     backbone.channels						):
																self.assertTrue(feature_map.shape[:2]				,     (batch_size, n_channels)						)
											self.assertIsNone(outputs.hidden_states						)
											self.assertIsNone(outputs.attentions						)

											# Test output_hidden_states=True
											__magic_name__					:							List[str]		   =							backbone(**lowerCamelCase				,     output_hidden_states=lowerCamelCase						)
											self.assertIsNotNone(outputs.hidden_states						)
											self.assertTrue(len(outputs.hidden_states						)				,     len(backbone.stage_names						)						)
											for hidden_state, n_channels in zip(outputs.hidden_states				,     backbone.channels						):
																self.assertTrue(hidden_state.shape[:2]				,     (batch_size, n_channels)						)

											# Test output_attentions=True
											if self.has_attentions:
																__magic_name__					:							Optional[int]		   =							backbone(**lowerCamelCase				,     output_attentions=lowerCamelCase						)
																self.assertIsNotNone(outputs.attentions						)









from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowercase_		=							logging.get_logger(__name__)

lowercase_		=							{
    '''uw-madison/yoso-4096''': '''https://huggingface.co/uw-madison/yoso-4096/resolve/main/config.json''',
    # See all YOSO models at https://huggingface.co/models?filter=yoso
}





class 		A__				(   __SCREAMING_SNAKE_CASE ):
	lowerCamelCase__		: Tuple				    ="yoso"






	def __init__(	self				,     lowerCamelCase=50265				,     lowerCamelCase=768				,     lowerCamelCase=12				,     lowerCamelCase=12				,     lowerCamelCase=3072				,     lowerCamelCase="gelu"				,     lowerCamelCase=0.1				,     lowerCamelCase=0.1				,     lowerCamelCase=4096				,     lowerCamelCase=1				,     lowerCamelCase=0.0_2				,     lowerCamelCase=1e-12				,     lowerCamelCase="absolute"				,     lowerCamelCase=True				,     lowerCamelCase=9				,     lowerCamelCase=64				,     lowerCamelCase=None				,     lowerCamelCase=True				,     lowerCamelCase=True				,     lowerCamelCase=1				,     lowerCamelCase=0				,     lowerCamelCase=2				,     **lowerCamelCase				,     )      ->   Tuple:




						"""simple docstring"""






						super().__init__(pad_token_id=lowerCamelCase				,     bos_token_id=lowerCamelCase				,     eos_token_id=lowerCamelCase				,     **lowerCamelCase						)

						__magic_name__					:							Union[str, Any]		   =							vocab_size
						__magic_name__					:							Union[str, Any]		   =							max_position_embeddings
						__magic_name__					:							Tuple		   =							hidden_size
						__magic_name__					:							Optional[Any]		   =							num_hidden_layers
						__magic_name__					:							Any		   =							num_attention_heads
						__magic_name__					:							List[str]		   =							intermediate_size
						__magic_name__					:							List[str]		   =							hidden_act
						__magic_name__					:							Tuple		   =							hidden_dropout_prob
						__magic_name__					:							str		   =							attention_probs_dropout_prob
						__magic_name__					:							str		   =							initializer_range
						__magic_name__					:							List[str]		   =							type_vocab_size
						__magic_name__					:							Dict		   =							layer_norm_eps
						__magic_name__					:							Any		   =							position_embedding_type
						__magic_name__					:							Optional[Any]		   =							use_expectation
						__magic_name__					:							Optional[Any]		   =							hash_code_len
						__magic_name__					:							Dict		   =							num_hash
						__magic_name__					:							str		   =							conv_window
						__magic_name__					:							Optional[Any]		   =							use_fast_hash
						__magic_name__					:							Union[str, Any]		   =							lsh_backward



