(ckpt_path: str)
| 182 | |
| 183 | # Function to convert a VAE checkpoint to the CogVideoX format |
| 184 | def convert_vae(ckpt_path: str): |
| 185 | original_state_dict = get_state_dict(torch.load(ckpt_path, map_location="cpu", mmap=True)) |
| 186 | vae = AutoencoderKLCogVideoX() |
| 187 | |
| 188 | for key in list(original_state_dict.keys()): |
| 189 | new_key = key[:] |
| 190 | for replace_key, rename_key in VAE_KEYS_RENAME_DICT.items(): |
| 191 | new_key = new_key.replace(replace_key, rename_key) |
| 192 | update_state_dict_inplace(original_state_dict, key, new_key) |
| 193 | |
| 194 | for key in list(original_state_dict.keys()): |
| 195 | for special_key, handler_fn_inplace in VAE_SPECIAL_KEYS_REMAP.items(): |
| 196 | if special_key not in key: |
| 197 | continue |
| 198 | handler_fn_inplace(key, original_state_dict) |
| 199 | |
| 200 | vae.load_state_dict(original_state_dict, strict=True) |
| 201 | return vae |
| 202 | |
| 203 | |
| 204 | # Function to parse command-line arguments for the script |
no test coverage detected