"""simple docstring"""


import math

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


lowerCAmelCase_:					str     =					logging.get_logger(__name__)

lowerCAmelCase_:					Tuple     =					{
    "facebook/data2vec-base-960h": "https://huggingface.co/facebook/data2vec-audio-base-960h/resolve/main/config.json",
    # See all Data2VecAudio models at https://huggingface.co/models?filter=data2vec-audio
}






class    a__    (   _a	):
   snake_case_							=      "data2vec-audio"


   def __init__(     self,				_UpperCAmelCase=32,				_UpperCAmelCase=768,				_UpperCAmelCase=12,				_UpperCAmelCase=12,				_UpperCAmelCase=3072,				_UpperCAmelCase="gelu",				_UpperCAmelCase=0.1,				_UpperCAmelCase=0.1,				_UpperCAmelCase=0.1,				_UpperCAmelCase=0.0,				_UpperCAmelCase=0.1,				_UpperCAmelCase=0.1,				_UpperCAmelCase=0.02,				_UpperCAmelCase=1E-5,				_UpperCAmelCase="gelu",				_UpperCAmelCase=(512, 512, 512, 512, 512, 512, 512),				_UpperCAmelCase=(5, 2, 2, 2, 2, 2, 2),				_UpperCAmelCase=(10, 3, 3, 3, 3, 2, 2),				_UpperCAmelCase=False,				_UpperCAmelCase=16,				_UpperCAmelCase=19,				_UpperCAmelCase=5,				_UpperCAmelCase=0.05,				_UpperCAmelCase=10,				_UpperCAmelCase=2,				_UpperCAmelCase=0.0,				_UpperCAmelCase=10,				_UpperCAmelCase=0,				_UpperCAmelCase="sum",				_UpperCAmelCase=False,				_UpperCAmelCase=False,				_UpperCAmelCase=256,				_UpperCAmelCase=(512, 512, 512, 512, 1500),				_UpperCAmelCase=(5, 3, 3, 1, 1),				_UpperCAmelCase=(1, 2, 3, 1, 1),				_UpperCAmelCase=512,				_UpperCAmelCase=0,				_UpperCAmelCase=1,				_UpperCAmelCase=2,				_UpperCAmelCase=False,				_UpperCAmelCase=3,				_UpperCAmelCase=2,				_UpperCAmelCase=3,				_UpperCAmelCase=None,				**_UpperCAmelCase,				):
        '''simple docstring'''



        super().__init__(**_UpperCAmelCase,				pad_token_id=_UpperCAmelCase,				bos_token_id=_UpperCAmelCase,				eos_token_id=_UpperCAmelCase  )
        lowercase__				 =							hidden_size
        lowercase__				 =							feat_extract_activation
        lowercase__				 =							list(_UpperCAmelCase  )
        lowercase__				 =							list(_UpperCAmelCase  )
        lowercase__				 =							list(_UpperCAmelCase  )
        lowercase__				 =							conv_bias
        lowercase__				 =							num_conv_pos_embeddings
        lowercase__				 =							num_conv_pos_embedding_groups
        lowercase__				 =							conv_pos_kernel_size
        lowercase__				 =							len(self.conv_dim  )
        lowercase__				 =							num_hidden_layers
        lowercase__				 =							intermediate_size
        lowercase__				 =							hidden_act
        lowercase__				 =							num_attention_heads
        lowercase__				 =							hidden_dropout
        lowercase__				 =							attention_dropout
        lowercase__				 =							activation_dropout
        lowercase__				 =							feat_proj_dropout
        lowercase__				 =							final_dropout
        lowercase__				 =							layerdrop
        lowercase__				 =							layer_norm_eps
        lowercase__				 =							initializer_range
        lowercase__				 =							vocab_size
        lowercase__				 =							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
        lowercase__				 =							mask_time_prob
        lowercase__				 =							mask_time_length
        lowercase__				 =							mask_time_min_masks
        lowercase__				 =							mask_feature_prob
        lowercase__				 =							mask_feature_length
        lowercase__				 =							mask_feature_min_masks

        # ctc loss
        lowercase__				 =							ctc_loss_reduction
        lowercase__				 =							ctc_zero_infinity

        # adapter
        lowercase__				 =							add_adapter
        lowercase__				 =							adapter_kernel_size
        lowercase__				 =							adapter_stride
        lowercase__				 =							num_adapter_layers
        lowercase__				 =							output_hidden_size or hidden_size

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

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


   @property
   def 	snake_case__	(     self  ):
        '''simple docstring'''



        return math.prod(self.conv_stride  )





"""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    a__    (   unittest.TestCase	):
   snake_case_							=      MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING


   def 	snake_case__	(     self,				_UpperCAmelCase,				_UpperCAmelCase,				_UpperCAmelCase  ):
        '''simple docstring'''



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


   def 	snake_case__	(     self,				_UpperCAmelCase,				_UpperCAmelCase  ):
        '''simple docstring'''



        for example in examples:
             lowercase__				 =							video_classifier(_UpperCAmelCase  )

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


   @require_torch
   def 	snake_case__	(     self  ):
        '''simple docstring'''



        lowercase__				 =							"hf-internal-testing/tiny-random-VideoMAEForVideoClassification"
        lowercase__				 =							VideoMAEFeatureExtractor(
            size={"shortest_edge": 10},				crop_size={"height": 10, "width": 10}  )
        lowercase__				 =							pipeline(
            "video-classification",				model=_UpperCAmelCase,				feature_extractor=_UpperCAmelCase,				frame_sampling_rate=4  )

        lowercase__				 =							hf_hub_download(repo_id="nateraw/video-demo",				filename="archery.mp4",				repo_type="dataset"  )
        lowercase__				 =							video_classifier(_UpperCAmelCase,				top_k=2  )
        self.assertEqual(
            nested_simplify(_UpperCAmelCase,				decimals=4  ),				[{"score": 0.5_199, "label": "LABEL_0"}, {"score": 0.4_801, "label": "LABEL_1"}],				)

        lowercase__				 =							video_classifier(
            [
                video_file_path,
                video_file_path,
            ],				top_k=2,				)
        self.assertEqual(
            nested_simplify(_UpperCAmelCase,				decimals=4  ),				[
                [{"score": 0.5_199, "label": "LABEL_0"}, {"score": 0.4_801, "label": "LABEL_1"}],
                [{"score": 0.5_199, "label": "LABEL_0"}, {"score": 0.4_801, "label": "LABEL_1"}],
            ],				)


   @require_tf
   def 	snake_case__	(     self  ):
        '''simple docstring'''



        pass




