Skip to content

Commit 283c5f3

Browse files
committed
chore(ltx2): clearer LoRA-loader logging; warn on unused keys
Logging/diagnostics only - what gets merged is unchanged: - a missing LoRA weight name returns early with one clear message (was two unclear logs); - a missing `transformer` is logged on its own (was folded into the weight-name message); - a missing `connectors` is now logged (previously had no message); - warn when a LoRA carries keys outside the two prefixes routed to the merges (`diffusion_model.` / `text_embedding_projection.`) - those keys were previously dropped without any notice.
1 parent 9595c5e commit 283c5f3

1 file changed

Lines changed: 20 additions & 12 deletions

File tree

src/maxdiffusion/loaders/ltx2_lora_nnx_loader.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,34 @@ def load_lora_weights(
5050
def translate_fn(nnx_path_str):
5151
return lora_conversion_utils.translate_ltx2_nnx_path_to_diffusers_lora(nnx_path_str, scan_layers=scan_layers)
5252

53-
h_state_dict = None
54-
if hasattr(pipeline, "transformer") and transformer_weight_name:
53+
if not transformer_weight_name:
54+
max_logging.log("No LoRA weight name provided; skipping LoRA load.")
55+
return pipeline
56+
57+
h_state_dict, _ = lora_loader.lora_state_dict(lora_model_path, weight_name=transformer_weight_name, **kwargs)
58+
transformer_state_dict = {}
59+
connector_state_dict = {}
60+
if hasattr(pipeline, "transformer"):
5561
max_logging.log(f"Merging LoRA into transformer with rank={rank}")
56-
h_state_dict, _ = lora_loader.lora_state_dict(lora_model_path, weight_name=transformer_weight_name, **kwargs)
5762
# Filter state dict for transformer keys to avoid confusing warnings
5863
transformer_state_dict = {k: v for k, v in h_state_dict.items() if k.startswith("diffusion_model")}
5964
merge_fn(pipeline.transformer, transformer_state_dict, rank, scale, translate_fn, dtype=dtype)
6065
else:
61-
max_logging.log("transformer not found or no weight name provided for LoRA.")
66+
max_logging.log("transformer not found.")
6267

6368
if hasattr(pipeline, "connectors"):
6469
max_logging.log(f"Merging LoRA into connectors with rank={rank}")
65-
if h_state_dict is None and transformer_weight_name:
66-
h_state_dict, _ = lora_loader.lora_state_dict(lora_model_path, weight_name=transformer_weight_name, **kwargs)
70+
connector_state_dict = {k: v for k, v in h_state_dict.items() if k.startswith("text_embedding_projection")}
71+
merge_fn(pipeline.connectors, connector_state_dict, rank, scale, translate_fn, dtype=dtype)
72+
else:
73+
max_logging.log("connectors not found.")
6774

68-
if h_state_dict is not None:
69-
# Filter state dict for connector keys to avoid confusing warnings
70-
connector_state_dict = {k: v for k, v in h_state_dict.items() if k.startswith("text_embedding_projection")}
71-
merge_fn(pipeline.connectors, connector_state_dict, rank, scale, translate_fn, dtype=dtype)
72-
else:
73-
max_logging.log("Could not load LoRA state dict for connectors.")
75+
# Warn if there are keys routed to no target.
76+
# the merge_fn warns about unmatched keys in each dict, so we only warn about any leftovers
77+
unmatched_keys = set(h_state_dict) - set(transformer_state_dict) - set(connector_state_dict)
78+
if unmatched_keys:
79+
max_logging.log(
80+
f"{len(unmatched_keys)} key(s) in LoRA dictionary routed to no merge target: {unmatched_keys}"
81+
)
7482

7583
return pipeline

0 commit comments

Comments
 (0)