From e0ddbbb6986cc2bbd7e93bae8a75a11adf90eee2 Mon Sep 17 00:00:00 2001 From: Bruno Fargnoli Date: Thu, 30 Jul 2026 22:50:43 +0200 Subject: [PATCH] Improved loading time by ComfyUI initialization --- configs/dit_config_2_1.yaml | 2 +- .../Apply_8Views_On_Mesh.json | 0 .../Batch_Generator.json | 0 .../Full_Workflow.json | 0 .../Mesh_Generation.json | 0 .../Mesh_Texturing.json | 0 .../Mesh_Texturing_UpscaleWithAuraSR.json | 0 .../Mesh_Texturing_UpscaleWithInvSR.json | 0 .../Mesh_Texturing_With_MetaData.json | 0 ...ing_With_MetaData_Upscaled_With_Model.json | 0 nodes.py | 74 +++++++++++++------ 11 files changed, 54 insertions(+), 22 deletions(-) rename {workflow_examples => example_workflows}/Apply_8Views_On_Mesh.json (100%) rename {workflow_examples => example_workflows}/Batch_Generator.json (100%) rename {workflow_examples => example_workflows}/Full_Workflow.json (100%) rename {workflow_examples => example_workflows}/Mesh_Generation.json (100%) rename {workflow_examples => example_workflows}/Mesh_Texturing.json (100%) rename {workflow_examples => example_workflows}/Mesh_Texturing_UpscaleWithAuraSR.json (100%) rename {workflow_examples => example_workflows}/Mesh_Texturing_UpscaleWithInvSR.json (100%) rename {workflow_examples => example_workflows}/Mesh_Texturing_With_MetaData.json (100%) rename {workflow_examples => example_workflows}/Mesh_Texturing_With_MetaData_Upscaled_With_Model.json (100%) diff --git a/configs/dit_config_2_1.yaml b/configs/dit_config_2_1.yaml index 3ee9747..0d0995b 100644 --- a/configs/dit_config_2_1.yaml +++ b/configs/dit_config_2_1.yaml @@ -76,7 +76,7 @@ image_processor: target: .hy3dshape.hy3dshape.preprocessors.ImageProcessorV2 params: size: 512 - border_ratio: 0.15 + border_ratio: 0.0 pipeline: target: .hy3dshape.hy3dshape.pipelines.Hunyuan3DDiTFlowMatchingPipeline diff --git a/workflow_examples/Apply_8Views_On_Mesh.json b/example_workflows/Apply_8Views_On_Mesh.json similarity index 100% rename from workflow_examples/Apply_8Views_On_Mesh.json rename to example_workflows/Apply_8Views_On_Mesh.json diff --git a/workflow_examples/Batch_Generator.json b/example_workflows/Batch_Generator.json similarity index 100% rename from workflow_examples/Batch_Generator.json rename to example_workflows/Batch_Generator.json diff --git a/workflow_examples/Full_Workflow.json b/example_workflows/Full_Workflow.json similarity index 100% rename from workflow_examples/Full_Workflow.json rename to example_workflows/Full_Workflow.json diff --git a/workflow_examples/Mesh_Generation.json b/example_workflows/Mesh_Generation.json similarity index 100% rename from workflow_examples/Mesh_Generation.json rename to example_workflows/Mesh_Generation.json diff --git a/workflow_examples/Mesh_Texturing.json b/example_workflows/Mesh_Texturing.json similarity index 100% rename from workflow_examples/Mesh_Texturing.json rename to example_workflows/Mesh_Texturing.json diff --git a/workflow_examples/Mesh_Texturing_UpscaleWithAuraSR.json b/example_workflows/Mesh_Texturing_UpscaleWithAuraSR.json similarity index 100% rename from workflow_examples/Mesh_Texturing_UpscaleWithAuraSR.json rename to example_workflows/Mesh_Texturing_UpscaleWithAuraSR.json diff --git a/workflow_examples/Mesh_Texturing_UpscaleWithInvSR.json b/example_workflows/Mesh_Texturing_UpscaleWithInvSR.json similarity index 100% rename from workflow_examples/Mesh_Texturing_UpscaleWithInvSR.json rename to example_workflows/Mesh_Texturing_UpscaleWithInvSR.json diff --git a/workflow_examples/Mesh_Texturing_With_MetaData.json b/example_workflows/Mesh_Texturing_With_MetaData.json similarity index 100% rename from workflow_examples/Mesh_Texturing_With_MetaData.json rename to example_workflows/Mesh_Texturing_With_MetaData.json diff --git a/workflow_examples/Mesh_Texturing_With_MetaData_Upscaled_With_Model.json b/example_workflows/Mesh_Texturing_With_MetaData_Upscaled_With_Model.json similarity index 100% rename from workflow_examples/Mesh_Texturing_With_MetaData_Upscaled_With_Model.json rename to example_workflows/Mesh_Texturing_With_MetaData_Upscaled_With_Model.json diff --git a/nodes.py b/nodes.py index f7f92f7..23c3b01 100644 --- a/nodes.py +++ b/nodes.py @@ -1,13 +1,8 @@ from PIL import Image, ImageSequence, ImageOps -from torch.utils.data import Dataset import torch import shutil import argparse import copy -import torch.nn as nn -from torch.utils.data import DataLoader -from torchvision.utils import save_image as imwrite -from torchvision import transforms import os import time import re @@ -16,25 +11,9 @@ import torch.nn.functional as F import trimesh as Trimesh import gc import json -from .hy3dshape.hy3dshape.pipelines import Hunyuan3DDiTFlowMatchingPipeline -from .hy3dshape.hy3dshape.postprocessors import FaceReducer, FloaterRemover, DegenerateFaceRemover -from .hy3dshape.hy3dshape.rembg import BackgroundRemover from typing import Union, Optional, Tuple, List, Any, Callable from pathlib import Path -#painting -from .hy3dpaint.DifferentiableRenderer.MeshRender import MeshRender -from .hy3dpaint.utils.simplify_mesh_utils import remesh_mesh -from .hy3dpaint.utils.multiview_utils import multiviewDiffusionNet -from .hy3dpaint.utils.pipeline_utils import ViewProcessor -from .hy3dpaint.utils.image_super_utils import imageSuperNet -from .hy3dpaint.utils.uvwrap_utils import mesh_uv_wrap -from .hy3dpaint.convert_utils import create_glb_with_pbr_materials -from .hy3dpaint.textureGenPipeline import Hunyuan3DPaintPipeline, Hunyuan3DPaintConfig -from .hy3dshape.hy3dshape.models.autoencoders import ShapeVAE - -from .hy3dshape.hy3dshape.meshlib import postprocessmesh - from spandrel import ModelLoader, ImageModelDescriptor import folder_paths @@ -45,6 +24,59 @@ import comfy.model_management as mm from comfy.utils import load_torch_file, ProgressBar import comfy.utils + +class _LazyImport: + """Defer a heavy import until the symbol is first actually used. + + Importing the shape/paint stacks at module scope made ComfyUI's startup scan + of this pack cost 10.7s (now 0.6s): diffusers, transformers, meshlib, plus + two separate paths into onnxruntime -- rembg, and textureGenPipeline -> + multiview_utils -> pytorch_lightning -> torchmetrics.functional.audio. + None of it is needed until a node actually runs, so we bind a proxy here + and resolve it on first use. + + Note this only moves the cost off startup; whichever pack loads first and + eagerly imports the same shared stack (ComfyUI-Hunyuan3DWrapper does) will + pay it instead. + + Only safe for names that are exclusively called or attribute-accessed; + anything used with isinstance() or subclassed must stay a real import. + """ + + __slots__ = ("_module", "_attr", "_resolved") + + def __init__(self, module, attr): + self._module = module + self._attr = attr + self._resolved = None + + def _get(self): + if self._resolved is None: + from importlib import import_module + self._resolved = getattr(import_module(self._module, __package__), self._attr) + return self._resolved + + def __call__(self, *args, **kwargs): + return self._get()(*args, **kwargs) + + def __getattr__(self, name): + return getattr(self._get(), name) + + +#shape +Hunyuan3DDiTFlowMatchingPipeline = _LazyImport(".hy3dshape.hy3dshape.pipelines", "Hunyuan3DDiTFlowMatchingPipeline") +FaceReducer = _LazyImport(".hy3dshape.hy3dshape.postprocessors", "FaceReducer") +FloaterRemover = _LazyImport(".hy3dshape.hy3dshape.postprocessors", "FloaterRemover") +DegenerateFaceRemover = _LazyImport(".hy3dshape.hy3dshape.postprocessors", "DegenerateFaceRemover") +BackgroundRemover = _LazyImport(".hy3dshape.hy3dshape.rembg", "BackgroundRemover") +ShapeVAE = _LazyImport(".hy3dshape.hy3dshape.models.autoencoders", "ShapeVAE") +postprocessmesh = _LazyImport(".hy3dshape.hy3dshape.meshlib", "postprocessmesh") + +#painting +mesh_uv_wrap = _LazyImport(".hy3dpaint.utils.uvwrap_utils", "mesh_uv_wrap") +Hunyuan3DPaintPipeline = _LazyImport(".hy3dpaint.textureGenPipeline", "Hunyuan3DPaintPipeline") +Hunyuan3DPaintConfig = _LazyImport(".hy3dpaint.textureGenPipeline", "Hunyuan3DPaintConfig") + script_directory = os.path.dirname(os.path.abspath(__file__)) comfy_path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) diffusions_dir = os.path.join(comfy_path, "models", "diffusers")