From c89570eae999133fb678cc8eb4a9e2da3f9fa356 Mon Sep 17 00:00:00 2001 From: Chris Dumas Date: Thu, 3 Sep 2026 15:35:39 +0000 Subject: [PATCH] Expand latent upscale spatial stitch controls --- H3_LONG_VIDEOS_GUIDE.md | 2 ++ README.md | 2 +- dumas_h3_latent_upscale.py | 6 +++++- dumas_h3_longvideos.py | 22 ++++++++++++++++------ tests/test_dumas_h3_longvideos.py | 1 + 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/H3_LONG_VIDEOS_GUIDE.md b/H3_LONG_VIDEOS_GUIDE.md index b1bc515..a0f4b93 100644 --- a/H3_LONG_VIDEOS_GUIDE.md +++ b/H3_LONG_VIDEOS_GUIDE.md @@ -1164,6 +1164,7 @@ What this really means: - the conditioning is rebuilt at that target size - the node then runs a short refinement pass over the upscaled latent with the sampler, scheduler, step count, denoise, and megapixel target you picked on the latent-upscale params node - if the target is larger than the spatial tile size, that refinement pass is processed in spatial batches using the same tile defaults as the upstream latent-split node +- the spatial stitch mode follows the upstream overlap controls, including `linear`, `smoothstep`, `overwrite`, and `midpoint` Good starting point: @@ -1172,6 +1173,7 @@ Good starting point: - start with `euler_ancestral`, `simple`, `2` steps, and `0.2` denoise - leave width and height at `0` unless you want an exact override; otherwise `megapixels` drives the target size - leave the spatial tile inputs at their defaults first: `512x512` tiles, `64` overlap, `0` fade width, `earlier` overlap mode +- keep `linear` blend first unless you want to reproduce a specific upstream stitch style The important part is that this stage is still a latent pass, not a pixel-space resize: diff --git a/README.md b/README.md index a61be42..cc39144 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ - Per-shot directives now support `continuity:`, `ref_mode:`, `ref_noise_aug:`, `anchor_add:`, `soundscape:`, and `music:` in addition to the existing timing and wardrobe directives. - `Dumas H3 Latent Upscale Params` - - Inputs: `mode`, `model_name`, `method`, `width`, `height`, `device`, `precision`, `sampler_name`, `scheduler`, `steps`, `denoise`, `megapixels`, `tile_width`, `tile_height`, `overlap`, `fade_width`, `overlap_mode` + - Inputs: `mode`, `model_name`, `method`, `width`, `height`, `device`, `precision`, `sampler_name`, `scheduler`, `steps`, `denoise`, `megapixels`, `tile_width`, `tile_height`, `overlap`, `fade_width`, `overlap_mode`, `overlap_blend` - Output: `latent_upscale_param` - Bundles the optional latent-space upscaler settings used by `Dumas H3 Long Videos` before decode, so the main node can rebuild conditioning at the target size and run a short refinement pass with your chosen sampler, scheduler, step count, denoise, and optional spatial batching. diff --git a/dumas_h3_latent_upscale.py b/dumas_h3_latent_upscale.py index 468653f..b9c9718 100644 --- a/dumas_h3_latent_upscale.py +++ b/dumas_h3_latent_upscale.py @@ -473,10 +473,12 @@ class H3LatentUpscaleParams: "tooltip": "Width in pixels of the freeze-to-free transition inside each overlap strip. 0 freezes the whole strip, matching the upstream default."}), "overlap_mode": (["earlier", "later"], {"default": "earlier", "tooltip": "Which tile wins the overlap band when stitching the spatial batches back together."}), + "overlap_blend": (["linear", "smoothstep", "overwrite", "midpoint"], {"default": "linear", + "tooltip": "How overlap bands are blended when the spatial batches are stitched back together."}), } } - def build(self, mode, model_name, method, width, height, device, precision, sampler_name, scheduler, steps, denoise, megapixels, tile_width, tile_height, overlap, fade_width, overlap_mode): + def build(self, mode, model_name, method, width, height, device, precision, sampler_name, scheduler, steps, denoise, megapixels, tile_width, tile_height, overlap, fade_width, overlap_mode, overlap_blend): width = int(width) height = int(height) steps = int(steps) @@ -500,6 +502,7 @@ class H3LatentUpscaleParams: "overlap": overlap, "fade_width": fade_width, "overlap_mode": overlap_mode, + "overlap_blend": overlap_blend, },) if width > 0: width = int(round(width / 32.0)) * 32 @@ -524,6 +527,7 @@ class H3LatentUpscaleParams: "overlap": overlap, "fade_width": fade_width, "overlap_mode": overlap_mode, + "overlap_blend": overlap_blend, },) diff --git a/dumas_h3_longvideos.py b/dumas_h3_longvideos.py index c3ee305..98826b4 100644 --- a/dumas_h3_longvideos.py +++ b/dumas_h3_longvideos.py @@ -4104,10 +4104,18 @@ def _latent_spatial_grid(h, w, th, tw, ol_h, ol_w): return rows, cols, trows, tcols -def _latent_spatial_blend_weights(t, overlap_mode): +def _latent_spatial_blend_weights(t, overlap_mode, overlap_blend="linear"): + if overlap_blend == "overwrite": + return torch.ones_like(t) if overlap_mode == "later" else torch.zeros_like(t) + if overlap_blend == "midpoint": + base = (t >= 0.5).to(t.dtype) + elif overlap_blend == "smoothstep": + base = t * t * (3.0 - 2.0 * t) + else: + base = t if overlap_mode == "later": - return 1.0 - t - return t + return base + return 1.0 - base def _nested_tensor_parts(samples): @@ -6510,6 +6518,7 @@ class H3LongVideos: overlap_px = max(0, int(latent_upscale_param.get("overlap", 64) or 64)) fade_px = max(0, int(latent_upscale_param.get("fade_width", 0) or 0)) overlap_mode = str(latent_upscale_param.get("overlap_mode", "earlier")) + overlap_blend = str(latent_upscale_param.get("overlap_blend", "linear")) tile_tw = max(1, min(int(up_w), max(1, tile_w_px // 16))) tile_th = max(1, min(int(up_h), max(1, tile_h_px // 16))) ol_tw = max(0, min(tile_tw - 1, overlap_px // 16)) @@ -6548,7 +6557,7 @@ class H3LongVideos: region.copy_(tile_video_out) if col_index > 0 and ol_tw > 0: t = torch.linspace(0.0, 1.0, ol_tw, device=region.device, dtype=region.dtype) - w = _latent_spatial_blend_weights(t, overlap_mode) + w = _latent_spatial_blend_weights(t, overlap_mode, overlap_blend) if fw_tw > 0: w = w.clone() w[:fw_tw] = 0.0 @@ -6558,7 +6567,7 @@ class H3LongVideos: ) if row_index > 0 and ol_th > 0: t = torch.linspace(0.0, 1.0, ol_th, device=region.device, dtype=region.dtype) - w = _latent_spatial_blend_weights(t, overlap_mode) + w = _latent_spatial_blend_weights(t, overlap_mode, overlap_blend) if fw_th > 0: w = w.clone() w[:fw_th] = 0.0 @@ -6707,8 +6716,9 @@ class H3LongVideos: tile_w_px = int(latent_upscale_param.get("tile_width", 512) or 512) tile_h_px = int(latent_upscale_param.get("tile_height", 512) or 512) overlap_px = max(0, int(latent_upscale_param.get("overlap", 64) or 64)) + overlap_blend = str(latent_upscale_param.get("overlap_blend", "linear")) if tile_w_px > 0 and tile_h_px > 0 and (tile_w_px < target_w or tile_h_px < target_h): - batch_note = f"; spatial batches {tile_w_px}x{tile_h_px}px overlap {overlap_px}px" + batch_note = f"; spatial batches {tile_w_px}x{tile_h_px}px overlap {overlap_px}px {overlap_blend}" latent_upscale_note = ( f" latent upscale: target {target_w}x{target_h}px{detail}; " f"{int(latent_upscale_param.get('steps', 2) or 2)}-step refinement " diff --git a/tests/test_dumas_h3_longvideos.py b/tests/test_dumas_h3_longvideos.py index 05da580..aaba18d 100644 --- a/tests/test_dumas_h3_longvideos.py +++ b/tests/test_dumas_h3_longvideos.py @@ -1132,6 +1132,7 @@ class DumasH3LongVideosHelperTests(unittest.TestCase): self.assertEqual(required["overlap"][1]["default"], 64) self.assertEqual(required["fade_width"][1]["default"], 0) self.assertEqual(required["overlap_mode"][1]["default"], "earlier") + self.assertEqual(required["overlap_blend"][1]["default"], "linear") def test_compose_persistent_does_not_expand_ambiguous_plural_to_full_cast(self): active = self.module.parse_wardrobe(