Add tiled MiniMax H3 latent upscale node
This commit is contained in:
@@ -30,6 +30,32 @@ or accept a re-encoded workflow.
|
|||||||
|
|
||||||
## Project rendering
|
## Project rendering
|
||||||
|
|
||||||
|
## MiniMax-H3 tiled latent upscale
|
||||||
|
|
||||||
|
`DumasMMH3TiledLatentUpscale` is a thin integration node for the native
|
||||||
|
`MMH3UltimateUpscale` node used by the MiniMax-H3 workflow. It accepts the
|
||||||
|
native H3 latent-upscale, temporal-split, and spatial-split parameter objects,
|
||||||
|
but creates a separate upscale sampler, scheduler, sigma schedule, noise seed,
|
||||||
|
denoise value, steps value, and CFG value. The base H3 sampling pass is not
|
||||||
|
changed.
|
||||||
|
|
||||||
|
Typical wiring:
|
||||||
|
|
||||||
|
```text
|
||||||
|
base H3 latent + model + conditioning
|
||||||
|
-> Dumas MiniMax-H3 Tiled Latent Upscale
|
||||||
|
H3 Latent Upscale Params --------------------^
|
||||||
|
H3 Temporal Split Params ---------------------^
|
||||||
|
H3 Spatial Split Params -----------------------^
|
||||||
|
```
|
||||||
|
|
||||||
|
The node requires the ComfyUI installation to provide `MMH3UltimateUpscale`,
|
||||||
|
`RandomNoise`, `KSamplerSelect`, and `BasicScheduler`. It does not copy or
|
||||||
|
redistribute the third-party H3 LongVideos implementation. The native node's
|
||||||
|
current socket types are `H3_UPSCALE_PARAM`, `H3_TEMPORAL_PARAM`, and
|
||||||
|
`H3_SPATIAL_PARAM`; these are deliberately used unchanged for workflow
|
||||||
|
compatibility.
|
||||||
|
|
||||||
The CSGlide `Render Project` control is the generation orchestrator: it renders
|
The CSGlide `Render Project` control is the generation orchestrator: it renders
|
||||||
clips sequentially, adopts each completed render, extracts the previous clip's
|
clips sequentially, adopts each completed render, extracts the previous clip's
|
||||||
tail, fills the next clip's `CONTINUE FROM` guide, and waits before advancing.
|
tail, fills the next clip's `CONTINUE FROM` guide, and waits before advancing.
|
||||||
|
|||||||
@@ -14,16 +14,22 @@ from .dumas_video_nodes import (
|
|||||||
NODE_CLASS_MAPPINGS as VIDEO_NODE_CLASS_MAPPINGS,
|
NODE_CLASS_MAPPINGS as VIDEO_NODE_CLASS_MAPPINGS,
|
||||||
NODE_DISPLAY_NAME_MAPPINGS as VIDEO_NODE_DISPLAY_NAME_MAPPINGS,
|
NODE_DISPLAY_NAME_MAPPINGS as VIDEO_NODE_DISPLAY_NAME_MAPPINGS,
|
||||||
)
|
)
|
||||||
|
from .dumas_minimax_nodes import (
|
||||||
|
NODE_CLASS_MAPPINGS as MINIMAX_NODE_CLASS_MAPPINGS,
|
||||||
|
NODE_DISPLAY_NAME_MAPPINGS as MINIMAX_NODE_DISPLAY_NAME_MAPPINGS,
|
||||||
|
)
|
||||||
|
|
||||||
NODE_CLASS_MAPPINGS = {}
|
NODE_CLASS_MAPPINGS = {}
|
||||||
NODE_CLASS_MAPPINGS.update(JSON_NODE_CLASS_MAPPINGS)
|
NODE_CLASS_MAPPINGS.update(JSON_NODE_CLASS_MAPPINGS)
|
||||||
NODE_CLASS_MAPPINGS.update(IMAGE_NODE_CLASS_MAPPINGS)
|
NODE_CLASS_MAPPINGS.update(IMAGE_NODE_CLASS_MAPPINGS)
|
||||||
NODE_CLASS_MAPPINGS.update(VIDEO_NODE_CLASS_MAPPINGS)
|
NODE_CLASS_MAPPINGS.update(VIDEO_NODE_CLASS_MAPPINGS)
|
||||||
|
NODE_CLASS_MAPPINGS.update(MINIMAX_NODE_CLASS_MAPPINGS)
|
||||||
|
|
||||||
NODE_DISPLAY_NAME_MAPPINGS = {}
|
NODE_DISPLAY_NAME_MAPPINGS = {}
|
||||||
NODE_DISPLAY_NAME_MAPPINGS.update(JSON_NODE_DISPLAY_NAME_MAPPINGS)
|
NODE_DISPLAY_NAME_MAPPINGS.update(JSON_NODE_DISPLAY_NAME_MAPPINGS)
|
||||||
NODE_DISPLAY_NAME_MAPPINGS.update(IMAGE_NODE_DISPLAY_NAME_MAPPINGS)
|
NODE_DISPLAY_NAME_MAPPINGS.update(IMAGE_NODE_DISPLAY_NAME_MAPPINGS)
|
||||||
NODE_DISPLAY_NAME_MAPPINGS.update(VIDEO_NODE_DISPLAY_NAME_MAPPINGS)
|
NODE_DISPLAY_NAME_MAPPINGS.update(VIDEO_NODE_DISPLAY_NAME_MAPPINGS)
|
||||||
|
NODE_DISPLAY_NAME_MAPPINGS.update(MINIMAX_NODE_DISPLAY_NAME_MAPPINGS)
|
||||||
|
|
||||||
WEB_DIRECTORY = "./js"
|
WEB_DIRECTORY = "./js"
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,150 @@
|
|||||||
|
"""Dumas MiniMax-H3 helpers.
|
||||||
|
|
||||||
|
This module intentionally does not vendor the third-party H3 LongVideos node.
|
||||||
|
It provides the missing tiled latent second pass around the native
|
||||||
|
``MMH3UltimateUpscale`` node that is already used by the user's H3 workflow.
|
||||||
|
The node keeps its own sampling controls, so changing the upscale pass cannot
|
||||||
|
silently change the base H3 render.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def _sampler_options():
|
||||||
|
try:
|
||||||
|
import comfy.samplers
|
||||||
|
return list(comfy.samplers.KSampler.SAMPLERS)
|
||||||
|
except Exception: # import-time test fallback
|
||||||
|
return ["euler", "euler_ancestral", "res_multistep", "sa_solver"]
|
||||||
|
|
||||||
|
|
||||||
|
def _scheduler_options():
|
||||||
|
try:
|
||||||
|
import comfy.samplers
|
||||||
|
return list(comfy.samplers.KSampler.SCHEDULERS)
|
||||||
|
except Exception: # import-time test fallback
|
||||||
|
return ["simple", "beta", "sgm_uniform", "karras", "exponential"]
|
||||||
|
|
||||||
|
|
||||||
|
def _native_node(name):
|
||||||
|
try:
|
||||||
|
import nodes
|
||||||
|
mapping = getattr(nodes, "NODE_CLASS_MAPPINGS", {}) or {}
|
||||||
|
cls = mapping.get(name)
|
||||||
|
if cls is not None:
|
||||||
|
return cls
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
class DumasMMH3TiledLatentUpscale:
|
||||||
|
"""Run a tiled MiniMax-H3 latent upscale/refinement pass.
|
||||||
|
|
||||||
|
The incoming latent is normally the output of the base H3 sampler. The
|
||||||
|
native MMH3 upscale node performs the actual model-specific tiled work;
|
||||||
|
this wrapper creates its noise, sampler and sigma schedule from its own
|
||||||
|
widgets and passes through the user's spatial split parameter object.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def INPUT_TYPES(cls):
|
||||||
|
return {
|
||||||
|
"required": {
|
||||||
|
"model": ("MODEL",),
|
||||||
|
"conditioning": ("CONDITIONING",),
|
||||||
|
"latent": ("LATENT",),
|
||||||
|
"latent_upscale_param": ("H3_UPSCALE_PARAM",),
|
||||||
|
"spatial_split_param": ("H3_SPATIAL_PARAM",),
|
||||||
|
"upscale_sampler": (_sampler_options(), {"default": "euler_ancestral"}),
|
||||||
|
"upscale_scheduler": (_scheduler_options(), {"default": "simple"}),
|
||||||
|
"upscale_steps": ("INT", {"default": 3, "min": 1, "max": 50}),
|
||||||
|
"upscale_denoise": ("FLOAT", {"default": 0.2, "min": 0.0, "max": 1.0, "step": 0.01}),
|
||||||
|
"upscale_cfg": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 20.0, "step": 0.1}),
|
||||||
|
"upscale_noise_seed": ("INT", {"default": 363742558835919, "min": 0, "max": 0xffffffffffffffff, "control_after_generate": True}),
|
||||||
|
},
|
||||||
|
"optional": {
|
||||||
|
"negative": ("CONDITIONING",),
|
||||||
|
"temporal_split_param": ("H3_TEMPORAL_PARAM",),
|
||||||
|
"upscale_sigmas": ("SIGMAS",),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
RETURN_TYPES = ("LATENT", "STRING")
|
||||||
|
RETURN_NAMES = ("upscaled_latent", "info")
|
||||||
|
FUNCTION = "upscale"
|
||||||
|
CATEGORY = "Dumas/MiniMax"
|
||||||
|
|
||||||
|
def upscale(
|
||||||
|
self, model, conditioning, latent, latent_upscale_param,
|
||||||
|
spatial_split_param, upscale_sampler, upscale_scheduler,
|
||||||
|
upscale_steps, upscale_denoise, upscale_cfg, upscale_noise_seed,
|
||||||
|
negative=None, temporal_split_param=None, upscale_sigmas=None,
|
||||||
|
):
|
||||||
|
native = _native_node("MMH3UltimateUpscale")
|
||||||
|
if native is None:
|
||||||
|
raise RuntimeError(
|
||||||
|
"MMH3UltimateUpscale is not installed. Install/update the MiniMax-H3 "
|
||||||
|
"node pack that provides the native tiled upscale node."
|
||||||
|
)
|
||||||
|
|
||||||
|
random_noise = _native_node("RandomNoise")
|
||||||
|
sampler_select = _native_node("KSamplerSelect")
|
||||||
|
scheduler = _native_node("BasicScheduler")
|
||||||
|
missing = [
|
||||||
|
name for name, value in (("RandomNoise", random_noise),
|
||||||
|
("KSamplerSelect", sampler_select),
|
||||||
|
("BasicScheduler", scheduler))
|
||||||
|
if value is None
|
||||||
|
]
|
||||||
|
if missing:
|
||||||
|
raise RuntimeError("Missing native ComfyUI nodes: " + ", ".join(missing))
|
||||||
|
|
||||||
|
noise = random_noise().get_noise(int(upscale_noise_seed))
|
||||||
|
sampler = sampler_select().get_sampler(str(upscale_sampler))
|
||||||
|
sigmas = upscale_sigmas
|
||||||
|
if sigmas is None:
|
||||||
|
sigmas = scheduler().get_sigmas(
|
||||||
|
model, str(upscale_scheduler), int(upscale_steps), float(upscale_denoise)
|
||||||
|
)
|
||||||
|
|
||||||
|
kwargs = {
|
||||||
|
"model": model,
|
||||||
|
"conditioning": conditioning,
|
||||||
|
"latent": latent,
|
||||||
|
"noise": noise,
|
||||||
|
"sampler": sampler,
|
||||||
|
"sigmas": sigmas,
|
||||||
|
"cfg": float(upscale_cfg),
|
||||||
|
"latent_upscale_param": latent_upscale_param,
|
||||||
|
"temporal_split_param": temporal_split_param,
|
||||||
|
"spatial_split_param": spatial_split_param,
|
||||||
|
}
|
||||||
|
if negative is not None:
|
||||||
|
kwargs["negative"] = negative
|
||||||
|
result = native().upscale(**kwargs)
|
||||||
|
if not isinstance(result, (tuple, list)) or not result:
|
||||||
|
raise RuntimeError("MMH3UltimateUpscale returned no latent output.")
|
||||||
|
output = result[0]
|
||||||
|
if not isinstance(output, dict) or "samples" not in output:
|
||||||
|
raise RuntimeError("MMH3UltimateUpscale returned an unexpected latent object.")
|
||||||
|
samples = output["samples"]
|
||||||
|
if samples.ndim != 5:
|
||||||
|
raise RuntimeError(f"Expected a 5-D H3 latent, got shape {tuple(samples.shape)}.")
|
||||||
|
if samples.shape[2] != latent["samples"].shape[2]:
|
||||||
|
raise RuntimeError("Tiled spatial upscale changed the temporal latent length.")
|
||||||
|
info = (
|
||||||
|
"Dumas tiled MiniMax-H3 latent upscale: "
|
||||||
|
f"sampler={upscale_sampler}, scheduler={upscale_scheduler}, "
|
||||||
|
f"steps={int(upscale_steps)}, denoise={float(upscale_denoise):g}, "
|
||||||
|
f"cfg={float(upscale_cfg):g}, noise_seed={int(upscale_noise_seed)}; "
|
||||||
|
"spatial split supplied by MMH3SpatialSplitParams"
|
||||||
|
)
|
||||||
|
return output, info
|
||||||
|
|
||||||
|
|
||||||
|
NODE_CLASS_MAPPINGS = {
|
||||||
|
"DumasMMH3TiledLatentUpscale": DumasMMH3TiledLatentUpscale,
|
||||||
|
}
|
||||||
|
|
||||||
|
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||||
|
"DumasMMH3TiledLatentUpscale": "Dumas MiniMax-H3 Tiled Latent Upscale",
|
||||||
|
}
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
import importlib.util
|
||||||
|
import sys
|
||||||
|
import types
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
|
class DumasMiniMaxNodeTests(unittest.TestCase):
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
comfy = types.ModuleType("comfy")
|
||||||
|
samplers = types.ModuleType("comfy.samplers")
|
||||||
|
samplers.KSampler = types.SimpleNamespace(
|
||||||
|
SAMPLERS=["euler", "euler_ancestral"],
|
||||||
|
SCHEDULERS=["simple", "beta"],
|
||||||
|
)
|
||||||
|
comfy.samplers = samplers
|
||||||
|
sys.modules.setdefault("comfy", comfy)
|
||||||
|
sys.modules.setdefault("comfy.samplers", samplers)
|
||||||
|
spec = importlib.util.spec_from_file_location("dumas_minimax_nodes", "dumas_minimax_nodes.py")
|
||||||
|
cls.module = importlib.util.module_from_spec(spec)
|
||||||
|
spec.loader.exec_module(cls.module)
|
||||||
|
|
||||||
|
def test_registers_tiled_upscale_node(self):
|
||||||
|
self.assertEqual(set(self.module.NODE_CLASS_MAPPINGS), {"DumasMMH3TiledLatentUpscale"})
|
||||||
|
|
||||||
|
def test_exposes_independent_upscale_controls_and_param_inputs(self):
|
||||||
|
inputs = self.module.DumasMMH3TiledLatentUpscale.INPUT_TYPES()
|
||||||
|
required = inputs["required"]
|
||||||
|
self.assertEqual(required["latent_upscale_param"][0], "H3_UPSCALE_PARAM")
|
||||||
|
self.assertEqual(required["spatial_split_param"][0], "H3_SPATIAL_PARAM")
|
||||||
|
self.assertEqual(required["upscale_steps"][1]["default"], 3)
|
||||||
|
self.assertIn("upscale_noise_seed", required)
|
||||||
|
self.assertEqual(inputs["optional"]["temporal_split_param"][0], "H3_TEMPORAL_PARAM")
|
||||||
|
self.assertIn("upscale_sigmas", inputs["optional"])
|
||||||
|
|
||||||
|
def test_missing_native_node_is_reported(self):
|
||||||
|
original = self.module._native_node
|
||||||
|
self.module._native_node = lambda name: None
|
||||||
|
try:
|
||||||
|
with self.assertRaisesRegex(RuntimeError, "MMH3UltimateUpscale"):
|
||||||
|
self.module.DumasMMH3TiledLatentUpscale().upscale(
|
||||||
|
object(), object(), {"samples": object()}, {}, {},
|
||||||
|
"euler_ancestral", "simple", 3, 0.2, 1.0, 1,
|
||||||
|
)
|
||||||
|
finally:
|
||||||
|
self.module._native_node = original
|
||||||
|
|
||||||
|
def test_calls_native_upscale_with_tiled_params_and_own_schedule(self):
|
||||||
|
calls = {}
|
||||||
|
|
||||||
|
class Noise:
|
||||||
|
def get_noise(self, seed):
|
||||||
|
calls["seed"] = seed
|
||||||
|
return "noise"
|
||||||
|
|
||||||
|
class Sampler:
|
||||||
|
def get_sampler(self, name):
|
||||||
|
calls["sampler"] = name
|
||||||
|
return "sampler"
|
||||||
|
|
||||||
|
class Scheduler:
|
||||||
|
def get_sigmas(self, model, name, steps, denoise):
|
||||||
|
calls["schedule"] = (name, steps, denoise)
|
||||||
|
return "sigmas"
|
||||||
|
|
||||||
|
class Native:
|
||||||
|
def upscale(self, **kwargs):
|
||||||
|
calls["kwargs"] = kwargs
|
||||||
|
return ({"samples": FakeTensor((1, 24, 9, 48, 72))}, {}, {})
|
||||||
|
|
||||||
|
class FakeTensor:
|
||||||
|
def __init__(self, shape):
|
||||||
|
self.shape = shape
|
||||||
|
self.ndim = len(shape)
|
||||||
|
|
||||||
|
original = self.module._native_node
|
||||||
|
mapping = {
|
||||||
|
"MMH3UltimateUpscale": Native,
|
||||||
|
"RandomNoise": Noise,
|
||||||
|
"KSamplerSelect": Sampler,
|
||||||
|
"BasicScheduler": Scheduler,
|
||||||
|
}
|
||||||
|
self.module._native_node = lambda name: mapping[name]
|
||||||
|
try:
|
||||||
|
latent = {"samples": FakeTensor((1, 24, 9, 24, 36))}
|
||||||
|
result, info = self.module.DumasMMH3TiledLatentUpscale().upscale(
|
||||||
|
"model", "conditioning", latent, "upscale", "spatial",
|
||||||
|
"euler_ancestral", "simple", 3, 0.2, 1.0, 123,
|
||||||
|
temporal_split_param="temporal",
|
||||||
|
)
|
||||||
|
self.assertEqual(result["samples"].shape[2], 9)
|
||||||
|
self.assertEqual(calls["seed"], 123)
|
||||||
|
self.assertEqual(calls["schedule"], ("simple", 3, 0.2))
|
||||||
|
self.assertEqual(calls["kwargs"]["spatial_split_param"], "spatial")
|
||||||
|
self.assertEqual(calls["kwargs"]["temporal_split_param"], "temporal")
|
||||||
|
self.assertIn("Dumas tiled MiniMax-H3", info)
|
||||||
|
finally:
|
||||||
|
self.module._native_node = original
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
Reference in New Issue
Block a user