From ce03875c69755ea7913c61996cc3102a3f332666 Mon Sep 17 00:00:00 2001 From: Z User Date: Wed, 14 Oct 2026 23:37:47 +0000 Subject: [PATCH] feat: enable automatic spatial tiling on Moxie MultiTrack Project Slow Bake enabled_tiling with tile_count 0 (automatic) into the Slow node's second pass: the engine picks the tile count from the available accelerator memory and bypasses tiling entirely when the full evaluation fits. This brings 1920x1080 output within reach of 12 GB cards and AMD/Intel GPUs - the tiling machinery only uses device-agnostic ComfyUI memory helpers. - _h3_tiling_config now accepts tile_count 0 (automatic) alongside 2-8 - easy h3SamplingPreviewSampler schema allows tile_count min 0 - tests: tiling config parsing, baked Slow passthrough, second-pass graph receives tile_count 0, sampler schema range - docs: CHANGELOG + multitrack-schema reference --- CHANGELOG.md | 2 +- moxie_project.py | 20 ++++-- nodes/project.py | 12 +++- .../references/multitrack-schema.md | 2 +- tests/test_minimax_node.py | 63 ++++++++++++++++++- 5 files changed, 89 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a44a852..81d92c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ ### ⚡ Improvements -- **Moxie MultiTrack Project Slow**: New project node variant that replaces the RTX VSR restore with a latent-upscale refine pass. The pipeline stays identical to Moxie MultiTrack Project — hidden half-resolution first pass with euler + beta sigmas from `steps` — but the low-resolution latent is upscaled to the final (editor) size by a latent upscaler checkpoint and refined with a hidden 2-step euler pass at 0.33 denoise. Segments are saved at the project resolution, so the Video Combine restore passes through untouched and nothing in the node requires NVIDIA RTX VSR. The upscaler is chosen in a new `upscale_model` dropdown on the node (placed with the model inputs; lists everything under `ComfyUI/models/latent_upscale_models/`, defaults to `minimax_h3_latent_upscaler_3d_fp16.safetensors`, and rejects `None` with a clear error since the node always upscales in latent space). End users still only set `steps` and `seed` (plus the shared `context_frames` overlap). The engine's first-pass downscale and upscale-skip logic were generalized (class hook + true size comparison) with zero behavior change for existing nodes. +- **Moxie MultiTrack Project Slow**: New project node variant that replaces the RTX VSR restore with a latent-upscale refine pass. The pipeline stays identical to Moxie MultiTrack Project — hidden half-resolution first pass with euler + beta sigmas from `steps` — but the low-resolution latent is upscaled to the final (editor) size by a latent upscaler checkpoint and refined with a hidden 2-step euler pass at 0.33 denoise. The refine pass samples through **automatic spatial tiling**: the engine picks the tile count from the available accelerator memory and bypasses tiling entirely when the full evaluation fits, so projects up to **1920x1080** also run on 12 GB cards and on **AMD/Intel GPUs** (the tiling machinery uses only device-agnostic ComfyUI memory helpers — nothing in this node requires CUDA; non-NVIDIA machines should pick the `pytorch_attention` backend on the loader, since the INT8 attention backend is Nvidia/AMD-only). Segments are saved at the project resolution, so the Video Combine restore passes through untouched and nothing in the node requires NVIDIA RTX VSR. The upscaler is chosen in a new `upscale_model` dropdown on the node (placed with the model inputs; lists everything under `ComfyUI/models/latent_upscale_models/`, defaults to `minimax_h3_latent_upscaler_3d_fp16.safetensors`, and rejects `None` with a clear error since the node always upscales in latent space). End users still only set `steps` and `seed` (plus the shared `context_frames` overlap). The engine's first-pass downscale and upscale-skip logic were generalized (class hook + true size comparison) with zero behavior change for existing nodes; `tile_count` values of `0` (automatic) are additionally accepted alongside the fixed 2–8 range. - **MultiTrack Project**: The inter-segment context overlap is now configurable. The new `context_frames` widget (5 / 22 / 39 / 56 frames, default 22) chooses how many frames of the previous segment are copied in as continuation context for segments using Context or Context Swap continuity — previously this was fixed at 22 frames in code. Longer values hand off motion more smoothly but generate that many extra frames per continued segment (each continuation also generates 12 grid-alignment tail frames that are trimmed after decode). Values are the H3 temporal-grid lengths already offered by the Moxie context sampler nodes; existing workflows keep 22 and behave exactly as before. The same widget (between `steps` and `seed`) is also exposed on **Moxie MultiTrack Project** — its baked euler/beta sampling stack is unchanged, so end users still only need `steps` and `seed` unless they touch the overlap. diff --git a/moxie_project.py b/moxie_project.py index 0e564e4..bc643dd 100644 --- a/moxie_project.py +++ b/moxie_project.py @@ -35,6 +35,12 @@ BAKED_SCHEDULER = "beta" SLOW_UPSCALE_MODEL = "minimax_h3_latent_upscaler_3d_fp16.safetensors" SLOW_SECOND_PASS_STEPS = 2 SLOW_SECOND_PASS_DENOISE = 0.33 +# Spatial tiling of the second pass with an automatic tile count: 0 lets the +# engine choose how many tiles fit into the available accelerator memory and +# skip tiling entirely when the full evaluation fits. The tiling module only +# uses device-agnostic ComfyUI memory helpers, so this also brings 1920x1080 +# output within reach of 12 GB cards and AMD/Intel GPUs. +SLOW_TILING_SETTINGS = {"enabled_tiling": "true", "tile_count": 0} SLOW_PROJECT_SETTINGS_DELTA = { "sampling_mode": "dual", # The first pass already runs at half the editor resolution, so the final @@ -43,6 +49,7 @@ SLOW_PROJECT_SETTINGS_DELTA = { # dimensions mode) bridges the half-res gap. The upscaler checkpoint is # NOT baked: the Slow node exposes an upscale_model widget instead. "upscale_by": 1.0, + "enabled_tiling": SLOW_TILING_SETTINGS, } @@ -215,9 +222,12 @@ class MoxieProjectSlow(MoxieProject): euler + beta sampling from `steps`), except the low-resolution latent is upscaled to the final size by a latent upscaler model chosen in the `upscale_model` widget and refined with a 2-step euler pass at 0.33 - denoise. Segments are saved at the project resolution, so the Video - Combine RTX restore passes through untouched - no NVIDIA RTX VSR is - used anywhere. + denoise. The refine pass samples through automatic spatial tiling, so + large projects (up to 1920x1080) also run on 12 GB cards and on AMD or + Intel GPUs; the tile count adapts to the machine and tiling is skipped + entirely when the whole evaluation fits in memory. Segments are saved at + the project resolution, so the Video Combine RTX restore passes through + untouched - no NVIDIA RTX VSR is used anywhere. """ @classmethod @@ -276,7 +286,9 @@ class MoxieProjectSlow(MoxieProject): "first pass samples euler + beta sigmas from steps, the " "half-resolution latent is upscaled to the final size with " "the chosen latent upscaler, and a 2-step euler pass at " - "0.33 denoise refines it; set only steps and seed." + "0.33 denoise refines it through automatic spatial tiling " + "(scales to the available VRAM, enabling up to 1920x1080 " + "output on 12 GB and AMD/Intel GPUs); set only steps and seed." ), is_input_list=True, enable_expand=True, diff --git a/nodes/project.py b/nodes/project.py index 43a646f..49d8ff3 100644 --- a/nodes/project.py +++ b/nodes/project.py @@ -421,8 +421,8 @@ def _h3_tiling_config(value: Any) -> tuple[bool, int]: if not enabled: return False, 0 tile_count = int(_first_input(config.get("tile_count"), 2)) - if not 2 <= tile_count <= 8: - raise ValueError("tile_count must be between 2 and 8") + if tile_count != 0 and not 2 <= tile_count <= 8: + raise ValueError("tile_count must be 0 (automatic) or between 2 and 8") return True, tile_count @@ -491,10 +491,16 @@ class EasyH3SamplingPreviewSampler(io.ComfyNode): io.Int.Input( "tile_count", default=2, - min=2, + min=0, max=8, step=1, optional=True, + tooltip=( + "Spatial tiles for high-resolution H3 sampling. " + "0 picks the tile count from the available memory and " + "bypasses tiling entirely when the full evaluation " + "fits." + ), ), io.Vae.Input("preview_vae", optional=True), io.String.Input("preview_node_id", default="", optional=True), diff --git a/skills/easy-media-multitrack-workflow/references/multitrack-schema.md b/skills/easy-media-multitrack-workflow/references/multitrack-schema.md index d6dfc5b..737462a 100644 --- a/skills/easy-media-multitrack-workflow/references/multitrack-schema.md +++ b/skills/easy-media-multitrack-workflow/references/multitrack-schema.md @@ -268,7 +268,7 @@ custom 示例: - `sampling_mode`: `single` 或 `dual`;`sampling_plan` 必须是当前节点可用预设。不要仅凭另一份流程中的值假设当前环境支持。 - `context_frames`(默认 `"22"`,可选 `"5"` / `"22"` / `"39"` / `"56"`)控制 Context / Context Swap 续接片段从上一段拷贝为延续上下文的视频帧数;取值必须落在 H3 时间潜空间网格(17k+5 帧)上,与 Moxie 上下文采样节点的选项一致。数值越大运动衔接越平滑,但每个续接片段会多生成等量帧(实际生成长度为 `任务长度 + context_frames + 12`,其中 12 帧为网格尾帧,解码后裁掉)。 - `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` 会直接报错,因为该节点始终走潜空间放大。旧工作流没有该控件时自动回落到默认检查点。 +- `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` 会直接报错,因为该节点始终走潜空间放大。旧工作流没有该控件时自动回落到默认检查点。二采默认启用**自动空间分块**(烘焙 `enabled_tiling={"enabled_tiling":"true","tile_count":0}`,`tile_count=0` 表示按可用显存自动选择分块数、放得下则完全不分块),因此 1920x1080 输出在 12GB 显存及 AMD/Intel GPU 上也可运行;分块实现只用 ComfyUI 的设备无关显存接口,不含 CUDA 专属代码(AMD/Intel 机器上 Loader 的注意力后端应选 `pytorch_attention`,INT8 注意力仅支持 Nvidia/AMD)。 - 编辑器分辨率是一采尺寸;`dual` 不会反算缩小一采。二采宽高分别为 `round(编辑器尺寸 * upscale_by / 32) * 32`,采用 Python `round` 就近对齐,恰好居中时取偶数,不是固定向上对齐。 - `upscale_by` 是 Project 的独立参数,默认 `1.250`,三位小数,步长 `0.001`;旧工作流保留已保存的值。两条放大路径及合并导出均使用放大并对齐后的尺寸。例如 `1344 × 768`、倍率 `1.250` 的二采为 `1664 × 960`。若用户指定最终输出尺寸,应同时核对编辑器尺寸与倍率,不能将编辑器尺寸直接当作双采样的最终尺寸。 - 单采样、仅一采预览保持编辑器尺寸;`upscale_by = 1.000` 不放大但可二采;纯音频项目(`32 × 32`)不放大。旧版反算缩小尺寸的一采检查点和上下文潜空间应重新生成后再按新规则续跑。 diff --git a/tests/test_minimax_node.py b/tests/test_minimax_node.py index de0aa46..0add01b 100644 --- a/tests/test_minimax_node.py +++ b/tests/test_minimax_node.py @@ -2415,7 +2415,9 @@ def test_h3_sampling_preview_sampler_exposes_optional_tiling(monkeypatch): assert inputs["enabled_tiling"].kwargs["default"] is False assert inputs["enabled_tiling"].kwargs["optional"] is True assert inputs["tile_count"].kwargs["default"] == 2 - assert inputs["tile_count"].kwargs["min"] == 2 + # 0 is allowed so engine-built graph nodes can request the automatic + # memory-based tile count (Moxie MultiTrack Project Slow bakes it). + assert inputs["tile_count"].kwargs["min"] == 0 assert inputs["tile_count"].kwargs["max"] == 8 assert inputs["preview_vae"].kwargs["optional"] is True @@ -2441,6 +2443,25 @@ def test_multitrack_project_tiles_inside_second_pass_sampler(monkeypatch): assert not any(node["class_type"] == "easy h3TiledModel" for node in nodes) +def test_multitrack_project_passes_automatic_tile_count_to_second_pass( + monkeypatch, +): + module = _load_minimax_node(monkeypatch) + module.comfy_nodes.NODE_CLASS_MAPPINGS["ImageResizeKJv2"] = _ImageResizeKJWithNvidia + # The baked Slow form: a plain dict (no list wrapping, no DynamicCombo + # envelope) with tile_count 0 for the memory-based automatic count. + inputs = _h3_project_inputs( + sampling_mode=_h3_sampling_mode("dual"), + enabled_tiling=[{"enabled_tiling": "true", "tile_count": 0}], + ) + + result = module.EasyMultiTrackProject.execute(**inputs) + tiled_sampler = _graph_node(result, "easy h3SamplingPreviewSampler") + + assert tiled_sampler["inputs"]["enabled_tiling"] is True + assert tiled_sampler["inputs"]["tile_count"] == 0 + + def test_multitrack_project_adds_preview_inputs_to_selflift_sampler(monkeypatch): module = _load_minimax_node(monkeypatch) module.EasyMultiTrackProject.hidden = types.SimpleNamespace(unique_id="84") @@ -6375,6 +6396,10 @@ def test_moxie_project_slow_bakes_latent_upscale_refine(monkeypatch): # Baked Slow settings reach the engine. assert captured["sampling_mode"] == "dual" assert captured["upscale_by"] == 1.0 + # The refine pass samples through automatic spatial tiling: the engine + # picks the tile count from the available memory (0) and skips tiling + # entirely when the full evaluation fits. + assert captured["enabled_tiling"] == {"enabled_tiling": "true", "tile_count": 0} # The connected/picked upscale_model widget value wins over any default. assert captured["upscale_model"] == "my_upscaler.safetensors" assert captured["sampling_plan"] == "custom" @@ -6458,6 +6483,42 @@ def test_moxie_project_slow_keeps_half_res_first_pass(monkeypatch): assert slow._h3_first_pass_resolution_scale(mode) == 0.5 +def test_h3_tiling_config_accepts_automatic_tile_count(monkeypatch): + module = _load_moxie_project(monkeypatch) + project_module = sys.modules["easy_media.nodes.project"] + config = project_module._h3_tiling_config + + assert config(None) == (False, 0) + assert config("false") == (False, 0) + # Plain-string enablement keeps the historical fixed count of 2. + assert config("true") == (True, 2) + # Baked Slow settings: automatic tile count chosen from free memory. + assert config({"enabled_tiling": "true", "tile_count": 0}) == (True, 0) + # DynamicCombo widget payloads arrive with list-wrapped children. + assert config({"enabled_tiling": ["true"], "tile_count": [3]}) == (True, 3) + assert config({"enabled_tiling": "true"}) == (True, 2) + assert config({"enabled_tiling": "false", "tile_count": 0}) == (False, 0) + + for bad_count in (1, -1, 9): + with pytest.raises( + ValueError, match=r"tile_count must be 0 \(automatic\) or between 2 and 8" + ): + config({"enabled_tiling": "true", "tile_count": bad_count}) + + +def test_h3_sampling_preview_sampler_allows_automatic_tile_count(monkeypatch): + module = _load_moxie_project(monkeypatch) + project_module = sys.modules["easy_media.nodes.project"] + schema = project_module.EasyH3SamplingPreviewSampler.define_schema() + inputs = {port.name: port for port in schema.inputs} + + tile_count = inputs["tile_count"] + assert tile_count.kwargs["default"] == 2 + assert tile_count.kwargs["min"] == 0 + assert tile_count.kwargs["max"] == 8 + assert "available memory" in tile_count.kwargs["tooltip"] + + def test_denoise_truncated_sigmas_matches_ksampler_math(monkeypatch): module = _load_moxie_project(monkeypatch) calls = []