From e6116df914cb80d19ea0b142d4ce73316d7dff33 Mon Sep 17 00:00:00 2001 From: Chris Dumas Date: Fri, 30 Oct 2026 11:06:44 +0000 Subject: [PATCH] Restore Continuum image reference inputs --- README.md | 13 ++-- dumas_h3_prompt_nodes.py | 102 +++----------------------- dumas_vendored_nodes.py | 110 +++-------------------------- tests/test_dumas_h3_nodes.py | 34 ++++----- tests/test_dumas_vendored_nodes.py | 10 +-- 5 files changed, 43 insertions(+), 226 deletions(-) diff --git a/README.md b/README.md index 2a538cc..b6627e9 100644 --- a/README.md +++ b/README.md @@ -93,14 +93,11 @@ the chunk count, the shared chunk duration, and a per-chunk reference bundle. Reference images are inserted as `@R1` through `@R9`; routing is based on the shared directive, soundscape, music, and each chunk's full prompt text. -The builder exposes nine optional `H3_REF_MODS` sockets, labelled `RefMod 1` -through `RefMod 9`. Each connected socket occupies the matching `@R` slot in -socket order, so the chips and generated prompt definitions are deterministic; -there is no image-socket offset or chained-bundle ambiguity. Visual RefMods are -automatically described in the generated shared directive and emitted through -the `ref_mods` output for downstream RefMod handling. The typed -`reference_images` output remains as an empty compatibility bundle for older -workflows; this builder no longer accepts image sockets. +The builder exposes nine optional `IMAGE` sockets, labelled `Reference Image 1` +through `Reference Image 9`. Each connected socket occupies the matching `@R` +slot, and the generated Continuum reference bundle contains those images with +per-chunk routing. RefMod inputs and direct RefMod conditioning are deliberately +not part of this node. The prompt builder intentionally uses the `ReferenceImagesV39Bundle` class from the installed upstream H3 Continuum pack. Install that pack alongside diff --git a/dumas_h3_prompt_nodes.py b/dumas_h3_prompt_nodes.py index 418f043..73dd78d 100644 --- a/dumas_h3_prompt_nodes.py +++ b/dumas_h3_prompt_nodes.py @@ -12,15 +12,6 @@ import sys REFERENCE_IMAGES_V39_TYPE = "H3_CONTINUUM_REFERENCE_IMAGES_V39" -class DumasH3RefModBundle(list): - """H3_REF_MODS list with optional per-chunk routing metadata.""" - - def __init__(self, values=(), *, chunk_refs=None): - super().__init__(values) - self.chunk_refs = tuple(tuple(int(index) for index in refs) - for refs in (chunk_refs or ())) - - def _continuum_reference_bundle_type(): """Find the upstream H3 bundle class without copying its implementation.""" candidates = [ @@ -42,34 +33,6 @@ def _continuum_reference_bundle_type(): ) -def _visual_refmods(mods): - """Return positive-weight visual RefMods in stable picker order.""" - result = [] - seen = set() - for mod, strength in (mods or []): - if getattr(mod, "kind", None) == "audio" or float(strength) <= 0: - continue - key = str(getattr(mod, "path", "") or "") or (getattr(mod, "name", "refmod"), id(mod)) - if key in seen: - continue - seen.add(key) - result.append((mod, float(strength))) - return result - - -def _refmod_directive(refmods, start_slot, slots=None): - """Build conservative default definitions for RefMods in the prompt.""" - lines = [] - for offset, (mod, _strength) in enumerate(refmods): - slot = slots[offset] if slots is not None else start_slot + offset - name = str(getattr(mod, "name", "visual reference") or "visual reference").strip() - lines.append( - f"@R{slot} is the {name} visual reference; preserve its identity, " - "appearance, and important physical details when it is used." - ) - return "\n".join(lines) - - MAX_CLIPS = 16 DEFAULT_CLIP_SECONDS = 4.0 @@ -200,8 +163,8 @@ class DumasH3SequencePromptBuilder: "the node emits one absolute Timeline prompt for Sequence Prompt." ) CATEGORY = "Dumas/MiniMax H3/Prompt" - RETURN_TYPES = ("STRING", "INT", "FLOAT", REFERENCE_IMAGES_V39_TYPE, "H3_REF_MODS", "INT") - RETURN_NAMES = ("sequence_prompt", "chunk_count", "chunk_duration", "reference_images", "ref_mods", "refmod_offset") + RETURN_TYPES = ("STRING", "INT", "FLOAT", REFERENCE_IMAGES_V39_TYPE) + RETURN_NAMES = ("sequence_prompt", "chunk_count", "chunk_duration", "reference_images") FUNCTION = "build" @classmethod @@ -218,9 +181,9 @@ class DumasH3SequencePromptBuilder: }, "optional": { **{ - f"ref_mod_{index}": ("H3_REF_MODS", { - "display_name": f"RefMod {index} (@R{index})", - "tooltip": f"RefMod socket {index}; use @R{index} in a clip prompt.", + f"reference_image_{index}": ("IMAGE", { + "display_name": f"Reference Image {index} (@R{index})", + "tooltip": f"Fixed Reference Image {index}; use @R{index} in a clip prompt.", }) for index in range(1, 10) }, }, @@ -249,73 +212,28 @@ class DumasH3SequencePromptBuilder: "clips": [clip for clip in sequence["clips"] if clip.get("enabled", True)], } selectors = [] - routing_directive = str(shared_directive or "").strip() - directive = routing_directive + directive = str(shared_directive or "").strip() sound = str(soundscape or "").strip() or "N/A" music_text = str(music or "").strip() or "N/A" - # Each socket is one deterministic @R slot. This avoids trying to - # inspect the contents of a chained bundle in the browser and makes - # the socket order match the prompt chips exactly. - refmods = [] - for index in range(1, 10): - refmods.extend(_visual_refmods(kwargs.get(f"ref_mod_{index}"))) - if len(refmods) > 9: - raise ValueError("The prompt builder supports at most nine RefMod slots.") - authored_text_by_chunk = [] - for clip in active_sequence["clips"]: - authored_text_by_chunk.append("\n".join([ - routing_directive, - *(str(slot.get("text", "")) for slot in clip["slots"]), - f"overall_soundscape: {sound}", - f"non_diegetic_music: {music_text}", - ])) - # RefMod slots are defined by socket order, but only referenced slots - # should be passed to the sampler. Keep the original @R number in the - # generated definition so a sparse use such as @R2 remains accurate. - referenced_slots = { - index for index in range(1, len(refmods) + 1) - if any(re.search(rf"@R{index}(?![A-Za-z0-9_])", text, re.IGNORECASE) - for text in authored_text_by_chunk) - } - selected_refmods = [ - refmod for index, refmod in enumerate(refmods, start=1) - if index in referenced_slots - ] - selected_slots = [index for index in range(1, len(refmods) + 1) if index in referenced_slots] - selected_position = {slot: position for position, slot in enumerate(selected_slots)} - chunk_refs = [] - for text in authored_text_by_chunk: - chunk_refs.append(tuple( - selected_position[index] - for index in selected_slots - if re.search(rf"@R{index}(?![A-Za-z0-9_])", text, re.IGNORECASE) - )) - generated = _refmod_directive(selected_refmods, 1, selected_slots) - if generated: - directive = "\n\n".join(part for part in (directive, generated) if part) for reference_index in range(1, 10): chunks = [] for chunk_index, clip in enumerate(active_sequence["clips"], start=1): # Match against the same per-chunk content emitted by # format_sequence_prompt, not only the editable shot lines. text = "\n".join([ - routing_directive, + directive, *(str(slot.get("text", "")) for slot in clip["slots"]), f"overall_soundscape: {sound}", f"non_diegetic_music: {music_text}", ]) - available = reference_index <= len(refmods) - if available and re.search( + if kwargs.get(f"reference_image_{reference_index}") is not None and re.search( rf"@(R{reference_index}|image{reference_index})(?![A-Za-z0-9_])", text, re.IGNORECASE, ): chunks.append(chunk_index) selectors.append(",".join(map(str, chunks)) or "off") - # Keep the typed reference-images output for compatibility with the - # Continuum bridge, but it is intentionally empty: this builder now - # owns RefMod sockets rather than image sockets. - images = (None,) * 9 + images = tuple(kwargs.get(f"reference_image_{index}") for index in range(1, 10)) reference_bundle = _continuum_reference_bundle_type()( images=images, reference_use="Per chunk", @@ -331,8 +249,6 @@ class DumasH3SequencePromptBuilder: len(active_sequence["clips"]), float(default_chunk_seconds), reference_bundle, - DumasH3RefModBundle(selected_refmods, chunk_refs=chunk_refs), - 0, ) diff --git a/dumas_vendored_nodes.py b/dumas_vendored_nodes.py index 89676d6..edd60f9 100644 --- a/dumas_vendored_nodes.py +++ b/dumas_vendored_nodes.py @@ -84,7 +84,7 @@ def _namespace_class(node_class, *, node_id, category, display_name): namespaced.CATEGORY = category namespaced.NODE_CATEGORY = category if node_id == "DumasH3Continuum_H3ContinuumSamplerV39": - namespaced = _add_direct_refmod_input(namespaced) + namespaced = _clean_v39_sampler_input(namespaced) namespaced.__module__ = __name__ namespaced.__qualname__ = node_class.__qualname__ namespaced.__name__ = node_class.__name__ @@ -92,13 +92,13 @@ def _namespace_class(node_class, *, node_id, category, display_name): return namespaced -def _add_direct_refmod_input(node_class): - """Add the DUMAS direct RefMod path to the vendored V3.9 sampler. +def _clean_v39_sampler_input(node_class): + """Keep the DUMAS V3.9 manual-dimension surface without RefMods. - Continuum's normal image-reference bundle remains untouched. When a - RefMod bundle is connected, the same model-scoped OUTER_SAMPLE bridge used - by the maintained RefMod pack is attached to a cloned model for this run. - This keeps RefMods on the native H3 ref2va path and avoids global state. + The sampler uses Continuum's native V3.9 ``reference_images`` bundle. We + retain the DUMAS cleanup that makes linked width/height authoritative and + removes duplicate legacy audio controls, without adding a second RefMod + conditioning path. """ original_input_types = node_class.INPUT_TYPES @@ -107,116 +107,24 @@ def _add_direct_refmod_input(node_class): schema = original_input_types() schema = {name: dict(value) for name, value in schema.items()} required = dict(schema.get("required", {})) - # V3.8 exposes both its newer resolution preset controls and the - # original aspect/size controls. The DUMAS V3.9 node is intentionally - # a clean manual-dimension node: width and height are the one source of - # truth and can be converted to linked inputs in ComfyUI. for name in ("aspect", "preset", "custom_mp", "size_source"): required.pop(name, None) schema["required"] = required optional = dict(schema.get("optional", {})) - # The bundled audio reference socket supersedes the two legacy scalar - # audio inputs; exposing both makes it unclear which route is active. for name in ("reference_audio_1", "reference_audio_vae"): optional.pop(name, None) - optional["refmods"] = ( - "H3_REF_MODS", - { - "display_name": "RefMods (Optional)", - "tooltip": ( - "Optional MiniMax H3 RefMod bundle. RefMods are injected directly " - "into this sampler for every generated chunk." - ), - }, - ) - optional["refmod_retention"] = ( - "FLOAT", - { - "default": 1.0, - "min": 0.0, - "max": 1.0, - "step": 0.01, - "display": "number", - "display_name": "RefMod Retention", - "tooltip": "Master RefMod strength. 1.0 preserves the selected bundle fully.", - }, - ) - optional["refmod_max_total_tokens"] = ( - "INT", - { - "default": 0, - "min": 0, - "max": 1048576, - "step": 1, - "display_name": "RefMod Token Budget", - "tooltip": "0 uses the RefMod bundle's normal budget; otherwise enforce this maximum.", - }, - ) schema["optional"] = optional return schema - def run(self, refmods=None, refmod_retention=1.0, - refmod_max_total_tokens=0, **kwargs): - # The clean DUMAS surface always uses the explicitly supplied width / - # height pair. Keep the upstream runtime's legacy arguments internal. + def run(self, **kwargs): kwargs["size_source"] = "Manual" kwargs.pop("aspect", None) kwargs.pop("preset", None) kwargs.pop("custom_mp", None) - if refmods: - model = kwargs.get("model") - if model is None: - raise ValueError( - "DUMAS H3 Continuum Sampler V3.9 requires a model when RefMods are connected." - ) - try: - pack = importlib.import_module( - f"{__package__}.vendor.dumas_minimax_h3_refmod.nodes" - if __package__ else "vendor.dumas_minimax_h3_refmod.nodes" - ) - bridge = importlib.import_module( - f"{__package__}.vendor.dumas_minimax_h3_refmod.continuum_bridge" - if __package__ else "vendor.dumas_minimax_h3_refmod.continuum_bridge" - ) - blocks = pack._ref_blocks( - refmods, - refmod_retention, - seed=-1, - scramble_mode="shuffle", - max_total_tokens=int(refmod_max_total_tokens), - ) - chunk_blocks = None - chunk_refs = getattr(refmods, "chunk_refs", None) - if chunk_refs: - # Build the per-chunk payloads from the same selected - # RefMods. Ordinary H3_REF_MODS lists have no routing - # metadata and retain the upstream all-chunks behavior. - chunk_blocks = [] - for positions in chunk_refs: - chunk_mods = [refmods[index] for index in positions] - chunk_blocks.append(pack._ref_blocks( - chunk_mods, - refmod_retention, - seed=-1, - scramble_mode="shuffle", - max_total_tokens=int(refmod_max_total_tokens), - )) - kwargs["model"] = bridge.attach( - model, blocks, enabled=True, chunk_blocks=chunk_blocks, - ) - print( - "[DUMAS H3 Continuum Sampler V3.9] direct RefMods active " - f"({len(blocks)} block(s))" - ) - except Exception as exc: - raise RuntimeError( - "Unable to attach RefMods directly to DUMAS H3 Continuum " - f"Sampler V3.9: {exc}" - ) from exc return super(node_class, self).run(**kwargs) - node_class.INPUT_TYPES = INPUT_TYPES node_class.run = run + node_class.INPUT_TYPES = INPUT_TYPES return node_class diff --git a/tests/test_dumas_h3_nodes.py b/tests/test_dumas_h3_nodes.py index 4d32bea..fd84c2c 100644 --- a/tests/test_dumas_h3_nodes.py +++ b/tests/test_dumas_h3_nodes.py @@ -77,9 +77,8 @@ class H3NodeTests(unittest.TestCase): "Dumas/MiniMax H3/Prompt", ) optional = PROMPT.DumasH3SequencePromptBuilder.INPUT_TYPES()["optional"] - self.assertEqual(optional["ref_mod_1"][0], "H3_REF_MODS") - self.assertEqual(optional["ref_mod_9"][0], "H3_REF_MODS") - self.assertNotIn("reference_image_1", optional) + self.assertEqual(optional["reference_image_1"][0], "IMAGE") + self.assertEqual(optional["reference_image_9"][0], "IMAGE") reference_module = types.ModuleType("upstream.v3.reference_images_v39") reference_module.ReferenceImagesV39Bundle = FakeReferenceBundle sys.modules[reference_module.__name__] = reference_module @@ -90,8 +89,8 @@ class H3NodeTests(unittest.TestCase): '{"clips":[{"slots":[{"start":0,"end":4,"text":"Walk."}]},' '{"slots":[{"start":0,"end":4,"text":"Turn."}]}]}', "Use @R2 ambience.", "Music.", - ref_mod_1=[(FakeRefMod("environment"), 1.0)], - ref_mod_2=[(FakeRefMod("hero"), 1.0)], + reference_image_1="environment", + reference_image_2="hero", ) self.assertEqual(result[1], 2) self.assertEqual(result[2], 4.0) @@ -101,7 +100,7 @@ class H3NodeTests(unittest.TestCase): finally: sys.modules.pop(reference_module.__name__, None) - def test_prompt_builder_defines_connected_refmods_and_emits_them(self): + def test_prompt_builder_emits_connected_images(self): reference_module = types.ModuleType("upstream.v3.reference_images_v39") reference_module.ReferenceImagesV39Bundle = FakeReferenceBundle sys.modules[reference_module.__name__] = reference_module @@ -109,11 +108,9 @@ class H3NodeTests(unittest.TestCase): result = PROMPT.DumasH3SequencePromptBuilder().build( 2, 4, "", '{"clips":[{"slots":[{"start":0,"end":4,"text":"Use @R1."}]},' '{"slots":[{"start":0,"end":4,"text":"Continue with @R1."}]}]}', - "", "", ref_mod_1=[(FakeRefMod("hero_ref"), 1.0)], + "", "", reference_image_1="hero_ref", ) - self.assertEqual(result[4][0][0].name, "hero_ref") - self.assertEqual(result[5], 0) - self.assertIn("@R1 is the hero_ref visual reference", result[0]) + self.assertEqual(result[3].images[0], "hero_ref") self.assertEqual(result[3].selectors[0], "1,2") finally: sys.modules.pop(reference_module.__name__, None) @@ -128,7 +125,7 @@ class H3NodeTests(unittest.TestCase): '{"enabled":true,"slots":[{"start":0,"end":4,"text":"Use @R1."}]},' '{"enabled":false,"slots":[{"start":0,"end":4,"text":"Do not emit @R1."}]},' '{"enabled":true,"slots":[{"start":0,"end":4,"text":"Continue @R1."}]}]}', - "", "", ref_mod_1=[(FakeRefMod("hero"), 1.0)], + "", "", reference_image_1="hero", ) self.assertEqual(result[1], 2) self.assertEqual(result[3].selectors[0], "1,2") @@ -139,7 +136,7 @@ class H3NodeTests(unittest.TestCase): finally: sys.modules.pop(reference_module.__name__, None) - def test_only_authored_refmod_tags_are_emitted(self): + def test_image_slots_are_preserved_even_when_not_referenced(self): reference_module = types.ModuleType("upstream.v3.reference_images_v39") reference_module.ReferenceImagesV39Bundle = FakeReferenceBundle sys.modules[reference_module.__name__] = reference_module @@ -148,14 +145,13 @@ class H3NodeTests(unittest.TestCase): 2, 4, "", '{"clips":[' '{"slots":[{"start":0,"end":4,"text":"Use @R2."}]},' '{"slots":[{"start":0,"end":4,"text":"No extra reference."}]}]}', - "", "", ref_mod_1=[(FakeRefMod("unused"), 1.0)], - ref_mod_2=[(FakeRefMod("used"), 1.0)], - ref_mod_3=[(FakeRefMod("also_unused"), 1.0)], + "", "", reference_image_1="unused", + reference_image_2="used", + reference_image_3="also_unused", ) - self.assertEqual([mod.name for mod, _strength in result[4]], ["used"]) - self.assertEqual(result[4].chunk_refs, ((0,), ())) - self.assertIn("@R2 is the used visual reference", result[0]) - self.assertNotIn("unused visual reference", result[0]) + self.assertEqual(result[3].images[1], "used") + self.assertEqual(result[3].images[0], "unused") + self.assertEqual(result[3].images[2], "also_unused") finally: sys.modules.pop(reference_module.__name__, None) diff --git a/tests/test_dumas_vendored_nodes.py b/tests/test_dumas_vendored_nodes.py index f85163f..75a72e2 100644 --- a/tests/test_dumas_vendored_nodes.py +++ b/tests/test_dumas_vendored_nodes.py @@ -49,8 +49,8 @@ class _Sampler(_SamplerBase): class VendoredNamespaceTests(unittest.TestCase): - def test_v39_sampler_exposes_direct_refmod_socket(self): - sampler = vendored._add_direct_refmod_input(_Sampler) + def test_v39_sampler_keeps_clean_image_reference_surface(self): + sampler = vendored._clean_v39_sampler_input(_Sampler) inputs = sampler.INPUT_TYPES() self.assertNotIn("aspect", inputs["required"]) self.assertNotIn("preset", inputs["required"]) @@ -60,9 +60,9 @@ class VendoredNamespaceTests(unittest.TestCase): self.assertIn("height", inputs["required"]) self.assertNotIn("reference_audio_1", inputs["optional"]) self.assertNotIn("reference_audio_vae", inputs["optional"]) - self.assertEqual(inputs["optional"]["refmods"][0], "H3_REF_MODS") - self.assertIn("refmod_retention", inputs["optional"]) - self.assertIn("refmod_max_total_tokens", inputs["optional"]) + self.assertNotIn("refmods", inputs["optional"]) + self.assertNotIn("refmod_retention", inputs["optional"]) + self.assertNotIn("refmod_max_total_tokens", inputs["optional"]) result = sampler().run( model=object(), width=128, height=64, size_source="Legacy", aspect="Auto", preset="Draft", custom_mp=0.3,