Use target dimensions for 2D H3 upscale
This commit is contained in:
@@ -92,8 +92,9 @@ checkpoint from [LBH-123-AI](https://huggingface.co/LBH-123-AI/Minimax_h3_latent
|
|||||||
It uses the model's published loader and architecture, but keeps DUMAS ownership
|
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
|
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
|
tile; temporal splitting is intentionally not used. Put the checkpoint in
|
||||||
`models/latent_upscale_models`, then set `tile_size` and `tile_overlap` to fit
|
`models/latent_upscale_models`, then set the target `width` and `height` in
|
||||||
available VRAM.
|
pixels. The dimensions are converted to H3 latent dimensions internally. Set
|
||||||
|
`tile_size` and `tile_overlap` to fit available VRAM.
|
||||||
|
|
||||||
`DumasMMH3LatentUpscale2DModelParams` is the matching parameter node. Its output
|
`DumasMMH3LatentUpscale2DModelParams` is the matching parameter node. Its output
|
||||||
is `latent_upscale_param` with type `H3_UPSCALE_PARAM`, so it connects to the
|
is `latent_upscale_param` with type `H3_UPSCALE_PARAM`, so it connects to the
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ class DumasMMH3LatentUpscale2DModelParams:
|
|||||||
"model_name": (names or ["(place model in models/latent_upscale_models)"],),
|
"model_name": (names or ["(place model in models/latent_upscale_models)"],),
|
||||||
"device": (["cuda", "rocm", "cpu"], {"default": "cuda"}),
|
"device": (["cuda", "rocm", "cpu"], {"default": "cuda"}),
|
||||||
"precision": (["fp32", "fp16", "bf16"], {"default": "fp16"}),
|
"precision": (["fp32", "fp16", "bf16"], {"default": "fp16"}),
|
||||||
"scale": ("FLOAT", {"default": 2.0, "min": 1.0, "max": 4.0, "step": 0.05}),
|
"width": ("INT", {"default": 1280, "min": 16, "max": 16384, "step": 16}),
|
||||||
|
"height": ("INT", {"default": 704, "min": 16, "max": 16384, "step": 16}),
|
||||||
"tile_size": ("INT", {"default": 64, "min": 8, "max": 1024, "step": 8}),
|
"tile_size": ("INT", {"default": 64, "min": 8, "max": 1024, "step": 8}),
|
||||||
"tile_overlap": ("INT", {"default": 8, "min": 0, "max": 128, "step": 1}),
|
"tile_overlap": ("INT", {"default": 8, "min": 0, "max": 128, "step": 1}),
|
||||||
"sharpness": ("INT", {"default": 1, "min": 1, "max": 6, "step": 1}),
|
"sharpness": ("INT", {"default": 1, "min": 1, "max": 6, "step": 1}),
|
||||||
@@ -40,7 +41,7 @@ class DumasMMH3LatentUpscale2DModelParams:
|
|||||||
FUNCTION = "build"
|
FUNCTION = "build"
|
||||||
CATEGORY = "Dumas/MiniMax H3/Upscale"
|
CATEGORY = "Dumas/MiniMax H3/Upscale"
|
||||||
|
|
||||||
def build(self, model_name, device, precision, scale, tile_size, tile_overlap, sharpness):
|
def build(self, model_name, device, precision, width, height, tile_size, tile_overlap, sharpness):
|
||||||
if str(model_name).startswith("("):
|
if str(model_name).startswith("("):
|
||||||
raise ValueError("Place the 2D H3 model in models/latent_upscale_models")
|
raise ValueError("Place the 2D H3 model in models/latent_upscale_models")
|
||||||
return ({
|
return ({
|
||||||
@@ -48,7 +49,8 @@ class DumasMMH3LatentUpscale2DModelParams:
|
|||||||
"model_name": str(model_name),
|
"model_name": str(model_name),
|
||||||
"device": str(device),
|
"device": str(device),
|
||||||
"precision": str(precision),
|
"precision": str(precision),
|
||||||
"scale": float(scale),
|
"target_width": int(width),
|
||||||
|
"target_height": int(height),
|
||||||
"tile_size": int(tile_size),
|
"tile_size": int(tile_size),
|
||||||
"tile_overlap": int(tile_overlap),
|
"tile_overlap": int(tile_overlap),
|
||||||
"sharpness": int(sharpness),
|
"sharpness": int(sharpness),
|
||||||
@@ -70,7 +72,8 @@ class DumasMMH3LatentUpscale2D:
|
|||||||
"required": {
|
"required": {
|
||||||
"latent": ("LATENT",),
|
"latent": ("LATENT",),
|
||||||
"model_name": (names or ["(place model in models/latent_upscale_models)"],),
|
"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}),
|
"width": ("INT", {"default": 1280, "min": 16, "max": 16384, "step": 16}),
|
||||||
|
"height": ("INT", {"default": 704, "min": 16, "max": 16384, "step": 16}),
|
||||||
"tile_size": ("INT", {"default": 64, "min": 8, "max": 1024, "step": 8}),
|
"tile_size": ("INT", {"default": 64, "min": 8, "max": 1024, "step": 8}),
|
||||||
"tile_overlap": ("INT", {"default": 8, "min": 0, "max": 128, "step": 1}),
|
"tile_overlap": ("INT", {"default": 8, "min": 0, "max": 128, "step": 1}),
|
||||||
"sharpness": ("INT", {"default": 1, "min": 1, "max": 6, "step": 1}),
|
"sharpness": ("INT", {"default": 1, "min": 1, "max": 6, "step": 1}),
|
||||||
@@ -94,7 +97,7 @@ class DumasMMH3LatentUpscale2D:
|
|||||||
starts.append(max(0, length - tile))
|
starts.append(max(0, length - tile))
|
||||||
return [(start, min(length, start + tile)) for start in sorted(set(starts))]
|
return [(start, min(length, start + tile)) for start in sorted(set(starts))]
|
||||||
|
|
||||||
def upscale(self, latent, model_name, scale, tile_size, tile_overlap, sharpness,
|
def upscale(self, latent, model_name, width, height, tile_size, tile_overlap, sharpness,
|
||||||
device, precision):
|
device, precision):
|
||||||
import torch
|
import torch
|
||||||
|
|
||||||
@@ -114,9 +117,13 @@ class DumasMMH3LatentUpscale2D:
|
|||||||
mean, std = module._make_norm_tensors(dev, compute_dtype)
|
mean, std = module._make_norm_tensors(dev, compute_dtype)
|
||||||
src = source.to(device=dev, dtype=compute_dtype, copy=True)
|
src = source.to(device=dev, dtype=compute_dtype, copy=True)
|
||||||
b, c, t, h, w = src.shape
|
b, c, t, h, w = src.shape
|
||||||
out_h, out_w = int(round(h * float(scale))), int(round(w * float(scale)))
|
if int(width) % 16 or int(height) % 16:
|
||||||
|
raise ValueError("Target width and height must be divisible by 16")
|
||||||
|
out_w, out_h = int(width) // 16, int(height) // 16
|
||||||
|
if out_h < h or out_w < w:
|
||||||
|
raise ValueError("Target dimensions must be at least as large as the input")
|
||||||
if out_h == h and out_w == w:
|
if out_h == h and out_w == w:
|
||||||
return latent, "DUMAS H3 2D upscale skipped: scale is 1"
|
return latent, "DUMAS H3 2D upscale skipped: target dimensions equal input"
|
||||||
|
|
||||||
result = torch.zeros((b, c, t, out_h, out_w), device=dev, dtype=compute_dtype)
|
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)
|
weights = torch.zeros((1, 1, 1, out_h, out_w), device=dev, dtype=compute_dtype)
|
||||||
@@ -129,16 +136,17 @@ class DumasMMH3LatentUpscale2D:
|
|||||||
xi0, xi1 = max(0, x0 - tile_overlap), min(w, x1 + tile_overlap)
|
xi0, xi1 = max(0, x0 - tile_overlap), min(w, x1 + tile_overlap)
|
||||||
tile = (src[:, :, :, yi0:yi1, xi0:xi1] - mean) / std
|
tile = (src[:, :, :, yi0:yi1, xi0:xi1] - mean) / std
|
||||||
tile_out = model(
|
tile_out = model(
|
||||||
tile, scale=float(scale),
|
tile, scale=1.0,
|
||||||
target_hw=(int(round((yi1 - yi0) * scale)),
|
target_hw=(int(round((yi1 - yi0) * out_h / h)),
|
||||||
int(round((xi1 - xi0) * scale))),
|
int(round((xi1 - xi0) * out_w / w))),
|
||||||
enable_chunking=False,
|
enable_chunking=False,
|
||||||
tier=(int(sharpness) if getattr(model.resizer, "tier_dim", 0) else None),
|
tier=(int(sharpness) if getattr(model.resizer, "tier_dim", 0) else None),
|
||||||
)
|
)
|
||||||
oy0, oy1 = int(round((y0 - yi0) * scale)), int(round((y1 - yi0) * scale))
|
sy, sx = out_h / h, out_w / w
|
||||||
ox0, ox1 = int(round((x0 - xi0) * scale)), int(round((x1 - xi0) * scale))
|
oy0, oy1 = int(round((y0 - yi0) * sy)), int(round((y1 - yi0) * sy))
|
||||||
dy0, dy1 = int(round(y0 * scale)), int(round(y1 * scale))
|
ox0, ox1 = int(round((x0 - xi0) * sx)), int(round((x1 - xi0) * sx))
|
||||||
dx0, dx1 = int(round(x0 * scale)), int(round(x1 * scale))
|
dy0, dy1 = int(round(y0 * sy)), int(round(y1 * sy))
|
||||||
|
dx0, dx1 = int(round(x0 * sx)), int(round(x1 * sx))
|
||||||
result[:, :, :, dy0:dy1, dx0:dx1] += tile_out[:, :, :, oy0:oy1, ox0:ox1]
|
result[:, :, :, dy0:dy1, dx0:dx1] += tile_out[:, :, :, oy0:oy1, ox0:ox1]
|
||||||
weights[:, :, :, dy0:dy1, dx0:dx1] += 1
|
weights[:, :, :, dy0:dy1, dx0:dx1] += 1
|
||||||
del tile, tile_out
|
del tile, tile_out
|
||||||
@@ -148,7 +156,7 @@ class DumasMMH3LatentUpscale2D:
|
|||||||
if dev.type == "cuda":
|
if dev.type == "cuda":
|
||||||
torch.cuda.empty_cache()
|
torch.cuda.empty_cache()
|
||||||
return {"samples": out}, (
|
return {"samples": out}, (
|
||||||
f"DUMAS H3 2D spatial upscale: {h}x{w} -> {out_h}x{out_w}; "
|
f"DUMAS H3 2D spatial upscale: {w * 16}x{h * 16} -> {int(width)}x{int(height)}; "
|
||||||
f"tiles={len(ys) * len(xs)}, tile={tile_size}, overlap={tile_overlap}, "
|
f"tiles={len(ys) * len(xs)}, tile={tile_size}, overlap={tile_overlap}, "
|
||||||
f"time=single-pass, sharpness={sharpness}"
|
f"time=single-pass, sharpness={sharpness}"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -338,7 +338,8 @@ class DumasH3ContinuumTiledLatentUpscalePerClip:
|
|||||||
upscaled, report = processor.upscale(
|
upscaled, report = processor.upscale(
|
||||||
{"samples": samples},
|
{"samples": samples},
|
||||||
model_name=upscale_param["model_name"],
|
model_name=upscale_param["model_name"],
|
||||||
scale=upscale_param["scale"],
|
width=upscale_param["target_width"],
|
||||||
|
height=upscale_param["target_height"],
|
||||||
tile_size=upscale_param["tile_size"],
|
tile_size=upscale_param["tile_size"],
|
||||||
tile_overlap=upscale_param["tile_overlap"],
|
tile_overlap=upscale_param["tile_overlap"],
|
||||||
sharpness=upscale_param["sharpness"],
|
sharpness=upscale_param["sharpness"],
|
||||||
|
|||||||
Reference in New Issue
Block a user