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
This commit is contained in:
Will Miao
2026-03-19 15:29:41 +08:00
parent 61c31ecbd0
commit a0dc5229f4

View File

@@ -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)