From 33ba82e0cc358267b0f14d3e34131cdbf51ce707 Mon Sep 17 00:00:00 2001 From: ussoewwin <136552381+ussoewwin@users.noreply.github.com> Date: Fri, 10 Jul 2026 11:12:11 +0900 Subject: [PATCH] refactor: unify logging across all LoRA nodes Remove debug print statements from 6 node files. Gate Key Diffusion per-key mapping logs behind NUNCHAKU_LOG_ENABLED env var. Status logs remain always-on. --- nodes/lora/qwenimage.py | 31 ++++++++++++++----------------- nodes/lora/qwenimage_v1.py | 3 --- nodes/lora/qwenimage_v2.py | 17 +++++++---------- nodes/lora/qwenimage_v3.py | 17 +++++++---------- nodes/lora/zimageturbo_v2.py | 3 --- nodes/lora/zimageturbo_v3.py | 7 ++----- nodes/lora/zimageturbo_v4.py | 4 ++-- 7 files changed, 32 insertions(+), 50 deletions(-) diff --git a/nodes/lora/qwenimage.py b/nodes/lora/qwenimage.py index 30348f2..9350e6a 100644 --- a/nodes/lora/qwenimage.py +++ b/nodes/lora/qwenimage.py @@ -14,9 +14,6 @@ current_dir = os.path.dirname(os.path.abspath(__file__)) lora_loader_dir = os.path.dirname(os.path.dirname(current_dir)) if lora_loader_dir not in sys.path: sys.path.insert(0, lora_loader_dir) - print(f"[DEBUG] Added to sys.path: {lora_loader_dir}") - print(f"[DEBUG] wrappers dir exists: {os.path.exists(os.path.join(lora_loader_dir, 'wrappers'))}") - print(f"[DEBUG] qwenimage.py exists: {os.path.exists(os.path.join(lora_loader_dir, 'wrappers', 'qwenimage.py'))}") import folder_paths @@ -106,7 +103,7 @@ class NunchakuQwenImageLoraLoader: detection = _detect_lora_format(lora_state_dict) _log_lora_format_detection(str(lora_name), detection) # First LoRA: Detailed key inspection (same as zimageturbo_v4.py lines 219-240) - print(f"--- DEBUG: Inspecting keys for LoRA 1 (Strength: {lora_strength}) ---") + logger.info(f"--- DEBUG: Inspecting keys for LoRA 1 (Strength: {lora_strength}) ---") _first_detection = _detect_lora_format(lora_state_dict) if _first_detection["has_standard"]: for key in lora_state_dict.keys(): @@ -114,14 +111,14 @@ class NunchakuQwenImageLoraLoader: if parsed_res: group, base_key, comp, ab = parsed_res mapped_name = f"{base_key}.{comp}.{ab}" if comp and ab else (f"{base_key}.{ab}" if ab else base_key) - print(f"Key: {key} -> Mapped to: {mapped_name} (Group: {group})") + logger.info(f"Key: {key} -> Mapped to: {mapped_name} (Group: {group})") else: - print(f"Key: {key} -> UNMATCHED (Ignored)") + logger.warning(f"Key: {key} -> UNMATCHED (Ignored)") else: - print("⚠️ Unsupported LoRA format detected (No standard keys).") - print(f" Skipping detailed key inspection of {len(lora_state_dict)} keys to prevent console freeze.") - print(" Note: This LoRA will likely have no effect or will be skipped entirely.") - print("--- DEBUG: End key inspection ---") + logger.warning("⚠️ Unsupported LoRA format detected (No standard keys).") + logger.warning(f" Skipping detailed key inspection of {len(lora_state_dict)} keys to prevent console freeze.") + logger.warning(" Note: This LoRA will likely have no effect or will be skipped entirely.") + logger.info("--- DEBUG: End key inspection ---") model_wrapper = model.model.diffusion_model @@ -322,7 +319,7 @@ class NunchakuQwenImageLoraStack: detection = _detect_lora_format(lora_state_dict) _log_lora_format_detection(str(_fn), detection) # First LoRA: Detailed key inspection (same as zimageturbo_v4.py lines 219-240) - print(f"--- DEBUG: Inspecting keys for LoRA 1 (Strength: {_fs}) ---") + logger.info(f"--- DEBUG: Inspecting keys for LoRA 1 (Strength: {_fs}) ---") _first_detection = _detect_lora_format(lora_state_dict) if _first_detection["has_standard"]: for key in lora_state_dict.keys(): @@ -330,14 +327,14 @@ class NunchakuQwenImageLoraStack: if parsed_res: group, base_key, comp, ab = parsed_res mapped_name = f"{base_key}.{comp}.{ab}" if comp and ab else (f"{base_key}.{ab}" if ab else base_key) - print(f"Key: {key} -> Mapped to: {mapped_name} (Group: {group})") + logger.info(f"Key: {key} -> Mapped to: {mapped_name} (Group: {group})") else: - print(f"Key: {key} -> UNMATCHED (Ignored)") + logger.warning(f"Key: {key} -> UNMATCHED (Ignored)") else: - print("⚠️ Unsupported LoRA format detected (No standard keys).") - print(f" Skipping detailed key inspection of {len(lora_state_dict)} keys to prevent console freeze.") - print(" Note: This LoRA will likely have no effect or will be skipped entirely.") - print("--- DEBUG: End key inspection ---") + logger.warning("⚠️ Unsupported LoRA format detected (No standard keys).") + logger.warning(f" Skipping detailed key inspection of {len(lora_state_dict)} keys to prevent console freeze.") + logger.warning(" Note: This LoRA will likely have no effect or will be skipped entirely.") + logger.info("--- DEBUG: End key inspection ---") model_wrapper = model.model.diffusion_model diff --git a/nodes/lora/qwenimage_v1.py b/nodes/lora/qwenimage_v1.py index 0b3c206..c05ce5a 100644 --- a/nodes/lora/qwenimage_v1.py +++ b/nodes/lora/qwenimage_v1.py @@ -16,9 +16,6 @@ current_dir = os.path.dirname(os.path.abspath(__file__)) lora_loader_dir = os.path.dirname(os.path.dirname(current_dir)) if lora_loader_dir not in sys.path: sys.path.insert(0, lora_loader_dir) - print(f"[DEBUG] Added to sys.path: {lora_loader_dir}") - print(f"[DEBUG] wrappers dir exists: {os.path.exists(os.path.join(lora_loader_dir, 'wrappers'))}") - print(f"[DEBUG] qwenimage.py exists: {os.path.exists(os.path.join(lora_loader_dir, 'wrappers', 'qwenimage.py'))}") import folder_paths diff --git a/nodes/lora/qwenimage_v2.py b/nodes/lora/qwenimage_v2.py index 0355f1d..2e187cd 100644 --- a/nodes/lora/qwenimage_v2.py +++ b/nodes/lora/qwenimage_v2.py @@ -14,9 +14,6 @@ current_dir = os.path.dirname(os.path.abspath(__file__)) lora_loader_dir = os.path.dirname(os.path.dirname(current_dir)) if lora_loader_dir not in sys.path: sys.path.insert(0, lora_loader_dir) - print(f"[DEBUG] Added to sys.path: {lora_loader_dir}") - print(f"[DEBUG] wrappers dir exists: {os.path.exists(os.path.join(lora_loader_dir, 'wrappers'))}") - print(f"[DEBUG] qwenimage.py exists: {os.path.exists(os.path.join(lora_loader_dir, 'wrappers', 'qwenimage.py'))}") import folder_paths @@ -148,7 +145,7 @@ class NunchakuQwenImageLoraStackV2: detection = _detect_lora_format(lora_state_dict) _log_lora_format_detection(str(_fn), detection) # First LoRA: Detailed key inspection (same as zimageturbo_v4.py lines 219-240) - print(f"--- DEBUG: Inspecting keys for LoRA 1 (Strength: {_fs}) ---") + logger.info(f"--- DEBUG: Inspecting keys for LoRA 1 (Strength: {_fs}) ---") _first_detection = _detect_lora_format(lora_state_dict) if _first_detection["has_standard"]: for key in lora_state_dict.keys(): @@ -156,14 +153,14 @@ class NunchakuQwenImageLoraStackV2: if parsed_res: group, base_key, comp, ab = parsed_res mapped_name = f"{base_key}.{comp}.{ab}" if comp and ab else (f"{base_key}.{ab}" if ab else base_key) - print(f"Key: {key} -> Mapped to: {mapped_name} (Group: {group})") + logger.info(f"Key: {key} -> Mapped to: {mapped_name} (Group: {group})") else: - print(f"Key: {key} -> UNMATCHED (Ignored)") + logger.warning(f"Key: {key} -> UNMATCHED (Ignored)") else: - print("⚠️ Unsupported LoRA format detected (No standard keys).") - print(f" Skipping detailed key inspection of {len(lora_state_dict)} keys to prevent console freeze.") - print(" Note: This LoRA will likely have no effect or will be skipped entirely.") - print("--- DEBUG: End key inspection ---") + logger.warning("⚠️ Unsupported LoRA format detected (No standard keys).") + logger.warning(f" Skipping detailed key inspection of {len(lora_state_dict)} keys to prevent console freeze.") + logger.warning(" Note: This LoRA will likely have no effect or will be skipped entirely.") + logger.info("--- DEBUG: End key inspection ---") model_wrapper = model.model.diffusion_model diff --git a/nodes/lora/qwenimage_v3.py b/nodes/lora/qwenimage_v3.py index 3387f8f..b2cd5de 100644 --- a/nodes/lora/qwenimage_v3.py +++ b/nodes/lora/qwenimage_v3.py @@ -14,9 +14,6 @@ current_dir = os.path.dirname(os.path.abspath(__file__)) lora_loader_dir = os.path.dirname(os.path.dirname(current_dir)) if lora_loader_dir not in sys.path: sys.path.insert(0, lora_loader_dir) - print(f"[DEBUG] Added to sys.path: {lora_loader_dir}") - print(f"[DEBUG] wrappers dir exists: {os.path.exists(os.path.join(lora_loader_dir, 'wrappers'))}") - print(f"[DEBUG] qwenimage.py exists: {os.path.exists(os.path.join(lora_loader_dir, 'wrappers', 'qwenimage.py'))}") import folder_paths @@ -186,7 +183,7 @@ class NunchakuQwenImageLoraStackV2: detection = _detect_lora_format(lora_state_dict) _log_lora_format_detection(str(_fn), detection) # First LoRA: Detailed key inspection (same as zimageturbo_v4.py lines 219-240) - print(f"--- DEBUG: Inspecting keys for LoRA 1 (Strength: {_fs}) ---") + logger.info(f"--- DEBUG: Inspecting keys for LoRA 1 (Strength: {_fs}) ---") _first_detection = _detect_lora_format(lora_state_dict) if _first_detection["has_standard"]: for key in lora_state_dict.keys(): @@ -194,14 +191,14 @@ class NunchakuQwenImageLoraStackV2: if parsed_res: group, base_key, comp, ab = parsed_res mapped_name = f"{base_key}.{comp}.{ab}" if comp and ab else (f"{base_key}.{ab}" if ab else base_key) - print(f"Key: {key} -> Mapped to: {mapped_name} (Group: {group})") + logger.info(f"Key: {key} -> Mapped to: {mapped_name} (Group: {group})") else: - print(f"Key: {key} -> UNMATCHED (Ignored)") + logger.warning(f"Key: {key} -> UNMATCHED (Ignored)") else: - print("⚠️ Unsupported LoRA format detected (No standard keys).") - print(f" Skipping detailed key inspection of {len(lora_state_dict)} keys to prevent console freeze.") - print(" Note: This LoRA will likely have no effect or will be skipped entirely.") - print("--- DEBUG: End key inspection ---") + logger.warning("⚠️ Unsupported LoRA format detected (No standard keys).") + logger.warning(f" Skipping detailed key inspection of {len(lora_state_dict)} keys to prevent console freeze.") + logger.warning(" Note: This LoRA will likely have no effect or will be skipped entirely.") + logger.info("--- DEBUG: End key inspection ---") model_wrapper = model.model.diffusion_model diff --git a/nodes/lora/zimageturbo_v2.py b/nodes/lora/zimageturbo_v2.py index 162b923..f8a7c66 100644 --- a/nodes/lora/zimageturbo_v2.py +++ b/nodes/lora/zimageturbo_v2.py @@ -14,9 +14,6 @@ current_dir = os.path.dirname(os.path.abspath(__file__)) lora_loader_dir = os.path.dirname(os.path.dirname(current_dir)) if lora_loader_dir not in sys.path: sys.path.insert(0, lora_loader_dir) - print(f"[DEBUG] Added to sys.path: {lora_loader_dir}") - print(f"[DEBUG] wrappers dir exists: {os.path.exists(os.path.join(lora_loader_dir, 'wrappers'))}") - print(f"[DEBUG] zimageturbo.py exists: {os.path.exists(os.path.join(lora_loader_dir, 'wrappers', 'zimageturbo.py'))}") import folder_paths diff --git a/nodes/lora/zimageturbo_v3.py b/nodes/lora/zimageturbo_v3.py index 21e8e9d..f6caa58 100644 --- a/nodes/lora/zimageturbo_v3.py +++ b/nodes/lora/zimageturbo_v3.py @@ -14,9 +14,6 @@ current_dir = os.path.dirname(os.path.abspath(__file__)) lora_loader_dir = os.path.dirname(os.path.dirname(current_dir)) if lora_loader_dir not in sys.path: sys.path.insert(0, lora_loader_dir) - print(f"[DEBUG] Added to sys.path: {lora_loader_dir}") - print(f"[DEBUG] wrappers dir exists: {os.path.exists(os.path.join(lora_loader_dir, 'wrappers'))}") - print(f"[DEBUG] zimageturbo.py exists: {os.path.exists(os.path.join(lora_loader_dir, 'wrappers', 'zimageturbo.py'))}") import folder_paths @@ -190,7 +187,7 @@ class NunchakuZImageTurboLoraStackV2: if lora_loader_dir not in sys.path: sys.path.insert(0, lora_loader_dir) - from nunchaku_code.lora_qwen import _classify_and_map_key, _load_lora_state_dict, _detect_lora_format + from nunchaku_code.lora_qwen import _classify_and_map_key, _load_lora_state_dict, _detect_lora_format, NUNCHAKU_LOG_ENABLED except ImportError as e: logger.warning(f"Failed to import mapping debug functions: {e}") logger.warning("Mapping debug logs will be skipped.") @@ -199,7 +196,7 @@ class NunchakuZImageTurboLoraStackV2: _detect_lora_format = None # DEBUG: Inspect all keys in the first LoRA (mapping debug logs) - if loras_to_apply and _classify_and_map_key and _load_lora_state_dict and _detect_lora_format: + if loras_to_apply and _classify_and_map_key and _load_lora_state_dict and _detect_lora_format and NUNCHAKU_LOG_ENABLED: first_lora_name, first_lora_strength = loras_to_apply[0] try: first_lora_path = folder_paths.get_full_path_or_raise("loras", first_lora_name) diff --git a/nodes/lora/zimageturbo_v4.py b/nodes/lora/zimageturbo_v4.py index 3007c6c..f6766e6 100644 --- a/nodes/lora/zimageturbo_v4.py +++ b/nodes/lora/zimageturbo_v4.py @@ -177,7 +177,7 @@ class NunchakuZImageTurboLoraStackV4: if lora_loader_dir not in sys.path: sys.path.insert(0, lora_loader_dir) - from nunchaku_code.lora_qwen import _classify_and_map_key, _load_lora_state_dict, _detect_lora_format, _log_lora_format_detection + from nunchaku_code.lora_qwen import _classify_and_map_key, _load_lora_state_dict, _detect_lora_format, _log_lora_format_detection, NUNCHAKU_LOG_ENABLED except ImportError as e: logger.warning(f"Failed to import mapping debug functions: {e}") logger.warning("Mapping debug logs will be skipped.") @@ -217,7 +217,7 @@ class NunchakuZImageTurboLoraStackV4: pass # First LoRA: Detailed key inspection (same as v3 compose_loras_v2) - if idx == 0: + if idx == 0 and NUNCHAKU_LOG_ENABLED: logger.info(f"--- DEBUG: Inspecting keys for LoRA 1 (Strength: {lora_strength}) ---") # Check format first (same optimization as v3)