(ckpt_path: str, scaling_factor: float, dtype: torch.dtype)
| 168 | |
| 169 | |
| 170 | def convert_vae(ckpt_path: str, scaling_factor: float, dtype: torch.dtype): |
| 171 | original_state_dict = get_state_dict(torch.load(ckpt_path, map_location="cpu", mmap=True)) |
| 172 | vae = AutoencoderKLCogVideoX(scaling_factor=scaling_factor).to(dtype=dtype) |
| 173 | |
| 174 | for key in list(original_state_dict.keys()): |
| 175 | new_key = key[:] |
| 176 | for replace_key, rename_key in VAE_KEYS_RENAME_DICT.items(): |
| 177 | new_key = new_key.replace(replace_key, rename_key) |
| 178 | update_state_dict_inplace(original_state_dict, key, new_key) |
| 179 | |
| 180 | for key in list(original_state_dict.keys()): |
| 181 | for special_key, handler_fn_inplace in VAE_SPECIAL_KEYS_REMAP.items(): |
| 182 | if special_key not in key: |
| 183 | continue |
| 184 | handler_fn_inplace(key, original_state_dict) |
| 185 | |
| 186 | vae.load_state_dict(original_state_dict, strict=True) |
| 187 | return vae |
| 188 | |
| 189 | |
| 190 | def get_args(): |
no test coverage detected