


'''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						):





							'''simple docstring'''






							lowercase__    :     List[Any]					=   MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING







							def 						__SCREAMING_SNAKE_CASE							(	self      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_     ) ->							Dict:
														lowerCAmelCase__      =			hf_hub_download(
														    repo_id='''nateraw/video-demo'''      ,					filename='''archery.mp4'''      ,					repo_type='''dataset'''     )
														lowerCAmelCase__      =			VideoClassificationPipeline(model=_lowercase      ,					image_processor=_lowercase      ,					top_k=2     )
														lowerCAmelCase__      =			[
														    example_video_filepath,
														    '''https://huggingface.co/datasets/nateraw/video-demo/resolve/main/archery.mp4''',
														]
														return video_classifier, examples







							def 						__SCREAMING_SNAKE_CASE							(	self      ,					lowerCamelCase_      ,					lowerCamelCase_     ) ->							Dict:
														for example in examples:
																					lowerCAmelCase__      =			video_classifier(_lowercase     )

																					self.assertEqual(
																					    _lowercase      ,					[
																					        {'''score''': ANY(_lowercase     ), '''label''': ANY(_lowercase     )},
																					        {'''score''': ANY(_lowercase     ), '''label''': ANY(_lowercase     )},
																					    ]      ,					)







							@require_torch
							def 						__SCREAMING_SNAKE_CASE							(	self     ) ->							List[str]:
														lowerCAmelCase__      =			'''hf-internal-testing/tiny-random-VideoMAEForVideoClassification'''
														lowerCAmelCase__      =			VideoMAEFeatureExtractor(
														    size={'''shortest_edge''': 10}      ,					crop_size={'''height''': 10, '''width''': 10}     )
														lowerCAmelCase__      =			pipeline(
														    '''video-classification'''      ,					model=_lowercase      ,					feature_extractor=_lowercase      ,					frame_sampling_rate=4     )

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

														lowerCAmelCase__      =			video_classifier(
														    [
														        video_file_path,
														        video_file_path,
														    ]      ,					top_k=2      ,					)
														self.assertEqual(
														    nested_simplify(_lowercase      ,					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 						__SCREAMING_SNAKE_CASE							(	self     ) ->							Optional[Any]:
														pass



'''simple docstring'''






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


__UpperCAmelCase					       =							logging.get_logger(__name__)

__UpperCAmelCase					       =							{'''ctrl''': '''https://huggingface.co/ctrl/resolve/main/config.json'''}




class 	a__       (							a__						):





							'''simple docstring'''






							lowercase__    :     Dict					=   "ctrl"
							lowercase__    :     str					=   ["past_key_values"]
							lowercase__    :     Optional[int]					=   {
							    "max_position_embeddings": "n_positions",
							    "hidden_size": "n_embd",
							    "num_attention_heads": "n_head",
							    "num_hidden_layers": "n_layer",
							}







							def __init__(	self      ,					lowerCamelCase_=24_65_34      ,					lowerCamelCase_=2_56      ,					lowerCamelCase_=12_80      ,					lowerCamelCase_=81_92      ,					lowerCamelCase_=48      ,					lowerCamelCase_=16      ,					lowerCamelCase_=0.1      ,					lowerCamelCase_=0.1      ,					lowerCamelCase_=1e-6      ,					lowerCamelCase_=0.02      ,					lowerCamelCase_=True      ,					**lowerCamelCase_      ,					) ->							Union[str, Any]:
														lowerCAmelCase__      =			vocab_size
														lowerCAmelCase__      =			n_positions
														lowerCAmelCase__      =			n_embd
														lowerCAmelCase__      =			n_layer
														lowerCAmelCase__      =			n_head
														lowerCAmelCase__      =			dff
														lowerCAmelCase__      =			resid_pdrop
														lowerCAmelCase__      =			embd_pdrop
														lowerCAmelCase__      =			layer_norm_epsilon
														lowerCAmelCase__      =			initializer_range

														lowerCAmelCase__      =			use_cache

														super().__init__(**lowerCamelCase_     )