'''simple docstring'''




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      lowerCamelCase_     (unittest.TestCase   ):
						'''simple docstring'''

						__UpperCamelCase:  Optional[Any]      =						"hf-internal-testing/tiny-stable-diffusion-pipe"
						__UpperCamelCase:  Dict      =						1
						__UpperCamelCase:  Optional[Any]      =						7_7
						__UpperCamelCase:  int      =						3_2
						__UpperCamelCase:  List[str]      =						4
						__UpperCamelCase:  Any      =						6_4
						__UpperCamelCase:  List[str]      =						torch.manual_seed(0   )




						def 					_A     (	self						:    str						, A						:    Tuple=0.9_999	):
													_UpperCAmelCase					:  List[Any]											=   UNetaDConditionModel.from_pretrained(self.model_id						, subfolder="unet"	)
													_UpperCAmelCase					:  Optional[Any]											=   unet.to(A	)
													_UpperCAmelCase					:  Tuple											=   EMAModel(unet.parameters()						, decay=A						, model_cls=A						, model_config=unet.config	)
													return unet, ema_unet




						def 					_A     (	self						:    str	):
													_UpperCAmelCase					:  int											=   torch.randn(
													    self.batch_size						, self.num_in_channels						, self.latent_height						, self.latent_width						, generator=self.generator	).to(A	)
													_UpperCAmelCase					:  Optional[int]											=   torch.randint(0						, 1000						, size=(self.batch_size,)						, generator=self.generator	).to(A	)
													_UpperCAmelCase					:  List[str]											=   torch.randn(
													    self.batch_size						, self.prompt_length						, self.text_encoder_hidden_dim						, generator=self.generator	).to(A	)
													return noisy_latents, timesteps, encoder_hidden_states




						def 					_A     (	self						:    List[Any]						, A						:    Any	):
													_UpperCAmelCase					:  str											=   {}
													for k, param in unet.state_dict().items():
																				_UpperCAmelCase					:  List[str]											=   torch.randn_like(A	) + (param * torch.randn_like(A	))
																				updated_state_dict.update({k: updated_param}	)
													unet.load_state_dict(A	)
													return unet




						def 					_A     (	self						:    Any	):
													_UpperCAmelCase					:  str											=   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						:    Union[str, Any]	):
													_UpperCAmelCase					:  Union[str, Any]											=   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()	)
													_UpperCAmelCase					:  List[str]											=   list(unet.parameters()	)
													for s_param, param in zip(ema_unet.shadow_params						, A	):
																				assert torch.allclose(A						, A	)

													# 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						, A	):
																				assert torch.allclose(A						, A	)




						def 					_A     (	self						:    List[Any]	):
													_UpperCAmelCase					:  str											=   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.
													_UpperCAmelCase					:  Tuple											=   self.simulate_backprop(A	)

													# 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.
													_UpperCAmelCase					:  Dict											=   list(unet_pseudo_updated_step_one.parameters()	)
													for s_param, param in zip(ema_unet.shadow_params						, A	):
																				assert ~torch.allclose(A						, A	)

													# 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						, A	):
																				assert ~torch.allclose(A						, A	)




						def 					_A     (	self						:    List[Any]	):
													# If we call EMA step after a backpropagation consecutively for two times,
													# the shadow params from those two steps should be different.
													_UpperCAmelCase					:  Dict											=   self.get_models()

													# First backprop + EMA
													_UpperCAmelCase					:  List[Any]											=   self.simulate_backprop(A	)
													ema_unet.step(unet_step_one.parameters()	)
													_UpperCAmelCase					:  List[str]											=   ema_unet.shadow_params

													# Second backprop + EMA
													_UpperCAmelCase					:  Union[str, Any]											=   self.simulate_backprop(A	)
													ema_unet.step(unet_step_two.parameters()	)
													_UpperCAmelCase					:  Tuple											=   ema_unet.shadow_params

													for step_one, step_two in zip(A						, A	):
																				assert ~torch.allclose(A						, A	)




						def 					_A     (	self						:    Optional[Any]	):
													# If there's no decay even if there are backprops, EMA steps
													# won't take any effect i.e., the shadow params would remain the
													# same.
													_UpperCAmelCase					:  Union[str, Any]											=   self.get_models(decay=0.0	)
													_UpperCAmelCase					:  str											=   self.simulate_backprop(A	)
													ema_unet.step(unet_step_one.parameters()	)
													_UpperCAmelCase					:  str											=   ema_unet.shadow_params

													_UpperCAmelCase					:  Any											=   self.simulate_backprop(A	)
													ema_unet.step(unet_step_two.parameters()	)
													_UpperCAmelCase					:  Optional[int]											=   ema_unet.shadow_params

													for step_one, step_two in zip(A						, A	):
																				assert torch.allclose(A						, A	)





						@skip_mps
						def 					_A     (	self						:    Optional[Any]	):
													_UpperCAmelCase					:  Tuple											=   self.get_models()
													_UpperCAmelCase					:  Optional[Any]											=   self.get_dummy_inputs()

													with tempfile.TemporaryDirectory() as tmpdir:
																				ema_unet.save_pretrained(A	)
																				_UpperCAmelCase					:  Optional[int]											=   UNetaDConditionModel.from_pretrained(A						, model_cls=A	)
																				_UpperCAmelCase					:  Any											=   loaded_unet.to(unet.device	)

													# Since no EMA step has been performed the outputs should match.
													_UpperCAmelCase					:  Any											=   unet(A						, A						, A	).sample
													_UpperCAmelCase					:  Any											=   loaded_unet(A						, A						, A	).sample

													assert torch.allclose(A						, A						, atol=1E-4	)


'''simple docstring'''




def      UpperCamelCase_							( _UpperCAmelCase  :				Optional[int]      ,     _UpperCAmelCase  :				List[Any]   )   ->   List[str]:


       """simple docstring"""







       if len(str(_UpperCAmelCase   )   ) == 1 or len(str(_UpperCAmelCase   )   ) == 1:
              return a * b

       _UpperCAmelCase					:  Any											=   max(len(str(_UpperCAmelCase   )   )      ,     len(str(_UpperCAmelCase   )   )   )
       _UpperCAmelCase					:  Any											=   ma // 2

       _UpperCAmelCase				,  _UpperCAmelCase					:  Union[str, Any]											=   divmod(_UpperCAmelCase      ,     10**ma   )
       _UpperCAmelCase				,  _UpperCAmelCase					:  int											=   divmod(_UpperCAmelCase      ,     10**ma   )

       _UpperCAmelCase					:  List[str]											=   karatsuba(_UpperCAmelCase      ,     _UpperCAmelCase   )
       _UpperCAmelCase					:  int											=   karatsuba((aa + aa)      ,     (ba + ba)   )
       _UpperCAmelCase					:  Any											=   karatsuba(_UpperCAmelCase      ,     _UpperCAmelCase   )

       return (z * 10 ** (2 * ma)) + ((y - z - x) * 10 ** (ma)) + (x)

def      UpperCamelCase_							( )   ->   List[str]:


       """simple docstring"""







       print(karatsuba(15_463      ,     23_489   )   )


if __name__ == "__main__":
  main()

