"""simple docstring"""




from typing import Any, Callable, Dict, List, Optional, Union

import torch
from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    DiffusionPipeline,
    LMSDiscreteScheduler,
    PNDMScheduler,
    StableDiffusionPipeline,
    UNetaDConditionModel,
)
from diffusers.pipelines.stable_diffusion import StableDiffusionPipelineOutput
from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker


__lowerCamelCase											=  "CompVis/stable-diffusion-v1-1"
__lowerCamelCase											=  "CompVis/stable-diffusion-v1-2"
__lowerCamelCase											=  "CompVis/stable-diffusion-v1-3"
__lowerCamelCase											=  "CompVis/stable-diffusion-v1-4"
class     UpperCamelCase__(			__A ):





						def __init__(       self		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase = True		,)					->				Optional[Any]:
													super()._init_()

													A__	     =							StableDiffusionPipeline.from_pretrained(__UpperCAmelCase     )
													A__	     =							StableDiffusionPipeline.from_pretrained(__UpperCAmelCase     )
													A__	     =							StableDiffusionPipeline.from_pretrained(__UpperCAmelCase     )
													A__	     =							StableDiffusionPipeline(
													    vae=__UpperCAmelCase		,text_encoder=__UpperCAmelCase		,tokenizer=__UpperCAmelCase		,unet=__UpperCAmelCase		,scheduler=__UpperCAmelCase		,safety_checker=__UpperCAmelCase		,feature_extractor=__UpperCAmelCase		,requires_safety_checker=__UpperCAmelCase		,)

													self.register_modules(pipelinea=self.pipea		,pipelinea=self.pipea		,pipelinea=self.pipea		,pipelinea=self.pipea     )





						@property
						def 				snake_case__	(       self     )					->				Dict[str, Any]:
													return {k: getattr(self		,__UpperCAmelCase     ) for k in self.config.keys() if not k.startswith('_'     )}





						def 				snake_case__	(       self		,__UpperCAmelCase = "auto"     )					->				Optional[Any]:
													if slice_size == "auto":
																				# half the attention head size is usually a good trade-off between
																				# speed and memory
																				A__	     =							self.unet.config.attention_head_dim // 2
													self.unet.set_attention_slice(__UpperCAmelCase     )





						def 				snake_case__	(       self     )					->				Optional[Any]:
													self.enable_attention_slicing(__UpperCAmelCase     )





						@torch.no_grad()
						def 				snake_case__	(       self		,__UpperCAmelCase		,__UpperCAmelCase = 5_12		,__UpperCAmelCase = 5_12		,__UpperCAmelCase = 50		,__UpperCAmelCase = 7.5		,__UpperCAmelCase = None		,__UpperCAmelCase = 1		,__UpperCAmelCase = 0.0		,__UpperCAmelCase = None		,__UpperCAmelCase = None		,__UpperCAmelCase = "pil"		,__UpperCAmelCase = True		,__UpperCAmelCase = None		,__UpperCAmelCase = 1		,**__UpperCAmelCase		,)					->				List[str]:
													return self.pipea(
													    prompt=__UpperCAmelCase		,height=__UpperCAmelCase		,width=__UpperCAmelCase		,num_inference_steps=__UpperCAmelCase		,guidance_scale=__UpperCAmelCase		,negative_prompt=__UpperCAmelCase		,num_images_per_prompt=__UpperCAmelCase		,eta=__UpperCAmelCase		,generator=__UpperCAmelCase		,latents=__UpperCAmelCase		,output_type=__UpperCAmelCase		,return_dict=__UpperCAmelCase		,callback=__UpperCAmelCase		,callback_steps=__UpperCAmelCase		,**__UpperCAmelCase		,)





						@torch.no_grad()
						def 				snake_case__	(       self		,__UpperCAmelCase		,__UpperCAmelCase = 5_12		,__UpperCAmelCase = 5_12		,__UpperCAmelCase = 50		,__UpperCAmelCase = 7.5		,__UpperCAmelCase = None		,__UpperCAmelCase = 1		,__UpperCAmelCase = 0.0		,__UpperCAmelCase = None		,__UpperCAmelCase = None		,__UpperCAmelCase = "pil"		,__UpperCAmelCase = True		,__UpperCAmelCase = None		,__UpperCAmelCase = 1		,**__UpperCAmelCase		,)					->				Optional[int]:
													return self.pipea(
													    prompt=__UpperCAmelCase		,height=__UpperCAmelCase		,width=__UpperCAmelCase		,num_inference_steps=__UpperCAmelCase		,guidance_scale=__UpperCAmelCase		,negative_prompt=__UpperCAmelCase		,num_images_per_prompt=__UpperCAmelCase		,eta=__UpperCAmelCase		,generator=__UpperCAmelCase		,latents=__UpperCAmelCase		,output_type=__UpperCAmelCase		,return_dict=__UpperCAmelCase		,callback=__UpperCAmelCase		,callback_steps=__UpperCAmelCase		,**__UpperCAmelCase		,)





						@torch.no_grad()
						def 				snake_case__	(       self		,__UpperCAmelCase		,__UpperCAmelCase = 5_12		,__UpperCAmelCase = 5_12		,__UpperCAmelCase = 50		,__UpperCAmelCase = 7.5		,__UpperCAmelCase = None		,__UpperCAmelCase = 1		,__UpperCAmelCase = 0.0		,__UpperCAmelCase = None		,__UpperCAmelCase = None		,__UpperCAmelCase = "pil"		,__UpperCAmelCase = True		,__UpperCAmelCase = None		,__UpperCAmelCase = 1		,**__UpperCAmelCase		,)					->				List[Any]:
													return self.pipea(
													    prompt=__UpperCAmelCase		,height=__UpperCAmelCase		,width=__UpperCAmelCase		,num_inference_steps=__UpperCAmelCase		,guidance_scale=__UpperCAmelCase		,negative_prompt=__UpperCAmelCase		,num_images_per_prompt=__UpperCAmelCase		,eta=__UpperCAmelCase		,generator=__UpperCAmelCase		,latents=__UpperCAmelCase		,output_type=__UpperCAmelCase		,return_dict=__UpperCAmelCase		,callback=__UpperCAmelCase		,callback_steps=__UpperCAmelCase		,**__UpperCAmelCase		,)





						@torch.no_grad()
						def 				snake_case__	(       self		,__UpperCAmelCase		,__UpperCAmelCase = 5_12		,__UpperCAmelCase = 5_12		,__UpperCAmelCase = 50		,__UpperCAmelCase = 7.5		,__UpperCAmelCase = None		,__UpperCAmelCase = 1		,__UpperCAmelCase = 0.0		,__UpperCAmelCase = None		,__UpperCAmelCase = None		,__UpperCAmelCase = "pil"		,__UpperCAmelCase = True		,__UpperCAmelCase = None		,__UpperCAmelCase = 1		,**__UpperCAmelCase		,)					->				Dict:
													return self.pipea(
													    prompt=__UpperCAmelCase		,height=__UpperCAmelCase		,width=__UpperCAmelCase		,num_inference_steps=__UpperCAmelCase		,guidance_scale=__UpperCAmelCase		,negative_prompt=__UpperCAmelCase		,num_images_per_prompt=__UpperCAmelCase		,eta=__UpperCAmelCase		,generator=__UpperCAmelCase		,latents=__UpperCAmelCase		,output_type=__UpperCAmelCase		,return_dict=__UpperCAmelCase		,callback=__UpperCAmelCase		,callback_steps=__UpperCAmelCase		,**__UpperCAmelCase		,)





						@torch.no_grad()
						def 				snake_case__	(       self		,__UpperCAmelCase		,__UpperCAmelCase = 5_12		,__UpperCAmelCase = 5_12		,__UpperCAmelCase = 50		,__UpperCAmelCase = 7.5		,__UpperCAmelCase = None		,__UpperCAmelCase = 1		,__UpperCAmelCase = 0.0		,__UpperCAmelCase = None		,__UpperCAmelCase = None		,__UpperCAmelCase = "pil"		,__UpperCAmelCase = True		,__UpperCAmelCase = None		,__UpperCAmelCase = 1		,**__UpperCAmelCase		,)					->				Any:
													A__	     =							'cuda' if torch.cuda.is_available() else 'cpu'
													self.to(__UpperCAmelCase     )

													# Checks if the height and width are divisible by 8 or not
													if height % 8 != 0 or width % 8 != 0:
																				raise ValueError(f'''`height` and `width` must be divisible by 8 but are {height} and {width}.'''     )

													# Get first result from Stable Diffusion Checkpoint v1.1
													A__	     =							self.textaimg_sda_a(
													    prompt=__UpperCAmelCase		,height=__UpperCAmelCase		,width=__UpperCAmelCase		,num_inference_steps=__UpperCAmelCase		,guidance_scale=__UpperCAmelCase		,negative_prompt=__UpperCAmelCase		,num_images_per_prompt=__UpperCAmelCase		,eta=__UpperCAmelCase		,generator=__UpperCAmelCase		,latents=__UpperCAmelCase		,output_type=__UpperCAmelCase		,return_dict=__UpperCAmelCase		,callback=__UpperCAmelCase		,callback_steps=__UpperCAmelCase		,**__UpperCAmelCase		,)

													# Get first result from Stable Diffusion Checkpoint v1.2
													A__	     =							self.textaimg_sda_a(
													    prompt=__UpperCAmelCase		,height=__UpperCAmelCase		,width=__UpperCAmelCase		,num_inference_steps=__UpperCAmelCase		,guidance_scale=__UpperCAmelCase		,negative_prompt=__UpperCAmelCase		,num_images_per_prompt=__UpperCAmelCase		,eta=__UpperCAmelCase		,generator=__UpperCAmelCase		,latents=__UpperCAmelCase		,output_type=__UpperCAmelCase		,return_dict=__UpperCAmelCase		,callback=__UpperCAmelCase		,callback_steps=__UpperCAmelCase		,**__UpperCAmelCase		,)

													# Get first result from Stable Diffusion Checkpoint v1.3
													A__	     =							self.textaimg_sda_a(
													    prompt=__UpperCAmelCase		,height=__UpperCAmelCase		,width=__UpperCAmelCase		,num_inference_steps=__UpperCAmelCase		,guidance_scale=__UpperCAmelCase		,negative_prompt=__UpperCAmelCase		,num_images_per_prompt=__UpperCAmelCase		,eta=__UpperCAmelCase		,generator=__UpperCAmelCase		,latents=__UpperCAmelCase		,output_type=__UpperCAmelCase		,return_dict=__UpperCAmelCase		,callback=__UpperCAmelCase		,callback_steps=__UpperCAmelCase		,**__UpperCAmelCase		,)

													# Get first result from Stable Diffusion Checkpoint v1.4
													A__	     =							self.textaimg_sda_a(
													    prompt=__UpperCAmelCase		,height=__UpperCAmelCase		,width=__UpperCAmelCase		,num_inference_steps=__UpperCAmelCase		,guidance_scale=__UpperCAmelCase		,negative_prompt=__UpperCAmelCase		,num_images_per_prompt=__UpperCAmelCase		,eta=__UpperCAmelCase		,generator=__UpperCAmelCase		,latents=__UpperCAmelCase		,output_type=__UpperCAmelCase		,return_dict=__UpperCAmelCase		,callback=__UpperCAmelCase		,callback_steps=__UpperCAmelCase		,**__UpperCAmelCase		,)

													# Get all result images into a single list and pass it via StableDiffusionPipelineOutput for final result
													return StableDiffusionPipelineOutput([resa[0], resa[0], resa[0], resa[0]]     )






"""simple docstring"""




import os
import unittest

from transformers.models.cpmant.tokenization_cpmant import VOCAB_FILES_NAMES, CpmAntTokenizer
from transformers.testing_utils import require_jieba, tooslow

from ...test_tokenization_common import TokenizerTesterMixin
@require_jieba
class     UpperCamelCase__(			__A		,						unittest.TestCase ):
						lowerCAmelCase__  :						Optional[int]													=		CpmAntTokenizer
						lowerCAmelCase__  :						List[str]													=		False





						def 				snake_case__	(       self     )					->				Dict:
													super().setUp()

													A__	     =							[
													    '<d>',
													    '</d>',
													    '<s>',
													    '</s>',
													    '</_>',
													    '<unk>',
													    '<pad>',
													    '</n>',
													    '我',
													    '是',
													    'C',
													    'P',
													    'M',
													    'A',
													    'n',
													    't',
													]
													A__	     =							os.path.join(self.tmpdirname		,VOCAB_FILES_NAMES['vocab_file']     )
													with open(self.vocab_file		,'w'		,encoding='utf-8'     ) as vocab_writer:
																				vocab_writer.write(''.join([x + '\n' for x in vocab_tokens]     )     )





						@tooslow
						def 				snake_case__	(       self     )					->				List[Any]:
													A__	     =							CpmAntTokenizer.from_pretrained('openbmb/cpm-ant-10b'     )
													A__	     =							'今天天气真好！'
													A__	     =							['今天', '天气', '真', '好', '！']
													A__	     =							tokenizer.tokenize(__UpperCAmelCase     )
													self.assertListEqual(__UpperCAmelCase		,__UpperCAmelCase     )
													A__	     =							'今天天气真好！'
													A__	     =							[tokenizer.bos_token] + tokens

													A__	     =							[6, 98_02, 1_49_62, 20_82, 8_31, 2_44]
													self.assertListEqual(tokenizer.convert_tokens_to_ids(__UpperCAmelCase     )		,__UpperCAmelCase     )

													A__	     =							tokenizer.decode(__UpperCAmelCase     )
													self.assertEqual(__UpperCAmelCase		,__UpperCAmelCase     )





