code: 
  """simple docstring"""
  import inspect
  import unittest
  import warnings
  from typing import List
  
  from transformers import EfficientFormerConfig
  from transformers.models.auto import get_values
  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 (
  			    MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
  			    MODEL_MAPPING,
  			    EfficientFormerForImageClassification,
  			    EfficientFormerForImageClassificationWithTeacher,
  			    EfficientFormerModel,
  			)
  			from transformers.models.efficientformer.modeling_efficientformer import (
  			    EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
  			)
  
  
  if is_vision_available():
  			from PIL import Image
  
  			from transformers import EfficientFormerImageProcessor
  
  
  class    _lowerCAmelCase						:
  
  
  
  							def __init__(      self ,						a_ ,						a_ = 13 ,						a_ = 64 ,						a_ = 2 ,						a_ = 3 ,						a_ = 3 ,						a_ = True ,						a_ = True ,						a_ = 128 ,						a_=[16, 32, 64, 128] ,						a_ = 7 ,						a_ = 4 ,						a_ = 37 ,						a_ = "gelu" ,						a_ = 0.1 ,						a_ = 0.1 ,						a_ = 10 ,						a_ = 0.02 ,						a_ = 2 ,						a_ = 1 ,						a_ = 128 ,						a_ = [2, 2, 2, 2] ,						a_ = 2 ,						a_ = 2 ,						)							->							Tuple:
  								_UpperCAmelCase =						parent
  								_UpperCAmelCase =						batch_size
  								_UpperCAmelCase =						image_size
  								_UpperCAmelCase =						patch_size
  								_UpperCAmelCase =						num_channels
  								_UpperCAmelCase =						is_training
  								_UpperCAmelCase =						use_labels
  								_UpperCAmelCase =						hidden_size
  								_UpperCAmelCase =						num_hidden_layers
  								_UpperCAmelCase =						num_attention_heads
  								_UpperCAmelCase =						intermediate_size
  								_UpperCAmelCase =						hidden_act
  								_UpperCAmelCase =						hidden_dropout_prob
  								_UpperCAmelCase =						attention_probs_dropout_prob
  								_UpperCAmelCase =						type_sequence_label_size
  								_UpperCAmelCase =						initializer_range
  								_UpperCAmelCase =						encoder_stride
  								_UpperCAmelCase =						num_attention_outputs
  								_UpperCAmelCase =						embed_dim
  								_UpperCAmelCase =						embed_dim + 1
  								_UpperCAmelCase =						resolution
  								_UpperCAmelCase =						depths
  								_UpperCAmelCase =						hidden_sizes
  								_UpperCAmelCase =						dim
  								_UpperCAmelCase =						mlp_expansion_ratio
  
  
  
  							def       _a   (      self   )							->							Tuple:
  								_UpperCAmelCase =						floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]   )
  
  								_UpperCAmelCase =						None
  								if self.use_labels:
  									_UpperCAmelCase =						ids_tensor([self.batch_size] ,						self.type_sequence_label_size   )
  
  								_UpperCAmelCase =						self.get_config()
  								return config, pixel_values, labels
  
  
  
  							def       _a   (      self   )							->							Optional[int]:
  								return EfficientFormerConfig(
  								    image_size=self.image_size ,						patch_size=self.patch_size ,						num_channels=self.num_channels ,						hidden_size=self.hidden_size ,						num_hidden_layers=self.num_hidden_layers ,						num_attention_heads=self.num_attention_heads ,						intermediate_size=self.intermediate_size ,						hidden_act=self.hidden_act ,						hidden_dropout_prob=self.hidden_dropout_prob ,						attention_probs_dropout_prob=self.attention_probs_dropout_prob ,						is_decoder=a_ ,						initializer_range=self.initializer_range ,						encoder_stride=self.encoder_stride ,						resolution=self.resolution ,						depths=self.depths ,						hidden_sizes=self.hidden_sizes ,						dim=self.dim ,						mlp_expansion_ratio=self.mlp_expansion_ratio ,						)
  
  
  
  							def       _a   (      self ,						a_ ,						a_ ,						a_   )							->							int:
  								_UpperCAmelCase =						EfficientFormerModel(config=a_   )
  								model.to(a_   )
  								model.eval()
  								_UpperCAmelCase =						model(a_   )
  								self.parent.assertEqual(result.last_hidden_state.shape ,						(self.batch_size, self.seq_length, self.hidden_size)   )
  
  
  
  							def       _a   (      self ,						a_ ,						a_ ,						a_   )							->							str:
  								_UpperCAmelCase =						self.type_sequence_label_size
  								_UpperCAmelCase =						EfficientFormerForImageClassification(a_   )
  								model.to(a_   )
  								model.eval()
  								_UpperCAmelCase =						model(a_ ,						labels=a_   )
  								self.parent.assertEqual(result.logits.shape ,						(self.batch_size, self.type_sequence_label_size)   )
  
  								# test greyscale images
  								_UpperCAmelCase =						1
  								_UpperCAmelCase =						EfficientFormerForImageClassification(a_   )
  								model.to(a_   )
  								model.eval()
  
  								_UpperCAmelCase =						floats_tensor([self.batch_size, 1, self.image_size, self.image_size]   )
  								_UpperCAmelCase =						model(a_   )
  								self.parent.assertEqual(result.logits.shape ,						(self.batch_size, self.type_sequence_label_size)   )
  
  
  
  							def       _a   (      self   )							->							Optional[int]:
  								_UpperCAmelCase =						self.prepare_config_and_inputs()
  								(
  								    (
  								    _UpperCAmelCase
  								) ,      (
  								    _UpperCAmelCase
  								) ,      (
  								    _UpperCAmelCase
  								) ,      
  								) =						config_and_inputs
  								_UpperCAmelCase =						{"pixel_values": pixel_values}
  								return config, inputs_dict
  
  
  
  
  
  @require_torch
  class    _lowerCAmelCase						(						lowerCamelCase    ,       lowerCamelCase    ,       unittest.TestCase						):
  							lowercase_     :     List[Any]       =							(
  							    (
  							        EfficientFormerModel,
  							        EfficientFormerForImageClassificationWithTeacher,
  							        EfficientFormerForImageClassification,
  							    )
  							    if is_torch_available()
  							    else ()
  							)
  							lowercase_     :     Optional[Any]       =							(
  							    {
  							        '''feature-extraction''': EfficientFormerModel,
  							        '''image-classification''': (
  							            EfficientFormerForImageClassification,
  							            EfficientFormerForImageClassificationWithTeacher,
  							        ),
  							    }
  							    if is_torch_available()
  							    else {}
  							)
  							lowercase_     :     List[str]       =							False
  
  							lowercase_     :     Dict       =							False
  							lowercase_     :     List[str]       =							False
  							lowercase_     :     List[str]       =							False
  
  
  
  							def       _a   (      self   )							->							Dict:
  								_UpperCAmelCase =						EfficientFormerModelTester(self   )
  								_UpperCAmelCase =						ConfigTester(
  								    self ,						config_class=a_ ,						has_text_modality=a_ ,						hidden_size=37   )
  
  
  
  							def       _a   (      self   )							->							List[Any]:
  								self.config_tester.run_common_tests()
  
  
  
  							@unittest.skip(reason="EfficientFormer does not use inputs_embeds"   )
  							def       _a   (      self   )							->							Tuple:
  								pass
  
  
  
  							@unittest.skip(reason="EfficientFormer does not support input and output embeddings"   )
  							def       _a   (      self   )							->							Optional[int]:
  								pass
  
  
  
  							def       _a   (      self   )							->							Optional[Any]:
  								_UpperCAmelCase ,      _UpperCAmelCase =						self.model_tester.prepare_config_and_inputs_for_common()
  
  								for model_class in self.all_model_classes:
  									_UpperCAmelCase =						model_class(a_   )
  									_UpperCAmelCase =						inspect.signature(model.forward   )
  									# signature.parameters is an OrderedDict => so arg_names order is deterministic
  									_UpperCAmelCase =						[*signature.parameters.keys()]
  
  									_UpperCAmelCase =						["pixel_values"]
  									self.assertListEqual(arg_names[:1] ,						a_   )
  
  
  
  							def       _a   (      self   )							->							int:
  								def check_hidden_states_output(a_ ,						a_ ,						a_   ):
  									_UpperCAmelCase =						model_class(a_   )
  									model.to(a_   )
  									model.eval()
  
  									with torch.no_grad():
  										_UpperCAmelCase =						model(**self._prepare_for_class(a_ ,						a_   )   )
  
  									_UpperCAmelCase =						outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states
  
  									_UpperCAmelCase =						getattr(
  									    self.model_tester ,						"expected_num_hidden_layers" ,						self.model_tester.num_hidden_layers + 1   )
  									self.assertEqual(len(a_   ) ,						a_   )
  
  									if hasattr(self.model_tester ,						"encoder_seq_length"   ):
  										_UpperCAmelCase =						self.model_tester.encoder_seq_length
  										if hasattr(self.model_tester ,						"chunk_length"   ) and self.model_tester.chunk_length > 1:
  											_UpperCAmelCase =						seq_length * self.model_tester.chunk_length
  									else:
  										_UpperCAmelCase =						self.model_tester.seq_length
  
  									self.assertListEqual(
  									    list(hidden_states[-1].shape[-2:]   ) ,						[seq_length, self.model_tester.hidden_size] ,						)
  
  									if config.is_encoder_decoder:
  										_UpperCAmelCase =						outputs.decoder_hidden_states
  
  										self.assertIsInstance(a_ ,						(list, tuple)   )
  										self.assertEqual(len(a_   ) ,						a_   )
  										_UpperCAmelCase =						getattr(self.model_tester ,						"seq_length" ,						a_   )
  										_UpperCAmelCase =						getattr(self.model_tester ,						"decoder_seq_length" ,						a_   )
  
  										self.assertListEqual(
  										    list(hidden_states[-1].shape[-2:]   ) ,						[decoder_seq_length, self.model_tester.hidden_size] ,						)
  
  								_UpperCAmelCase ,      _UpperCAmelCase =						self.model_tester.prepare_config_and_inputs_for_common()
  
  								for model_class in self.all_model_classes:
  									_UpperCAmelCase =						True
  									check_hidden_states_output(a_ ,						a_ ,						a_   )
  
  									# check that output_hidden_states also work using config
  									del inputs_dict["output_hidden_states"]
  									_UpperCAmelCase =						True
  
  									check_hidden_states_output(a_ ,						a_ ,						a_   )
  
  
  
  							def       _a   (      self ,						a_ ,						a_ ,						a_=False   )							->							Optional[Any]:
  								_UpperCAmelCase =						super()._prepare_for_class(a_ ,						a_ ,						return_labels=a_   )
  
  								if return_labels:
  									if model_class.__name__ == "EfficientFormerForImageClassificationWithTeacher":
  										del inputs_dict["labels"]
  
  								return inputs_dict
  
  
  
  							def       _a   (      self   )							->							int:
  								_UpperCAmelCase =						self.model_tester.prepare_config_and_inputs()
  								self.model_tester.create_and_check_model(*a_   )
  
  
  
  							@unittest.skip(reason="EfficientFormer does not implement masked image modeling yet"   )
  							def       _a   (      self   )							->							int:
  								_UpperCAmelCase =						self.model_tester.prepare_config_and_inputs()
  								self.model_tester.create_and_check_for_masked_image_modeling(*a_   )
  
  
  
  							def       _a   (      self   )							->							int:
  								_UpperCAmelCase =						self.model_tester.prepare_config_and_inputs()
  								self.model_tester.create_and_check_for_image_classification(*a_   )
  
  
  
  							def       _a   (      self   )							->							str:
  								if not self.model_tester.is_training:
  									return
  
  								_UpperCAmelCase ,      _UpperCAmelCase =						self.model_tester.prepare_config_and_inputs_for_common()
  								_UpperCAmelCase =						True
  
  								for model_class in self.all_model_classes:
  									# EfficientFormerForImageClassificationWithTeacher supports inference-only
  									if (
  									    model_class in get_values(a_   )
  									    or model_class.__name__ == "EfficientFormerForImageClassificationWithTeacher"
  									):
  										continue
  									_UpperCAmelCase =						model_class(a_   )
  									model.to(a_   )
  									model.train()
  									_UpperCAmelCase =						self._prepare_for_class(a_ ,						a_ ,						return_labels=a_   )
  									_UpperCAmelCase =						model(**a_   ).loss
  									loss.backward()
  
  
  
  							def       _a   (      self   )							->							Tuple:
  								_UpperCAmelCase ,      _UpperCAmelCase =						self.model_tester.prepare_config_and_inputs_for_common()
  
  								_UpperCAmelCase =						[
  								    {"title": "multi_label_classification", "num_labels": 2, "dtype": torch.float},
  								    {"title": "single_label_classification", "num_labels": 1, "dtype": torch.long},
  								    {"title": "regression", "num_labels": 1, "dtype": torch.float},
  								]
  
  								for model_class in self.all_model_classes:
  									if (
  									    model_class
  									    not in [
  									        *get_values(a_   ),
  									    ]
  									    or model_class.__name__ == "EfficientFormerForImageClassificationWithTeacher"
  									):
  										continue
  
  									for problem_type in problem_types:
  										with self.subTest(msg=f"Testing {model_class} with {problem_type['title']}"   ):
  											_UpperCAmelCase =						problem_type["title"]
  											_UpperCAmelCase =						problem_type["num_labels"]
  
  											_UpperCAmelCase =						model_class(a_   )
  											model.to(a_   )
  											model.train()
  
  											_UpperCAmelCase =						self._prepare_for_class(a_ ,						a_ ,						return_labels=a_   )
  
  											if problem_type["num_labels"] > 1:
  												_UpperCAmelCase =						inputs["labels"].unsqueeze(1   ).repeat(1 ,						problem_type["num_labels"]   )
  
  											_UpperCAmelCase =						inputs["labels"].to(problem_type["dtype"]   )
  
  											# This tests that we do not trigger the warning form PyTorch "Using a target size that is different
  											# to the input size. This will likely lead to incorrect results due to broadcasting. Please ensure
  											# they have the same size." which is a symptom something in wrong for the regression problem.
  											# See https://github.com/huggingface/transformers/issues/11780
  											with warnings.catch_warnings(record=a_   ) as warning_list:
  												_UpperCAmelCase =						model(**a_   ).loss
  											for w in warning_list:
  												if "Using a target size that is different to the input size" in str(w.message   ):
  													raise ValueError(
  													    f"Something is going wrong in the regression problem: intercepted {w.message}"   )
  
  											loss.backward()
  
  
  
  							@slow
  							def       _a   (      self   )							->							Tuple:
  								for model_name in EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
  									_UpperCAmelCase =						EfficientFormerModel.from_pretrained(a_   )
  									self.assertIsNotNone(a_   )
  
  
  
  							def       _a   (      self   )							->							Union[str, Any]:
  								_UpperCAmelCase ,      _UpperCAmelCase =						self.model_tester.prepare_config_and_inputs_for_common()
  								_UpperCAmelCase =						True
  
  								_UpperCAmelCase =						getattr(self.model_tester ,						"seq_length" ,						a_   )
  								_UpperCAmelCase =						getattr(self.model_tester ,						"encoder_seq_length" ,						a_   )
  								_UpperCAmelCase =						getattr(self.model_tester ,						"key_length" ,						a_   )
  								_UpperCAmelCase =						getattr(self.model_tester ,						"chunk_length" ,						a_   )
  
  								if chunk_length is not None and hasattr(self.model_tester ,						"num_hashes"   ):
  									_UpperCAmelCase =						encoder_seq_length * self.model_tester.num_hashes
  
  								for model_class in self.all_model_classes:
  									_UpperCAmelCase =						True
  									_UpperCAmelCase =						False
  									_UpperCAmelCase =						True
  									_UpperCAmelCase =						model_class(a_   )
  									model.to(a_   )
  									model.eval()
  									with torch.no_grad():
  										_UpperCAmelCase =						model(**self._prepare_for_class(a_ ,						a_   )   )
  									_UpperCAmelCase =						outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions
  									self.assertEqual(len(a_   ) ,						self.model_tester.num_attention_outputs   )
  
  									# check that output_attentions also work using config
  									del inputs_dict["output_attentions"]
  									_UpperCAmelCase =						True
  									_UpperCAmelCase =						model_class(a_   )
  									model.to(a_   )
  									model.eval()
  									with torch.no_grad():
  										_UpperCAmelCase =						model(**self._prepare_for_class(a_ ,						a_   )   )
  									_UpperCAmelCase =						outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions
  									self.assertEqual(len(a_   ) ,						self.model_tester.num_attention_outputs   )
  
  									if chunk_length is not None:
  										self.assertListEqual(
  										    list(attentions[0].shape[-4:]   ) ,						[self.model_tester.num_attention_heads, encoder_seq_length, chunk_length, encoder_key_length] ,						)
  									else:
  										self.assertListEqual(
  										    list(attentions[0].shape[-3:]   ) ,						[self.model_tester.num_attention_heads, encoder_seq_length, encoder_key_length] ,						)
  
  
  
  
  
  def     __lowerCamelCase  (		):
  
  
  	"""simple docstring"""
  
  
  
  
  
  
  	_UpperCAmelCase =						Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"      )
  	return image
  
  
  
  @require_torch
  @require_vision
  class    _lowerCAmelCase						(						unittest.TestCase						):
  
  
  
  							@cached_property
  							def       _a   (      self   )							->							Optional[Any]:
  								return (
  								    EfficientFormerImageProcessor.from_pretrained("snap-research/efficientformer-l1-300"   )
  								    if is_vision_available()
  								    else None
  								)
  
  
  
  							@slow
  							def       _a   (      self   )							->							Tuple:
  								_UpperCAmelCase =						EfficientFormerForImageClassification.from_pretrained("snap-research/efficientformer-l1-300"   ).to(
  								    a_   )
  
  								_UpperCAmelCase =						self.default_image_processor
  								_UpperCAmelCase =						prepare_img()
  								_UpperCAmelCase =						image_processor(images=a_ ,						return_tensors="pt"   ).to(a_   )
  
  								# forward pass
  								with torch.no_grad():
  									_UpperCAmelCase =						model(**a_   )
  
  								# verify the logits
  								_UpperCAmelCase =						(1, 1000)
  								self.assertEqual(outputs.logits.shape ,						a_   )
  
  								_UpperCAmelCase =						torch.tensor([-0.0555, 0.4825, -0.0852]   ).to(a_   )
  								self.assertTrue(torch.allclose(outputs.logits[0][:3] ,						a_ ,						atol=1e-4   )   )
  
  
  
  							@slow
  							def       _a   (      self   )							->							Tuple:
  								_UpperCAmelCase =						EfficientFormerForImageClassificationWithTeacher.from_pretrained(
  								    "snap-research/efficientformer-l1-300"   ).to(a_   )
  
  								_UpperCAmelCase =						self.default_image_processor
  								_UpperCAmelCase =						prepare_img()
  								_UpperCAmelCase =						image_processor(images=a_ ,						return_tensors="pt"   ).to(a_   )
  
  								# forward pass
  								with torch.no_grad():
  									_UpperCAmelCase =						model(**a_   )
  
  								# verify the logits
  								_UpperCAmelCase =						(1, 1000)
  								self.assertEqual(outputs.logits.shape ,						a_   )
  
  								_UpperCAmelCase =						torch.tensor([-0.1312, 0.4353, -1.0499]   ).to(a_   )
  								self.assertTrue(torch.allclose(outputs.logits[0][:3] ,						a_ ,						atol=1e-4   )   )
  
  
  
  
  
style_context: 
  """simple docstring"""
  import heapq
  
  
  
  
  def     __lowerCamelCase  (		UpperCamelCase__				,     UpperCamelCase__				,     UpperCamelCase__      ):
  
  
  	"""simple docstring"""
  
  
  
  
  
  
  	_UpperCAmelCase =						[(0, start)]  # cost from start node,end node
  	_UpperCAmelCase =						set()
  	while heap:
  		((_UpperCAmelCase) ,      (_UpperCAmelCase)) =						heapq.heappop(UpperCamelCase__      )
  		if u in visited:
  			continue
  		visited.add(UpperCamelCase__      )
  		if u == end:
  			return cost
  		for v, c in graph[u]:
  			if v in visited:
  				continue
  			_UpperCAmelCase =						cost + c
  			heapq.heappush(UpperCamelCase__				,     (next_item, v)      )
  	return -1
  
  
  __magic_name__		       =				{
      '''A''': [['''B''', 2], ['''C''', 5]],
      '''B''': [['''A''', 2], ['''D''', 3], ['''E''', 1], ['''F''', 1]],
      '''C''': [['''A''', 5], ['''F''', 3]],
      '''D''': [['''B''', 3]],
      '''E''': [['''B''', 4], ['''F''', 3]],
      '''F''': [['''C''', 3], ['''E''', 3]],
  }
  __magic_name__		       =				{
      '''B''': [['''C''', 1]],
      '''C''': [['''D''', 1]],
      '''D''': [['''F''', 1]],
      '''E''': [['''B''', 1], ['''F''', 3]],
      '''F''': [],
  }
  __magic_name__		       =				{
      '''B''': [['''C''', 1]],
      '''C''': [['''D''', 1]],
      '''D''': [['''F''', 1]],
      '''E''': [['''B''', 1], ['''G''', 2]],
      '''F''': [],
      '''G''': [['''F''', 1]],
  }
  
  __magic_name__		       =				dijkstra(G, '''E''', '''C''')
  print(short_distance)  # E -- 3 --> F -- 3 --> C == 6
  
  __magic_name__		       =				dijkstra(Ga, '''E''', '''F''')
  print(short_distance)  # E -- 3 --> F == 3
  
  __magic_name__		       =				dijkstra(Ga, '''E''', '''F''')
  print(short_distance)  # E -- 2 --> G -- 1 --> F == 3
  
  if __name__ == "__main__":
  			import doctest
  
  			doctest.testmod()
  
  
  
  
  