




from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


UpperCAmelCase_						=logging.get_logger(__name__)

UpperCAmelCase_						={
    """xlm-mlm-en-2048""": """https://huggingface.co/xlm-mlm-en-2048/resolve/main/config.json""",
    """xlm-mlm-ende-1024""": """https://huggingface.co/xlm-mlm-ende-1024/resolve/main/config.json""",
    """xlm-mlm-enfr-1024""": """https://huggingface.co/xlm-mlm-enfr-1024/resolve/main/config.json""",
    """xlm-mlm-enro-1024""": """https://huggingface.co/xlm-mlm-enro-1024/resolve/main/config.json""",
    """xlm-mlm-tlm-xnli15-1024""": """https://huggingface.co/xlm-mlm-tlm-xnli15-1024/resolve/main/config.json""",
    """xlm-mlm-xnli15-1024""": """https://huggingface.co/xlm-mlm-xnli15-1024/resolve/main/config.json""",
    """xlm-clm-enfr-1024""": """https://huggingface.co/xlm-clm-enfr-1024/resolve/main/config.json""",
    """xlm-clm-ende-1024""": """https://huggingface.co/xlm-clm-ende-1024/resolve/main/config.json""",
    """xlm-mlm-17-1280""": """https://huggingface.co/xlm-mlm-17-1280/resolve/main/config.json""",
    """xlm-mlm-100-1280""": """https://huggingface.co/xlm-mlm-100-1280/resolve/main/config.json""",
}


class 							__UpperCamelCase			( __UpperCAmelCase  ):





    '''simple docstring'''



    __a							: int										="""xlm"""
    __a							: Dict										={
        """hidden_size""": """emb_dim""",
        """num_attention_heads""": """n_heads""",
        """num_hidden_layers""": """n_layers""",
        """n_words""": """vocab_size""",  # For backward compatibility
    }



    def __init__( self       , UpperCAmelCase_=3_01_45       , UpperCAmelCase_=20_48       , UpperCAmelCase_=12       , UpperCAmelCase_=16       , UpperCAmelCase_=0.1       , UpperCAmelCase_=0.1       , UpperCAmelCase_=True       , UpperCAmelCase_=False       , UpperCAmelCase_=False       , UpperCAmelCase_=False       , UpperCAmelCase_=1       , UpperCAmelCase_=True       , UpperCAmelCase_=5_12       , UpperCAmelCase_=20_48**-0.5       , UpperCAmelCase_=1E-1_2       , UpperCAmelCase_=0.02       , UpperCAmelCase_=0       , UpperCAmelCase_=1       , UpperCAmelCase_=2       , UpperCAmelCase_=3       , UpperCAmelCase_=5       , UpperCAmelCase_=True       , UpperCAmelCase_="first"       , UpperCAmelCase_=True       , UpperCAmelCase_=None       , UpperCAmelCase_=True       , UpperCAmelCase_=0.1       , UpperCAmelCase_=5       , UpperCAmelCase_=5       , UpperCAmelCase_=0       , UpperCAmelCase_=0       , UpperCAmelCase_=2       , UpperCAmelCase_=0       , **UpperCAmelCase_       , ):
           lowerCAmelCase   =		vocab_size
           lowerCAmelCase   =		emb_dim
           lowerCAmelCase   =		n_layers
           lowerCAmelCase   =		n_heads
           lowerCAmelCase   =		dropout
           lowerCAmelCase   =		attention_dropout
           lowerCAmelCase   =		gelu_activation
           lowerCAmelCase   =		sinusoidal_embeddings
           lowerCAmelCase   =		causal
           lowerCAmelCase   =		asm
           lowerCAmelCase   =		n_langs
           lowerCAmelCase   =		use_lang_emb
           lowerCAmelCase   =		layer_norm_eps
           lowerCAmelCase   =		bos_index
           lowerCAmelCase   =		eos_index
           lowerCAmelCase   =		pad_index
           lowerCAmelCase   =		unk_index
           lowerCAmelCase   =		mask_index
           lowerCAmelCase   =		is_encoder
           lowerCAmelCase   =		max_position_embeddings
           lowerCAmelCase   =		embed_init_std
           lowerCAmelCase   =		init_std
           lowerCAmelCase   =		summary_type
           lowerCAmelCase   =		summary_use_proj
           lowerCAmelCase   =		summary_activation
           lowerCAmelCase   =		summary_proj_to_labels
           lowerCAmelCase   =		summary_first_dropout
           lowerCAmelCase   =		start_n_top
           lowerCAmelCase   =		end_n_top
           lowerCAmelCase   =		mask_token_id
           lowerCAmelCase   =		lang_id

           if "n_words" in kwargs:
                  lowerCAmelCase   =		kwargs['''n_words''']

           super().__init__(pad_token_id=UpperCAmelCase_       , bos_token_id=UpperCAmelCase_       , **UpperCAmelCase_						)




class 							__UpperCamelCase			( __UpperCAmelCase  ):





    '''simple docstring'''



    @property
    def       __snake_case		( self						):

           if self.task == "multiple-choice":
                  lowerCAmelCase   =		{0: '''batch''', 1: '''choice''', 2: '''sequence'''}
           else:
                  lowerCAmelCase   =		{0: '''batch''', 1: '''sequence'''}
           return OrderedDict(
               [
                   ('''input_ids''', dynamic_axis),
                   ('''attention_mask''', dynamic_axis),
                   ('''token_type_ids''', dynamic_axis),
               ]						)









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





				'''simple docstring'''



				__a							: str										=MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING



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



				def       __snake_case		( self       , UpperCAmelCase_       , UpperCAmelCase_						):
											for example in examples:
																		lowerCAmelCase   =		video_classifier(UpperCAmelCase_						)

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



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

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

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



