Compare commits

..

1 Commits

Author SHA1 Message Date
Jukka Seppänen
0d0eb1bd7f
Merge 68d5d31096 into 20f5e474da 2026-05-10 00:25:07 +00:00
3 changed files with 45 additions and 30 deletions

View File

@ -14,8 +14,7 @@ class EmptyHiDreamO1LatentImage(io.ComfyNode):
def define_schema(cls) -> io.Schema:
return io.Schema(
node_id="EmptyHiDreamO1LatentImage",
display_name="Empty HiDream-O1 Latent Image",
category="latent/image",
category="latent/hidream_o1",
description=(
"Empty pixel-space latent for HiDream-O1-Image. When "
"snap_to_predefined is on, dimensions are matched (by aspect "
@ -41,7 +40,7 @@ class EmptyHiDreamO1LatentImage(io.ComfyNode):
@classmethod
def execute(cls, *, width: int, height: int, batch_size: int = 1,
snap_to_predefined: bool = True) -> io.NodeOutput:
if snap_to_predefined: #TODO: better way to handle this
if snap_to_predefined:
sw, sh = find_closest_resolution(width, height)
width, height = sw, sh
width = (width // 32) * 32
@ -54,17 +53,24 @@ class EmptyHiDreamO1LatentImage(io.ComfyNode):
class HiDreamO1ReferenceImages(io.ComfyNode):
"""Attach reference images to both positive and negative conditioning."""
"""Attach reference images to both positive and negative conditioning.
Refs are model-level inputs, not per-prompt CONDITIONING they must ride
on both CFG branches, otherwise CFG amplifies "with-refs vs no-refs"
instead of "edit prompt vs empty prompt with same refs" and saturation
blows out.
"""
@classmethod
def define_schema(cls) -> io.Schema:
return io.Schema(
node_id="HiDreamO1ReferenceImages",
display_name="HiDream-O1 Reference Images",
category="conditioning/image",
category="conditioning/hidream_o1",
description=(
"Attach 1-10 reference images to conditioning, one for edit instruction"
"or multiple for subject-driven personalization."
"Attach 1-10 reference images to BOTH positive and negative "
"conditioning for HiDream-O1 edit (K=1) or subject-driven "
"personalization (K=2..10). Refs must ride on both CFG "
"branches; this node enforces that."
),
inputs=[
io.Conditioning.Input(id="positive"),
@ -90,9 +96,14 @@ class HiDreamO1ReferenceImages(io.ComfyNode):
@classmethod
def execute(cls, *, positive, negative, images: io.Autogrow.Type) -> io.NodeOutput:
# Numeric-suffix order; alphabetic sort would give image_1, image_10, image_2, ...
refs = [images[f"image_{i}"] for i in range(1, 11) if f"image_{i}" in images]
positive = node_helpers.conditioning_set_values(positive, {"hidream_o1_ref_images": refs})
negative = node_helpers.conditioning_set_values(negative, {"hidream_o1_ref_images": refs})
positive = node_helpers.conditioning_set_values(
positive, {"hidream_o1_ref_images": refs},
)
negative = node_helpers.conditioning_set_values(
negative, {"hidream_o1_ref_images": refs},
)
return io.NodeOutput(positive, negative)
@ -103,22 +114,23 @@ class HiDreamO1Sampling(io.ComfyNode):
def define_schema(cls) -> io.Schema:
return io.Schema(
node_id="HiDreamO1Sampling",
display_name="HiDream-O1 Sampling",
category="advanced/model",
category="advanced/model/hidream_o1",
description=(
"Patch HiDream-O1's sigma shift and noise scaling factor. "
"Base model defaults: shift=3.0, s_noise=8.0. "
"Dev/flash sampler defaults: shift=1.0, s_noise=7.5."
"Full recipe: shift=3.0, s_noise=8.0. "
"Dev/flash recipe: shift=1.0, s_noise=7.5."
),
inputs=[
io.Model.Input(id="model"),
io.Float.Input(
id="shift", default=3.0, min=0.0, max=100.0, step=0.01,
tooltip="Flow-match sigma shift. Defaults: 3.0 for base, 1.0 for dev.",
tooltip="Flow-match sigma shift. 3.0 for full, 1.0 for dev.",
),
io.Float.Input(
id="s_noise", default=8.0, min=0.0, max=64.0, step=0.1,
tooltip=("HiDream-O1 noise scale (CONST_SCALED_NOISE). Defaults: 8.0 for base, 7.5 for dev/flash."
tooltip=(
"HiDream-O1 noise scale (CONST_SCALED_NOISE._s_noise). "
"8.0 for full, 7.5 for dev/flash."
),
),
],
@ -148,9 +160,11 @@ class SamplerEulerFlashFlowmatch(io.ComfyNode):
def define_schema(cls) -> io.Schema:
return io.Schema(
node_id="SamplerEulerFlashFlowmatch",
display_name="Sampler Euler Flash Flowmatch",
category="sampling/custom_sampling/samplers",
description=("HiDream-O1 dev/flash sampler with tunable per-step noise"),
description=(
"HiDream-O1 dev/flash sampler with tunable per-step noise "
"schedule (start, end, clip_std). Wire into SamplerCustom."
),
inputs=[
io.Float.Input(
id="s_noise_start", default=7.5, min=0.0, max=64.0, step=0.1,
@ -159,13 +173,17 @@ class SamplerEulerFlashFlowmatch(io.ComfyNode):
io.Float.Input(
id="s_noise_end", default=7.5, min=0.0, max=64.0, step=0.1,
tooltip=(
"Per-step noise scale at the last step. Default: 7.5 for dev/flash. "
"Differ from s_noise_start to linearly ramp noise across steps."
"Per-step noise scale at the last step. Equals "
"s_noise_start for upstream-default behaviour; differ "
"to ramp the noise across the trajectory."
),
),
io.Float.Input(
id="noise_clip_std", default=2.5, min=0.0, max=10.0, step=0.1,
tooltip=("Clamp per-step noise to +/- N*std. 0 disables.")
tooltip=(
"Clamp per-step noise to +/- N*std. 0 disables. "
"Upstream dev recipe: 2.5."
),
),
],
outputs=[io.Sampler.Output()],

View File

@ -63,7 +63,7 @@ class MathExpressionNode(io.ComfyNode):
@classmethod
def define_schema(cls) -> io.Schema:
autogrow = io.Autogrow.TemplateNames(
input=io.MultiType.Input("value", [io.Float, io.Int, io.Boolean]),
input=io.MultiType.Input("value", [io.Float, io.Int]),
names=list(string.ascii_lowercase),
min=1,
)
@ -82,7 +82,6 @@ class MathExpressionNode(io.ComfyNode):
outputs=[
io.Float.Output(display_name="FLOAT"),
io.Int.Output(display_name="INT"),
io.Boolean.Output(display_name="BOOL"),
],
)
@ -98,7 +97,7 @@ class MathExpressionNode(io.ComfyNode):
result = simple_eval(expression, names=context, functions=MATH_FUNCTIONS)
# bool check must come first because bool is a subclass of int in Python
if not isinstance(result, (int, float)):
if isinstance(result, bool) or not isinstance(result, (int, float)):
raise ValueError(
f"Math Expression '{expression}' must evaluate to a numeric result, "
f"got {type(result).__name__}: {result!r}"
@ -107,7 +106,7 @@ class MathExpressionNode(io.ComfyNode):
raise ValueError(
f"Math Expression '{expression}' produced a non-finite result: {result}"
)
return io.NodeOutput(float(result), int(result), bool(result))
return io.NodeOutput(float(result), int(result))
class MathExtension(ComfyExtension):

View File

@ -124,11 +124,9 @@ class TestMathExpressionExecute:
with pytest.raises(Exception, match="not defined"):
self._exec("str(a)", a=42)
def test_boolean_result(self):
result = self._exec("a > b", a=5, b=3)
assert result[2] is True
result = self._exec("a > b", a=3, b=5)
assert result[2] is False
def test_boolean_result_raises(self):
with pytest.raises(ValueError, match="got bool"):
self._exec("a > b", a=5, b=3)
def test_empty_expression_raises(self):
with pytest.raises(ValueError, match="Expression cannot be empty"):