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
fix(minimax-h3): validate the canvas like the frame count
Lincoln Stein1c85460252b7
diff --git a/invokeai/app/invocations/minimax_h3_denoise.py b/invokeai/app/invocations/minimax_h3_denoise.pyindex 2c63fd27d4..8c4a577b12 100644--- a/invokeai/app/invocations/minimax_h3_denoise.py+++ b/invokeai/app/invocations/minimax_h3_denoise.py@@ -41,6 +41,7 @@ from invokeai.backend.minimax_h3.sampling import (MINIMAX_H3_SPATIAL_COMPRESSION,MINIMAX_H3_VAE_LATENT_CHANNELS,build_denoise_state,+ validate_canvas,validate_num_frames,)from invokeai.backend.minimax_h3.transformer_minimax_h3 import MiniMaxH3Transformer3DModel@@ -144,6 +145,7 @@ class MiniMaxH3DenoiseInvocation(BaseInvocation):@torch.no_grad()def invoke(self, context: InvocationContext) -> MiniMaxH3DenoiseOutput:validate_num_frames(self.num_frames)+ validate_canvas(self.height, self.width)device = TorchDevice.choose_torch_device()diff --git a/invokeai/backend/minimax_h3/sampling.py b/invokeai/backend/minimax_h3/sampling.pyindex 3994f7db85..3f2d7235ac 100644--- a/invokeai/backend/minimax_h3/sampling.py+++ b/invokeai/backend/minimax_h3/sampling.py@@ -19,12 +19,17 @@ from diffusers.utils.torch_utils import randn_tensorfrom invokeai.backend.minimax_h3.packing import (MINIMAX_H3_AUDIO_CHANNELS,+ MINIMAX_H3_CANVAS_MULTIPLE,MINIMAX_H3_FPS,MINIMAX_H3_FRAMES_PER_CHUNK,MINIMAX_H3_KEYFRAME_NOISE_AUG,MINIMAX_H3_LATENTS_PER_CHUNK,+ MINIMAX_H3_MAX_ASPECT_RATIO,MINIMAX_H3_MAX_DURATION,+ MINIMAX_H3_MAX_PIXELS,+ MINIMAX_H3_MIN_ASPECT_RATIO,MINIMAX_H3_MIN_DURATION,+ MINIMAX_H3_SHORT_EDGE,MiniMaxH3PackedSequence,build_packed_sequence,build_row_timesteps,@@ -75,6 +80,44 @@ def validate_num_frames(num_frames: int) -> None:)+def validate_canvas(height: int, width: int) -> None:+ """Reject canvases the FL2VA checkpoint was not released for.++ H3 was released for a 768 px short edge under a soft ``768 * 1344`` area cap, with aspect+ ratios from 1:4 to 4:1 and both axes on the 32 px grid. Without this the packed sequence+ simply grows with the canvas — a 4096x4096 request builds a ~607k-row sequence against the+ native canvas's ~38k — and the run surfaces as an out-of-memory failure rather than a named+ error, while ``num_frames`` one off the grid is rejected precisely.++ The area test carries the rounding slack rather than comparing to the cap directly:+ :func:`~invokeai.backend.minimax_h3.packing.resolve_canvas_size` rounds both axes to the 32+ grid *after* applying the area cap, so its own outputs reach ~1.04x the cap (e.g. 576x1856).+ Shrinking each axis by the maximum rounding-up slack asks the real question — could this+ canvas have come from rounding a within-budget canvas up? — and accepts every canvas+ ``resolve_canvas_size`` can emit.+ """+ if height <= 0 or width <= 0:+ raise ValueError(f"Canvas dimensions must be positive, got {width}x{height}.")+ if height % MINIMAX_H3_CANVAS_MULTIPLE or width % MINIMAX_H3_CANVAS_MULTIPLE:+ raise ValueError(+ f"MiniMax H3 requires both canvas axes to be multiples of "+ f"{MINIMAX_H3_CANVAS_MULTIPLE}, got {width}x{height}."+ )++ ratio = width / 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 {width}x{height} ({ratio:g}).")++ slack = MINIMAX_H3_CANVAS_MULTIPLE // 2+ if (height - slack) * (width - slack) > MINIMAX_H3_MAX_PIXELS:+ raise ValueError(+ f"MiniMax H3 was released for a {MINIMAX_H3_SHORT_EDGE}px short edge with a soft area cap of "+ f"{MINIMAX_H3_MAX_PIXELS} pixels ({MINIMAX_H3_SHORT_EDGE}x{MINIMAX_H3_MAX_PIXELS // MINIMAX_H3_SHORT_EDGE}); "+ f"{width}x{height} is {width * height / MINIMAX_H3_MAX_PIXELS:.1f}x that budget. Larger canvases grow the "+ "packed sequence past what the model can attend over and will exhaust device memory."+ )++def build_schedulers(num_inference_steps: int, device: torch.device) -> tuple[MiniMaxH3Scheduler, MiniMaxH3Scheduler]:"""The two schedules of a request: video (shift 12.0) and audio (shift 3.0)."""scheduler = MiniMaxH3Scheduler(shift=MINIMAX_H3_VIDEO_FLOW_SHIFT)diff --git a/tests/backend/minimax_h3/test_sampling.py b/tests/backend/minimax_h3/test_sampling.pyindex d8bbe56d3e..94387243b0 100644--- a/tests/backend/minimax_h3/test_sampling.py+++ b/tests/backend/minimax_h3/test_sampling.py@@ -6,9 +6,46 @@ import torchfrom invokeai.backend.minimax_h3.packing import (align_num_frames,audio_latent_num_frames,+ resolve_canvas_size,video_latent_num_frames,)-from invokeai.backend.minimax_h3.sampling import build_denoise_state, validate_num_frames+from invokeai.backend.minimax_h3.sampling import build_denoise_state, validate_canvas, validate_num_frames+++class TestCanvas:+ def test_every_resolvable_canvas_is_accepted(self):+ # The guard must never reject a canvas resolve_canvas_size can emit. Rounding both axes to+ # the 32 grid happens *after* the area cap, so its own outputs reach ~1.04x the cap.+ canvases = set()+ for index in range(1501):+ ratio = min(0.25 + index * (3.75 / 1500), 4.0)+ canvases.add(resolve_canvas_size(ratio, 1.0))+ assert len(canvases) > 50+ for height, width in canvases:+ validate_canvas(height, width)++ def test_native_canvas_accepted(self):+ validate_canvas(768, 1344)+ validate_canvas(1344, 768)++ def test_oversized_canvas_rejected(self):+ # 4096x4096 builds a ~607k-row packed sequence against the native canvas's ~38k.+ with pytest.raises(ValueError, match="soft area cap"):+ validate_canvas(4096, 4096)+ with pytest.raises(ValueError, match="soft area cap"):+ validate_canvas(2048, 2048)++ def test_off_grid_canvas_rejected(self):+ with pytest.raises(ValueError, match="multiples of 32"):+ validate_canvas(768, 1000)++ def test_extreme_aspect_ratio_rejected(self):+ with pytest.raises(ValueError, match="aspect ratios"):+ validate_canvas(128, 1344)++ def test_nonpositive_rejected(self):+ with pytest.raises(ValueError, match="must be positive"):+ validate_canvas(0, 1344)class TestFrameGrid: