






import functools
import operator

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


lowercase  							=					logging.get_logger(__name__)

lowercase  							=					{
    "facebook/wav2vec2-base-960h": "https://huggingface.co/facebook/wav2vec2-base-960h/resolve/main/config.json",
    # See all Wav2Vec2 models at https://huggingface.co/models?filter=wav2vec2
}




class  UpperCamelCase_      (			snake_case_				):



	'''simple docstring'''




	lowerCAmelCase													= '''wav2vec2'''




	def __init__(       self       ,			a=32       ,			a=7_68       ,			a=12       ,			a=12       ,			a=30_72       ,			a="gelu"       ,			a=0.1       ,			a=0.1       ,			a=0.1       ,			a=0.0       ,			a=0.0       ,			a=0.1       ,			a=0.1       ,			a=0.02       ,			a=1E-5       ,			a="group"       ,			a="gelu"       ,			a=(5_12, 5_12, 5_12, 5_12, 5_12, 5_12, 5_12)       ,			a=(5, 2, 2, 2, 2, 2, 2)       ,			a=(10, 3, 3, 3, 3, 2, 2)       ,			a=False       ,			a=1_28       ,			a=16       ,			a=False       ,			a=True       ,			a=0.05       ,			a=10       ,			a=2       ,			a=0.0       ,			a=10       ,			a=0       ,			a=3_20       ,			a=2       ,			a=0.1       ,			a=1_00       ,			a=2_56       ,			a=2_56       ,			a=0.1       ,			a="sum"       ,			a=False       ,			a=False       ,			a=2_56       ,			a=(5_12, 5_12, 5_12, 5_12, 15_00)       ,			a=(5, 3, 3, 1, 1)       ,			a=(1, 2, 3, 1, 1)       ,			a=5_12       ,			a=0       ,			a=1       ,			a=2       ,			a=False       ,			a=3       ,			a=2       ,			a=3       ,			a=None       ,			a=None       ,			**a       ,			)       ->    Optional[Any]:
								super().__init__(**a       ,			pad_token_id=a       ,			bos_token_id=a       ,			eos_token_id=a					)
								snake_case_				=							hidden_size
								snake_case_				=							feat_extract_norm
								snake_case_				=							feat_extract_activation
								snake_case_				=							list(a					)
								snake_case_				=							list(a					)
								snake_case_				=							list(a					)
								snake_case_				=							conv_bias
								snake_case_				=							num_conv_pos_embeddings
								snake_case_				=							num_conv_pos_embedding_groups
								snake_case_				=							len(self.conv_dim					)
								snake_case_				=							num_hidden_layers
								snake_case_				=							intermediate_size
								snake_case_				=							hidden_act
								snake_case_				=							num_attention_heads
								snake_case_				=							hidden_dropout
								snake_case_				=							attention_dropout
								snake_case_				=							activation_dropout
								snake_case_				=							feat_proj_dropout
								snake_case_				=							final_dropout
								snake_case_				=							layerdrop
								snake_case_				=							layer_norm_eps
								snake_case_				=							initializer_range
								snake_case_				=							vocab_size
								snake_case_				=							do_stable_layer_norm
								snake_case_				=							use_weighted_layer_sum

								if (
								    (len(self.conv_stride					) != self.num_feat_extract_layers)
								    or (len(self.conv_kernel					) != self.num_feat_extract_layers)
								    or (len(self.conv_dim					) != self.num_feat_extract_layers)
								):
															raise ValueError(
															    'Configuration for convolutional layers is incorrect. It is required that `len(config.conv_dim)` =='
															    ' `len(config.conv_stride)` == `len(config.conv_kernel)`, but is `len(config.conv_dim) ='
															    F''' {len(self.conv_dim					)}`, `len(config.conv_stride) = {len(self.conv_stride					)}`,'''
															    F''' `len(config.conv_kernel) = {len(self.conv_kernel					)}`.'''					)

								# fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
								snake_case_				=							apply_spec_augment
								snake_case_				=							mask_time_prob
								snake_case_				=							mask_time_length
								snake_case_				=							mask_time_min_masks
								snake_case_				=							mask_feature_prob
								snake_case_				=							mask_feature_length
								snake_case_				=							mask_feature_min_masks

								# parameters for pretraining with codevector quantized representations
								snake_case_				=							num_codevectors_per_group
								snake_case_				=							num_codevector_groups
								snake_case_				=							contrastive_logits_temperature
								snake_case_				=							feat_quantizer_dropout
								snake_case_				=							num_negatives
								snake_case_				=							codevector_dim
								snake_case_				=							proj_codevector_dim
								snake_case_				=							diversity_loss_weight

								# ctc loss
								snake_case_				=							ctc_loss_reduction
								snake_case_				=							ctc_zero_infinity

								# adapter
								snake_case_				=							add_adapter
								snake_case_				=							adapter_kernel_size
								snake_case_				=							adapter_stride
								snake_case_				=							num_adapter_layers
								snake_case_				=							output_hidden_size or hidden_size
								snake_case_				=							adapter_attn_dim

								# SequenceClassification-specific parameter. Feel free to ignore for other classes.
								snake_case_				=							classifier_proj_size

								# XVector-specific parameters. Feel free to ignore for other classes.
								snake_case_				=							list(a					)
								snake_case_				=							list(a					)
								snake_case_				=							list(a					)
								snake_case_				=							xvector_output_dim






	@property
	def 							_UpperCamelCase			(       self					)       ->    Union[str, Any]:
								return functools.reduce(operator.mul       ,			self.conv_stride       ,			1					)













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



	'''simple docstring'''




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

								from datasets import load_dataset

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

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

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

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

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

								snake_case_				=							torch.tensor(
								    [-0.4_158, -0.4_092, -0.4_347]       ,			device=a       ,			dtype=torch.float       ,			)
								self.assertTrue(torch.allclose(logits[0, :3]       ,			a       ,			atol=1E-4					)					)





