code: 
  
  
  
  
  
  '''simple docstring'''
  
  
  
  
  import gc
  import unittest
  
  import numpy as np
  import torch
  from transformers import CLIPTextConfig, CLIPTextModel, CLIPTextModelWithProjection, CLIPTokenizer
  
  from diffusers import (
      AutoencoderKL,
      DiffusionPipeline,
      EulerDiscreteScheduler,
      StableDiffusionXLPipeline,
      UNetaDConditionModel,
  )
  from diffusers.utils import slow, torch_device
  from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu
  
  from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS
  from ..test_pipelines_common import PipelineLatentTesterMixin, PipelineTesterMixin
  
  
  enable_full_determinism()
  
  
  
  
  
  
  class 							__snake_case    (				__magic_name__					,					__magic_name__					,					unittest.TestCase       ):
  	__lowerCAmelCase						=     StableDiffusionXLPipeline
  	__lowerCAmelCase						=     TEXT_TO_IMAGE_PARAMS
  	__lowerCAmelCase						=     TEXT_TO_IMAGE_BATCH_PARAMS
  	__lowerCAmelCase						=     TEXT_TO_IMAGE_IMAGE_PARAMS
  	__lowerCAmelCase						=     TEXT_TO_IMAGE_IMAGE_PARAMS
  
  
  
  
  
  	def      _snake_case      (		self		)			->		str:
  		torch.manual_seed(0		)
  		snake_case__  					=      UNetaDConditionModel(
  		    block_out_channels=(32, 64)			,					layers_per_block=2			,					sample_size=32			,					in_channels=4			,					out_channels=4			,					down_block_types=('DownBlock2D', 'CrossAttnDownBlock2D')			,					up_block_types=('CrossAttnUpBlock2D', 'UpBlock2D')			,					attention_head_dim=(2, 4)			,					use_linear_projection=UpperCamelCase_			,					addition_embed_type='text_time'			,					addition_time_embed_dim=8			,					transformer_layers_per_block=(1, 2)			,					projection_class_embeddings_input_dim=80			,					cross_attention_dim=64			,					)
  		snake_case__  					=      EulerDiscreteScheduler(
  		    beta_start=0.0_0_0_8_5			,					beta_end=0.0_1_2			,					steps_offset=1			,					beta_schedule='scaled_linear'			,					timestep_spacing='leading'			,					)
  		torch.manual_seed(0		)
  		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		)
  		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=32			,					)
  		snake_case__  					=      CLIPTextModel(UpperCamelCase_		)
  		snake_case__  					=      CLIPTokenizer.from_pretrained('hf-internal-testing/tiny-random-clip'			,					local_files_only=UpperCamelCase_		)
  
  		snake_case__  					=      CLIPTextModelWithProjection(UpperCamelCase_		)
  		snake_case__  					=      CLIPTokenizer.from_pretrained('hf-internal-testing/tiny-random-clip'			,					local_files_only=UpperCamelCase_		)
  
  		snake_case__  					=      {
  		    'unet': unet,
  		    'scheduler': scheduler,
  		    'vae': vae,
  		    'text_encoder': text_encoder,
  		    'tokenizer': tokenizer,
  		    'text_encoder_2': text_encoder_a,
  		    'tokenizer_2': tokenizer_a,
  		    # "safety_checker": None,
  		    # "feature_extractor": None,
  		}
  		return components
  
  
  
  
  
  	def      _snake_case      (		self			,					UpperCamelCase_			,					UpperCamelCase_=0		)			->		List[str]:
  		if str(UpperCamelCase_		).startswith('mps'		):
  			snake_case__  					=      torch.manual_seed(UpperCamelCase_		)
  		else:
  			snake_case__  					=      torch.Generator(device=UpperCamelCase_		).manual_seed(UpperCamelCase_		)
  		snake_case__  					=      {
  		    'prompt': 'A painting of a squirrel eating a burger',
  		    'generator': generator,
  		    'num_inference_steps': 2,
  		    'guidance_scale': 5.0,
  		    'output_type': 'numpy',
  		}
  		return inputs
  
  
  
  
  
  	def      _snake_case      (		self		)			->		Union[str, Any]:
  		snake_case__  					=      'cpu'  # ensure determinism for the device-dependent torch.Generator
  		snake_case__  					=      self.get_dummy_components()
  		snake_case__  					=      StableDiffusionXLPipeline(**UpperCamelCase_		)
  		snake_case__  					=      sd_pipe.to(UpperCamelCase_		)
  		sd_pipe.set_progress_bar_config(disable=UpperCamelCase_		)
  
  		snake_case__  					=      self.get_dummy_inputs(UpperCamelCase_		)
  		snake_case__  					=      sd_pipe(**UpperCamelCase_		).images
  		snake_case__  					=      image[0, -3:, -3:, -1]
  
  		assert image.shape == (1, 64, 64, 3)
  		snake_case__  					=      np.array([0.5_8_7_3, 0.6_1_2_8, 0.4_7_9_7, 0.5_1_2_2, 0.5_6_7_4, 0.4_6_3_9, 0.5_2_2_7, 0.5_1_4_9, 0.4_7_4_7]		)
  
  		assert np.abs(image_slice.flatten() - expected_slice		).max() < 1E-2
  
  
  
  
  
  	def      _snake_case      (		self		)			->		List[str]:
  		snake_case__  					=      self.get_dummy_components()
  		snake_case__  					=      StableDiffusionXLPipeline(**UpperCamelCase_		)
  		snake_case__  					=      sd_pipe.to(UpperCamelCase_		)
  		snake_case__  					=      sd_pipe.to(UpperCamelCase_		)
  		sd_pipe.set_progress_bar_config(disable=UpperCamelCase_		)
  
  		# forward without prompt embeds
  		snake_case__  					=      self.get_dummy_inputs(UpperCamelCase_		)
  		snake_case__  					=      3 * ['this is a negative prompt']
  		snake_case__  					=      negative_prompt
  		snake_case__  					=      3 * [inputs['prompt']]
  
  		snake_case__  					=      sd_pipe(**UpperCamelCase_		)
  		snake_case__  					=      output.images[0, -3:, -3:, -1]
  
  		# forward with prompt embeds
  		snake_case__  					=      self.get_dummy_inputs(UpperCamelCase_		)
  		snake_case__  					=      3 * ['this is a negative prompt']
  		snake_case__  					=      3 * [inputs.pop('prompt'		)]
  
  		(
  		    (
  		    snake_case__
  		)					,     (
  		    snake_case__
  		)					,     (
  		    snake_case__
  		)					,     (
  		    snake_case__
  		)					,     
  		)  					=      sd_pipe.encode_prompt(UpperCamelCase_			,					negative_prompt=UpperCamelCase_		)
  
  		snake_case__  					=      sd_pipe(
  		    **UpperCamelCase_			,					prompt_embeds=UpperCamelCase_			,					negative_prompt_embeds=UpperCamelCase_			,					pooled_prompt_embeds=UpperCamelCase_			,					negative_pooled_prompt_embeds=UpperCamelCase_			,					)
  		snake_case__  					=      output.images[0, -3:, -3:, -1]
  
  		# make sure that it's equal
  		assert np.abs(image_slice_a.flatten() - image_slice_a.flatten()		).max() < 1E-4
  
  
  
  
  
  	def      _snake_case      (		self		)			->		List[Any]:
  		super().test_attention_slicing_forward_pass(expected_max_diff=3E-3		)
  
  
  
  
  
  	def      _snake_case      (		self		)			->		Optional[Any]:
  		super().test_inference_batch_single_identical(expected_max_diff=3E-3		)
  
  
  
  
  
  
  @slow
  @require_torch_gpu
  class 							__snake_case    (				unittest.TestCase       ):
  
  
  
  
  
  	def      _snake_case      (		self		)			->		int:
  		super().tearDown()
  		gc.collect()
  		torch.cuda.empty_cache()
  
  
  
  
  
  	def      _snake_case      (		self			,					UpperCamelCase_			,					UpperCamelCase_="cpu"			,					UpperCamelCase_=torch.floataa			,					UpperCamelCase_=0		)			->		Optional[Any]:
  		snake_case__  					=      torch.Generator(device=UpperCamelCase_		).manual_seed(UpperCamelCase_		)
  		snake_case__  					=      np.random.RandomState(UpperCamelCase_		).standard_normal((1, 4, 64, 64)		)
  		snake_case__  					=      torch.from_numpy(UpperCamelCase_		).to(device=UpperCamelCase_			,					dtype=UpperCamelCase_		)
  		snake_case__  					=      {
  		    'prompt': 'a photograph of an astronaut riding a horse',
  		    'latents': latents,
  		    'generator': generator,
  		    'num_inference_steps': 3,
  		    'guidance_scale': 7.5,
  		    'output_type': 'numpy',
  		}
  		return inputs
  
  
  
  
  
  	def      _snake_case      (		self		)			->		List[str]:
  		snake_case__  					=      DiffusionPipeline.from_pretrained('stabilityai/stable-diffusion-2-base'		)
  		pipe.to(UpperCamelCase_		)
  		pipe.set_progress_bar_config(disable=UpperCamelCase_		)
  
  		snake_case__  					=      self.get_inputs(UpperCamelCase_		)
  		snake_case__  					=      pipe(**UpperCamelCase_		).images
  		snake_case__  					=      image[0, -3:, -3:, -1].flatten()
  
  		assert image.shape == (1, 512, 512, 3)
  		snake_case__  					=      np.array([0.4_9_4_9_3, 0.4_7_8_9_6, 0.4_0_7_9_8, 0.5_4_2_1_4, 0.5_3_2_1_2, 0.4_8_2_0_2, 0.4_7_6_5_6, 0.4_6_3_2_9, 0.4_8_5_0_6]		)
  		assert np.abs(image_slice - expected_slice		).max() < 7E-3
  
  
  
  
style_context: 
  
  
  
  
  
  '''simple docstring'''
  
  
  
  
  from collections import OrderedDict
  from typing import Mapping
  
  from packaging import version
  
  from ...configuration_utils import PretrainedConfig
  from ...onnx import OnnxConfig
  from ...utils import logging
  
  
  a__				: Dict									=    logging.get_logger(__name__)
  
  a__				: Tuple									=    {
      '''apple/mobilevitv2-1.0''': '''https://huggingface.co/apple/mobilevitv2-1.0/resolve/main/config.json''',
  }
  
  
  
  
  
  
  class 							__snake_case    (				__magic_name__       ):
  	__lowerCAmelCase						=     '''mobilevitv2'''
  
  
  
  
  
  	def __init__(		self			,					UpperCamelCase_=3			,					UpperCamelCase_=256			,					UpperCamelCase_=2			,					UpperCamelCase_=2.0			,					UpperCamelCase_="swish"			,					UpperCamelCase_=3			,					UpperCamelCase_=32			,					UpperCamelCase_=0.1			,					UpperCamelCase_=0.0_2			,					UpperCamelCase_=1E-5			,					UpperCamelCase_=512			,					UpperCamelCase_=[6, 12, 18]			,					UpperCamelCase_=0.1			,					UpperCamelCase_=255			,					UpperCamelCase_=[2, 4, 3]			,					UpperCamelCase_=[128, 192, 256]			,					UpperCamelCase_=1.0			,					UpperCamelCase_=2			,					UpperCamelCase_=0.0			,					UpperCamelCase_=0.0			,					**UpperCamelCase_			,					)			->		Union[str, Any]:
  		super().__init__(**UpperCamelCase_		)
  
  		snake_case__  					=      num_channels
  		snake_case__  					=      image_size
  		snake_case__  					=      patch_size
  		snake_case__  					=      expand_ratio
  		snake_case__  					=      hidden_act
  		snake_case__  					=      conv_kernel_size
  		snake_case__  					=      output_stride
  		snake_case__  					=      initializer_range
  		snake_case__  					=      layer_norm_eps
  		snake_case__  					=      n_attn_blocks
  		snake_case__  					=      base_attn_unit_dims
  		snake_case__  					=      width_multiplier
  		snake_case__  					=      ffn_multiplier
  		snake_case__  					=      ffn_dropout
  		snake_case__  					=      attn_dropout
  		snake_case__  					=      classifier_dropout_prob
  
  		# decode head attributes for semantic segmentation
  		snake_case__  					=      aspp_out_channels
  		snake_case__  					=      atrous_rates
  		snake_case__  					=      aspp_dropout_prob
  		snake_case__  					=      semantic_loss_ignore_index
  
  
  
  
  
  
  class 							__snake_case    (				__magic_name__       ):
  	__lowerCAmelCase						=     version.parse('''1.11'''       )
  
  
  
  
  
  	@property
  	def      _snake_case      (		self		)			->		Mapping[str, Mapping[int, str]]:
  		return OrderedDict([('pixel_values', {0: 'batch', 1: 'num_channels', 2: 'height', 3: 'width'})]		)
  
  
  
  
  
  	@property
  	def      _snake_case      (		self		)			->		Mapping[str, Mapping[int, str]]:
  		if self.task == "image-classification":
  			return OrderedDict([('logits', {0: 'batch'})]		)
  		else:
  			return OrderedDict([('last_hidden_state', {0: 'batch'}), ('pooler_output', {0: 'batch'})]		)
  
  
  
  
  
  	@property
  	def      _snake_case      (		self		)			->		float:
  		return 1E-4
  
  
  
  