MCPcopy Create free account
hub / github.com/OpenDriveLab/ReSim / convert_vae

Function convert_vae

tools/convert_weight_sat2hf.py:184–201  ·  view source on GitHub ↗
(ckpt_path: str)

Source from the content-addressed store, hash-verified

182
183# Function to convert a VAE checkpoint to the CogVideoX format
184def 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

Callers 1

Calls 4

get_state_dictFunction · 0.85
loadMethod · 0.45
load_state_dictMethod · 0.45

Tested by

no test coverage detected