From d3930f6c73dc63019b54c5a3af9d807686ad92d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?To=C3=B1o=20Pita?= Date: Thu, 8 Oct 2026 21:48:37 +0200 Subject: [PATCH] ComfyUI backend: add MiniMax H3 3D latent upscaler support to Refiner --- .../ComfyUIBackend/ComfyUIBackendExtension.cs | 3 +- .../ComfyUIBackend/WorkflowGeneratorSteps.cs | 125 +++++++++++++----- src/Core/InstallableFeatures.cs | 1 + 3 files changed, 97 insertions(+), 32 deletions(-) diff --git a/src/BuiltinExtensions/ComfyUIBackend/ComfyUIBackendExtension.cs b/src/BuiltinExtensions/ComfyUIBackend/ComfyUIBackendExtension.cs index edcd87148..bac6120a4 100644 --- a/src/BuiltinExtensions/ComfyUIBackend/ComfyUIBackendExtension.cs +++ b/src/BuiltinExtensions/ComfyUIBackend/ComfyUIBackendExtension.cs @@ -69,7 +69,8 @@ public record class ComfyCustomWorkflow(string Name, string Workflow, string Pro ["TeaCache"] = "teacache", ["TeaCacheForVidGen"] = "teacache", ["TeaCacheForImgGen"] = "teacache_oldvers", - ["OverrideCLIPDevice"] = "set_clip_device" + ["OverrideCLIPDevice"] = "set_clip_device", + ["MinimaxH3LatentUpscaler3D"] = "minimax_h3_latent_upscaler" }; /// diff --git a/src/BuiltinExtensions/ComfyUIBackend/WorkflowGeneratorSteps.cs b/src/BuiltinExtensions/ComfyUIBackend/WorkflowGeneratorSteps.cs index 8e18f2c12..84b882646 100644 --- a/src/BuiltinExtensions/ComfyUIBackend/WorkflowGeneratorSteps.cs +++ b/src/BuiltinExtensions/ComfyUIBackend/WorkflowGeneratorSteps.cs @@ -1699,48 +1699,111 @@ JArray doMaskShrinkApply(WorkflowGenerator g, JArray imgIn) } else if (doUpscale && upscaleMethod.StartsWith("latentmodel-")) { - g.CreateNode("LatentUpscaleModelLoader", new JObject() + string modelName = upscaleMethod.After("latentmodel-"); + if (g.IsMiniMaxH3()) { - ["model_name"] = upscaleMethod.After("latentmodel-") - }, "27"); - if (g.IsHunyuanVideo15()) - { - g.CreateNode("HunyuanVideo15LatentUpscaleWithModel", new JObject() + width = (width / 32) * 32; + height = (height / 32) * 32; + if (!g.Features.Contains("minimax_h3_latent_upscaler")) { - ["model"] = NodePath("27", 0), - ["samples"] = g.CurrentMedia.Path, - ["upscale_method"] = "bilinear", - ["width"] = width, - ["height"] = height, - ["crop"] = "disabled" - }, "26"); - g.CurrentMedia = g.CurrentMedia.WithPath(["26", 0], WGNodeData.DT_LATENT_VIDEO); - } - else if (g.IsLTXV2()) - { - g.CurrentMedia = g.CurrentMedia.AsLatentImage(g.CurrentVae); - string cropGuides = g.CreateNode("LTXVCropGuides", new JObject() + throw new SwarmUserErrorException("MiniMax H3 latent upscaling requires the Comfyui_Minimax_h3_latent_Upscaler node pack."); + } + JArray vidLatent; + JArray audLatent = null; + if (g.CurrentMedia.DataType == WGNodeData.DT_LATENT_AUDIOVIDEO) { - ["positive"] = prompt, - ["negative"] = negPrompt, - ["latent"] = g.CurrentMedia.Path - }); - prompt = [cropGuides, 0]; - negPrompt = [cropGuides, 1]; - g.CreateNode("LTXVLatentUpsampler", new JObject() + string sepNode = g.CreateNode("LTXVSeparateAVLatent", new JObject() + { + ["av_latent"] = g.CurrentMedia.Path + }); + vidLatent = NodePath(sepNode, 0); + audLatent = NodePath(sepNode, 1); + } + else { - ["vae"] = g.CurrentVae.Path, - ["samples"] = NodePath(cropGuides, 2), - ["upscale_model"] = NodePath("27", 0) + vidLatent = g.CurrentMedia.Path; + if (g.CurrentMedia.AttachedAudio is not null) + { + audLatent = g.CurrentMedia.AttachedAudio.Path; + } + } + string upscaleNode = g.CreateNode("MinimaxH3LatentUpscaler3D", new JObject() + { + ["latent"] = vidLatent, + ["model_name"] = modelName, + ["mode"] = "scale by multiplier", + ["mode.scale"] = refineUpscale, + ["align"] = 32, + ["enable_temporal_chunking"] = true, + ["force_unload"] = true, + ["device"] = "cuda", + ["precision"] = "fp16" }, "26"); - g.CurrentMedia = g.CurrentMedia.WithPath(["26", 0], WGNodeData.DT_LATENT_VIDEO); + if (audLatent is not null) + { + string concatNode = g.CreateNode("LTXVConcatAVLatent", new JObject() + { + ["video_latent"] = NodePath(upscaleNode, 0), + ["audio_latent"] = audLatent + }); + g.CurrentMedia = g.CurrentMedia.WithPath([concatNode, 0], WGNodeData.DT_LATENT_AUDIOVIDEO); + g.CurrentMedia.AttachedAudio = null; + } + else + { + g.CurrentMedia = g.CurrentMedia.WithPath([upscaleNode, 0], WGNodeData.DT_LATENT_VIDEO); + } } else { - throw new SwarmUserErrorException($"Cannot latent-upscale with a model for {g.CurrentCompatClass()}, check your Refiner Upscale Method parameter"); + g.CreateNode("LatentUpscaleModelLoader", new JObject() + { + ["model_name"] = modelName + }, "27"); + if (g.IsHunyuanVideo15()) + { + g.CreateNode("HunyuanVideo15LatentUpscaleWithModel", new JObject() + { + ["model"] = NodePath("27", 0), + ["samples"] = g.CurrentMedia.Path, + ["upscale_method"] = "bilinear", + ["width"] = width, + ["height"] = height, + ["crop"] = "disabled" + }, "26"); + g.CurrentMedia = g.CurrentMedia.WithPath(["26", 0], WGNodeData.DT_LATENT_VIDEO); + } + else if (g.IsLTXV2()) + { + g.CurrentMedia = g.CurrentMedia.AsLatentImage(g.CurrentVae); + string cropGuides = g.CreateNode("LTXVCropGuides", new JObject() + { + ["positive"] = prompt, + ["negative"] = negPrompt, + ["latent"] = g.CurrentMedia.Path + }); + prompt = [cropGuides, 0]; + negPrompt = [cropGuides, 1]; + g.CreateNode("LTXVLatentUpsampler", new JObject() + { + ["vae"] = g.CurrentVae.Path, + ["samples"] = NodePath(cropGuides, 2), + ["upscale_model"] = NodePath("27", 0) + }, "26"); + g.CurrentMedia = g.CurrentMedia.WithPath(["26", 0], WGNodeData.DT_LATENT_VIDEO); + } + else + { + throw new SwarmUserErrorException($"Cannot latent-upscale with a model for {g.CurrentCompatClass()}, check your Refiner Upscale Method parameter"); + } } g.CurrentMedia.Width = width; g.CurrentMedia.Height = height; + if (refinerControl <= 0) + { + g.IsRefinerStage = false; + return; + } } if (isSeedVr) { diff --git a/src/Core/InstallableFeatures.cs b/src/Core/InstallableFeatures.cs index 565a20e27..28e13e294 100644 --- a/src/Core/InstallableFeatures.cs +++ b/src/Core/InstallableFeatures.cs @@ -36,5 +36,6 @@ static InstallableFeatures() RegisterInstallableFeature(new("ExtraModels", "extramodels", "https://github.com/city96/ComfyUI_ExtraModels", "city96", "This will install ExtraModels support developed by city96.\nDo you wish to install?")); RegisterInstallableFeature(new("Nunchaku", "nunchaku", "https://github.com/mit-han-lab/ComfyUI-nunchaku", "mit-han-lab")); RegisterInstallableFeature(new("TeaCache", "teacache", "https://github.com/welltop-cn/ComfyUI-TeaCache", "welltop-cn")); + RegisterInstallableFeature(new("MiniMax H3 Latent Upscaler", "minimax_h3_latent_upscaler", "https://github.com/LBH-123-AI/Comfyui_Minimax_h3_latent_Upscaler", "LBH-123-AI")); } }