Archive fork in favor of upstream and DUMAS nodes
This commit is contained in:
+27
-7
@@ -61,7 +61,11 @@ from .memory_action_policy import (
|
||||
resolve_memory_action_policy,
|
||||
)
|
||||
from .node_facade import execute_v38_runtime_request, make_runtime_request
|
||||
from .nodes import CATEGORY as CONTINUUM_CATEGORY, H3ContinuumSamplerProduction
|
||||
from .nodes import (
|
||||
CATEGORY as CONTINUUM_CATEGORY,
|
||||
H3ContinuumSamplerProduction,
|
||||
_regenerate_from_value,
|
||||
)
|
||||
from .resolution import (
|
||||
H3_ASPECT_AUTO,
|
||||
H3_ASPECT_OPTIONS,
|
||||
@@ -739,15 +743,31 @@ class H3ContinuumSamplerV38(H3ContinuumSamplerV37):
|
||||
def IS_CHANGED(
|
||||
cls,
|
||||
generation_mode=GENERATION_MODE_FULL_RUN,
|
||||
run_storage="Off",
|
||||
reroll_from_chunk="Auto",
|
||||
reroll_nonce=0,
|
||||
**kwargs,
|
||||
):
|
||||
# Review execution depends on validated Run Storage state that is
|
||||
# intentionally outside the visible graph inputs. Always execute the
|
||||
# V3.8 sampler in Review mode and let Run Storage remain the sole
|
||||
# authority for exact prefix reuse. Full Run keeps Core's stable cache
|
||||
# behavior, and this method is deliberately not inherited by V3.7/Easy.
|
||||
if generation_mode == GENERATION_MODE_REVIEW:
|
||||
# Review and automatic reroll variations depend on saved state outside
|
||||
# Core's input cache. Run Storage still owns all reuse/safety decisions.
|
||||
# Core supplies None for linked inputs during its cache-key pass.
|
||||
if generation_mode is None or generation_mode == GENERATION_MODE_REVIEW:
|
||||
return float("NaN")
|
||||
if run_storage in ("Save + Auto Resume", None):
|
||||
try:
|
||||
if reroll_nonce is not None and int(reroll_nonce) != 0:
|
||||
return False
|
||||
if reroll_from_chunk is None:
|
||||
return float("NaN")
|
||||
# The execution path validates the actual configured chunk range.
|
||||
boundary = _regenerate_from_value(
|
||||
reroll_from_chunk, chunks=16
|
||||
)
|
||||
if boundary > 0:
|
||||
return float("NaN")
|
||||
except (TypeError, ValueError, OverflowError):
|
||||
pass # Core/backend validation owns malformed inputs.
|
||||
# Ordinary Full Run and fixed positive nonces keep stable caching.
|
||||
return False
|
||||
|
||||
def run(
|
||||
|
||||
+20
-103
@@ -29,7 +29,6 @@ from .refine_schedule import (
|
||||
serializable_schedule_contract,
|
||||
)
|
||||
from .refine_sampling import sample_refine_chunk
|
||||
from .tiled_latent_upscale_nodes import _call_native, _unwrap_single_output
|
||||
|
||||
|
||||
class SecondPassContractError(ValueError):
|
||||
@@ -458,7 +457,6 @@ 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."""
|
||||
|
||||
@@ -503,7 +501,6 @@ 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 = (
|
||||
@@ -517,74 +514,27 @@ 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)
|
||||
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 = _unwrap_single_output(
|
||||
config["random_noise"]().get_noise(upscale_seed), "RandomNoise"
|
||||
)
|
||||
upscale_sampler = config["sampler"]
|
||||
upscale_sigmas = config.get("sigmas")
|
||||
if upscale_sigmas is None:
|
||||
upscale_sigmas = _unwrap_single_output(
|
||||
config["scheduler"]().get_sigmas(
|
||||
chunk_model,
|
||||
config["scheduler_name"],
|
||||
config["steps"],
|
||||
config["denoise"],
|
||||
),
|
||||
"BasicScheduler",
|
||||
)
|
||||
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:
|
||||
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"tiled upscale returned no output for physical group {group_index + 1}"
|
||||
f"selected physical group {group_index + 1} has no temporal window"
|
||||
)
|
||||
sampled = native_result[0]
|
||||
sample_arguments["temporal_window"] = temporal_window
|
||||
sampled = sample_fn(**sample_arguments)
|
||||
refined_video, _temporary_audio = stream_extractor(sampled)
|
||||
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]):
|
||||
if tuple(refined_video.shape) != tuple(video_samples.shape):
|
||||
raise SecondPassContractError(
|
||||
f"tiled upscale group {group_index} changed B/C/T geometry"
|
||||
f"refined video group {group_index} changed B/C/T/H/W geometry"
|
||||
)
|
||||
if not bool(torch.isfinite(refined_video.float()).all().item()):
|
||||
raise SecondPassContractError(
|
||||
@@ -604,17 +554,9 @@ 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}, "
|
||||
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"
|
||||
f"refine_seed={physical_seed}, shape={tuple(refined_video.shape)}, "
|
||||
"sampling_passes=1, temporary_audio_discarded=true"
|
||||
)
|
||||
if tiled_upscale_config is not None:
|
||||
group_report_lines.append(
|
||||
"tiled sigma source="
|
||||
f"{tiled_upscale_config.get('sigma_source', 'node_steps_fallback')}"
|
||||
)
|
||||
if adaptation_stats is not None:
|
||||
group_report_lines.append(
|
||||
"group "
|
||||
@@ -677,36 +619,11 @@ 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_tiled_upscale_audio_locked_v1"
|
||||
if tiled_upscale_config is not None
|
||||
else "context_aware_physical_groups_audio_locked_v3"
|
||||
)
|
||||
contract["execution"] = "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:
|
||||
|
||||
+1
-119
@@ -9,7 +9,6 @@ from .refine_scope import MODE_ALL, MODE_LOGICAL_CHUNK, MODE_PHYSICAL_GROUP
|
||||
from .refine_window import MODE_TIME_WINDOW
|
||||
from .second_pass import run_second_pass_groups
|
||||
from .targeted_second_pass import run_targeted_second_pass_groups
|
||||
from .tiled_latent_upscale_nodes import _native_node, _unwrap_single_output
|
||||
|
||||
|
||||
REFINE_TARGET_VIDEO_ONLY = "Video Only"
|
||||
@@ -50,30 +49,6 @@ def _single_list_input(name: str, value: Any) -> Any:
|
||||
return value[0]
|
||||
|
||||
|
||||
def _optional_single_list_input(name: str, value: Any) -> Any:
|
||||
"""Unwrap an optional INPUT_IS_LIST value without losing an absent socket."""
|
||||
|
||||
if value is None:
|
||||
return None
|
||||
return _single_list_input(name, value)
|
||||
|
||||
|
||||
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."""
|
||||
|
||||
@@ -84,10 +59,7 @@ class H3ContinuumSecondPassV35:
|
||||
"Connect the optional Continuum refine context to preserve the physical group's "
|
||||
"First/Last/Reference conditioning. "
|
||||
"SIGMAS controls the low-denoise refine schedule; audio output is preserved "
|
||||
"bit-exact from the first pass. In tiled-upscale mode, connected "
|
||||
"upscale-specific sockets take priority; the main SIGMAS socket is the "
|
||||
"fallback external schedule. The other optional tiled sockets fall back "
|
||||
"to their node widgets when they are not connected."
|
||||
"bit-exact from the first pass."
|
||||
)
|
||||
|
||||
@classmethod
|
||||
@@ -111,28 +83,10 @@ 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",),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -161,78 +115,7 @@ 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)):
|
||||
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": _unwrap_single_output(
|
||||
required_native["KSamplerSelect"]().get_sampler(
|
||||
str(_single_list_input("upscale_sampler", upscale_sampler))
|
||||
),
|
||||
"KSamplerSelect",
|
||||
),
|
||||
"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)
|
||||
),
|
||||
# A dedicated tiled schedule wins. The main SIGMAS socket is
|
||||
# the backwards-compatible external fallback used by existing
|
||||
# DUMAS workflows.
|
||||
"sigmas": _optional_single_list_input(
|
||||
"upscale_sigmas", upscale_sigmas
|
||||
)
|
||||
if upscale_sigmas is not None
|
||||
else _optional_single_list_input("sigmas", sigmas),
|
||||
"sigma_source": (
|
||||
"upscale_sigmas_socket"
|
||||
if upscale_sigmas is not None
|
||||
else "sigmas_socket"
|
||||
if sigmas is not None
|
||||
else "node_steps_fallback"
|
||||
),
|
||||
}
|
||||
return run_second_pass_groups(
|
||||
model=_single_list_input("model", model),
|
||||
clip=_single_list_input("clip", clip),
|
||||
@@ -253,7 +136,6 @@ class H3ContinuumSecondPassV35:
|
||||
else _single_list_input("video_vae", video_vae)
|
||||
),
|
||||
refine_schedule=refine_schedule,
|
||||
tiled_upscale_config=tiled_config,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -1,357 +0,0 @@
|
||||
"""Per-clip tiled latent upscaling for MiniMax H3 Continuum.
|
||||
|
||||
Continuum exposes physical video groups as a LATENT list. The native
|
||||
``MMH3UltimateUpscale`` node operates on one H3 latent at a time, so this
|
||||
adapter deliberately applies it independently to each physical clip instead
|
||||
of concatenating the clips into one larger VRAM allocation.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
|
||||
def _sampler_options() -> list[str]:
|
||||
try:
|
||||
import comfy.samplers
|
||||
|
||||
return list(comfy.samplers.KSampler.SAMPLERS)
|
||||
except Exception: # pragma: no cover - exercised on a ComfyUI host
|
||||
return ["euler", "euler_ancestral", "res_multistep", "sa_solver"]
|
||||
|
||||
|
||||
def _scheduler_options() -> list[str]:
|
||||
try:
|
||||
import comfy.samplers
|
||||
|
||||
return list(comfy.samplers.KSampler.SCHEDULERS)
|
||||
except Exception: # pragma: no cover - exercised on a ComfyUI host
|
||||
return ["simple", "beta", "sgm_uniform", "karras", "exponential"]
|
||||
|
||||
|
||||
def _native_node(name: str):
|
||||
try:
|
||||
import nodes
|
||||
|
||||
return (getattr(nodes, "NODE_CLASS_MAPPINGS", {}) or {}).get(name)
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
||||
def _unwrap_node_output(value: Any) -> Any:
|
||||
"""Extract values returned by ComfyUI's newer NodeOutput API.
|
||||
|
||||
The v3 API wraps node results in ``NodeOutput`` while legacy nodes expect
|
||||
the underlying tensor/object directly. Keep this adapter compatible with
|
||||
both APIs without importing ComfyUI internals.
|
||||
"""
|
||||
|
||||
result = getattr(value, "result", None)
|
||||
if result is None and not hasattr(value, "result"):
|
||||
return value
|
||||
return result
|
||||
|
||||
|
||||
def _unwrap_single_output(value: Any, name: str) -> Any:
|
||||
marker = object()
|
||||
result = getattr(value, "result", marker)
|
||||
# Ordinary tuples are valid values for the lightweight test doubles and
|
||||
# for some legacy ComfyUI helpers. Only unwrap an actual NodeOutput-like
|
||||
# object, identified by its result property.
|
||||
if result is marker:
|
||||
return value
|
||||
if isinstance(result, (tuple, list)):
|
||||
if len(result) != 1:
|
||||
raise ValueError(f"{name} returned {len(result)} outputs; expected one")
|
||||
return result[0]
|
||||
return result
|
||||
|
||||
|
||||
def _call_native(node_class, kwargs: dict[str, Any]):
|
||||
"""Invoke a ComfyUI node through its declared FUNCTION contract.
|
||||
|
||||
ComfyUI node classes do not have a universal Python method name. The live
|
||||
MiniMax node currently declares its executor through ``FUNCTION`` rather
|
||||
than exposing a method named ``upscale``.
|
||||
"""
|
||||
|
||||
instance = node_class()
|
||||
declared = getattr(node_class, "FUNCTION", None)
|
||||
candidates = []
|
||||
if isinstance(declared, str) and declared:
|
||||
candidates.append(declared)
|
||||
candidates.extend(("execute", "run", "process", "sample", "upscale"))
|
||||
seen = set()
|
||||
for name in candidates:
|
||||
if name in seen:
|
||||
continue
|
||||
seen.add(name)
|
||||
method = getattr(instance, name, None)
|
||||
if callable(method):
|
||||
return _unwrap_node_output(method(**kwargs))
|
||||
raise RuntimeError(
|
||||
"MMH3UltimateUpscale exposes no callable ComfyUI FUNCTION method "
|
||||
f"(declared={declared!r})"
|
||||
)
|
||||
|
||||
|
||||
def _one(value: Any, name: str) -> Any:
|
||||
"""Unwrap ComfyUI list inputs while rejecting ambiguous values."""
|
||||
|
||||
if isinstance(value, list):
|
||||
if len(value) != 1:
|
||||
raise ValueError(f"{name} must contain one shared value")
|
||||
return value[0]
|
||||
return value
|
||||
|
||||
|
||||
def _clips(value: Any) -> list[Any]:
|
||||
if isinstance(value, list):
|
||||
return value
|
||||
return [value]
|
||||
|
||||
|
||||
def _per_clip(value: Any, count: int, name: str) -> list[Any]:
|
||||
values = _clips(value)
|
||||
if len(values) == 1:
|
||||
return values * count
|
||||
if len(values) != count:
|
||||
raise ValueError(f"{name} has {len(values)} values for {count} clips")
|
||||
return values
|
||||
|
||||
|
||||
class H3ContinuumTiledLatentUpscalePerClip:
|
||||
"""Upscale each Continuum physical clip separately with tiled H3 latent work.
|
||||
|
||||
This is intentionally a thin adapter around ComfyUI's native
|
||||
``MMH3UltimateUpscale`` implementation. It does not vendor or replace
|
||||
the model-specific implementation; it only supplies an independent
|
||||
sampler/scheduler/noise/CFG schedule for each clip and preserves list
|
||||
boundaries so clips never become one oversized VRAM job.
|
||||
"""
|
||||
|
||||
DESCRIPTION = (
|
||||
"Apply native MiniMax H3 tiled latent upscaling independently to every "
|
||||
"Continuum physical clip. Clips remain separate LATENT list items."
|
||||
)
|
||||
SEARCH_ALIASES = [
|
||||
"H3 tiled upscale per clip",
|
||||
"MiniMax H3 clip upscale",
|
||||
"Continuum latent upscale",
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"model": ("MODEL",),
|
||||
"clip": ("CLIP",),
|
||||
"video_latents": ("LATENT",),
|
||||
"assembly_plan": ("H3_CONTINUUM_ASSEMBLY_PLAN",),
|
||||
"refine_context": ("H3_CONTINUUM_REFINE_CONTEXT",),
|
||||
"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": {
|
||||
"conditioning": ("CONDITIONING",),
|
||||
"video_vae": ("VAE",),
|
||||
"negative": ("CONDITIONING",),
|
||||
"temporal_split_param": ("H3_TEMPORAL_PARAM",),
|
||||
"upscale_sigmas": ("SIGMAS",),
|
||||
},
|
||||
}
|
||||
|
||||
INPUT_IS_LIST = True
|
||||
RETURN_TYPES = ("LATENT", "STRING")
|
||||
RETURN_NAMES = ("upscaled_video_latents", "report")
|
||||
OUTPUT_IS_LIST = (True, False)
|
||||
FUNCTION = "upscale"
|
||||
CATEGORY = "MiniMax H3/Continuum/Upscale"
|
||||
|
||||
def upscale(
|
||||
self,
|
||||
model,
|
||||
clip,
|
||||
video_latents,
|
||||
assembly_plan,
|
||||
refine_context,
|
||||
latent_upscale_param,
|
||||
spatial_split_param,
|
||||
upscale_sampler,
|
||||
upscale_scheduler,
|
||||
upscale_steps,
|
||||
upscale_denoise,
|
||||
upscale_cfg,
|
||||
upscale_noise_seed,
|
||||
conditioning=None,
|
||||
video_vae=None,
|
||||
negative=None,
|
||||
temporal_split_param=None,
|
||||
upscale_sigmas=None,
|
||||
):
|
||||
native = _native_node("MMH3UltimateUpscale")
|
||||
random_noise = _native_node("RandomNoise")
|
||||
sampler_select = _native_node("KSamplerSelect")
|
||||
scheduler = _native_node("BasicScheduler")
|
||||
missing = [
|
||||
name
|
||||
for name, value in (
|
||||
("MMH3UltimateUpscale", native),
|
||||
("RandomNoise", random_noise),
|
||||
("KSamplerSelect", sampler_select),
|
||||
("BasicScheduler", scheduler),
|
||||
)
|
||||
if value is None
|
||||
]
|
||||
if missing:
|
||||
raise RuntimeError("Missing native ComfyUI nodes: " + ", ".join(missing))
|
||||
|
||||
latents = _clips(video_latents)
|
||||
if not latents:
|
||||
raise ValueError("video_latents must contain at least one clip")
|
||||
if conditioning is None:
|
||||
# The Continuum sampler's refine context is a runtime contract, not
|
||||
# a Core CONDITIONING value. Reuse Continuum's own bridge so each
|
||||
# physical clip receives its captured prompt/reference conditioning
|
||||
# and its context-aware model clone at the target geometry.
|
||||
from .second_pass import prepare_physical_refine_groups
|
||||
|
||||
prepared = prepare_physical_refine_groups(
|
||||
model=_one(model, "model"),
|
||||
clip=_one(clip, "clip"),
|
||||
video_latents=latents,
|
||||
assembly_plan=_one(assembly_plan, "assembly_plan"),
|
||||
refine_context=_one(refine_context, "refine_context"),
|
||||
video_vae=(
|
||||
None if video_vae is None else _one(video_vae, "video_vae")
|
||||
),
|
||||
)
|
||||
models = prepared["group_models"]
|
||||
conditionings = prepared["conditioning"]
|
||||
if len(models) != len(latents) or len(conditionings) != len(latents):
|
||||
raise ValueError(
|
||||
"refine context bridge did not produce one model and conditioning "
|
||||
"value per physical clip"
|
||||
)
|
||||
else:
|
||||
models = _per_clip(model, len(latents), "model")
|
||||
conditionings = _per_clip(conditioning, len(latents), "conditioning")
|
||||
negatives = (
|
||||
[None] * len(latents)
|
||||
if negative is None
|
||||
else _per_clip(negative, len(latents), "negative")
|
||||
)
|
||||
temporal = (
|
||||
[None] * len(latents)
|
||||
if temporal_split_param is None
|
||||
else _per_clip(temporal_split_param, len(latents), "temporal_split_param")
|
||||
)
|
||||
sigma_values = (
|
||||
[None] * len(latents)
|
||||
if upscale_sigmas is None
|
||||
else _per_clip(upscale_sigmas, len(latents), "upscale_sigmas")
|
||||
)
|
||||
|
||||
sampler_name = str(_one(upscale_sampler, "upscale_sampler"))
|
||||
scheduler_name = str(_one(upscale_scheduler, "upscale_scheduler"))
|
||||
steps = int(_one(upscale_steps, "upscale_steps"))
|
||||
denoise = float(_one(upscale_denoise, "upscale_denoise"))
|
||||
cfg = float(_one(upscale_cfg, "upscale_cfg"))
|
||||
seed = int(_one(upscale_noise_seed, "upscale_noise_seed"))
|
||||
upscale_param = _one(latent_upscale_param, "latent_upscale_param")
|
||||
spatial_param = _one(spatial_split_param, "spatial_split_param")
|
||||
|
||||
outputs = []
|
||||
reports = []
|
||||
for index, (clip_latent, clip_model, clip_conditioning) in enumerate(
|
||||
zip(latents, models, conditionings), start=1
|
||||
):
|
||||
samples = clip_latent.get("samples") if isinstance(clip_latent, dict) else None
|
||||
if samples is None or getattr(samples, "ndim", None) != 5:
|
||||
raise ValueError(f"clip {index} is not a 5-D H3 LATENT")
|
||||
noise = _unwrap_single_output(
|
||||
random_noise().get_noise(seed + index - 1), "RandomNoise"
|
||||
)
|
||||
sampler = _unwrap_single_output(
|
||||
sampler_select().get_sampler(sampler_name), "KSamplerSelect"
|
||||
)
|
||||
sigmas = sigma_values[index - 1]
|
||||
if sigmas is None:
|
||||
sigmas = _unwrap_single_output(
|
||||
scheduler().get_sigmas(
|
||||
clip_model, scheduler_name, steps, denoise
|
||||
),
|
||||
"BasicScheduler",
|
||||
)
|
||||
kwargs = {
|
||||
"model": clip_model,
|
||||
"conditioning": clip_conditioning,
|
||||
"latent": clip_latent,
|
||||
"noise": noise,
|
||||
"sampler": sampler,
|
||||
"sigmas": sigmas,
|
||||
"cfg": cfg,
|
||||
"latent_upscale_param": upscale_param,
|
||||
"temporal_split_param": temporal[index - 1],
|
||||
"spatial_split_param": spatial_param,
|
||||
}
|
||||
if negatives[index - 1] is not None:
|
||||
kwargs["negative"] = negatives[index - 1]
|
||||
result = _call_native(native, kwargs)
|
||||
if not isinstance(result, (tuple, list)) or not result:
|
||||
raise RuntimeError(f"native upscale returned no output for clip {index}")
|
||||
output = result[0]
|
||||
output_samples = output.get("samples") if isinstance(output, dict) else None
|
||||
if output_samples is None or output_samples.ndim != 5:
|
||||
raise RuntimeError(f"native upscale returned an invalid clip {index}")
|
||||
if output_samples.shape[2] != samples.shape[2]:
|
||||
raise RuntimeError(f"tiled upscale changed temporal length for clip {index}")
|
||||
outputs.append(output)
|
||||
reports.append(
|
||||
f"clip {index}: {tuple(samples.shape)} -> {tuple(output_samples.shape)}"
|
||||
)
|
||||
|
||||
return (
|
||||
outputs,
|
||||
"H3 Continuum per-clip tiled upscale; "
|
||||
f"clips={len(outputs)}, sampler={sampler_name}, scheduler={scheduler_name}, "
|
||||
f"steps={steps}, denoise={denoise:g}, cfg={cfg:g}, seed_base={seed}; "
|
||||
+ "; ".join(reports),
|
||||
)
|
||||
|
||||
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"H3ContinuumTiledLatentUpscalePerClip": H3ContinuumTiledLatentUpscalePerClip,
|
||||
}
|
||||
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"H3ContinuumTiledLatentUpscalePerClip": (
|
||||
"H3 Continuum Tiled Latent Upscale (Per Clip)"
|
||||
),
|
||||
}
|
||||
Reference in New Issue
Block a user