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


_UpperCAmelCase		:       Tuple						    =	logging.get_logger(__name__)

_UpperCAmelCase		:       Optional[Any]						    =	{
    """tiiuae/falcon-40b""": """https://huggingface.co/tiiuae/falcon-40b/resolve/main/config.json""",
    """tiiuae/falcon-7b""": """https://huggingface.co/tiiuae/falcon-7b/resolve/main/config.json""",
}







class 			lowercase    (	__A      ):
				__SCREAMING_SNAKE_CASE :			List[str]	      =      'falcon'
				__SCREAMING_SNAKE_CASE :			Optional[int]	      =      ['past_key_values']




				def __init__( self				,       snake_case=6_5024				,       snake_case=4544				,       snake_case=32				,       snake_case=71				,       snake_case=1e-5				,       snake_case=0.02				,       snake_case=True				,       snake_case=0.0				,       snake_case=0.0				,       snake_case=None				,       snake_case=False				,       snake_case=False				,       snake_case=True				,       snake_case=True				,       snake_case=False				,       snake_case=11				,       snake_case=11				,       **snake_case				,       ):
											snake_case_          =   vocab_size
											# Backward compatibility with n_embed kwarg
											snake_case_          =   kwargs.pop('n_embed'				,       __lowercase	)
											snake_case_          =   hidden_size if n_embed is None else n_embed
											snake_case_          =   num_hidden_layers
											snake_case_          =   num_attention_heads
											snake_case_          =   layer_norm_epsilon
											snake_case_          =   initializer_range
											snake_case_          =   use_cache
											snake_case_          =   hidden_dropout
											snake_case_          =   attention_dropout

											snake_case_          =   bos_token_id
											snake_case_          =   eos_token_id
											snake_case_          =   num_attention_heads if num_kv_heads is None else num_kv_heads
											snake_case_          =   alibi
											snake_case_          =   new_decoder_architecture
											snake_case_          =   multi_query  # Ignored when new_decoder_architecture is True
											snake_case_          =   parallel_attn
											snake_case_          =   bias

											super().__init__(bos_token_id=__lowercase				,       eos_token_id=__lowercase				,       **__lowercase	)




				@property
				def    a							( self	):
											return self.hidden_size // self.num_attention_heads




				@property
				def    a							( self	):
											return not self.alibi







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 			lowercase    (	unittest.TestCase      ):




				@slow
				def    a							( self	):
											snake_case_          =   AutoImageProcessor.from_pretrained('microsoft/dit-base-finetuned-rvlcdip'	)
											snake_case_          =   AutoModelForImageClassification.from_pretrained('microsoft/dit-base-finetuned-rvlcdip'	)
											model.to(snake_case	)

											from datasets import load_dataset

											snake_case_          =   load_dataset('nielsr/rvlcdip-demo'	)

											snake_case_          =   dataset['train'][0]['image'].convert('RGB'	)

											snake_case_          =   image_processor(snake_case				,       return_tensors='pt'	).to(snake_case	)

											# forward pass
											with torch.no_grad():
																		snake_case_          =   model(**snake_case	)
																		snake_case_          =   outputs.logits

											snake_case_          =   torch.Size((1, 16)	)
											self.assertEqual(logits.shape				,       snake_case	)

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




