

'''simple docstring'''


import inspect
import unittest

from transformers import MobileNetVaConfig
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_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
					import torch

					from transformers import MobileNetVaForImageClassification, MobileNetVaForSemanticSegmentation, MobileNetVaModel
					from transformers.models.mobilenet_va.modeling_mobilenet_va import MOBILENET_V2_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
					from PIL import Image

					from transformers import MobileNetVaImageProcessor




class      a      (					__a							):






						"""simple docstring"""




						def    __magic_name__				(				self       :   Dict	):



								'''simple docstring'''



								snake_case__    :							int							    =	self.config_class(**self.inputs_dict	)
								self.parent.assertTrue(hasattr(_lowerCamelCase      ,      '''tf_padding'''	)	)
								self.parent.assertTrue(hasattr(_lowerCamelCase      ,      '''depth_multiplier'''	)	)





class      a      :






						"""simple docstring"""




						def __init__(				self       :   Optional[Any]      ,      snake_case_       :   Any      ,      snake_case_       :   Tuple=1_3      ,      snake_case_       :   Dict=3      ,      snake_case_       :   Optional[int]=3_2      ,      snake_case_       :   Optional[int]=0.2_5      ,      snake_case_       :   List[str]=8      ,      snake_case_       :   Dict=8      ,      snake_case_       :   List[str]=6      ,      snake_case_       :   Any=3_2      ,      snake_case_       :   Tuple=True      ,      snake_case_       :   Tuple=True      ,      snake_case_       :   Dict=True      ,      snake_case_       :   int="relu6"      ,      snake_case_       :   List[Any]=1_2_8_0      ,      snake_case_       :   Optional[int]=0.1      ,      snake_case_       :   Tuple=0.0_2      ,      snake_case_       :   List[str]=True      ,      snake_case_       :   List[str]=True      ,      snake_case_       :   Tuple=1_0      ,      snake_case_       :   Tuple=None      ,      ):



								'''simple docstring'''



								snake_case__    :							int							    =	parent
								snake_case__    :							Optional[int]							    =	batch_size
								snake_case__    :							Optional[int]							    =	num_channels
								snake_case__    :							List[str]							    =	image_size
								snake_case__    :							List[str]							    =	depth_multiplier
								snake_case__    :							Optional[int]							    =	depth_divisible_by
								snake_case__    :							Dict							    =	min_depth
								snake_case__    :							List[str]							    =	expand_ratio
								snake_case__    :							int							    =	tf_padding
								snake_case__    :							Optional[Any]							    =	output_stride
								snake_case__    :							List[str]							    =	first_layer_is_expansion
								snake_case__    :							Optional[Any]							    =	finegrained_output
								snake_case__    :							Optional[Any]							    =	hidden_act
								snake_case__    :							Dict							    =	last_hidden_size if finegrained_output else int(last_hidden_size * depth_multiplier	)
								snake_case__    :							Dict							    =	classifier_dropout_prob
								snake_case__    :							Optional[Any]							    =	use_labels
								snake_case__    :							List[Any]							    =	is_training
								snake_case__    :							Dict							    =	num_labels
								snake_case__    :							Dict							    =	initializer_range
								snake_case__    :							List[str]							    =	scope







						def    __magic_name__				(				self       :   Dict	):



								'''simple docstring'''



								snake_case__    :							str							    =	floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]	)

								snake_case__    :							int							    =	None
								snake_case__    :							Optional[Any]							    =	None
								if self.use_labels:
										snake_case__    :							int							    =	ids_tensor([self.batch_size]      ,      self.num_labels	)
										snake_case__    :							int							    =	ids_tensor([self.batch_size, self.image_size, self.image_size]      ,      self.num_labels	)

								snake_case__    :							Optional[int]							    =	self.get_config()

								return config, pixel_values, labels, pixel_labels







						def    __magic_name__				(				self       :   List[str]	):



								'''simple docstring'''



								return MobileNetVaConfig(
								    num_channels=self.num_channels      ,      image_size=self.image_size      ,      depth_multiplier=self.depth_multiplier      ,      depth_divisible_by=self.depth_divisible_by      ,      min_depth=self.min_depth      ,      expand_ratio=self.expand_ratio      ,      output_stride=self.output_stride      ,      first_layer_is_expansion=self.first_layer_is_expansion      ,      finegrained_output=self.finegrained_output      ,      hidden_act=self.hidden_act      ,      tf_padding=self.tf_padding      ,      classifier_dropout_prob=self.classifier_dropout_prob      ,      initializer_range=self.initializer_range      ,      )







						def    __magic_name__				(				self       :   Dict      ,      snake_case_       :   Dict      ,      snake_case_       :   Any      ,      snake_case_       :   str      ,      snake_case_       :   Optional[Any]	):



								'''simple docstring'''



								snake_case__    :							Dict							    =	MobileNetVaModel(config=_lowerCamelCase	)
								model.to(_lowerCamelCase	)
								model.eval()
								snake_case__    :							int							    =	model(_lowerCamelCase	)
								self.parent.assertEqual(
								    result.last_hidden_state.shape      ,      (
								        self.batch_size,
								        self.last_hidden_size,
								        self.image_size // self.output_stride,
								        self.image_size // self.output_stride,
								    )      ,      )
								self.parent.assertEqual(
								    result.pooler_output.shape      ,      (self.batch_size, self.last_hidden_size)      ,      )







						def    __magic_name__				(				self       :   Optional[int]      ,      snake_case_       :   Union[str, Any]      ,      snake_case_       :   Any      ,      snake_case_       :   str      ,      snake_case_       :   Optional[Any]	):



								'''simple docstring'''



								snake_case__    :							int							    =	self.num_labels
								snake_case__    :							Union[str, Any]							    =	MobileNetVaForImageClassification(_lowerCamelCase	)
								model.to(_lowerCamelCase	)
								model.eval()
								snake_case__    :							int							    =	model(_lowerCamelCase      ,      labels=_lowerCamelCase	)
								self.parent.assertEqual(result.logits.shape      ,      (self.batch_size, self.num_labels)	)







						def    __magic_name__				(				self       :   str      ,      snake_case_       :   Dict      ,      snake_case_       :   Any      ,      snake_case_       :   int      ,      snake_case_       :   List[str]	):



								'''simple docstring'''



								snake_case__    :							Optional[int]							    =	self.num_labels
								snake_case__    :							Tuple							    =	MobileNetVaForSemanticSegmentation(_lowerCamelCase	)
								model.to(_lowerCamelCase	)
								model.eval()
								snake_case__    :							Dict							    =	model(_lowerCamelCase	)
								self.parent.assertEqual(
								    result.logits.shape      ,      (
								        self.batch_size,
								        self.num_labels,
								        self.image_size // self.output_stride,
								        self.image_size // self.output_stride,
								    )      ,      )
								snake_case__    :							Any							    =	model(_lowerCamelCase      ,      labels=_lowerCamelCase	)
								self.parent.assertEqual(
								    result.logits.shape      ,      (
								        self.batch_size,
								        self.num_labels,
								        self.image_size // self.output_stride,
								        self.image_size // self.output_stride,
								    )      ,      )







						def    __magic_name__				(				self       :   Dict	):



								'''simple docstring'''



								snake_case__    :							Any							    =	self.prepare_config_and_inputs()
								snake_case__    ,							snake_case__    ,							snake_case__    ,							snake_case__    :							Optional[int]							    =	config_and_inputs
								snake_case__    :							str							    =	{'''pixel_values''': pixel_values}
								return config, inputs_dict





@require_torch
class      a      (					__a      ,      __a      ,      unittest.TestCase							):






						"""simple docstring"""




						__UpperCAmelCase        =     (
						    (MobileNetVaModel, MobileNetVaForImageClassification, MobileNetVaForSemanticSegmentation)
						    if is_torch_available()
						    else ()
						)
						__UpperCAmelCase        =     (
						    {
						        'feature-extraction': MobileNetVaModel,
						        'image-classification': MobileNetVaForImageClassification,
						        'image-segmentation': MobileNetVaForSemanticSegmentation,
						    }
						    if is_torch_available()
						    else {}
						)

						__UpperCAmelCase        =     False
						__UpperCAmelCase        =     False
						__UpperCAmelCase        =     False
						__UpperCAmelCase        =     False







						def    __magic_name__				(				self       :   str	):



								'''simple docstring'''



								snake_case__    :							Tuple							    =	MobileNetVaModelTester(self	)
								snake_case__    :							Dict							    =	MobileNetVaConfigTester(self      ,      config_class=_lowerCamelCase      ,      has_text_modality=_lowerCamelCase	)







						def    __magic_name__				(				self       :   int	):



								'''simple docstring'''



								self.config_tester.run_common_tests()







						@unittest.skip(reason='''MobileNetV2 does not use inputs_embeds'''	)
						def    __magic_name__				(				self       :   List[Any]	):



								'''simple docstring'''



								pass







						@unittest.skip(reason='''MobileNetV2 does not support input and output embeddings'''	)
						def    __magic_name__				(				self       :   List[str]	):



								'''simple docstring'''



								pass







						@unittest.skip(reason='''MobileNetV2 does not output attentions'''	)
						def    __magic_name__				(				self       :   str	):



								'''simple docstring'''



								pass







						def    __magic_name__				(				self       :   List[Any]	):



								'''simple docstring'''



								snake_case__    ,							snake_case__    :							str							    =	self.model_tester.prepare_config_and_inputs_for_common()

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

										snake_case__    :							List[str]							    =	['''pixel_values''']
										self.assertListEqual(arg_names[:1]      ,      _lowerCamelCase	)







						def    __magic_name__				(				self       :   Dict	):



								'''simple docstring'''



								snake_case__    :							Union[str, Any]							    =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*_lowerCamelCase	)







						def    __magic_name__				(				self       :   Tuple	):



								'''simple docstring'''



								def check_hidden_states_output(snake_case_       :   Tuple      ,      snake_case_       :   Union[str, Any]      ,      snake_case_       :   Optional[Any]	):
										snake_case__    :							int							    =	model_class(_lowerCamelCase	)
										model.to(_lowerCamelCase	)
										model.eval()

										with torch.no_grad():
												snake_case__    :							Union[str, Any]							    =	model(**self._prepare_for_class(_lowerCamelCase      ,      _lowerCamelCase	)	)

										snake_case__    :							List[Any]							    =	outputs.hidden_states

										snake_case__    :							List[Any]							    =	1_6
										self.assertEqual(len(_lowerCamelCase	)      ,      _lowerCamelCase	)

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

								for model_class in self.all_model_classes:
										snake_case__    :							int							    =	True
										check_hidden_states_output(_lowerCamelCase      ,      _lowerCamelCase      ,      _lowerCamelCase	)

										# check that output_hidden_states also work using config
										del inputs_dict["output_hidden_states"]
										snake_case__    :							Union[str, Any]							    =	True

										check_hidden_states_output(_lowerCamelCase      ,      _lowerCamelCase      ,      _lowerCamelCase	)







						def    __magic_name__				(				self       :   Union[str, Any]	):



								'''simple docstring'''



								snake_case__    :							Optional[Any]							    =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_image_classification(*_lowerCamelCase	)







						def    __magic_name__				(				self       :   Union[str, Any]	):



								'''simple docstring'''



								snake_case__    :							Dict							    =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_semantic_segmentation(*_lowerCamelCase	)







						@slow
						def    __magic_name__				(				self       :   Any	):



								'''simple docstring'''



								for model_name in MOBILENET_V2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
										snake_case__    :							Dict							    =	MobileNetVaModel.from_pretrained(_lowerCamelCase	)
										self.assertIsNotNone(_lowerCamelCase	)





def 						_a							(					):

		"""simple docstring"""

		snake_case__    :							List[str]							    =	Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''  )
		return image





@require_torch
@require_vision
class      a      (					unittest.TestCase							):






						"""simple docstring"""




						@cached_property
						def    __magic_name__				(				self       :   Any	):



								'''simple docstring'''



								return (
								    MobileNetVaImageProcessor.from_pretrained('''google/mobilenet_v2_1.0_224'''	) if is_vision_available() else None
								)







						@slow
						def    __magic_name__				(				self       :   Optional[int]	):



								'''simple docstring'''



								snake_case__    :							Union[str, Any]							    =	MobileNetVaForImageClassification.from_pretrained('''google/mobilenet_v2_1.0_224'''	).to(_lowerCamelCase	)

								snake_case__    :							Tuple							    =	self.default_image_processor
								snake_case__    :							int							    =	prepare_img()
								snake_case__    :							Optional[int]							    =	image_processor(images=_lowerCamelCase      ,      return_tensors='''pt'''	).to(_lowerCamelCase	)

								# forward pass
								with torch.no_grad():
										snake_case__    :							int							    =	model(**_lowerCamelCase	)

								# verify the logits
								snake_case__    :							List[Any]							    =	torch.Size((1, 1_0_0_1)	)
								self.assertEqual(outputs.logits.shape      ,      _lowerCamelCase	)

								snake_case__    :							int							    =	torch.tensor([0.2_4_4_5, -1.1_9_9_3, 0.1_9_0_5]	).to(_lowerCamelCase	)

								self.assertTrue(torch.allclose(outputs.logits[0, :3]      ,      _lowerCamelCase      ,      atol=1e-4	)	)







						@slow
						def    __magic_name__				(				self       :   str	):



								'''simple docstring'''



								snake_case__    :							str							    =	MobileNetVaForSemanticSegmentation.from_pretrained('''google/deeplabv3_mobilenet_v2_1.0_513'''	)
								snake_case__    :							List[Any]							    =	model.to(_lowerCamelCase	)

								snake_case__    :							Optional[int]							    =	MobileNetVaImageProcessor.from_pretrained('''google/deeplabv3_mobilenet_v2_1.0_513'''	)

								snake_case__    :							Tuple							    =	prepare_img()
								snake_case__    :							int							    =	image_processor(images=_lowerCamelCase      ,      return_tensors='''pt'''	).to(_lowerCamelCase	)

								# forward pass
								with torch.no_grad():
										snake_case__    :							str							    =	model(**_lowerCamelCase	)
								snake_case__    :							Any							    =	outputs.logits

								# verify the logits
								snake_case__    :							Tuple							    =	torch.Size((1, 2_1, 6_5, 6_5)	)
								self.assertEqual(logits.shape      ,      _lowerCamelCase	)

								snake_case__    :							Optional[Any]							    =	torch.tensor(
								    [
								        [[1_7.5_7_9_0, 1_7.7_5_8_1, 1_8.3_3_5_5], [1_8.3_2_5_7, 1_8.4_2_3_0, 1_8.8_9_7_3], [1_8.6_1_6_9, 1_8.8_6_5_0, 1_9.2_1_8_7]],
								        [[-2.1_5_9_5, -2.0_9_7_7, -2.3_7_4_1], [-2.4_2_2_6, -2.3_0_2_8, -2.6_8_3_5], [-2.7_8_1_9, -2.5_9_9_1, -2.7_7_0_6]],
								        [[4.2_0_5_8, 4.8_3_1_7, 4.7_6_3_8], [4.4_1_3_6, 5.0_3_6_1, 4.9_3_8_3], [4.5_0_2_8, 4.9_6_4_4, 4.8_7_3_4]],
								    ]      ,      device=_lowerCamelCase      ,      )

								self.assertTrue(torch.allclose(logits[0, :3, :3, :3]      ,      _lowerCamelCase      ,      atol=1e-4	)	)




'''simple docstring'''

from __future__ import annotations



def snake_case_      (					__snake_case  :							list[int | str])			->					None:
   create_state_space_tree(__snake_case	,   []	,   0	,   [0 for i in range(len(__snake_case))])



def snake_case_      (					__snake_case  :							list[int | str]	,   __snake_case  :							list[int | str]	,   __snake_case  :							int	,   __snake_case  :							list[int]	,   )			->					None:

   if index == len(__snake_case):
      print(__snake_case)
      return

   for i in range(len(__snake_case)):
      if not index_used[i]:
         current_sequence.append(sequence[i])
         lowerCAmelCase_			=      True
         create_state_space_tree(__snake_case	,   __snake_case	,   index + 1	,   __snake_case)
         current_sequence.pop()
         lowerCAmelCase_			=      False
A_     :						list[int | str]    							=[3, 1, 2, 4]
generate_all_permutations(sequence)

A_     :						list[int | str]    							=["A", "B", "C"]






generate_all_permutations(sequence_a)





