diff --git a/CHANGELOG.md b/CHANGELOG.md index cc45187..90c8fbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,10 @@ - **Moxie Multimedia Loader**: Locked the loader to the MiniMax H3 model set. The `clip_type` dropdown (which previously exposed every CLIP recipe in ComfyUI) was removed; the H3 Qwen3-VL text encoder is now always loaded with the `minimax` CLIP recipe. Any older ComfyUI build without `CLIPType.MINIMAX` raises a clear startup error instead of silently loading the wrong encoder. - **Moxie Multimedia Loader / Moxie MultiTrack Project**: Removed the legacy `FAST_MODEL_LOADER` (`model_loader`) bundle. The loader now outputs exactly `model`, `clip`, `video_vae`, and `audio_vae` (with the attention backend and LoRA already applied to the model), and the Moxie MultiTrack Project takes those four outputs as required direct inputs instead of a bundled loader. `Moxie Preview Override` likewise dropped its `model_loader` pass-through slots and now patches the `model` input directly. The generic `easy multitrackProject` node keeps its `model_loader` input for non-Moxie workflows. +### 🐛 Bug Fixes + +- **MultiTrack Project / Moxie MultiTrack Project (Slow)**: Multi-segment projects no longer crash on the first continuation segment with `RuntimeError: shape '[1, 24, 1, 1, 8, 2, 15, 2]' is invalid for input of size 12240` (`patchify_video`). The hidden half-resolution first pass declared its size with plain integer halving, so a 1920x1080 editor sampled at 960x540 — and a latent encoded from 540px carries an odd 17-row count. Odd latents sample fine, but when the segment tail comes back as motion-context keyframes on the next segment, the model's `patchify_video` (2x2 latent patches) cannot reshape them and the second scene dies. The first pass now snaps onto the nearest 64px grid so every latent in the pipeline (initial latent, reference conditioning, saved context tail) keeps even row/column counts: 1920x1080 samples at 960x512, 1344x768 at 704x384, and a 3840x2160 editor is unchanged at 1920x1088 (the size the VAE already rounds up to — the 4K-editor trick behaves identically). Outputs and second-pass dimensions are unchanged; only continuation segments that previously crashed now run. + ## [1.3.3] - 2026-09-25 ### ✨ New Features diff --git a/nodes/project.py b/nodes/project.py index 49d8ff3..22f8757 100644 --- a/nodes/project.py +++ b/nodes/project.py @@ -16,6 +16,7 @@ from ..utils.h3_presets import get_h3_preset_keys, load_h3_presets, select_h3_pr from ..utils.h3_project import ( clear_h3_project_segments_from, compose_h3_project_video, + h3_even_latent_size, h3_generation_mode, h3_locked_audio_track, h3_locked_video_track, @@ -1234,8 +1235,18 @@ class EasyMultiTrackProject(io.ComfyNode): first_pass_width, first_pass_height = editor_width, editor_height first_pass_scale = float(cls._h3_first_pass_resolution_scale(sampling_mode)) if first_pass_scale != 1.0 and not audio_only: - scaled_width = max(32, int(editor_width * first_pass_scale)) - scaled_height = max(32, int(editor_height * first_pass_scale)) + # Snap the hidden first pass onto the H3 latent grid: a size like + # 540px encodes to a latent with an odd row count, which samples + # fine but breaks patchify_video when the tail comes back as + # context keyframes on the next segment (shape ... is invalid for + # input of size ...). 1920x1080 therefore samples at 960x512 and + # a 4K editor keeps sampling at 1920x1088. + scaled_width = h3_even_latent_size( + int(editor_width * first_pass_scale) + ) + scaled_height = h3_even_latent_size( + int(editor_height * first_pass_scale) + ) if (scaled_width, scaled_height) != (32, 32): first_pass_width, first_pass_height = scaled_width, scaled_height target_width, target_height = h3_second_pass_dimensions( diff --git a/skills/easy-media-multitrack-workflow/references/multitrack-schema.md b/skills/easy-media-multitrack-workflow/references/multitrack-schema.md index 1e01bd6..22bb882 100644 --- a/skills/easy-media-multitrack-workflow/references/multitrack-schema.md +++ b/skills/easy-media-multitrack-workflow/references/multitrack-schema.md @@ -270,6 +270,7 @@ custom 示例: - `Moxie MultiTrack Project`(`MoxieProject`)同样暴露同一个 `context_frames` 下拉,位于 `steps` 与 `seed` 之间;该节点的其余采样设置仍保持隐藏(euler + beta sigmas 由 `steps` 推导)。 - `Moxie MultiTrack Project Slow`(`MoxieProjectSlow`)是 Moxie 变体:参数与 `Moxie MultiTrack Project` 完全一致,但用潜空间放大替代 RTX VSR——隐藏的半分辨率一采之后,用 `models/latent_upscale_models/` 下选定的潜空间放大模型把潜空间升到最终(编辑器)尺寸,再以 2 步 euler、0.33 denoise 的隐藏二采精修;片段按项目分辨率保存,Video Combine 的 RTX 还原会直接跳过。该节点在 `audio_vae` 之后新增 `upscale_model` 下拉(默认 `minimax_h3_latent_upscaler_3d_fp16.safetensors`,列出 `models/latent_upscale_models/` 全部检查点);选 `None` 会直接报错,因为该节点始终走潜空间放大。旧工作流没有该控件时自动回落到默认检查点。二采默认启用**自动空间分块**(`tile_count=0` 表示按可用显存自动选择分块数、放得下则完全不分块),因此 1920x1080 输出在 12GB 显存及 AMD/Intel GPU 上也可运行;`upscale_model` 旁新增 `tiling` 开关(Boolean,默认 **on**)可整体关闭分块——关闭时引擎向二采注入 `{"enabled_tiling":"false","tile_count":0}`,二采改走普通 `SamplerCustomAdvanced` 一体化采样;旧工作流没有该开关时保持分块开启。分块实现只用 ComfyUI 的设备无关显存接口,不含 CUDA 专属代码(AMD/Intel 机器上 Loader 的注意力后端应选 `pytorch_attention`,INT8 注意力仅支持 Nvidia/AMD)。 - 编辑器分辨率是一采尺寸;`dual` 不会反算缩小一采。二采宽高分别为 `round(编辑器尺寸 * upscale_by / 32) * 32`,采用 Python `round` 就近对齐,恰好居中时取偶数,不是固定向上对齐。 +- 隐藏的半分辨率一采(单采样与 Moxie 变体)会**对齐到偶数潜空间网格**:先按 0.5 缩放,再取最近的 64px 整数倍(`h3_even_latent_size`)。原因:H3 视频 patch 覆盖 2x2 潜空间格子(32px 潜空间网格),非 64px 倍数的尺寸编码出的潜空间行/列数为奇数(如 540px → 17 行),采样本身可行,但作为下一片段的 Motion Context keyframes 回流时 `patchify_video` 无法 reshape,报 `shape '[1, 24, 1, 1, 8, 2, 15, 2]' is invalid for input of size 12240`。对齐结果:1920x1080 编辑器一采 960x**512**,1344x768 → 704x**384**,3840x2160 → 1920x**1088**(与 VAE 原本向上取整一致,4K 编辑器技巧行为不变)。二采与最终输出尺寸不受影响。 - `upscale_by` 是 Project 的独立参数,默认 `1.250`,三位小数,步长 `0.001`;旧工作流保留已保存的值。两条放大路径及合并导出均使用放大并对齐后的尺寸。例如 `1344 × 768`、倍率 `1.250` 的二采为 `1664 × 960`。若用户指定最终输出尺寸,应同时核对编辑器尺寸与倍率,不能将编辑器尺寸直接当作双采样的最终尺寸。 - 单采样、仅一采预览保持编辑器尺寸;`upscale_by = 1.000` 不放大但可二采;纯音频项目(`32 × 32`)不放大。旧版反算缩小尺寸的一采检查点和上下文潜空间应重新生成后再按新规则续跑。 - `1st_pass_only` 仅适用于显式的一阶段检查点流程;不要自动开启。 diff --git a/tests/test_minimax_node.py b/tests/test_minimax_node.py index 0b7b6c1..953e4b1 100644 --- a/tests/test_minimax_node.py +++ b/tests/test_minimax_node.py @@ -2332,7 +2332,10 @@ def test_multitrack_h3_project_expands_single_task_sampling_pipeline(monkeypatch conditioning = nodes_by_type["easy minimaxH3ToVideo"]["inputs"] assert conditioning["mode"] == "multi_frames" assert conditioning["ref_image_size"] == "match" - assert (conditioning["width"], conditioning["height"]) == (1344, 768) + # Single pass samples at half the editor resolution (the hidden RTX + # restore trick), snapped onto the even-latent grid: 1344x768 -> + # 672x384 -> 704x384 because 672 encodes to an odd latent column count. + assert (conditioning["width"], conditioning["height"]) == (704, 384) assert "SamplerCustomAdvanced" in nodes_by_type assert "easy h3SegmentSamplingStart" in nodes_by_type assert ( @@ -6566,6 +6569,89 @@ def test_h3_sampling_preview_sampler_allows_automatic_tile_count(monkeypatch): assert "available memory" in tile_count.kwargs["tooltip"] +def test_h3_even_latent_size_snaps_to_even_latent_grid(): + # nodes.project imports the helper from utils.h3_project, so the loaded + # engine module exposes it directly. + snap = sys.modules["easy_media.nodes.project"].h3_even_latent_size + + # 1080p: 540 encodes to a 17-row latent (odd) -> 512 keeps 16 rows. + assert snap(540) == 512 + # 4K trick: 1080 already rounds up to 1088 in the VAE (34 rows, even). + assert snap(1080) == 1088 + # 1344-wide editors: 672 -> odd latent columns -> 704. + assert snap(672) == 704 + # Sizes already on the even-latent grid pass through untouched. + assert snap(384) == 384 + assert snap(512) == 512 + assert snap(960) == 960 + assert snap(1088) == 1088 + # Small and degenerate sizes keep the 32px audio-only floor. + assert snap(32) == 32 + assert snap(16) == 32 + assert snap(50) == 64 + # Snapped sizes always encode to even (patchable) latent dimensions. + for pixels in (540, 544, 672, 720, 1056, 1080, 1440, 2160): + assert snap(pixels) % 64 == 0 + + +def test_h3_first_pass_dims_snap_to_even_latent_grid(monkeypatch): + module = _load_minimax_node(monkeypatch) + + def tracks(width, height): + return [{ + "width": width, + "height": height, + "frame_rate": 24, + "format": "MiniMax", + "tracks": [{ + "type": "task", + "segments": [{ + "start_frame": 0, + "end_frame": 120, + "content": { + "task_mode": "default", + "continuity_mode": "shot", + "images": [], + "user_prompt": "a cinematic scene", + }, + }], + }], + }] + + # Editor 1920x1080: the hidden half-res first pass used to declare + # 960x540, whose context latent carries 17 latent rows; patchify_video + # then failed on the next segment ("shape '[1, 24, 1, 1, 8, 2, 15, 2]' + # is invalid for input of size 12240"). Snapped to 960x512, the saved + # context tail patches cleanly on continuation segments. + result = module.EasyMultiTrackProject.execute( + **_h3_project_inputs( + tracks_info=tracks(1920, 1080), + sampling_mode=_h3_sampling_mode("single"), + ) + ) + conditioning = next( + node + for node in result.expand.values() + if node["class_type"] == "easy minimaxH3ToVideo" + )["inputs"] + assert (conditioning["width"], conditioning["height"]) == (960, 512) + + # The 4K-editor trick is unchanged: 1080 already lands on 1088, the + # size the H3 VAE rounds up to (34 even latent rows). + result = module.EasyMultiTrackProject.execute( + **_h3_project_inputs( + tracks_info=tracks(3840, 2160), + sampling_mode=_h3_sampling_mode("single"), + ) + ) + conditioning = next( + node + for node in result.expand.values() + if node["class_type"] == "easy minimaxH3ToVideo" + )["inputs"] + assert (conditioning["width"], conditioning["height"]) == (1920, 1088) + + def test_denoise_truncated_sigmas_matches_ksampler_math(monkeypatch): module = _load_moxie_project(monkeypatch) calls = [] diff --git a/utils/h3_project.py b/utils/h3_project.py index 68adbe3..ea8a9e7 100644 --- a/utils/h3_project.py +++ b/utils/h3_project.py @@ -400,6 +400,26 @@ def h3_second_pass_dimensions( ) +def h3_even_latent_size(pixels: int) -> int: + """Snap a pixel size onto the H3 latent grid with even row/column counts. + + H3 video patches cover 2x2 latent cells on the 32px latent grid, so a + latent encoded from a size that is not a multiple of 64 ends up with an + odd row/column count (540px encodes to 17 rows). Odd latents sample + fine, but they cannot be patchified when they come back as context + keyframes on a continuation segment: patchify_video computes the patch + grid with floor division and the reshape fails with "shape ... is + invalid for input of size ...". Landing the size on the nearest 64px + multiple keeps every latent in the pipeline (initial latent, reference + conditioning, saved context tail) on one consistent, patchable grid: + 540 -> 512, 672 -> 704, 1080 -> 1088 (the size the VAE already rounds + up to, so 4K-editor workflows are unchanged). + """ + if pixels <= 32: + return max(32, pixels) + return max(64, int(math.floor(pixels / 64 + 0.5)) * 64) + + def h3_task_type(entry: dict[str, Any], info: dict[str, Any]) -> str: task = entry.get("task", {}) content = task.get("content", {}) if isinstance(task, dict) else {}