


import functools
import operator

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


__lowerCAmelCase	: Optional[Any]  				=logging.get_logger(__name__)

__lowerCAmelCase	: List[str]  				={
    '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        _lowercase      (			A__       ):






				'''simple docstring'''



				SCREAMING_SNAKE_CASE__				:			Any						=		'''wav2vec2'''


				def __init__(       self			:Any			,			lowerCAmelCase__			:Optional[Any]=32			,			lowerCAmelCase__			:Optional[int]=768			,			lowerCAmelCase__			:Tuple=12			,			lowerCAmelCase__			:List[str]=12			,			lowerCAmelCase__			:Any=3_072			,			lowerCAmelCase__			:Dict="gelu"			,			lowerCAmelCase__			:Dict=0.1			,			lowerCAmelCase__			:List[str]=0.1			,			lowerCAmelCase__			:str=0.1			,			lowerCAmelCase__			:Any=0.0			,			lowerCAmelCase__			:Union[str, Any]=0.0			,			lowerCAmelCase__			:Optional[Any]=0.1			,			lowerCAmelCase__			:Optional[Any]=0.1			,			lowerCAmelCase__			:List[Any]=0.02			,			lowerCAmelCase__			:Optional[int]=1E-5			,			lowerCAmelCase__			:Tuple="group"			,			lowerCAmelCase__			:Optional[int]="gelu"			,			lowerCAmelCase__			:Dict=(512, 512, 512, 512, 512, 512, 512)			,			lowerCAmelCase__			:Any=(5, 2, 2, 2, 2, 2, 2)			,			lowerCAmelCase__			:Optional[int]=(10, 3, 3, 3, 3, 2, 2)			,			lowerCAmelCase__			:List[Any]=False			,			lowerCAmelCase__			:Dict=128			,			lowerCAmelCase__			:List[Any]=16			,			lowerCAmelCase__			:int=False			,			lowerCAmelCase__			:List[Any]=True			,			lowerCAmelCase__			:str=0.05			,			lowerCAmelCase__			:Any=10			,			lowerCAmelCase__			:Dict=2			,			lowerCAmelCase__			:Any=0.0			,			lowerCAmelCase__			:Optional[Any]=10			,			lowerCAmelCase__			:List[Any]=0			,			lowerCAmelCase__			:List[str]=320			,			lowerCAmelCase__			:Union[str, Any]=2			,			lowerCAmelCase__			:str=0.1			,			lowerCAmelCase__			:Union[str, Any]=100			,			lowerCAmelCase__			:str=256			,			lowerCAmelCase__			:List[str]=256			,			lowerCAmelCase__			:Any=0.1			,			lowerCAmelCase__			:Tuple="sum"			,			lowerCAmelCase__			:Dict=False			,			lowerCAmelCase__			:Dict=False			,			lowerCAmelCase__			:Union[str, Any]=256			,			lowerCAmelCase__			:Optional[Any]=(512, 512, 512, 512, 1_500)			,			lowerCAmelCase__			:Optional[int]=(5, 3, 3, 1, 1)			,			lowerCAmelCase__			:Any=(1, 2, 3, 1, 1)			,			lowerCAmelCase__			:Union[str, Any]=512			,			lowerCAmelCase__			:Any=0			,			lowerCAmelCase__			:Optional[Any]=1			,			lowerCAmelCase__			:Any=2			,			lowerCAmelCase__			:int=False			,			lowerCAmelCase__			:str=3			,			lowerCAmelCase__			:Tuple=2			,			lowerCAmelCase__			:Dict=3			,			lowerCAmelCase__			:int=None			,			lowerCAmelCase__			:Optional[int]=None			,			**lowerCAmelCase__			:Any			,			)		->			List[str]:
										super().__init__(**lowerCAmelCase__			,			pad_token_id=lowerCAmelCase__			,			bos_token_id=lowerCAmelCase__			,			eos_token_id=lowerCAmelCase__	)
										__SCREAMING_SNAKE_CASE						:     str					=		hidden_size
										__SCREAMING_SNAKE_CASE						:     List[Any]					=		feat_extract_norm
										__SCREAMING_SNAKE_CASE						:     List[str]					=		feat_extract_activation
										__SCREAMING_SNAKE_CASE						:     Optional[int]					=		list(lowerCAmelCase__	)
										__SCREAMING_SNAKE_CASE						:     List[str]					=		list(lowerCAmelCase__	)
										__SCREAMING_SNAKE_CASE						:     str					=		list(lowerCAmelCase__	)
										__SCREAMING_SNAKE_CASE						:     Dict					=		conv_bias
										__SCREAMING_SNAKE_CASE						:     Any					=		num_conv_pos_embeddings
										__SCREAMING_SNAKE_CASE						:     Tuple					=		num_conv_pos_embedding_groups
										__SCREAMING_SNAKE_CASE						:     Optional[int]					=		len(self.conv_dim	)
										__SCREAMING_SNAKE_CASE						:     Tuple					=		num_hidden_layers
										__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		intermediate_size
										__SCREAMING_SNAKE_CASE						:     Any					=		hidden_act
										__SCREAMING_SNAKE_CASE						:     Tuple					=		num_attention_heads
										__SCREAMING_SNAKE_CASE						:     int					=		hidden_dropout
										__SCREAMING_SNAKE_CASE						:     str					=		attention_dropout
										__SCREAMING_SNAKE_CASE						:     Dict					=		activation_dropout
										__SCREAMING_SNAKE_CASE						:     str					=		feat_proj_dropout
										__SCREAMING_SNAKE_CASE						:     Dict					=		final_dropout
										__SCREAMING_SNAKE_CASE						:     Optional[int]					=		layerdrop
										__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		layer_norm_eps
										__SCREAMING_SNAKE_CASE						:     str					=		initializer_range
										__SCREAMING_SNAKE_CASE						:     Tuple					=		vocab_size
										__SCREAMING_SNAKE_CASE						:     int					=		do_stable_layer_norm
										__SCREAMING_SNAKE_CASE						:     Tuple					=		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
										__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		apply_spec_augment
										__SCREAMING_SNAKE_CASE						:     List[Any]					=		mask_time_prob
										__SCREAMING_SNAKE_CASE						:     str					=		mask_time_length
										__SCREAMING_SNAKE_CASE						:     Any					=		mask_time_min_masks
										__SCREAMING_SNAKE_CASE						:     Optional[int]					=		mask_feature_prob
										__SCREAMING_SNAKE_CASE						:     int					=		mask_feature_length
										__SCREAMING_SNAKE_CASE						:     int					=		mask_feature_min_masks

										# parameters for pretraining with codevector quantized representations
										__SCREAMING_SNAKE_CASE						:     Dict					=		num_codevectors_per_group
										__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		num_codevector_groups
										__SCREAMING_SNAKE_CASE						:     Optional[int]					=		contrastive_logits_temperature
										__SCREAMING_SNAKE_CASE						:     Any					=		feat_quantizer_dropout
										__SCREAMING_SNAKE_CASE						:     List[Any]					=		num_negatives
										__SCREAMING_SNAKE_CASE						:     Tuple					=		codevector_dim
										__SCREAMING_SNAKE_CASE						:     List[str]					=		proj_codevector_dim
										__SCREAMING_SNAKE_CASE						:     Union[str, Any]					=		diversity_loss_weight

										# ctc loss
										__SCREAMING_SNAKE_CASE						:     Tuple					=		ctc_loss_reduction
										__SCREAMING_SNAKE_CASE						:     Optional[int]					=		ctc_zero_infinity

										# adapter
										__SCREAMING_SNAKE_CASE						:     str					=		add_adapter
										__SCREAMING_SNAKE_CASE						:     Union[str, Any]					=		adapter_kernel_size
										__SCREAMING_SNAKE_CASE						:     Any					=		adapter_stride
										__SCREAMING_SNAKE_CASE						:     List[str]					=		num_adapter_layers
										__SCREAMING_SNAKE_CASE						:     List[str]					=		output_hidden_size or hidden_size
										__SCREAMING_SNAKE_CASE						:     int					=		adapter_attn_dim

										# SequenceClassification-specific parameter. Feel free to ignore for other classes.
										__SCREAMING_SNAKE_CASE						:     Union[str, Any]					=		classifier_proj_size

										# XVector-specific parameters. Feel free to ignore for other classes.
										__SCREAMING_SNAKE_CASE						:     Optional[int]					=		list(lowerCAmelCase__	)
										__SCREAMING_SNAKE_CASE						:     Tuple					=		list(lowerCAmelCase__	)
										__SCREAMING_SNAKE_CASE						:     str					=		list(lowerCAmelCase__	)
										__SCREAMING_SNAKE_CASE						:     List[str]					=		xvector_output_dim



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




import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_video_inputs


if is_torch_available():
						import torch

if is_vision_available():
						from PIL import Image

						from transformers import VivitImageProcessor
class        _lowercase      (			unittest.TestCase       ):






				'''simple docstring'''



				def __init__(       self			:Any			,			lowerCAmelCase__			:Union[str, Any]			,			lowerCAmelCase__			:Tuple=7			,			lowerCAmelCase__			:List[Any]=3			,			lowerCAmelCase__			:Any=10			,			lowerCAmelCase__			:Optional[int]=18			,			lowerCAmelCase__			:Dict=30			,			lowerCAmelCase__			:Tuple=400			,			lowerCAmelCase__			:List[Any]=True			,			lowerCAmelCase__			:Tuple=None			,			lowerCAmelCase__			:str=True			,			lowerCAmelCase__			:List[str]=[0.5, 0.5, 0.5]			,			lowerCAmelCase__			:List[str]=[0.5, 0.5, 0.5]			,			lowerCAmelCase__			:Optional[Any]=None			,			)		->			Optional[Any]:
										__SCREAMING_SNAKE_CASE						:     Dict					=		size if size is not None else {'''shortest_edge''': 18}
										__SCREAMING_SNAKE_CASE						:     Optional[int]					=		crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}

										__SCREAMING_SNAKE_CASE						:     Tuple					=		parent
										__SCREAMING_SNAKE_CASE						:     List[Any]					=		batch_size
										__SCREAMING_SNAKE_CASE						:     List[str]					=		num_channels
										__SCREAMING_SNAKE_CASE						:     Union[str, Any]					=		num_frames
										__SCREAMING_SNAKE_CASE						:     Tuple					=		image_size
										__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		min_resolution
										__SCREAMING_SNAKE_CASE						:     Any					=		max_resolution
										__SCREAMING_SNAKE_CASE						:     List[Any]					=		do_resize
										__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		size
										__SCREAMING_SNAKE_CASE						:     Optional[int]					=		do_normalize
										__SCREAMING_SNAKE_CASE						:     List[Any]					=		image_mean
										__SCREAMING_SNAKE_CASE						:     List[str]					=		image_std
										__SCREAMING_SNAKE_CASE						:     str					=		crop_size



				def 		__magic_name__(       self			:Tuple	)		->			Any:
										return {
										    "image_mean": self.image_mean,
										    "image_std": self.image_std,
										    "do_normalize": self.do_normalize,
										    "do_resize": self.do_resize,
										    "size": self.size,
										    "crop_size": self.crop_size,
										}




@require_torch
@require_vision
class        _lowercase      (			A__						,			unittest.TestCase       ):






				'''simple docstring'''



				SCREAMING_SNAKE_CASE__				:			List[str]						=		VivitImageProcessor if is_vision_available() else None


				def 		__magic_name__(       self			:List[str]	)		->			Union[str, Any]:
										__SCREAMING_SNAKE_CASE						:     str					=		VivitImageProcessingTester(self	)


				@property
				def 		__magic_name__(       self			:int	)		->			Union[str, Any]:
										return self.image_processor_tester.prepare_image_processor_dict()


				def 		__magic_name__(       self			:List[str]	)		->			Optional[int]:
										__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		self.image_processing_class(**self.image_processor_dict	)
										self.assertTrue(hasattr(lowerCAmelCase__			,			'''image_mean'''	)	)
										self.assertTrue(hasattr(lowerCAmelCase__			,			'''image_std'''	)	)
										self.assertTrue(hasattr(lowerCAmelCase__			,			'''do_normalize'''	)	)
										self.assertTrue(hasattr(lowerCAmelCase__			,			'''do_resize'''	)	)
										self.assertTrue(hasattr(lowerCAmelCase__			,			'''do_center_crop'''	)	)
										self.assertTrue(hasattr(lowerCAmelCase__			,			'''size'''	)	)


				def 		__magic_name__(       self			:Optional[Any]	)		->			Optional[int]:
										__SCREAMING_SNAKE_CASE						:     Union[str, Any]					=		self.image_processing_class.from_dict(self.image_processor_dict	)
										self.assertEqual(image_processor.size			,			{'''shortest_edge''': 18}	)
										self.assertEqual(image_processor.crop_size			,			{'''height''': 18, '''width''': 18}	)

										__SCREAMING_SNAKE_CASE						:     Tuple					=		self.image_processing_class.from_dict(self.image_processor_dict			,			size=42			,			crop_size=84	)
										self.assertEqual(image_processor.size			,			{'''shortest_edge''': 42}	)
										self.assertEqual(image_processor.crop_size			,			{'''height''': 84, '''width''': 84}	)


				def 		__magic_name__(       self			:List[Any]	)		->			Union[str, Any]:
										# Initialize image_processing
										__SCREAMING_SNAKE_CASE						:     Dict					=		self.image_processing_class(**self.image_processor_dict	)
										# create random PIL videos
										__SCREAMING_SNAKE_CASE						:     List[Any]					=		prepare_video_inputs(self.image_processor_tester			,			equal_resolution=lowerCAmelCase__	)
										for video in video_inputs:
																self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)
																self.assertIsInstance(video[0]			,			Image.Image	)

										# Test not batched input
										__SCREAMING_SNAKE_CASE						:     List[str]					=		image_processing(video_inputs[0]			,			return_tensors='''pt'''	).pixel_values
										self.assertEqual(
										    encoded_videos.shape			,			(
										        1,
										        self.image_processor_tester.num_frames,
										        self.image_processor_tester.num_channels,
										        self.image_processor_tester.crop_size['''height'''],
										        self.image_processor_tester.crop_size['''width'''],
										    )			,			)

										# Test batched
										__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		image_processing(lowerCAmelCase__			,			return_tensors='''pt'''	).pixel_values
										self.assertEqual(
										    encoded_videos.shape			,			(
										        self.image_processor_tester.batch_size,
										        self.image_processor_tester.num_frames,
										        self.image_processor_tester.num_channels,
										        self.image_processor_tester.crop_size['''height'''],
										        self.image_processor_tester.crop_size['''width'''],
										    )			,			)


				def 		__magic_name__(       self			:str	)		->			int:
										# Initialize image_processing
										__SCREAMING_SNAKE_CASE						:     Any					=		self.image_processing_class(**self.image_processor_dict	)
										# create random numpy tensors
										__SCREAMING_SNAKE_CASE						:     List[str]					=		prepare_video_inputs(self.image_processor_tester			,			equal_resolution=lowerCAmelCase__			,			numpify=lowerCAmelCase__	)
										for video in video_inputs:
																self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)
																self.assertIsInstance(video[0]			,			np.ndarray	)

										# Test not batched input
										__SCREAMING_SNAKE_CASE						:     Optional[int]					=		image_processing(video_inputs[0]			,			return_tensors='''pt'''	).pixel_values
										self.assertEqual(
										    encoded_videos.shape			,			(
										        1,
										        self.image_processor_tester.num_frames,
										        self.image_processor_tester.num_channels,
										        self.image_processor_tester.crop_size['''height'''],
										        self.image_processor_tester.crop_size['''width'''],
										    )			,			)

										# Test batched
										__SCREAMING_SNAKE_CASE						:     Any					=		image_processing(lowerCAmelCase__			,			return_tensors='''pt'''	).pixel_values
										self.assertEqual(
										    encoded_videos.shape			,			(
										        self.image_processor_tester.batch_size,
										        self.image_processor_tester.num_frames,
										        self.image_processor_tester.num_channels,
										        self.image_processor_tester.crop_size['''height'''],
										        self.image_processor_tester.crop_size['''width'''],
										    )			,			)



				def 		__magic_name__(       self			:Any	)		->			List[str]:
										# Initialize image_processing
										__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		self.image_processing_class(**self.image_processor_dict	)
										# create random PyTorch tensors
										__SCREAMING_SNAKE_CASE						:     Optional[int]					=		prepare_video_inputs(self.image_processor_tester			,			equal_resolution=lowerCAmelCase__			,			torchify=lowerCAmelCase__	)
										for video in video_inputs:
																self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)
																self.assertIsInstance(video[0]			,			torch.Tensor	)

										# Test not batched input
										__SCREAMING_SNAKE_CASE						:     Tuple					=		image_processing(video_inputs[0]			,			return_tensors='''pt'''	).pixel_values
										self.assertEqual(
										    encoded_videos.shape			,			(
										        1,
										        self.image_processor_tester.num_frames,
										        self.image_processor_tester.num_channels,
										        self.image_processor_tester.crop_size['''height'''],
										        self.image_processor_tester.crop_size['''width'''],
										    )			,			)

										# Test batched
										__SCREAMING_SNAKE_CASE						:     Optional[int]					=		image_processing(lowerCAmelCase__			,			return_tensors='''pt'''	).pixel_values
										self.assertEqual(
										    encoded_videos.shape			,			(
										        self.image_processor_tester.batch_size,
										        self.image_processor_tester.num_frames,
										        self.image_processor_tester.num_channels,
										        self.image_processor_tester.crop_size['''height'''],
										        self.image_processor_tester.crop_size['''width'''],
										    )			,			)
