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.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
feat(minimax-h3): resolution presets in the Ideal Dimensions node
Lincoln Stein6273dd4ca769
diff --git a/invokeai/app/invocations/minimax_h3_ideal_dimensions.py b/invokeai/app/invocations/minimax_h3_ideal_dimensions.pyindex 2f99f20dbd..5baabb2387 100644--- a/invokeai/app/invocations/minimax_h3_ideal_dimensions.py+++ b/invokeai/app/invocations/minimax_h3_ideal_dimensions.py@@ -1,19 +1,30 @@"""Compute the MiniMax H3 canvas for a source image's aspect ratio.-Unlike Wan (which offers several target resolutions), H3 was released for exactly one-canvas family: a 768 px short edge under a soft area cap of 768x1344, both axes rounded-to the nearest multiple of 32, aspect ratios limited to 1:4 through 4:1. That policy is-implemented by :func:`invokeai.backend.minimax_h3.packing.resolve_canvas_size` (a-first-party port of the released pipeline's canvas resolution); this node is a thin-workflow-graph wrapper so image-to-video workflows can derive the canvas from the-uploaded keyframe instead of asking the user to type matching width/height values.+H3 was released for exactly one canvas family: a 768 px short edge under a soft area cap+of 768x1344, both axes rounded to the nearest multiple of 32, aspect ratios limited to+1:4 through 4:1. That policy is implemented by+:func:`invokeai.backend.minimax_h3.packing.resolve_canvas_size` (a first-party port of+the released pipeline's canvas resolution). This node wraps it for workflow graphs so+image-to-video workflows can derive the canvas from the uploaded keyframe instead of+asking the user to type matching width/height values, and adds a reduced "768 lowres"+preset (:func:`~invokeai.backend.minimax_h3.packing.resolve_lowres_canvas_size`) that+pins the LONG edge to 768 for cheaper preview/test renders."""+from typing import Literal+from invokeai.app.invocations.baseinvocation import BaseInvocation, Classification, invocationfrom invokeai.app.invocations.fields import InputFieldfrom invokeai.app.invocations.ideal_size import IdealSizeOutputfrom invokeai.app.services.shared.invocation_context import InvocationContext-from invokeai.backend.minimax_h3.packing import resolve_canvas_size+from invokeai.backend.minimax_h3.packing import resolve_canvas_size, resolve_lowres_canvas_size++MiniMaxH3TargetResolution = Literal["768 highres", "768 lowres"]++MINIMAX_H3_TARGET_RESOLUTION_LABELS: dict[str, str] = {+ "768 highres": "768 highres (native: short edge 768, cap 768x1344)",+ "768 lowres": "768 lowres (long edge 768 — smaller, faster)",+}@invocation(@@ -21,18 +32,21 @@ from invokeai.backend.minimax_h3.packing import resolve_canvas_sizetitle="MiniMax H3 Ideal Dimensions",tags=["minimax", "video", "dimensions", "math"],category="video",- version="1.0.0",+ version="1.1.0",classification=Classification.Prototype,)class MiniMaxH3IdealDimensionsInvocation(BaseInvocation):"""Ideal dimensions for MiniMax H3 from a source image's aspect ratio.- Applies the released pipeline's canvas policy: short edge 768, soft area cap of- 768x1344, both axes rounded to the nearest multiple of 32. Only the aspect ratio of- the inputs matters. Aspect ratios beyond 1:4 / 4:1 are rejected. Wire from ``Image- Primitive``'s width/height outputs and into the width/height of ``Prompt - MiniMax- H3``, ``Frame Conditioning - MiniMax H3`` and ``Denoise - MiniMax H3`` (all three- must share the same canvas).+ "768 highres" applies the released pipeline's canvas policy: short edge 768, soft+ area cap of 768x1344. "768 lowres" pins the LONG edge to 768 instead, giving a+ canvas with roughly half the pixels for non-square ratios (e.g. a 2:3 source becomes+ 512x768 instead of 768x1152) — faster and cheaper, at some cost in fidelity since it+ is below the model's training resolution. Both presets round each axis to the+ nearest multiple of 32. Only the aspect ratio of the inputs matters. Aspect ratios+ beyond 1:4 / 4:1 are rejected. Wire from ``Image Primitive``'s width/height outputs+ and into the width/height of ``Prompt - MiniMax H3``, ``Frame Conditioning - MiniMax+ H3`` and ``Denoise - MiniMax H3`` (all three must share the same canvas)."""width: int = InputField(@@ -45,8 +59,18 @@ class MiniMaxH3IdealDimensionsInvocation(BaseInvocation):gt=0,description="Source image height in pixels.",)+ target_resolution: MiniMaxH3TargetResolution = InputField(+ default="768 highres",+ description=(+ "Canvas preset. '768 highres' is H3's native policy (short edge 768, soft cap "+ "768x1344). '768 lowres' pins the long edge to 768 for smaller, faster test "+ "renders (e.g. 512x768 from a 2:3 source) at some cost in fidelity."+ ),+ ui_choice_labels=MINIMAX_H3_TARGET_RESOLUTION_LABELS,+ )def invoke(self, context: InvocationContext) -> IdealSizeOutput:- # resolve_canvas_size returns (height, width).- h, w = resolve_canvas_size(float(self.width), float(self.height))+ resolver = resolve_lowres_canvas_size if self.target_resolution == "768 lowres" else resolve_canvas_size+ # Both resolvers return (height, width).+ h, w = resolver(float(self.width), float(self.height))return IdealSizeOutput(width=w, height=h)diff --git a/invokeai/app/services/workflow_records/default_workflows/First Frame to Video - MiniMax H3.json b/invokeai/app/services/workflow_records/default_workflows/First Frame to Video - MiniMax H3.jsonindex 23a60dc9eb..6ce5508c2d 100644--- a/invokeai/app/services/workflow_records/default_workflows/First Frame to Video - MiniMax H3.json+++ b/invokeai/app/services/workflow_records/default_workflows/First Frame to Video - MiniMax H3.json@@ -351,7 +351,7 @@"type": "invocation","data": {"id": "9e8d7c6b-5a4f-4e3d-9c2b-1a0f9e8d7c6b",- "version": "1.0.0",+ "version": "1.1.0","nodePack": "invokeai","label": "","notes": "",@@ -368,6 +368,12 @@"label": "","description": "","value": 1024+ },+ "target_resolution": {+ "name": "target_resolution",+ "label": "",+ "description": "",+ "value": "768 highres"}},"isOpen": true,diff --git a/invokeai/backend/minimax_h3/packing.py b/invokeai/backend/minimax_h3/packing.pyindex 8b7eb6597e..e03123aa45 100644--- a/invokeai/backend/minimax_h3/packing.py+++ b/invokeai/backend/minimax_h3/packing.py@@ -126,6 +126,19 @@ class MiniMaxH3PackedSequence:num_condition_audio_rows: int+def _validated_aspect_ratio(aspect_width: float, aspect_height: float) -> float:+ """Validate an aspect pair against H3's 1:4 – 4:1 envelope and return width/height."""+ if aspect_width <= 0 or aspect_height <= 0:+ raise ValueError(f"The aspect ratio must be positive, got {aspect_width}:{aspect_height}.")++ ratio = aspect_width / aspect_height+ if not MINIMAX_H3_MIN_ASPECT_RATIO <= ratio <= MINIMAX_H3_MAX_ASPECT_RATIO:+ raise ValueError(+ f"MiniMax-H3 supports aspect ratios from 1:4 to 4:1, got {aspect_width}:{aspect_height} ({ratio:g})."+ )+ return ratio++def resolve_canvas_size(aspect_width: float, aspect_height: float) -> tuple[int, int]:r"""Resolve a display aspect ratio into a MiniMax-H3 canvas.@@ -141,14 +154,7 @@ def resolve_canvas_size(aspect_width: float, aspect_height: float) -> tuple[int,Returns:`tuple[int, int]`: the `(height, width)` of the canvas."""- if aspect_width <= 0 or aspect_height <= 0:- raise ValueError(f"The aspect ratio must be positive, got {aspect_width}:{aspect_height}.")-- ratio = aspect_width / aspect_height- if not MINIMAX_H3_MIN_ASPECT_RATIO <= ratio <= MINIMAX_H3_MAX_ASPECT_RATIO:- raise ValueError(- f"MiniMax-H3 supports aspect ratios from 1:4 to 4:1, got {aspect_width}:{aspect_height} ({ratio:g})."- )+ ratio = _validated_aspect_ratio(aspect_width, aspect_height)if ratio >= 1.0:width, height = MINIMAX_H3_SHORT_EDGE * ratio, float(MINIMAX_H3_SHORT_EDGE)@@ -164,6 +170,34 @@ def resolve_canvas_size(aspect_width: float, aspect_height: float) -> tuple[int,return max(multiple, round(height / multiple) * multiple), max(multiple, round(width / multiple) * multiple)+def resolve_lowres_canvas_size(aspect_width: float, aspect_height: float) -> tuple[int, int]:+ r"""+ Resolve a display aspect ratio into a reduced-size MiniMax-H3 canvas with a 768 px LONG edge.++ This is not a released H3 canvas family: the model was trained for a 768 short edge+ (see :func:`resolve_canvas_size`). Pinning the long edge instead yields a canvas with roughly half the pixels+ for non-square ratios — useful for fast preview/test renders at some cost in fidelity. The short edge follows+ the aspect ratio and both axes are rounded to the nearest multiple of 32; the area always sits far below the+ `768 * 1344` cap, so no cap scaling is applied. Only the ratio of the two arguments matters.++ Args:+ aspect_width (`float`): Width of the target ratio.+ aspect_height (`float`): Height of the target ratio.++ Returns:+ `tuple[int, int]`: the `(height, width)` of the canvas.+ """+ ratio = _validated_aspect_ratio(aspect_width, aspect_height)++ if ratio >= 1.0:+ width, height = float(MINIMAX_H3_SHORT_EDGE), MINIMAX_H3_SHORT_EDGE / ratio+ else:+ width, height = MINIMAX_H3_SHORT_EDGE * ratio, float(MINIMAX_H3_SHORT_EDGE)++ multiple = MINIMAX_H3_CANVAS_MULTIPLE+ return max(multiple, round(height / multiple) * multiple), max(multiple, round(width / multiple) * multiple)++def align_num_frames(num_frames: int) -> int:r"""Snap a frame count up to the next `17 * n + 5` the video VAE can encode.diff --git a/invokeai/frontend/web/openapi.json b/invokeai/frontend/web/openapi.jsonindex 2c4ac5da2b..06697020eb 100644--- a/invokeai/frontend/web/openapi.json+++ b/invokeai/frontend/web/openapi.json@@ -66306,7 +66306,7 @@"category": "video","class": "invocation","classification": "prototype",- "description": "Ideal dimensions for MiniMax H3 from a source image's aspect ratio.\n\nApplies the released pipeline's canvas policy: short edge 768, soft area cap of\n768x1344, both axes rounded to the nearest multiple of 32. Only the aspect ratio of\nthe inputs matters. Aspect ratios beyond 1:4 / 4:1 are rejected. Wire from ``Image\nPrimitive``'s width/height outputs and into the width/height of ``Prompt - MiniMax\nH3``, ``Frame Conditioning - MiniMax H3`` and ``Denoise - MiniMax H3`` (all three\nmust share the same canvas).",+ "description": "Ideal dimensions for MiniMax H3 from a source image's aspect ratio.\n\n\"768 highres\" applies the released pipeline's canvas policy: short edge 768, soft\narea cap of 768x1344. \"768 lowres\" pins the LONG edge to 768 instead, giving a\ncanvas with roughly half the pixels for non-square ratios (e.g. a 2:3 source becomes\n512x768 instead of 768x1152) \u2014 faster and cheaper, at some cost in fidelity since it\nis below the model's training resolution. Both presets round each axis to the\nnearest multiple of 32. Only the aspect ratio of the inputs matters. Aspect ratios\nbeyond 1:4 / 4:1 are rejected. Wire from ``Image Primitive``'s width/height outputs\nand into the width/height of ``Prompt - MiniMax H3``, ``Frame Conditioning - MiniMax\nH3`` and ``Denoise - MiniMax H3`` (all three must share the same canvas).","node_pack": "invokeai","properties": {"id": {@@ -66355,6 +66355,21 @@"title": "Height","type": "integer"},+ "target_resolution": {+ "default": "768 highres",+ "description": "Canvas preset. '768 highres' is H3's native policy (short edge 768, soft cap 768x1344). '768 lowres' pins the long edge to 768 for smaller, faster test renders (e.g. 512x768 from a 2:3 source) at some cost in fidelity.",+ "enum": ["768 highres", "768 lowres"],+ "field_kind": "input",+ "input": "any",+ "orig_default": "768 highres",+ "orig_required": false,+ "title": "Target Resolution",+ "type": "string",+ "ui_choice_labels": {+ "768 highres": "768 highres (native: short edge 768, cap 768x1344)",+ "768 lowres": "768 lowres (long edge 768 \u2014 smaller, faster)"+ }+ },"type": {"const": "minimax_h3_ideal_dimensions","default": "minimax_h3_ideal_dimensions",@@ -66367,7 +66382,7 @@"tags": ["minimax", "video", "dimensions", "math"],"title": "MiniMax H3 Ideal Dimensions","type": "object",- "version": "1.0.0",+ "version": "1.1.0","output": {"$ref": "#/components/schemas/IdealSizeOutput"}diff --git a/invokeai/frontend/web/src/services/api/schema.ts b/invokeai/frontend/web/src/services/api/schema.tsindex 8923e69b8b..6bec9614e7 100644--- a/invokeai/frontend/web/src/services/api/schema.ts+++ b/invokeai/frontend/web/src/services/api/schema.ts@@ -27945,12 +27945,15 @@ export type components = {* MiniMax H3 Ideal Dimensions* @description Ideal dimensions for MiniMax H3 from a source image's aspect ratio.*- * Applies the released pipeline's canvas policy: short edge 768, soft area cap of- * 768x1344, both axes rounded to the nearest multiple of 32. Only the aspect ratio of- * the inputs matters. Aspect ratios beyond 1:4 / 4:1 are rejected. Wire from ``Image- * Primitive``'s width/height outputs and into the width/height of ``Prompt - MiniMax- * H3``, ``Frame Conditioning - MiniMax H3`` and ``Denoise - MiniMax H3`` (all three- * must share the same canvas).+ * "768 highres" applies the released pipeline's canvas policy: short edge 768, soft+ * area cap of 768x1344. "768 lowres" pins the LONG edge to 768 instead, giving a+ * canvas with roughly half the pixels for non-square ratios (e.g. a 2:3 source becomes+ * 512x768 instead of 768x1152) — faster and cheaper, at some cost in fidelity since it+ * is below the model's training resolution. Both presets round each axis to the+ * nearest multiple of 32. Only the aspect ratio of the inputs matters. Aspect ratios+ * beyond 1:4 / 4:1 are rejected. Wire from ``Image Primitive``'s width/height outputs+ * and into the width/height of ``Prompt - MiniMax H3``, ``Frame Conditioning - MiniMax+ * H3`` and ``Denoise - MiniMax H3`` (all three must share the same canvas).*/MiniMaxH3IdealDimensionsInvocation: {/**@@ -27982,6 +27985,13 @@ export type components = {* @default 1024*/height?: number;+ /**+ * Target Resolution+ * @description Canvas preset. '768 highres' is H3's native policy (short edge 768, soft cap 768x1344). '768 lowres' pins the long edge to 768 for smaller, faster test renders (e.g. 512x768 from a 2:3 source) at some cost in fidelity.+ * @default 768 highres+ * @enum {string}+ */+ target_resolution?: "768 highres" | "768 lowres";/*** type* @default minimax_h3_ideal_dimensionsdiff --git a/tests/app/invocations/test_minimax_h3_ideal_dimensions.py b/tests/app/invocations/test_minimax_h3_ideal_dimensions.pyindex c4cb3d982b..2fb7d93e76 100644--- a/tests/app/invocations/test_minimax_h3_ideal_dimensions.py+++ b/tests/app/invocations/test_minimax_h3_ideal_dimensions.py@@ -13,8 +13,8 @@ from invokeai.backend.minimax_h3.packing import ()-def _resolve(w: int, h: int) -> tuple[int, int]:- out = MiniMaxH3IdealDimensionsInvocation(width=w, height=h).invoke(None) # type: ignore[arg-type]+def _resolve(w: int, h: int, **kwargs) -> tuple[int, int]:+ out = MiniMaxH3IdealDimensionsInvocation(width=w, height=h, **kwargs).invoke(None) # type: ignore[arg-type]return out.width, out.height@@ -38,6 +38,32 @@ class TestCommonResolutions:assert _resolve(192, 108) == _resolve(1920, 1080) == _resolve(3840, 2160)+class TestTargetResolutionPresets:+ def test_default_is_native_highres(self) -> None:+ # The pre-1.1.0 behavior: adding the dropdown must not change stored workflows.+ assert _resolve(1024, 1536) == _resolve(1024, 1536, target_resolution="768 highres") == (768, 1152)++ @pytest.mark.parametrize(+ "w, h, expected",+ [+ (1024, 1536, (512, 768)), # 2:3 — the "small test render" case+ (1920, 1080, (768, 448)), # 16:9 — true 432 short edge rounds up to the 32-grid+ (1080, 1920, (448, 768)), # 9:16+ (1024, 1024, (768, 768)), # square: both presets agree+ ],+ )+ def test_lowres_pins_long_edge(self, w: int, h: int, expected: tuple[int, int]) -> None:+ assert _resolve(w, h, target_resolution="768 lowres") == expected++ @pytest.mark.parametrize("w, h", [(1920, 1080), (500, 500), (1000, 300), (300, 1000), (4032, 3024)])+ def test_lowres_never_larger_than_highres(self, w: int, h: int) -> None:+ lw, lh = _resolve(w, h, target_resolution="768 lowres")+ hw, hh = _resolve(w, h, target_resolution="768 highres")+ assert lw * lh <= hw * hh+ assert lw % MINIMAX_H3_CANVAS_MULTIPLE == 0+ assert lh % MINIMAX_H3_CANVAS_MULTIPLE == 0++class TestPostconditions:@pytest.mark.parametrize("w, h", [(1920, 1080), (500, 500), (1000, 300), (300, 1000), (4032, 3024)])def test_grid_and_area(self, w: int, h: int) -> None:diff --git a/tests/backend/minimax_h3/test_sampling.py b/tests/backend/minimax_h3/test_sampling.pyindex d8bbe56d3e..b0f7d30125 100644--- a/tests/backend/minimax_h3/test_sampling.py+++ b/tests/backend/minimax_h3/test_sampling.py@@ -6,6 +6,8 @@ import torchfrom invokeai.backend.minimax_h3.packing import (align_num_frames,audio_latent_num_frames,+ resolve_canvas_size,+ resolve_lowres_canvas_size,video_latent_num_frames,)from invokeai.backend.minimax_h3.sampling import build_denoise_state, validate_num_frames@@ -52,6 +54,39 @@ class TestFrameGrid:assert audio_latent_num_frames(124) == round(124 / 24 * 40)+class TestLowresCanvasResolution:+ # The native short-edge-768 policy is covered by tests/app/invocations/test_minimax_h3_ideal_dimensions.py.++ def test_lowres_pins_the_long_edge(self):+ # Same aspect inputs, but the LONG edge is fixed at 768.+ assert resolve_lowres_canvas_size(1, 1) == (768, 768)+ # 2:3 portrait -> 512x768 (the user-facing "small test render" case).+ assert resolve_lowres_canvas_size(800, 1200) == (768, 512)+ assert resolve_lowres_canvas_size(1200, 800) == (512, 768)+ # 16:9 -> short edge 432 rounds to the nearest multiple of 32 (448).+ assert resolve_lowres_canvas_size(16, 9) == (448, 768)+ assert resolve_lowres_canvas_size(9, 16) == (768, 448)++ def test_lowres_never_exceeds_the_highres_area(self):+ for w, h in ((1, 1), (16, 9), (9, 16), (2, 3), (4, 1), (1, 4), (1024, 1000)):+ lo_h, lo_w = resolve_lowres_canvas_size(w, h)+ hi_h, hi_w = resolve_canvas_size(w, h)+ assert lo_h * lo_w <= hi_h * hi_w+ assert lo_h % 32 == 0 and lo_w % 32 == 0++ def test_extreme_aspect_ratios_stay_on_grid(self):+ # 4:1 is the limit of the supported envelope; 768/4 = 192 divides the grid exactly (6 * 32).+ assert resolve_lowres_canvas_size(4, 1) == (192, 768)+ assert resolve_lowres_canvas_size(1, 4) == (768, 192)++ def test_invalid_aspects_rejected_by_both_presets(self):+ for fn in (resolve_canvas_size, resolve_lowres_canvas_size):+ with pytest.raises(ValueError, match="positive"):+ fn(0, 100)+ with pytest.raises(ValueError, match="1:4"):+ fn(9, 1)++def _build_state(seed: int, with_keyframe: bool = False):kwargs = {}if with_keyframe: