Spaces:
Sleeping
Sleeping
Update h3_split_blocks.py
Browse files- h3_split_blocks.py +112 -11
h3_split_blocks.py
CHANGED
|
@@ -12,22 +12,23 @@ Two things the blocks leave to the caller: a keyframe reaches them EXIF-transpos
|
|
| 12 |
frame count is aligned to `17 * n + 5` before the call, since that arithmetic lives on the denoising side of the cut.
|
| 13 |
"""
|
| 14 |
|
| 15 |
-
|
|
|
|
|
|
|
| 16 |
from diffusers.modular_pipelines.minimax_h3.decoders import MiniMaxH3AfterDenoiseStep
|
| 17 |
from diffusers.modular_pipelines.minimax_h3.encoders import (
|
|
|
|
| 18 |
MiniMaxH3Ref2VAReferenceEncoderStep,
|
| 19 |
MiniMaxH3Ref2VATextEncoderStep,
|
| 20 |
MiniMaxH3TextEncoderStep,
|
| 21 |
)
|
| 22 |
from diffusers.modular_pipelines.minimax_h3.modular_blocks_minimax_h3 import (
|
| 23 |
-
MiniMaxH3AutoKeyframeVaeEncoderStep,
|
| 24 |
-
MiniMaxH3AutoResizeStep,
|
| 25 |
MiniMaxH3CoreDenoiseStep,
|
| 26 |
MiniMaxH3DecodeStep,
|
|
|
|
| 27 |
MiniMaxH3Ref2VACoreDenoiseStep,
|
| 28 |
-
_generation_outputs,
|
| 29 |
)
|
| 30 |
-
from diffusers.modular_pipelines.modular_pipeline import SequentialPipelineBlocks
|
| 31 |
from diffusers.modular_pipelines.modular_pipeline_utils import OutputParam
|
| 32 |
|
| 33 |
|
|
@@ -46,11 +47,95 @@ def _wire_outputs(num_frames: bool = True) -> list[OutputParam]:
|
|
| 46 |
]
|
| 47 |
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
class MiniMaxH3ConditionerBlocks(SequentialPipelineBlocks):
|
| 50 |
"""The conditioner half of a split MiniMax-H3: the keyframes on the canvas plus the Qwen3-VL read at layer 50."""
|
| 51 |
|
| 52 |
model_name = "minimax-h3"
|
| 53 |
-
block_classes = [
|
| 54 |
block_names = ["resize", "text_encoder"]
|
| 55 |
|
| 56 |
@property
|
|
@@ -71,9 +156,9 @@ class MiniMaxH3GeneratorBlocks(SequentialPipelineBlocks):
|
|
| 71 |
|
| 72 |
model_name = "minimax-h3"
|
| 73 |
block_classes = [
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
MiniMaxH3AfterDenoiseStep,
|
| 78 |
MiniMaxH3DecodeStep,
|
| 79 |
]
|
|
@@ -89,7 +174,15 @@ class MiniMaxH3GeneratorBlocks(SequentialPipelineBlocks):
|
|
| 89 |
|
| 90 |
@property
|
| 91 |
def outputs(self):
|
| 92 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
|
| 95 |
class MiniMaxH3Ref2VAConditionerBlocks(SequentialPipelineBlocks):
|
|
@@ -144,4 +237,12 @@ class MiniMaxH3Ref2VAGeneratorBlocks(SequentialPipelineBlocks):
|
|
| 144 |
|
| 145 |
@property
|
| 146 |
def outputs(self):
|
| 147 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
frame count is aligned to `17 * n + 5` before the call, since that arithmetic lives on the denoising side of the cut.
|
| 13 |
"""
|
| 14 |
|
| 15 |
+
import torch
|
| 16 |
+
|
| 17 |
+
from diffusers.modular_pipelines.minimax_h3.before_encoder import MiniMaxH3ResizeStep, MiniMaxH3Ref2VASetupStep
|
| 18 |
from diffusers.modular_pipelines.minimax_h3.decoders import MiniMaxH3AfterDenoiseStep
|
| 19 |
from diffusers.modular_pipelines.minimax_h3.encoders import (
|
| 20 |
+
MiniMaxH3KeyframeVaeEncoderStep,
|
| 21 |
MiniMaxH3Ref2VAReferenceEncoderStep,
|
| 22 |
MiniMaxH3Ref2VATextEncoderStep,
|
| 23 |
MiniMaxH3TextEncoderStep,
|
| 24 |
)
|
| 25 |
from diffusers.modular_pipelines.minimax_h3.modular_blocks_minimax_h3 import (
|
|
|
|
|
|
|
| 26 |
MiniMaxH3CoreDenoiseStep,
|
| 27 |
MiniMaxH3DecodeStep,
|
| 28 |
+
MiniMaxH3FL2VACoreDenoiseStep,
|
| 29 |
MiniMaxH3Ref2VACoreDenoiseStep,
|
|
|
|
| 30 |
)
|
| 31 |
+
from diffusers.modular_pipelines.modular_pipeline import ConditionalPipelineBlocks, SequentialPipelineBlocks
|
| 32 |
from diffusers.modular_pipelines.modular_pipeline_utils import OutputParam
|
| 33 |
|
| 34 |
|
|
|
|
| 47 |
]
|
| 48 |
|
| 49 |
|
| 50 |
+
class MiniMaxH3SplitBeforeEncodeStep(ConditionalPipelineBlocks):
|
| 51 |
+
"""Media preparation block for the split deployment's `t2va` / `fl2va` half — no `ref2va` branch.
|
| 52 |
+
|
| 53 |
+
Narrower than main's own `MiniMaxH3AutoBeforeEncodeStep`, the same way `MiniMaxH3A2VAutoBeforeEncodeStep` is
|
| 54 |
+
in the audio-conditioned Space: the upstream auto wrapper's `ref2va` branch declares
|
| 55 |
+
`MiniMaxH3Ref2VASetupStep`, which this half never needs — `MiniMaxH3Ref2VAConditionerBlocks` already owns
|
| 56 |
+
that, on its own `transformer_ref`-side classes.
|
| 57 |
+
"""
|
| 58 |
+
|
| 59 |
+
model_name = "minimax-h3"
|
| 60 |
+
block_classes = [MiniMaxH3ResizeStep]
|
| 61 |
+
block_names = ["keyframes"]
|
| 62 |
+
block_trigger_inputs = ["image", "last_image"]
|
| 63 |
+
default_block_name = None
|
| 64 |
+
|
| 65 |
+
def select_block(self, **kwargs) -> str | None:
|
| 66 |
+
if kwargs.get("image") is not None or kwargs.get("last_image") is not None:
|
| 67 |
+
return "keyframes"
|
| 68 |
+
return None
|
| 69 |
+
|
| 70 |
+
@property
|
| 71 |
+
def description(self):
|
| 72 |
+
return (
|
| 73 |
+
"Media preparation block.\n"
|
| 74 |
+
" - `MiniMaxH3ResizeStep` runs when a keyframe is provided (`fl2va`), putting it onto the target "
|
| 75 |
+
"canvas.\n"
|
| 76 |
+
" - a text-only request (`t2va`) skips this block, and the layout step falls back to MiniMax-H3's own "
|
| 77 |
+
"16:9 canvas."
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
class MiniMaxH3SplitVaeEncoderStep(ConditionalPipelineBlocks):
|
| 82 |
+
"""VAE encoder block for the split deployment's `t2va` / `fl2va` half — no `ref2va` branch, for the same
|
| 83 |
+
reason `MiniMaxH3SplitBeforeEncodeStep` has none."""
|
| 84 |
+
|
| 85 |
+
model_name = "minimax-h3"
|
| 86 |
+
block_classes = [MiniMaxH3KeyframeVaeEncoderStep]
|
| 87 |
+
block_names = ["keyframes"]
|
| 88 |
+
block_trigger_inputs = ["image", "last_image"]
|
| 89 |
+
default_block_name = None
|
| 90 |
+
|
| 91 |
+
def select_block(self, **kwargs) -> str | None:
|
| 92 |
+
if kwargs.get("image") is not None or kwargs.get("last_image") is not None:
|
| 93 |
+
return "keyframes"
|
| 94 |
+
return None
|
| 95 |
+
|
| 96 |
+
@property
|
| 97 |
+
def description(self):
|
| 98 |
+
return (
|
| 99 |
+
"VAE encoder block.\n"
|
| 100 |
+
" - `MiniMaxH3KeyframeVaeEncoderStep` runs when a keyframe is provided (`fl2va`).\n"
|
| 101 |
+
" - a text-only request (`t2va`) skips this block."
|
| 102 |
+
)
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
class MiniMaxH3SplitDenoiseStep(ConditionalPipelineBlocks):
|
| 106 |
+
"""Denoise block for the split deployment's `t2va` / `fl2va` half.
|
| 107 |
+
|
| 108 |
+
`MiniMaxH3CoreDenoiseStep` is `t2va`-only as of the diffusers 0.40.0 refactor (it opens with
|
| 109 |
+
`MiniMaxH3NoKeyframeAnchorsStep`); keyframe-anchored generation moved to the separate
|
| 110 |
+
`MiniMaxH3FL2VACoreDenoiseStep`. This selects between them the same way `MiniMaxH3A2VAutoDenoiseStep` selects
|
| 111 |
+
between its own audio-conditioned pair — no `ref2va` branch, since that would declare `transformer_ref`, the
|
| 112 |
+
partition this half must never load.
|
| 113 |
+
"""
|
| 114 |
+
|
| 115 |
+
model_name = "minimax-h3"
|
| 116 |
+
block_classes = [MiniMaxH3FL2VACoreDenoiseStep, MiniMaxH3CoreDenoiseStep]
|
| 117 |
+
block_names = ["fl2va", "t2va"]
|
| 118 |
+
block_trigger_inputs = ["image", "last_image"]
|
| 119 |
+
default_block_name = "t2va"
|
| 120 |
+
|
| 121 |
+
def select_block(self, **kwargs) -> str | None:
|
| 122 |
+
if kwargs.get("image") is not None or kwargs.get("last_image") is not None:
|
| 123 |
+
return "fl2va"
|
| 124 |
+
return None
|
| 125 |
+
|
| 126 |
+
@property
|
| 127 |
+
def description(self):
|
| 128 |
+
return (
|
| 129 |
+
"Denoise block.\n"
|
| 130 |
+
" - the `fl2va` core runs when a keyframe is provided, against the `transformer` partition.\n"
|
| 131 |
+
" - the `t2va` core runs otherwise, against the same partition."
|
| 132 |
+
)
|
| 133 |
+
|
| 134 |
class MiniMaxH3ConditionerBlocks(SequentialPipelineBlocks):
|
| 135 |
"""The conditioner half of a split MiniMax-H3: the keyframes on the canvas plus the Qwen3-VL read at layer 50."""
|
| 136 |
|
| 137 |
model_name = "minimax-h3"
|
| 138 |
+
block_classes = [MiniMaxH3SplitBeforeEncodeStep, MiniMaxH3TextEncoderStep]
|
| 139 |
block_names = ["resize", "text_encoder"]
|
| 140 |
|
| 141 |
@property
|
|
|
|
| 156 |
|
| 157 |
model_name = "minimax-h3"
|
| 158 |
block_classes = [
|
| 159 |
+
MiniMaxH3SplitBeforeEncodeStep,
|
| 160 |
+
MiniMaxH3SplitVaeEncoderStep,
|
| 161 |
+
MiniMaxH3SplitDenoiseStep,
|
| 162 |
MiniMaxH3AfterDenoiseStep,
|
| 163 |
MiniMaxH3DecodeStep,
|
| 164 |
]
|
|
|
|
| 174 |
|
| 175 |
@property
|
| 176 |
def outputs(self):
|
| 177 |
+
return [
|
| 178 |
+
OutputParam.template("videos", description="The generated video."),
|
| 179 |
+
OutputParam(
|
| 180 |
+
"audio",
|
| 181 |
+
type_hint=torch.Tensor,
|
| 182 |
+
description="The soundtrack of the packed sequence, of shape `(1, 2, num_samples)`.",
|
| 183 |
+
),
|
| 184 |
+
OutputParam("sampling_rate", type_hint=int, description="Sample rate of the soundtrack in Hz."),
|
| 185 |
+
]
|
| 186 |
|
| 187 |
|
| 188 |
class MiniMaxH3Ref2VAConditionerBlocks(SequentialPipelineBlocks):
|
|
|
|
| 237 |
|
| 238 |
@property
|
| 239 |
def outputs(self):
|
| 240 |
+
return [
|
| 241 |
+
OutputParam.template("videos", description="The generated video."),
|
| 242 |
+
OutputParam(
|
| 243 |
+
"audio",
|
| 244 |
+
type_hint=torch.Tensor,
|
| 245 |
+
description="The soundtrack of the packed sequence, of shape `(1, 2, num_samples)`.",
|
| 246 |
+
),
|
| 247 |
+
OutputParam("sampling_rate", type_hint=int, description="Sample rate of the soundtrack in Hz."),
|
| 248 |
+
]
|