






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


UpperCAmelCase__				   =		logging.get_logger(__name__)

UpperCAmelCase__				   =		{
    "google/switch-base-8": "https://huggingface.co/google/switch-base-8/blob/main/config.json",
}






class 		lowercase_					(	lowercase   ):






      '''simple docstring'''




      __snake_case       =  '''switch_transformers'''
      __snake_case       =  ['''past_key_values''']
      __snake_case       =  {'''hidden_size''': '''d_model''', '''num_attention_heads''': '''num_heads''', '''num_hidden_layers''': '''num_layers'''}







      def __init__(      self      :						Dict ,					__UpperCAmelCase      :						List[Any]=32_128 ,					__UpperCAmelCase      :						List[str]=768 ,					__UpperCAmelCase      :						str=64 ,					__UpperCAmelCase      :						Dict=2_048 ,					__UpperCAmelCase      :						int=64 ,					__UpperCAmelCase      :						str=12 ,					__UpperCAmelCase      :						Tuple=3 ,					__UpperCAmelCase      :						str=12 ,					__UpperCAmelCase      :						List[str]=3 ,					__UpperCAmelCase      :						Dict=12 ,					__UpperCAmelCase      :						List[str]=8 ,					__UpperCAmelCase      :						Union[str, Any]=False ,					__UpperCAmelCase      :						List[Any]=0.01 ,					__UpperCAmelCase      :						Any="float32" ,					__UpperCAmelCase      :						Any=False ,					__UpperCAmelCase      :						int=32 ,					__UpperCAmelCase      :						str=128 ,					__UpperCAmelCase      :						Optional[int]=0.1 ,					__UpperCAmelCase      :						Optional[Any]=1e-6 ,					__UpperCAmelCase      :						Optional[int]=0.001 ,					__UpperCAmelCase      :						Any=0.001 ,					__UpperCAmelCase      :						List[Any]=1.0 ,					__UpperCAmelCase      :						List[Any]="relu" ,					__UpperCAmelCase      :						Optional[int]=True ,					__UpperCAmelCase      :						Tuple=False ,					__UpperCAmelCase      :						str=True ,					__UpperCAmelCase      :						Any=0 ,					__UpperCAmelCase      :						str=1 ,					**__UpperCAmelCase      :						List[Any] ,					)    ->Optional[int]:




       """simple docstring"""


       a		  =      vocab_size
       a		  =      d_model
       a		  =      d_kv
       a		  =      d_ff

       a		  =      num_sparse_encoder_layers

       a		  =      num_layers
       a		  =      (
           num_decoder_layers if num_decoder_layers is not None else self.num_layers
       )  # default = symmetry
       a		  =      num_sparse_decoder_layers

       # This tells us, each how many encoder layer we'll have to set a sparse layer.
       if self.num_sparse_encoder_layers > 0:
        a		  =      self.num_layers // self.num_sparse_encoder_layers
       else:
        a		  =      self.num_layers  # HACK: this will create 0 sparse layers

       # This tells us, each how many encoder layer we'll have to set a sparse layer.
       if self.num_sparse_decoder_layers > 0:
        a		  =      self.num_decoder_layers // self.num_sparse_decoder_layers
       else:
        a		  =      self.num_decoder_layers  # HACK: this will create 0 sparse layers

       a		  =      num_heads
       a		  =      num_experts
       a		  =      expert_capacity
       a		  =      router_bias
       a		  =      router_jitter_noise
       if router_dtype not in ["float32", "float16", "bfloat16"]:
        raise ValueError(F"""`router_dtype` must be one of 'float32', 'float16' or 'bfloat16', got {router_dtype}"""  )
       a		  =      router_dtype

       a		  =      router_ignore_padding_tokens
       a		  =      relative_attention_num_buckets
       a		  =      relative_attention_max_distance

       a		  =      dropout_rate
       a		  =      layer_norm_epsilon
       a		  =      initializer_factor
       a		  =      feed_forward_proj
       a		  =      use_cache
       a		  =      add_router_probs

       a		  =      router_z_loss_coef
       a		  =      router_aux_loss_coef

       a		  =      self.feed_forward_proj.split('''-'''  )
       a		  =      act_info[-1]
       a		  =      act_info[0] == '''gated'''

       if len(__UpperCAmelCase  ) > 1 and act_info[0] != "gated" or len(__UpperCAmelCase  ) > 2:
        raise ValueError(
            F"""`feed_forward_proj`: {feed_forward_proj} is not a valid activation function of the dense layer."""
            '''Please make sure `feed_forward_proj` is of the format `gated-{ACT_FN}` or `{ACT_FN}`, e.g. '''
            '''\'gated-gelu\' or \'relu\''''  )

       # for backwards compatibility
       if feed_forward_proj == "gated-gelu":
        a		  =      '''gelu_new'''

       super().__init__(
           pad_token_id=__UpperCAmelCase ,					eos_token_id=__UpperCAmelCase ,					is_encoder_decoder=__UpperCAmelCase ,					**__UpperCAmelCase ,					)




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 				lowercase					(		unittest.TestCase   ):
		__lowercase       :       Any	     =				MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING



		def __UpperCamelCase ( self				,      A_				,      A_				,      A_       )  ->					List[Any]:
				"""simple docstring"""
				UpperCamelCase		=     hf_hub_download(
				    repo_id='nateraw/video-demo'				,      filename='archery.mp4'				,      repo_type='dataset'       )
				UpperCamelCase		=     VideoClassificationPipeline(model=A_				,      image_processor=A_				,      top_k=2       )
				UpperCamelCase		=     [
				    example_video_filepath,
				    'https://huggingface.co/datasets/nateraw/video-demo/resolve/main/archery.mp4',
				]
				return video_classifier, examples



		def __UpperCamelCase ( self				,      A_				,      A_       )  ->					Optional[int]:
				"""simple docstring"""
				for example in examples:
						UpperCamelCase		=     video_classifier(A_       )

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



		@require_torch
		def __UpperCamelCase ( self       )  ->					Optional[Any]:
				"""simple docstring"""
				UpperCamelCase		=     'hf-internal-testing/tiny-random-VideoMAEForVideoClassification'
				UpperCamelCase		=     VideoMAEFeatureExtractor(
				    size={'shortest_edge': 10}				,      crop_size={'height': 10, 'width': 10}       )
				UpperCamelCase		=     pipeline(
				    'video-classification'				,      model=A_				,      feature_extractor=A_				,      frame_sampling_rate=4       )

				UpperCamelCase		=     hf_hub_download(repo_id='nateraw/video-demo'				,      filename='archery.mp4'				,      repo_type='dataset'       )
				UpperCamelCase		=     video_classifier(A_				,      top_k=2       )
				self.assertEqual(
				    nested_simplify(A_				,      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(A_				,      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 __UpperCamelCase ( self       )  ->					Tuple:
				"""simple docstring"""
				pass
