





import inspect
import re

from transformers.utils import direct_transformers_import


# All paths are set with the intent you should run this script from the root of the repo with the command
# python utils/check_config_docstrings.py
UpperCamelCase__           =			"src/transformers"


# This is to make sure the transformers module imported is the one in the repo.
UpperCamelCase__           =			direct_transformers_import(PATH_TO_TRANSFORMERS)

UpperCamelCase__           =			transformers.models.auto.configuration_auto.CONFIG_MAPPING

# Regex pattern used to find the checkpoint mentioned in the docstring of `config_class`.
# For example, `[bert-base-uncased](https://huggingface.co/bert-base-uncased)`
UpperCamelCase__           =			re.compile(r"\[(.+?)\]\((https://huggingface\.co/.+?)\)")


UpperCamelCase__           =			{
    "DecisionTransformerConfig",
    "EncoderDecoderConfig",
    "MusicgenConfig",
    "RagConfig",
    "SpeechEncoderDecoderConfig",
    "TimmBackboneConfig",
    "VisionEncoderDecoderConfig",
    "VisionTextDualEncoderConfig",
    "LlamaConfig",
}





def      _UpperCamelCase  (a__ :Tuple							):






							"""simple docstring"""





							UpperCamelCase__					  =      None

							# source code of `config_class`
							UpperCamelCase__					  =      inspect.getsource(a__							)
							UpperCamelCase__					  =      _re_checkpoint.findall(a__							)

							# Each `checkpoint` is a tuple of a checkpoint name and a checkpoint link.
							# For example, `('bert-base-uncased', 'https://huggingface.co/bert-base-uncased')`
							for ckpt_name, ckpt_link in checkpoints:
														# allow the link to end with `/`
														if ckpt_link.endswith("""/"""							):
																					UpperCamelCase__					  =      ckpt_link[:-1]

														# verify the checkpoint name corresponds to the checkpoint link
														UpperCamelCase__					  =      f"""https://huggingface.co/{ckpt_name}"""
														if ckpt_link == ckpt_link_from_name:
																					UpperCamelCase__					  =      ckpt_name
																					break

							return checkpoint





def      _UpperCamelCase  ():






							"""simple docstring"""





							UpperCamelCase__					  =      []

							for config_class in list(CONFIG_MAPPING.values()							):
														# Skip deprecated models
														if "models.deprecated" in config_class.__module__:
																					continue
														UpperCamelCase__					  =      get_checkpoint_from_config_class(a__							)

														UpperCamelCase__					  =      config_class.__name__
														if checkpoint is None and name not in CONFIG_CLASSES_TO_IGNORE_FOR_DOCSTRING_CHECKPOINT_CHECK:
																					configs_without_checkpoint.append(a__							)

							if len(a__							) > 0:
														UpperCamelCase__					  =      """\n""".join(sorted(a__							)							)
														raise ValueError(f"""The following configurations don't contain any valid checkpoint:\n{message}"""							)


if __name__ == "__main__":
					check_config_docstrings_have_checkpoints()











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 							__SCREAMING_SNAKE_CASE       (  unittest.TestCase							):
							snake_case  :   List[str]      =							MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING






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






							def 					_lowerCamelCase		(    self	,			__lowerCAmelCase	,			__lowerCAmelCase	):
														for example in examples:
																					UpperCamelCase__					  =      video_classifier(__lowerCAmelCase	)

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






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

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




