From a0dc5229f43b3d4222b8b5758fd86d5b5cf7823a Mon Sep 17 00:00:00 2001 From: Will Miao Date: Thu, 19 Mar 2026 15:29:41 +0800 Subject: [PATCH] feat(unet_loader): move torch import inside methods for lazy loading - Delay torch import until needed in load_unet and load_unet_gguf methods - This improves module loading performance by avoiding unnecessary imports - Maintains functionality while reducing initial import overhead --- py/nodes/unet_loader.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/py/nodes/unet_loader.py b/py/nodes/unet_loader.py index 64704904..96982d69 100644 --- a/py/nodes/unet_loader.py +++ b/py/nodes/unet_loader.py @@ -1,7 +1,6 @@ import logging import os from typing import List, Tuple -import torch import comfy.sd from ..utils.utils import get_checkpoint_info_absolute, _format_model_name_for_comfyui @@ -101,6 +100,8 @@ class UNETLoaderLM: Returns: Tuple of (MODEL,) """ + import torch + # Get absolute path from cache using ComfyUI-style name unet_path, metadata = get_checkpoint_info_absolute(unet_name) @@ -143,6 +144,7 @@ class UNETLoaderLM: Returns: Tuple of (MODEL,) """ + import torch from .gguf_import_helper import get_gguf_modules # Get ComfyUI-GGUF modules using helper (handles various import scenarios)