


"""simple docstring"""







import copy
import os
from typing import TYPE_CHECKING, List, Union


if TYPE_CHECKING:
     pass

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


lowerCAmelCase__      				=   logging.get_logger(__name__)

lowerCAmelCase__      				=   {
    '''kakaobrain/align-base''': '''https://huggingface.co/kakaobrain/align-base/resolve/main/config.json''',
}


class       SCREAMING_SNAKE_CASE__				(		lowercase				):
       """simple docstring"""


       a  :				int   ="align_text_model"

       def __init__(						self		,     snake_case__=30_522		,     snake_case__=768		,     snake_case__=12		,     snake_case__=12		,     snake_case__=3_072		,     snake_case__="gelu"		,     snake_case__=0.1		,     snake_case__=0.1		,     snake_case__=512		,     snake_case__=2		,     snake_case__=0.02		,     snake_case__=1e-12		,     snake_case__=0		,     snake_case__="absolute"		,     snake_case__=True		,     **snake_case__		,     ):






         """simple docstring"""





         super().__init__(**snake_case__						)

         lowerCAmelCase     :     str								=							vocab_size
         lowerCAmelCase     :     Optional[int]								=							hidden_size
         lowerCAmelCase     :     str								=							num_hidden_layers
         lowerCAmelCase     :     int								=							num_attention_heads
         lowerCAmelCase     :     Dict								=							hidden_act
         lowerCAmelCase     :     Any								=							intermediate_size
         lowerCAmelCase     :     Optional[Any]								=							hidden_dropout_prob
         lowerCAmelCase     :     Any								=							attention_probs_dropout_prob
         lowerCAmelCase     :     str								=							max_position_embeddings
         lowerCAmelCase     :     Tuple								=							type_vocab_size
         lowerCAmelCase     :     int								=							initializer_range
         lowerCAmelCase     :     Optional[int]								=							layer_norm_eps
         lowerCAmelCase     :     List[Any]								=							position_embedding_type
         lowerCAmelCase     :     Tuple								=							use_cache
         lowerCAmelCase     :     Union[str, Any]								=							pad_token_id







       @classmethod
       def        lowercase__							(						cls		,     snake_case__		,     **snake_case__						):






         """simple docstring"""





         cls._set_token_in_kwargs(snake_case__						)

         lowerCAmelCase						,  lowerCAmelCase     :     Dict								=							cls.get_config_dict(snake_case__		,     **snake_case__						)

         # get the text config dict if we are loading from AlignConfig
         if config_dict.get("model_type"						) == "align":
           lowerCAmelCase     :     List[Any]								=							config_dict["text_config"]

         if "model_type" in config_dict and hasattr(cls		,     "model_type"						) and config_dict["model_type"] != cls.model_type:
           logger.warning(
               f"""You are using a model of type {config_dict["model_type"]} to instantiate a model of type """
               f"""{cls.model_type}. This is not supported for all configurations of models and can yield errors."""						)

         return cls.from_dict(snake_case__		,     **snake_case__						)


class       SCREAMING_SNAKE_CASE__				(		lowercase				):
       """simple docstring"""


       a  :				int   ="align_vision_model"

       def __init__(						self		,     snake_case__ = 3		,     snake_case__ = 600		,     snake_case__ = 2.0		,     snake_case__ = 3.1		,     snake_case__ = 8		,     snake_case__ = [3, 3, 5, 3, 5, 5, 3]		,     snake_case__ = [32, 16, 24, 40, 80, 112, 192]		,     snake_case__ = [16, 24, 40, 80, 112, 192, 320]		,     snake_case__ = []		,     snake_case__ = [1, 2, 2, 2, 1, 2, 1]		,     snake_case__ = [1, 2, 2, 3, 3, 4, 1]		,     snake_case__ = [1, 6, 6, 6, 6, 6, 6]		,     snake_case__ = 0.25		,     snake_case__ = "swish"		,     snake_case__ = 2_560		,     snake_case__ = "mean"		,     snake_case__ = 0.02		,     snake_case__ = 0.001		,     snake_case__ = 0.99		,     snake_case__ = 0.2		,     **snake_case__		,     ):






         """simple docstring"""





         super().__init__(**snake_case__						)

         lowerCAmelCase     :     Optional[int]								=							num_channels
         lowerCAmelCase     :     str								=							image_size
         lowerCAmelCase     :     Optional[Any]								=							width_coefficient
         lowerCAmelCase     :     Optional[int]								=							depth_coefficient
         lowerCAmelCase     :     Tuple								=							depth_divisor
         lowerCAmelCase     :     List[Any]								=							kernel_sizes
         lowerCAmelCase     :     int								=							in_channels
         lowerCAmelCase     :     Tuple								=							out_channels
         lowerCAmelCase     :     Any								=							depthwise_padding
         lowerCAmelCase     :     Optional[int]								=							strides
         lowerCAmelCase     :     Union[str, Any]								=							num_block_repeats
         lowerCAmelCase     :     Dict								=							expand_ratios
         lowerCAmelCase     :     Optional[int]								=							squeeze_expansion_ratio
         lowerCAmelCase     :     Optional[Any]								=							hidden_act
         lowerCAmelCase     :     str								=							hidden_dim
         lowerCAmelCase     :     Union[str, Any]								=							pooling_type
         lowerCAmelCase     :     int								=							initializer_range
         lowerCAmelCase     :     Dict								=							batch_norm_eps
         lowerCAmelCase     :     str								=							batch_norm_momentum
         lowerCAmelCase     :     List[Any]								=							drop_connect_rate
         lowerCAmelCase     :     Dict								=							sum(snake_case__						) * 4







       @classmethod
       def        lowercase__							(						cls		,     snake_case__		,     **snake_case__						):






         """simple docstring"""





         cls._set_token_in_kwargs(snake_case__						)

         lowerCAmelCase						,  lowerCAmelCase     :     Union[str, Any]								=							cls.get_config_dict(snake_case__		,     **snake_case__						)

         # get the vision config dict if we are loading from AlignConfig
         if config_dict.get("model_type"						) == "align":
           lowerCAmelCase     :     Tuple								=							config_dict["vision_config"]

         if "model_type" in config_dict and hasattr(cls		,     "model_type"						) and config_dict["model_type"] != cls.model_type:
           logger.warning(
               f"""You are using a model of type {config_dict["model_type"]} to instantiate a model of type """
               f"""{cls.model_type}. This is not supported for all configurations of models and can yield errors."""						)

         return cls.from_dict(snake_case__		,     **snake_case__						)


class       SCREAMING_SNAKE_CASE__				(		lowercase				):
       """simple docstring"""


       a  :				Tuple   ="align"
       a  :				Dict   =True

       def __init__(						self		,     snake_case__=None		,     snake_case__=None		,     snake_case__=640		,     snake_case__=1.0		,     snake_case__=0.02		,     **snake_case__		,     ):






         """simple docstring"""





         super().__init__(**snake_case__						)

         if text_config is None:
           lowerCAmelCase     :     List[Any]								=							{}
           logger.info("text_config is None. Initializing the AlignTextConfig with default values."						)

         if vision_config is None:
           lowerCAmelCase     :     Union[str, Any]								=							{}
           logger.info("vision_config is None. Initializing the AlignVisionConfig with default values."						)

         lowerCAmelCase     :     Optional[int]								=							AlignTextConfig(**snake_case__						)
         lowerCAmelCase     :     str								=							AlignVisionConfig(**snake_case__						)

         lowerCAmelCase     :     List[str]								=							projection_dim
         lowerCAmelCase     :     Union[str, Any]								=							temperature_init_value
         lowerCAmelCase     :     Union[str, Any]								=							initializer_range

       @classmethod
       def        lowercase__							(						cls		,     snake_case__		,     snake_case__		,     **snake_case__						):






         """simple docstring"""





         return cls(text_config=text_config.to_dict()		,     vision_config=vision_config.to_dict()		,     **snake_case__						)







       def        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase     :     Union[str, Any]								=							copy.deepcopy(self.__dict__						)
         lowerCAmelCase     :     Tuple								=							self.text_config.to_dict()
         lowerCAmelCase     :     Union[str, Any]								=							self.vision_config.to_dict()
         lowerCAmelCase     :     Dict								=							self.__class__.model_type
         return output









"""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       SCREAMING_SNAKE_CASE__				(		unittest.TestCase				):
       """simple docstring"""


       a  :				int   =MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING

       def        lowercase__							(						self		,     snake_case__		,     snake_case__		,     snake_case__						):






         """simple docstring"""





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

       def        lowercase__							(						self		,     snake_case__		,     snake_case__						):






         """simple docstring"""





         for example in examples:
           lowerCAmelCase     :     str								=							video_classifier(snake_case__						)

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

       @require_torch
       def        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase     :     Union[str, Any]								=							"hf-internal-testing/tiny-random-VideoMAEForVideoClassification"
         lowerCAmelCase     :     str								=							VideoMAEFeatureExtractor(
             size={"shortest_edge": 10}		,     crop_size={"height": 10, "width": 10}						)
         lowerCAmelCase     :     int								=							pipeline(
             "video-classification"		,     model=snake_case__		,     feature_extractor=snake_case__		,     frame_sampling_rate=4						)

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

         lowerCAmelCase     :     Tuple								=							video_classifier(
             [
                 video_file_path,
                 video_file_path,
             ]		,     top_k=2		,     )
         self.assertEqual(
             nested_simplify(snake_case__		,     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        lowercase__							(						self						):






         """simple docstring"""





         pass





