

from __future__ import annotations

import unittest

from transformers import FunnelConfig, is_tf_available
from transformers.testing_utils import require_tf

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
    import tensorflow as tf

    from transformers import (
        TFFunnelBaseModel,
        TFFunnelForMaskedLM,
        TFFunnelForMultipleChoice,
        TFFunnelForPreTraining,
        TFFunnelForQuestionAnswering,
        TFFunnelForSequenceClassification,
        TFFunnelForTokenClassification,
        TFFunnelModel,
    )
class  _A		:

  def __init__(				self ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE=13 ,					_SCREAMING_SNAKE_CASE=7 ,					_SCREAMING_SNAKE_CASE=True ,					_SCREAMING_SNAKE_CASE=True ,					_SCREAMING_SNAKE_CASE=True ,					_SCREAMING_SNAKE_CASE=True ,					_SCREAMING_SNAKE_CASE=99 ,					_SCREAMING_SNAKE_CASE=[1, 1, 2] ,					_SCREAMING_SNAKE_CASE=1 ,					_SCREAMING_SNAKE_CASE=32 ,					_SCREAMING_SNAKE_CASE=4 ,					_SCREAMING_SNAKE_CASE=8 ,					_SCREAMING_SNAKE_CASE=37 ,					_SCREAMING_SNAKE_CASE="gelu_new" ,					_SCREAMING_SNAKE_CASE=0.1 ,					_SCREAMING_SNAKE_CASE=0.1 ,					_SCREAMING_SNAKE_CASE=0.0 ,					_SCREAMING_SNAKE_CASE=512 ,					_SCREAMING_SNAKE_CASE=3 ,					_SCREAMING_SNAKE_CASE=0.02 ,					_SCREAMING_SNAKE_CASE=3 ,					_SCREAMING_SNAKE_CASE=4 ,					_SCREAMING_SNAKE_CASE=None ,					_SCREAMING_SNAKE_CASE=False ,					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  int           =     parent
        SCREAMING_SNAKE_CASE_				:  List[Any]           =     batch_size
        SCREAMING_SNAKE_CASE_				:  Any           =     seq_length
        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     is_training
        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     use_input_mask
        SCREAMING_SNAKE_CASE_				:  Dict           =     use_token_type_ids
        SCREAMING_SNAKE_CASE_				:  int           =     use_labels
        SCREAMING_SNAKE_CASE_				:  Any           =     vocab_size
        SCREAMING_SNAKE_CASE_				:  Dict           =     block_sizes
        SCREAMING_SNAKE_CASE_				:  Tuple           =     num_decoder_layers
        SCREAMING_SNAKE_CASE_				:  Any           =     d_model
        SCREAMING_SNAKE_CASE_				:  List[Any]           =     n_head
        SCREAMING_SNAKE_CASE_				:  int           =     d_head
        SCREAMING_SNAKE_CASE_				:  List[Any]           =     d_inner
        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     hidden_act
        SCREAMING_SNAKE_CASE_				:  Dict           =     hidden_dropout
        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     attention_dropout
        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     activation_dropout
        SCREAMING_SNAKE_CASE_				:  Any           =     max_position_embeddings
        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     type_vocab_size
        SCREAMING_SNAKE_CASE_				:  Dict           =     2
        SCREAMING_SNAKE_CASE_				:  List[str]           =     num_labels
        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     num_choices
        SCREAMING_SNAKE_CASE_				:  List[str]           =     scope
        SCREAMING_SNAKE_CASE_				:  Any           =     initializer_std

        # Used in the tests to check the size of the first attention layer
        SCREAMING_SNAKE_CASE_				:  Any           =     n_head
        # Used in the tests to check the size of the first hidden state
        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     self.d_model
        # Used in the tests to check the number of output hidden states/attentions
        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     sum(self.block_sizes					) + (0 if base else self.num_decoder_layers)
        # FunnelModel adds two hidden layers: input embeddings and the sum of the upsampled encoder hidden state with
        # the last hidden state of the first block (which is the first hidden state of the decoder).
        if not base:
              SCREAMING_SNAKE_CASE_				:  Any           =     self.num_hidden_layers + 2

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  List[str]           =     ids_tensor([self.batch_size, self.seq_length] ,					self.vocab_size					)

        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     None
        if self.use_input_mask:
              SCREAMING_SNAKE_CASE_				:  List[Any]           =     random_attention_mask([self.batch_size, self.seq_length]					)

        SCREAMING_SNAKE_CASE_				:  List[str]           =     None
        if self.use_token_type_ids:
              SCREAMING_SNAKE_CASE_				:  Optional[int]           =     ids_tensor([self.batch_size, self.seq_length] ,					self.type_vocab_size					)

        SCREAMING_SNAKE_CASE_				:  int           =     None
        SCREAMING_SNAKE_CASE_				:  Tuple           =     None
        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     None
        if self.use_labels:
              SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     ids_tensor([self.batch_size] ,					self.type_sequence_label_size					)
              SCREAMING_SNAKE_CASE_				:  Any           =     ids_tensor([self.batch_size, self.seq_length] ,					self.num_labels					)
              SCREAMING_SNAKE_CASE_				:  Dict           =     ids_tensor([self.batch_size] ,					self.num_choices					)

        SCREAMING_SNAKE_CASE_				:  Dict           =     FunnelConfig(
            vocab_size=self.vocab_size ,					block_sizes=self.block_sizes ,					num_decoder_layers=self.num_decoder_layers ,					d_model=self.d_model ,					n_head=self.n_head ,					d_head=self.d_head ,					d_inner=self.d_inner ,					hidden_act=self.hidden_act ,					hidden_dropout=self.hidden_dropout ,					attention_dropout=self.attention_dropout ,					activation_dropout=self.activation_dropout ,					max_position_embeddings=self.max_position_embeddings ,					type_vocab_size=self.type_vocab_size ,					initializer_std=self.initializer_std ,					)

        return (
            config,
            input_ids,
            token_type_ids,
            input_mask,
            sequence_labels,
            token_labels,
            choice_labels,
        )

  def  UpperCAmelCase    (				self ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Any           =     TFFunnelModel(config=_SCREAMING_SNAKE_CASE					)
        SCREAMING_SNAKE_CASE_				:  Dict           =     {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
        SCREAMING_SNAKE_CASE_				:  List[Any]           =     model(_SCREAMING_SNAKE_CASE					)

        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     [input_ids, input_mask]
        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     model(_SCREAMING_SNAKE_CASE					)

        SCREAMING_SNAKE_CASE_				:  List[str]           =     model(_SCREAMING_SNAKE_CASE					)
        self.parent.assertEqual(result.last_hidden_state.shape ,					(self.batch_size, self.seq_length, self.d_model)					)

        SCREAMING_SNAKE_CASE_				:  Any           =     False
        SCREAMING_SNAKE_CASE_				:  Any           =     TFFunnelModel(config=_SCREAMING_SNAKE_CASE					)
        SCREAMING_SNAKE_CASE_				:  List[Any]           =     model(_SCREAMING_SNAKE_CASE					)
        self.parent.assertEqual(result.last_hidden_state.shape ,					(self.batch_size, self.seq_length, self.d_model)					)

        SCREAMING_SNAKE_CASE_				:  str           =     False
        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     TFFunnelModel(config=_SCREAMING_SNAKE_CASE					)
        SCREAMING_SNAKE_CASE_				:  List[Any]           =     model(_SCREAMING_SNAKE_CASE					)
        self.parent.assertEqual(result.last_hidden_state.shape ,					(self.batch_size, self.seq_length, self.d_model)					)

  def  UpperCAmelCase    (				self ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  List[Any]           =     TFFunnelBaseModel(config=_SCREAMING_SNAKE_CASE					)
        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     model(_SCREAMING_SNAKE_CASE					)

        SCREAMING_SNAKE_CASE_				:  str           =     [input_ids, input_mask]
        SCREAMING_SNAKE_CASE_				:  Dict           =     model(_SCREAMING_SNAKE_CASE					)

        SCREAMING_SNAKE_CASE_				:  int           =     model(_SCREAMING_SNAKE_CASE					)
        self.parent.assertEqual(result.last_hidden_state.shape ,					(self.batch_size, 2, self.d_model)					)

        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     False
        SCREAMING_SNAKE_CASE_				:  Tuple           =     TFFunnelBaseModel(config=_SCREAMING_SNAKE_CASE					)
        SCREAMING_SNAKE_CASE_				:  List[str]           =     model(_SCREAMING_SNAKE_CASE					)
        self.parent.assertEqual(result.last_hidden_state.shape ,					(self.batch_size, 3, self.d_model)					)

        SCREAMING_SNAKE_CASE_				:  Dict           =     False
        SCREAMING_SNAKE_CASE_				:  List[Any]           =     TFFunnelBaseModel(config=_SCREAMING_SNAKE_CASE					)
        SCREAMING_SNAKE_CASE_				:  Any           =     model(_SCREAMING_SNAKE_CASE					)
        self.parent.assertEqual(result.last_hidden_state.shape ,					(self.batch_size, 2, self.d_model)					)

  def  UpperCAmelCase    (				self ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  List[str]           =     TFFunnelForPreTraining(config=_SCREAMING_SNAKE_CASE					)
        SCREAMING_SNAKE_CASE_				:  str           =     {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
        SCREAMING_SNAKE_CASE_				:  Tuple           =     model(_SCREAMING_SNAKE_CASE					)
        self.parent.assertEqual(result.logits.shape ,					(self.batch_size, self.seq_length)					)

  def  UpperCAmelCase    (				self ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Any           =     TFFunnelForMaskedLM(config=_SCREAMING_SNAKE_CASE					)
        SCREAMING_SNAKE_CASE_				:  str           =     {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
        SCREAMING_SNAKE_CASE_				:  str           =     model(_SCREAMING_SNAKE_CASE					)
        self.parent.assertEqual(result.logits.shape ,					(self.batch_size, self.seq_length, self.vocab_size)					)

  def  UpperCAmelCase    (				self ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Dict           =     self.num_labels
        SCREAMING_SNAKE_CASE_				:  List[Any]           =     TFFunnelForSequenceClassification(config=_SCREAMING_SNAKE_CASE					)
        SCREAMING_SNAKE_CASE_				:  Dict           =     {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
        SCREAMING_SNAKE_CASE_				:  int           =     model(_SCREAMING_SNAKE_CASE					)
        self.parent.assertEqual(result.logits.shape ,					(self.batch_size, self.num_labels)					)

  def  UpperCAmelCase    (				self ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  int           =     self.num_choices
        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     TFFunnelForMultipleChoice(config=_SCREAMING_SNAKE_CASE					)
        SCREAMING_SNAKE_CASE_				:  Dict           =     tf.tile(tf.expand_dims(_SCREAMING_SNAKE_CASE ,					1					) ,					(1, self.num_choices, 1)					)
        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     tf.tile(tf.expand_dims(_SCREAMING_SNAKE_CASE ,					1					) ,					(1, self.num_choices, 1)					)
        SCREAMING_SNAKE_CASE_				:  List[str]           =     tf.tile(tf.expand_dims(_SCREAMING_SNAKE_CASE ,					1					) ,					(1, self.num_choices, 1)					)
        SCREAMING_SNAKE_CASE_				:  Any           =     {
            'input_ids': multiple_choice_inputs_ids,
            'attention_mask': multiple_choice_input_mask,
            'token_type_ids': multiple_choice_token_type_ids,
        }
        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     model(_SCREAMING_SNAKE_CASE					)
        self.parent.assertEqual(result.logits.shape ,					(self.batch_size, self.num_choices)					)

  def  UpperCAmelCase    (				self ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  int           =     self.num_labels
        SCREAMING_SNAKE_CASE_				:  int           =     TFFunnelForTokenClassification(config=_SCREAMING_SNAKE_CASE					)
        SCREAMING_SNAKE_CASE_				:  str           =     {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
        SCREAMING_SNAKE_CASE_				:  int           =     model(_SCREAMING_SNAKE_CASE					)
        self.parent.assertEqual(result.logits.shape ,					(self.batch_size, self.seq_length, self.num_labels)					)

  def  UpperCAmelCase    (				self ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  str           =     TFFunnelForQuestionAnswering(config=_SCREAMING_SNAKE_CASE					)
        SCREAMING_SNAKE_CASE_				:  List[str]           =     {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
        SCREAMING_SNAKE_CASE_				:  str           =     model(_SCREAMING_SNAKE_CASE					)
        self.parent.assertEqual(result.start_logits.shape ,					(self.batch_size, self.seq_length)					)
        self.parent.assertEqual(result.end_logits.shape ,					(self.batch_size, self.seq_length)					)



  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Any           =     self.prepare_config_and_inputs()
        (
            (
            SCREAMING_SNAKE_CASE_
        )       ,						(
            SCREAMING_SNAKE_CASE_
        )       ,						(
            SCREAMING_SNAKE_CASE_
        )       ,						(
            SCREAMING_SNAKE_CASE_
        )       ,						(
            SCREAMING_SNAKE_CASE_
        )       ,						(
            SCREAMING_SNAKE_CASE_
        )       ,						(
            SCREAMING_SNAKE_CASE_
        )       ,						
        )				:  str           =     config_and_inputs
        SCREAMING_SNAKE_CASE_				:  int           =     {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
        return config, inputs_dict

@require_tf
class  _A		(  __magic_name__   ,     __magic_name__   ,     unittest.TestCase):
  SCREAMING_SNAKE_CASE    :      str       =  (
      (
          TFFunnelModel,
          TFFunnelForMaskedLM,
          TFFunnelForPreTraining,
          TFFunnelForQuestionAnswering,
          TFFunnelForTokenClassification,
      )
      if is_tf_available()
      else ()
  )
  SCREAMING_SNAKE_CASE    :      str       =  (
      {
          '''feature-extraction''': (TFFunnelBaseModel, TFFunnelModel),
          '''fill-mask''': TFFunnelForMaskedLM,
          '''question-answering''': TFFunnelForQuestionAnswering,
          '''text-classification''': TFFunnelForSequenceClassification,
          '''token-classification''': TFFunnelForTokenClassification,
          '''zero-shot''': TFFunnelForSequenceClassification,
      }
      if is_tf_available()
      else {}
  )
  SCREAMING_SNAKE_CASE    :      Union[str, Any]       =  False
  SCREAMING_SNAKE_CASE    :      Any       =  False

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Any           =     TFFunnelModelTester(self					)
        SCREAMING_SNAKE_CASE_				:  Dict           =     ConfigTester(self ,					config_class=_SCREAMING_SNAKE_CASE					)

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        self.config_tester.run_common_tests()

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  List[str]           =     self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*_SCREAMING_SNAKE_CASE					)

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_pretraining(*_SCREAMING_SNAKE_CASE					)

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  str           =     self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_masked_lm(*_SCREAMING_SNAKE_CASE					)

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_token_classification(*_SCREAMING_SNAKE_CASE					)



  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_question_answering(*_SCREAMING_SNAKE_CASE					)

@require_tf
class  _A		(  __magic_name__   ,     unittest.TestCase):
  SCREAMING_SNAKE_CASE    :      Union[str, Any]       =  (
      (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
  )
  SCREAMING_SNAKE_CASE    :      Union[str, Any]       =  False
  SCREAMING_SNAKE_CASE    :      Dict       =  False

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Any           =     TFFunnelModelTester(self ,					base=_SCREAMING_SNAKE_CASE					)
        SCREAMING_SNAKE_CASE_				:  int           =     ConfigTester(self ,					config_class=_SCREAMING_SNAKE_CASE					)

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        self.config_tester.run_common_tests()

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  str           =     self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_base_model(*_SCREAMING_SNAKE_CASE					)

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Dict           =     self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_sequence_classification(*_SCREAMING_SNAKE_CASE					)



  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Tuple           =     self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_multiple_choice(*_SCREAMING_SNAKE_CASE					)









import unittest

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


if is_torch_available():
    import torch

    from transformers import AutoModelForImageClassification

if is_vision_available():
    from transformers import AutoImageProcessor
@require_torch
@require_vision
class  _A		(  unittest.TestCase):

  @slow
  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  List[str]           =     AutoImageProcessor.from_pretrained('microsoft/dit-base-finetuned-rvlcdip'					)
        SCREAMING_SNAKE_CASE_				:  Any           =     AutoModelForImageClassification.from_pretrained('microsoft/dit-base-finetuned-rvlcdip'					)
        model.to(_SCREAMING_SNAKE_CASE					)

        from datasets import load_dataset

        SCREAMING_SNAKE_CASE_				:  str           =     load_dataset('nielsr/rvlcdip-demo'					)

        SCREAMING_SNAKE_CASE_				:  List[Any]           =     dataset['train'][0]['image'].convert('RGB'					)

        SCREAMING_SNAKE_CASE_				:  List[Any]           =     image_processor(_SCREAMING_SNAKE_CASE ,					return_tensors='pt'					).to(_SCREAMING_SNAKE_CASE					)

        # forward pass
        with torch.no_grad():
              SCREAMING_SNAKE_CASE_				:  int           =     model(**_SCREAMING_SNAKE_CASE					)
              SCREAMING_SNAKE_CASE_				:  Any           =     outputs.logits

        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     torch.Size((1, 16)					)
        self.assertEqual(logits.shape ,					_SCREAMING_SNAKE_CASE					)

        SCREAMING_SNAKE_CASE_				:  List[str]           =     torch.tensor(
            [-0.4158, -0.4092, -0.4347] ,					device=_SCREAMING_SNAKE_CASE ,					dtype=torch.float ,					)
        self.assertTrue(torch.allclose(logits[0, :3] ,					_SCREAMING_SNAKE_CASE ,					atol=1e-4					)					)






