Spaces:
Running on Zero
fix: tiled + framewise VAE decode at the proven-fit envelope — upstream's dispatch is the gate
Browse files1216x704x121 completed its ~52 s denoise and died inside vae.decode's
conv3d on the MIG allocator (~26 GB per full-resolution intermediate at
121 frames on ~35 GB of resident weights). 704x480x49 fits. The decode,
not the denoise, is the ceiling.
Read at the pinned ac56fa2f (byte-identical in the local 0.37.1 copy):
AutoencoderKLLTX2.enable_tiling sets use_tiling and the six thresholds;
use_framewise_decoding is a SEPARATE flag it never touches; _decode
converts thresholds to latent units by floor division and compares the
actual tensor with strict >, framewise first, spatial second; and
_temporal_tiled_decode re-dispatches each temporal chunk through spatial
tiled_decode, so the two mechanisms compose and the peak decode tensor
is one tile-chunk. _encode checks the DECODING flag for its temporal
branch (an upstream quirk, identical at the pin).
The design: configure_vae_tiling hands enable_tiling thresholds equal to
the largest PROVEN-fit decode -- 704x480 spatial, 56 frames temporal --
and sets both framewise flags, once, on the ONE shared VAE at load.
Upstream's own dispatch is then the size gate:
* Always-on with upstream DEFAULTS was checked against the source and
REJECTED: the 512 px default minimum would re-route the proven-fitting
704x480 decode through the tiled blend path -- perturbing a working
size for no memory benefit. Not free, so not chosen.
* At the envelope values, everything at or inside the proven envelope
takes the SAME untiled code path as before -- structurally (strict >),
not by luck. The sha256-banked 256x256x9 (latent 8x8x2 vs thresholds
22x15x7) is nowhere near any boundary. The temporal boundary lands
EXACTLY on the proven point: 49 frames occupy (49-1)//8+1 = 7 latent
frames against a 56//8 = 7 threshold, so 7 > 7 is False -- and 57
frames chunk. The offline gate cannot verify CUDA bytes; the byte
check is the sha256 re-run on the Space, and the source-level claim
here is that the dispatch cannot reach the tiled path for those
configs.
* Anything beyond the envelope decodes in tiles of exactly the
proven-fit shape. Strides preserve upstream's own blend widths (64 px
spatial, 8 frames temporal) so oversized decodes get exactly the
shipped seam behaviour at our tile size.
* Stage 2 needs no branch of ours: the gate keys on the tensor being
decoded, and stage 2's inputs ARE the 2x size (1408x960 -> tiled).
Caveat reported rather than papered over: stage 2's FINAL pixels come
from the diffusion decoder, a separate model this flag set does not
govern.
A divisibility tripwire refuses to load if any threshold stops dividing
the loaded VAE's compression ratios exactly -- the floor division would
silently SHIFT the proven envelope, which is the off-by-one no test
downstream would notice.
Tests (12): exact plumbing, both flags, the tripwire, wiring into
_base_pipeline, and the dispatch predicate replicated verbatim from the
pinned source driving the envelope: banked config untouched, proven-fit
boundary exact, one-step-past engages the right mechanism per axis, the
live failure config engages both, stage-2's decoded size gates on what
is decoded. Gate: 2339 passed / 13 skipped (baseline 2327).
- ltx25_studio/pipelines.py +111 -0
- tests/test_vae_tiling.py +200 -0
|
@@ -64,9 +64,16 @@ __all__ = [
|
|
| 64 |
"assert_compression_ratios",
|
| 65 |
"assert_frame_rate_default",
|
| 66 |
"clear_cache",
|
|
|
|
| 67 |
"derive_pipeline",
|
| 68 |
"get_pipeline",
|
| 69 |
"mmap_backing_report",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
"stage_1_kwargs",
|
| 71 |
"stage_2_size_note",
|
| 72 |
"STAGE_2_SPATIAL_SCALE",
|
|
@@ -140,6 +147,109 @@ def assert_compression_ratios(vae) -> tuple[int, int]:
|
|
| 140 |
return temporal, spatial
|
| 141 |
|
| 142 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
def assert_frame_rate_default(pipeline_object) -> None:
|
| 144 |
"""Tripwire on upstream's own ``frame_rate`` default.
|
| 145 |
|
|
@@ -548,6 +658,7 @@ def _base_pipeline(*, dtype=None, device: str | None = None, quantization: str |
|
|
| 548 |
vae = getattr(built, "vae", None)
|
| 549 |
if vae is not None:
|
| 550 |
assert_compression_ratios(vae)
|
|
|
|
| 551 |
assert_frame_rate_default(built)
|
| 552 |
|
| 553 |
_CACHE[_BASE_CACHE_KEY] = built
|
|
|
|
| 64 |
"assert_compression_ratios",
|
| 65 |
"assert_frame_rate_default",
|
| 66 |
"clear_cache",
|
| 67 |
+
"configure_vae_tiling",
|
| 68 |
"derive_pipeline",
|
| 69 |
"get_pipeline",
|
| 70 |
"mmap_backing_report",
|
| 71 |
+
"VAE_TILE_MIN_HEIGHT",
|
| 72 |
+
"VAE_TILE_MIN_WIDTH",
|
| 73 |
+
"VAE_TILE_MIN_NUM_FRAMES",
|
| 74 |
+
"VAE_TILE_STRIDE_HEIGHT",
|
| 75 |
+
"VAE_TILE_STRIDE_WIDTH",
|
| 76 |
+
"VAE_TILE_STRIDE_NUM_FRAMES",
|
| 77 |
"stage_1_kwargs",
|
| 78 |
"stage_2_size_note",
|
| 79 |
"STAGE_2_SPATIAL_SCALE",
|
|
|
|
| 147 |
return temporal, spatial
|
| 148 |
|
| 149 |
|
| 150 |
+
# ---------------------------------------------------------------------------
|
| 151 |
+
# VAE decode tiling -- the envelope is the measured one, and the gate is
|
| 152 |
+
# upstream's own dispatch
|
| 153 |
+
# ---------------------------------------------------------------------------
|
| 154 |
+
|
| 155 |
+
#: The largest decode PROVEN to fit the 96 GB MIG slice untiled, from live
|
| 156 |
+
#: runs: 704x480x49 decoded clean; 1216x704x121 completed its denoise and then
|
| 157 |
+
#: died inside ``vae.decode``'s conv3d on the CUDACachingAllocator (~26 GB per
|
| 158 |
+
#: full-resolution intermediate at 121 frames, on ~35 GB of resident weights).
|
| 159 |
+
#:
|
| 160 |
+
#: These values are handed to ``AutoencoderKLLTX2.enable_tiling`` so that
|
| 161 |
+
#: **upstream's own dispatch is the size gate**: its ``_decode`` compares the
|
| 162 |
+
#: actual latent tensor against ``tile_sample_min_* // compression_ratio``
|
| 163 |
+
#: with strict ``>`` (read at the pinned ``ac56fa2f``, byte-identical in the
|
| 164 |
+
#: local 0.37.1 copy), so
|
| 165 |
+
#:
|
| 166 |
+
#: * anything at or inside the proven envelope -- 704x480 spatial, 49 frames
|
| 167 |
+
#: temporal, which includes the sha256-banked 256x256x9 -- takes the SAME
|
| 168 |
+
#: untiled code path as before this change, structurally byte-identical;
|
| 169 |
+
#: * anything beyond it decodes in tiles of exactly the proven-fit shape,
|
| 170 |
+
#: temporal chunks re-dispatching through spatial tiling (upstream's
|
| 171 |
+
#: ``_temporal_tiled_decode`` composes both), so the peak decode tensor is
|
| 172 |
+
#: bounded by a shape the card has already survived.
|
| 173 |
+
#:
|
| 174 |
+
#: Keying on the tensor being decoded is also what makes stage 2 need no
|
| 175 |
+
#: branch of ours: its inputs are 2x the request, and 2x is what the dispatch
|
| 176 |
+
#: sees. (Stage 2's FINAL pixels come from the diffusion decoder, a separate
|
| 177 |
+
#: model this flag set does not govern -- see StageRunner.)
|
| 178 |
+
#:
|
| 179 |
+
#: Always-on with upstream's DEFAULTS was measured against the source and
|
| 180 |
+
#: rejected: the default 512px tile minimum would have re-routed the
|
| 181 |
+
#: proven-fitting 704x480 decode through the tiled blend path, perturbing a
|
| 182 |
+
#: working size for no memory benefit. The envelope values keep the change
|
| 183 |
+
#: invisible everywhere the platform has already been proven.
|
| 184 |
+
VAE_TILE_MIN_HEIGHT = 480
|
| 185 |
+
VAE_TILE_MIN_WIDTH = 704
|
| 186 |
+
#: 56 pixel frames -> a latent threshold of 56 // 8 = 7, and a 49-frame video
|
| 187 |
+
#: occupies (49 - 1) // 8 + 1 = 7 latent frames -- so ``7 > 7`` is False and
|
| 188 |
+
#: the proven 49-frame decode is EXACTLY the last untouched point. This is the
|
| 189 |
+
#: off-by-one that matters: 57 frames occupy 8 latent frames and chunk.
|
| 190 |
+
VAE_TILE_MIN_NUM_FRAMES = 56
|
| 191 |
+
#: Strides preserve upstream's own default overlaps -- 64 px spatial blend
|
| 192 |
+
#: (512 - 448) and 8-frame temporal blend (16 - 8) -- so the seam-blending
|
| 193 |
+
#: behaviour for oversized decodes is exactly the one upstream ships, at our
|
| 194 |
+
#: tile size.
|
| 195 |
+
VAE_TILE_STRIDE_HEIGHT = 416
|
| 196 |
+
VAE_TILE_STRIDE_WIDTH = 640
|
| 197 |
+
VAE_TILE_STRIDE_NUM_FRAMES = 48
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
def configure_vae_tiling(vae) -> None:
|
| 201 |
+
"""Enable tiled + framewise decoding with the proven-fit envelope.
|
| 202 |
+
|
| 203 |
+
Set once on the ONE shared VAE at load: every derived pipeline and the
|
| 204 |
+
stage-2 upsampler hold this same object, so the envelope governs each
|
| 205 |
+
place a video tensor meets ``vae.decode`` or ``vae.encode`` -- the
|
| 206 |
+
in-pipeline decode that died at 1216x704x121, and the conditioning
|
| 207 |
+
encodes, whose flagship-size inputs carry the same arithmetic.
|
| 208 |
+
|
| 209 |
+
Both framewise flags are set although upstream's dispatch currently reads
|
| 210 |
+
only ``use_framewise_decoding`` (its ``_encode`` checks the *decoding*
|
| 211 |
+
flag -- an upstream quirk, identical at the pinned SHA): setting the
|
| 212 |
+
encoding flag too costs nothing today and keeps this correct the day the
|
| 213 |
+
quirk is fixed.
|
| 214 |
+
|
| 215 |
+
The divisibility tripwire is not pedantry: the dispatch converts these
|
| 216 |
+
pixel values to latent units by floor division, so a threshold that does
|
| 217 |
+
not divide exactly SHIFTS the envelope silently -- the proven boundary
|
| 218 |
+
would drift without any test noticing. Raise instead, naming the drift.
|
| 219 |
+
"""
|
| 220 |
+
spatial = int(getattr(vae, "spatial_compression_ratio", DEFAULT_SPATIAL_COMPRESSION_RATIO))
|
| 221 |
+
temporal = int(getattr(vae, "temporal_compression_ratio", DEFAULT_TEMPORAL_COMPRESSION_RATIO))
|
| 222 |
+
exact = {
|
| 223 |
+
"VAE_TILE_MIN_HEIGHT": (VAE_TILE_MIN_HEIGHT, spatial),
|
| 224 |
+
"VAE_TILE_MIN_WIDTH": (VAE_TILE_MIN_WIDTH, spatial),
|
| 225 |
+
"VAE_TILE_STRIDE_HEIGHT": (VAE_TILE_STRIDE_HEIGHT, spatial),
|
| 226 |
+
"VAE_TILE_STRIDE_WIDTH": (VAE_TILE_STRIDE_WIDTH, spatial),
|
| 227 |
+
"VAE_TILE_MIN_NUM_FRAMES": (VAE_TILE_MIN_NUM_FRAMES, temporal),
|
| 228 |
+
"VAE_TILE_STRIDE_NUM_FRAMES": (VAE_TILE_STRIDE_NUM_FRAMES, temporal),
|
| 229 |
+
}
|
| 230 |
+
off_grid = {name: value for name, (value, ratio) in exact.items() if value % ratio}
|
| 231 |
+
if off_grid:
|
| 232 |
+
raise ModelLoadError(
|
| 233 |
+
component="vae",
|
| 234 |
+
reason=(
|
| 235 |
+
f"VAE tile thresholds must divide the compression ratios exactly "
|
| 236 |
+
f"(spatial {spatial}, temporal {temporal}) or the floor division in "
|
| 237 |
+
f"upstream's dispatch silently shifts the proven-fit envelope: {off_grid}. "
|
| 238 |
+
f"Fix the constants in pipelines.py before continuing."
|
| 239 |
+
),
|
| 240 |
+
)
|
| 241 |
+
vae.enable_tiling(
|
| 242 |
+
tile_sample_min_height=VAE_TILE_MIN_HEIGHT,
|
| 243 |
+
tile_sample_min_width=VAE_TILE_MIN_WIDTH,
|
| 244 |
+
tile_sample_min_num_frames=VAE_TILE_MIN_NUM_FRAMES,
|
| 245 |
+
tile_sample_stride_height=VAE_TILE_STRIDE_HEIGHT,
|
| 246 |
+
tile_sample_stride_width=VAE_TILE_STRIDE_WIDTH,
|
| 247 |
+
tile_sample_stride_num_frames=VAE_TILE_STRIDE_NUM_FRAMES,
|
| 248 |
+
)
|
| 249 |
+
vae.use_framewise_decoding = True
|
| 250 |
+
vae.use_framewise_encoding = True
|
| 251 |
+
|
| 252 |
+
|
| 253 |
def assert_frame_rate_default(pipeline_object) -> None:
|
| 254 |
"""Tripwire on upstream's own ``frame_rate`` default.
|
| 255 |
|
|
|
|
| 658 |
vae = getattr(built, "vae", None)
|
| 659 |
if vae is not None:
|
| 660 |
assert_compression_ratios(vae)
|
| 661 |
+
configure_vae_tiling(vae)
|
| 662 |
assert_frame_rate_default(built)
|
| 663 |
|
| 664 |
_CACHE[_BASE_CACHE_KEY] = built
|
|
@@ -0,0 +1,200 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Spec for the VAE decode-tiling envelope — pipelines.configure_vae_tiling.
|
| 2 |
+
|
| 3 |
+
The live failure this exists for: 1216x704x121 completed its ~52 s denoise and
|
| 4 |
+
then died inside ``vae.decode``'s conv3d on the MIG allocator — full-resolution
|
| 5 |
+
decode intermediates are ~26 GB per tensor at 121 frames, on ~35 GB of
|
| 6 |
+
resident weights. 704x480x49 fits; 1216x704x121 does not.
|
| 7 |
+
|
| 8 |
+
The design under test: hand ``AutoencoderKLLTX2.enable_tiling`` thresholds
|
| 9 |
+
equal to the largest PROVEN-fit decode, so that upstream's own dispatch is the
|
| 10 |
+
size gate. Its ``_decode`` compares the actual latent tensor against
|
| 11 |
+
``tile_sample_min_* // compression_ratio`` with strict ``>`` (read at the
|
| 12 |
+
pinned ``ac56fa2f``; byte-identical in the local 0.37.1 copy), which gives the
|
| 13 |
+
two properties these tests pin:
|
| 14 |
+
|
| 15 |
+
* everything at or inside the proven envelope — the sha256-banked 256x256x9
|
| 16 |
+
above all — takes the SAME untiled code path as before the change;
|
| 17 |
+
* everything beyond it decodes in tiles of exactly the proven-fit shape, the
|
| 18 |
+
temporal chunks re-dispatching through spatial tiling.
|
| 19 |
+
|
| 20 |
+
What the offline gate can and cannot say, plainly: these tests verify the
|
| 21 |
+
plumbing, the threshold arithmetic, and that the dispatch predicate — as
|
| 22 |
+
replicated verbatim from the pinned source — routes the banked configs down
|
| 23 |
+
the untouched path. Byte-identity itself is a CUDA fact and is confirmed by
|
| 24 |
+
the sha256 re-check on the Space re-run, not here.
|
| 25 |
+
"""
|
| 26 |
+
|
| 27 |
+
from __future__ import annotations
|
| 28 |
+
|
| 29 |
+
import inspect as _inspect
|
| 30 |
+
|
| 31 |
+
import pytest
|
| 32 |
+
|
| 33 |
+
from ltx25_studio import pipelines
|
| 34 |
+
from ltx25_studio.constraints import (
|
| 35 |
+
DEFAULT_SPATIAL_COMPRESSION_RATIO,
|
| 36 |
+
DEFAULT_TEMPORAL_COMPRESSION_RATIO,
|
| 37 |
+
)
|
| 38 |
+
from ltx25_studio.errors import ModelLoadError
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
class FakeTilingVae:
|
| 42 |
+
spatial_compression_ratio = DEFAULT_SPATIAL_COMPRESSION_RATIO
|
| 43 |
+
temporal_compression_ratio = DEFAULT_TEMPORAL_COMPRESSION_RATIO
|
| 44 |
+
|
| 45 |
+
def __init__(self):
|
| 46 |
+
self.tiling_kwargs = None
|
| 47 |
+
self.use_framewise_decoding = False
|
| 48 |
+
self.use_framewise_encoding = False
|
| 49 |
+
|
| 50 |
+
def enable_tiling(self, **kwargs):
|
| 51 |
+
self.tiling_kwargs = kwargs
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def _configured():
|
| 55 |
+
vae = FakeTilingVae()
|
| 56 |
+
pipelines.configure_vae_tiling(vae)
|
| 57 |
+
return vae
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
# --------------------------------------------------------------------------
|
| 61 |
+
# the plumbing: what is set, exactly
|
| 62 |
+
# --------------------------------------------------------------------------
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def test_the_envelope_is_handed_to_enable_tiling_verbatim():
|
| 66 |
+
vae = _configured()
|
| 67 |
+
assert vae.tiling_kwargs == {
|
| 68 |
+
"tile_sample_min_height": pipelines.VAE_TILE_MIN_HEIGHT,
|
| 69 |
+
"tile_sample_min_width": pipelines.VAE_TILE_MIN_WIDTH,
|
| 70 |
+
"tile_sample_min_num_frames": pipelines.VAE_TILE_MIN_NUM_FRAMES,
|
| 71 |
+
"tile_sample_stride_height": pipelines.VAE_TILE_STRIDE_HEIGHT,
|
| 72 |
+
"tile_sample_stride_width": pipelines.VAE_TILE_STRIDE_WIDTH,
|
| 73 |
+
"tile_sample_stride_num_frames": pipelines.VAE_TILE_STRIDE_NUM_FRAMES,
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def test_both_framewise_flags_are_set():
|
| 78 |
+
"""enable_tiling alone never chunks time — use_framewise_decoding is a
|
| 79 |
+
separate flag it does not touch (read at the pinned SHA). The encoding
|
| 80 |
+
flag rides along because upstream's _encode currently checks the DECODING
|
| 81 |
+
flag (a quirk, identical at the pin): setting both is correct today and
|
| 82 |
+
stays correct the day the quirk is fixed."""
|
| 83 |
+
vae = _configured()
|
| 84 |
+
assert vae.use_framewise_decoding is True
|
| 85 |
+
assert vae.use_framewise_encoding is True
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def test_off_grid_thresholds_are_refused_naming_the_drift():
|
| 89 |
+
"""The dispatch floor-divides these by the compression ratios; a value
|
| 90 |
+
that does not divide exactly SHIFTS the proven envelope silently. A VAE
|
| 91 |
+
whose ratios changed upstream must therefore refuse to load rather than
|
| 92 |
+
tile at a boundary nobody measured."""
|
| 93 |
+
|
| 94 |
+
class WeirdVae(FakeTilingVae):
|
| 95 |
+
spatial_compression_ratio = 33
|
| 96 |
+
|
| 97 |
+
with pytest.raises(ModelLoadError) as excinfo:
|
| 98 |
+
pipelines.configure_vae_tiling(WeirdVae())
|
| 99 |
+
assert "envelope" in str(excinfo.value)
|
| 100 |
+
assert "VAE_TILE" in str(excinfo.value)
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def test_base_pipeline_wires_the_configuration_in():
|
| 104 |
+
source = _inspect.getsource(pipelines._base_pipeline)
|
| 105 |
+
assert "configure_vae_tiling(" in source, (
|
| 106 |
+
"the tiling envelope must be applied to the ONE shared VAE at load — "
|
| 107 |
+
"an unwired configure function is the §8 inert-guard shape"
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
# --------------------------------------------------------------------------
|
| 112 |
+
# the envelope arithmetic — upstream's dispatch, replicated verbatim
|
| 113 |
+
# --------------------------------------------------------------------------
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def _dispatch(width, height, num_frames):
|
| 117 |
+
"""The pinned ``AutoencoderKLLTX2._decode`` routing, verbatim in latent
|
| 118 |
+
units: framewise when latent frames exceed min_frames // temporal_ratio,
|
| 119 |
+
tiled when either latent axis exceeds min // spatial_ratio, else plain."""
|
| 120 |
+
spatial = DEFAULT_SPATIAL_COMPRESSION_RATIO
|
| 121 |
+
temporal = DEFAULT_TEMPORAL_COMPRESSION_RATIO
|
| 122 |
+
latent_w, latent_h = width // spatial, height // spatial
|
| 123 |
+
latent_f = (num_frames - 1) // temporal + 1
|
| 124 |
+
|
| 125 |
+
framewise = latent_f > pipelines.VAE_TILE_MIN_NUM_FRAMES // temporal
|
| 126 |
+
tiled = (
|
| 127 |
+
latent_w > pipelines.VAE_TILE_MIN_WIDTH // spatial
|
| 128 |
+
or latent_h > pipelines.VAE_TILE_MIN_HEIGHT // spatial
|
| 129 |
+
)
|
| 130 |
+
return framewise, tiled
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
def test_the_sha256_banked_config_takes_the_untouched_path():
|
| 134 |
+
"""256x256x9 was sha256-proven byte-identical across three containers
|
| 135 |
+
TODAY. Both comparisons are strict >, so this config decodes through the
|
| 136 |
+
same plain path as before this change — structurally, not by luck."""
|
| 137 |
+
assert _dispatch(256, 256, 9) == (False, False)
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
def test_the_largest_proven_fit_decode_is_exactly_the_last_untouched_point():
|
| 141 |
+
"""704x480x49 decoded clean on the slice; 49 frames occupy (49-1)//8+1 = 7
|
| 142 |
+
latent frames and the threshold is 56//8 = 7, so 7 > 7 is False — the
|
| 143 |
+
proven point is the boundary, and nothing that ever worked changes."""
|
| 144 |
+
assert _dispatch(704, 480, 49) == (False, False)
|
| 145 |
+
assert _dispatch(704, 480, 1) == (False, False)
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def test_one_step_past_the_proven_envelope_engages_the_right_mechanism():
|
| 149 |
+
assert _dispatch(704, 480, 57) == (True, False), "57 frames -> 8 latent -> framewise"
|
| 150 |
+
assert _dispatch(736, 480, 49) == (False, True), "one tile-width past -> spatial"
|
| 151 |
+
assert _dispatch(704, 512, 49) == (False, True), "one tile-height past -> spatial"
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
def test_the_live_failure_config_engages_both_mechanisms():
|
| 155 |
+
"""1216x704x121 — the run that died. Temporal chunks re-dispatch through
|
| 156 |
+
spatial tiling upstream, so the peak decode tensor is bounded by a
|
| 157 |
+
proven-fit shape."""
|
| 158 |
+
assert _dispatch(1216, 704, 121) == (True, True)
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
def test_the_stage_2_decoded_size_is_gated_by_what_is_decoded_not_requested():
|
| 162 |
+
"""Stage 2 hands the VAE 2x the request (1408x960 from 704x480). The gate
|
| 163 |
+
lives inside the dispatch and keys on the tensor itself, so the doubled
|
| 164 |
+
size is what gets compared — no branch of ours reads the request."""
|
| 165 |
+
assert _dispatch(1408, 960, 49) == (False, True)
|
| 166 |
+
assert _dispatch(1408, 960, 121) == (True, True)
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
# --------------------------------------------------------------------------
|
| 170 |
+
# the envelope constants themselves
|
| 171 |
+
# --------------------------------------------------------------------------
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
def test_the_thresholds_sit_exactly_on_the_latent_grid():
|
| 175 |
+
spatial = DEFAULT_SPATIAL_COMPRESSION_RATIO
|
| 176 |
+
temporal = DEFAULT_TEMPORAL_COMPRESSION_RATIO
|
| 177 |
+
assert pipelines.VAE_TILE_MIN_HEIGHT % spatial == 0
|
| 178 |
+
assert pipelines.VAE_TILE_MIN_WIDTH % spatial == 0
|
| 179 |
+
assert pipelines.VAE_TILE_STRIDE_HEIGHT % spatial == 0
|
| 180 |
+
assert pipelines.VAE_TILE_STRIDE_WIDTH % spatial == 0
|
| 181 |
+
assert pipelines.VAE_TILE_MIN_NUM_FRAMES % temporal == 0
|
| 182 |
+
assert pipelines.VAE_TILE_STRIDE_NUM_FRAMES % temporal == 0
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
def test_the_strides_preserve_upstreams_own_blend_widths():
|
| 186 |
+
"""The overlap (min - stride) is the blend region. Upstream ships 64 px
|
| 187 |
+
spatial (512-448) and 8 frames temporal (16-8); keeping those means the
|
| 188 |
+
seam behaviour for oversized decodes is exactly the shipped one, only at
|
| 189 |
+
our tile size."""
|
| 190 |
+
assert pipelines.VAE_TILE_MIN_WIDTH - pipelines.VAE_TILE_STRIDE_WIDTH == 64
|
| 191 |
+
assert pipelines.VAE_TILE_MIN_HEIGHT - pipelines.VAE_TILE_STRIDE_HEIGHT == 64
|
| 192 |
+
assert pipelines.VAE_TILE_MIN_NUM_FRAMES - pipelines.VAE_TILE_STRIDE_NUM_FRAMES == 8
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
def test_strides_stay_strictly_inside_the_tile():
|
| 196 |
+
"""A stride >= its tile min means zero (or negative) overlap and a
|
| 197 |
+
degenerate blend; upstream does not guard this, so we do."""
|
| 198 |
+
assert 0 < pipelines.VAE_TILE_STRIDE_WIDTH < pipelines.VAE_TILE_MIN_WIDTH
|
| 199 |
+
assert 0 < pipelines.VAE_TILE_STRIDE_HEIGHT < pipelines.VAE_TILE_MIN_HEIGHT
|
| 200 |
+
assert 0 < pipelines.VAE_TILE_STRIDE_NUM_FRAMES < pipelines.VAE_TILE_MIN_NUM_FRAMES
|