Spaces:
Running on Zero
Running on Zero
Drop module-load pre-warming (Triton/fp8+LoRA needs real CUDA)
Browse filesThe pre-warm block hit torch.AcceleratorError: no CUDA-capable device on ZeroGPU because fp8_cast's LoRA fusion launches a Triton kernel (_fused_add_round_launch) at build time, and ZeroGPU only provides a real CUDA device inside @spaces.GPU-decorated functions.
The Lightricks/LTX-2-3 Space gets away with module-load pre-warm only because it uses loras=[] β no LoRA fusion path, no Triton. We always have the HDR LoRA fused in, so we can't pre-warm at module load.
Keeping only the scene-emb .pt revert from this PR. Each generate call will re-build transformer + VAE components inside the GPU slot; slower than cached, but correct.
app.py
CHANGED
|
@@ -67,8 +67,6 @@ import logging
|
|
| 67 |
import random
|
| 68 |
import tempfile
|
| 69 |
import zipfile
|
| 70 |
-
from collections.abc import Iterator
|
| 71 |
-
from contextlib import contextmanager
|
| 72 |
|
| 73 |
import torch
|
| 74 |
torch._dynamo.config.suppress_errors = True
|
|
@@ -79,7 +77,6 @@ import gradio as gr
|
|
| 79 |
import numpy as np
|
| 80 |
from huggingface_hub import hf_hub_download
|
| 81 |
|
| 82 |
-
from ltx_core.model.upsampler import upsample_video
|
| 83 |
from ltx_core.model.video_vae import TilingConfig
|
| 84 |
from ltx_core.quantization import QuantizationPolicy
|
| 85 |
from ltx_pipelines.hdr_ic_lora import HDRICLoraPipeline, _make_tiling_config
|
|
@@ -156,83 +153,6 @@ pipeline = HDRICLoraPipeline(
|
|
| 156 |
)
|
| 157 |
print(f"HDRICLoraPipeline ready. HDR transform: {pipeline.hdr_transform}, "
|
| 158 |
f"ref_downscale={pipeline.reference_downscale_factor}")
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 162 |
-
# Pre-warm for ZeroGPU: build each component once at module load (ZeroGPU
|
| 163 |
-
# tensor-packing captures the weights), then replace the pipeline's blocks
|
| 164 |
-
# with tiny wrappers that reuse the cached models and skip gpu_model's
|
| 165 |
-
# meta-device freeing. Avoids re-reading the 22B checkpoint + re-fusing
|
| 166 |
-
# the LoRA + re-fp8-casting on every @spaces.GPU invocation.
|
| 167 |
-
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 168 |
-
print("Pre-warming models (one-shot build)...")
|
| 169 |
-
|
| 170 |
-
_cached_image_encoder = pipeline.image_conditioner._build_encoder()
|
| 171 |
-
_cached_transformer = pipeline.stage_1._build_transformer()
|
| 172 |
-
_cached_upsampler_encoder = (
|
| 173 |
-
pipeline.upsampler._encoder_builder
|
| 174 |
-
.build(device=_DEVICE, dtype=_DTYPE).to(_DEVICE).eval()
|
| 175 |
-
)
|
| 176 |
-
_cached_upsampler = (
|
| 177 |
-
pipeline.upsampler._upsampler_builder
|
| 178 |
-
.build(device=_DEVICE, dtype=_DTYPE).to(_DEVICE).eval()
|
| 179 |
-
)
|
| 180 |
-
_cached_video_decoder = (
|
| 181 |
-
pipeline.video_decoder._decoder_builder
|
| 182 |
-
.build(device=_DEVICE, dtype=_DTYPE).to(_DEVICE).eval()
|
| 183 |
-
)
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
@contextmanager
|
| 187 |
-
def _yield_cached(model):
|
| 188 |
-
"""Drop-in for gpu_model that does NOT move params to meta on exit."""
|
| 189 |
-
yield model
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
# Patch the transformer context manager on both stages to yield the cached
|
| 193 |
-
# transformer without freeing. stage_1 uses _transformer_ctx inside __call__;
|
| 194 |
-
# stage_2 uses model_context() -> _transformer_ctx.
|
| 195 |
-
def _cached_stage_ctx(**_kwargs):
|
| 196 |
-
return _yield_cached(_cached_transformer)
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
pipeline.stage_1._transformer_ctx = _cached_stage_ctx
|
| 200 |
-
pipeline.stage_2._transformer_ctx = _cached_stage_ctx
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
class _CachedImageConditioner:
|
| 204 |
-
def __call__(self, fn):
|
| 205 |
-
return fn(_cached_image_encoder)
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
class _CachedVideoUpsampler:
|
| 209 |
-
def __call__(self, latent):
|
| 210 |
-
return upsample_video(
|
| 211 |
-
latent=latent,
|
| 212 |
-
video_encoder=_cached_upsampler_encoder,
|
| 213 |
-
upsampler=_cached_upsampler,
|
| 214 |
-
)
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
class _CachedVideoDecoder:
|
| 218 |
-
def __call__(
|
| 219 |
-
self,
|
| 220 |
-
latent: torch.Tensor,
|
| 221 |
-
tiling_config=None,
|
| 222 |
-
generator=None,
|
| 223 |
-
*,
|
| 224 |
-
output_dtype: torch.dtype = torch.uint8,
|
| 225 |
-
) -> Iterator[torch.Tensor]:
|
| 226 |
-
return _cached_video_decoder.decode_video(
|
| 227 |
-
latent, tiling_config, generator, output_dtype=output_dtype,
|
| 228 |
-
)
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
pipeline.image_conditioner = _CachedImageConditioner()
|
| 232 |
-
pipeline.upsampler = _CachedVideoUpsampler()
|
| 233 |
-
pipeline.video_decoder = _CachedVideoDecoder()
|
| 234 |
-
|
| 235 |
-
print("Pre-warm complete.")
|
| 236 |
print("=" * 80)
|
| 237 |
|
| 238 |
|
|
|
|
| 67 |
import random
|
| 68 |
import tempfile
|
| 69 |
import zipfile
|
|
|
|
|
|
|
| 70 |
|
| 71 |
import torch
|
| 72 |
torch._dynamo.config.suppress_errors = True
|
|
|
|
| 77 |
import numpy as np
|
| 78 |
from huggingface_hub import hf_hub_download
|
| 79 |
|
|
|
|
| 80 |
from ltx_core.model.video_vae import TilingConfig
|
| 81 |
from ltx_core.quantization import QuantizationPolicy
|
| 82 |
from ltx_pipelines.hdr_ic_lora import HDRICLoraPipeline, _make_tiling_config
|
|
|
|
| 153 |
)
|
| 154 |
print(f"HDRICLoraPipeline ready. HDR transform: {pipeline.hdr_transform}, "
|
| 155 |
f"ref_downscale={pipeline.reference_downscale_factor}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
print("=" * 80)
|
| 157 |
|
| 158 |
|