Unwrap ComfyUI v3 node outputs for tiled upscale
This commit is contained in:
@@ -38,6 +38,35 @@ def _native_node(name: str):
|
||||
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.
|
||||
|
||||
@@ -59,7 +88,7 @@ def _call_native(node_class, kwargs: dict[str, Any]):
|
||||
seen.add(name)
|
||||
method = getattr(instance, name, None)
|
||||
if callable(method):
|
||||
return method(**kwargs)
|
||||
return _unwrap_node_output(method(**kwargs))
|
||||
raise RuntimeError(
|
||||
"MMH3UltimateUpscale exposes no callable ComfyUI FUNCTION method "
|
||||
f"(declared={declared!r})"
|
||||
@@ -266,12 +295,19 @@ class H3ContinuumTiledLatentUpscalePerClip:
|
||||
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 = random_noise().get_noise(seed + index - 1)
|
||||
sampler = sampler_select().get_sampler(sampler_name)
|
||||
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 = scheduler().get_sigmas(
|
||||
clip_model, scheduler_name, steps, denoise
|
||||
sigmas = _unwrap_single_output(
|
||||
scheduler().get_sigmas(
|
||||
clip_model, scheduler_name, steps, denoise
|
||||
),
|
||||
"BasicScheduler",
|
||||
)
|
||||
kwargs = {
|
||||
"model": clip_model,
|
||||
|
||||
Reference in New Issue
Block a user