fix: scope the even-latent first-pass snap to Moxie MultiTrack Project Slow
The crash fix for the scene-2+ patchify_video failure had been applied in the shared EasyMultiTrackProject pipeline, changing the hidden first-pass size of the certified MultiTrack Project and Moxie MultiTrack Project nodes too. Certification requires those nodes to keep their exact behavior, so the snap now lives behind overridable hooks whose defaults are the certified rules: - _h3_first_pass_size default: max(32, int(editor * scale)) plain halving (the certified formula). MoxieProjectSlow overrides it to snap onto the nearest 64px grid, fixing the odd-latent crash on its own continuation segments only (1080p -> 960x512, 1344x768 -> 704x384, 4K -> 1920x1088 unchanged). - _h3_needs_latent_upscale default: the certified 'upscale_by <= 1' skip rule. MoxieProjectSlow overrides it with a true size comparison (load-bearing for its latent-upscale refine at upscale_by 1.0). - The certified sampling preview sampler keeps its widget text, default 2 and max 8; min stays 0 only because the engine passes the Slow node's automatic tile_count 0 through it and ComfyUI validates inputs against min at execution. utils/h3_project.py is back to its certified state (the snap helper now lives in the Slow node's own file). Regression tests pin the certified first-pass dims and decision rules of both certified project nodes so any future drift fails the suite loudly.
This commit is contained in:
parent
46617b71b8
commit
5347719cdd
@ -29,7 +29,7 @@
|
||||
|
||||
### 🐛 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.
|
||||
- **Moxie MultiTrack Project Slow** (Slow node only — every other node keeps its certified behavior byte for byte): multi-segment projects at 1920x1080 crashed 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 Slow node's hidden half-resolution first pass declared its size with plain integer halving, so a 1080p 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. The Slow node now snaps its hidden first pass onto the nearest 64px grid (`MoxieProjectSlow._h3_first_pass_size` override): 1920x1080 samples at 960x512, 1344x768 at 704x384, 3840x2160 at 1920x1088 (unchanged vs the VAE round-up). Output sizes and the second pass are unchanged; only Slow continuation segments that previously crashed now run. Regression tests pin the certified plain-halving first pass of `MultiTrack Project` and `Moxie MultiTrack Project` (672x384 at a 1344x768 editor) and the certified decision rules of the sampling preview sampler node (widget text, default 2, max 8 — its `min` is widened to 0 only because the engine passes the Slow node's automatic `tile_count 0` through it and ComfyUI validates inputs against `min` at execution; certified `tile_count` values validate exactly as before).
|
||||
|
||||
## [1.3.3] - 2026-09-25
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@ from __future__ import annotations
|
||||
|
||||
import comfy.samplers
|
||||
import folder_paths
|
||||
import math
|
||||
from comfy_api.latest import io
|
||||
|
||||
from .nodes.project import (
|
||||
@ -67,6 +68,28 @@ def _tiling_switch(value, default: bool = True) -> bool:
|
||||
return bool(enabled)
|
||||
|
||||
|
||||
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 Slow pipeline (initial latent,
|
||||
reference conditioning, saved context tail) on one consistent,
|
||||
patchable grid: 540 -> 512, 672 -> 704, 1080 -> 1088.
|
||||
|
||||
Scoped to the Slow node on purpose: the other project nodes are
|
||||
certified and keep their plain-halving first pass.
|
||||
"""
|
||||
if pixels <= 32:
|
||||
return max(32, pixels)
|
||||
return max(64, int(math.floor(pixels / 64 + 0.5)) * 64)
|
||||
|
||||
|
||||
def _require_moxie_components(model, clip, video_vae, audio_vae) -> None:
|
||||
missing = [
|
||||
name
|
||||
@ -241,9 +264,12 @@ class MoxieProjectSlow(MoxieProject):
|
||||
Intel GPUs; the tile count adapts to the machine and tiling is skipped
|
||||
entirely when the whole evaluation fits in memory. The `tiling` switch
|
||||
turns the tiles off for machines that prefer the refine pass sampled in
|
||||
one piece. Segments are saved at the project resolution, so the Video
|
||||
Combine RTX restore passes through untouched - no NVIDIA RTX VSR is
|
||||
used anywhere.
|
||||
one piece. Unlike the certified project nodes, the Slow node's hidden
|
||||
first pass is snapped onto the even-latent grid (nearest 64px multiple)
|
||||
so continuation segments can patchify the context tail; output sizes
|
||||
are unchanged. Segments are saved at the project resolution, so the
|
||||
Video Combine RTX restore passes through untouched - no NVIDIA RTX VSR
|
||||
is used anywhere.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
@ -300,6 +326,41 @@ class MoxieProjectSlow(MoxieProject):
|
||||
# lets the latent upscaler bridge the gap instead of RTX VSR.
|
||||
return 0.5
|
||||
|
||||
@classmethod
|
||||
def _h3_first_pass_size(
|
||||
cls, editor_width: int, editor_height: int, first_pass_scale: float
|
||||
) -> tuple[int, int]:
|
||||
# Slow-only deviation from the certified first pass: snap the hidden
|
||||
# pass onto the even-latent grid so continuation segments can
|
||||
# patchify the context tail (odd latents crash patchify_video on
|
||||
# scene 2+). The certified project nodes keep the plain-halving
|
||||
# behavior via the base class default.
|
||||
return (
|
||||
_h3_even_latent_size(int(editor_width * first_pass_scale)),
|
||||
_h3_even_latent_size(int(editor_height * first_pass_scale)),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def _h3_needs_latent_upscale(
|
||||
cls,
|
||||
audio_only: bool,
|
||||
first_pass_width: int,
|
||||
first_pass_height: int,
|
||||
target_width: int,
|
||||
target_height: int,
|
||||
upscale_by: float,
|
||||
) -> bool:
|
||||
# The Slow node samples the first pass at half resolution and always
|
||||
# bridges the gap with the latent upscaler, so the decision is a true
|
||||
# size comparison instead of the certified upscale_by rule (which
|
||||
# would skip at upscale_by 1.0 and leave the refine pass at half
|
||||
# size).
|
||||
return not (
|
||||
audio_only
|
||||
or (first_pass_width, first_pass_height)
|
||||
== (target_width, target_height)
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def define_schema(cls) -> io.Schema:
|
||||
return io.Schema(
|
||||
|
||||
@ -16,7 +16,6 @@ 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,
|
||||
@ -492,16 +491,15 @@ class EasyH3SamplingPreviewSampler(io.ComfyNode):
|
||||
io.Int.Input(
|
||||
"tile_count",
|
||||
default=2,
|
||||
# min 0 is required by Moxie MultiTrack Project Slow: the
|
||||
# engine builds this node with tile_count 0 (automatic,
|
||||
# memory-based) and ComfyUI validates inputs against min
|
||||
# at execution (execution.py "smaller than min"). Values
|
||||
# 2-8 and the default validate exactly as before.
|
||||
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),
|
||||
@ -899,6 +897,40 @@ class EasyMultiTrackProject(io.ComfyNode):
|
||||
"""
|
||||
return 0.5 if sampling_mode == "single" else 1.0
|
||||
|
||||
@classmethod
|
||||
def _h3_first_pass_size(
|
||||
cls, editor_width: int, editor_height: int, first_pass_scale: float
|
||||
) -> tuple[int, int]:
|
||||
"""Scaled hidden first-pass size for the given editor dimensions.
|
||||
|
||||
Default is the certified plain-halving behavior. Subclasses may
|
||||
override this to adjust their own hidden pass without changing how
|
||||
this node or any other project variant samples.
|
||||
"""
|
||||
return (
|
||||
max(32, int(editor_width * first_pass_scale)),
|
||||
max(32, int(editor_height * first_pass_scale)),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def _h3_needs_latent_upscale(
|
||||
cls,
|
||||
audio_only: bool,
|
||||
first_pass_width: int,
|
||||
first_pass_height: int,
|
||||
target_width: int,
|
||||
target_height: int,
|
||||
upscale_by: float,
|
||||
) -> bool:
|
||||
"""Whether the second pass needs the latent upscaled to the target.
|
||||
|
||||
Default is the certified rule: skip whenever no upscale factor is
|
||||
configured. Variants that sample the first pass below the target
|
||||
size (latent-upscale refine) override this with a true size
|
||||
comparison.
|
||||
"""
|
||||
return not (audio_only or upscale_by <= 1)
|
||||
|
||||
@classmethod
|
||||
def define_schema(cls) -> io.Schema:
|
||||
return io.Schema(
|
||||
@ -1235,17 +1267,8 @@ 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:
|
||||
# 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)
|
||||
scaled_width, scaled_height = cls._h3_first_pass_size(
|
||||
editor_width, editor_height, first_pass_scale
|
||||
)
|
||||
if (scaled_width, scaled_height) != (32, 32):
|
||||
first_pass_width, first_pass_height = scaled_width, scaled_height
|
||||
@ -1921,13 +1944,17 @@ class EasyMultiTrackProject(io.ComfyNode):
|
||||
and context_second_pass_sigmas is not None
|
||||
):
|
||||
segment_second_pass_sigmas = context_second_pass_sigmas
|
||||
# No upscale pass is needed when the first-pass latent already
|
||||
# sits at the target size (upscale_by <= 1 configurations, or
|
||||
# variants that downscale the first pass to the target size).
|
||||
if audio_only or (
|
||||
# No upscale pass is needed when the certified rule says the
|
||||
# factor does not ask for one, or when a variant sampled the
|
||||
# first pass directly at the target size.
|
||||
if not cls._h3_needs_latent_upscale(
|
||||
audio_only,
|
||||
first_pass_width,
|
||||
first_pass_height,
|
||||
) == (target_width, target_height):
|
||||
target_width,
|
||||
target_height,
|
||||
upscale_by,
|
||||
):
|
||||
report_segment_step(0.46)
|
||||
upscaled_latent = final_latent
|
||||
else:
|
||||
|
||||
@ -268,9 +268,8 @@ 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` 会直接报错,因为该节点始终走潜空间放大。旧工作流没有该控件时自动回落到默认检查点。二采默认启用**自动空间分块**(`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)。
|
||||
- `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)。此外,Slow 节点隐藏一采的尺寸会在半分辨率基础上吸附到最近的 64px 网格(1080p 编辑器一采 960x512、1344x768 一采 704x384、4K 编辑器一采 1920x1088 不变),保证续接片段的 context 关键帧 latent 行列数为偶数、可被 `patchify_video` 处理(否则多片段 1080p 项目在第二段崩溃)——该吸附**仅作用于 Slow 节点**,`MultiTrack Project` 与 `Moxie MultiTrack Project` 保持认证的整数减半一采行为(如 1344x768 编辑器一采 672x384),输出尺寸不受影响。
|
||||
- 编辑器分辨率是一采尺寸;`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` 仅适用于显式的一阶段检查点流程;不要自动开启。
|
||||
|
||||
@ -2332,10 +2332,9 @@ 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"
|
||||
# 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)
|
||||
# Certified plain-halving first pass: 1344x768 editor samples at half
|
||||
# size (672x384). The even-latent snap is a Slow-node-only deviation.
|
||||
assert (conditioning["width"], conditioning["height"]) == (672, 384)
|
||||
assert "SamplerCustomAdvanced" in nodes_by_type
|
||||
assert "easy h3SegmentSamplingStart" in nodes_by_type
|
||||
assert (
|
||||
@ -6556,100 +6555,63 @@ def test_h3_tiling_config_accepts_automatic_tile_count(monkeypatch):
|
||||
config({"enabled_tiling": "true", "tile_count": bad_count})
|
||||
|
||||
|
||||
def test_h3_sampling_preview_sampler_allows_automatic_tile_count(monkeypatch):
|
||||
def test_h3_sampling_preview_sampler_keeps_certified_tile_count_schema(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}
|
||||
|
||||
# The certified widget text and default are untouched; the only widening
|
||||
# is min 2 -> 0, which Moxie MultiTrack Project Slow requires because the
|
||||
# engine builds this node with tile_count 0 (automatic) and ComfyUI
|
||||
# validates inputs against min at execution. Certified workflows send
|
||||
# 2-8 (or nothing) and validate exactly as before.
|
||||
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"]
|
||||
assert tile_count.kwargs.get("tooltip") is None
|
||||
|
||||
|
||||
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
|
||||
def test_moxie_project_slow_snaps_first_pass_even_latent_grid_scoped_to_slow(
|
||||
monkeypatch,
|
||||
):
|
||||
module = _load_moxie_project(monkeypatch)
|
||||
snap = module._h3_even_latent_size
|
||||
|
||||
# 1080p: 540 encodes to a 17-row latent (odd) -> 512 keeps 16 rows.
|
||||
# Pure helper: nearest 64px multiple keeps even latent row/column counts.
|
||||
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(1080) == 1088
|
||||
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
|
||||
assert snap(31) == 32
|
||||
assert snap(33) == 64
|
||||
|
||||
# Certified nodes keep the plain-halving first pass, byte for byte.
|
||||
base = module.EasyMultiTrackProject
|
||||
easy = module.MoxieProject
|
||||
for project_class in (base, easy):
|
||||
assert project_class._h3_first_pass_size(1344, 768, 0.5) == (672, 384)
|
||||
assert project_class._h3_first_pass_size(1920, 1080, 0.5) == (960, 540)
|
||||
assert project_class._h3_first_pass_size(3840, 2160, 0.5) == (1920, 1080)
|
||||
|
||||
def test_h3_first_pass_dims_snap_to_even_latent_grid(monkeypatch):
|
||||
module = _load_minimax_node(monkeypatch)
|
||||
# Only the Slow node snaps its hidden pass onto the even-latent grid.
|
||||
slow = module.MoxieProjectSlow
|
||||
assert slow._h3_first_pass_size(1344, 768, 0.5) == (704, 384)
|
||||
assert slow._h3_first_pass_size(1920, 1080, 0.5) == (960, 512)
|
||||
assert slow._h3_first_pass_size(3840, 2160, 0.5) == (1920, 1088)
|
||||
|
||||
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)
|
||||
# Certified upscale rule: skip exactly when the factor does not ask for
|
||||
# one. Slow decides by size comparison instead (its first pass sits at
|
||||
# half resolution and must always be bridged by the upscaler).
|
||||
for project_class in (base, easy):
|
||||
assert project_class._h3_needs_latent_upscale(False, 672, 384, 840, 480, 1.25)
|
||||
assert not project_class._h3_needs_latent_upscale(False, 672, 384, 672, 384, 1.0)
|
||||
assert not project_class._h3_needs_latent_upscale(True, 32, 32, 32, 32, 1.25)
|
||||
assert slow._h3_needs_latent_upscale(False, 960, 512, 1920, 1080, 1.0)
|
||||
assert not slow._h3_needs_latent_upscale(False, 1920, 1080, 1920, 1080, 1.0)
|
||||
assert not slow._h3_needs_latent_upscale(True, 32, 32, 32, 32, 1.0)
|
||||
|
||||
|
||||
def test_denoise_truncated_sigmas_matches_ksampler_math(monkeypatch):
|
||||
|
||||
@ -400,26 +400,6 @@ 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 {}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user