Allow V3.9 sampler to consume RefMods directly
This commit is contained in:
@@ -138,6 +138,14 @@ behaviour. The picker shows matching preview images when present.
|
|||||||
The maintained MiniMax H3 RefMod reader must be installed alongside DUMAS;
|
The maintained MiniMax H3 RefMod reader must be installed alongside DUMAS;
|
||||||
DUMAS does not duplicate that reader or override its node IDs.
|
DUMAS does not duplicate that reader or override its node IDs.
|
||||||
|
|
||||||
|
The vendored `DUMAS H3 Continuum · H3 Continuum Sampler V3.9` also exposes an
|
||||||
|
optional `RefMods (Optional)` socket. Connect the `H3_REF_MODS` output from a
|
||||||
|
RefMod loader or creator directly to that socket; the sampler clones the model
|
||||||
|
and attaches the RefMod bridge only for that run. `RefMod Retention` and
|
||||||
|
`RefMod Token Budget` are available beside the socket, while ordinary image
|
||||||
|
reference routing remains unchanged. The separate model bridge node is still
|
||||||
|
available for V3.8 and other samplers.
|
||||||
|
|
||||||
### DUMAS H3 RefMods to Continuum
|
### DUMAS H3 RefMods to Continuum
|
||||||
|
|
||||||
`DUMAS H3 RefMods to Continuum` is the minimal compatibility bridge for the
|
`DUMAS H3 RefMods to Continuum` is the minimal compatibility bridge for the
|
||||||
|
|||||||
@@ -83,6 +83,8 @@ def _namespace_class(node_class, *, node_id, category, display_name):
|
|||||||
# constructing the node search index.
|
# constructing the node search index.
|
||||||
namespaced.CATEGORY = category
|
namespaced.CATEGORY = category
|
||||||
namespaced.NODE_CATEGORY = category
|
namespaced.NODE_CATEGORY = category
|
||||||
|
if node_id == "DumasH3Continuum_H3ContinuumSamplerV39":
|
||||||
|
namespaced = _add_direct_refmod_input(namespaced)
|
||||||
namespaced.__module__ = __name__
|
namespaced.__module__ = __name__
|
||||||
namespaced.__qualname__ = node_class.__qualname__
|
namespaced.__qualname__ = node_class.__qualname__
|
||||||
namespaced.__name__ = node_class.__name__
|
namespaced.__name__ = node_class.__name__
|
||||||
@@ -90,6 +92,98 @@ def _namespace_class(node_class, *, node_id, category, display_name):
|
|||||||
return namespaced
|
return namespaced
|
||||||
|
|
||||||
|
|
||||||
|
def _add_direct_refmod_input(node_class):
|
||||||
|
"""Add the DUMAS direct RefMod path to the vendored V3.9 sampler.
|
||||||
|
|
||||||
|
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.
|
||||||
|
"""
|
||||||
|
original_input_types = node_class.INPUT_TYPES
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def INPUT_TYPES(cls):
|
||||||
|
schema = original_input_types()
|
||||||
|
schema = {name: dict(value) for name, value in schema.items()}
|
||||||
|
optional = dict(schema.get("optional", {}))
|
||||||
|
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):
|
||||||
|
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),
|
||||||
|
)
|
||||||
|
kwargs["model"] = bridge.attach(model, blocks, enabled=True)
|
||||||
|
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
|
||||||
|
return node_class
|
||||||
|
|
||||||
|
|
||||||
def _namespaced_mappings():
|
def _namespaced_mappings():
|
||||||
mappings = {}
|
mappings = {}
|
||||||
display = {}
|
display = {}
|
||||||
|
|||||||
@@ -21,7 +21,27 @@ class _ModernNode:
|
|||||||
return _Schema("UpstreamModern", "Upstream", "Modern")
|
return _Schema("UpstreamModern", "Upstream", "Modern")
|
||||||
|
|
||||||
|
|
||||||
|
class _SamplerBase:
|
||||||
|
@classmethod
|
||||||
|
def INPUT_TYPES(cls):
|
||||||
|
return {"required": {"model": ("MODEL",)}, "optional": {}}
|
||||||
|
|
||||||
|
def run(self, **kwargs):
|
||||||
|
return kwargs
|
||||||
|
|
||||||
|
|
||||||
|
class _Sampler(_SamplerBase):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class VendoredNamespaceTests(unittest.TestCase):
|
class VendoredNamespaceTests(unittest.TestCase):
|
||||||
|
def test_v39_sampler_exposes_direct_refmod_socket(self):
|
||||||
|
sampler = vendored._add_direct_refmod_input(_Sampler)
|
||||||
|
inputs = sampler.INPUT_TYPES()
|
||||||
|
self.assertEqual(inputs["optional"]["refmods"][0], "H3_REF_MODS")
|
||||||
|
self.assertIn("refmod_retention", inputs["optional"])
|
||||||
|
self.assertIn("refmod_max_total_tokens", inputs["optional"])
|
||||||
|
|
||||||
def test_legacy_and_modern_nodes_get_distinct_dumas_identity(self):
|
def test_legacy_and_modern_nodes_get_distinct_dumas_identity(self):
|
||||||
original_packages = vendored._PACKAGES
|
original_packages = vendored._PACKAGES
|
||||||
original_loader = vendored._load_pack
|
original_loader = vendored._load_pack
|
||||||
|
|||||||
Reference in New Issue
Block a user