


import unittest

from transformers import DebertaVaTokenizer, DebertaVaTokenizerFast
from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin


SCREAMING_SNAKE_CASE_      =			get_tests_dir('fixtures/spiece.model')


@require_sentencepiece
@require_tokenizers
class  lowerCAmelCase_						(       snake_case__		,    unittest.TestCase      ):





  """simple docstring"""



  a_       :str												=DebertaVaTokenizer
  a_       :Optional[Any]												=DebertaVaTokenizerFast
  a_       :List[Any]												=True
  a_       :Dict												=True

  def __a						(					self     :							Optional[Any]						):





       '''simple docstring'''

       super().setUp()

       # We have a SentencePiece fixture for testing
       __a       =   DebertaVaTokenizer(SCREAMING_SNAKE_CASE__				,							unk_token="""<unk>"""						)
       tokenizer.save_pretrained(self.tmpdirname						)

  def __a						(					self     :							Dict				,							SCREAMING_SNAKE_CASE__     :							int						):





       '''simple docstring'''

       __a       =   """this is a test"""
       __a       =   """this is a test"""
       return input_text, output_text

  def __a						(					self     :							Optional[int]						):





       '''simple docstring'''

       __a       =   """<pad>"""
       __a       =   0

       self.assertEqual(self.get_tokenizer()._convert_token_to_id(SCREAMING_SNAKE_CASE__						)				,							SCREAMING_SNAKE_CASE__						)
       self.assertEqual(self.get_tokenizer()._convert_id_to_token(SCREAMING_SNAKE_CASE__						)				,							SCREAMING_SNAKE_CASE__						)

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





       '''simple docstring'''

       __a       =   list(self.get_tokenizer().get_vocab().keys()						)
       self.assertEqual(vocab_keys[0]				,							"""<pad>"""						)
       self.assertEqual(vocab_keys[1]				,							"""<unk>"""						)
       self.assertEqual(vocab_keys[-1]				,							"""[PAD]"""						)
       self.assertEqual(len(SCREAMING_SNAKE_CASE__						)				,							3_0_0_0_1						)

  def __a						(					self     :							Optional[Any]						):





       '''simple docstring'''

       self.assertEqual(self.get_tokenizer().vocab_size				,							3_0_0_0_0						)

  def __a						(					self     :							Optional[Any]						):





       '''simple docstring'''

       __a       =   """ \tHeLLo!how  \n Are yoU?  """
       __a       =   ["""▁hello""", """!""", """how""", """▁are""", """▁you""", """?"""]
       # fmt: on

       __a       =   DebertaVaTokenizer(SCREAMING_SNAKE_CASE__				,							do_lower_case=SCREAMING_SNAKE_CASE__						)
       __a       =   tokenizer.convert_ids_to_tokens(tokenizer.encode(SCREAMING_SNAKE_CASE__				,							add_special_tokens=SCREAMING_SNAKE_CASE__						)						)

       self.assertListEqual(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__						)

       __a       =   DebertaVaTokenizerFast(SCREAMING_SNAKE_CASE__				,							do_lower_case=SCREAMING_SNAKE_CASE__						)
       __a       =   rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(SCREAMING_SNAKE_CASE__				,							add_special_tokens=SCREAMING_SNAKE_CASE__						)						)

       self.assertListEqual(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__						)

  @unittest.skip("""There is an inconsistency between slow and fast tokenizer due to a bug in the fast one."""						)
  def __a						(					self     :							Dict						):





       '''simple docstring'''

       pass

  @unittest.skip("""There is an inconsistency between slow and fast tokenizer due to a bug in the fast one."""						)
  def __a						(					self     :							int						):





       '''simple docstring'''

       pass

  def __a						(					self     :							int						):





       '''simple docstring'''

       __a       =   """I was born in 92000, and this is falsé."""
       __a       =   ["""▁""", """<unk>""", """▁was""", """▁born""", """▁in""", """▁9""", """2000""", """▁""", """,""", """▁and""", """▁this""", """▁is""", """▁fal""", """s""", """<unk>""", """▁""", """.""", ]
       # fmt: on

       __a       =   DebertaVaTokenizer(SCREAMING_SNAKE_CASE__				,							split_by_punct=SCREAMING_SNAKE_CASE__						)
       __a       =   tokenizer.convert_ids_to_tokens(tokenizer.encode(SCREAMING_SNAKE_CASE__				,							add_special_tokens=SCREAMING_SNAKE_CASE__						)						)

       self.assertListEqual(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__						)

       __a       =   DebertaVaTokenizerFast(SCREAMING_SNAKE_CASE__				,							split_by_punct=SCREAMING_SNAKE_CASE__						)
       __a       =   rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(SCREAMING_SNAKE_CASE__				,							add_special_tokens=SCREAMING_SNAKE_CASE__						)						)

       self.assertListEqual(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__						)

  def __a						(					self     :							Dict						):





       '''simple docstring'''

       __a       =   """I was born in 92000, and this is falsé."""
       __a       =   ["""▁i""", """▁was""", """▁born""", """▁in""", """▁9""", """2000""", """▁""", """,""", """▁and""", """▁this""", """▁is""", """▁fal""", """s""", """<unk>""", """▁""", """.""", ]
       # fmt: on

       __a       =   DebertaVaTokenizer(SCREAMING_SNAKE_CASE__				,							do_lower_case=SCREAMING_SNAKE_CASE__				,							split_by_punct=SCREAMING_SNAKE_CASE__						)
       __a       =   tokenizer.convert_ids_to_tokens(tokenizer.encode(SCREAMING_SNAKE_CASE__				,							add_special_tokens=SCREAMING_SNAKE_CASE__						)						)
       self.assertListEqual(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__						)

       __a       =   DebertaVaTokenizerFast(SCREAMING_SNAKE_CASE__				,							do_lower_case=SCREAMING_SNAKE_CASE__				,							split_by_punct=SCREAMING_SNAKE_CASE__						)
       __a       =   rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(SCREAMING_SNAKE_CASE__				,							add_special_tokens=SCREAMING_SNAKE_CASE__						)						)
       self.assertListEqual(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__						)

  def __a						(					self     :							str						):





       '''simple docstring'''

       __a       =   """I was born in 92000, and this is falsé."""
       __a       =   ["""▁i""", """▁was""", """▁born""", """▁in""", """▁9""", """2000""", """,""", """▁and""", """▁this""", """▁is""", """▁fal""", """s""", """<unk>""", """.""", ]
       # fmt: on

       __a       =   DebertaVaTokenizer(SCREAMING_SNAKE_CASE__				,							do_lower_case=SCREAMING_SNAKE_CASE__				,							split_by_punct=SCREAMING_SNAKE_CASE__						)
       __a       =   tokenizer.convert_ids_to_tokens(tokenizer.encode(SCREAMING_SNAKE_CASE__				,							add_special_tokens=SCREAMING_SNAKE_CASE__						)						)

       self.assertListEqual(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__						)

       __a       =   DebertaVaTokenizerFast(SCREAMING_SNAKE_CASE__				,							do_lower_case=SCREAMING_SNAKE_CASE__				,							split_by_punct=SCREAMING_SNAKE_CASE__						)
       __a       =   rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(SCREAMING_SNAKE_CASE__				,							add_special_tokens=SCREAMING_SNAKE_CASE__						)						)

       self.assertListEqual(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__						)

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





       '''simple docstring'''

       __a       =   """I was born in 92000, and this is falsé."""
       __a       =   ["""▁""", """<unk>""", """▁was""", """▁born""", """▁in""", """▁9""", """2000""", """▁""", """,""", """▁and""", """▁this""", """▁is""", """▁fal""", """s""", """<unk>""", """▁""", """.""", ]
       # fmt: on

       __a       =   DebertaVaTokenizer(SCREAMING_SNAKE_CASE__				,							do_lower_case=SCREAMING_SNAKE_CASE__				,							split_by_punct=SCREAMING_SNAKE_CASE__						)
       __a       =   tokenizer.convert_ids_to_tokens(tokenizer.encode(SCREAMING_SNAKE_CASE__				,							add_special_tokens=SCREAMING_SNAKE_CASE__						)						)

       self.assertListEqual(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__						)

       __a       =   DebertaVaTokenizerFast(SCREAMING_SNAKE_CASE__				,							do_lower_case=SCREAMING_SNAKE_CASE__				,							split_by_punct=SCREAMING_SNAKE_CASE__						)
       __a       =   rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(SCREAMING_SNAKE_CASE__				,							add_special_tokens=SCREAMING_SNAKE_CASE__						)						)

       self.assertListEqual(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__						)

  def __a						(					self     :							Tuple						):





       '''simple docstring'''

       __a       =   """ \tHeLLo!how  \n Are yoU?  """
       __a       =   ["""▁""", """<unk>""", """e""", """<unk>""", """o""", """!""", """how""", """▁""", """<unk>""", """re""", """▁yo""", """<unk>""", """?"""]
       # fmt: on

       __a       =   DebertaVaTokenizer(SCREAMING_SNAKE_CASE__				,							do_lower_case=SCREAMING_SNAKE_CASE__				,							split_by_punct=SCREAMING_SNAKE_CASE__						)
       __a       =   tokenizer.convert_ids_to_tokens(tokenizer.encode(SCREAMING_SNAKE_CASE__				,							add_special_tokens=SCREAMING_SNAKE_CASE__						)						)

       self.assertListEqual(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__						)

       __a       =   DebertaVaTokenizerFast(SCREAMING_SNAKE_CASE__				,							do_lower_case=SCREAMING_SNAKE_CASE__				,							split_by_punct=SCREAMING_SNAKE_CASE__						)
       __a       =   rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(SCREAMING_SNAKE_CASE__				,							add_special_tokens=SCREAMING_SNAKE_CASE__						)						)

       self.assertListEqual(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__						)

  def __a						(					self     :							str						):





       '''simple docstring'''

       __a       =   self.get_tokenizer()
       __a       =   self.get_rust_tokenizer()

       __a       =   """I was born in 92000, and this is falsé."""

       __a       =   tokenizer.convert_ids_to_tokens(tokenizer.encode(SCREAMING_SNAKE_CASE__				,							add_special_tokens=SCREAMING_SNAKE_CASE__						)						)
       __a       =   rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(SCREAMING_SNAKE_CASE__				,							add_special_tokens=SCREAMING_SNAKE_CASE__						)						)
       self.assertListEqual(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__						)

       __a       =   tokenizer.encode(SCREAMING_SNAKE_CASE__				,							add_special_tokens=SCREAMING_SNAKE_CASE__						)
       __a       =   rust_tokenizer.encode(SCREAMING_SNAKE_CASE__				,							add_special_tokens=SCREAMING_SNAKE_CASE__						)
       self.assertListEqual(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__						)

       __a       =   self.get_rust_tokenizer()
       __a       =   tokenizer.encode(SCREAMING_SNAKE_CASE__						)
       __a       =   rust_tokenizer.encode(SCREAMING_SNAKE_CASE__						)
       self.assertListEqual(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__						)

  def __a						(					self     :							Optional[int]						):





       '''simple docstring'''

       __a       =   """This is a test"""
       __a       =   [1_3, 1, 4_3_9_8, 2_5, 2_1, 1_2_8_9]
       __a       =   ["""▁""", """T""", """his""", """▁is""", """▁a""", """▁test"""]
       __a       =   ["""▁""", """<unk>""", """his""", """▁is""", """▁a""", """▁test"""]

       __a       =   DebertaVaTokenizer(SCREAMING_SNAKE_CASE__				,							keep_accents=SCREAMING_SNAKE_CASE__						)
       __a       =   DebertaVaTokenizerFast(SCREAMING_SNAKE_CASE__				,							keep_accents=SCREAMING_SNAKE_CASE__						)

       __a       =   tokenizer.encode(SCREAMING_SNAKE_CASE__				,							add_special_tokens=SCREAMING_SNAKE_CASE__						)
       self.assertListEqual(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__						)
       __a       =   tokenizer.tokenize(SCREAMING_SNAKE_CASE__						)
       self.assertListEqual(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__						)
       __a       =   tokenizer.convert_ids_to_tokens(SCREAMING_SNAKE_CASE__						)
       self.assertListEqual(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__						)

       __a       =   rust_tokenizer.encode(SCREAMING_SNAKE_CASE__				,							add_special_tokens=SCREAMING_SNAKE_CASE__						)
       self.assertListEqual(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__						)
       __a       =   rust_tokenizer.tokenize(SCREAMING_SNAKE_CASE__						)
       self.assertListEqual(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__						)
       __a       =   rust_tokenizer.convert_ids_to_tokens(SCREAMING_SNAKE_CASE__						)
       self.assertListEqual(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__						)

       # fmt: off
       __a       =   """I was born in 92000, and this is falsé."""
       __a       =   [1_3, 1, 2_3, 3_8_6, 1_9, 5_6_1, 3_0_5_0, 1_5, 1_7, 4_8, 2_5, 8_2_5_6, 1_8, 1, 9]
       __a       =   ["""▁""", """I""", """▁was""", """▁born""", """▁in""", """▁9""", """2000""", """,""", """▁and""", """▁this""", """▁is""", """▁fal""", """s""", """é""", """.""", ]
       __a       =   ["""▁""", """<unk>""", """▁was""", """▁born""", """▁in""", """▁9""", """2000""", """,""", """▁and""", """▁this""", """▁is""", """▁fal""", """s""", """<unk>""", """.""", ]
       # fmt: on

       __a       =   tokenizer.encode(SCREAMING_SNAKE_CASE__				,							add_special_tokens=SCREAMING_SNAKE_CASE__						)
       self.assertListEqual(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__						)
       __a       =   tokenizer.tokenize(SCREAMING_SNAKE_CASE__						)
       self.assertListEqual(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__						)
       __a       =   tokenizer.convert_ids_to_tokens(SCREAMING_SNAKE_CASE__						)
       self.assertListEqual(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__						)

       __a       =   rust_tokenizer.encode(SCREAMING_SNAKE_CASE__				,							add_special_tokens=SCREAMING_SNAKE_CASE__						)
       self.assertListEqual(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__						)
       __a       =   rust_tokenizer.tokenize(SCREAMING_SNAKE_CASE__						)
       self.assertListEqual(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__						)
       __a       =   rust_tokenizer.convert_ids_to_tokens(SCREAMING_SNAKE_CASE__						)
       self.assertListEqual(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__						)

  def __a						(					self     :							List[Any]						):





       '''simple docstring'''

       __a       =   DebertaVaTokenizer(SCREAMING_SNAKE_CASE__						)

       __a       =   tokenizer.encode("""sequence builders"""						)
       __a       =   tokenizer.encode("""multi-sequence build"""						)

       __a       =   tokenizer.build_inputs_with_special_tokens(SCREAMING_SNAKE_CASE__						)
       __a       =   tokenizer.build_inputs_with_special_tokens(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__						)

       self.assertEqual([tokenizer.cls_token_id] + text + [tokenizer.sep_token_id]				,							SCREAMING_SNAKE_CASE__						)
       self.assertEqual(
           [tokenizer.cls_token_id] + text + [tokenizer.sep_token_id] + text_a + [tokenizer.sep_token_id]				,							SCREAMING_SNAKE_CASE__				,							)


  @slow
  def __a						(					self     :							int						):





       '''simple docstring'''

       __a       =   {"""input_ids""": [[1, 3_9_8_6_7, 3_6, 1_9_3_9_0, 4_8_6, 2_7, 3_5_0_5_2, 8_1_4_3_6, 1_8, 6_0_6_8_5, 1_2_2_5, 7, 3_5_0_5_2, 8_1_4_3_6, 1_8, 9_3_6_7, 1_6_8_9_9, 1_8, 1_5_9_3_7, 5_3, 5_9_4, 7_7_3, 1_8, 1_6_2_8_7, 3_0_4_6_5, 3_6, 1_5_9_3_7, 6, 4_1_1_3_9, 3_8, 3_6_9_7_9, 6_0_7_6_3, 1_9_1, 6, 3_4_1_3_2, 9_9, 6, 5_0_5_3_8, 3_9_0, 4_3_2_3_0, 6, 3_4_1_3_2, 2_7_7_9, 2_0_8_5_0, 1_4, 6_9_9, 1_0_7_2, 1_1_9_4, 3_6, 3_8_2, 1_0_9_0_1, 5_3, 7, 6_9_9, 1_0_7_2, 2_0_8_4, 3_6, 2_0_4_2_2, 6_3_0, 5_3, 1_9, 1_0_5, 3_0_4_9, 1_8_9_6, 1_0_5_3, 1_6_8_9_9, 1_5_0_6, 1_1, 3_7_9_7_8, 4_2_4_3, 7, 1_2_3_7, 3_1_8_6_9, 2_0_0, 1_6_5_6_6, 6_5_4, 6, 3_5_0_5_2, 8_1_4_3_6, 7, 5_5_6_3_0, 1_3_5_9_3, 4, 2], [1, 2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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]}  # noqa: E501
       # fmt: on

       self.tokenizer_integration_test_util(
           expected_encoding=SCREAMING_SNAKE_CASE__				,							model_name="""microsoft/deberta-v2-xlarge"""				,							revision="""ad6e42c1532ddf3a15c39246b63f5559d558b670"""				,							)










'''simple docstring'''







import inspect
import unittest

from transformers import ViTConfig
from transformers.testing_utils import (
    require_accelerate,
    require_torch,
    require_torch_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, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
 import torch
 from torch import nn

 from transformers import ViTForImageClassification, ViTForMaskedImageModeling, ViTModel
 from transformers.models.vit.modeling_vit import VIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
 from PIL import Image

 from transformers import ViTImageProcessor


class  lowerCAmelCase_						:





  """simple docstring"""



  def __init__(					self     :							Any				,							SCREAMING_SNAKE_CASE__     :							int				,							SCREAMING_SNAKE_CASE__     :							List[str]=1_3				,							SCREAMING_SNAKE_CASE__     :							int=3_0				,							SCREAMING_SNAKE_CASE__     :							List[str]=2				,							SCREAMING_SNAKE_CASE__     :							Union[str, Any]=3				,							SCREAMING_SNAKE_CASE__     :							List[str]=True				,							SCREAMING_SNAKE_CASE__     :							Dict=True				,							SCREAMING_SNAKE_CASE__     :							str=3_2				,							SCREAMING_SNAKE_CASE__     :							Tuple=5				,							SCREAMING_SNAKE_CASE__     :							List[Any]=4				,							SCREAMING_SNAKE_CASE__     :							Dict=3_7				,							SCREAMING_SNAKE_CASE__     :							Any="gelu"				,							SCREAMING_SNAKE_CASE__     :							Optional[Any]=0.1				,							SCREAMING_SNAKE_CASE__     :							Union[str, Any]=0.1				,							SCREAMING_SNAKE_CASE__     :							Union[str, Any]=1_0				,							SCREAMING_SNAKE_CASE__     :							str=0.0_2				,							SCREAMING_SNAKE_CASE__     :							Union[str, Any]=None				,							SCREAMING_SNAKE_CASE__     :							Any=2				,							):





       '''simple docstring'''

       __a       =   parent
       __a       =   batch_size
       __a       =   image_size
       __a       =   patch_size
       __a       =   num_channels
       __a       =   is_training
       __a       =   use_labels
       __a       =   hidden_size
       __a       =   num_hidden_layers
       __a       =   num_attention_heads
       __a       =   intermediate_size
       __a       =   hidden_act
       __a       =   hidden_dropout_prob
       __a       =   attention_probs_dropout_prob
       __a       =   type_sequence_label_size
       __a       =   initializer_range
       __a       =   scope
       __a       =   encoder_stride

       # in ViT, the seq length equals the number of patches + 1 (we add 1 for the [CLS] token)
       __a       =   (image_size // patch_size) ** 2
       __a       =   num_patches + 1

  def __a						(					self     :							Any						):





       '''simple docstring'''

       __a       =   floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

       __a       =   None
       if self.use_labels:
            __a       =   ids_tensor([self.batch_size]				,							self.type_sequence_label_size						)

       __a       =   self.get_config()

       return config, pixel_values, labels

  def __a						(					self     :							Optional[int]						):





       '''simple docstring'''

       return ViTConfig(
           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				,							)

  def __a						(					self     :							Dict				,							SCREAMING_SNAKE_CASE__     :							Optional[Any]				,							SCREAMING_SNAKE_CASE__     :							Any				,							SCREAMING_SNAKE_CASE__     :							Optional[Any]						):





       '''simple docstring'''

       __a       =   ViTModel(config=SCREAMING_SNAKE_CASE__						)
       model.to(SCREAMING_SNAKE_CASE__						)
       model.eval()
       __a       =   model(SCREAMING_SNAKE_CASE__						)
       self.parent.assertEqual(result.last_hidden_state.shape				,							(self.batch_size, self.seq_length, self.hidden_size)						)

  def __a						(					self     :							str				,							SCREAMING_SNAKE_CASE__     :							List[str]				,							SCREAMING_SNAKE_CASE__     :							Tuple				,							SCREAMING_SNAKE_CASE__     :							str						):





       '''simple docstring'''

       __a       =   ViTForMaskedImageModeling(config=SCREAMING_SNAKE_CASE__						)
       model.to(SCREAMING_SNAKE_CASE__						)
       model.eval()
       __a       =   model(SCREAMING_SNAKE_CASE__						)
       self.parent.assertEqual(
           result.reconstruction.shape				,							(self.batch_size, self.num_channels, self.image_size, self.image_size)						)

       # test greyscale images
       __a       =   1
       __a       =   ViTForMaskedImageModeling(SCREAMING_SNAKE_CASE__						)
       model.to(SCREAMING_SNAKE_CASE__						)
       model.eval()

       __a       =   floats_tensor([self.batch_size, 1, self.image_size, self.image_size]						)
       __a       =   model(SCREAMING_SNAKE_CASE__						)
       self.parent.assertEqual(result.reconstruction.shape				,							(self.batch_size, 1, self.image_size, self.image_size)						)

  def __a						(					self     :							str				,							SCREAMING_SNAKE_CASE__     :							Tuple				,							SCREAMING_SNAKE_CASE__     :							List[Any]				,							SCREAMING_SNAKE_CASE__     :							Dict						):





       '''simple docstring'''

       __a       =   self.type_sequence_label_size
       __a       =   ViTForImageClassification(SCREAMING_SNAKE_CASE__						)
       model.to(SCREAMING_SNAKE_CASE__						)
       model.eval()
       __a       =   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
       __a       =   1
       __a       =   ViTForImageClassification(SCREAMING_SNAKE_CASE__						)
       model.to(SCREAMING_SNAKE_CASE__						)
       model.eval()

       __a       =   floats_tensor([self.batch_size, 1, self.image_size, self.image_size]						)
       __a       =   model(SCREAMING_SNAKE_CASE__						)
       self.parent.assertEqual(result.logits.shape				,							(self.batch_size, self.type_sequence_label_size)						)


  def __a						(					self     :							str						):





       '''simple docstring'''

       __a       =   self.prepare_config_and_inputs()
       (
           (
           __a
       ) ,						(
           __a
       ) ,						(
           __a
       ) ,						
       )       =   config_and_inputs
       __a       =   {"""pixel_values""": pixel_values}
       return config, inputs_dict


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





  """simple docstring"""



  a_       :str												=(
      (
          ViTModel,
          ViTForImageClassification,
          ViTForMaskedImageModeling,
      )
      if is_torch_available()
      else ()
  )
  a_       :Tuple												=(
      {"""feature-extraction""": ViTModel, """image-classification""": ViTForImageClassification}
      if is_torch_available()
      else {}
  )
  a_       :List[str]												=True

  a_       :str												=False
  a_       :Optional[int]												=False
  a_       :Tuple												=False

  def __a						(					self     :							str						):





       '''simple docstring'''

       __a       =   ViTModelTester(self						)
       __a       =   ConfigTester(self				,							config_class=SCREAMING_SNAKE_CASE__				,							has_text_modality=SCREAMING_SNAKE_CASE__				,							hidden_size=3_7						)

  def __a						(					self     :							Dict						):





       '''simple docstring'''

       self.config_tester.run_common_tests()

  @unittest.skip(reason="""ViT does not use inputs_embeds"""						)
  def __a						(					self     :							List[Any]						):





       '''simple docstring'''

       pass

  def __a						(					self     :							int						):





       '''simple docstring'''

       __a ,						__a       =   self.model_tester.prepare_config_and_inputs_for_common()

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

  def __a						(					self     :							int						):





       '''simple docstring'''

       __a ,						__a       =   self.model_tester.prepare_config_and_inputs_for_common()

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

            __a       =   ["""pixel_values"""]
            self.assertListEqual(arg_names[:1]				,							SCREAMING_SNAKE_CASE__						)

  def __a						(					self     :							List[str]						):





       '''simple docstring'''

       __a       =   self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE__						)

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





       '''simple docstring'''

       __a       =   self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_masked_image_modeling(*SCREAMING_SNAKE_CASE__						)

  def __a						(					self     :							Optional[Any]						):





       '''simple docstring'''

       __a       =   self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_image_classification(*SCREAMING_SNAKE_CASE__						)


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





       '''simple docstring'''

       for model_name in VIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
            __a       =   ViTModel.from_pretrained(SCREAMING_SNAKE_CASE__						)
            self.assertIsNotNone(SCREAMING_SNAKE_CASE__						)




def        __lowercase						(      )				->					int:
     """simple docstring"""




     __a       =   Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""		)
     return image



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





  """simple docstring"""



  @cached_property
  def __a						(					self     :							str						):





       '''simple docstring'''

       return ViTImageProcessor.from_pretrained("""google/vit-base-patch16-224"""						) if is_vision_available() else None

  @slow
  def __a						(					self     :							Dict						):





       '''simple docstring'''

       __a       =   ViTForImageClassification.from_pretrained("""google/vit-base-patch16-224"""						).to(SCREAMING_SNAKE_CASE__						)

       __a       =   self.default_image_processor
       __a       =   prepare_img()
       __a       =   image_processor(images=SCREAMING_SNAKE_CASE__				,							return_tensors="""pt"""						).to(SCREAMING_SNAKE_CASE__						)

       # forward pass
       with torch.no_grad():
            __a       =   model(**SCREAMING_SNAKE_CASE__						)

       # verify the logits
       __a       =   torch.Size((1, 1_0_0_0)						)
       self.assertEqual(outputs.logits.shape				,							SCREAMING_SNAKE_CASE__						)

       __a       =   torch.tensor([-0.2_7_4_4, 0.8_2_1_5, -0.0_8_3_6]						).to(SCREAMING_SNAKE_CASE__						)

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

  @slow
  def __a						(					self     :							int						):





       '''simple docstring'''

       __a       =   ViTModel.from_pretrained("""facebook/dino-vits8"""						).to(SCREAMING_SNAKE_CASE__						)

       __a       =   ViTImageProcessor.from_pretrained("""facebook/dino-vits8"""				,							size=4_8_0						)
       __a       =   prepare_img()
       __a       =   image_processor(images=SCREAMING_SNAKE_CASE__				,							return_tensors="""pt"""						)
       __a       =   inputs.pixel_values.to(SCREAMING_SNAKE_CASE__						)

       # forward pass
       with torch.no_grad():
            __a       =   model(SCREAMING_SNAKE_CASE__				,							interpolate_pos_encoding=SCREAMING_SNAKE_CASE__						)

       # verify the logits
       __a       =   torch.Size((1, 3_6_0_1, 3_8_4)						)
       self.assertEqual(outputs.last_hidden_state.shape				,							SCREAMING_SNAKE_CASE__						)

       __a       =   torch.tensor(
           [[4.2_3_4_0, 4.3_9_0_6, -6.6_6_9_2], [4.5_4_6_3, 1.8_9_2_8, -6.7_2_5_7], [4.4_4_2_9, 0.8_4_9_6, -5.8_5_8_5]]						).to(SCREAMING_SNAKE_CASE__						)

       self.assertTrue(torch.allclose(outputs.last_hidden_state[0, :3, :3]				,							SCREAMING_SNAKE_CASE__				,							atol=1E-4						)						)


  @slow
  @require_accelerate
  @require_torch_gpu
  def __a						(					self     :							Optional[Any]						):





       '''simple docstring'''

       __a       =   ViTModel.from_pretrained("""facebook/dino-vits8"""				,							torch_dtype=torch.floataa				,							device_map="""auto"""						)
       __a       =   self.default_image_processor

       __a       =   prepare_img()
       __a       =   image_processor(images=SCREAMING_SNAKE_CASE__				,							return_tensors="""pt"""						)
       __a       =   inputs.pixel_values.to(SCREAMING_SNAKE_CASE__						)

       # forward pass to make sure inference works in fp16
       with torch.no_grad():
            __a       =   model(SCREAMING_SNAKE_CASE__						)






