'''simple docstring'''




import unittest

import numpy as np

from transformers import RobertaPreLayerNormConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask


if is_flax_available():
  import jax.numpy as jnp

  from transformers.models.roberta_prelayernorm.modeling_flax_roberta_prelayernorm import (
      FlaxRobertaPreLayerNormForCausalLM,
      FlaxRobertaPreLayerNormForMaskedLM,
      FlaxRobertaPreLayerNormForMultipleChoice,
      FlaxRobertaPreLayerNormForQuestionAnswering,
      FlaxRobertaPreLayerNormForSequenceClassification,
      FlaxRobertaPreLayerNormForTokenClassification,
      FlaxRobertaPreLayerNormModel,
  )




class     a__      (   unittest.TestCase ):






     def __init__( self		:		Union[str, Any]  ,				a		:		Optional[int]  ,				a		:		str=13  ,				a		:		str=7  ,				a		:		Optional[Any]=True  ,				a		:		List[Any]=True  ,				a		:		str=True  ,				a		:		str=True  ,				a		:		Dict=99  ,				a		:		Dict=32  ,				a		:		Union[str, Any]=5  ,				a		:		Tuple=4  ,				a		:		List[str]=37  ,				a		:		Optional[int]="gelu"  ,				a		:		Dict=0.1  ,				a		:		List[str]=0.1  ,				a		:		Any=5_12  ,				a		:		int=16  ,				a		:		List[Any]=2  ,				a		:		List[str]=0.02  ,				a		:		Any=4  ,				):





         """simple docstring"""



         __lowerCamelCase		=  parent
         __lowerCamelCase		=  batch_size
         __lowerCamelCase		=  seq_length
         __lowerCamelCase		=  is_training
         __lowerCamelCase		=  use_attention_mask
         __lowerCamelCase		=  use_token_type_ids
         __lowerCamelCase		=  use_labels
         __lowerCamelCase		=  vocab_size
         __lowerCamelCase		=  hidden_size
         __lowerCamelCase		=  num_hidden_layers
         __lowerCamelCase		=  num_attention_heads
         __lowerCamelCase		=  intermediate_size
         __lowerCamelCase		=  hidden_act
         __lowerCamelCase		=  hidden_dropout_prob
         __lowerCamelCase		=  attention_probs_dropout_prob
         __lowerCamelCase		=  max_position_embeddings
         __lowerCamelCase		=  type_vocab_size
         __lowerCamelCase		=  type_sequence_label_size
         __lowerCamelCase		=  initializer_range
         __lowerCamelCase		=  num_choices






     def    SCREAMING_SNAKE_CASE__   ( self		:		int    ):





         """simple docstring"""



         __lowerCamelCase		=  ids_tensor([self.batch_size, self.seq_length]  ,				self.vocab_size    )

         __lowerCamelCase		=  None
         if self.use_attention_mask:
             __lowerCamelCase		=  random_attention_mask([self.batch_size, self.seq_length]    )

         __lowerCamelCase		=  None
         if self.use_token_type_ids:
             __lowerCamelCase		=  ids_tensor([self.batch_size, self.seq_length]  ,				self.type_vocab_size    )

         __lowerCamelCase		=  RobertaPreLayerNormConfig(
             vocab_size=self.vocab_size  ,				hidden_size=self.hidden_size  ,				num_hidden_layers=self.num_hidden_layers  ,				num_attention_heads=self.num_attention_heads  ,				intermediate_size=self.intermediate_size  ,				hidden_act=self.hidden_act  ,				hidden_dropout_prob=self.hidden_dropout_prob  ,				attention_probs_dropout_prob=self.attention_probs_dropout_prob  ,				max_position_embeddings=self.max_position_embeddings  ,				type_vocab_size=self.type_vocab_size  ,				is_decoder=a  ,				initializer_range=self.initializer_range  ,				)

         return config, input_ids, token_type_ids, attention_mask






     def    SCREAMING_SNAKE_CASE__   ( self		:		Optional[Any]    ):





         """simple docstring"""



         __lowerCamelCase		=  self.prepare_config_and_inputs()
         __lowerCamelCase	,  __lowerCamelCase	,  __lowerCamelCase	,  __lowerCamelCase		=  config_and_inputs
         __lowerCamelCase		=  {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': attention_mask}
         return config, inputs_dict






     def    SCREAMING_SNAKE_CASE__   ( self		:		Optional[int]    ):





         """simple docstring"""



         __lowerCamelCase		=  self.prepare_config_and_inputs()
         __lowerCamelCase	,  __lowerCamelCase	,  __lowerCamelCase	,  __lowerCamelCase		=  config_and_inputs

         __lowerCamelCase		=  True
         __lowerCamelCase		=  floats_tensor([self.batch_size, self.seq_length, self.hidden_size]    )
         __lowerCamelCase		=  ids_tensor([self.batch_size, self.seq_length]  ,				vocab_size=2    )

         return (
             config,
             input_ids,
             token_type_ids,
             encoder_hidden_states,
             encoder_attention_mask,
         )




@require_flax
# Copied from tests.models.roberta.test_modelling_flax_roberta.FlaxRobertaPreLayerNormModelTest with ROBERTA->ROBERTA_PRELAYERNORM,Roberta->RobertaPreLayerNorm,roberta-base->andreasmadsen/efficient_mlm_m0.40
class     a__      (   UpperCAmelCase__							,   unittest.TestCase ):
     lowerCamelCase  :     Optional[Any]							=True

     lowerCamelCase  :     Dict							=(
         (
             FlaxRobertaPreLayerNormModel,
             FlaxRobertaPreLayerNormForCausalLM,
             FlaxRobertaPreLayerNormForMaskedLM,
             FlaxRobertaPreLayerNormForSequenceClassification,
             FlaxRobertaPreLayerNormForTokenClassification,
             FlaxRobertaPreLayerNormForMultipleChoice,
             FlaxRobertaPreLayerNormForQuestionAnswering,
         )
         if is_flax_available()
         else ()
     )






     def    SCREAMING_SNAKE_CASE__   ( self		:		Optional[int]    ):





         """simple docstring"""



         __lowerCamelCase		=  FlaxRobertaPreLayerNormModelTester(self    )






     @slow
     def    SCREAMING_SNAKE_CASE__   ( self		:		Dict    ):





         """simple docstring"""



         for model_class_name in self.all_model_classes:
             __lowerCamelCase		=  model_class_name.from_pretrained('''andreasmadsen/efficient_mlm_m0.40'''  ,				from_pt=a    )
             __lowerCamelCase		=  model(np.ones((1, 1)    )    )
             self.assertIsNotNone(a    )




@require_flax
class     a__      (   unittest.TestCase ):






     @slow
     def    SCREAMING_SNAKE_CASE__   ( self		:		Optional[int]    ):





         """simple docstring"""



         __lowerCamelCase		=  FlaxRobertaPreLayerNormForMaskedLM.from_pretrained('''andreasmadsen/efficient_mlm_m0.40'''  ,				from_pt=a    )

         __lowerCamelCase		=  np.array([[0, 3_14_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69, 4_60_78, 15_88, 2]]  ,				dtype=jnp.intaa    )
         __lowerCamelCase		=  model(a    )[0]
         __lowerCamelCase		=  [1, 11, 5_02_65]
         self.assertEqual(list(output.shape    )  ,				a    )
         # compare the actual values for a slice.
         __lowerCamelCase		=  np.array(
             [[[40.48_80, 18.01_99, -5.23_67], [-1.88_77, -4.08_85, 10.70_85], [-2.26_13, -5.61_10, 7.26_65]]]  ,				dtype=np.floataa    )
         self.assertTrue(np.allclose(output[:, :3, :3]  ,				a  ,				atol=1e-4    )    )






     @slow
     def    SCREAMING_SNAKE_CASE__   ( self		:		List[Any]    ):





         """simple docstring"""



         __lowerCamelCase		=  FlaxRobertaPreLayerNormModel.from_pretrained('''andreasmadsen/efficient_mlm_m0.40'''  ,				from_pt=a    )

         __lowerCamelCase		=  np.array([[0, 3_14_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69, 4_60_78, 15_88, 2]]  ,				dtype=jnp.intaa    )
         __lowerCamelCase		=  model(a    )[0]
         # compare the actual values for a slice.
         __lowerCamelCase		=  np.array(
             [[[0.02_08, -0.03_56, 0.02_37], [-0.15_69, -0.04_11, -0.26_26], [0.18_79, 0.01_25, -0.00_89]]]  ,				dtype=np.floataa    )
         self.assertTrue(np.allclose(output[:, :3, :3]  ,				a  ,				atol=1e-4    )    )


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 __snake_case		(      unittest.TestCase     ):
    _a		:						Optional[int]=				MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING
    def       _SCREAMING_SNAKE_CASE       (  self		,snake_case		,snake_case		,snake_case      ):



           '''simple docstring'''







           lowercase							:     Any       	=      hf_hub_download(
               repo_id="""nateraw/video-demo"""		,filename="""archery.mp4"""		,repo_type="""dataset"""      )
           lowercase							:     List[str]       	=      VideoClassificationPipeline(model=snake_case		,image_processor=snake_case		,top_k=2      )
           lowercase							:     Dict       	=      [
               example_video_filepath,
               """https://huggingface.co/datasets/nateraw/video-demo/resolve/main/archery.mp4""",
           ]
           return video_classifier, examples
    def       _SCREAMING_SNAKE_CASE       (  self		,snake_case		,snake_case      ):



           '''simple docstring'''







           for example in examples:
                  lowercase							:     int       	=      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       _SCREAMING_SNAKE_CASE       (  self      ):



           '''simple docstring'''







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

           lowercase							:     Dict       	=      hf_hub_download(repo_id="""nateraw/video-demo"""		,filename="""archery.mp4"""		,repo_type="""dataset"""      )
           lowercase							:     Any       	=      video_classifier(snake_case		,top_k=2      )
           self.assertEqual(
               nested_simplify(snake_case		,decimals=4      )		,[{"""score""": 0.5_199, """label""": """LABEL_0"""}, {"""score""": 0.4_801, """label""": """LABEL_1"""}]		,)

           lowercase							:     str       	=      video_classifier(
               [
                   video_file_path,
                   video_file_path,
               ]		,top_k=2		,)
           self.assertEqual(
               nested_simplify(snake_case		,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       _SCREAMING_SNAKE_CASE       (  self      ):



           '''simple docstring'''







           pass
