





"""simple docstring"""





import functools
import operator

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


lowerCAmelCase__     			=			logging.get_logger(__name__)

lowerCAmelCase__     			=			{
    '''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        _lowerCamelCase      (       _lowercase ):
						UpperCAmelCase_ =			"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   ,							) ->   int:
								super().__init__(**__a   ,							pad_token_id=__a   ,							bos_token_id=__a   ,							eos_token_id=__a		)
								UpperCamelCase   =	hidden_size
								UpperCamelCase   =	feat_extract_norm
								UpperCamelCase   =	feat_extract_activation
								UpperCamelCase   =	list(__a		)
								UpperCamelCase   =	list(__a		)
								UpperCamelCase   =	list(__a		)
								UpperCamelCase   =	conv_bias
								UpperCamelCase   =	num_conv_pos_embeddings
								UpperCamelCase   =	num_conv_pos_embedding_groups
								UpperCamelCase   =	len(self.conv_dim		)
								UpperCamelCase   =	num_hidden_layers
								UpperCamelCase   =	intermediate_size
								UpperCamelCase   =	hidden_act
								UpperCamelCase   =	num_attention_heads
								UpperCamelCase   =	hidden_dropout
								UpperCamelCase   =	attention_dropout
								UpperCamelCase   =	activation_dropout
								UpperCamelCase   =	feat_proj_dropout
								UpperCamelCase   =	final_dropout
								UpperCamelCase   =	layerdrop
								UpperCamelCase   =	layer_norm_eps
								UpperCamelCase   =	initializer_range
								UpperCamelCase   =	vocab_size
								UpperCamelCase   =	do_stable_layer_norm
								UpperCamelCase   =	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
								UpperCamelCase   =	apply_spec_augment
								UpperCamelCase   =	mask_time_prob
								UpperCamelCase   =	mask_time_length
								UpperCamelCase   =	mask_time_min_masks
								UpperCamelCase   =	mask_feature_prob
								UpperCamelCase   =	mask_feature_length
								UpperCamelCase   =	mask_feature_min_masks

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

								# ctc loss
								UpperCamelCase   =	ctc_loss_reduction
								UpperCamelCase   =	ctc_zero_infinity

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

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

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




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







"""simple docstring"""





import unittest

from huggingface_hub import hf_hub_download

from transformers import MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING, VideoMAEFeatureExtractor
from transformers.pipelines import VideoClassificationPipeline, pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_decord,
    require_tf,
    require_torch,
    require_torch_or_tf,
    require_vision,
)

from .test_pipelines_common import ANY





@is_pipeline_test
@require_torch_or_tf
@require_vision
@require_decord
class        _lowerCamelCase      (       unittest.TestCase ):
						UpperCAmelCase_ =			MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING


						def     snake_case_   (self   ,							__a   ,							__a   ,							__a		) ->   str:
								UpperCamelCase   =	hf_hub_download(
								    repo_id="nateraw/video-demo"   ,							filename="archery.mp4"   ,							repo_type="dataset"		)
								UpperCamelCase   =	VideoClassificationPipeline(model=__a   ,							image_processor=__a   ,							top_k=2		)
								UpperCamelCase   =	[
								    example_video_filepath,
								    "https://huggingface.co/datasets/nateraw/video-demo/resolve/main/archery.mp4",
								]
								return video_classifier, examples


						def     snake_case_   (self   ,							__a   ,							__a		) ->   str:
								for example in examples:
										UpperCamelCase   =	video_classifier(__a		)

										self.assertEqual(
										    __a   ,							[
										        {"score": ANY(__a		), "label": ANY(__a		)},
										        {"score": ANY(__a		), "label": ANY(__a		)},
										    ]   ,							)


						@require_torch
						def     snake_case_   (self		) ->   int:
								UpperCamelCase   =	"hf-internal-testing/tiny-random-VideoMAEForVideoClassification"
								UpperCamelCase   =	VideoMAEFeatureExtractor(
								    size={"shortest_edge": 10}   ,							crop_size={"height": 10, "width": 10}		)
								UpperCamelCase   =	pipeline(
								    "video-classification"   ,							model=__a   ,							feature_extractor=__a   ,							frame_sampling_rate=4		)

								UpperCamelCase   =	hf_hub_download(repo_id="nateraw/video-demo"   ,							filename="archery.mp4"   ,							repo_type="dataset"		)
								UpperCamelCase   =	video_classifier(__a   ,							top_k=2		)
								self.assertEqual(
								    nested_simplify(__a   ,							decimals=4		)   ,							[{"score": 0.5199, "label": "LABEL_0"}, {"score": 0.4801, "label": "LABEL_1"}]   ,							)

								UpperCamelCase   =	video_classifier(
								    [
								        video_file_path,
								        video_file_path,
								    ]   ,							top_k=2   ,							)
								self.assertEqual(
								    nested_simplify(__a   ,							decimals=4		)   ,							[
								        [{"score": 0.5199, "label": "LABEL_0"}, {"score": 0.4801, "label": "LABEL_1"}],
								        [{"score": 0.5199, "label": "LABEL_0"}, {"score": 0.4801, "label": "LABEL_1"}],
								    ]   ,							)




						@require_tf
						def     snake_case_   (self		) ->   Optional[Any]:
								pass






