diff --git a/nodes/minimax.py b/nodes/minimax.py index 766eac5..47e0103 100644 --- a/nodes/minimax.py +++ b/nodes/minimax.py @@ -685,6 +685,20 @@ class MiniMaxH3ReferenceToVideoFallback(io.ComfyNode): continue soundtrack = video_audios.get("ref_video_audio_" + name.rsplit("_", 1)[-1]) frames = _prepare_reference_video_frames(frames, frame_count) + # Grid-align the reference video canvas: comfy core's + # patchify_video floors each latent side into 2x2 patches, so an + # off-grid frame size (API callers can inject arbitrary media) + # would produce an odd latent dimension and crash sampling with + # "shape '[1, 24, ...]' is invalid for input of size N". ComfyUI + # builds with native H3 nodes do this alignment inside core's + # MiniMaxH3ReferenceToVideo; this fallback copy must match. + ref_height, ref_width = int(frames.shape[1]), int(frames.shape[2]) + aligned_ref_width = _align_canvas_dimension(ref_width) + aligned_ref_height = _align_canvas_dimension(ref_height) + if (aligned_ref_width, aligned_ref_height) != (ref_width, ref_height): + frames = _resize( + frames, aligned_ref_width, aligned_ref_height, "disabled" + ) aligned_count = frames.shape[0] canvas_height, canvas_width = frames.shape[1], frames.shape[2] if aligned_count < 5: diff --git a/nodes/project.py b/nodes/project.py index 06870ce..ebdb1a6 100644 --- a/nodes/project.py +++ b/nodes/project.py @@ -46,7 +46,7 @@ from ..utils.multitrack import ( MULTITRACK_RUNTIME_CACHE_KEY, multitrack_runtime_cache, ) -from .minimax import CANVAS_MULTIPLE +from .minimax import CANVAS_MULTIPLE, _align_canvas_dimension TYPE_FAST_MODEL_LOADER = io.Custom(io_type="FAST_MODEL_LOADER") @@ -1111,6 +1111,19 @@ class EasyMultiTrackProject(io.ComfyNode): if not uses_linked_prepare: _require_minimax_h3_model(model) info = parse_tracks_info(kwargs.get("tracks_info")) + # External app clients (the Moxie app drives this node through the + # ComfyUI API) can inject project dimensions that are not on the H3 + # 32px canvas grid; the MultiTrack Editor UI only offers grid sizes. + # Every latent side is pixels // 16 and the diffusion model patchifies + # that latent 2x2, so any off-grid side eventually reaches comfy's + # patchify_video as an odd latent dimension and crashes first sampling + # with "shape '[1, 24, ...]' is invalid for input of size N". Floor + # both sides onto the grid once, here, so media loading, reference + # encoding, both sampling passes and the exported project all agree + # on the same aligned canvas. Editor-selected sizes are already + # multiples of 32, so this is a no-op for UI workflows. + info["width"] = _align_canvas_dimension(info["width"]) + info["height"] = _align_canvas_dimension(info["height"]) hidden_inputs = getattr(cls, "hidden", None) validate_h3_project_outputs( info, diff --git a/tests/test_minimax_node.py b/tests/test_minimax_node.py index c827b76..45fff5d 100644 --- a/tests/test_minimax_node.py +++ b/tests/test_minimax_node.py @@ -2472,6 +2472,53 @@ def test_multitrack_h3_project_reads_ref_image_size_from_each_segment(monkeypatc assert conditioning["ref_image_size"] == "max" +def test_multitrack_h3_project_keeps_544x960_first_pass_on_grid(monkeypatch): + """Regression for the 2026-10-16 user crash report. + + A 544x960 single-pass project used to sample its hidden first pass at the + raw half resolution 272x480. The keyframe conditioned on that canvas is a + 17-wide latent, and comfy's patchify_video floors it into 2x2 patches, + crashing with "shape '[1, 24, 1, 1, 15, 2, 8, 2]' is invalid for input of + size 12240". The first pass must land on the 32px canvas grid instead. + """ + module = _load_minimax_node(monkeypatch) + module.comfy_nodes.NODE_CLASS_MAPPINGS["ImageResizeKJv2"] = _ImageResizeKJWithNvidia + inputs = _h3_project_inputs(sampling_mode=_h3_sampling_mode("single")) + inputs["tracks_info"][0]["width"] = 544 + inputs["tracks_info"][0]["height"] = 960 + + result = module.EasyMultiTrackProject.execute(**inputs) + conditioning = _graph_node(result, "easy minimaxH3ToVideo")["inputs"] + + # half of 544x960 stays on the 32px grid: 256x480 -> latent 16x30, even. + assert conditioning["width"] == 256 + assert conditioning["height"] == 480 + + +def test_multitrack_h3_project_aligns_off_grid_api_dimensions(monkeypatch): + """External app clients inject project dimensions through the ComfyUI API + that are not multiples of 32; the editor UI only offers grid sizes. The + project must run both sampling passes on the same grid-aligned canvas + instead of the raw injected size (odd latent -> patchify_video crash).""" + module = _load_minimax_node(monkeypatch) + module.comfy_nodes.NODE_CLASS_MAPPINGS["ImageResizeKJv2"] = _ImageResizeKJWithNvidia + inputs = _h3_project_inputs(sampling_mode=_h3_sampling_mode("dual")) + inputs["tracks_info"][0]["width"] = 530 + inputs["tracks_info"][0]["height"] = 964 + + result = module.EasyMultiTrackProject.execute(**inputs) + conditionings = [ + node["inputs"] + for node in result.expand.values() + if node["class_type"] == "easy minimaxH3ToVideo" + ] + + # 530x964 floors onto the 32px grid as 512x960; the default 1.25x second + # pass rounds to 640x1216 (960*1.25=1200 rounds up to the 32px grid). + assert sorted(item["width"] for item in conditionings) == [512, 640] + assert sorted(item["height"] for item in conditionings) == [960, 1216] + + def test_multitrack_h3_project_logs_steps_and_reports_progress(monkeypatch): module = _load_minimax_node(monkeypatch) assert module is not None @@ -5322,6 +5369,32 @@ def test_reference_encodes_images_video_audio_and_standalone_audio(monkeypatch): assert conditioning["inputs"]["ref_video_0"][1] == 0 +def test_reference_fallback_grid_aligns_off_grid_ref_videos(monkeypatch): + """ComfyUI builds with native H3 nodes grid-align reference videos inside + core's MiniMaxH3ReferenceToVideo; the fallback copy must do the same, or + an off-grid media size (the API can inject arbitrary media) yields an odd + latent dimension and crashes patchify_video during sampling.""" + module = _load_minimax_node(monkeypatch) + assert module is not None + vae = _Vae() + + module.MiniMaxH3ReferenceToVideoFallback.execute( + clip=_Clip(), + vae=vae, + audio_vae=None, + prompt="prompt", + width=32, + height=32, + length=5, + ref_videos={"ref_video_0": torch.zeros(6, 270, 480, 3)}, + ) + + encoded_frames = vae.encoded[-1] + # Frames are [T, H, W, C]: 270 floors onto the 32px grid as 256; 480 is + # already aligned. + assert tuple(encoded_frames.shape[1:3]) == (256, 480) + + def test_reference_bridge_groups_fixed_inputs_before_direct_execute(monkeypatch): module = _load_minimax_node(monkeypatch) assert module is not None