Spaces:
Paused
Paused
Update api/ltx/ltx_utils.py
Browse files- api/ltx/ltx_utils.py +12 -7
api/ltx/ltx_utils.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
# FILE: api/ltx/ltx_utils.py
|
| 2 |
# DESCRIPTION: A pure utility library for the LTX ecosystem.
|
| 3 |
-
# Contains the official low-level builder function for
|
|
|
|
| 4 |
|
| 5 |
import os
|
| 6 |
import random
|
|
@@ -29,12 +30,15 @@ def add_deps_to_path():
|
|
| 29 |
|
| 30 |
add_deps_to_path()
|
| 31 |
|
| 32 |
-
|
| 33 |
from ltx_video.pipelines.pipeline_ltx_video import LTXVideoPipeline
|
| 34 |
from ltx_video.models.autoencoders.causal_video_autoencoder import CausalVideoAutoencoder
|
| 35 |
from ltx_video.models.transformers.transformer3d import Transformer3DModel
|
| 36 |
from ltx_video.models.transformers.symmetric_patchifier import SymmetricPatchifier
|
| 37 |
from ltx_video.schedulers.rf import RectifiedFlowScheduler
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
# ==============================================================================
|
| 40 |
# --- FUNÇÃO HELPER 'create_transformer' (Essencial) ---
|
|
@@ -62,12 +66,12 @@ def create_transformer(ckpt_path: str, precision: str) -> Transformer3DModel:
|
|
| 62 |
# --- BUILDER DE BAIXO NÍVEL OFICIAL ---
|
| 63 |
# ==============================================================================
|
| 64 |
|
| 65 |
-
def
|
| 66 |
"""
|
| 67 |
-
Constrói o pipeline LTX
|
| 68 |
Esta é a função de construção fundamental usada pelo LTXAducManager.
|
| 69 |
"""
|
| 70 |
-
logging.info(f"Building LTX
|
| 71 |
|
| 72 |
with safe_open(checkpoint_path, framework="pt") as f:
|
| 73 |
metadata = f.metadata() or {}
|
|
@@ -88,6 +92,7 @@ def build_components_on_cpu(checkpoint_path: str, config: Dict) -> Tuple[LTXVide
|
|
| 88 |
if precision == "bfloat16":
|
| 89 |
text_encoder.to(torch.bfloat16)
|
| 90 |
vae.to(torch.bfloat16)
|
|
|
|
| 91 |
|
| 92 |
pipeline = LTXVideoPipeline(
|
| 93 |
transformer=transformer,
|
|
@@ -95,7 +100,7 @@ def build_components_on_cpu(checkpoint_path: str, config: Dict) -> Tuple[LTXVide
|
|
| 95 |
text_encoder=text_encoder,
|
| 96 |
tokenizer=tokenizer,
|
| 97 |
scheduler=scheduler,
|
| 98 |
-
vae=vae, # VAE é
|
| 99 |
allowed_inference_steps=allowed_inference_steps,
|
| 100 |
prompt_enhancer_image_caption_model=None,
|
| 101 |
prompt_enhancer_image_caption_processor=None,
|
|
@@ -103,7 +108,7 @@ def build_components_on_cpu(checkpoint_path: str, config: Dict) -> Tuple[LTXVide
|
|
| 103 |
prompt_enhancer_llm_tokenizer=None,
|
| 104 |
)
|
| 105 |
|
| 106 |
-
return pipeline
|
| 107 |
|
| 108 |
# ==============================================================================
|
| 109 |
# --- FUNÇÕES AUXILIARES GENÉRICAS ---
|
|
|
|
| 1 |
# FILE: api/ltx/ltx_utils.py
|
| 2 |
# DESCRIPTION: A pure utility library for the LTX ecosystem.
|
| 3 |
+
# Contains the official low-level builder function for the complete pipeline
|
| 4 |
+
# and other stateless helper functions.
|
| 5 |
|
| 6 |
import os
|
| 7 |
import random
|
|
|
|
| 30 |
|
| 31 |
add_deps_to_path()
|
| 32 |
|
| 33 |
+
try:
|
| 34 |
from ltx_video.pipelines.pipeline_ltx_video import LTXVideoPipeline
|
| 35 |
from ltx_video.models.autoencoders.causal_video_autoencoder import CausalVideoAutoencoder
|
| 36 |
from ltx_video.models.transformers.transformer3d import Transformer3DModel
|
| 37 |
from ltx_video.models.transformers.symmetric_patchifier import SymmetricPatchifier
|
| 38 |
from ltx_video.schedulers.rf import RectifiedFlowScheduler
|
| 39 |
+
except ImportError as e:
|
| 40 |
+
logging.critical("Failed to import a core LTX-Video library component.", exc_info=True)
|
| 41 |
+
raise ImportError(f"Could not import from LTX-Video library. Check repo integrity at '{LTX_VIDEO_REPO_DIR}'. Error: {e}")
|
| 42 |
|
| 43 |
# ==============================================================================
|
| 44 |
# --- FUNÇÃO HELPER 'create_transformer' (Essencial) ---
|
|
|
|
| 66 |
# --- BUILDER DE BAIXO NÍVEL OFICIAL ---
|
| 67 |
# ==============================================================================
|
| 68 |
|
| 69 |
+
def build_complete_pipeline_on_cpu(checkpoint_path: str, config: Dict) -> LTXVideoPipeline:
|
| 70 |
"""
|
| 71 |
+
Constrói o pipeline LTX COMPLETO, incluindo o VAE, e o mantém na CPU.
|
| 72 |
Esta é a função de construção fundamental usada pelo LTXAducManager.
|
| 73 |
"""
|
| 74 |
+
logging.info(f"Building complete LTX pipeline from checkpoint: {Path(checkpoint_path).name}")
|
| 75 |
|
| 76 |
with safe_open(checkpoint_path, framework="pt") as f:
|
| 77 |
metadata = f.metadata() or {}
|
|
|
|
| 92 |
if precision == "bfloat16":
|
| 93 |
text_encoder.to(torch.bfloat16)
|
| 94 |
vae.to(torch.bfloat16)
|
| 95 |
+
# O transformer já foi convertido para bfloat16 dentro de create_transformer, se aplicável
|
| 96 |
|
| 97 |
pipeline = LTXVideoPipeline(
|
| 98 |
transformer=transformer,
|
|
|
|
| 100 |
text_encoder=text_encoder,
|
| 101 |
tokenizer=tokenizer,
|
| 102 |
scheduler=scheduler,
|
| 103 |
+
vae=vae, # VAE é incluído para que o pipeline possa ser auto-suficiente
|
| 104 |
allowed_inference_steps=allowed_inference_steps,
|
| 105 |
prompt_enhancer_image_caption_model=None,
|
| 106 |
prompt_enhancer_image_caption_processor=None,
|
|
|
|
| 108 |
prompt_enhancer_llm_tokenizer=None,
|
| 109 |
)
|
| 110 |
|
| 111 |
+
return pipeline
|
| 112 |
|
| 113 |
# ==============================================================================
|
| 114 |
# --- FUNÇÕES AUXILIARES GENÉRICAS ---
|