Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -300,15 +300,44 @@ print(f"Checkpoint: {checkpoint_path}")
|
|
| 300 |
print(f"Spatial upsampler: {spatial_upsampler_path}")
|
| 301 |
print(f"[Gemma] Root ready: {gemma_root}")
|
| 302 |
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
# ----------------------------------------------------------------
|
| 313 |
|
| 314 |
def _make_lora_key(singularity_strength: float, teneros_strength: float, pose_strength: float, general_strength: float, motion_strength: float, dreamlay_strength: float, mself_strength: float, dramatic_strength: float, fluid_strength: float, liquid_strength: float, demopose_strength: float, voice_strength: float, realism_strength: float, transition_strength: float, physics_strength: float, reasoning_strength: float, twostep_strength: float, mcfurry_strength: float, dm_strength: float, praxis_strength: float, threed_strength: float, concept_strength: float, bulge_strength: float) -> tuple[str, str]:
|
|
@@ -375,7 +404,8 @@ def prepare_lora_cache(
|
|
| 375 |
"""
|
| 376 |
global PENDING_LORA_KEY, PENDING_LORA_STATE, PENDING_LORA_STATUS
|
| 377 |
|
| 378 |
-
|
|
|
|
| 379 |
key, _ = _make_lora_key(singularity_strength, teneros_strength, pose_strength, general_strength, motion_strength, dreamlay_strength, mself_strength, dramatic_strength, fluid_strength, liquid_strength, demopose_strength, voice_strength, realism_strength, transition_strength, physics_strength, reasoning_strength, twostep_strength, mcfurry_strength, dm_strength, praxis_strength, threed_strength, concept_strength, bulge_strength)
|
| 380 |
cache_path = LORA_CACHE_DIR / f"{key}.safetensors"
|
| 381 |
|
|
@@ -501,49 +531,6 @@ def apply_prepared_lora_state_to_pipeline():
|
|
| 501 |
print("[LoRA] Prepared LoRA state applied to the pipeline.")
|
| 502 |
return True
|
| 503 |
|
| 504 |
-
# ---- REPLACE PRELOAD BLOCK START ----
|
| 505 |
-
# Preload all models for ZeroGPU tensor packing.
|
| 506 |
-
print("Preloading all models (including Gemma and audio components)...")
|
| 507 |
-
ledger = pipeline.model_ledger
|
| 508 |
-
|
| 509 |
-
# Save the original factory methods so we can rebuild individual components later.
|
| 510 |
-
# These are bound callables on ledger that will call the builder when invoked.
|
| 511 |
-
_orig_transformer_factory = ledger.transformer
|
| 512 |
-
_orig_video_encoder_factory = ledger.video_encoder
|
| 513 |
-
_orig_video_decoder_factory = ledger.video_decoder
|
| 514 |
-
_orig_audio_encoder_factory = ledger.audio_encoder
|
| 515 |
-
_orig_audio_decoder_factory = ledger.audio_decoder
|
| 516 |
-
_orig_vocoder_factory = ledger.vocoder
|
| 517 |
-
_orig_spatial_upsampler_factory = ledger.spatial_upsampler
|
| 518 |
-
_orig_text_encoder_factory = ledger.text_encoder
|
| 519 |
-
_orig_gemma_embeddings_factory = ledger.gemma_embeddings_processor
|
| 520 |
-
|
| 521 |
-
# Call the original factories once to create the cached instances we will serve by default.
|
| 522 |
-
_transformer = _orig_transformer_factory()
|
| 523 |
-
_video_encoder = _orig_video_encoder_factory()
|
| 524 |
-
_video_decoder = _orig_video_decoder_factory()
|
| 525 |
-
_audio_encoder = _orig_audio_encoder_factory()
|
| 526 |
-
_audio_decoder = _orig_audio_decoder_factory()
|
| 527 |
-
_vocoder = _orig_vocoder_factory()
|
| 528 |
-
_spatial_upsampler = _orig_spatial_upsampler_factory()
|
| 529 |
-
_text_encoder = _orig_text_encoder_factory()
|
| 530 |
-
_embeddings_processor = _orig_gemma_embeddings_factory()
|
| 531 |
-
|
| 532 |
-
# Replace ledger methods with lightweight lambdas that return the cached instances.
|
| 533 |
-
# We keep the original factories above so we can call them later to rebuild components.
|
| 534 |
-
ledger.transformer = lambda: _transformer
|
| 535 |
-
ledger.video_encoder = lambda: _video_encoder
|
| 536 |
-
ledger.video_decoder = lambda: _video_decoder
|
| 537 |
-
ledger.audio_encoder = lambda: _audio_encoder
|
| 538 |
-
ledger.audio_decoder = lambda: _audio_decoder
|
| 539 |
-
ledger.vocoder = lambda: _vocoder
|
| 540 |
-
ledger.spatial_upsampler = lambda: _spatial_upsampler
|
| 541 |
-
ledger.text_encoder = lambda: _text_encoder
|
| 542 |
-
ledger.gemma_embeddings_processor = lambda: _embeddings_processor
|
| 543 |
-
|
| 544 |
-
print("All models preloaded (including Gemma text encoder and audio encoder)!")
|
| 545 |
-
# ---- REPLACE PRELOAD BLOCK END ----
|
| 546 |
-
|
| 547 |
print("=" * 80)
|
| 548 |
print("Pipeline ready!")
|
| 549 |
print("=" * 80)
|
|
@@ -700,10 +687,14 @@ def generate_video(
|
|
| 700 |
|
| 701 |
log_memory("before pipeline call")
|
| 702 |
|
| 703 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 704 |
|
| 705 |
-
video, audio = pipeline(
|
| 706 |
-
prompt=prompt,
|
| 707 |
seed=current_seed,
|
| 708 |
height=int(height),
|
| 709 |
width=int(width),
|
|
|
|
| 300 |
print(f"Spatial upsampler: {spatial_upsampler_path}")
|
| 301 |
print(f"[Gemma] Root ready: {gemma_root}")
|
| 302 |
|
| 303 |
+
pipeline = None
|
| 304 |
+
_transformer = None
|
| 305 |
+
|
| 306 |
+
def get_pipeline():
|
| 307 |
+
global pipeline, _transformer
|
| 308 |
+
if pipeline is None:
|
| 309 |
+
print("Loading LTX-2.3 Pipeline safely inside ZeroGPU...")
|
| 310 |
+
pipeline = LTX23DistilledA2VPipeline(
|
| 311 |
+
distilled_checkpoint_path=checkpoint_path,
|
| 312 |
+
spatial_upsampler_path=spatial_upsampler_path,
|
| 313 |
+
gemma_root=gemma_root,
|
| 314 |
+
loras=[],
|
| 315 |
+
quantization=None,
|
| 316 |
+
)
|
| 317 |
+
|
| 318 |
+
ledger = pipeline.model_ledger
|
| 319 |
+
_transformer = ledger.transformer()
|
| 320 |
+
_video_encoder = ledger.video_encoder()
|
| 321 |
+
_video_decoder = ledger.video_decoder()
|
| 322 |
+
_audio_encoder = ledger.audio_encoder()
|
| 323 |
+
_audio_decoder = ledger.audio_decoder()
|
| 324 |
+
_vocoder = ledger.vocoder()
|
| 325 |
+
_spatial_upsampler = ledger.spatial_upsampler()
|
| 326 |
+
_text_encoder = ledger.text_encoder()
|
| 327 |
+
_embeddings_processor = ledger.gemma_embeddings_processor()
|
| 328 |
+
|
| 329 |
+
ledger.transformer = lambda: _transformer
|
| 330 |
+
ledger.video_encoder = lambda: _video_encoder
|
| 331 |
+
ledger.video_decoder = lambda: _video_decoder
|
| 332 |
+
ledger.audio_encoder = lambda: _audio_encoder
|
| 333 |
+
ledger.audio_decoder = lambda: _audio_decoder
|
| 334 |
+
ledger.vocoder = lambda: _vocoder
|
| 335 |
+
ledger.spatial_upsampler = lambda: _spatial_upsampler
|
| 336 |
+
ledger.text_encoder = lambda: _text_encoder
|
| 337 |
+
ledger.gemma_embeddings_processor = lambda: _embeddings_processor
|
| 338 |
+
return pipeline
|
| 339 |
+
|
| 340 |
+
|
| 341 |
# ----------------------------------------------------------------
|
| 342 |
|
| 343 |
def _make_lora_key(singularity_strength: float, teneros_strength: float, pose_strength: float, general_strength: float, motion_strength: float, dreamlay_strength: float, mself_strength: float, dramatic_strength: float, fluid_strength: float, liquid_strength: float, demopose_strength: float, voice_strength: float, realism_strength: float, transition_strength: float, physics_strength: float, reasoning_strength: float, twostep_strength: float, mcfurry_strength: float, dm_strength: float, praxis_strength: float, threed_strength: float, concept_strength: float, bulge_strength: float) -> tuple[str, str]:
|
|
|
|
| 404 |
"""
|
| 405 |
global PENDING_LORA_KEY, PENDING_LORA_STATE, PENDING_LORA_STATUS
|
| 406 |
|
| 407 |
+
active_pipeline = get_pipeline()
|
| 408 |
+
ledger = active_pipeline.model_ledger
|
| 409 |
key, _ = _make_lora_key(singularity_strength, teneros_strength, pose_strength, general_strength, motion_strength, dreamlay_strength, mself_strength, dramatic_strength, fluid_strength, liquid_strength, demopose_strength, voice_strength, realism_strength, transition_strength, physics_strength, reasoning_strength, twostep_strength, mcfurry_strength, dm_strength, praxis_strength, threed_strength, concept_strength, bulge_strength)
|
| 410 |
cache_path = LORA_CACHE_DIR / f"{key}.safetensors"
|
| 411 |
|
|
|
|
| 531 |
print("[LoRA] Prepared LoRA state applied to the pipeline.")
|
| 532 |
return True
|
| 533 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 534 |
print("=" * 80)
|
| 535 |
print("Pipeline ready!")
|
| 536 |
print("=" * 80)
|
|
|
|
| 687 |
|
| 688 |
log_memory("before pipeline call")
|
| 689 |
|
| 690 |
+
# Safely get the pipeline inside ZeroGPU right before execution
|
| 691 |
+
active_pipeline = get_pipeline()
|
| 692 |
+
|
| 693 |
+
apply_prepared_lora_state_to_pipeline()
|
| 694 |
+
|
| 695 |
+
video, audio = active_pipeline(
|
| 696 |
+
prompt=prompt,
|
| 697 |
|
|
|
|
|
|
|
| 698 |
seed=current_seed,
|
| 699 |
height=int(height),
|
| 700 |
width=int(width),
|