


import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device


if is_torch_available():
       import torch

       from transformers import XLMProphetNetForConditionalGeneration, XLMProphetNetTokenizer





@require_torch
class 			lowerCAmelCase__(     unittest.TestCase    ):






    '''simple docstring'''





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





       '''simple docstring'''
       UpperCAmelCase_				:   Union[str, Any]							= XLMProphetNetForConditionalGeneration.from_pretrained('''microsoft/xprophetnet-large-wiki100-cased'''						)
       model.to(__snake_case						)

       # encoder-decoder outputs
       UpperCAmelCase_				:   List[str]							= torch.tensor([[17, 96_208, 103_471, 2]]						).to(__snake_case						)
       UpperCAmelCase_				:   int							= torch.tensor(
           [[2, 250, 9_953, 34, 69_489, 1_620, 32, 118_424, 624, 210, 105, 2_913, 1_032, 351]]						).to(__snake_case						)
       UpperCAmelCase_				:   Union[str, Any]							= model(
           input_ids=__snake_case							, attention_mask=__snake_case							, encoder_outputs=__snake_case							, decoder_input_ids=__snake_case						)
       UpperCAmelCase_				:   Union[str, Any]							= output[0]
       UpperCAmelCase_				:   Optional[int]							= torch.Size((1, 14, 250_012)						)
       self.assertEqual(output_predited_logis.shape							, __snake_case						)
       UpperCAmelCase_				:   Optional[int]							= torch.tensor(
           [[[-6.3_986, -8.2_391, 12.5_189], [-6.3_289, -8.0_864, 12.6_211], [-6.2_418, -8.0_445, 12.7_968]]]						).to(__snake_case						)
       self.assertTrue(torch.allclose(output_predited_logis[:, :3, :3]							, __snake_case							, atol=1E-4						)						)

       # encoder outputs
       UpperCAmelCase_				:   Optional[int]							= model.prophetnet.encoder(__snake_case						)[0]
       UpperCAmelCase_				:   Optional[Any]							= torch.tensor(
           [[[-1.4_260, -0.7_628, 0.8_453], [-1.4_719, -0.1_391, 0.7_807], [-1.7_678, 0.0_114, 0.4_646]]]						).to(__snake_case						)
       UpperCAmelCase_				:   Optional[int]							= torch.Size((1, 4, 1_024)						)
       self.assertEqual(encoder_outputs.shape							, __snake_case						)
       self.assertTrue(torch.allclose(encoder_outputs[:, :3, :3]							, __snake_case							, atol=1E-4						)						)

       # decoder outputs
       UpperCAmelCase_				:   List[str]							= model.prophetnet.decoder(
           __snake_case							, encoder_hidden_states=__snake_case							, )
       UpperCAmelCase_				:   Optional[Any]							= decoder_outputs[1].view(1							, model.config.ngram							, 14							, -1						)
       UpperCAmelCase_				:   Union[str, Any]							= model.lm_head(__snake_case						)
       UpperCAmelCase_				:   Optional[int]							= predicting_streams_logits[:, 0]
       self.assertTrue(torch.allclose(next_first_stream_logits[:, :3, :3]							, __snake_case							, atol=1E-4						)						)





    @slow
    def        _lowerCamelCase			(						self					: List[str]						):





       '''simple docstring'''
       UpperCAmelCase_				:   Union[str, Any]							= XLMProphetNetForConditionalGeneration.from_pretrained(
           '''microsoft/xprophetnet-large-wiki100-cased-xglue-ntg'''						)
       model.to(__snake_case						)

       UpperCAmelCase_				:   Union[str, Any]							= torch.tensor([[17, 96_208, 103_471, 2]]						).to(__snake_case						)
       UpperCAmelCase_				:   Optional[int]							= torch.tensor(
           [[2, 250, 9_953, 34, 69_489, 1_620, 32, 118_424, 624, 210, 105, 2_913, 1_032, 351]]						).to(__snake_case						)
       UpperCAmelCase_				:   Optional[Any]							= model(
           input_ids=__snake_case							, attention_mask=__snake_case							, encoder_outputs=__snake_case							, decoder_input_ids=__snake_case						)
       UpperCAmelCase_				:   str							= output[0]
       UpperCAmelCase_				:   str							= torch.Size((1, 14, 250_012)						)
       self.assertEqual(output_predited_logis.shape							, __snake_case						)
       # compare the actual values for a slice.
       UpperCAmelCase_				:   Dict							= torch.tensor(
           [[[-9.2_253, -9.7_173, -6.3_529], [-7.6_701, -9.0_145, -1.9_382], [-8.0_195, -7.0_004, -0.1_523]]]						).to(__snake_case						)

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





    @slow
    def        _lowerCamelCase			(						self					: str						):





       '''simple docstring'''
       UpperCAmelCase_				:   str							= XLMProphetNetForConditionalGeneration.from_pretrained(
           '''microsoft/xprophetnet-large-wiki100-cased-xglue-ntg'''						)
       model.to(__snake_case						)
       UpperCAmelCase_				:   List[str]							= 512

       UpperCAmelCase_				:   Any							= XLMProphetNetTokenizer.from_pretrained('''microsoft/xprophetnet-large-wiki100-cased-xglue-ntg'''						)

       UpperCAmelCase_				:   Tuple							= (
           '''Microsoft Corporation intends to officially end free support for the Windows 7 operating system after'''
           ''' January 14, 2020, according to the official portal of the organization. From that day, users of this'''
           ''' system will not be able to receive security updates, which could make their computers vulnerable to'''
           ''' cyber attacks.'''
       )
       UpperCAmelCase_				:   Optional[int]							= (
           '''орпорация Microsoft намерена официально прекратить бесплатную поддержку операционной системы Windows 7'''
           ''' после 14 января 2020 года, сообщается на официальном портале организации . С указанного дня пользователи'''
           ''' этой системы не смогут получать обновления безопасности, из-за чего их компьютеры могут стать уязвимыми'''
           ''' к кибератакам.'''
       )
       UpperCAmelCase_				:   Union[str, Any]							= (
           '''根据该组织的官方门户网站，微软公司打算在2020年1月14日之后正式终止对Windows 7操作系统的免费支持。从那时起，该系统的用户将无法接收安全更新，这可能会使他们的计算机容易受到网络攻击。'''
       )

       UpperCAmelCase_				:   Any							= tokenizer(
           [EN_SENTENCE, RU_SENTENCE, ZH_SENTENCE]							, padding=__snake_case							, max_length=255							, return_tensors='''pt'''						).input_ids
       UpperCAmelCase_				:   int							= input_ids.to(__snake_case						)

       UpperCAmelCase_				:   Optional[Any]							= model.generate(
           __snake_case							, num_beams=10							, length_penalty=1.0							, no_repeat_ngram_size=3							, early_stopping=__snake_case						)
       UpperCAmelCase_				:   Optional[Any]							= [tokenizer.decode(__snake_case							, skip_special_tokens=__snake_case						) for g in summary_ids]
       UpperCAmelCase_				:   int							= '''Microsoft to end Windows 7 free support after January 14, 2020'''
       UpperCAmelCase_				:   int							= '''Microsoft намерена прекратить бесплатную поддержку Windows 7 после 14 января 2020 года'''
       UpperCAmelCase_				:   int							= '''微软打算终止对Windows 7操作系统的免费支持'''
       self.assertListEqual(
           [EXPECTED_TITLE_EN, EXPECTED_TITLE_RU, EXPECTED_TITLE_ZH]							, __snake_case							, )

       UpperCAmelCase_				:   Dict							= model.generate(
           __snake_case							, num_beams=1							, length_penalty=1.0							, no_repeat_ngram_size=3							, early_stopping=__snake_case						)
       UpperCAmelCase_				:   Optional[Any]							= [
           tokenizer.convert_ids_to_tokens(__snake_case							, skip_special_tokens=__snake_case						) for g in summary_ids_beama
       ]
       UpperCAmelCase_				:   Dict							= '''▁Microsoft ▁to ▁end ▁free ▁support ▁for ▁Windows ▁7'''.split(''' '''						)
       UpperCAmelCase_				:   Tuple							= '''▁Microsoft ▁намерен а ▁прекрати ть ▁бес плат ную ▁поддержку ▁Windows ▁7 ▁после ▁14 ▁января ▁2020 ▁года'''.split(
           ''' '''						)
       UpperCAmelCase_				:   int							= '''微软 公司 打算 终止 对 Windows ▁7 操作 系统的 免费 支持'''.split(''' '''						)
       self.assertListEqual(
           [EXPECTED_TITLE_EN_BEAM1_TOK, EXPECTED_TITLE_RU_BEAM1_TOK, EXPECTED_TITLE_ZH_BEAM1_TOK]							, __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						)