



import argparse

import OmegaConf
import torch

from diffusers import DDIMScheduler, LDMPipeline, UNetLDMModel, VQModel



def 		lowerCAmelCase__     (       UpperCamelCase_					:							str			,							UpperCamelCase_					:							List[str]			,							UpperCamelCase_					:							Optional[int]						)->	List[str]:
    A__					=       OmegaConf.load(UpperCamelCase_						)
    A__					=       torch.load(UpperCamelCase_			,							map_location='''cpu'''						)['''model''']
    A__					=       list(state_dict.keys()						)

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

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

    A__					=       config.model.params.first_stage_config.params
    A__					=       config.model.params.unet_config.params

    A__					=       VQModel(**UpperCamelCase_						).eval()
    vqvae.load_state_dict(UpperCamelCase_						)

    A__					=       UNetLDMModel(**UpperCamelCase_						).eval()
    unet.load_state_dict(UpperCamelCase_						)

    A__					=       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_			,							)

    A__					=       LDMPipeline(UpperCamelCase_			,							UpperCamelCase_			,							UpperCamelCase_						)
    pipeline.save_pretrained(UpperCamelCase_						)


if __name__ == "__main__":
   _lowercase    	=		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)
   _lowercase    	=		parser.parse_args()

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





def 		lowerCAmelCase__     (       UpperCamelCase_					:							int						)->	int:
    A__					=       1
    for i in range(1			,							num + 1						):
        fact *= i
    return fact



def 		lowerCAmelCase__     (       UpperCamelCase_					:							int						)->	int:
    A__					=       0
    while number > 0:
        A__					=       number % 1_0
        sum_of_digits += last_digit
        A__					=       number // 1_0  # Removing the last_digit from the given number
    return sum_of_digits



def 		lowerCAmelCase__     (       UpperCamelCase_					:							int = 1_0_0						)->	int:
    A__					=       factorial(UpperCamelCase_						)
    A__					=       split_and_add(UpperCamelCase_						)
    return result


if __name__ == "__main__":
   print(solution(int(input("Enter the Number: ").strip())))
