





from __future__ import annotations

import unittest

from transformers import MobileBertConfig, is_tf_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
     import tensorflow as tf

     from transformers import (
         TF_MODEL_FOR_PRETRAINING_MAPPING,
         TFMobileBertForMaskedLM,
         TFMobileBertForMultipleChoice,
         TFMobileBertForNextSentencePrediction,
         TFMobileBertForPreTraining,
         TFMobileBertForQuestionAnswering,
         TFMobileBertForSequenceClassification,
         TFMobileBertForTokenClassification,
         TFMobileBertModel,
     )



@require_tf
class    _SCREAMING_SNAKE_CASE						(	UpperCAmelCase_    ,							UpperCAmelCase_    ,							unittest.TestCase    ):







 '''simple docstring'''
 lowercase_		=			(
     (
         TFMobileBertModel,
         TFMobileBertForMaskedLM,
         TFMobileBertForNextSentencePrediction,
         TFMobileBertForPreTraining,
         TFMobileBertForQuestionAnswering,
         TFMobileBertForSequenceClassification,
         TFMobileBertForTokenClassification,
         TFMobileBertForMultipleChoice,
     )
     if is_tf_available()
     else ()
 )
 lowercase_		=			(
     {
         """feature-extraction""": TFMobileBertModel,
         """fill-mask""": TFMobileBertForMaskedLM,
         """question-answering""": TFMobileBertForQuestionAnswering,
         """text-classification""": TFMobileBertForSequenceClassification,
         """token-classification""": TFMobileBertForTokenClassification,
         """zero-shot""": TFMobileBertForSequenceClassification,
     }
     if is_tf_available()
     else {}
 )
 lowercase_		=			False
 lowercase_		=			False

 def 							SCREAMING_SNAKE_CASE_					(self				:   int       , UpperCAmelCase_				:   Optional[Any]       , UpperCAmelCase_				:   Any       , UpperCAmelCase_				:   Optional[int]=False)       ->Union[str, Any]:



   '''simple docstring'''



   lowerCamelCase__:      List[str]			  =super()._prepare_for_class(__lowercase       , __lowercase       , return_labels=__lowercase)

   if return_labels:
     if model_class in get_values(__lowercase):
       lowerCamelCase__:      Union[str, Any]			  =tf.zeros(self.model_tester.batch_size       , dtype=tf.intaa)

   return inputs_dict



 class    _SCREAMING_SNAKE_CASE						(	UpperCAmelCase_    ):







  '''simple docstring'''

  def __init__(self				:   List[Any]       , UpperCAmelCase_				:   str       , UpperCAmelCase_				:   Any=13       , UpperCAmelCase_				:   int=7       , UpperCAmelCase_				:   List[Any]=True       , UpperCAmelCase_				:   Tuple=True       , UpperCAmelCase_				:   int=True       , UpperCAmelCase_				:   str=True       , UpperCAmelCase_				:   Tuple=99       , UpperCAmelCase_				:   List[str]=32       , UpperCAmelCase_				:   int=32       , UpperCAmelCase_				:   int=2       , UpperCAmelCase_				:   Optional[int]=4       , UpperCAmelCase_				:   Dict=37       , UpperCAmelCase_				:   int="gelu"       , UpperCAmelCase_				:   Any=0.1       , UpperCAmelCase_				:   List[str]=0.1       , UpperCAmelCase_				:   Optional[int]=512       , UpperCAmelCase_				:   Union[str, Any]=16       , UpperCAmelCase_				:   List[Any]=2       , UpperCAmelCase_				:   Any=0.02       , UpperCAmelCase_				:   List[str]=3       , UpperCAmelCase_				:   Tuple=4       , UpperCAmelCase_				:   Any=None       , )       ->Any:



    '''simple docstring'''



    lowerCamelCase__:      List[Any]			  =parent
    lowerCamelCase__:      Any			  =batch_size
    lowerCamelCase__:      Dict			  =seq_length
    lowerCamelCase__:      List[str]			  =is_training
    lowerCamelCase__:      List[Any]			  =use_input_mask
    lowerCamelCase__:      Optional[int]			  =use_token_type_ids
    lowerCamelCase__:      Any			  =use_labels
    lowerCamelCase__:      List[str]			  =vocab_size
    lowerCamelCase__:      Any			  =hidden_size
    lowerCamelCase__:      Optional[int]			  =num_hidden_layers
    lowerCamelCase__:      Union[str, Any]			  =num_attention_heads
    lowerCamelCase__:      Dict			  =intermediate_size
    lowerCamelCase__:      str			  =hidden_act
    lowerCamelCase__:      List[Any]			  =hidden_dropout_prob
    lowerCamelCase__:      Union[str, Any]			  =attention_probs_dropout_prob
    lowerCamelCase__:      List[str]			  =max_position_embeddings
    lowerCamelCase__:      List[str]			  =type_vocab_size
    lowerCamelCase__:      Dict			  =type_sequence_label_size
    lowerCamelCase__:      str			  =initializer_range
    lowerCamelCase__:      int			  =num_labels
    lowerCamelCase__:      int			  =num_choices
    lowerCamelCase__:      List[str]			  =scope
    lowerCamelCase__:      Any			  =embedding_size

  def 							SCREAMING_SNAKE_CASE_					(self				:   List[Any])       ->str:



    '''simple docstring'''



    lowerCamelCase__:      str			  =ids_tensor([self.batch_size, self.seq_length]       , self.vocab_size)

    lowerCamelCase__:      str			  =None
    if self.use_input_mask:
      lowerCamelCase__:      List[str]			  =random_attention_mask([self.batch_size, self.seq_length])

    lowerCamelCase__:      Union[str, Any]			  =None
    if self.use_token_type_ids:
      lowerCamelCase__:      Tuple			  =ids_tensor([self.batch_size, self.seq_length]       , self.type_vocab_size)

    lowerCamelCase__:      int			  =None
    lowerCamelCase__:      str			  =None
    lowerCamelCase__:      Any			  =None
    if self.use_labels:
      lowerCamelCase__:      Optional[Any]			  =ids_tensor([self.batch_size]       , self.type_sequence_label_size)
      lowerCamelCase__:      Tuple			  =ids_tensor([self.batch_size, self.seq_length]       , self.num_labels)
      lowerCamelCase__:      Optional[Any]			  =ids_tensor([self.batch_size]       , self.num_choices)

    lowerCamelCase__:      str			  =MobileBertConfig(
        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       , initializer_range=self.initializer_range       , embedding_size=self.embedding_size       , )

    return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels

  def 							SCREAMING_SNAKE_CASE_					(self				:   Optional[Any]       , UpperCAmelCase_				:   List[Any]       , UpperCAmelCase_				:   Optional[int]       , UpperCAmelCase_				:   Tuple       , UpperCAmelCase_				:   List[str]       , UpperCAmelCase_				:   Any       , UpperCAmelCase_				:   Optional[Any]       , UpperCAmelCase_				:   List[str])       ->str:



    '''simple docstring'''



    lowerCamelCase__:      Dict			  =TFMobileBertModel(config=__lowercase)
    lowerCamelCase__:      List[Any]			  ={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
    lowerCamelCase__:      Dict			  =model(__lowercase)

    lowerCamelCase__:      Union[str, Any]			  =[input_ids, input_mask]
    lowerCamelCase__:      Optional[Any]			  =model(__lowercase)

    lowerCamelCase__:      str			  =model(__lowercase)

    self.parent.assertEqual(
        result.last_hidden_state.shape       , (self.batch_size, self.seq_length, self.hidden_size))
    self.parent.assertEqual(result.pooler_output.shape       , (self.batch_size, self.hidden_size))

  def 							SCREAMING_SNAKE_CASE_					(self				:   Union[str, Any]       , UpperCAmelCase_				:   Any       , UpperCAmelCase_				:   Tuple       , UpperCAmelCase_				:   Union[str, Any]       , UpperCAmelCase_				:   Optional[Any]       , UpperCAmelCase_				:   Optional[Any]       , UpperCAmelCase_				:   Dict       , UpperCAmelCase_				:   Tuple)       ->Dict:



    '''simple docstring'''



    lowerCamelCase__:      int			  =TFMobileBertForMaskedLM(config=__lowercase)
    lowerCamelCase__:      Optional[int]			  ={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
    lowerCamelCase__:      Union[str, Any]			  =model(__lowercase)
    self.parent.assertEqual(result.logits.shape       , (self.batch_size, self.seq_length, self.vocab_size))

  def 							SCREAMING_SNAKE_CASE_					(self				:   Any       , UpperCAmelCase_				:   Optional[Any]       , UpperCAmelCase_				:   Any       , UpperCAmelCase_				:   Union[str, Any]       , UpperCAmelCase_				:   int       , UpperCAmelCase_				:   int       , UpperCAmelCase_				:   Tuple       , UpperCAmelCase_				:   Union[str, Any])       ->Optional[Any]:



    '''simple docstring'''



    lowerCamelCase__:      int			  =TFMobileBertForNextSentencePrediction(config=__lowercase)
    lowerCamelCase__:      Any			  ={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
    lowerCamelCase__:      Optional[int]			  =model(__lowercase)
    self.parent.assertEqual(result.logits.shape       , (self.batch_size, 2))

  def 							SCREAMING_SNAKE_CASE_					(self				:   Tuple       , UpperCAmelCase_				:   Dict       , UpperCAmelCase_				:   Union[str, Any]       , UpperCAmelCase_				:   Any       , UpperCAmelCase_				:   List[Any]       , UpperCAmelCase_				:   str       , UpperCAmelCase_				:   Optional[Any]       , UpperCAmelCase_				:   List[Any])       ->List[Any]:



    '''simple docstring'''



    lowerCamelCase__:      List[str]			  =TFMobileBertForPreTraining(config=__lowercase)
    lowerCamelCase__:      int			  ={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
    lowerCamelCase__:      Optional[Any]			  =model(__lowercase)
    self.parent.assertEqual(
        result.prediction_logits.shape       , (self.batch_size, self.seq_length, self.vocab_size))
    self.parent.assertEqual(result.seq_relationship_logits.shape       , (self.batch_size, 2))

  def 							SCREAMING_SNAKE_CASE_					(self				:   Dict       , UpperCAmelCase_				:   Any       , UpperCAmelCase_				:   Optional[Any]       , UpperCAmelCase_				:   Optional[int]       , UpperCAmelCase_				:   int       , UpperCAmelCase_				:   List[Any]       , UpperCAmelCase_				:   Dict       , UpperCAmelCase_				:   Optional[int])       ->Union[str, Any]:



    '''simple docstring'''



    lowerCamelCase__:      Any			  =self.num_labels
    lowerCamelCase__:      Dict			  =TFMobileBertForSequenceClassification(config=__lowercase)
    lowerCamelCase__:      Union[str, Any]			  ={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
    lowerCamelCase__:      List[Any]			  =model(__lowercase)
    self.parent.assertEqual(result.logits.shape       , (self.batch_size, self.num_labels))

  def 							SCREAMING_SNAKE_CASE_					(self				:   Any       , UpperCAmelCase_				:   List[Any]       , UpperCAmelCase_				:   Optional[Any]       , UpperCAmelCase_				:   List[Any]       , UpperCAmelCase_				:   List[str]       , UpperCAmelCase_				:   List[str]       , UpperCAmelCase_				:   Dict       , UpperCAmelCase_				:   List[str])       ->int:



    '''simple docstring'''



    lowerCamelCase__:      Union[str, Any]			  =self.num_choices
    lowerCamelCase__:      Optional[Any]			  =TFMobileBertForMultipleChoice(config=__lowercase)
    lowerCamelCase__:      Dict			  =tf.tile(tf.expand_dims(__lowercase       , 1)       , (1, self.num_choices, 1))
    lowerCamelCase__:      Union[str, Any]			  =tf.tile(tf.expand_dims(__lowercase       , 1)       , (1, self.num_choices, 1))
    lowerCamelCase__:      Union[str, Any]			  =tf.tile(tf.expand_dims(__lowercase       , 1)       , (1, self.num_choices, 1))
    lowerCamelCase__:      Any			  ={
        '''input_ids''': multiple_choice_inputs_ids,
        '''attention_mask''': multiple_choice_input_mask,
        '''token_type_ids''': multiple_choice_token_type_ids,
    }
    lowerCamelCase__:      Optional[int]			  =model(__lowercase)
    self.parent.assertEqual(result.logits.shape       , (self.batch_size, self.num_choices))

  def 							SCREAMING_SNAKE_CASE_					(self				:   List[Any]       , UpperCAmelCase_				:   int       , UpperCAmelCase_				:   Union[str, Any]       , UpperCAmelCase_				:   Optional[int]       , UpperCAmelCase_				:   Any       , UpperCAmelCase_				:   str       , UpperCAmelCase_				:   int       , UpperCAmelCase_				:   List[str])       ->Tuple:



    '''simple docstring'''



    lowerCamelCase__:      Optional[int]			  =self.num_labels
    lowerCamelCase__:      Optional[int]			  =TFMobileBertForTokenClassification(config=__lowercase)
    lowerCamelCase__:      Optional[Any]			  ={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
    lowerCamelCase__:      Optional[Any]			  =model(__lowercase)
    self.parent.assertEqual(result.logits.shape       , (self.batch_size, self.seq_length, self.num_labels))

  def 							SCREAMING_SNAKE_CASE_					(self				:   int       , UpperCAmelCase_				:   Tuple       , UpperCAmelCase_				:   List[Any]       , UpperCAmelCase_				:   Tuple       , UpperCAmelCase_				:   Union[str, Any]       , UpperCAmelCase_				:   List[Any]       , UpperCAmelCase_				:   int       , UpperCAmelCase_				:   Union[str, Any])       ->int:



    '''simple docstring'''



    lowerCamelCase__:      int			  =TFMobileBertForQuestionAnswering(config=__lowercase)
    lowerCamelCase__:      List[Any]			  ={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
    lowerCamelCase__:      Any			  =model(__lowercase)
    self.parent.assertEqual(result.start_logits.shape       , (self.batch_size, self.seq_length))
    self.parent.assertEqual(result.end_logits.shape       , (self.batch_size, self.seq_length))







  def 							SCREAMING_SNAKE_CASE_					(self				:   str)       ->Tuple:



    '''simple docstring'''



    lowerCamelCase__:      Optional[Any]			  =self.prepare_config_and_inputs()
    (
        lowerCamelCase__       
    ):      List[str]			  =config_and_inputs
    lowerCamelCase__:      str			  ={'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
    return config, inputs_dict



 def 							SCREAMING_SNAKE_CASE_					(self				:   Optional[int])       ->Tuple:



   '''simple docstring'''



   lowerCamelCase__:      List[Any]			  =TFMobileBertModelTest.TFMobileBertModelTester(self)
   lowerCamelCase__:      str			  =ConfigTester(self       , config_class=__lowercase       , hidden_size=37)

 def 							SCREAMING_SNAKE_CASE_					(self				:   Tuple)       ->List[Any]:



   '''simple docstring'''



   self.config_tester.run_common_tests()

 def 							SCREAMING_SNAKE_CASE_					(self				:   Tuple)       ->Tuple:



   '''simple docstring'''



   lowerCamelCase__:      Any			  =self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_mobilebert_model(*__lowercase)

 def 							SCREAMING_SNAKE_CASE_					(self				:   str)       ->Optional[Any]:



   '''simple docstring'''



   lowerCamelCase__:      Union[str, Any]			  =self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_mobilebert_for_masked_lm(*__lowercase)

 def 							SCREAMING_SNAKE_CASE_					(self				:   Union[str, Any])       ->Optional[Any]:



   '''simple docstring'''



   lowerCamelCase__:      Tuple			  =self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_mobilebert_for_multiple_choice(*__lowercase)

 def 							SCREAMING_SNAKE_CASE_					(self				:   List[str])       ->Dict:



   '''simple docstring'''



   lowerCamelCase__:      int			  =self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*__lowercase)

 def 							SCREAMING_SNAKE_CASE_					(self				:   List[str])       ->Tuple:



   '''simple docstring'''



   lowerCamelCase__:      Optional[Any]			  =self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_mobilebert_for_pretraining(*__lowercase)

 def 							SCREAMING_SNAKE_CASE_					(self				:   List[Any])       ->List[Any]:



   '''simple docstring'''



   lowerCamelCase__:      List[Any]			  =self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_mobilebert_for_question_answering(*__lowercase)

 def 							SCREAMING_SNAKE_CASE_					(self				:   Dict)       ->Any:



   '''simple docstring'''



   lowerCamelCase__:      List[str]			  =self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_mobilebert_for_sequence_classification(*__lowercase)

 def 							SCREAMING_SNAKE_CASE_					(self				:   Optional[Any])       ->Optional[int]:



   '''simple docstring'''



   lowerCamelCase__:      str			  =self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_mobilebert_for_token_classification(*__lowercase)







 @slow
 def 							SCREAMING_SNAKE_CASE_					(self				:   List[str])       ->List[Any]:



   '''simple docstring'''



   for model_name in ["google/mobilebert-uncased"]:
     lowerCamelCase__:      List[str]			  =TFMobileBertModel.from_pretrained(__lowercase)
     self.assertIsNotNone(__lowercase)



@require_tf
class    _SCREAMING_SNAKE_CASE						(	unittest.TestCase    ):







 '''simple docstring'''

 @slow
 def 							SCREAMING_SNAKE_CASE_					(self				:   Tuple)       ->Any:



   '''simple docstring'''



   lowerCamelCase__:      Union[str, Any]			  =TFMobileBertForPreTraining.from_pretrained("google/mobilebert-uncased")
   lowerCamelCase__:      Any			  =tf.constant([[0, 1, 2, 3, 4, 5]])
   lowerCamelCase__:      int			  =model(__lowercase)[0]

   lowerCamelCase__:      Optional[Any]			  =[1, 6, 30_522]
   self.assertEqual(output.shape       , __lowercase)

   lowerCamelCase__:      Dict			  =tf.constant(
       [
           [
               [-4.591_9547, -9.24_8295, -9.64_5256],
               [-6.730_6175, -6.44_0284, -6.605_2837],
               [-7.274_3506, -6.784_7915, -6.02_4673],
           ]
       ])
   tf.debugging.assert_near(output[:, :3, :3]       , __lowercase       , atol=1E-4)


import unittest

import numpy as np
import torch
from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    DPMSolverMultistepScheduler,
    TextToVideoSDPipeline,
    UNetaDConditionModel,
)
from diffusers.utils import is_xformers_available, load_numpy, skip_mps, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism

from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_PARAMS
from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()


@skip_mps
class 	lowerCamelCase_     (   UpperCAmelCase_						,	unittest.TestCase ):






    '''simple docstring'''






    a__	:						str						=      TextToVideoSDPipeline
    a__	:						Union[str, Any]						=      TEXT_TO_IMAGE_PARAMS
    a__	:						Tuple						=      TEXT_TO_IMAGE_BATCH_PARAMS
    # No `output_type`.
    a__	:						int						=      frozenset(
        [
            """num_inference_steps""",
            """generator""",
            """latents""",
            """return_dict""",
            """callback""",
            """callback_steps""",
        ] )







    def 			UpperCamelCase__   (	self)       ->	Optional[Any]:
        torch.manual_seed(0)
        __UpperCamelCase     :str			  =		UNetaDConditionModel(
            block_out_channels=(32, 64, 64, 64) , layers_per_block=2 , sample_size=32 , in_channels=4 , out_channels=4 , down_block_types=('''CrossAttnDownBlock3D''', '''CrossAttnDownBlock3D''', '''CrossAttnDownBlock3D''', '''DownBlock3D''') , up_block_types=('''UpBlock3D''', '''CrossAttnUpBlock3D''', '''CrossAttnUpBlock3D''', '''CrossAttnUpBlock3D''') , cross_attention_dim=32 , attention_head_dim=4 , )
        __UpperCamelCase     :Optional[int]			  =		DDIMScheduler(
            beta_start=0.0_00_85 , beta_end=0.0_12 , beta_schedule='''scaled_linear''' , clip_sample=__lowercase , set_alpha_to_one=__lowercase , )
        torch.manual_seed(0)
        __UpperCamelCase     :Optional[int]			  =		AutoencoderKL(
            block_out_channels=[32, 64] , in_channels=3 , out_channels=3 , down_block_types=['''DownEncoderBlock2D''', '''DownEncoderBlock2D'''] , up_block_types=['''UpDecoderBlock2D''', '''UpDecoderBlock2D'''] , latent_channels=4 , sample_size=128 , )
        torch.manual_seed(0)
        __UpperCamelCase     :Optional[int]			  =		CLIPTextConfig(
            bos_token_id=0 , eos_token_id=2 , hidden_size=32 , intermediate_size=37 , layer_norm_eps=1E-0_5 , num_attention_heads=4 , num_hidden_layers=5 , pad_token_id=1 , vocab_size=1_000 , hidden_act='''gelu''' , projection_dim=512 , )
        __UpperCamelCase     :Optional[Any]			  =		CLIPTextModel(__lowercase)
        __UpperCamelCase     :Optional[int]			  =		CLIPTokenizer.from_pretrained('''hf-internal-testing/tiny-random-clip''')

        __UpperCamelCase     :Union[str, Any]			  =		{
            '''unet''': unet,
            '''scheduler''': scheduler,
            '''vae''': vae,
            '''text_encoder''': text_encoder,
            '''tokenizer''': tokenizer,
        }
        return components







    def 			UpperCamelCase__   (	self , __lowercase , __lowercase=0)       ->	Optional[int]:
        if str(__lowercase).startswith('''mps'''):
            __UpperCamelCase     :List[Any]			  =		torch.manual_seed(__lowercase)
        else:
            __UpperCamelCase     :Tuple			  =		torch.Generator(device=__lowercase).manual_seed(__lowercase)
        __UpperCamelCase     :Dict			  =		{
            '''prompt''': '''A painting of a squirrel eating a burger''',
            '''generator''': generator,
            '''num_inference_steps''': 2,
            '''guidance_scale''': 6.0,
            '''output_type''': '''pt''',
        }
        return inputs







    def 			UpperCamelCase__   (	self)       ->	Optional[Any]:
        __UpperCamelCase     :int			  =		'''cpu'''  # ensure determinism for the device-dependent torch.Generator
        __UpperCamelCase     :Optional[int]			  =		self.get_dummy_components()
        __UpperCamelCase     :Dict			  =		TextToVideoSDPipeline(**__lowercase)
        __UpperCamelCase     :Any			  =		sd_pipe.to(__lowercase)
        sd_pipe.set_progress_bar_config(disable=__lowercase)

        __UpperCamelCase     :Optional[Any]			  =		self.get_dummy_inputs(__lowercase)
        __UpperCamelCase     :int			  =		'''np'''
        __UpperCamelCase     :List[str]			  =		sd_pipe(**__lowercase).frames
        __UpperCamelCase     :Optional[Any]			  =		frames[0][-3:, -3:, -1]

        assert frames[0].shape == (64, 64, 3)
        __UpperCamelCase     :str			  =		np.array([1_58.0, 1_60.0, 1_53.0, 1_25.0, 1_00.0, 1_21.0, 1_11.0, 93.0, 1_13.0])

        assert np.abs(image_slice.flatten() - expected_slice).max() < 1E-2







    def 			UpperCamelCase__   (	self)       ->	Tuple:
        self._test_attention_slicing_forward_pass(test_mean_pixel_difference=__lowercase , expected_max_diff=3E-3)







    @unittest.skipIf(
        torch_device != '''cuda''' or not is_xformers_available() , reason='''XFormers attention is only available with CUDA and `xformers` installed''' , )
    def 			UpperCamelCase__   (	self)       ->	Optional[int]:
        self._test_xformers_attention_forwardGenerator_pass(test_mean_pixel_difference=__lowercase , expected_max_diff=1E-2)







    @unittest.skip(reason='''Batching needs to be properly figured out first for this pipeline.''')
    def 			UpperCamelCase__   (	self)       ->	Union[str, Any]:
        pass







    @unittest.skip(reason='''Batching needs to be properly figured out first for this pipeline.''')
    def 			UpperCamelCase__   (	self)       ->	Dict:
        pass







    @unittest.skip(reason='''`num_images_per_prompt` argument is not supported for this pipeline.''')
    def 			UpperCamelCase__   (	self)       ->	str:
        pass







    def 			UpperCamelCase__   (	self)       ->	List[str]:
        return super().test_progress_bar()


@slow
@skip_mps
class 	lowerCamelCase_     (   unittest.TestCase ):






    '''simple docstring'''






    def 			UpperCamelCase__   (	self)       ->	Dict:
        __UpperCamelCase     :Union[str, Any]			  =		load_numpy(
            '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/text_to_video/video.npy''')

        __UpperCamelCase     :List[str]			  =		TextToVideoSDPipeline.from_pretrained('''damo-vilab/text-to-video-ms-1.7b''')
        __UpperCamelCase     :Union[str, Any]			  =		DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
        __UpperCamelCase     :str			  =		pipe.to('''cuda''')

        __UpperCamelCase     :Optional[Any]			  =		'''Spiderman is surfing'''
        __UpperCamelCase     :Union[str, Any]			  =		torch.Generator(device='''cpu''').manual_seed(0)

        __UpperCamelCase     :List[Any]			  =		pipe(__lowercase , generator=__lowercase , num_inference_steps=25 , output_type='''pt''').frames
        __UpperCamelCase     :Optional[int]			  =		video_frames.cpu().numpy()

        assert np.abs(expected_video - video).mean() < 5E-2







    def 			UpperCamelCase__   (	self)       ->	int:
        __UpperCamelCase     :str			  =		load_numpy(
            '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/text_to_video/video_2step.npy''')

        __UpperCamelCase     :Union[str, Any]			  =		TextToVideoSDPipeline.from_pretrained('''damo-vilab/text-to-video-ms-1.7b''')
        __UpperCamelCase     :str			  =		pipe.to('''cuda''')

        __UpperCamelCase     :Union[str, Any]			  =		'''Spiderman is surfing'''
        __UpperCamelCase     :int			  =		torch.Generator(device='''cpu''').manual_seed(0)

        __UpperCamelCase     :List[Any]			  =		pipe(__lowercase , generator=__lowercase , num_inference_steps=2 , output_type='''pt''').frames
        __UpperCamelCase     :Optional[Any]			  =		video_frames.cpu().numpy()

        assert np.abs(expected_video - video).mean() < 5E-2





