Integrate tiled upscale into Continuum second pass
tests / test (push) Canceled after 0s
tests / windows-storage (push) Canceled after 0s

This commit is contained in:
2026-10-14 15:17:09 +00:00
parent 39e6734ff4
commit 4a969bf909
3 changed files with 198 additions and 21 deletions
+10
View File
@@ -17,6 +17,16 @@ context-to-conditioning adaptation as **H3 Continuum Conditioning Bridge V3.5**.
The separate `conditioning` input is optional for advanced legacy graphs; it is
not needed in the normal Continuum wiring.
The recommended production wiring is now the **H3 Continuum Second Pass V3.5**
node with `tiled_upscale = true`. That node receives the main sampler's video
and audio latent lists plus its `refine_context` and `assembly_plan`, rebuilds a
complete AV latent for each physical group, and runs the native tiled upscale
one group at a time. It returns the upscaled video latent list while preserving
the first-pass audio latent list. Connect the latent-upscale and spatial-split
parameter nodes to its optional tiled inputs; its sampler, scheduler, steps,
denoise, CFG and noise seed are independent from the ordinary Second Pass
settings.
The node is an adapter around ComfyUI's native MiniMax H3 tiled-upscale
implementation; it does not include model weights or vendor the upstream
implementation. Install this repository as a normal custom-node folder and
+94 -21
View File
@@ -29,6 +29,7 @@ from .refine_schedule import (
serializable_schedule_contract,
)
from .refine_sampling import sample_refine_chunk
from .tiled_latent_upscale_nodes import _call_native
class SecondPassContractError(ValueError):
@@ -457,6 +458,7 @@ def run_second_pass_groups(
refine_schedule: RefineSchedule | None = None,
selected_group_indices: Sequence[int] | None = None,
temporal_windows_by_group: Mapping[int, Any] | None = None,
tiled_upscale_config: Mapping[str, Any] | None = None,
) -> tuple[list[dict[str, Any]], list[Any], dict[str, Any], str]:
"""Refine complete physical groups while preserving first-pass audio exactly."""
@@ -501,6 +503,7 @@ def run_second_pass_groups(
context_frames = int(detail["context_frames"])
physical_seed = derive_refine_seed(int(refine_seed), group_index)
group_seeds.append(physical_seed)
upscale_seed = None
conditioning_sources.append(conditioning_source)
route_record = detail.get("reference_routing_v1")
inheritance = (
@@ -514,27 +517,69 @@ def run_second_pass_groups(
"contract_sha256": route_record.get("sha256") if route_record is not None else None,
})
nested_latent = latent_builder(video_samples, audio_samples)
sample_arguments = dict(
model=chunk_model,
conditioning=conditioning,
latent=nested_latent,
sampler=sampler,
sigmas=effective_sigmas,
seed=physical_seed,
enable_preview=bool(enable_preview),
)
if temporal_windows_by_group is not None:
temporal_window = temporal_windows_by_group.get(group_index)
if temporal_window is None:
raise SecondPassContractError(
f"selected physical group {group_index + 1} has no temporal window"
if tiled_upscale_config is None:
sample_arguments = dict(
model=chunk_model,
conditioning=conditioning,
latent=nested_latent,
sampler=sampler,
sigmas=effective_sigmas,
seed=physical_seed,
enable_preview=bool(enable_preview),
)
if temporal_windows_by_group is not None:
temporal_window = temporal_windows_by_group.get(group_index)
if temporal_window is None:
raise SecondPassContractError(
f"selected physical group {group_index + 1} has no temporal window"
)
sample_arguments["temporal_window"] = temporal_window
sampled = sample_fn(**sample_arguments)
else:
config = tiled_upscale_config
native = config["native"]
upscale_seed = derive_refine_seed(
int(config.get("seed_base", physical_seed)), group_index
)
noise = config["random_noise"]().get_noise(upscale_seed)
upscale_sampler = config["sampler"]
upscale_sigmas = config.get("sigmas")
if upscale_sigmas is None:
upscale_sigmas = config["scheduler"]().get_sigmas(
chunk_model,
config["scheduler_name"],
config["steps"],
config["denoise"],
)
sample_arguments["temporal_window"] = temporal_window
sampled = sample_fn(**sample_arguments)
native_kwargs = {
"model": chunk_model,
"conditioning": conditioning,
"latent": nested_latent,
"noise": noise,
"sampler": upscale_sampler,
"sigmas": upscale_sigmas,
"cfg": config["cfg"],
"latent_upscale_param": config["latent_upscale_param"],
"temporal_split_param": config.get("temporal_split_param"),
"spatial_split_param": config["spatial_split_param"],
}
if config.get("negative") is not None:
native_kwargs["negative"] = config["negative"]
native_result = _call_native(native, native_kwargs)
if not isinstance(native_result, (tuple, list)) or not native_result:
raise SecondPassContractError(
f"tiled upscale returned no output for physical group {group_index + 1}"
)
sampled = native_result[0]
refined_video, _temporary_audio = stream_extractor(sampled)
if tuple(refined_video.shape) != tuple(video_samples.shape):
if tiled_upscale_config is None:
if tuple(refined_video.shape) != tuple(video_samples.shape):
raise SecondPassContractError(
f"refined video group {group_index} changed B/C/T/H/W geometry"
)
elif tuple(refined_video.shape[:3]) != tuple(video_samples.shape[:3]):
raise SecondPassContractError(
f"refined video group {group_index} changed B/C/T/H/W geometry"
f"tiled upscale group {group_index} changed B/C/T geometry"
)
if not bool(torch.isfinite(refined_video.float()).all().item()):
raise SecondPassContractError(
@@ -554,8 +599,11 @@ def run_second_pass_groups(
f"reference_inheritance={inheritance}, "
f"physical_clip_index={physical_clip_index}, "
f"context_frames={context_frames}, "
f"refine_seed={physical_seed}, shape={tuple(refined_video.shape)}, "
"sampling_passes=1, temporary_audio_discarded=true"
f"refine_seed={physical_seed}, "
f"upscale_seed={upscale_seed if upscale_seed is not None else 'n/a'}, "
f"shape={tuple(refined_video.shape)}, "
f"sampling_passes=1, tiled_upscale={tiled_upscale_config is not None}, "
"temporary_audio_discarded=true"
)
if adaptation_stats is not None:
group_report_lines.append(
@@ -619,11 +667,36 @@ def run_second_pass_groups(
passthrough_audio = passthrough_audio_latents(audio_latents)
updated_plan = prepared["updated_assembly_plan"]
if tiled_upscale_config is not None:
if selection_active:
raise SecondPassContractError(
"tiled upscale mode requires all physical groups; selective tiled "
"upscale would produce mixed output geometry"
)
output_samples = _latent_samples(
refined_videos[0], name="tiled refined video group 0"
)
target_height = int(output_samples.shape[-2]) * 16
target_width = int(output_samples.shape[-1]) * 16
updated_plan = copy.deepcopy(updated_plan)
updated_plan["height"] = target_height
updated_plan["width"] = target_width
updated_plan["second_pass_contract"]["target_height"] = target_height
updated_plan["second_pass_contract"]["target_width"] = target_width
for group in updated_plan["second_pass_contract"]["physical_groups"]:
group["target_latent_h"] = int(output_samples.shape[-2])
group["target_latent_w"] = int(output_samples.shape[-1])
group["target_height"] = target_height
group["target_width"] = target_width
contract = updated_plan["second_pass_contract"]
if conditioning_sources and all(
source == "refine_context" for source in conditioning_sources
):
contract["execution"] = "context_aware_physical_groups_audio_locked_v3"
contract["execution"] = (
"context_aware_physical_groups_tiled_upscale_audio_locked_v1"
if tiled_upscale_config is not None
else "context_aware_physical_groups_audio_locked_v3"
)
elif any(source == "refine_context" for source in conditioning_sources):
contract["execution"] = "mixed_context_physical_groups_audio_locked_v3"
else:
+94
View File
@@ -49,6 +49,22 @@ def _single_list_input(name: str, value: Any) -> Any:
return value[0]
def _sampler_options():
try:
import comfy.samplers
return list(comfy.samplers.KSampler.SAMPLERS)
except Exception:
return ["euler", "euler_ancestral", "res_multistep", "sa_solver"]
def _scheduler_options():
try:
import comfy.samplers
return list(comfy.samplers.KSampler.SCHEDULERS)
except Exception:
return ["simple", "beta", "sgm_uniform", "karras", "exponential"]
class H3ContinuumSecondPassV35:
"""Low-sigma refinement over complete physical decode groups."""
@@ -83,10 +99,28 @@ class H3ContinuumSecondPassV35:
"tooltip": "Base seed independently derived once per physical group.",
},
),
"tiled_upscale": (
"BOOLEAN",
{
"default": False,
"tooltip": "Use native tiled H3 latent upscale instead of the low-sigma refine pass.",
},
),
},
"optional": {
"refine_context": ("H3_CONTINUUM_REFINE_CONTEXT",),
"video_vae": ("VAE",),
"latent_upscale_param": ("H3_UPSCALE_PARAM",),
"spatial_split_param": ("H3_SPATIAL_PARAM",),
"temporal_split_param": ("H3_TEMPORAL_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": 0, "min": 0, "max": 0xFFFFFFFFFFFFFFFF, "control_after_generate": True}),
"upscale_negative": ("CONDITIONING",),
"upscale_sigmas": ("SIGMAS",),
},
}
@@ -115,7 +149,66 @@ class H3ContinuumSecondPassV35:
refine_context=None,
video_vae=None,
refine_schedule=None,
tiled_upscale=False,
latent_upscale_param=None,
spatial_split_param=None,
temporal_split_param=None,
upscale_sampler="euler_ancestral",
upscale_scheduler="simple",
upscale_steps=3,
upscale_denoise=0.2,
upscale_cfg=1.0,
upscale_noise_seed=0,
upscale_negative=None,
upscale_sigmas=None,
):
tiled_config = None
if bool(_single_list_input("tiled_upscale", tiled_upscale)):
from .tiled_latent_upscale_nodes import _native_node
required_native = {
name: _native_node(name)
for name in (
"MMH3UltimateUpscale",
"RandomNoise",
"KSamplerSelect",
"BasicScheduler",
)
}
missing = [name for name, value in required_native.items() if value is None]
if missing:
raise RuntimeError("Missing native tiled-upscale nodes: " + ", ".join(missing))
if latent_upscale_param is None or spatial_split_param is None:
raise ValueError(
"Tiled upscale mode requires latent_upscale_param and spatial_split_param"
)
tiled_config = {
"native": required_native["MMH3UltimateUpscale"],
"random_noise": required_native["RandomNoise"],
"sampler": required_native["KSamplerSelect"]().get_sampler(
str(_single_list_input("upscale_sampler", upscale_sampler))
),
"scheduler": required_native["BasicScheduler"],
"scheduler_name": str(_single_list_input("upscale_scheduler", upscale_scheduler)),
"steps": int(_single_list_input("upscale_steps", upscale_steps)),
"denoise": float(_single_list_input("upscale_denoise", upscale_denoise)),
"cfg": float(_single_list_input("upscale_cfg", upscale_cfg)),
"seed_base": int(_single_list_input("upscale_noise_seed", upscale_noise_seed)),
"latent_upscale_param": _single_list_input("latent_upscale_param", latent_upscale_param),
"spatial_split_param": _single_list_input("spatial_split_param", spatial_split_param),
"temporal_split_param": (
None if temporal_split_param is None
else _single_list_input("temporal_split_param", temporal_split_param)
),
"negative": (
None if upscale_negative is None
else _single_list_input("upscale_negative", upscale_negative)
),
"sigmas": (
None if upscale_sigmas is None
else _single_list_input("upscale_sigmas", upscale_sigmas)
),
}
return run_second_pass_groups(
model=_single_list_input("model", model),
clip=_single_list_input("clip", clip),
@@ -136,6 +229,7 @@ class H3ContinuumSecondPassV35:
else _single_list_input("video_vae", video_vae)
),
refine_schedule=refine_schedule,
tiled_upscale_config=tiled_config,
)