code: 
  
  
  
  import tempfile
  import unittest
  
  import torch
  
  from diffusers import UNetaDConditionModel
  from diffusers.training_utils import EMAModel
  from diffusers.utils.testing_utils import enable_full_determinism, skip_mps, torch_device
  
  
  enable_full_determinism()
  
  class      UpperCAmelCase_						(     unittest.TestCase ):
  
  						'''simple docstring'''
  
  
  
  
  						UpperCamelCase__    :				Optional[int]							=						'''hf-internal-testing/tiny-stable-diffusion-pipe'''
  						UpperCamelCase__    :				int							=						1
  						UpperCamelCase__    :				str							=						77
  						UpperCamelCase__    :				Any							=						32
  						UpperCamelCase__    :				Union[str, Any]							=						4
  						UpperCamelCase__    :				int							=						64
  						UpperCamelCase__    :				Optional[Any]							=						torch.manual_seed(0 )
  
  
  
  
  
  
  						def  _A			(					self   ,							_A=0.9_9_9_9	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      UNetaDConditionModel.from_pretrained(self.model_id   ,							subfolder='unet'	)
  													__SCREAMING_SNAKE_CASE								=      unet.to(__snake_case	)
  													__SCREAMING_SNAKE_CASE								=      EMAModel(unet.parameters()   ,							decay=__snake_case   ,							model_cls=__snake_case   ,							model_config=unet.config	)
  													return unet, ema_unet
  
  
  
  
  
  
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      torch.randn(
  													    self.batch_size   ,							self.num_in_channels   ,							self.latent_height   ,							self.latent_width   ,							generator=self.generator	).to(__snake_case	)
  													__SCREAMING_SNAKE_CASE								=      torch.randint(0   ,							1_000   ,							size=(self.batch_size,)   ,							generator=self.generator	).to(__snake_case	)
  													__SCREAMING_SNAKE_CASE								=      torch.randn(
  													    self.batch_size   ,							self.prompt_length   ,							self.text_encoder_hidden_dim   ,							generator=self.generator	).to(__snake_case	)
  													return noisy_latents, timesteps, encoder_hidden_states
  
  
  
  
  
  
  						def  _A			(					self   ,							_A	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      {}
  													for k, param in unet.state_dict().items():
  																				__SCREAMING_SNAKE_CASE								=      torch.randn_like(__snake_case	) + (param * torch.randn_like(__snake_case	))
  																				updated_state_dict.update({k: updated_param}	)
  													unet.load_state_dict(__snake_case	)
  													return unet
  
  
  
  
  
  
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE							, __SCREAMING_SNAKE_CASE								=      self.get_models()
  													# Take the first (hypothetical) EMA step.
  													ema_unet.step(unet.parameters()	)
  													assert ema_unet.optimization_step == 1
  
  													# Take two more.
  													for _ in range(2	):
  																				ema_unet.step(unet.parameters()	)
  													assert ema_unet.optimization_step == 3
  
  
  
  
  
  
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE							, __SCREAMING_SNAKE_CASE								=      self.get_models()
  													# Since the `unet` is not being updated (i.e., backprop'd)
  													# there won't be any difference between the `params` of `unet`
  													# and `ema_unet` even if we call `ema_unet.step(unet.parameters())`.
  													ema_unet.step(unet.parameters()	)
  													__SCREAMING_SNAKE_CASE								=      list(unet.parameters()	)
  													for s_param, param in zip(ema_unet.shadow_params   ,							__snake_case	):
  																				assert torch.allclose(__snake_case   ,							__snake_case	)
  
  													# The above holds true even if we call `ema.step()` multiple times since
  													# `unet` params are still not being updated.
  													for _ in range(4	):
  																				ema_unet.step(unet.parameters()	)
  													for s_param, param in zip(ema_unet.shadow_params   ,							__snake_case	):
  																				assert torch.allclose(__snake_case   ,							__snake_case	)
  
  
  
  
  
  
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE							, __SCREAMING_SNAKE_CASE								=      self.get_models()
  													# Here we simulate the parameter updates for `unet`. Since there might
  													# be some parameters which are initialized to zero we take extra care to
  													# initialize their values to something non-zero before the multiplication.
  													__SCREAMING_SNAKE_CASE								=      self.simulate_backprop(__snake_case	)
  
  													# Take the EMA step.
  													ema_unet.step(unet_pseudo_updated_step_one.parameters()	)
  
  													# Now the EMA'd parameters won't be equal to the original model parameters.
  													__SCREAMING_SNAKE_CASE								=      list(unet_pseudo_updated_step_one.parameters()	)
  													for s_param, param in zip(ema_unet.shadow_params   ,							__snake_case	):
  																				assert ~torch.allclose(__snake_case   ,							__snake_case	)
  
  													# Ensure this is the case when we take multiple EMA steps.
  													for _ in range(4	):
  																				ema_unet.step(unet.parameters()	)
  													for s_param, param in zip(ema_unet.shadow_params   ,							__snake_case	):
  																				assert ~torch.allclose(__snake_case   ,							__snake_case	)
  
  
  
  
  
  
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE							, __SCREAMING_SNAKE_CASE								=      self.get_models()
  
  													# First backprop + EMA
  													__SCREAMING_SNAKE_CASE								=      self.simulate_backprop(__snake_case	)
  													ema_unet.step(unet_step_one.parameters()	)
  													__SCREAMING_SNAKE_CASE								=      ema_unet.shadow_params
  
  													# Second backprop + EMA
  													__SCREAMING_SNAKE_CASE								=      self.simulate_backprop(__snake_case	)
  													ema_unet.step(unet_step_two.parameters()	)
  													__SCREAMING_SNAKE_CASE								=      ema_unet.shadow_params
  
  													for step_one, step_two in zip(__snake_case   ,							__snake_case	):
  																				assert ~torch.allclose(__snake_case   ,							__snake_case	)
  
  
  
  
  
  
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE							, __SCREAMING_SNAKE_CASE								=      self.get_models(decay=0.0	)
  													__SCREAMING_SNAKE_CASE								=      self.simulate_backprop(__snake_case	)
  													ema_unet.step(unet_step_one.parameters()	)
  													__SCREAMING_SNAKE_CASE								=      ema_unet.shadow_params
  
  													__SCREAMING_SNAKE_CASE								=      self.simulate_backprop(__snake_case	)
  													ema_unet.step(unet_step_two.parameters()	)
  													__SCREAMING_SNAKE_CASE								=      ema_unet.shadow_params
  
  													for step_one, step_two in zip(__snake_case   ,							__snake_case	):
  																				assert torch.allclose(__snake_case   ,							__snake_case	)
  
  
  
  
  
  
  						@skip_mps
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE							, __SCREAMING_SNAKE_CASE								=      self.get_models()
  													__SCREAMING_SNAKE_CASE							, __SCREAMING_SNAKE_CASE							, __SCREAMING_SNAKE_CASE								=      self.get_dummy_inputs()
  
  													with tempfile.TemporaryDirectory() as tmpdir:
  																				ema_unet.save_pretrained(__snake_case	)
  																				__SCREAMING_SNAKE_CASE								=      UNetaDConditionModel.from_pretrained(__snake_case   ,							model_cls=__snake_case	)
  																				__SCREAMING_SNAKE_CASE								=      loaded_unet.to(unet.device	)
  
  													# Since no EMA step has been performed the outputs should match.
  													__SCREAMING_SNAKE_CASE								=      unet(__snake_case   ,							__snake_case   ,							__snake_case	).sample
  													__SCREAMING_SNAKE_CASE								=      loaded_unet(__snake_case   ,							__snake_case   ,							__snake_case	).sample
  
  													assert torch.allclose(__snake_case   ,							__snake_case   ,							atol=1e-4	)
  
  
  
  
  
  
  
style_context: 
  
  
  
  from itertools import combinations, product
  
  
  
  
  
  
  def 			__lowercase     (				a__							,     a__							,     a__							,     a__     )       ->				bool:
  							if xa == ya == 0 or xa == ya == 0:
  														return False
  							__SCREAMING_SNAKE_CASE								=      xa * xa + ya * ya
  							__SCREAMING_SNAKE_CASE								=      xa * xa + ya * ya
  							__SCREAMING_SNAKE_CASE								=      (xa - xa) * (xa - xa) + (ya - ya) * (ya - ya)
  							return (
  							    a_square + b_square == c_square
  							    or a_square + c_square == b_square
  							    or b_square + c_square == a_square
  							)
  
  
  
  
  
  
  def 			__lowercase     (				a__ = 50     )       ->				int:
  							return sum(
  							    1
  							    for pta, pta in combinations(product(range(limit + 1     )							,     repeat=2     )							,     2     )
  							    if is_right(*a__							,     *a__     )     )
  
  
  if __name__ == "__main__":
  			print(F'''{solution() = }''')
  
  
  
  
  
  
  