




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






				'''simple docstring'''
				__UpperCamelCase			  =						MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING





				def    _lowerCAmelCase				(       self		, _a		, _a		, _a ):





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





				def    _lowerCAmelCase				(       self		, _a		, _a ):





							"""simple docstring"""
							for example in examples:
										lowerCamelCase			      =					video_classifier(_a )

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





				@require_torch
				def    _lowerCAmelCase				(       self ):





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

							lowerCamelCase			      =					hf_hub_download(repo_id="""nateraw/video-demo"""		, filename="""archery.mp4"""		, repo_type="""dataset""" )
							lowerCamelCase			      =					video_classifier(_a		, top_k=2 )
							self.assertEqual(
							    nested_simplify(_a		, 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(_a		, 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    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							pass









"""simple docstring"""




import operator as op


lowerCAmelCase							:			Dict     							=							"""scaler.pt"""
lowerCAmelCase							:			Tuple     							=							"""pytorch_model"""
lowerCAmelCase							:			Union[str, Any]     							=							"""random_states"""
lowerCAmelCase							:			Union[str, Any]     							=							"""optimizer"""
lowerCAmelCase							:			Dict     							=							"""scheduler"""
lowerCAmelCase							:			int     							=							"""pytorch_model.bin"""
lowerCAmelCase							:			str     							=							"""pytorch_model.bin.index.json"""
lowerCAmelCase							:			Union[str, Any]     							=							"""model.safetensors"""
lowerCAmelCase							:			List[Any]     							=							"""model.safetensors.index.json"""
lowerCAmelCase							:			List[Any]     							=							"""1.10.2"""
lowerCAmelCase							:			Any     							=							"""py38"""
lowerCAmelCase							:			Optional[int]     							=							"""4.17.0"""
lowerCAmelCase							:			str     							=							["""ml.p3.16xlarge""", """ml.p3dn.24xlarge""", """ml.p4dn.24xlarge"""]
lowerCAmelCase							:			Tuple     							=							["""FULL_SHARD""", """SHARD_GRAD_OP""", """NO_SHARD""", """HYBRID_SHARD""", """HYBRID_SHARD_ZERO2"""]
lowerCAmelCase							:			List[Any]     							=							["""TRANSFORMER_BASED_WRAP""", """SIZE_BASED_WRAP""", """NO_WRAP"""]
lowerCAmelCase							:			List[str]     							=							["""BACKWARD_PRE""", """BACKWARD_POST""", """NO_PREFETCH"""]
lowerCAmelCase							:			List[str]     							=							["""FULL_STATE_DICT""", """LOCAL_STATE_DICT""", """SHARDED_STATE_DICT"""]
lowerCAmelCase							:			Any     							=							"""2.0.1"""
lowerCAmelCase							:			List[Any]     							=							["""pdsh""", """standard""", """openmpi""", """mvapich"""]
lowerCAmelCase							:			Union[str, Any]     							=							["""default""", """reduce-overhead""", """max-autotune"""]

lowerCAmelCase							:			Optional[int]     							=							{""">""": op.gt, """>=""": op.ge, """==""": op.eq, """!=""": op.ne, """<=""": op.le, """<""": op.lt}

# These are the args for `torch.distributed.launch` for pytorch < 1.9
lowerCAmelCase							:			Union[str, Any]     							=							[
    """nnodes""",
    """nproc_per_node""",
    """rdzv_backend""",
    """rdzv_endpoint""",
    """rdzv_id""",
    """rdzv_conf""",
    """standalone""",
    """max_restarts""",
    """monitor_interval""",
    """start_method""",
    """role""",
    """module""",
    """m""",
    """no_python""",
    """run_path""",
    """log_dir""",
    """r""",
    """redirects""",
    """t""",
    """tee""",
    """node_rank""",
    """master_addr""",
    """master_port""",
]

lowerCAmelCase							:			List[str]     							=							["""DEEPSPEED""", """MULTI_GPU""", """FSDP""", """MEGATRON_LM"""]
lowerCAmelCase							:			Optional[Any]     							=							["""DEEPSPEED""", """MULTI_XPU""", """FSDP"""]



