




'''simple docstring'''







import unittest

import numpy as np
import torch

from diffusers import KarrasVePipeline, KarrasVeScheduler, UNetaDModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch, slow, torch_device


enable_full_determinism()


class 			_a  (	unittest.TestCase ):
       @property
       def     A      (	self						:	Union[str, Any]				):



           '''simple docstring'''

           torch.manual_seed(0				)
           UpperCAmelCase			       =		UNetaDModel(
               block_out_channels=(32, 64)   ,				layers_per_block=2   ,				sample_size=32   ,				in_channels=3   ,				out_channels=3   ,				down_block_types=('''DownBlock2D''', '''AttnDownBlock2D''')   ,				up_block_types=('''AttnUpBlock2D''', '''UpBlock2D''')   ,				)
           return model







       def     A      (	self						:	Dict				):



           '''simple docstring'''

           UpperCAmelCase			       =		self.dummy_uncond_unet
           UpperCAmelCase			       =		KarrasVeScheduler()

           UpperCAmelCase			       =		KarrasVePipeline(unet=lowercase   ,				scheduler=lowercase				)
           pipe.to(lowercase				)
           pipe.set_progress_bar_config(disable=lowercase				)

           UpperCAmelCase			       =		torch.manual_seed(0				)
           UpperCAmelCase			       =		pipe(num_inference_steps=2   ,				generator=lowercase   ,				output_type='''numpy'''				).images

           UpperCAmelCase			       =		torch.manual_seed(0				)
           UpperCAmelCase			       =		pipe(num_inference_steps=2   ,				generator=lowercase   ,				output_type='''numpy'''   ,				return_dict=lowercase				)[0]

           UpperCAmelCase			       =		image[0, -3:, -3:, -1]
           UpperCAmelCase			       =		image_from_tuple[0, -3:, -3:, -1]

           assert image.shape == (1, 32, 32, 3)
           UpperCAmelCase			       =		np.array([0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]				)

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






@slow
@require_torch
class 			_a  (	unittest.TestCase ):
       def     A      (	self						:	Union[str, Any]				):



           '''simple docstring'''

           UpperCAmelCase			       =		'''google/ncsnpp-celebahq-256'''
           UpperCAmelCase			       =		UNetaDModel.from_pretrained(lowercase				)
           UpperCAmelCase			       =		KarrasVeScheduler()

           UpperCAmelCase			       =		KarrasVePipeline(unet=lowercase   ,				scheduler=lowercase				)
           pipe.to(lowercase				)
           pipe.set_progress_bar_config(disable=lowercase				)

           UpperCAmelCase			       =		torch.manual_seed(0				)
           UpperCAmelCase			       =		pipe(num_inference_steps=20   ,				generator=lowercase   ,				output_type='''numpy'''				).images

           UpperCAmelCase			       =		image[0, -3:, -3:, -1]
           assert image.shape == (1, 256, 256, 3)
           UpperCAmelCase			       =		np.array([0.578, 0.5811, 0.5924, 0.5809, 0.587, 0.5886, 0.5861, 0.5802, 0.586]				)

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










'''simple docstring'''







import warnings

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding


class 			_a  (	__a ):
       __a				:     int   				=					["""image_processor""", """tokenizer"""]
       __a				:     Union[str, Any]   				=					"""ChineseCLIPImageProcessor"""
       __a				:     List[Any]   				=					("""BertTokenizer""", """BertTokenizerFast""")
       def __init__(	self						:	Dict   ,				lowercase						:	Union[str, Any]=None   ,				lowercase						:	Dict=None   ,				**lowercase						:	Optional[Any]				):



           '''simple docstring'''

           UpperCAmelCase			       =		None
           if "feature_extractor" in kwargs:
               warnings.warn(
                   '''The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`'''
                   ''' instead.'''   ,				lowercase   ,				)
               UpperCAmelCase			       =		kwargs.pop('''feature_extractor'''				)

           UpperCAmelCase			       =		image_processor if image_processor is not None else feature_extractor
           if image_processor is None:
               raise ValueError('''You need to specify an `image_processor`.'''				)
           if tokenizer is None:
               raise ValueError('''You need to specify a `tokenizer`.'''				)

           super().__init__(lowercase   ,				lowercase				)
           UpperCAmelCase			       =		self.image_processor
       def __call__(	self						:	Tuple   ,				lowercase						:	Optional[Any]=None   ,				lowercase						:	Union[str, Any]=None   ,				lowercase						:	int=None   ,				**lowercase						:	Dict				):



           '''simple docstring'''

           if text is None and images is None:
               raise ValueError('''You have to specify either text or images. Both cannot be none.'''				)

           if text is not None:
               UpperCAmelCase			       =		self.tokenizer(lowercase   ,				return_tensors=lowercase   ,				**lowercase				)

           if images is not None:
               UpperCAmelCase			       =		self.image_processor(lowercase   ,				return_tensors=lowercase   ,				**lowercase				)

           if text is not None and images is not None:
               UpperCAmelCase			       =		image_features.pixel_values
               return encoding
           elif text is not None:
               return encoding
           else:
               return BatchEncoding(data=dict(**lowercase				)   ,				tensor_type=lowercase				)
       def     A      (	self						:	int   ,				*lowercase						:	Tuple   ,				**lowercase						:	List[str]				):



           '''simple docstring'''

           return self.tokenizer.batch_decode(*lowercase   ,				**lowercase				)
       def     A      (	self						:	Optional[Any]   ,				*lowercase						:	int   ,				**lowercase						:	Optional[int]				):



           '''simple docstring'''

           return self.tokenizer.decode(*lowercase   ,				**lowercase				)
       @property
       def     A      (	self						:	Optional[int]				):



           '''simple docstring'''

           UpperCAmelCase			       =		self.tokenizer.model_input_names
           UpperCAmelCase			       =		self.image_processor.model_input_names
           return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names				)				)







       @property
       def     A      (	self						:	List[Any]				):



           '''simple docstring'''

           warnings.warn(
               '''`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.'''   ,				lowercase   ,				)
           return self.image_processor_class




