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 							__UpperCAmelCase  (       A__		,					A__		,					unittest.TestCase						):
  
  
  
  
  
  
  
  		'''simple docstring'''
  
  
  
  
  
  
  
  		__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        A     (self						:      Dict      ):
  			torch.manual_seed(0      )
  			A							  =      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=_lowerCAmelCase      ,      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      ,      )
  			A							  =      EulerDiscreteScheduler(
  			    beta_start=0.00_085      ,      beta_end=0.012      ,      steps_offset=1      ,      beta_schedule="""scaled_linear"""      ,      timestep_spacing="""leading"""      ,      )
  			torch.manual_seed(0      )
  			A							  =      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      )
  			A							  =      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=32      ,      )
  			A							  =      CLIPTextModel(_lowerCAmelCase      )
  			A							  =      CLIPTokenizer.from_pretrained("""hf-internal-testing/tiny-random-clip"""      ,      local_files_only=_lowerCAmelCase      )
  
  			A							  =      CLIPTextModelWithProjection(_lowerCAmelCase      )
  			A							  =      CLIPTokenizer.from_pretrained("""hf-internal-testing/tiny-random-clip"""      ,      local_files_only=_lowerCAmelCase      )
  
  			A							  =      {
  			    """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        A     (self						:      Optional[Any]      ,      _lowerCAmelCase						:      int      ,      _lowerCAmelCase						:      List[Any]=0      ):
  			if str(_lowerCAmelCase      ).startswith("""mps"""      ):
  				A							  =      torch.manual_seed(_lowerCAmelCase      )
  			else:
  				A							  =      torch.Generator(device=_lowerCAmelCase      ).manual_seed(_lowerCAmelCase      )
  			A							  =      {
  			    """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        A     (self						:      Optional[Any]      ):
  			A							  =      """cpu"""  # ensure determinism for the device-dependent torch.Generator
  			A							  =      self.get_dummy_components()
  			A							  =      StableDiffusionXLPipeline(**_lowerCAmelCase      )
  			A							  =      sd_pipe.to(_lowerCAmelCase      )
  			sd_pipe.set_progress_bar_config(disable=_lowerCAmelCase      )
  
  			A							  =      self.get_dummy_inputs(_lowerCAmelCase      )
  			A							  =      sd_pipe(**_lowerCAmelCase      ).images
  			A							  =      image[0, -3:, -3:, -1]
  
  			assert image.shape == (1, 64, 64, 3)
  			A							  =      np.array([0.5_873, 0.6_128, 0.4_797, 0.5_122, 0.5_674, 0.4_639, 0.5_227, 0.5_149, 0.4_747]      )
  
  			assert np.abs(image_slice.flatten() - expected_slice      ).max() < 1e-2
  
  
  
  
  
  
  
  		def        A     (self						:      List[Any]      ):
  			A							  =      self.get_dummy_components()
  			A							  =      StableDiffusionXLPipeline(**_lowerCAmelCase      )
  			A							  =      sd_pipe.to(_lowerCAmelCase      )
  			A							  =      sd_pipe.to(_lowerCAmelCase      )
  			sd_pipe.set_progress_bar_config(disable=_lowerCAmelCase      )
  
  			# forward without prompt embeds
  			A							  =      self.get_dummy_inputs(_lowerCAmelCase      )
  			A							  =      3 * ["""this is a negative prompt"""]
  			A							  =      negative_prompt
  			A							  =      3 * [inputs["""prompt"""]]
  
  			A							  =      sd_pipe(**_lowerCAmelCase      )
  			A							  =      output.images[0, -3:, -3:, -1]
  
  			# forward with prompt embeds
  			A							  =      self.get_dummy_inputs(_lowerCAmelCase      )
  			A							  =      3 * ["""this is a negative prompt"""]
  			A							  =      3 * [inputs.pop("""prompt"""      )]
  
  			(
  			    (
  			    A
  			)  ,    (
  			    A
  			)  ,    (
  			    A
  			)  ,    (
  			    A
  			)  ,    
  			)							  =      sd_pipe.encode_prompt(_lowerCAmelCase      ,      negative_prompt=_lowerCAmelCase      )
  
  			A							  =      sd_pipe(
  			    **_lowerCAmelCase      ,      prompt_embeds=_lowerCAmelCase      ,      negative_prompt_embeds=_lowerCAmelCase      ,      pooled_prompt_embeds=_lowerCAmelCase      ,      negative_pooled_prompt_embeds=_lowerCAmelCase      ,      )
  			A							  =      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        A     (self						:      List[Any]      ):
  			super().test_attention_slicing_forward_pass(expected_max_diff=3e-3      )
  
  
  
  
  
  
  
  		def        A     (self						:      Tuple      ):
  			super().test_inference_batch_single_identical(expected_max_diff=3e-3      )
  
  
  
  
  
  
  @slow
  @require_torch_gpu
  class 							__UpperCAmelCase  (       unittest.TestCase						):
  
  
  
  
  
  
  
  		'''simple docstring'''
  
  
  
  
  
  
  
  		def        A     (self						:      str      ):
  			super().tearDown()
  			gc.collect()
  			torch.cuda.empty_cache()
  
  
  
  
  
  
  
  		def        A     (self						:      Optional[int]      ,      _lowerCAmelCase						:      Dict      ,      _lowerCAmelCase						:      List[str]="cpu"      ,      _lowerCAmelCase						:      Union[str, Any]=torch.floataa      ,      _lowerCAmelCase						:      Optional[int]=0      ):
  			A							  =      torch.Generator(device=_lowerCAmelCase      ).manual_seed(_lowerCAmelCase      )
  			A							  =      np.random.RandomState(_lowerCAmelCase      ).standard_normal((1, 4, 64, 64)      )
  			A							  =      torch.from_numpy(_lowerCAmelCase      ).to(device=_lowerCAmelCase      ,      dtype=_lowerCAmelCase      )
  			A							  =      {
  			    """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        A     (self						:      Dict      ):
  			A							  =      DiffusionPipeline.from_pretrained("""stabilityai/stable-diffusion-2-base"""      )
  			pipe.to(_lowerCAmelCase      )
  			pipe.set_progress_bar_config(disable=_lowerCAmelCase      )
  
  			A							  =      self.get_inputs(_lowerCAmelCase      )
  			A							  =      pipe(**_lowerCAmelCase      ).images
  			A							  =      image[0, -3:, -3:, -1].flatten()
  
  			assert image.shape == (1, 512, 512, 3)
  			A							  =      np.array([0.49_493, 0.47_896, 0.40_798, 0.54_214, 0.53_212, 0.48_202, 0.47_656, 0.46_329, 0.48_506]      )
  			assert np.abs(image_slice - expected_slice      ).max() < 7e-3
  
  
style_context: 
  
  
  
  
  
  '''simple docstring'''
  
  
  import hashlib
  import importlib.util
  import json
  import os
  import pathlib
  from types import ModuleType
  
  import pytest
  import requests
  
  _lowerCamelCase				:	Optional[Any]				    =       pathlib.Path.cwd().joinpath('project_euler')
  _lowerCamelCase				:	Optional[int]				    =       pathlib.Path.cwd().joinpath(
      'scripts', 'project_euler_answers.json'
  )
  
  with open(PROJECT_EULER_ANSWERS_PATH) as file_handle:
  				_lowerCamelCase				:	dict[str, str]				    =       json.load(file_handle)
  
  
  
  
  def    __a (     UpperCAmelCase    )      ->ModuleType:
  
  
  
  	"""simple docstring"""
  
  
  
  
  
  
  
  	A							  =      importlib.util.spec_from_file_location(file_path.name       ,			str(UpperCAmelCase    )    )
  	A							  =      importlib.util.module_from_spec(UpperCAmelCase    )  # type: ignore
  	spec.loader.exec_module(UpperCAmelCase    )  # type: ignore
  	return module
  
  
  
  
  def    __a (     )      ->list[pathlib.Path]:
  
  
  
  	"""simple docstring"""
  
  
  
  
  
  
  
  	A							  =      []
  	for problem_dir_path in PROJECT_EULER_DIR_PATH.iterdir():
  		if problem_dir_path.is_file() or problem_dir_path.name.startswith("""_"""    ):
  			continue
  		for file_path in problem_dir_path.iterdir():
  			if file_path.suffix != ".py" or file_path.name.startswith(("""_""", """test""")    ):
  				continue
  			solution_file_paths.append(UpperCAmelCase    )
  	return solution_file_paths
  
  
  
  
  def    __a (     )      ->str:
  
  
  
  	"""simple docstring"""
  
  
  
  
  
  
  
  	with open(os.environ["""GITHUB_EVENT_PATH"""]    ) as file:
  		A							  =      json.load(UpperCAmelCase    )
  	return event["pull_request"]["url"] + "/files"
  
  
  
  
  def    __a (     )      ->list[pathlib.Path]:
  
  
  
  	"""simple docstring"""
  
  
  
  
  
  
  
  	A							  =      []
  	A							  =      {
  	    """Accept""": """application/vnd.github.v3+json""",
  	    """Authorization""": """token """ + os.environ["""GITHUB_TOKEN"""],
  	}
  	A							  =      requests.get(get_files_url()       ,			headers=UpperCAmelCase    ).json()
  	for file in files:
  		A							  =      pathlib.Path.cwd().joinpath(file["""filename"""]    )
  		if (
  		    filepath.suffix != ".py"
  		    or filepath.name.startswith(("""_""", """test""")    )
  		    or not filepath.name.startswith("""sol"""    )
  		):
  			continue
  		solution_file_paths.append(UpperCAmelCase    )
  	return solution_file_paths
  
  
  
  
  def    __a (     )      ->list[pathlib.Path]:
  
  
  
  	"""simple docstring"""
  
  
  
  
  
  
  
  	if os.environ.get("""CI"""    ) and os.environ.get("""GITHUB_EVENT_NAME"""    ) == "pull_request":
  		# Return only if there are any, otherwise default to all solutions
  		if filepaths := added_solution_file_path():
  			return filepaths
  	return all_solution_file_paths()
  
  
  
  
  @pytest.mark.parametrize(
      """solution_path"""       ,			collect_solution_file_paths()       ,			ids=lambda UpperCAmelCase    : f"""{path.parent.name}/{path.name}"""       ,			)
  def    __a (     UpperCAmelCase    )      ->None:
  
  
  
  	"""simple docstring"""
  
  
  
  
  
  
  
  	A							  =      solution_path.parent.name[8:].zfill(3    )
  	A							  =      PROBLEM_ANSWERS[problem_number]
  	A							  =      convert_path_to_module(UpperCAmelCase    )
  	A							  =      str(solution_module.solution()    )  # type: ignore
  	A							  =      hashlib.shaaaa(answer.encode()    ).hexdigest()
  	assert (
  	    answer == expected
  	), f"""Expected solution to {problem_number} to have hash {expected}, got {answer}"""
  
  