




from ...configuration_utils import PretrainedConfig
from ...utils import logging


__a							     =					logging.get_logger(__name__)

__a							     =					{'openai-gpt': 'https://huggingface.co/openai-gpt/resolve/main/config.json'}

class     __a(	_a  ):






    """simple docstring"""





    lowerCAmelCase         = '''openai-gpt'''
    lowerCAmelCase         = {
        '''max_position_embeddings''': '''n_positions''',
        '''hidden_size''': '''n_embd''',
        '''num_attention_heads''': '''n_head''',
        '''num_hidden_layers''': '''n_layer''',
    }





    def __init__( self  ,_SCREAMING_SNAKE_CASE=40_478  ,_SCREAMING_SNAKE_CASE=512  ,_SCREAMING_SNAKE_CASE=768  ,_SCREAMING_SNAKE_CASE=12  ,_SCREAMING_SNAKE_CASE=12  ,_SCREAMING_SNAKE_CASE="gelu"  ,_SCREAMING_SNAKE_CASE=0.1  ,_SCREAMING_SNAKE_CASE=0.1  ,_SCREAMING_SNAKE_CASE=0.1  ,_SCREAMING_SNAKE_CASE=1e-5  ,_SCREAMING_SNAKE_CASE=0.02  ,_SCREAMING_SNAKE_CASE="cls_index"  ,_SCREAMING_SNAKE_CASE=True  ,_SCREAMING_SNAKE_CASE=None  ,_SCREAMING_SNAKE_CASE=True  ,_SCREAMING_SNAKE_CASE=0.1  ,**_SCREAMING_SNAKE_CASE  ,)					->						Optional[int]:
         UpperCAmelCase_     :				Dict  =     vocab_size
         UpperCAmelCase_     :				int  =     n_positions
         UpperCAmelCase_     :				Dict  =     n_embd
         UpperCAmelCase_     :				List[str]  =     n_layer
         UpperCAmelCase_     :				Optional[int]  =     n_head
         UpperCAmelCase_     :				List[Any]  =     afn
         UpperCAmelCase_     :				Union[str, Any]  =     resid_pdrop
         UpperCAmelCase_     :				Tuple  =     embd_pdrop
         UpperCAmelCase_     :				Union[str, Any]  =     attn_pdrop
         UpperCAmelCase_     :				Optional[int]  =     layer_norm_epsilon
         UpperCAmelCase_     :				List[Any]  =     initializer_range
         UpperCAmelCase_     :				List[str]  =     summary_type
         UpperCAmelCase_     :				str  =     summary_use_proj
         UpperCAmelCase_     :				List[Any]  =     summary_activation
         UpperCAmelCase_     :				Optional[int]  =     summary_first_dropout
         UpperCAmelCase_     :				List[Any]  =     summary_proj_to_labels
         super().__init__(**_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  ):






    """simple docstring"""





    @slow
    def 				a__ ( self    )					->						List[str]:
         UpperCAmelCase_     :				Tuple  =     AutoImageProcessor.from_pretrained('''microsoft/dit-base-finetuned-rvlcdip'''    )
         UpperCAmelCase_     :				Union[str, Any]  =     AutoModelForImageClassification.from_pretrained('''microsoft/dit-base-finetuned-rvlcdip'''    )
         model.to(_SCREAMING_SNAKE_CASE    )

         from datasets import load_dataset

         UpperCAmelCase_     :				Optional[int]  =     load_dataset('''nielsr/rvlcdip-demo'''    )

         UpperCAmelCase_     :				Optional[Any]  =     dataset['''train'''][0]['''image'''].convert('''RGB'''    )

         UpperCAmelCase_     :				str  =     image_processor(_SCREAMING_SNAKE_CASE  ,return_tensors='''pt'''    ).to(_SCREAMING_SNAKE_CASE    )

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

         UpperCAmelCase_     :				Tuple  =     torch.Size((1, 16)    )
         self.assertEqual(logits.shape  ,_SCREAMING_SNAKE_CASE    )

         UpperCAmelCase_     :				int  =     torch.tensor(
             [-0.41_58, -0.40_92, -0.43_47]  ,device=_SCREAMING_SNAKE_CASE  ,dtype=torch.float  ,)
         self.assertTrue(torch.allclose(logits[0, :3]  ,_SCREAMING_SNAKE_CASE  ,atol=1e-4    )    )