"""Dumas MiniMax-H3 helpers. This module intentionally does not vendor the third-party H3 LongVideos node. It provides the missing tiled latent second pass around the native ``MMH3UltimateUpscale`` node that is already used by the user's H3 workflow. The node keeps its own sampling controls, so changing the upscale pass cannot silently change the base H3 render. """ def _sampler_options(): try: import comfy.samplers return list(comfy.samplers.KSampler.SAMPLERS) except Exception: # import-time test fallback return ["euler", "euler_ancestral", "res_multistep", "sa_solver"] def _scheduler_options(): try: import comfy.samplers return list(comfy.samplers.KSampler.SCHEDULERS) except Exception: # import-time test fallback return ["simple", "beta", "sgm_uniform", "karras", "exponential"] def _native_node(name): try: import nodes mapping = getattr(nodes, "NODE_CLASS_MAPPINGS", {}) or {} cls = mapping.get(name) if cls is not None: return cls except Exception: pass return None class DumasMMH3TiledLatentUpscale: """Run a tiled MiniMax-H3 latent upscale/refinement pass. The incoming latent is normally the output of the base H3 sampler. The native MMH3 upscale node performs the actual model-specific tiled work; this wrapper creates its noise, sampler and sigma schedule from its own widgets and passes through the user's spatial split parameter object. """ @classmethod def INPUT_TYPES(cls): return { "required": { "model": ("MODEL",), "conditioning": ("CONDITIONING",), "latent": ("LATENT",), "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": { "negative": ("CONDITIONING",), "temporal_split_param": ("H3_TEMPORAL_PARAM",), "upscale_sigmas": ("SIGMAS",), }, } RETURN_TYPES = ("LATENT", "STRING") RETURN_NAMES = ("upscaled_latent", "info") FUNCTION = "upscale" CATEGORY = "Dumas/MiniMax H3/Upscale" def upscale( self, model, conditioning, latent, latent_upscale_param, spatial_split_param, upscale_sampler, upscale_scheduler, upscale_steps, upscale_denoise, upscale_cfg, upscale_noise_seed, negative=None, temporal_split_param=None, upscale_sigmas=None, ): native = _native_node("MMH3UltimateUpscale") if native is None: raise RuntimeError( "MMH3UltimateUpscale is not installed. Install/update the MiniMax-H3 " "node pack that provides the native tiled upscale node." ) random_noise = _native_node("RandomNoise") sampler_select = _native_node("KSamplerSelect") scheduler = _native_node("BasicScheduler") missing = [ name for name, value in (("RandomNoise", random_noise), ("KSamplerSelect", sampler_select), ("BasicScheduler", scheduler)) if value is None ] if missing: raise RuntimeError("Missing native ComfyUI nodes: " + ", ".join(missing)) noise = random_noise().get_noise(int(upscale_noise_seed)) sampler = sampler_select().get_sampler(str(upscale_sampler)) sigmas = upscale_sigmas if sigmas is None: sigmas = scheduler().get_sigmas( model, str(upscale_scheduler), int(upscale_steps), float(upscale_denoise) ) kwargs = { "model": model, "conditioning": conditioning, "latent": latent, "noise": noise, "sampler": sampler, "sigmas": sigmas, "cfg": float(upscale_cfg), "latent_upscale_param": latent_upscale_param, "temporal_split_param": temporal_split_param, "spatial_split_param": spatial_split_param, } if negative is not None: kwargs["negative"] = negative result = native().upscale(**kwargs) if not isinstance(result, (tuple, list)) or not result: raise RuntimeError("MMH3UltimateUpscale returned no latent output.") output = result[0] if not isinstance(output, dict) or "samples" not in output: raise RuntimeError("MMH3UltimateUpscale returned an unexpected latent object.") samples = output["samples"] if samples.ndim != 5: raise RuntimeError(f"Expected a 5-D H3 latent, got shape {tuple(samples.shape)}.") if samples.shape[2] != latent["samples"].shape[2]: raise RuntimeError("Tiled spatial upscale changed the temporal latent length.") info = ( "Dumas tiled MiniMax-H3 latent upscale: " f"sampler={upscale_sampler}, scheduler={upscale_scheduler}, " f"steps={int(upscale_steps)}, denoise={float(upscale_denoise):g}, " f"cfg={float(upscale_cfg):g}, noise_seed={int(upscale_noise_seed)}; " "spatial split supplied by MMH3SpatialSplitParams" ) return output, info NODE_CLASS_MAPPINGS = { "DumasMMH3TiledLatentUpscale": DumasMMH3TiledLatentUpscale, } NODE_DISPLAY_NAME_MAPPINGS = { "DumasMMH3TiledLatentUpscale": "DUMAS MiniMax-H3 Tiled Latent Upscale", }