





import copy
import inspect

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






@require_torch
class 	UpperCamelCase_     :
					_a			:	Dict							=				()
					_a			:	Any							=				True



					def      __a    (		self    :    int	):
							lowerCamelCase_  :    Optional[int]   	=			self.config_class

							# test default config
							lowerCamelCase_  :    Dict   	=			config_class()
							self.assertIsNotNone(lowerCamelCase	)
							lowerCamelCase_  :    List[str]   	=			['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
							lowerCamelCase_  :    Dict   	=			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
							lowerCamelCase_  :    str   	=			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
							lowerCamelCase_  :    Dict   	=			config_class(out_features=['stage1', 'stage3']	)
							self.assertEqual(config.out_features					,			['stage1', 'stage3']	)
							self.assertEqual(config.out_indices					,			[1, 3]	)

							# Only out_indices set
							lowerCamelCase_  :    Dict   	=			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	):
									lowerCamelCase_  :    Tuple   	=			config_class(out_features=['stage1', 'stage2']					,			out_indices=[0, 2]	)



					def      __a    (		self    :    Any	):
							lowerCamelCase_	,			lowerCamelCase_  :    Dict   	=			self.model_tester.prepare_config_and_inputs_for_common()

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



					def      __a    (		self    :    Optional[Any]	):
							lowerCamelCase_	,			lowerCamelCase_  :    Tuple   	=			self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
									lowerCamelCase_  :    Dict   	=			model_class(lowerCamelCase	)
									self.assertEqual(len(model.channels	)					,			len(config.out_features	)	)
									lowerCamelCase_  :    int   	=			model.num_features
									lowerCamelCase_  :    Tuple   	=			[config.stage_names.index(lowerCamelCase	) for feat in config.out_features]
									lowerCamelCase_  :    Dict   	=			[num_features[idx] for idx in out_indices]
									self.assertListEqual(model.channels					,			lowerCamelCase	)

									lowerCamelCase_  :    Any   	=			copy.deepcopy(lowerCamelCase	)
									lowerCamelCase_  :    Optional[Any]   	=			None
									lowerCamelCase_  :    Optional[int]   	=			model_class(lowerCamelCase	)
									self.assertEqual(len(model.channels	)					,			1	)
									self.assertListEqual(model.channels					,			[num_features[-1]]	)

									lowerCamelCase_  :    Dict   	=			copy.deepcopy(lowerCamelCase	)
									lowerCamelCase_  :    Optional[int]   	=			None
									lowerCamelCase_  :    int   	=			model_class(lowerCamelCase	)
									self.assertEqual(len(model.channels	)					,			1	)
									self.assertListEqual(model.channels					,			[num_features[-1]]	)



					def      __a    (		self    :    List[str]	):
							lowerCamelCase_	,			lowerCamelCase_  :    List[str]   	=			self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
									lowerCamelCase_  :    int   	=			model_class(lowerCamelCase	)
									model.to(lowerCamelCase	)
									model.eval()
									lowerCamelCase_  :    int   	=			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
									lowerCamelCase_  :    List[str]   	=			copy.deepcopy(lowerCamelCase	)
									lowerCamelCase_  :    Any   	=			None
									lowerCamelCase_  :    Optional[int]   	=			model_class(lowerCamelCase	)
									model.to(lowerCamelCase	)
									model.eval()
									lowerCamelCase_  :    Any   	=			model(**lowerCamelCase	)

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

									lowerCamelCase_  :    Any   	=			copy.deepcopy(lowerCamelCase	)
									lowerCamelCase_  :    Dict   	=			None
									lowerCamelCase_  :    int   	=			model_class(lowerCamelCase	)
									model.to(lowerCamelCase	)
									model.eval()
									lowerCamelCase_  :    int   	=			model(**lowerCamelCase	)

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

									# Check backbone can be initialized with fresh weights
									lowerCamelCase_  :    Union[str, Any]   	=			copy.deepcopy(lowerCamelCase	)
									lowerCamelCase_  :    Tuple   	=			False
									lowerCamelCase_  :    Any   	=			model_class(lowerCamelCase	)
									model.to(lowerCamelCase	)
									model.eval()
									lowerCamelCase_  :    Any   	=			model(**lowerCamelCase	)



					def      __a    (		self    :    Optional[int]	):
							lowerCamelCase_	,			lowerCamelCase_  :    List[Any]   	=			self.model_tester.prepare_config_and_inputs_for_common()

							for backbone_class in self.all_model_classes:
									lowerCamelCase_  :    int   	=			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      __a    (		self    :    Dict	):
							lowerCamelCase_	,			lowerCamelCase_  :    Optional[int]   	=			self.model_tester.prepare_config_and_inputs_for_common()
							lowerCamelCase_  :    Any   	=			inputs_dict['pixel_values'].shape[0]

							for backbone_class in self.all_model_classes:
									lowerCamelCase_  :    List[Any]   	=			backbone_class(lowerCamelCase	)
									backbone.to(lowerCamelCase	)
									backbone.eval()

									lowerCamelCase_  :    Union[str, Any]   	=			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
									lowerCamelCase_  :    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:
											lowerCamelCase_  :    Union[str, Any]   	=			backbone(**lowerCamelCase					,			output_attentions=lowerCamelCase	)
											self.assertIsNotNone(outputs.attentions	)







def 		_SCREAMING_SNAKE_CASE    (   lowerCAmelCase__       ,lowerCAmelCase__	):
		return (input_a, input_a).count(0	) % 2


def 		_SCREAMING_SNAKE_CASE    (   ):
		assert xor_gate(0       ,0	) == 0
		assert xor_gate(0       ,1	) == 1
		assert xor_gate(1       ,0	) == 1
		assert xor_gate(1       ,1	) == 0


if __name__ == "__main__":
		print(xor_gate(0, 0))
		print(xor_gate(0, 1))
