code: 
  
  
  
  
  
  '''simple docstring'''
  
  
  
  
  import tempfile
  import unittest
  
  import numpy as np
  import torch
  
  from diffusers import DiffusionPipeline
  from diffusers.models.attention_processor import Attention, AttnAddedKVProcessor
  
  
  
  
  
  
  class 							__snake_case    (				unittest.TestCase       ):
  
  
  
  
  
  	def      _snake_case      (		self			,					UpperCamelCase_ = False		)			->		Optional[int]:
  		snake_case__  					=      10
  
  		if only_cross_attention:
  			snake_case__  					=      12
  		else:
  			# when only cross attention is not set, the cross attention dim must be the same as the query dim
  			snake_case__  					=      query_dim
  
  		return {
  		    "query_dim": query_dim,
  		    "cross_attention_dim": cross_attention_dim,
  		    "heads": 2,
  		    "dim_head": 4,
  		    "added_kv_proj_dim": 6,
  		    "norm_num_groups": 1,
  		    "only_cross_attention": only_cross_attention,
  		    "processor": AttnAddedKVProcessor(),
  		}
  
  
  
  
  
  	def      _snake_case      (		self			,					UpperCamelCase_			,					UpperCamelCase_		)			->		Union[str, Any]:
  		snake_case__  					=      2
  
  		snake_case__  					=      torch.rand(UpperCamelCase_			,					UpperCamelCase_			,					3			,					2		)
  		snake_case__  					=      torch.rand(UpperCamelCase_			,					4			,					UpperCamelCase_		)
  		snake_case__  					=      None
  
  		return {
  		    "hidden_states": hidden_states,
  		    "encoder_hidden_states": encoder_hidden_states,
  		    "attention_mask": attention_mask,
  		}
  
  
  
  
  
  	def      _snake_case      (		self		)			->		List[Any]:
  		# self and cross attention
  
  		torch.manual_seed(0		)
  
  		snake_case__  					=      self.get_constructor_arguments(only_cross_attention=UpperCamelCase_		)
  		snake_case__  					=      Attention(**UpperCamelCase_		)
  
  		self.assertTrue(attn.to_k is not None		)
  		self.assertTrue(attn.to_v is not None		)
  
  		snake_case__  					=      self.get_forward_arguments(
  		    query_dim=constructor_args['query_dim']			,					added_kv_proj_dim=constructor_args['added_kv_proj_dim']		)
  
  		snake_case__  					=      attn(**UpperCamelCase_		)
  
  		# only self attention
  
  		torch.manual_seed(0		)
  
  		snake_case__  					=      self.get_constructor_arguments(only_cross_attention=UpperCamelCase_		)
  		snake_case__  					=      Attention(**UpperCamelCase_		)
  
  		self.assertTrue(attn.to_k is None		)
  		self.assertTrue(attn.to_v is None		)
  
  		snake_case__  					=      self.get_forward_arguments(
  		    query_dim=constructor_args['query_dim']			,					added_kv_proj_dim=constructor_args['added_kv_proj_dim']		)
  
  		snake_case__  					=      attn(**UpperCamelCase_		)
  
  		self.assertTrue((only_cross_attn_out != self_and_cross_attn_out).all()		)
  
  
  
  
  
  
  class 							__snake_case    (				unittest.TestCase       ):
  
  
  
  
  
  	def      _snake_case      (		self		)			->		str:
  		snake_case__  					=      DiffusionPipeline.from_pretrained('hf-internal-testing/tiny-stable-diffusion-pipe'			,					safety_checker=UpperCamelCase_		)
  
  		snake_case__  					=      pipe(
  		    'foo'			,					num_inference_steps=2			,					generator=torch.Generator('cpu'		).manual_seed(0		)			,					output_type='np'			,					).images
  
  		# the initial conversion succeeds
  		snake_case__  					=      DiffusionPipeline.from_pretrained(
  		    'hf-internal-testing/tiny-stable-diffusion-pipe'			,					device_map='sequential'			,					safety_checker=UpperCamelCase_		)
  
  		snake_case__  					=      pipe(
  		    'foo'			,					num_inference_steps=2			,					generator=torch.Generator('cpu'		).manual_seed(0		)			,					output_type='np'			,					).images
  
  		with tempfile.TemporaryDirectory() as tmpdir:
  			# save the converted model
  			pipe.save_pretrained(UpperCamelCase_		)
  
  			# can also load the converted weights
  			snake_case__  					=      DiffusionPipeline.from_pretrained(UpperCamelCase_			,					device_map='sequential'			,					safety_checker=UpperCamelCase_		)
  
  		snake_case__  					=      pipe(
  		    'foo'			,					num_inference_steps=2			,					generator=torch.Generator('cpu'		).manual_seed(0		)			,					output_type='np'			,					).images
  
  		self.assertTrue(np.allclose(UpperCamelCase_			,					UpperCamelCase_			,					atol=1E-5		)		)
  		self.assertTrue(np.allclose(UpperCamelCase_			,					UpperCamelCase_			,					atol=1E-5		)		)
  
  
  
  
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
  
  
  
  