Add DUMAS MiniMax H3 2D spatial upscaler

This commit is contained in:
2026-11-12 08:58:30 +00:00
parent 1871066185
commit 6a899bfacb
5 changed files with 1317 additions and 0 deletions
+10
View File
@@ -85,6 +85,16 @@ current socket types are `H3_UPSCALE_PARAM`, `H3_TEMPORAL_PARAM`, and
`H3_SPATIAL_PARAM`; these are deliberately used unchanged for workflow `H3_SPATIAL_PARAM`; these are deliberately used unchanged for workflow
compatibility. compatibility.
### MiniMax H3 2D spatial latent upscale
`DumasMMH3LatentUpscale2D` supports the `minimax_h3_latent_upscaler_2d_conv_v1`
checkpoint from [LBH-123-AI](https://huggingface.co/LBH-123-AI/Minimax_h3_latent_Upscaler).
It uses the model's published loader and architecture, but keeps DUMAS ownership
of the node and adds X/Y tiling. The full temporal latent is passed through each
tile; temporal splitting is intentionally not used. Put the checkpoint in
`models/latent_upscale_models`, then set `tile_size` and `tile_overlap` to fit
available VRAM.
### DUMAS H3 Sequence Prompt Builder ### DUMAS H3 Sequence Prompt Builder
`DumasH3SequencePromptBuilder` provides the tabbed, timeline-oriented prompt `DumasH3SequencePromptBuilder` provides the tabbed, timeline-oriented prompt
+6
View File
@@ -35,6 +35,10 @@ from .dumas_h3_upscale_nodes import (
NODE_CLASS_MAPPINGS as H3_UPSCALE_NODE_CLASS_MAPPINGS, NODE_CLASS_MAPPINGS as H3_UPSCALE_NODE_CLASS_MAPPINGS,
NODE_DISPLAY_NAME_MAPPINGS as H3_UPSCALE_NODE_DISPLAY_NAME_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS as H3_UPSCALE_NODE_DISPLAY_NAME_MAPPINGS,
) )
from .dumas_h3_latent_upscale_2d import (
NODE_CLASS_MAPPINGS as H3_UPSCALE_2D_NODE_CLASS_MAPPINGS,
NODE_DISPLAY_NAME_MAPPINGS as H3_UPSCALE_2D_NODE_DISPLAY_NAME_MAPPINGS,
)
from .dumas_h3_refmod_nodes import ( from .dumas_h3_refmod_nodes import (
NODE_CLASS_MAPPINGS as H3_REFMOD_NODE_CLASS_MAPPINGS, NODE_CLASS_MAPPINGS as H3_REFMOD_NODE_CLASS_MAPPINGS,
NODE_DISPLAY_NAME_MAPPINGS as H3_REFMOD_NODE_DISPLAY_NAME_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS as H3_REFMOD_NODE_DISPLAY_NAME_MAPPINGS,
@@ -61,6 +65,7 @@ NODE_CLASS_MAPPINGS.update(H3_PROMPT_NODE_CLASS_MAPPINGS)
NODE_CLASS_MAPPINGS.update(REFERENCE_PREPROCESSOR_NODE_CLASS_MAPPINGS) NODE_CLASS_MAPPINGS.update(REFERENCE_PREPROCESSOR_NODE_CLASS_MAPPINGS)
NODE_CLASS_MAPPINGS.update(CLOTHING_LAYOUT_NODE_CLASS_MAPPINGS) NODE_CLASS_MAPPINGS.update(CLOTHING_LAYOUT_NODE_CLASS_MAPPINGS)
NODE_CLASS_MAPPINGS.update(H3_UPSCALE_NODE_CLASS_MAPPINGS) NODE_CLASS_MAPPINGS.update(H3_UPSCALE_NODE_CLASS_MAPPINGS)
NODE_CLASS_MAPPINGS.update(H3_UPSCALE_2D_NODE_CLASS_MAPPINGS)
NODE_CLASS_MAPPINGS.update(H3_REFMOD_NODE_CLASS_MAPPINGS) NODE_CLASS_MAPPINGS.update(H3_REFMOD_NODE_CLASS_MAPPINGS)
NODE_CLASS_MAPPINGS.update(H3_REFMOD_PICKER_NODE_CLASS_MAPPINGS) NODE_CLASS_MAPPINGS.update(H3_REFMOD_PICKER_NODE_CLASS_MAPPINGS)
NODE_CLASS_MAPPINGS.update(RESOLUTION_NODE_CLASS_MAPPINGS) NODE_CLASS_MAPPINGS.update(RESOLUTION_NODE_CLASS_MAPPINGS)
@@ -75,6 +80,7 @@ NODE_DISPLAY_NAME_MAPPINGS.update(H3_PROMPT_NODE_DISPLAY_NAME_MAPPINGS)
NODE_DISPLAY_NAME_MAPPINGS.update(REFERENCE_PREPROCESSOR_DISPLAY_NAME_MAPPINGS) NODE_DISPLAY_NAME_MAPPINGS.update(REFERENCE_PREPROCESSOR_DISPLAY_NAME_MAPPINGS)
NODE_DISPLAY_NAME_MAPPINGS.update(CLOTHING_LAYOUT_DISPLAY_NAME_MAPPINGS) NODE_DISPLAY_NAME_MAPPINGS.update(CLOTHING_LAYOUT_DISPLAY_NAME_MAPPINGS)
NODE_DISPLAY_NAME_MAPPINGS.update(H3_UPSCALE_NODE_DISPLAY_NAME_MAPPINGS) NODE_DISPLAY_NAME_MAPPINGS.update(H3_UPSCALE_NODE_DISPLAY_NAME_MAPPINGS)
NODE_DISPLAY_NAME_MAPPINGS.update(H3_UPSCALE_2D_NODE_DISPLAY_NAME_MAPPINGS)
NODE_DISPLAY_NAME_MAPPINGS.update(H3_REFMOD_NODE_DISPLAY_NAME_MAPPINGS) NODE_DISPLAY_NAME_MAPPINGS.update(H3_REFMOD_NODE_DISPLAY_NAME_MAPPINGS)
NODE_DISPLAY_NAME_MAPPINGS.update(H3_REFMOD_PICKER_NODE_DISPLAY_NAME_MAPPINGS) NODE_DISPLAY_NAME_MAPPINGS.update(H3_REFMOD_PICKER_NODE_DISPLAY_NAME_MAPPINGS)
NODE_DISPLAY_NAME_MAPPINGS.update(RESOLUTION_NODE_DISPLAY_NAME_MAPPINGS) NODE_DISPLAY_NAME_MAPPINGS.update(RESOLUTION_NODE_DISPLAY_NAME_MAPPINGS)
+119
View File
@@ -0,0 +1,119 @@
"""DUMAS spatially tiled wrapper for the MiniMax H3 2D latent upscaler.
The model implementation and checkpoint loader are vendored from the Apache-2.0
licensed LBH-123-AI ComfyUI node. DUMAS owns the workflow node and adds spatial
tiling; time is always processed as one sequence.
"""
def _upscaler_module():
try:
from .vendor import minimax_h3_latent_upscaler_2d as module
except ImportError:
from vendor import minimax_h3_latent_upscaler_2d as module
return module
class DumasMMH3LatentUpscale2D:
"""Apply the MiniMax H3 2D upscaler using X/Y tiles only."""
@classmethod
def INPUT_TYPES(cls):
import folder_paths
names = [
name for name in folder_paths.get_filename_list("latent_upscale_models")
if str(name).lower().endswith((".safetensors", ".pth"))
]
return {
"required": {
"latent": ("LATENT",),
"model_name": (names or ["(place model in models/latent_upscale_models)"],),
"scale": ("FLOAT", {"default": 2.0, "min": 1.0, "max": 4.0, "step": 0.05}),
"tile_size": ("INT", {"default": 64, "min": 8, "max": 1024, "step": 8}),
"tile_overlap": ("INT", {"default": 8, "min": 0, "max": 128, "step": 1}),
"sharpness": ("INT", {"default": 1, "min": 1, "max": 6, "step": 1}),
"device": (["cuda", "rocm", "cpu"], {"default": "cuda"}),
"precision": (["fp32", "fp16", "bf16"], {"default": "fp16"}),
}
}
RETURN_TYPES = ("LATENT", "STRING")
RETURN_NAMES = ("upscaled_latent", "info")
FUNCTION = "upscale"
CATEGORY = "Dumas/MiniMax H3/Upscale"
@staticmethod
def _ranges(length, tile, overlap):
step = tile - overlap
if step <= 0:
raise ValueError("tile_overlap must be smaller than tile_size")
starts = list(range(0, max(1, length - tile + 1), step))
if not starts or starts[-1] + tile < length:
starts.append(max(0, length - tile))
return [(start, min(length, start + tile)) for start in sorted(set(starts))]
def upscale(self, latent, model_name, scale, tile_size, tile_overlap, sharpness,
device, precision):
import torch
if str(model_name).startswith("("):
raise ValueError("Place the 2D H3 model in models/latent_upscale_models")
source = latent.get("samples") if isinstance(latent, dict) else None
if source is None or source.ndim != 5:
raise ValueError("DUMAS H3 2D upscale expects a 5-D latent: B,C,T,H,W")
if source.shape[1] != 24:
raise ValueError(f"MiniMax H3 latents must have 24 channels, got {source.shape[1]}")
module = _upscaler_module()
dev = module._resolve_device(device)
compute_dtype = {"fp32": torch.float32, "fp16": torch.float16,
"bf16": torch.bfloat16}[precision]
model = module.load_model(model_name, dev, precision)
mean, std = module._make_norm_tensors(dev, compute_dtype)
src = source.to(device=dev, dtype=compute_dtype, copy=True)
b, c, t, h, w = src.shape
out_h, out_w = int(round(h * float(scale))), int(round(w * float(scale)))
if out_h == h and out_w == w:
return latent, "DUMAS H3 2D upscale skipped: scale is 1"
result = torch.zeros((b, c, t, out_h, out_w), device=dev, dtype=compute_dtype)
weights = torch.zeros((1, 1, 1, out_h, out_w), device=dev, dtype=compute_dtype)
ys = self._ranges(h, int(tile_size), int(tile_overlap))
xs = self._ranges(w, int(tile_size), int(tile_overlap))
with torch.inference_mode():
for y0, y1 in ys:
for x0, x1 in xs:
yi0, yi1 = max(0, y0 - tile_overlap), min(h, y1 + tile_overlap)
xi0, xi1 = max(0, x0 - tile_overlap), min(w, x1 + tile_overlap)
tile = (src[:, :, :, yi0:yi1, xi0:xi1] - mean) / std
tile_out = model(
tile, scale=float(scale),
target_hw=(int(round((yi1 - yi0) * scale)),
int(round((xi1 - xi0) * scale))),
enable_chunking=False,
tier=(int(sharpness) if getattr(model.resizer, "tier_dim", 0) else None),
)
oy0, oy1 = int(round((y0 - yi0) * scale)), int(round((y1 - yi0) * scale))
ox0, ox1 = int(round((x0 - xi0) * scale)), int(round((x1 - xi0) * scale))
dy0, dy1 = int(round(y0 * scale)), int(round(y1 * scale))
dx0, dx1 = int(round(x0 * scale)), int(round(x1 * scale))
result[:, :, :, dy0:dy1, dx0:dx1] += tile_out[:, :, :, oy0:oy1, ox0:ox1]
weights[:, :, :, dy0:dy1, dx0:dx1] += 1
del tile, tile_out
out = (result / weights.clamp_min(1) * std + mean).to("cpu", dtype=source.dtype)
if dev.type in ("cuda", "mps"):
model.to("cpu")
if dev.type == "cuda":
torch.cuda.empty_cache()
return {"samples": out}, (
f"DUMAS H3 2D spatial upscale: {h}x{w} -> {out_h}x{out_w}; "
f"tiles={len(ys) * len(xs)}, tile={tile_size}, overlap={tile_overlap}, "
f"time=single-pass, sharpness={sharpness}"
)
NODE_CLASS_MAPPINGS = {"DumasMMH3LatentUpscale2D": DumasMMH3LatentUpscale2D}
NODE_DISPLAY_NAME_MAPPINGS = {
"DumasMMH3LatentUpscale2D": "DUMAS MiniMax-H3 2D Spatial Latent Upscale",
}
+29
View File
@@ -0,0 +1,29 @@
import importlib.util
import pathlib
import unittest
ROOT = pathlib.Path(__file__).parents[1]
spec = importlib.util.spec_from_file_location(
"dumas_h3_latent_upscale_2d_test", ROOT / "dumas_h3_latent_upscale_2d.py"
)
module = importlib.util.module_from_spec(spec)
assert spec.loader is not None
spec.loader.exec_module(module)
class H3LatentUpscale2DTests(unittest.TestCase):
def test_ranges_cover_dimension_without_overlap_gap(self):
ranges = module.DumasMMH3LatentUpscale2D._ranges(150, 64, 8)
self.assertEqual(ranges[0], (0, 64))
self.assertEqual(ranges[-1], (86, 150))
for (_, end), (start, _) in zip(ranges, ranges[1:]):
self.assertLessEqual(start, end)
def test_rejects_overlap_equal_to_tile(self):
with self.assertRaises(ValueError):
module.DumasMMH3LatentUpscale2D._ranges(64, 32, 32)
if __name__ == "__main__":
unittest.main()
File diff suppressed because it is too large Load Diff