




"""simple docstring"""






import random
import unittest

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

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    UNetaDConditionModel,
    VideoToVideoSDPipeline,
)
from diffusers.utils import floats_tensor, is_xformers_available, skip_mps
from diffusers.utils.testing_utils import enable_full_determinism, slow, torch_device

from ..pipeline_params import (
    TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS,
    TEXT_GUIDED_IMAGE_VARIATION_PARAMS,
)
from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()




@skip_mps
class   a__			(       UpperCamelCase_					,	unittest.TestCase  ):
						snake_case__             = VideoToVideoSDPipeline
						snake_case__             = TEXT_GUIDED_IMAGE_VARIATION_PARAMS.union({'''video'''}  ) - {'''image''', '''width''', '''height'''}
						snake_case__             = TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS.union({'''video'''}  ) - {'''image'''}
						snake_case__             = PipelineTesterMixin.required_optional_params - {'''latents'''}
						snake_case__             = False

						# No `output_type`.
						snake_case__             = frozenset(
						    [
						        '''num_inference_steps''',
						        '''generator''',
						        '''latents''',
						        '''return_dict''',
						        '''callback''',
						        '''callback_steps''',
						    ]  )





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




											"""simple docstring"""







											torch.manual_seed(0)
											_lowerCAmelCase:Optional[int]									=  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     ,)
											_lowerCAmelCase:int									=  DDIMScheduler(
											    beta_start=0.00085     ,beta_end=0.012     ,beta_schedule='''scaled_linear'''     ,clip_sample=a__     ,set_alpha_to_one=a__     ,)
											torch.manual_seed(0)
											_lowerCAmelCase:Dict									=  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)
											_lowerCAmelCase:int									=  CLIPTextConfig(
											    bos_token_id=0     ,eos_token_id=2     ,hidden_size=32     ,intermediate_size=37     ,layer_norm_eps=1E-05     ,num_attention_heads=4     ,num_hidden_layers=5     ,pad_token_id=1     ,vocab_size=1000     ,hidden_act='''gelu'''     ,projection_dim=512     ,)
											_lowerCAmelCase:Any									=  CLIPTextModel(a__)
											_lowerCAmelCase:Any									=  CLIPTokenizer.from_pretrained('''hf-internal-testing/tiny-random-clip''')

											_lowerCAmelCase:str									=  {
											    '''unet''': unet,
											    '''scheduler''': scheduler,
											    '''vae''': vae,
											    '''text_encoder''': text_encoder,
											    '''tokenizer''': tokenizer,
											}
											return components





						def       __UpperCamelCase     (							self      :	List[Any]     ,a__      :	List[Any]     ,a__      :	str=0)						->       Union[str, Any]:




											"""simple docstring"""







											_lowerCAmelCase:Optional[Any]									=  floats_tensor((1, 3, 3, 32, 32)     ,rng=random.Random(a__)).to(a__)

											if str(a__).startswith('''mps'''):
																_lowerCAmelCase:Tuple									=  torch.manual_seed(a__)
											else:
																_lowerCAmelCase:str									=  torch.Generator(device=a__).manual_seed(a__)
											_lowerCAmelCase:Union[str, Any]									=  {
											    '''prompt''': '''A painting of a squirrel eating a burger''',
											    '''video''': video,
											    '''generator''': generator,
											    '''num_inference_steps''': 2,
											    '''guidance_scale''': 6.0,
											    '''output_type''': '''pt''',
											}
											return inputs





						def       __UpperCamelCase     (							self      :	List[str])						->       str:




											"""simple docstring"""







											_lowerCAmelCase:str									=  '''cpu'''  # ensure determinism for the device-dependent torch.Generator
											_lowerCAmelCase:Tuple									=  self.get_dummy_components()
											_lowerCAmelCase:Any									=  VideoToVideoSDPipeline(**a__)
											_lowerCAmelCase:str									=  sd_pipe.to(a__)
											sd_pipe.set_progress_bar_config(disable=a__)

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

											assert frames[0].shape == (32, 32, 3)
											_lowerCAmelCase:Optional[Any]									=  np.array([106, 117, 113, 174, 137, 112, 148, 151, 131])

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





						@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[Any])						->       Union[str, Any]:




											"""simple docstring"""







											self._test_xformers_attention_forwardGenerator_pass(test_mean_pixel_difference=a__     ,expected_max_diff=5E-3)





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




											"""simple docstring"""







											pass





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




											"""simple docstring"""







											pass





						@unittest.skip(reason='''`num_images_per_prompt` argument is not supported for this pipeline.''')
						def       __UpperCamelCase     (							self      :	List[str])						->       Optional[Any]:




											"""simple docstring"""







											pass







						def       __UpperCamelCase     (							self      :	Dict)						->       str:




											"""simple docstring"""







											return super().test_progress_bar()




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





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




											"""simple docstring"""







											_lowerCAmelCase:Optional[int]									=  VideoToVideoSDPipeline.from_pretrained('''cerspense/zeroscope_v2_XL'''     ,torch_dtype=torch.floataa)
											pipe.enable_model_cpu_offload()

											# 10 frames
											_lowerCAmelCase:List[Any]									=  torch.Generator(device='''cpu''').manual_seed(0)
											_lowerCAmelCase:str									=  torch.randn((1, 10, 3, 1024, 576)     ,generator=a__)
											_lowerCAmelCase:Optional[int]									=  video.to('''cuda''')

											_lowerCAmelCase:Optional[Any]									=  '''Spiderman is surfing'''

											_lowerCAmelCase:Tuple									=  pipe(a__     ,video=a__     ,generator=a__     ,num_inference_steps=3     ,output_type='''pt''').frames

											_lowerCAmelCase:Tuple									=  np.array([-1.0458984, -1.1279297, -0.9663086, -0.91503906, -0.75097656])
											assert np.abs(video_frames.cpu().numpy()[0, 0, 0, 0, -5:] - expected_array).sum() < 1E-2












"""simple docstring"""






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


UpperCamelCase__						=			logging.get_logger(__name__)

UpperCamelCase__						=			{
    '''weiweishi/roc-bert-base-zh''': '''https://huggingface.co/weiweishi/roc-bert-base-zh/resolve/main/config.json''',
}




class   a__			(       UpperCamelCase_  ):
						snake_case__             = '''roc_bert'''





						def __init__(							self      :	Union[str, Any]     ,a__      :	Union[str, Any]=3_0522     ,a__      :	List[Any]=768     ,a__      :	Tuple=12     ,a__      :	Optional[int]=12     ,a__      :	Any=3072     ,a__      :	Optional[int]="gelu"     ,a__      :	Union[str, Any]=0.1     ,a__      :	List[str]=0.1     ,a__      :	Dict=512     ,a__      :	int=2     ,a__      :	Dict=0.02     ,a__      :	Dict=1E-12     ,a__      :	int=True     ,a__      :	Optional[int]=0     ,a__      :	Union[str, Any]="absolute"     ,a__      :	List[Any]=None     ,a__      :	str=True     ,a__      :	str=True     ,a__      :	List[str]=768     ,a__      :	Optional[int]=910     ,a__      :	Any=512     ,a__      :	str=2_4858     ,a__      :	List[str]=True     ,**a__      :	str     ,)						->       List[str]:




											"""simple docstring"""







											_lowerCAmelCase:Tuple									=  vocab_size
											_lowerCAmelCase:Any									=  max_position_embeddings
											_lowerCAmelCase:Union[str, Any]									=  hidden_size
											_lowerCAmelCase:Optional[Any]									=  num_hidden_layers
											_lowerCAmelCase:int									=  num_attention_heads
											_lowerCAmelCase:int									=  intermediate_size
											_lowerCAmelCase:Union[str, Any]									=  hidden_act
											_lowerCAmelCase:Any									=  hidden_dropout_prob
											_lowerCAmelCase:List[Any]									=  attention_probs_dropout_prob
											_lowerCAmelCase:List[Any]									=  initializer_range
											_lowerCAmelCase:Dict									=  type_vocab_size
											_lowerCAmelCase:Dict									=  layer_norm_eps
											_lowerCAmelCase:str									=  use_cache
											_lowerCAmelCase:Any									=  enable_pronunciation
											_lowerCAmelCase:List[str]									=  enable_shape
											_lowerCAmelCase:Optional[int]									=  pronunciation_embed_dim
											_lowerCAmelCase:Union[str, Any]									=  pronunciation_vocab_size
											_lowerCAmelCase:str									=  shape_embed_dim
											_lowerCAmelCase:List[Any]									=  shape_vocab_size
											_lowerCAmelCase:str									=  concat_input
											_lowerCAmelCase:Optional[int]									=  position_embedding_type
											_lowerCAmelCase:Any									=  classifier_dropout
											super().__init__(pad_token_id=a__     ,**a__)






