


import unittest

from transformers import (
    MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
    TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
    SummarizationPipeline,
    TFPreTrainedModel,
    pipeline,
)
from transformers.testing_utils import get_gpu_count, is_pipeline_test, require_tf, require_torch, slow, torch_device
from transformers.tokenization_utils import TruncationStrategy

from .test_pipelines_common import ANY


__UpperCamelCase					:	Union[str, Any]          =				-1 if torch_device == 'cpu' else 0





@is_pipeline_test
class 			lowerCAmelCase__(     unittest.TestCase    ):






    '''simple docstring'''





    A_	:  Optional[int]								=			MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
    A_	:  Union[str, Any]								=			TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING





    def        _lowerCamelCase			(						self					: str							, __snake_case					: Optional[Any]							, __snake_case					: Optional[Any]							, __snake_case					: List[Any]						):





       '''simple docstring'''
       UpperCAmelCase_				:   int							= SummarizationPipeline(model=__snake_case							, tokenizer=__snake_case						)
       return summarizer, ["(CNN)The Palestinian Authority officially became", "Some other text"]





    def        _lowerCamelCase			(						self					: Any							, __snake_case					: List[Any]							, __snake_case					: Any						):





       '''simple docstring'''
       UpperCAmelCase_				:   List[str]							= summarizer.model

       UpperCAmelCase_				:   List[str]							= summarizer('''(CNN)The Palestinian Authority officially became'''						)
       self.assertEqual(__snake_case							, [{'''summary_text''': ANY(__snake_case						)}]						)

       UpperCAmelCase_				:   Optional[Any]							= summarizer(
           '''(CNN)The Palestinian Authority officially became '''							, num_beams=2							, min_length=2							, max_length=5							, )
       self.assertEqual(__snake_case							, [{'''summary_text''': ANY(__snake_case						)}]						)

       # Some models (Switch Transformers, LED, T5, LongT5, etc) can handle long sequences.
       UpperCAmelCase_				:   str							= [
           '''SwitchTransformersConfig''',
           '''T5Config''',
           '''LongT5Config''',
           '''LEDConfig''',
           '''PegasusXConfig''',
           '''FSMTConfig''',
           '''M2M100Config''',
           '''ProphetNetConfig''',  # positional embeddings up to a fixed maximum size (otherwise clamping the values)
       ]
       if model.config.__class__.__name__ not in model_can_handle_longer_seq:
          # Too long and exception is expected.
          # For TF models, if the weights are initialized in GPU context, we won't get expected index error from
          # the embedding layer.
          if not (
              isinstance(__snake_case							, __snake_case						)
              and get_gpu_count() > 0
              and len(summarizer.model.trainable_weights						) > 0
          ):
             with self.assertRaises(__snake_case						):
                UpperCAmelCase_				:   Dict							= summarizer('''This ''' * 1_000						)
       UpperCAmelCase_				:   int							= summarizer('''This ''' * 1_000							, truncation=TruncationStrategy.ONLY_FIRST						)





    @require_torch
    def        _lowerCamelCase			(						self					: Dict						):





       '''simple docstring'''
       UpperCAmelCase_				:   Tuple							= pipeline(task='''summarization'''							, model='''sshleifer/tiny-mbart'''							, framework='''pt'''						)
       UpperCAmelCase_				:   Union[str, Any]							= summarizer('''This is a small test'''						)
       self.assertEqual(
           __snake_case							, [
               {
                   '''summary_text''': '''เข้าไปเข้าไปเข้าไปเข้าไปเข้าไปเข้าไปเข้าไปเข้าไปเข้าไปเข้าไปเข้าไปเข้าไปเข้าไปเข้าไปเข้าไปเข้าไปเข้าไปเข้าไป'''
               }
           ]							, )





    @require_tf
    def        _lowerCamelCase			(						self					: Any						):





       '''simple docstring'''
       UpperCAmelCase_				:   Tuple							= pipeline(task='''summarization'''							, model='''sshleifer/tiny-mbart'''							, framework='''tf'''						)
       UpperCAmelCase_				:   str							= summarizer('''This is a small test'''						)
       self.assertEqual(
           __snake_case							, [
               {
                   '''summary_text''': '''เข้าไปเข้าไปเข้าไปเข้าไปเข้าไปเข้าไปเข้าไปเข้าไปเข้าไปเข้าไปเข้าไปเข้าไปเข้าไปเข้าไปเข้าไปเข้าไปเข้าไปเข้าไป'''
               }
           ]							, )





    @require_torch
    @slow
    def        _lowerCamelCase			(						self					: Dict						):





       '''simple docstring'''
       UpperCAmelCase_				:   int							= pipeline(task='''summarization'''							, device=__snake_case						)
       UpperCAmelCase_				:   Any							= (
           ''' (CNN)The Palestinian Authority officially became the 123rd member of the International Criminal Court on'''
           ''' Wednesday, a step that gives the court jurisdiction over alleged crimes in Palestinian territories. The'''
           ''' formal accession was marked with a ceremony at The Hague, in the Netherlands, where the court is based.'''
           ''' The Palestinians signed the ICC\'s founding Rome Statute in January, when they also accepted its'''
           ''' jurisdiction over alleged crimes committed "in the occupied Palestinian territory, including East'''
           ''' Jerusalem, since June 13, 2014." Later that month, the ICC opened a preliminary examination into the'''
           ''' situation in Palestinian territories, paving the way for possible war crimes investigations against'''
           ''' Israelis. As members of the court, Palestinians may be subject to counter-charges as well. Israel and'''
           ''' the United States, neither of which is an ICC member, opposed the Palestinians\' efforts to join the'''
           ''' body. But Palestinian Foreign Minister Riad al-Malki, speaking at Wednesday\'s ceremony, said it was a'''
           ''' move toward greater justice. "As Palestine formally becomes a State Party to the Rome Statute today, the'''
           ''' world is also a step closer to ending a long era of impunity and injustice," he said, according to an'''
           ''' ICC news release. "Indeed, today brings us closer to our shared goals of justice and peace." Judge'''
           ''' Kuniko Ozaki, a vice president of the ICC, said acceding to the treaty was just the first step for the'''
           ''' Palestinians. "As the Rome Statute today enters into force for the State of Palestine, Palestine'''
           ''' acquires all the rights as well as responsibilities that come with being a State Party to the Statute.'''
           ''' These are substantive commitments, which cannot be taken lightly," she said. Rights group Human Rights'''
           ''' Watch welcomed the development. "Governments seeking to penalize Palestine for joining the ICC should'''
           ''' immediately end their pressure, and countries that support universal acceptance of the court\'s treaty'''
           ''' should speak out to welcome its membership," said Balkees Jarrah, international justice counsel for the'''
           ''' group. \"What\'s objectionable is the attempts to undermine international justice, not Palestine\'s'''
           ''' decision to join a treaty to which over 100 countries around the world are members." In January, when'''
           ''' the preliminary ICC examination was opened, Israeli Prime Minister Benjamin Netanyahu described it as an'''
           ''' outrage, saying the court was overstepping its boundaries. The United States also said it "strongly"'''
           ''' disagreed with the court\'s decision. \"As we have said repeatedly, we do not believe that Palestine is a'''
           ''' state and therefore we do not believe that it is eligible to join the ICC," the State Department said in'''
           ''' a statement. It urged the warring sides to resolve their differences through direct negotiations. "We'''
           ''' will continue to oppose actions against Israel at the ICC as counterproductive to the cause of peace,"'''
           ''' it said. But the ICC begs to differ with the definition of a state for its purposes and refers to the'''
           ''' territories as "Palestine." While a preliminary examination is not a formal investigation, it allows the'''
           ''' court to review evidence and determine whether to investigate suspects on both sides. Prosecutor Fatou'''
           ''' Bensouda said her office would "conduct its analysis in full independence and impartiality." The war'''
           ''' between Israel and Hamas militants in Gaza last summer left more than 2,000 people dead. The inquiry'''
           ''' will include alleged war crimes committed since June. The International Criminal Court was set up in'''
           ''' 2002 to prosecute genocide, crimes against humanity and war crimes. CNN\'s Vasco Cotovio, Kareem Khadder'''
           ''' and Faith Karimi contributed to this report.'''
       )
       UpperCAmelCase_				:   Optional[int]							= (
           ''' The Palestinian Authority becomes the 123rd member of the International Criminal Court . The move gives'''
           ''' the court jurisdiction over alleged crimes in Palestinian territories . Israel and the United States'''
           ''' opposed the Palestinians\' efforts to join the court . Rights group Human Rights Watch welcomes the move,'''
           ''' says governments seeking to penalize Palestine should end pressure .'''
       )
       UpperCAmelCase_				:   Optional[Any]							= summarizer(__snake_case						)
       self.assertEqual(result[0]['''summary_text''']							, __snake_case						)



import inspect
import unittest

from transformers import DataaVecVisionConfig
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_torch_multi_gpu, 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, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
       import torch
       from torch import nn

       from transformers import (
           MODEL_MAPPING,
           DataaVecVisionForImageClassification,
           DataaVecVisionForSemanticSegmentation,
           DataaVecVisionModel,
       )
       from transformers.models.dataavec.modeling_dataavec_vision import DATA2VEC_VISION_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
       from PIL import Image

       from transformers import BeitImageProcessor





class 			lowerCAmelCase__:






    '''simple docstring'''





    def __init__(						self					: int							, __snake_case					: Any							, __snake_case					: Optional[int]=100							, __snake_case					: Any=13							, __snake_case					: str=30							, __snake_case					: Any=2							, __snake_case					: Tuple=3							, __snake_case					: Tuple=True							, __snake_case					: Tuple=True							, __snake_case					: int=32							, __snake_case					: Dict=4							, __snake_case					: Optional[int]=4							, __snake_case					: List[str]=37							, __snake_case					: str="gelu"							, __snake_case					: Any=0.1							, __snake_case					: Optional[Any]=0.1							, __snake_case					: List[str]=10							, __snake_case					: Tuple=0.02							, __snake_case					: List[str]=3							, __snake_case					: Dict=None							, __snake_case					: Optional[Any]=[0, 1, 2, 3]							, ):





       '''simple docstring'''
       UpperCAmelCase_				:   Union[str, Any]							= parent
       UpperCAmelCase_				:   str							= 100
       UpperCAmelCase_				:   Dict							= batch_size
       UpperCAmelCase_				:   Union[str, Any]							= image_size
       UpperCAmelCase_				:   str							= patch_size
       UpperCAmelCase_				:   List[str]							= num_channels
       UpperCAmelCase_				:   Union[str, Any]							= is_training
       UpperCAmelCase_				:   Tuple							= use_labels
       UpperCAmelCase_				:   List[Any]							= hidden_size
       UpperCAmelCase_				:   Optional[int]							= num_hidden_layers
       UpperCAmelCase_				:   Tuple							= num_attention_heads
       UpperCAmelCase_				:   Optional[Any]							= intermediate_size
       UpperCAmelCase_				:   Union[str, Any]							= hidden_act
       UpperCAmelCase_				:   int							= hidden_dropout_prob
       UpperCAmelCase_				:   Any							= attention_probs_dropout_prob
       UpperCAmelCase_				:   List[str]							= type_sequence_label_size
       UpperCAmelCase_				:   Tuple							= initializer_range
       UpperCAmelCase_				:   Optional[int]							= scope
       UpperCAmelCase_				:   List[str]							= out_indices
       UpperCAmelCase_				:   List[str]							= num_labels

       # in BeiT, the seq length equals the number of patches + 1 (we add 1 for the [CLS] token)
       UpperCAmelCase_				:   List[Any]							= (image_size // patch_size) ** 2
       UpperCAmelCase_				:   Optional[int]							= num_patches + 1





    def        _lowerCamelCase			(						self					: List[str]						):





       '''simple docstring'''
       UpperCAmelCase_				:   List[str]							= floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

       UpperCAmelCase_				:   Tuple							= None
       UpperCAmelCase_				:   Dict							= None
       if self.use_labels:
          UpperCAmelCase_				:   Tuple							= ids_tensor([self.batch_size]							, self.type_sequence_label_size						)
          UpperCAmelCase_				:   Any							= ids_tensor([self.batch_size, self.image_size, self.image_size]							, self.num_labels						)

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

       return config, pixel_values, labels, pixel_labels





    def        _lowerCamelCase			(						self					: Any						):





       '''simple docstring'''
       return DataaVecVisionConfig(
           vocab_size=self.vocab_size							, 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=__snake_case							, initializer_range=self.initializer_range							, out_indices=self.out_indices							, )





    def        _lowerCamelCase			(						self					: Tuple							, __snake_case					: Dict							, __snake_case					: Union[str, Any]							, __snake_case					: str							, __snake_case					: Optional[int]						):





       '''simple docstring'''
       UpperCAmelCase_				:   Optional[Any]							= DataaVecVisionModel(config=__snake_case						)
       model.to(__snake_case						)
       model.eval()
       UpperCAmelCase_				:   Any							= model(__snake_case						)
       # expected sequence length = num_patches + 1 (we add 1 for the [CLS] token)
       UpperCAmelCase_				:   int							= (self.image_size // self.patch_size) ** 2
       self.parent.assertEqual(result.last_hidden_state.shape							, (self.batch_size, num_patches + 1, self.hidden_size)						)





    def        _lowerCamelCase			(						self					: Any							, __snake_case					: str							, __snake_case					: Union[str, Any]							, __snake_case					: Optional[int]							, __snake_case					: Any						):





       '''simple docstring'''
       UpperCAmelCase_				:   Optional[int]							= self.type_sequence_label_size
       UpperCAmelCase_				:   Tuple							= DataaVecVisionForImageClassification(__snake_case						)
       model.to(__snake_case						)
       model.eval()
       UpperCAmelCase_				:   int							= model(__snake_case							, labels=__snake_case						)
       self.parent.assertEqual(result.logits.shape							, (self.batch_size, self.type_sequence_label_size)						)





    def        _lowerCamelCase			(						self					: Union[str, Any]							, __snake_case					: Any							, __snake_case					: Optional[Any]							, __snake_case					: Any							, __snake_case					: Dict						):





       '''simple docstring'''
       UpperCAmelCase_				:   List[Any]							= self.num_labels
       UpperCAmelCase_				:   Dict							= DataaVecVisionForSemanticSegmentation(__snake_case						)
       model.to(__snake_case						)
       model.eval()
       UpperCAmelCase_				:   str							= model(__snake_case						)
       self.parent.assertEqual(
           result.logits.shape							, (self.batch_size, self.num_labels, self.image_size * 2, self.image_size * 2)						)
       UpperCAmelCase_				:   Any							= model(__snake_case							, labels=__snake_case						)
       self.parent.assertEqual(
           result.logits.shape							, (self.batch_size, self.num_labels, self.image_size * 2, self.image_size * 2)						)





    def        _lowerCamelCase			(						self					: Tuple						):





       '''simple docstring'''
       UpperCAmelCase_				:   Optional[Any]							= self.prepare_config_and_inputs()
       UpperCAmelCase_		,   UpperCAmelCase_		,   UpperCAmelCase_		,   UpperCAmelCase_				:   Dict							= config_and_inputs
       UpperCAmelCase_				:   Optional[Any]							= {'''pixel_values''': pixel_values}
       return config, inputs_dict





@require_torch
class 			lowerCAmelCase__(     snake_case__     ,     snake_case__     ,     unittest.TestCase    ):






    '''simple docstring'''





    A_	:  str								=			(
        (DataaVecVisionModel, DataaVecVisionForImageClassification, DataaVecVisionForSemanticSegmentation)
        if is_torch_available()
        else ()
    )
    A_	:  int								=			(
        {
            'feature-extraction': DataaVecVisionModel,
            'image-classification': DataaVecVisionForImageClassification,
            'image-segmentation': DataaVecVisionForSemanticSegmentation,
        }
        if is_torch_available()
        else {}
    )

    A_	:  Tuple								=			False
    A_	:  int								=			False
    A_	:  List[str]								=			False





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





       '''simple docstring'''
       UpperCAmelCase_				:   List[Any]							= DataaVecVisionModelTester(self						)
       UpperCAmelCase_				:   Dict							= ConfigTester(
           self							, config_class=__snake_case							, has_text_modality=__snake_case							, hidden_size=37						)





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





       '''simple docstring'''
       self.config_tester.run_common_tests()





    def        _lowerCamelCase			(						self					: Optional[Any]						):





       '''simple docstring'''
       # Data2VecVision does not use inputs_embeds
       pass





    @require_torch_multi_gpu
    @unittest.skip(
        reason='''Data2VecVision has some layers using `add_module` which doesn\'t work well with `nn.DataParallel`'''						)
    def        _lowerCamelCase			(						self					: Optional[Any]						):





       '''simple docstring'''
       pass





    def        _lowerCamelCase			(						self					: Any						):





       '''simple docstring'''
       UpperCAmelCase_		,   UpperCAmelCase_				:   int							= self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
          UpperCAmelCase_				:   Tuple							= model_class(__snake_case						)
          self.assertIsInstance(model.get_input_embeddings()							, (nn.Module)						)
          UpperCAmelCase_				:   int							= model.get_output_embeddings()
          self.assertTrue(x is None or isinstance(__snake_case							, nn.Linear						)						)





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





       '''simple docstring'''
       UpperCAmelCase_		,   UpperCAmelCase_				:   Dict							= self.model_tester.prepare_config_and_inputs_for_common()

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

          UpperCAmelCase_				:   List[Any]							= ['''pixel_values''']
          self.assertListEqual(arg_names[:1]							, __snake_case						)





    def        _lowerCamelCase			(						self					: Optional[Any]						):





       '''simple docstring'''
       UpperCAmelCase_				:   Dict							= self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*__snake_case						)





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





       '''simple docstring'''
       UpperCAmelCase_				:   Dict							= self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_image_segmentation(*__snake_case						)





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





       '''simple docstring'''
       if not self.model_tester.is_training:
          return

       UpperCAmelCase_		,   UpperCAmelCase_				:   Tuple							= self.model_tester.prepare_config_and_inputs_for_common()
       UpperCAmelCase_				:   List[str]							= True

       for model_class in self.all_model_classes:
          if model_class in [*get_values(__snake_case						)]:
             continue

          UpperCAmelCase_				:   Union[str, Any]							= model_class(__snake_case						)
          model.to(__snake_case						)
          model.train()
          UpperCAmelCase_				:   List[Any]							= self._prepare_for_class(__snake_case							, __snake_case							, return_labels=__snake_case						)
          UpperCAmelCase_				:   Any							= model(**__snake_case						).loss
          loss.backward()





    def        _lowerCamelCase			(						self					: int						):





       '''simple docstring'''
       UpperCAmelCase_		,   UpperCAmelCase_				:   Dict							= self.model_tester.prepare_config_and_inputs_for_common()
       if not self.model_tester.is_training:
          return

       UpperCAmelCase_				:   str							= False
       UpperCAmelCase_				:   Union[str, Any]							= True

       for model_class in self.all_model_classes:
          if model_class in [*get_values(__snake_case						)] or not model_class.supports_gradient_checkpointing:
             continue
          # TODO: remove the following 3 lines once we have a MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING
          # this can then be incorporated into _prepare_for_class in test_modeling_common.py
          elif model_class.__name__ == "Data2VecVisionForSemanticSegmentation":
             UpperCAmelCase_		,   UpperCAmelCase_		,   UpperCAmelCase_		,   UpperCAmelCase_				:   Any							= inputs_dict['''pixel_values'''].shape
             UpperCAmelCase_				:   Optional[int]							= torch.zeros(
                 [self.model_tester.batch_size, height, width]							, device=__snake_case						).long()
          UpperCAmelCase_				:   Union[str, Any]							= model_class(__snake_case						)
          model.gradient_checkpointing_enable()
          model.to(__snake_case						)
          model.train()
          UpperCAmelCase_				:   Union[str, Any]							= self._prepare_for_class(__snake_case							, __snake_case							, return_labels=__snake_case						)
          UpperCAmelCase_				:   List[str]							= model(**__snake_case						).loss
          loss.backward()





    def        _lowerCamelCase			(						self					: List[Any]						):





       '''simple docstring'''
       UpperCAmelCase_		,   UpperCAmelCase_				:   List[str]							= self.model_tester.prepare_config_and_inputs_for_common()

       UpperCAmelCase_				:   List[Any]							= _config_zero_init(__snake_case						)
       for model_class in self.all_model_classes:
          UpperCAmelCase_				:   Optional[int]							= model_class(config=__snake_case						)
          for name, param in model.named_parameters():
             # we skip lambda parameters as these require special initial values
             # determined by config.layer_scale_init_value
             if "lambda" in name:
                continue
             if param.requires_grad:
                self.assertIn(
                    ((param.data.mean() * 1E9).round() / 1E9).item()							, [0.0, 1.0]							, msg=f'''Parameter {name} of model {model_class} seems not properly initialized'''							, )





    def        _lowerCamelCase			(						self					: Any							, __snake_case					: Any							, __snake_case					: Dict							, __snake_case					: Dict							, __snake_case					: int=2E-4							, __snake_case					: Optional[Any]="outputs"							, __snake_case					: Tuple=None						):





       '''simple docstring'''
       # We override with a slightly higher tol value, as semseg models tend to diverge a bit more
       super().check_pt_tf_outputs(__snake_case							, __snake_case							, __snake_case							, __snake_case							, __snake_case							, __snake_case						)





    def        _lowerCamelCase			(						self					: Tuple						):





       '''simple docstring'''
       UpperCAmelCase_				:   List[str]							= self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_image_classification(*__snake_case						)





    @slow
    def        _lowerCamelCase			(						self					: Optional[Any]						):





       '''simple docstring'''
       for model_name in DATA2VEC_VISION_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
          UpperCAmelCase_				:   Optional[int]							= DataaVecVisionModel.from_pretrained(__snake_case						)
          self.assertIsNotNone(__snake_case						)





def   snake_case_    (			):
   UpperCAmelCase_				:   Tuple							= Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''							)
   return image





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






    '''simple docstring'''





    @cached_property
    def        _lowerCamelCase			(						self					: Optional[Any]						):





       '''simple docstring'''
       return (
           BeitImageProcessor.from_pretrained('''facebook/data2vec-vision-base-ft1k'''						) if is_vision_available() else None
       )





    @slow
    def        _lowerCamelCase			(						self					: int						):





       '''simple docstring'''
       UpperCAmelCase_				:   int							= DataaVecVisionForImageClassification.from_pretrained('''facebook/data2vec-vision-base-ft1k'''						).to(
           __snake_case						)

       UpperCAmelCase_				:   Optional[Any]							= self.default_image_processor
       UpperCAmelCase_				:   int							= prepare_img()
       UpperCAmelCase_				:   Optional[int]							= image_processor(images=__snake_case							, return_tensors='''pt'''						).to(__snake_case						)

       # forward pass
       with torch.no_grad():
          UpperCAmelCase_				:   int							= model(**__snake_case						)
       UpperCAmelCase_				:   Optional[int]							= outputs.logits

       # verify the logits
       UpperCAmelCase_				:   List[str]							= torch.Size((1, 1_000)						)
       self.assertEqual(logits.shape							, __snake_case						)

       UpperCAmelCase_				:   Optional[Any]							= torch.tensor([0.3_277, -0.1_395, 0.0_911]						).to(__snake_case						)

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

       UpperCAmelCase_				:   List[Any]							= [model.config.labelaid[i] for i in ['''remote control, remote''', '''tabby, tabby cat''']]
       self.assertEqual(logits[0].topk(2						).indices.cpu().tolist()							, __snake_case						)