Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

Add dype area option (#8844)

Jonathanbacdfecb1365
diff --git a/invokeai/app/invocations/flux_denoise.py b/invokeai/app/invocations/flux_denoise.py
index ff002b15cf..d6102b105b 100644
--- a/invokeai/app/invocations/flux_denoise.py
+++ b/invokeai/app/invocations/flux_denoise.py
@@ -71,7 +71,7 @@ from invokeai.backend.util.devices import TorchDevice
title="FLUX Denoise",
tags=["image", "flux"],
category="image",
- version="4.5.0",
+ version="4.5.1",
)
class FluxDenoiseInvocation(BaseInvocation):
"""Run denoising process with a FLUX transformer model."""
@@ -176,7 +176,10 @@ class FluxDenoiseInvocation(BaseInvocation):
# DyPE (Dynamic Position Extrapolation) for high-resolution generation
dype_preset: DyPEPreset = InputField(
default=DYPE_PRESET_OFF,
- description="DyPE preset for high-resolution generation. 'auto' enables automatically for resolutions > 1536px. '4k' uses optimized settings for 4K output.",
+ description=(
+ "DyPE preset for high-resolution generation. 'auto' enables automatically for resolutions > 1536px. "
+ "'area' enables automatically based on image area. '4k' uses optimized settings for 4K output."
+ ),
ui_order=100,
ui_choice_labels=DYPE_PRESET_LABELS,
)
diff --git a/invokeai/backend/flux/dype/__init__.py b/invokeai/backend/flux/dype/__init__.py
index 9e82c27fad..eebcfc45df 100644
--- a/invokeai/backend/flux/dype/__init__.py
+++ b/invokeai/backend/flux/dype/__init__.py
@@ -10,11 +10,13 @@ from invokeai.backend.flux.dype.base import DyPEConfig
from invokeai.backend.flux.dype.embed import DyPEEmbedND
from invokeai.backend.flux.dype.presets import (
DYPE_PRESET_4K,
+ DYPE_PRESET_AREA,
DYPE_PRESET_AUTO,
DYPE_PRESET_LABELS,
DYPE_PRESET_MANUAL,
DYPE_PRESET_OFF,
DyPEPreset,
+ get_dype_config_for_area,
get_dype_config_for_resolution,
)
@@ -25,7 +27,9 @@ __all__ = [
"DYPE_PRESET_OFF",
"DYPE_PRESET_MANUAL",
"DYPE_PRESET_AUTO",
+ "DYPE_PRESET_AREA",
"DYPE_PRESET_4K",
"DYPE_PRESET_LABELS",
+ "get_dype_config_for_area",
"get_dype_config_for_resolution",
]
diff --git a/invokeai/backend/flux/dype/presets.py b/invokeai/backend/flux/dype/presets.py
index 97499ae239..f6c20df89e 100644
--- a/invokeai/backend/flux/dype/presets.py
+++ b/invokeai/backend/flux/dype/presets.py
@@ -1,17 +1,19 @@
"""DyPE presets and automatic configuration."""
+import math
from dataclasses import dataclass
from typing import Literal
from invokeai.backend.flux.dype.base import DyPEConfig
# DyPE preset type - using Literal for proper frontend dropdown support
-DyPEPreset = Literal["off", "manual", "auto", "4k"]
+DyPEPreset = Literal["off", "manual", "auto", "area", "4k"]
# Constants for preset values
DYPE_PRESET_OFF: DyPEPreset = "off"
DYPE_PRESET_MANUAL: DyPEPreset = "manual"
DYPE_PRESET_AUTO: DyPEPreset = "auto"
+DYPE_PRESET_AREA: DyPEPreset = "area"
DYPE_PRESET_4K: DyPEPreset = "4k"
# Human-readable labels for the UI
@@ -19,6 +21,7 @@ DYPE_PRESET_LABELS: dict[str, str] = {
"off": "Off",
"manual": "Manual",
"auto": "Auto (>1536px)",
+ "area": "Area (auto)",
"4k": "4K Optimized",
}
@@ -88,6 +91,48 @@ def get_dype_config_for_resolution(
)
+def get_dype_config_for_area(
+ width: int,
+ height: int,
+ base_resolution: int = 1024,
+) -> DyPEConfig | None:
+ """Automatically determine DyPE config based on target area.
+
+ Uses sqrt(area/base_area) as an effective side-length ratio.
+ DyPE is enabled only when target area exceeds base area.
+
+ Returns:
+ DyPEConfig if DyPE should be enabled, None otherwise
+ """
+ area = width * height
+ base_area = base_resolution**2
+
+ if area <= base_area:
+ return None
+
+ area_ratio = area / base_area
+ effective_side_ratio = math.sqrt(area_ratio) # 1.0 at base, 2.0 at 2K (if base is 1K)
+
+ # Strength: keep original growth-with-size behavior, but make it 0 at base.
+ # This yields: 2K -> 4.0, 4K -> 8.0 (clamped), matching the prior intent.
+ dynamic_dype_scale = min(4.0 * (effective_side_ratio - 1.0), 8.0)
+
+ # Continuous exponent schedule:
+ # r=1 -> 0.5, r=2 -> 1.0, r=4 -> 2.0 (exact), smoothly varying in between.
+ x = math.log2(effective_side_ratio)
+ dype_exponent = 0.25 * (x**2) + 0.25 * x + 0.5
+ dype_exponent = max(0.5, min(dype_exponent, 2.0))
+
+ return DyPEConfig(
+ enable_dype=True,
+ base_resolution=base_resolution,
+ method="vision_yarn",
+ dype_scale=dynamic_dype_scale,
+ dype_exponent=dype_exponent,
+ dype_start_sigma=1.0,
+ )
+
+
def get_dype_config_from_preset(
preset: DyPEPreset,
width: int,
@@ -133,6 +178,14 @@ def get_dype_config_from_preset(
activation_threshold=1536,
)
+ if preset == DYPE_PRESET_AREA:
+ # Area-based preset - custom values are ignored
+ return get_dype_config_for_area(
+ width=width,
+ height=height,
+ base_resolution=1024,
+ )
+
# Use preset configuration (4K etc.) - custom values are ignored
preset_config = DYPE_PRESETS.get(preset)
if preset_config is None:
diff --git a/invokeai/frontend/web/openapi.json b/invokeai/frontend/web/openapi.json
index bf6c425d91..2878975eda 100644
--- a/invokeai/frontend/web/openapi.json
+++ b/invokeai/frontend/web/openapi.json
@@ -16879,7 +16879,7 @@
},
"DyPEPreset": {
"description": "Predefined DyPE configurations.",
- "enum": ["off", "auto", "4k"],
+ "enum": ["off", "auto", "area", "4k"],
"title": "DyPEPreset",
"type": "string"
},
diff --git a/invokeai/frontend/web/src/features/controlLayers/store/paramsSlice.ts b/invokeai/frontend/web/src/features/controlLayers/store/paramsSlice.ts
index 1f8ad18d35..3cc2606172 100644
--- a/invokeai/frontend/web/src/features/controlLayers/store/paramsSlice.ts
+++ b/invokeai/frontend/web/src/features/controlLayers/store/paramsSlice.ts
@@ -29,6 +29,7 @@ import type {
ParameterCLIPGEmbedModel,
ParameterCLIPLEmbedModel,
ParameterControlLoRAModel,
+ ParameterFluxDypePreset,
ParameterGuidance,
ParameterModel,
ParameterNegativePrompt,
@@ -72,7 +73,7 @@ const slice = createSlice({
setFluxScheduler: (state, action: PayloadAction<'euler' | 'heun' | 'lcm'>) => {
state.fluxScheduler = action.payload;
},
- setFluxDypePreset: (state, action: PayloadAction<'off' | 'manual' | 'auto' | '4k'>) => {
+ setFluxDypePreset: (state, action: PayloadAction<ParameterFluxDypePreset>) => {
state.fluxDypePreset = action.payload;
},
setFluxDypeScale: (state, action: PayloadAction<number>) => {
diff --git a/invokeai/frontend/web/src/features/nodes/types/common.ts b/invokeai/frontend/web/src/features/nodes/types/common.ts
index 25ab951ca2..2cfe637bee 100644
--- a/invokeai/frontend/web/src/features/nodes/types/common.ts
+++ b/invokeai/frontend/web/src/features/nodes/types/common.ts
@@ -72,7 +72,7 @@ export const zFluxSchedulerField = z.enum(['euler', 'heun', 'lcm']);
export const zZImageSchedulerField = z.enum(['euler', 'heun', 'lcm']);
// Flux DyPE (Dynamic Position Extrapolation) preset options for high-resolution generation
-export const zFluxDypePresetField = z.enum(['off', 'manual', 'auto', '4k']);
+export const zFluxDypePresetField = z.enum(['off', 'manual', 'auto', 'area', '4k']);
// Flux DyPE scale (magnitude λs) - 0.0-8.0, default 2.0
export const zFluxDypeScaleField = z.number().min(0).max(8);
diff --git a/invokeai/frontend/web/src/features/parameters/components/Core/ParamFluxDypePreset.tsx b/invokeai/frontend/web/src/features/parameters/components/Core/ParamFluxDypePreset.tsx
index 69f3892ce0..3625ea44f6 100644
--- a/invokeai/frontend/web/src/features/parameters/components/Core/ParamFluxDypePreset.tsx
+++ b/invokeai/frontend/web/src/features/parameters/components/Core/ParamFluxDypePreset.tsx
@@ -12,6 +12,7 @@ const FLUX_DYPE_PRESET_OPTIONS: ComboboxOption[] = [
{ value: 'off', label: 'Off' },
{ value: 'manual', label: 'Manual' },
{ value: 'auto', label: 'Auto (> 1536px)' },
+ { value: 'area', label: 'Area (auto)' },
{ value: '4k', label: '4K Optimized' },
];
diff --git a/invokeai/frontend/web/src/services/api/schema.ts b/invokeai/frontend/web/src/services/api/schema.ts
index 2249b91fdd..fc1888bb9d 100644
--- a/invokeai/frontend/web/src/services/api/schema.ts
+++ b/invokeai/frontend/web/src/services/api/schema.ts
@@ -8781,11 +8781,11 @@ export type components = {
kontext_conditioning?: components["schemas"]["FluxKontextConditioningField"] | components["schemas"]["FluxKontextConditioningField"][] | null;
/**
* Dype Preset
- * @description DyPE preset for high-resolution generation. 'auto' enables automatically for resolutions > 1536px. '4k' uses optimized settings for 4K output.
+ * @description DyPE preset for high-resolution generation. 'auto' enables automatically for resolutions > 1536px. 'area' enables automatically based on image area. '4k' uses optimized settings for 4K output.
* @default off
* @enum {string}
*/
- dype_preset?: "off" | "manual" | "auto" | "4k";
+ dype_preset?: "off" | "manual" | "auto" | "area" | "4k";
/**
* Dype Scale
* @description DyPE magnitude (λs). Higher values = stronger extrapolation. Only used when dype_preset is not 'off'.
@@ -8975,11 +8975,11 @@ export type components = {
kontext_conditioning?: components["schemas"]["FluxKontextConditioningField"] | components["schemas"]["FluxKontextConditioningField"][] | null;
/**
* Dype Preset
- * @description DyPE preset for high-resolution generation. 'auto' enables automatically for resolutions > 1536px. '4k' uses optimized settings for 4K output.
+ * @description DyPE preset for high-resolution generation. 'auto' enables automatically for resolutions > 1536px. 'area' enables automatically based on image area. '4k' uses optimized settings for 4K output.
* @default off
* @enum {string}
*/
- dype_preset?: "off" | "manual" | "auto" | "4k";
+ dype_preset?: "off" | "manual" | "auto" | "area" | "4k";
/**
* Dype Scale
* @description DyPE magnitude (λs). Higher values = stronger extrapolation. Only used when dype_preset is not 'off'.
diff --git a/tests/backend/flux/dype/test_dype.py b/tests/backend/flux/dype/test_dype.py
index 1dbcaee7ee..cc0b99011c 100644
--- a/tests/backend/flux/dype/test_dype.py
+++ b/tests/backend/flux/dype/test_dype.py
@@ -13,10 +13,12 @@ from invokeai.backend.flux.dype.base import (
from invokeai.backend.flux.dype.embed import DyPEEmbedND
from invokeai.backend.flux.dype.presets import (
DYPE_PRESET_4K,
+ DYPE_PRESET_AREA,
DYPE_PRESET_AUTO,
DYPE_PRESET_MANUAL,
DYPE_PRESET_OFF,
DYPE_PRESETS,
+ get_dype_config_for_area,
get_dype_config_for_resolution,
get_dype_config_from_preset,
)
@@ -264,6 +266,35 @@ class TestDyPEPresets:
assert config_4k is not None
assert config_4k.dype_scale > config_2k.dype_scale
+ def test_get_dype_config_for_area_below_threshold(self):
+ """When area is below threshold area, should return None."""
+ config = get_dype_config_for_area(
+ width=1024,
+ height=1024,
+ )
+ assert config is None
+
+ def test_get_dype_config_for_area_above_threshold(self):
+ """When area is above threshold area, should return config."""
+ config = get_dype_config_for_area(
+ width=2048,
+ height=1536,
+ base_resolution=1024,
+ )
+ assert config is not None
+ assert config.enable_dype is True
+ assert config.method == "vision_yarn"
+
+ def test_get_dype_config_from_preset_area(self):
+ """Preset AREA should use area-based config."""
+ config = get_dype_config_from_preset(
+ preset=DYPE_PRESET_AREA,
+ width=2048,
+ height=1536,
+ )
+ assert config is not None
+ assert config.enable_dype is True
+
def test_get_dype_config_from_preset_off(self):
"""Preset OFF should return None."""
config = get_dype_config_from_preset(