code: 
  
  
  
  
  
  
  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     __a						:
  
  
  
  
  
  
  
   def __init__(	self      :     int							,     SCREAMING_SNAKE_CASE      :     str							,     SCREAMING_SNAKE_CASE      :     int = 13							,     SCREAMING_SNAKE_CASE      :     int = 64							,     SCREAMING_SNAKE_CASE      :     int = 2							,     SCREAMING_SNAKE_CASE      :     int = 3							,     SCREAMING_SNAKE_CASE      :     int = 3							,     SCREAMING_SNAKE_CASE      :     bool = True							,     SCREAMING_SNAKE_CASE      :     bool = True							,     SCREAMING_SNAKE_CASE      :     int = 1_28							,     SCREAMING_SNAKE_CASE      :     str=[16, 32, 64, 1_28]							,     SCREAMING_SNAKE_CASE      :     int = 7							,     SCREAMING_SNAKE_CASE      :     int = 4							,     SCREAMING_SNAKE_CASE      :     int = 37							,     SCREAMING_SNAKE_CASE      :     str = "gelu"							,     SCREAMING_SNAKE_CASE      :     float = 0.1							,     SCREAMING_SNAKE_CASE      :     float = 0.1							,     SCREAMING_SNAKE_CASE      :     int = 10							,     SCREAMING_SNAKE_CASE      :     float = 0.0_2							,     SCREAMING_SNAKE_CASE      :     int = 2							,     SCREAMING_SNAKE_CASE      :     int = 1							,     SCREAMING_SNAKE_CASE      :     int = 1_28							,     SCREAMING_SNAKE_CASE      :     List[int] = [2, 2, 2, 2]							,     SCREAMING_SNAKE_CASE      :     int = 2							,     SCREAMING_SNAKE_CASE      :     int = 2							,     ):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Any        =						parent
        UpperCamelCase__    :     Dict        =						batch_size
        UpperCamelCase__    :     str        =						image_size
        UpperCamelCase__    :     Optional[Any]        =						patch_size
        UpperCamelCase__    :     List[str]        =						num_channels
        UpperCamelCase__    :     str        =						is_training
        UpperCamelCase__    :     List[str]        =						use_labels
        UpperCamelCase__    :     Tuple        =						hidden_size
        UpperCamelCase__    :     Optional[Any]        =						num_hidden_layers
        UpperCamelCase__    :     Optional[int]        =						num_attention_heads
        UpperCamelCase__    :     List[str]        =						intermediate_size
        UpperCamelCase__    :     Union[str, Any]        =						hidden_act
        UpperCamelCase__    :     Optional[int]        =						hidden_dropout_prob
        UpperCamelCase__    :     Optional[int]        =						attention_probs_dropout_prob
        UpperCamelCase__    :     Optional[int]        =						type_sequence_label_size
        UpperCamelCase__    :     Union[str, Any]        =						initializer_range
        UpperCamelCase__    :     Optional[int]        =						encoder_stride
        UpperCamelCase__    :     List[Any]        =						num_attention_outputs
        UpperCamelCase__    :     Dict        =						embed_dim
        UpperCamelCase__    :     int        =						embed_dim + 1
        UpperCamelCase__    :     Any        =						resolution
        UpperCamelCase__    :     int        =						depths
        UpperCamelCase__    :     str        =						hidden_sizes
        UpperCamelCase__    :     Tuple        =						dim
        UpperCamelCase__    :     Optional[int]        =						mlp_expansion_ratio
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Dict		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     List[Any]        =						floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]		)
  
        UpperCamelCase__    :     Any        =						None
        if self.use_labels:
             UpperCamelCase__    :     Dict        =						ids_tensor([self.batch_size]							,     self.type_sequence_label_size		)
  
        UpperCamelCase__    :     int        =						self.get_config()
        return config, pixel_values, labels
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     List[Any]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        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=SCREAMING_SNAKE_CASE							,     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       __lowercase      (	self      :     Optional[int]							,     SCREAMING_SNAKE_CASE      :     Optional[int]							,     SCREAMING_SNAKE_CASE      :     str							,     SCREAMING_SNAKE_CASE      :     Any		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     List[str]        =						EfficientFormerModel(config=SCREAMING_SNAKE_CASE		)
        model.to(SCREAMING_SNAKE_CASE		)
        model.eval()
        UpperCamelCase__    :     Any        =						model(SCREAMING_SNAKE_CASE		)
        self.parent.assertEqual(result.last_hidden_state.shape							,     (self.batch_size, self.seq_length, self.hidden_size)		)
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Union[str, Any]							,     SCREAMING_SNAKE_CASE      :     Optional[Any]							,     SCREAMING_SNAKE_CASE      :     List[str]							,     SCREAMING_SNAKE_CASE      :     Optional[int]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     int        =						self.type_sequence_label_size
        UpperCamelCase__    :     Optional[Any]        =						EfficientFormerForImageClassification(SCREAMING_SNAKE_CASE		)
        model.to(SCREAMING_SNAKE_CASE		)
        model.eval()
        UpperCamelCase__    :     Dict        =						model(SCREAMING_SNAKE_CASE							,     labels=SCREAMING_SNAKE_CASE		)
        self.parent.assertEqual(result.logits.shape							,     (self.batch_size, self.type_sequence_label_size)		)
  
        # test greyscale images
        UpperCamelCase__    :     str        =						1
        UpperCamelCase__    :     Optional[Any]        =						EfficientFormerForImageClassification(SCREAMING_SNAKE_CASE		)
        model.to(SCREAMING_SNAKE_CASE		)
        model.eval()
  
        UpperCamelCase__    :     Tuple        =						floats_tensor([self.batch_size, 1, self.image_size, self.image_size]		)
        UpperCamelCase__    :     Tuple        =						model(SCREAMING_SNAKE_CASE		)
        self.parent.assertEqual(result.logits.shape							,     (self.batch_size, self.type_sequence_label_size)		)
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     List[Any]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Any        =						self.prepare_config_and_inputs()
        (
            UpperCamelCase__  
        )    :     Union[str, Any]        =						config_and_inputs
        UpperCamelCase__    :     Tuple        =						{"pixel_values": pixel_values}
        return config, inputs_dict
  
  
  
  
  
  
  
  @require_torch
  class     __a						(					A__ ,     A__ ,     unittest.TestCase ):
   _lowerCAmelCase : Optional[int] 				=				(
       (
           EfficientFormerModel,
           EfficientFormerForImageClassificationWithTeacher,
           EfficientFormerForImageClassification,
       )
       if is_torch_available()
       else ()
   )
   _lowerCAmelCase : Optional[int] 				=				(
       {
           '''feature-extraction''': EfficientFormerModel,
           '''image-classification''': (
               EfficientFormerForImageClassification,
               EfficientFormerForImageClassificationWithTeacher,
           ),
       }
       if is_torch_available()
       else {}
   )
   _lowerCAmelCase : int 				=				False
  
   _lowerCAmelCase : Union[str, Any] 				=				False
   _lowerCAmelCase : List[str] 				=				False
   _lowerCAmelCase : Optional[Any] 				=				False
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Any		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Any        =						EfficientFormerModelTester(self		)
        UpperCamelCase__    :     int        =						ConfigTester(
            self							,     config_class=SCREAMING_SNAKE_CASE							,     has_text_modality=SCREAMING_SNAKE_CASE							,     hidden_size=37		)
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Dict		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        self.config_tester.run_common_tests()
  
  
  
  
  
  
  
   @unittest.skip(reason="EfficientFormer does not use inputs_embeds"		)
   def       __lowercase      (	self      :     Optional[Any]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        pass
  
  
  
  
  
  
  
   @unittest.skip(reason="EfficientFormer does not support input and output embeddings"		)
   def       __lowercase      (	self      :     List[str]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        pass
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Union[str, Any]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Optional[Any]        =						self.model_tester.prepare_config_and_inputs_for_common()
  
        for model_class in self.all_model_classes:
             UpperCamelCase__    :     Optional[Any]        =						model_class(SCREAMING_SNAKE_CASE		)
             UpperCamelCase__    :     Union[str, Any]        =						inspect.signature(model.forward		)
             # signature.parameters is an OrderedDict => so arg_names order is deterministic
             UpperCamelCase__    :     Optional[Any]        =						[*signature.parameters.keys()]
  
             UpperCamelCase__    :     List[str]        =						["pixel_values"]
             self.assertListEqual(arg_names[:1]							,     SCREAMING_SNAKE_CASE		)
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     int		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        def check_hidden_states_output(SCREAMING_SNAKE_CASE      :     List[str]							,     SCREAMING_SNAKE_CASE      :     int							,     SCREAMING_SNAKE_CASE      :     Optional[int]		):
             UpperCamelCase__    :     List[Any]        =						model_class(SCREAMING_SNAKE_CASE		)
             model.to(SCREAMING_SNAKE_CASE		)
             model.eval()
  
             with torch.no_grad():
                  UpperCamelCase__    :     Any        =						model(**self._prepare_for_class(SCREAMING_SNAKE_CASE							,     SCREAMING_SNAKE_CASE		)		)
  
             UpperCamelCase__    :     Tuple        =						outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states
  
             UpperCamelCase__    :     List[str]        =						getattr(
                 self.model_tester							,     "expected_num_hidden_layers"							,     self.model_tester.num_hidden_layers + 1		)
             self.assertEqual(len(SCREAMING_SNAKE_CASE		)							,     SCREAMING_SNAKE_CASE		)
  
             if hasattr(self.model_tester							,     "encoder_seq_length"		):
                  UpperCamelCase__    :     Dict        =						self.model_tester.encoder_seq_length
                  if hasattr(self.model_tester							,     "chunk_length"		) and self.model_tester.chunk_length > 1:
                       UpperCamelCase__    :     Dict        =						seq_length * self.model_tester.chunk_length
             else:
                  UpperCamelCase__    :     Dict        =						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__    :     Dict        =						outputs.decoder_hidden_states
  
                  self.assertIsInstance(SCREAMING_SNAKE_CASE							,     (list, tuple)		)
                  self.assertEqual(len(SCREAMING_SNAKE_CASE		)							,     SCREAMING_SNAKE_CASE		)
                  UpperCamelCase__    :     Tuple        =						getattr(self.model_tester							,     "seq_length"							,     SCREAMING_SNAKE_CASE		)
                  UpperCamelCase__    :     Optional[int]        =						getattr(self.model_tester							,     "decoder_seq_length"							,     SCREAMING_SNAKE_CASE		)
  
                  self.assertListEqual(
                      list(hidden_states[-1].shape[-2:]		)							,     [decoder_seq_length, self.model_tester.hidden_size]							,     )
  
        UpperCamelCase__    :     Union[str, Any]        =						self.model_tester.prepare_config_and_inputs_for_common()
  
        for model_class in self.all_model_classes:
             UpperCamelCase__    :     int        =						True
             check_hidden_states_output(SCREAMING_SNAKE_CASE							,     SCREAMING_SNAKE_CASE							,     SCREAMING_SNAKE_CASE		)
  
             # check that output_hidden_states also work using config
             del inputs_dict["output_hidden_states"]
             UpperCamelCase__    :     Dict        =						True
  
             check_hidden_states_output(SCREAMING_SNAKE_CASE							,     SCREAMING_SNAKE_CASE							,     SCREAMING_SNAKE_CASE		)
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Optional[int]							,     SCREAMING_SNAKE_CASE      :     Optional[Any]							,     SCREAMING_SNAKE_CASE      :     Optional[Any]							,     SCREAMING_SNAKE_CASE      :     Union[str, Any]=False		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     str        =						super()._prepare_for_class(SCREAMING_SNAKE_CASE							,     SCREAMING_SNAKE_CASE							,     return_labels=SCREAMING_SNAKE_CASE		)
  
        if return_labels:
             if model_class.__name__ == "EfficientFormerForImageClassificationWithTeacher":
                  del inputs_dict["labels"]
  
        return inputs_dict
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Optional[Any]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Dict        =						self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE		)
  
  
  
  
  
  
  
   @unittest.skip(reason="EfficientFormer does not implement masked image modeling yet"		)
   def       __lowercase      (	self      :     List[str]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     str        =						self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_masked_image_modeling(*SCREAMING_SNAKE_CASE		)
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Any		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     List[Any]        =						self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_image_classification(*SCREAMING_SNAKE_CASE		)
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     List[Any]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        if not self.model_tester.is_training:
             return
  
        UpperCamelCase__    :     str        =						self.model_tester.prepare_config_and_inputs_for_common()
        UpperCamelCase__    :     Dict        =						True
  
        for model_class in self.all_model_classes:
             # EfficientFormerForImageClassificationWithTeacher supports inference-only
             if (
                 model_class in get_values(SCREAMING_SNAKE_CASE		)
                 or model_class.__name__ == "EfficientFormerForImageClassificationWithTeacher"
             ):
                  continue
             UpperCamelCase__    :     int        =						model_class(SCREAMING_SNAKE_CASE		)
             model.to(SCREAMING_SNAKE_CASE		)
             model.train()
             UpperCamelCase__    :     int        =						self._prepare_for_class(SCREAMING_SNAKE_CASE							,     SCREAMING_SNAKE_CASE							,     return_labels=SCREAMING_SNAKE_CASE		)
             UpperCamelCase__    :     Tuple        =						model(**SCREAMING_SNAKE_CASE		).loss
             loss.backward()
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Dict		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     List[str]        =						self.model_tester.prepare_config_and_inputs_for_common()
  
        UpperCamelCase__    :     int        =						[
            {"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(SCREAMING_SNAKE_CASE		),
                 ]
                 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__    :     Any        =						problem_type["title"]
                       UpperCamelCase__    :     List[str]        =						problem_type["num_labels"]
  
                       UpperCamelCase__    :     Union[str, Any]        =						model_class(SCREAMING_SNAKE_CASE		)
                       model.to(SCREAMING_SNAKE_CASE		)
                       model.train()
  
                       UpperCamelCase__    :     Any        =						self._prepare_for_class(SCREAMING_SNAKE_CASE							,     SCREAMING_SNAKE_CASE							,     return_labels=SCREAMING_SNAKE_CASE		)
  
                       if problem_type["num_labels"] > 1:
                            UpperCamelCase__    :     Any        =						inputs["labels"].unsqueeze(1		).repeat(1							,     problem_type["num_labels"]		)
  
                       UpperCamelCase__    :     Optional[Any]        =						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=SCREAMING_SNAKE_CASE		) as warning_list:
                            UpperCamelCase__    :     Dict        =						model(**SCREAMING_SNAKE_CASE		).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       __lowercase      (	self      :     str		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        for model_name in EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             UpperCamelCase__    :     List[Any]        =						EfficientFormerModel.from_pretrained(SCREAMING_SNAKE_CASE		)
             self.assertIsNotNone(SCREAMING_SNAKE_CASE		)
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Union[str, Any]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Optional[Any]        =						self.model_tester.prepare_config_and_inputs_for_common()
        UpperCamelCase__    :     Dict        =						True
  
        UpperCamelCase__    :     Tuple        =						getattr(self.model_tester							,     "seq_length"							,     SCREAMING_SNAKE_CASE		)
        UpperCamelCase__    :     Tuple        =						getattr(self.model_tester							,     "encoder_seq_length"							,     SCREAMING_SNAKE_CASE		)
        UpperCamelCase__    :     Optional[int]        =						getattr(self.model_tester							,     "key_length"							,     SCREAMING_SNAKE_CASE		)
        UpperCamelCase__    :     Union[str, Any]        =						getattr(self.model_tester							,     "chunk_length"							,     SCREAMING_SNAKE_CASE		)
  
        if chunk_length is not None and hasattr(self.model_tester							,     "num_hashes"		):
             UpperCamelCase__    :     List[Any]        =						encoder_seq_length * self.model_tester.num_hashes
  
        for model_class in self.all_model_classes:
             UpperCamelCase__    :     List[Any]        =						True
             UpperCamelCase__    :     List[Any]        =						False
             UpperCamelCase__    :     int        =						True
             UpperCamelCase__    :     List[str]        =						model_class(SCREAMING_SNAKE_CASE		)
             model.to(SCREAMING_SNAKE_CASE		)
             model.eval()
             with torch.no_grad():
                  UpperCamelCase__    :     Any        =						model(**self._prepare_for_class(SCREAMING_SNAKE_CASE							,     SCREAMING_SNAKE_CASE		)		)
             UpperCamelCase__    :     Optional[Any]        =						outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions
             self.assertEqual(len(SCREAMING_SNAKE_CASE		)							,     self.model_tester.num_attention_outputs		)
  
             # check that output_attentions also work using config
             del inputs_dict["output_attentions"]
             UpperCamelCase__    :     List[str]        =						True
             UpperCamelCase__    :     str        =						model_class(SCREAMING_SNAKE_CASE		)
             model.to(SCREAMING_SNAKE_CASE		)
             model.eval()
             with torch.no_grad():
                  UpperCamelCase__    :     Any        =						model(**self._prepare_for_class(SCREAMING_SNAKE_CASE							,     SCREAMING_SNAKE_CASE		)		)
             UpperCamelCase__    :     Optional[int]        =						outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions
             self.assertEqual(len(SCREAMING_SNAKE_CASE		)							,     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 	SCREAMING_SNAKE_CASE							(      )				->			List[Any]:
       UpperCamelCase__    :     str        =						Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"    )
       return image
  
  
  
  
  
  @require_torch
  @require_vision
  class     __a						(					unittest.TestCase ):
  
  
  
  
  
  
  
   @cached_property
   def       __lowercase      (	self      :     Any		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        return (
            EfficientFormerImageProcessor.from_pretrained("snap-research/efficientformer-l1-300"		)
            if is_vision_available()
            else None
        )
  
  
  
  
  
  
  
   @slow
   def       __lowercase      (	self      :     Any		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Tuple        =						EfficientFormerForImageClassification.from_pretrained("snap-research/efficientformer-l1-300"		).to(
            SCREAMING_SNAKE_CASE		)
  
        UpperCamelCase__    :     Any        =						self.default_image_processor
        UpperCamelCase__    :     Optional[int]        =						prepare_img()
        UpperCamelCase__    :     Any        =						image_processor(images=SCREAMING_SNAKE_CASE							,     return_tensors="pt"		).to(SCREAMING_SNAKE_CASE		)
  
        # forward pass
        with torch.no_grad():
             UpperCamelCase__    :     Any        =						model(**SCREAMING_SNAKE_CASE		)
  
        # verify the logits
        UpperCamelCase__    :     List[str]        =						(1, 10_00)
        self.assertEqual(outputs.logits.shape							,     SCREAMING_SNAKE_CASE		)
  
        UpperCamelCase__    :     List[str]        =						torch.tensor([-0.0_5_5_5, 0.4_8_2_5, -0.0_8_5_2]		).to(SCREAMING_SNAKE_CASE		)
        self.assertTrue(torch.allclose(outputs.logits[0][:3]							,     SCREAMING_SNAKE_CASE							,     atol=1e-4		)		)
  
  
  
  
  
  
  
   @slow
   def       __lowercase      (	self      :     List[Any]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Any        =						EfficientFormerForImageClassificationWithTeacher.from_pretrained(
            "snap-research/efficientformer-l1-300"		).to(SCREAMING_SNAKE_CASE		)
  
        UpperCamelCase__    :     str        =						self.default_image_processor
        UpperCamelCase__    :     List[Any]        =						prepare_img()
        UpperCamelCase__    :     Union[str, Any]        =						image_processor(images=SCREAMING_SNAKE_CASE							,     return_tensors="pt"		).to(SCREAMING_SNAKE_CASE		)
  
        # forward pass
        with torch.no_grad():
             UpperCamelCase__    :     int        =						model(**SCREAMING_SNAKE_CASE		)
  
        # verify the logits
        UpperCamelCase__    :     Dict        =						(1, 10_00)
        self.assertEqual(outputs.logits.shape							,     SCREAMING_SNAKE_CASE		)
  
        UpperCamelCase__    :     Any        =						torch.tensor([-0.1_3_1_2, 0.4_3_5_3, -1.0_4_9_9]		).to(SCREAMING_SNAKE_CASE		)
        self.assertTrue(torch.allclose(outputs.logits[0][:3]							,     SCREAMING_SNAKE_CASE							,     atol=1e-4		)		)
style_context: 
  
  
  
  
  
  
  from __future__ import annotations
  
  from collections.abc import Iterator
  from typing import Any
  
  
  
  
  
  class     __a						:
  
  
  
  
  
  
  
   def __init__(	self      :     str							,     SCREAMING_SNAKE_CASE      :     Any		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Any        =						data
        UpperCamelCase__    :     Node | None        =						None
  
  
  
  
  
  
  
   def __str__(	self      :     Union[str, Any]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        return F'{self.data}'
  
  
  
  
  
  
  
  class     __a						:
  
  
  
  
  
  
  
   def __init__(	self      :     Optional[int]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Node | None        =						None
        UpperCamelCase__    :     Node | None        =						None
  
  
  
  
  
  
  
   def __iter__(	self      :     str		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     int        =						self.front
        while node:
             yield node.data
             UpperCamelCase__    :     Any        =						node.next
  
  
  
  
  
  
  
   def __len__(	self      :     Tuple		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        return len(tuple(iter(self		)		)		)
  
  
  
  
  
  
  
   def __str__(	self      :     Union[str, Any]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        return " <- ".join(str(SCREAMING_SNAKE_CASE		) for item in self		)
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     List[str]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        return len(self		) == 0
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Union[str, Any]							,     SCREAMING_SNAKE_CASE      :     Any		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     int        =						Node(SCREAMING_SNAKE_CASE		)
        if self.is_empty():
             UpperCamelCase__    :     int        =						node
        else:
             assert isinstance(self.rear							,     SCREAMING_SNAKE_CASE		)
             UpperCamelCase__    :     Dict        =						node
             UpperCamelCase__    :     str        =						node
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Dict		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        if self.is_empty():
             raise IndexError("dequeue from empty queue"		)
        assert isinstance(self.front							,     SCREAMING_SNAKE_CASE		)
        UpperCamelCase__    :     Optional[int]        =						self.front
        UpperCamelCase__    :     List[str]        =						self.front.next
        if self.front is None:
             UpperCamelCase__    :     List[Any]        =						None
        return node.data
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     str		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Optional[int]        =						None
  
  
  if __name__ == "__main__":
   from doctest import testmod
  
   testmod()