

def   lowerCamelCase__       (       UpperCamelCase__     :    int  )     ->	Optional[int]:



					'''simple docstring'''




					_snake_case													=			abs(UpperCamelCase__  )
					_snake_case													=			0
					while n > 0:
										res += n % 10
										n //= 10
					return res





def   lowerCamelCase__       (       UpperCamelCase__     :    int  )     ->	str:



					'''simple docstring'''




					_snake_case													=			abs(UpperCamelCase__  )
					return n if n < 10 else n % 10 + sum_of_digits(n // 10  )





def   lowerCamelCase__       (       UpperCamelCase__     :    int  )     ->	Any:



					'''simple docstring'''




					return sum(int(UpperCamelCase__  ) for c in str(abs(UpperCamelCase__  )  )  )





def   lowerCamelCase__       (       )     ->	Any:



					'''simple docstring'''




					from collections.abc import Callable
					from timeit import timeit

					def benchmark_a_function(UpperCamelCase__     :    Callable    ,      UpperCamelCase__     :    int  ) -> None:
										_snake_case													=			F'''{func.__name__}({value})'''
										_snake_case													=			timeit(F'''__main__.{call}'''    ,      setup='import __main__'  )
										print(F'''{call:56} = {func(UpperCamelCase__  )} -- {timing:.4f} seconds'''  )

					for value in (262_144, 1_125_899_906_842_624, 1_267_650_600_228_229_401_496_703_205_376):
										for func in (sum_of_digits, sum_of_digits_recursion, sum_of_digits_compact):
															benchmark_a_function(UpperCamelCase__    ,      UpperCamelCase__  )
										print()


if __name__ == "__main__":
					import doctest

					doctest.testmod()
					benchmark()










import argparse

import OmegaConf
import torch

from diffusers import DDIMScheduler, LDMPipeline, UNetLDMModel, VQModel





def   lowerCamelCase__       (       UpperCamelCase__     :    Dict    ,      UpperCamelCase__     :    List[str]    ,      UpperCamelCase__     :    Dict  )     ->	List[Any]:



					'''simple docstring'''




					_snake_case													=			OmegaConf.load(UpperCamelCase__  )
					_snake_case													=			torch.load(UpperCamelCase__    ,      map_location='cpu'  )['model']
					_snake_case													=			list(state_dict.keys()  )

					# extract state_dict for VQVAE
					_snake_case													=			{}
					_snake_case													=			'first_stage_model.'
					for key in keys:
										if key.startswith(UpperCamelCase__  ):
															_snake_case													=			state_dict[key]

    # extract state_dict for UNetLDM
					_snake_case													=			{}
					_snake_case													=			'model.diffusion_model.'
					for key in keys:
										if key.startswith(UpperCamelCase__  ):
															_snake_case													=			state_dict[key]

					_snake_case													=			config.model.params.first_stage_config.params
					_snake_case													=			config.model.params.unet_config.params

					_snake_case													=			VQModel(**UpperCamelCase__  ).eval()
					vqvae.load_state_dict(UpperCamelCase__  )

					_snake_case													=			UNetLDMModel(**UpperCamelCase__  ).eval()
					unet.load_state_dict(UpperCamelCase__  )

					_snake_case													=			DDIMScheduler(
					    timesteps=config.model.params.timesteps    ,      beta_schedule='scaled_linear'    ,      beta_start=config.model.params.linear_start    ,      beta_end=config.model.params.linear_end    ,      clip_sample=UpperCamelCase__    ,      )

					_snake_case													=			LDMPipeline(UpperCamelCase__    ,      UpperCamelCase__    ,      UpperCamelCase__  )
					pipeline.save_pretrained(UpperCamelCase__  )


if __name__ == "__main__":
					UpperCAmelCase_ 							=       argparse.ArgumentParser()
					parser.add_argument("""--checkpoint_path""", type=str, required=True)
					parser.add_argument("""--config_path""", type=str, required=True)
					parser.add_argument("""--output_path""", type=str, required=True)
					UpperCAmelCase_ 							=       parser.parse_args()

					convert_ldm_original(args.checkpoint_path, args.config_path, args.output_path)



