1 Commits
Author SHA1 Message Date
li-lizhe 13bb3c625e fix(z-image): strip the ComfyUI model.diffusion_model. key prefix before converting (#522)
LoadZImageTransformerModel.loadmodel decides whether to run convert_state_dict
by looking for a bare `x_embedder.weight` key, and the converter itself assumes
bare keys.  ComfyUI-native checkpoints (e.g. CivitAI Z-Image fine-tunes) store
every tensor under a `model.diffusion_model.` prefix, so the gate never fired,
the prefix survived, and the strict load_state_dict failed with
"Missing key(s): x_pad_token ... / Unexpected key(s): model.diffusion_model...".

Strip the prefix when every key carries it, then convert as before.  Bare-key
checkpoints are untouched.

Signed-off-by: li-lizhe <147392333@qq.com>
2026-10-14 09:43:58 +08:00
+6
View File
@@ -97,6 +97,12 @@ class LoadZImageTransformerModel:
model_path = folder_paths.get_full_path("diffusion_models", model_name)
transformer_state_dict = load_torch_file(model_path, safe_load=True)
# Some ComfyUI-native checkpoints store every diffusion-model tensor under a
# `model.diffusion_model.` prefix (e.g. CivitAI Z-Image fine-tunes). Strip it so
# the conversion gate below and `convert_state_dict` receive bare keys.
_prefix = "model.diffusion_model."
if transformer_state_dict and all(k.startswith(_prefix) for k in transformer_state_dict):
transformer_state_dict = {k[len(_prefix):]: v for k, v in transformer_state_dict.items()}
def convert_state_dict(old_state_dict):
new_state_dict = {}
for key, value in old_state_dict.items():