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.
433 lines
18 KiB
Python
433 lines
18 KiB
Python
from __future__ import annotations
|
|
|
|
import comfy.samplers
|
|
import folder_paths
|
|
import math
|
|
from comfy_api.latest import io
|
|
|
|
from .nodes.project import (
|
|
EasyMultiTrackProject,
|
|
H3_CONTEXT_LENGTH_OPTIONS,
|
|
H3_CONTEXT_SOURCE_FRAMES,
|
|
TYPE_TRACKS_INFO,
|
|
_first_input,
|
|
)
|
|
|
|
# Values baked from the reference workflow (Moxie-clean.json). End users only
|
|
# control project_name, steps and seed on this node.
|
|
BAKED_PROJECT_SETTINGS = {
|
|
"project_save": "override",
|
|
"segment_start_number": 1,
|
|
"segment_count": -1,
|
|
"sampling_plan": "custom",
|
|
"sampling_mode": "single",
|
|
"1st_pass_only": False,
|
|
"disable_2nd_noise": False,
|
|
"upscale_by": 1.5,
|
|
"upscale_model": "None",
|
|
"enabled_tiling": "false",
|
|
}
|
|
BAKED_SAMPLER_NAME = "euler"
|
|
BAKED_SCHEDULER = "beta"
|
|
|
|
# Moxie MultiTrack Project Slow: the hidden half-resolution first pass is
|
|
# upscaled to the final size by the H3 latent upscaler model and refined with
|
|
# a short low-denoise euler pass instead of the RTX VSR pixel restore.
|
|
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}
|
|
# The tiling toggle OFF: the engine skips tiling and samples the refine pass
|
|
# in one piece (plain SamplerCustomAdvanced, the pre-tiling behaviour).
|
|
SLOW_TILING_DISABLED = {"enabled_tiling": "false", "tile_count": 0}
|
|
SLOW_PROJECT_SETTINGS_DELTA = {
|
|
"sampling_mode": "dual",
|
|
# The first pass already runs at half the editor resolution, so the final
|
|
# size IS the editor size: a scale factor of 1.0 keeps the project
|
|
# manifest at the editor dimensions while the latent upscaler (target
|
|
# dimensions mode) bridges the half-res gap. The upscaler checkpoint is
|
|
# NOT baked and neither is tiling: the Slow node exposes the
|
|
# upscale_model widget and the tiling toggle instead.
|
|
"upscale_by": 1.0,
|
|
}
|
|
|
|
|
|
_TILING_ON_VALUES = frozenset({"true", "enable", "enabled", "on", "1"})
|
|
|
|
|
|
def _tiling_switch(value, default: bool = True) -> bool:
|
|
"""Resolve the tiling toggle; tolerates booleans and legacy strings."""
|
|
enabled = _first_input(value, default)
|
|
if isinstance(enabled, str):
|
|
return enabled.strip().lower() in _TILING_ON_VALUES
|
|
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
|
|
for name, value in (
|
|
("model", model),
|
|
("clip", clip),
|
|
("video_vae", video_vae),
|
|
("audio_vae", audio_vae),
|
|
)
|
|
if value is None
|
|
]
|
|
if missing:
|
|
raise ValueError(
|
|
"MoxieProject: Missing required model components: "
|
|
+ ", ".join(missing)
|
|
+ ". Wire model, clip, video_vae, and audio_vae from Moxie Multimedia Loader."
|
|
)
|
|
|
|
|
|
def _denoise_truncated_sigmas(
|
|
model_sampling, scheduler: str, steps: int, denoise: float
|
|
):
|
|
"""Sigma schedule for `steps` steps at `denoise`, matching KSampler.
|
|
|
|
Replicates comfy KSampler.set_steps: build the schedule at
|
|
int(steps / denoise) total steps, then keep the last steps + 1 sigmas.
|
|
Written out because newer ComfyUI builds dropped the denoise kwarg from
|
|
comfy.samplers.calculate_sigmas.
|
|
"""
|
|
if denoise <= 0.0:
|
|
raise ValueError("denoise must be positive")
|
|
if denoise > 0.9999:
|
|
total_steps = steps
|
|
else:
|
|
total_steps = int(steps / denoise)
|
|
schedule = comfy.samplers.calculate_sigmas(
|
|
model_sampling, scheduler, total_steps
|
|
).cpu()
|
|
return schedule[-(steps + 1):]
|
|
|
|
|
|
class MoxieProject(EasyMultiTrackProject):
|
|
"""MultiTrack Project with the sampling stack consolidated.
|
|
|
|
Replaces: easy multitrackProject + 2x KSamplerSelect (euler / sa_solver)
|
|
+ BasicScheduler (beta) + ManualSigmas. Execution delegates to the
|
|
battle-tested Easy-Media implementation with sampler/sigmas computed
|
|
internally from the exposed `steps` widget.
|
|
"""
|
|
|
|
@classmethod
|
|
def _baked_project_settings(cls) -> dict:
|
|
return dict(BAKED_PROJECT_SETTINGS)
|
|
|
|
@classmethod
|
|
def _component_inputs(cls) -> list:
|
|
"""Extra inputs subclasses slot in after the model components."""
|
|
return []
|
|
|
|
@classmethod
|
|
def _project_inputs(cls) -> list:
|
|
inputs = [
|
|
TYPE_TRACKS_INFO.Input("tracks_info"),
|
|
io.Model.Input("model", tooltip="Diffusion model from Moxie Multimedia Loader (attention backend already applied)."),
|
|
io.Clip.Input("clip", tooltip="CLIP text encoder from Moxie Multimedia Loader."),
|
|
io.Vae.Input("video_vae", tooltip="Video VAE from Moxie Multimedia Loader."),
|
|
io.Vae.Input("audio_vae", tooltip="Audio VAE from Moxie Multimedia Loader (required to decode Moxie audio)."),
|
|
]
|
|
inputs.extend(cls._component_inputs())
|
|
inputs.extend(
|
|
[
|
|
io.String.Input("project_name", default="",
|
|
tooltip="Name of the project; used for output folders."),
|
|
io.Int.Input(
|
|
"steps",
|
|
default=3,
|
|
min=1,
|
|
max=10000,
|
|
tooltip="Sampling steps for the beta scheduler (3 for the baked-in 3-step distill; "
|
|
"8 for busy motion, 6 low motion, 4 runs/no dialogue).",
|
|
),
|
|
io.Combo.Input(
|
|
"context_frames",
|
|
options=[str(option) for option in H3_CONTEXT_LENGTH_OPTIONS],
|
|
default=str(H3_CONTEXT_SOURCE_FRAMES),
|
|
tooltip=(
|
|
"Video frames copied from the previous segment as "
|
|
"continuation context for segments whose continuity "
|
|
"mode is Context or Context Swap. Longer values hand "
|
|
"off motion more smoothly but generate that many extra "
|
|
"frames per segment. Values are H3 temporal-grid "
|
|
"lengths shared with the Moxie context sampler nodes."
|
|
),
|
|
),
|
|
io.Int.Input(
|
|
"seed",
|
|
default=42,
|
|
min=0,
|
|
max=0xFFFFFFFFFFFFFFFF,
|
|
step=1,
|
|
control_after_generate=io.ControlAfterGenerate.randomize,
|
|
),
|
|
]
|
|
)
|
|
return inputs
|
|
|
|
@classmethod
|
|
def define_schema(cls) -> io.Schema:
|
|
return io.Schema(
|
|
node_id="MoxieProject",
|
|
display_name="Moxie MultiTrack Project",
|
|
category="EasyUse/MultiTrackEditor",
|
|
description=(
|
|
"Build and execute a multi-track Moxie project. "
|
|
"Takes model, clip, video_vae and audio_vae directly from the Moxie Multimedia Loader. "
|
|
"Sampling is baked to a single pass with euler + beta sigmas; set only steps and seed."
|
|
),
|
|
is_input_list=True,
|
|
enable_expand=True,
|
|
not_idempotent=True,
|
|
inputs=cls._project_inputs(),
|
|
hidden=[io.Hidden.prompt, io.Hidden.unique_id],
|
|
outputs=[
|
|
io.String.Output("PROJECT_NAME"),
|
|
io.Audio.Output("LOCKED_AUDIO"),
|
|
],
|
|
)
|
|
|
|
@classmethod
|
|
def execute(cls, **kwargs) -> io.NodeOutput:
|
|
steps = int(_first_input(kwargs.get("steps"), 3))
|
|
|
|
model = _first_input(kwargs.get("model"))
|
|
clip = _first_input(kwargs.get("clip"))
|
|
video_vae = _first_input(kwargs.get("video_vae"))
|
|
audio_vae = _first_input(kwargs.get("audio_vae"))
|
|
_require_moxie_components(model, clip, video_vae, audio_vae)
|
|
|
|
# Pack the direct inputs into the loader dict consumed by
|
|
# EasyMultiTrackProject.execute (internal plumbing only).
|
|
synthesized_loader = {
|
|
"model": model,
|
|
"clip": clip,
|
|
"vae": video_vae,
|
|
"audio_vae": audio_vae,
|
|
}
|
|
|
|
# Same math as the native BasicScheduler node (scheduler=beta, denoise=1.0).
|
|
sigmas = comfy.samplers.calculate_sigmas(
|
|
model.get_model_object("model_sampling"), BAKED_SCHEDULER, steps
|
|
).cpu()
|
|
sigmas = sigmas[-(steps + 1):]
|
|
sampler = comfy.samplers.sampler_object(BAKED_SAMPLER_NAME)
|
|
|
|
baked = dict(kwargs)
|
|
baked.update(cls._baked_project_settings())
|
|
baked["model_loader"] = synthesized_loader
|
|
baked["sampler"] = sampler
|
|
baked["sigmas"] = sigmas
|
|
return super().execute(**baked)
|
|
|
|
|
|
class MoxieProjectSlow(MoxieProject):
|
|
"""Moxie MultiTrack Project with a latent-upscale refine pass.
|
|
|
|
Identical pipeline to MoxieProject (hidden half-resolution first pass,
|
|
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. 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. The `tiling` switch
|
|
turns the tiles off for machines that prefer the refine pass sampled in
|
|
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
|
|
def _latent_upscaler_options(cls) -> list:
|
|
models = list(folder_paths.get_filename_list("latent_upscale_models"))
|
|
if SLOW_UPSCALE_MODEL not in models:
|
|
# Keep the bundled checkpoint selectable even before it is
|
|
# downloaded; the combo default must always be a valid option.
|
|
models.append(SLOW_UPSCALE_MODEL)
|
|
return ["None"] + models
|
|
|
|
@classmethod
|
|
def _component_inputs(cls) -> list:
|
|
return [
|
|
io.Combo.Input(
|
|
"upscale_model",
|
|
options=cls._latent_upscaler_options(),
|
|
default=SLOW_UPSCALE_MODEL,
|
|
tooltip=(
|
|
"Latent upscaler checkpoint that brings the hidden "
|
|
"half-resolution first pass to the final size before "
|
|
"the 2-step refine. Files live under "
|
|
"ComfyUI/models/latent_upscale_models/; None is "
|
|
"rejected because this node always upscales in latent "
|
|
"space instead of the RTX restore."
|
|
),
|
|
),
|
|
io.Boolean.Input(
|
|
"tiling",
|
|
default=True,
|
|
tooltip=(
|
|
"Tile the 2-step refine pass so large projects (up to "
|
|
"1920x1080) also fit on 12 GB cards and on AMD or Intel "
|
|
"GPUs; the tile count adapts to the available memory and "
|
|
"tiling is skipped entirely when the whole pass fits "
|
|
"anyway. Disable to sample the refine pass in one piece."
|
|
),
|
|
),
|
|
]
|
|
|
|
@classmethod
|
|
def _baked_project_settings(cls) -> dict:
|
|
settings = dict(BAKED_PROJECT_SETTINGS)
|
|
# The upscaler checkpoint and the tiling switch come from widgets.
|
|
settings.pop("upscale_model", None)
|
|
settings.pop("enabled_tiling", None)
|
|
settings.update(SLOW_PROJECT_SETTINGS_DELTA)
|
|
return settings
|
|
|
|
@classmethod
|
|
def _h3_first_pass_resolution_scale(cls, sampling_mode: str) -> float:
|
|
# Dual mode would sample the first pass at the editor size; the Slow
|
|
# node keeps MoxieProject's hidden half-resolution speed trick and
|
|
# 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(
|
|
node_id="MoxieProjectSlow",
|
|
display_name="Moxie MultiTrack Project Slow",
|
|
category="EasyUse/MultiTrackEditor",
|
|
description=(
|
|
"Build and execute a multi-track Moxie project with a "
|
|
"latent-upscale refine pass. Takes model, clip, video_vae and "
|
|
"audio_vae directly from the Moxie Multimedia Loader and an "
|
|
"upscale_model checkpoint from latent_upscale_models. The "
|
|
"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 through automatic spatial tiling "
|
|
"(scales to the available VRAM, enabling up to 1920x1080 "
|
|
"output on 12 GB and AMD/Intel GPUs); the tiling switch "
|
|
"turns the tiles off; set only steps and seed."
|
|
),
|
|
is_input_list=True,
|
|
enable_expand=True,
|
|
not_idempotent=True,
|
|
inputs=cls._project_inputs(),
|
|
hidden=[io.Hidden.prompt, io.Hidden.unique_id],
|
|
outputs=[
|
|
io.String.Output("PROJECT_NAME"),
|
|
io.Audio.Output("LOCKED_AUDIO"),
|
|
],
|
|
)
|
|
|
|
@classmethod
|
|
def execute(cls, **kwargs) -> io.NodeOutput:
|
|
model = _first_input(kwargs.get("model"))
|
|
clip = _first_input(kwargs.get("clip"))
|
|
video_vae = _first_input(kwargs.get("video_vae"))
|
|
audio_vae = _first_input(kwargs.get("audio_vae"))
|
|
_require_moxie_components(model, clip, video_vae, audio_vae)
|
|
|
|
upscale_model = _first_input(kwargs.get("upscale_model"))
|
|
if upscale_model is None:
|
|
upscale_model = SLOW_UPSCALE_MODEL
|
|
upscale_model = str(upscale_model).strip()
|
|
if not upscale_model or upscale_model == "None":
|
|
raise ValueError(
|
|
"Moxie MultiTrack Project Slow always upscales the "
|
|
"half-resolution latent in latent space, so it needs a "
|
|
"model: pick a checkpoint in the upscale_model dropdown "
|
|
"(files under ComfyUI/models/latent_upscale_models/)."
|
|
)
|
|
|
|
sigmas_2nd = _denoise_truncated_sigmas(
|
|
model.get_model_object("model_sampling"),
|
|
BAKED_SCHEDULER,
|
|
SLOW_SECOND_PASS_STEPS,
|
|
SLOW_SECOND_PASS_DENOISE,
|
|
)
|
|
# The tiling toggle: ON (default, also for old workflows without the
|
|
# widget) keeps the memory-adaptive automatic tile count; OFF hands
|
|
# the engine an explicit disabled config so the refine pass is
|
|
# sampled in one piece.
|
|
tiling_on = _tiling_switch(kwargs.get("tiling"))
|
|
injected = dict(kwargs)
|
|
injected["sampler_2nd"] = comfy.samplers.sampler_object(BAKED_SAMPLER_NAME)
|
|
injected["sigmas_2nd"] = sigmas_2nd
|
|
injected["upscale_model"] = upscale_model
|
|
injected["enabled_tiling"] = (
|
|
SLOW_TILING_SETTINGS if tiling_on else SLOW_TILING_DISABLED
|
|
)
|
|
return super().execute(**injected)
|