





import unittest

from transformers import (
    MODEL_FOR_CAUSAL_LM_MAPPING,
    TF_MODEL_FOR_CAUSAL_LM_MAPPING,
    TextGenerationPipeline,
    logging,
    pipeline,
)
from transformers.testing_utils import (
    CaptureLogger,
    is_pipeline_test,
    require_accelerate,
    require_tf,
    require_torch,
    require_torch_gpu,
    require_torch_or_tf,
)

from .test_pipelines_common import ANY

@is_pipeline_test
@require_torch_or_tf
class 		UpperCamelCase__ (      unittest.TestCase   ):



     '''simple docstring'''

     __snake_case    :	Union[str, Any]			=			MODEL_FOR_CAUSAL_LM_MAPPING
     __snake_case    :	List[Any]			=			TF_MODEL_FOR_CAUSAL_LM_MAPPING






     @require_torch
     def 				SCREAMING_SNAKE_CASE__  (							self						:    Union[str, Any]       )     ->		Optional[int]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						pipeline(task="""text-generation"""						,model="""sshleifer/tiny-ctrl"""						,framework="""pt"""       )
           # Using `do_sample=False` to force deterministic output
           SCREAMING_SNAKE_CASE		=						text_generator("""This is a test"""						,do_sample=lowerCamelCase__       )
           self.assertEqual(
               lowerCamelCase__						,[
                   {
                       """generated_text""": (
                           """This is a test ☃ ☃ segmental segmental segmental 议议eski eski flutter flutter Lacy oscope."""
                           """ oscope. FiliFili@@"""
                       )
                   }
               ]						,)

           SCREAMING_SNAKE_CASE		=						text_generator(["""This is a test""", """This is a second test"""]       )
           self.assertEqual(
               lowerCamelCase__						,[
                   [
                       {
                           """generated_text""": (
                               """This is a test ☃ ☃ segmental segmental segmental 议议eski eski flutter flutter Lacy oscope."""
                               """ oscope. FiliFili@@"""
                           )
                       }
                   ],
                   [
                       {
                           """generated_text""": (
                               """This is a second test ☃ segmental segmental segmental 议议eski eski flutter flutter Lacy"""
                               """ oscope. oscope. FiliFili@@"""
                           )
                       }
                   ],
               ]						,)

           SCREAMING_SNAKE_CASE		=						text_generator("""This is a test"""						,do_sample=lowerCamelCase__						,num_return_sequences=2						,return_tensors=lowerCamelCase__       )
           self.assertEqual(
               lowerCamelCase__						,[
                   {"""generated_token_ids""": ANY(lowerCamelCase__       )},
                   {"""generated_token_ids""": ANY(lowerCamelCase__       )},
               ]						,)
           SCREAMING_SNAKE_CASE		=						text_generator.model.config.eos_token_id
           SCREAMING_SNAKE_CASE		=						"""<pad>"""
           SCREAMING_SNAKE_CASE		=						text_generator(
               ["""This is a test""", """This is a second test"""]						,do_sample=lowerCamelCase__						,num_return_sequences=2						,batch_size=2						,return_tensors=lowerCamelCase__						,)
           self.assertEqual(
               lowerCamelCase__						,[
                   [
                       {"""generated_token_ids""": ANY(lowerCamelCase__       )},
                       {"""generated_token_ids""": ANY(lowerCamelCase__       )},
                   ],
                   [
                       {"""generated_token_ids""": ANY(lowerCamelCase__       )},
                       {"""generated_token_ids""": ANY(lowerCamelCase__       )},
                   ],
               ]						,)






     @require_tf
     def 				SCREAMING_SNAKE_CASE__  (							self						:    List[str]       )     ->		Tuple:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						pipeline(task="""text-generation"""						,model="""sshleifer/tiny-ctrl"""						,framework="""tf"""       )

           # Using `do_sample=False` to force deterministic output
           SCREAMING_SNAKE_CASE		=						text_generator("""This is a test"""						,do_sample=lowerCamelCase__       )
           self.assertEqual(
               lowerCamelCase__						,[
                   {
                       """generated_text""": (
                           """This is a test FeyFeyFey(Croatis.), s.), Cannes Cannes Cannes 閲閲Cannes Cannes Cannes 攵"""
                           """ please,"""
                       )
                   }
               ]						,)

           SCREAMING_SNAKE_CASE		=						text_generator(["""This is a test""", """This is a second test"""]						,do_sample=lowerCamelCase__       )
           self.assertEqual(
               lowerCamelCase__						,[
                   [
                       {
                           """generated_text""": (
                               """This is a test FeyFeyFey(Croatis.), s.), Cannes Cannes Cannes 閲閲Cannes Cannes Cannes 攵"""
                               """ please,"""
                           )
                       }
                   ],
                   [
                       {
                           """generated_text""": (
                               """This is a second test Chieftain Chieftain prefecture prefecture prefecture Cannes Cannes"""
                               """ Cannes 閲閲Cannes Cannes Cannes 攵 please,"""
                           )
                       }
                   ],
               ]						,)






     def 				SCREAMING_SNAKE_CASE__  (							self						:    Any						,lowerCamelCase__						:    List[str]						,lowerCamelCase__						:    List[str]						,lowerCamelCase__						:    List[str]       )     ->		List[str]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						TextGenerationPipeline(model=lowerCamelCase__						,tokenizer=lowerCamelCase__       )
           return text_generator, ["This is a test", "Another test"]






     def 				SCREAMING_SNAKE_CASE__  (							self						:    Optional[Any]       )     ->		Tuple:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						"""Hello I believe in"""
           SCREAMING_SNAKE_CASE		=						pipeline("""text-generation"""						,model="""hf-internal-testing/tiny-random-gpt2"""       )
           SCREAMING_SNAKE_CASE		=						text_generator(lowerCamelCase__       )
           self.assertEqual(
               lowerCamelCase__						,[{"""generated_text""": """Hello I believe in fe fe fe fe fe fe fe fe fe fe fe fe"""}]						,)

           SCREAMING_SNAKE_CASE		=						text_generator(lowerCamelCase__						,stop_sequence=""" fe"""       )
           self.assertEqual(lowerCamelCase__						,[{"""generated_text""": """Hello I believe in fe"""}]       )






     def 				SCREAMING_SNAKE_CASE__  (							self						:    List[Any]						,lowerCamelCase__						:    int						,lowerCamelCase__						:    Dict       )     ->		str:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						text_generator.model
           SCREAMING_SNAKE_CASE		=						text_generator.tokenizer

           SCREAMING_SNAKE_CASE		=						text_generator("""This is a test"""       )
           self.assertEqual(lowerCamelCase__						,[{"""generated_text""": ANY(lowerCamelCase__       )}]       )
           self.assertTrue(outputs[0]["""generated_text"""].startswith("""This is a test"""       )       )

           SCREAMING_SNAKE_CASE		=						text_generator("""This is a test"""						,return_full_text=lowerCamelCase__       )
           self.assertEqual(lowerCamelCase__						,[{"""generated_text""": ANY(lowerCamelCase__       )}]       )
           self.assertNotIn("""This is a test"""						,outputs[0]["""generated_text"""]       )

           SCREAMING_SNAKE_CASE		=						pipeline(task="""text-generation"""						,model=lowerCamelCase__						,tokenizer=lowerCamelCase__						,return_full_text=lowerCamelCase__       )
           SCREAMING_SNAKE_CASE		=						text_generator("""This is a test"""       )
           self.assertEqual(lowerCamelCase__						,[{"""generated_text""": ANY(lowerCamelCase__       )}]       )
           self.assertNotIn("""This is a test"""						,outputs[0]["""generated_text"""]       )

           SCREAMING_SNAKE_CASE		=						text_generator("""This is a test"""						,return_full_text=lowerCamelCase__       )
           self.assertEqual(lowerCamelCase__						,[{"""generated_text""": ANY(lowerCamelCase__       )}]       )
           self.assertTrue(outputs[0]["""generated_text"""].startswith("""This is a test"""       )       )

           SCREAMING_SNAKE_CASE		=						text_generator(["""This is great !""", """Something else"""]						,num_return_sequences=2						,do_sample=lowerCamelCase__       )
           self.assertEqual(
               lowerCamelCase__						,[
                   [{"""generated_text""": ANY(lowerCamelCase__       )}, {"""generated_text""": ANY(lowerCamelCase__       )}],
                   [{"""generated_text""": ANY(lowerCamelCase__       )}, {"""generated_text""": ANY(lowerCamelCase__       )}],
               ]						,)

           if text_generator.tokenizer.pad_token is not None:
                 SCREAMING_SNAKE_CASE		=						text_generator(
                     ["""This is great !""", """Something else"""]						,num_return_sequences=2						,batch_size=2						,do_sample=lowerCamelCase__       )
                 self.assertEqual(
                     lowerCamelCase__						,[
                         [{"""generated_text""": ANY(lowerCamelCase__       )}, {"""generated_text""": ANY(lowerCamelCase__       )}],
                         [{"""generated_text""": ANY(lowerCamelCase__       )}, {"""generated_text""": ANY(lowerCamelCase__       )}],
                     ]						,)

           with self.assertRaises(lowerCamelCase__       ):
                 SCREAMING_SNAKE_CASE		=						text_generator("""test"""						,return_full_text=lowerCamelCase__						,return_text=lowerCamelCase__       )
           with self.assertRaises(lowerCamelCase__       ):
                 SCREAMING_SNAKE_CASE		=						text_generator("""test"""						,return_full_text=lowerCamelCase__						,return_tensors=lowerCamelCase__       )
           with self.assertRaises(lowerCamelCase__       ):
                 SCREAMING_SNAKE_CASE		=						text_generator("""test"""						,return_text=lowerCamelCase__						,return_tensors=lowerCamelCase__       )

           # Empty prompt is slighly special
           # it requires BOS token to exist.
           # Special case for Pegasus which will always append EOS so will
           # work even without BOS.
           if (
               text_generator.tokenizer.bos_token_id is not None
               or "Pegasus" in tokenizer.__class__.__name__
               or "Git" in model.__class__.__name__
           ):
                 SCREAMING_SNAKE_CASE		=						text_generator(""""""       )
                 self.assertEqual(lowerCamelCase__						,[{"""generated_text""": ANY(lowerCamelCase__       )}]       )
           else:
                 with self.assertRaises((ValueError, AssertionError)       ):
                       SCREAMING_SNAKE_CASE		=						text_generator(""""""       )

           if text_generator.framework == "tf":
                 # TF generation does not support max_new_tokens, and it's impossible
                 # to control long generation with only max_length without
                 # fancy calculation, dismissing tests for now.
                 return
           # We don't care about infinite range models.
           # They already work.
           # Skip this test for XGLM, since it uses sinusoidal positional embeddings which are resized on-the-fly.
           SCREAMING_SNAKE_CASE		=						["""RwkvForCausalLM""", """XGLMForCausalLM""", """GPTNeoXForCausalLM"""]
           if (
               tokenizer.model_max_length < 10000
               and text_generator.model.__class__.__name__ not in EXTRA_MODELS_CAN_HANDLE_LONG_INPUTS
           ):
                 # Handling of large generations
                 with self.assertRaises((RuntimeError, IndexError, ValueError, AssertionError)       ):
                       text_generator("""This is a test""" * 500						,max_new_tokens=20       )

                 SCREAMING_SNAKE_CASE		=						text_generator("""This is a test""" * 500						,handle_long_generation="""hole"""						,max_new_tokens=20       )
                 # Hole strategy cannot work
                 with self.assertRaises(lowerCamelCase__       ):
                       text_generator(
                           """This is a test""" * 500						,handle_long_generation="""hole"""						,max_new_tokens=tokenizer.model_max_length + 10						,)






     @require_torch
     @require_accelerate
     @require_torch_gpu
     def 				SCREAMING_SNAKE_CASE__  (							self						:    Tuple       )     ->		Union[str, Any]:




           '''simple docstring'''


           import torch

           # Classic `model_kwargs`
           SCREAMING_SNAKE_CASE		=						pipeline(
               model="""hf-internal-testing/tiny-random-bloom"""						,model_kwargs={"""device_map""": """auto""", """torch_dtype""": torch.bfloataa}						,)
           self.assertEqual(pipe.model.device						,torch.device(0       )       )
           self.assertEqual(pipe.model.lm_head.weight.dtype						,torch.bfloataa       )
           SCREAMING_SNAKE_CASE		=						pipe("""This is a test"""       )
           self.assertEqual(
               lowerCamelCase__						,[
                   {
                       """generated_text""": (
                           """This is a test test test test test test test test test test test test test test test test"""
                           """ test"""
                       )
                   }
               ]						,)

           # Upgraded those two to real pipeline arguments (they just get sent for the model as they're unlikely to mean anything else.)
           SCREAMING_SNAKE_CASE		=						pipeline(model="""hf-internal-testing/tiny-random-bloom"""						,device_map="""auto"""						,torch_dtype=torch.bfloataa       )
           self.assertEqual(pipe.model.device						,torch.device(0       )       )
           self.assertEqual(pipe.model.lm_head.weight.dtype						,torch.bfloataa       )
           SCREAMING_SNAKE_CASE		=						pipe("""This is a test"""       )
           self.assertEqual(
               lowerCamelCase__						,[
                   {
                       """generated_text""": (
                           """This is a test test test test test test test test test test test test test test test test"""
                           """ test"""
                       )
                   }
               ]						,)

           # torch_dtype will be automatically set to float32 if not provided - check: https://github.com/huggingface/transformers/pull/20602
           SCREAMING_SNAKE_CASE		=						pipeline(model="""hf-internal-testing/tiny-random-bloom"""						,device_map="""auto"""       )
           self.assertEqual(pipe.model.device						,torch.device(0       )       )
           self.assertEqual(pipe.model.lm_head.weight.dtype						,torch.floataa       )
           SCREAMING_SNAKE_CASE		=						pipe("""This is a test"""       )
           self.assertEqual(
               lowerCamelCase__						,[
                   {
                       """generated_text""": (
                           """This is a test test test test test test test test test test test test test test test test"""
                           """ test"""
                       )
                   }
               ]						,)






     @require_torch
     @require_torch_gpu
     def 				SCREAMING_SNAKE_CASE__  (							self						:    int       )     ->		List[str]:




           '''simple docstring'''


           import torch

           SCREAMING_SNAKE_CASE		=						pipeline(model="""hf-internal-testing/tiny-random-bloom"""						,device=0						,torch_dtype=torch.floataa       )
           pipe("""This is a test"""       )






     @require_torch
     @require_accelerate
     @require_torch_gpu
     def 				SCREAMING_SNAKE_CASE__  (							self						:    Union[str, Any]       )     ->		List[str]:




           '''simple docstring'''


           import torch

           SCREAMING_SNAKE_CASE		=						pipeline(model="""hf-internal-testing/tiny-random-bloom"""						,device_map="""auto"""						,torch_dtype=torch.floataa       )
           pipe("""This is a test"""						,do_sample=lowerCamelCase__						,top_p=0.5       )






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




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						"""Hello world"""
           SCREAMING_SNAKE_CASE		=						pipeline("""text-generation"""						,model="""hf-internal-testing/tiny-random-gpt2"""       )
           if text_generator.model.framework == "tf":
                 SCREAMING_SNAKE_CASE		=						logging.get_logger("""transformers.generation.tf_utils"""       )
           else:
                 SCREAMING_SNAKE_CASE		=						logging.get_logger("""transformers.generation.utils"""       )
           SCREAMING_SNAKE_CASE		=						"""Both `max_new_tokens`"""  # The beggining of the message to be checked in this test

           # Both are set by the user -> log warning
           with CaptureLogger(lowerCamelCase__       ) as cl:
                 SCREAMING_SNAKE_CASE		=						text_generator(lowerCamelCase__						,max_length=10						,max_new_tokens=1       )
           self.assertIn(lowerCamelCase__						,cl.out       )

           # The user only sets one -> no warning
           with CaptureLogger(lowerCamelCase__       ) as cl:
                 SCREAMING_SNAKE_CASE		=						text_generator(lowerCamelCase__						,max_new_tokens=1       )
           self.assertNotIn(lowerCamelCase__						,cl.out       )

           with CaptureLogger(lowerCamelCase__       ) as cl:
                 SCREAMING_SNAKE_CASE		=						text_generator(lowerCamelCase__						,max_length=10       )
           self.assertNotIn(lowerCamelCase__						,cl.out       )









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 		UpperCamelCase__ (      lowerCAmelCase_							,      unittest.TestCase   ):



     '''simple docstring'''

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






     def 				SCREAMING_SNAKE_CASE__  (							self						:    Optional[int]       )     ->		Optional[int]:




           '''simple docstring'''


           torch.manual_seed(0       )
           SCREAMING_SNAKE_CASE		=						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						,)
           SCREAMING_SNAKE_CASE		=						DDIMScheduler(
               beta_start=0.00085						,beta_end=0.012						,beta_schedule="""scaled_linear"""						,clip_sample=lowerCamelCase__						,set_alpha_to_one=lowerCamelCase__						,)
           torch.manual_seed(0       )
           SCREAMING_SNAKE_CASE		=						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       )
           SCREAMING_SNAKE_CASE		=						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=1000						,hidden_act="""gelu"""						,projection_dim=512						,)
           SCREAMING_SNAKE_CASE		=						CLIPTextModel(lowerCamelCase__       )
           SCREAMING_SNAKE_CASE		=						CLIPTokenizer.from_pretrained("""hf-internal-testing/tiny-random-clip"""       )

           SCREAMING_SNAKE_CASE		=						{
               """unet""": unet,
               """scheduler""": scheduler,
               """vae""": vae,
               """text_encoder""": text_encoder,
               """tokenizer""": tokenizer,
           }
           return components






     def 				SCREAMING_SNAKE_CASE__  (							self						:    int						,lowerCamelCase__						:    Optional[Any]						,lowerCamelCase__						:    int=0       )     ->		List[Any]:




           '''simple docstring'''


           if str(lowerCamelCase__       ).startswith("""mps"""       ):
                 SCREAMING_SNAKE_CASE		=						torch.manual_seed(lowerCamelCase__       )
           else:
                 SCREAMING_SNAKE_CASE		=						torch.Generator(device=lowerCamelCase__       ).manual_seed(lowerCamelCase__       )
           SCREAMING_SNAKE_CASE		=						{
               """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 				SCREAMING_SNAKE_CASE__  (							self						:    Optional[Any]       )     ->		List[str]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						"""cpu"""  # ensure determinism for the device-dependent torch.Generator
           SCREAMING_SNAKE_CASE		=						self.get_dummy_components()
           SCREAMING_SNAKE_CASE		=						TextToVideoSDPipeline(**lowerCamelCase__       )
           SCREAMING_SNAKE_CASE		=						sd_pipe.to(lowerCamelCase__       )
           sd_pipe.set_progress_bar_config(disable=lowerCamelCase__       )

           SCREAMING_SNAKE_CASE		=						self.get_dummy_inputs(lowerCamelCase__       )
           SCREAMING_SNAKE_CASE		=						"""np"""
           SCREAMING_SNAKE_CASE		=						sd_pipe(**lowerCamelCase__       ).frames
           SCREAMING_SNAKE_CASE		=						frames[0][-3:, -3:, -1]

           assert frames[0].shape == (64, 64, 3)
           SCREAMING_SNAKE_CASE		=						np.array([158.0, 160.0, 153.0, 125.0, 100.0, 121.0, 111.0, 93.0, 113.0]       )

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






     def 				SCREAMING_SNAKE_CASE__  (							self						:    Dict       )     ->		int:




           '''simple docstring'''


           self._test_attention_slicing_forward_pass(test_mean_pixel_difference=lowerCamelCase__						,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 				SCREAMING_SNAKE_CASE__  (							self						:    Tuple       )     ->		Any:




           '''simple docstring'''


           self._test_xformers_attention_forwardGenerator_pass(test_mean_pixel_difference=lowerCamelCase__						,expected_max_diff=1e-2       )






     @unittest.skip(reason="""Batching needs to be properly figured out first for this pipeline."""       )
     def 				SCREAMING_SNAKE_CASE__  (							self						:    Optional[Any]       )     ->		List[Any]:




           '''simple docstring'''


           pass






     @unittest.skip(reason="""Batching needs to be properly figured out first for this pipeline."""       )
     def 				SCREAMING_SNAKE_CASE__  (							self						:    Optional[Any]       )     ->		Any:




           '''simple docstring'''


           pass






     @unittest.skip(reason="""`num_images_per_prompt` argument is not supported for this pipeline."""       )
     def 				SCREAMING_SNAKE_CASE__  (							self						:    Optional[int]       )     ->		Tuple:




           '''simple docstring'''


           pass






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




           '''simple docstring'''


           return super().test_progress_bar()

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



     '''simple docstring'''

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




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						load_numpy(
               """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/text_to_video/video.npy"""       )

           SCREAMING_SNAKE_CASE		=						TextToVideoSDPipeline.from_pretrained("""damo-vilab/text-to-video-ms-1.7b"""       )
           SCREAMING_SNAKE_CASE		=						DPMSolverMultistepScheduler.from_config(pipe.scheduler.config       )
           SCREAMING_SNAKE_CASE		=						pipe.to("""cuda"""       )

           SCREAMING_SNAKE_CASE		=						"""Spiderman is surfing"""
           SCREAMING_SNAKE_CASE		=						torch.Generator(device="""cpu"""       ).manual_seed(0       )

           SCREAMING_SNAKE_CASE		=						pipe(lowerCamelCase__						,generator=lowerCamelCase__						,num_inference_steps=25						,output_type="""pt"""       ).frames
           SCREAMING_SNAKE_CASE		=						video_frames.cpu().numpy()

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






     def 				SCREAMING_SNAKE_CASE__  (							self						:    Any       )     ->		Any:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						load_numpy(
               """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/text_to_video/video_2step.npy"""       )

           SCREAMING_SNAKE_CASE		=						TextToVideoSDPipeline.from_pretrained("""damo-vilab/text-to-video-ms-1.7b"""       )
           SCREAMING_SNAKE_CASE		=						pipe.to("""cuda"""       )

           SCREAMING_SNAKE_CASE		=						"""Spiderman is surfing"""
           SCREAMING_SNAKE_CASE		=						torch.Generator(device="""cpu"""       ).manual_seed(0       )

           SCREAMING_SNAKE_CASE		=						pipe(lowerCamelCase__						,generator=lowerCamelCase__						,num_inference_steps=2						,output_type="""pt"""       ).frames
           SCREAMING_SNAKE_CASE		=						video_frames.cpu().numpy()

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


