Spaces:
Sleeping
Sleeping
Upload h3_split_blocks.py with huggingface_hub
Browse files- h3_split_blocks.py +147 -0
h3_split_blocks.py
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Composable conditioner and generator halves of MiniMax-H3, for both checkpoint partitions.
|
| 2 |
+
|
| 3 |
+
The blocks cut `MiniMaxH3Blocks` at its `text_encoder` step. They can run in separate Spaces with `prompt_embeds` and
|
| 4 |
+
`text_token_tags` as a wire format, or sequentially in one GPU worker when a compact local conditioner fits beside
|
| 5 |
+
the generator.
|
| 6 |
+
|
| 7 |
+
`resize` / `setup` run on **both** sides: they own no pretrained component, and each half needs the canvas and the
|
| 8 |
+
prepared keyframes or normalized references. Both conditioner halves also return the resolved `height` / `width` /
|
| 9 |
+
`num_frames`, which the generating half pins rather than re-deriving.
|
| 10 |
+
|
| 11 |
+
Two things the blocks leave to the caller: a keyframe reaches them EXIF-transposed and in RGB, and the `t2va` / `fl2va`
|
| 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 |
+
from diffusers.modular_pipelines.minimax_h3.before_encoder import MiniMaxH3Ref2VASetupStep
|
| 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 |
+
|
| 34 |
+
def _wire_outputs(num_frames: bool = True) -> list[OutputParam]:
|
| 35 |
+
"""The wire format of the split. `num_frames` is declared by the `ref2va` half alone, whose setup resolves one."""
|
| 36 |
+
return [
|
| 37 |
+
OutputParam.template("prompt_embeds"),
|
| 38 |
+
OutputParam("text_token_tags", description="The per-row modality tag of every row of `prompt_embeds`."),
|
| 39 |
+
OutputParam("height", type_hint=int, description="Resolved height of the generated video in pixels."),
|
| 40 |
+
OutputParam("width", type_hint=int, description="Resolved width of the generated video in pixels."),
|
| 41 |
+
*(
|
| 42 |
+
[OutputParam("num_frames", type_hint=int, description="Resolved number of frames, of the form 17 * n + 5.")]
|
| 43 |
+
if num_frames
|
| 44 |
+
else []
|
| 45 |
+
),
|
| 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 = [MiniMaxH3AutoResizeStep, MiniMaxH3TextEncoderStep]
|
| 54 |
+
block_names = ["resize", "text_encoder"]
|
| 55 |
+
|
| 56 |
+
@property
|
| 57 |
+
def description(self):
|
| 58 |
+
return (
|
| 59 |
+
"The conditioner half of a split MiniMax-H3 deployment: puts the keyframes onto the target canvas and "
|
| 60 |
+
"encodes MiniMax-H3's presentation of the request into the `prompt_embeds` / `text_token_tags` pair the "
|
| 61 |
+
"denoising half consumes. The frame count is the caller's to align."
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
@property
|
| 65 |
+
def outputs(self):
|
| 66 |
+
return _wire_outputs(num_frames=False)
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
class MiniMaxH3GeneratorBlocks(SequentialPipelineBlocks):
|
| 70 |
+
"""The denoising half of a split MiniMax-H3: `MiniMaxH3Blocks` with its `text_encoder` step removed."""
|
| 71 |
+
|
| 72 |
+
model_name = "minimax-h3"
|
| 73 |
+
block_classes = [
|
| 74 |
+
MiniMaxH3AutoResizeStep,
|
| 75 |
+
MiniMaxH3AutoKeyframeVaeEncoderStep,
|
| 76 |
+
MiniMaxH3CoreDenoiseStep,
|
| 77 |
+
MiniMaxH3AfterDenoiseStep,
|
| 78 |
+
MiniMaxH3DecodeStep,
|
| 79 |
+
]
|
| 80 |
+
block_names = ["resize", "vae_encoder", "denoise", "after_denoise", "decode"]
|
| 81 |
+
|
| 82 |
+
@property
|
| 83 |
+
def description(self):
|
| 84 |
+
return (
|
| 85 |
+
"The denoising half of a split MiniMax-H3 deployment: the `t2va` / `fl2va` branch of `MiniMaxH3Blocks` "
|
| 86 |
+
"without its text-encoder step, so `prompt_embeds` and `text_token_tags` come in as inputs and the "
|
| 87 |
+
"conditioner is supplied by the caller or by the preceding local conditioner half."
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
@property
|
| 91 |
+
def outputs(self):
|
| 92 |
+
return _generation_outputs()
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
class MiniMaxH3Ref2VAConditionerBlocks(SequentialPipelineBlocks):
|
| 96 |
+
"""The conditioner half of a split `ref2va`: the resolved plan plus the Qwen3-VL read at its 50th layer.
|
| 97 |
+
|
| 98 |
+
Component for component this is `MiniMaxH3ConditionerBlocks`, so one conditioner Space serves both partitions.
|
| 99 |
+
What differs is the presentation: `ref2va` prepends a label per reference and a vision block per image and per
|
| 100 |
+
merged video frame pair, so the references themselves have to reach this half.
|
| 101 |
+
"""
|
| 102 |
+
|
| 103 |
+
model_name = "minimax-h3"
|
| 104 |
+
block_classes = [MiniMaxH3Ref2VASetupStep, MiniMaxH3Ref2VATextEncoderStep]
|
| 105 |
+
block_names = ["setup", "text_encoder"]
|
| 106 |
+
|
| 107 |
+
@property
|
| 108 |
+
def description(self):
|
| 109 |
+
return (
|
| 110 |
+
"The conditioner half of a split MiniMax-H3 `ref2va` deployment: resolves the request plan (canvas, frame "
|
| 111 |
+
"count, references normalized onto MiniMax-H3's own rates and resolutions) and encodes MiniMax-H3's "
|
| 112 |
+
"presentation of it into the `prompt_embeds` / `text_token_tags` pair the denoising half consumes."
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
@property
|
| 116 |
+
def outputs(self):
|
| 117 |
+
return _wire_outputs()
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
class MiniMaxH3Ref2VAGeneratorBlocks(SequentialPipelineBlocks):
|
| 121 |
+
"""The denoising half of a split `ref2va`: the `ref2va` branch with its `text_encoder` step removed.
|
| 122 |
+
|
| 123 |
+
`reference_encoder` stays here, next to the two autoencoders it runs: its output shapes are where every reference
|
| 124 |
+
block's geometry in the packed layout comes from.
|
| 125 |
+
"""
|
| 126 |
+
|
| 127 |
+
model_name = "minimax-h3"
|
| 128 |
+
block_classes = [
|
| 129 |
+
MiniMaxH3Ref2VASetupStep,
|
| 130 |
+
MiniMaxH3Ref2VAReferenceEncoderStep,
|
| 131 |
+
MiniMaxH3Ref2VACoreDenoiseStep,
|
| 132 |
+
MiniMaxH3AfterDenoiseStep,
|
| 133 |
+
MiniMaxH3DecodeStep,
|
| 134 |
+
]
|
| 135 |
+
block_names = ["setup", "reference_encoder", "denoise", "after_denoise", "decode"]
|
| 136 |
+
|
| 137 |
+
@property
|
| 138 |
+
def description(self):
|
| 139 |
+
return (
|
| 140 |
+
"The denoising half of a split MiniMax-H3 `ref2va` deployment: the `ref2va` branch of `MiniMaxH3Blocks` "
|
| 141 |
+
"without its text-encoder step, so `prompt_embeds` and `text_token_tags` come in as inputs and the "
|
| 142 |
+
"conditioner is supplied by the caller or preceding local half. The transformer is the `transformer_ref` partition."
|
| 143 |
+
)
|
| 144 |
+
|
| 145 |
+
@property
|
| 146 |
+
def outputs(self):
|
| 147 |
+
return _generation_outputs()
|