MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / convert_vae

Function convert_vae

diffusers/scripts/convert_cogvideox_to_diffusers.py:170–187  ·  view source on GitHub ↗
(ckpt_path: str, scaling_factor: float, dtype: torch.dtype)

Source from the content-addressed store, hash-verified

168
169
170def 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
190def get_args():

Calls 6

get_state_dictFunction · 0.85
load_state_dictMethod · 0.80
loadMethod · 0.45
toMethod · 0.45

Tested by

no test coverage detected