Update api/ltx_server_refactored.py
Browse files- api/ltx_server_refactored.py +1 -51
api/ltx_server_refactored.py
CHANGED
|
@@ -318,7 +318,7 @@ class VideoService:
|
|
| 318 |
if i == 0:
|
| 319 |
self.pipeline.transformer.to(device)
|
| 320 |
self.pipeline.text_encoder.to(device)
|
| 321 |
-
self.pipeline.patchifier.to(device)
|
| 322 |
# Nota: Para multi-worker transformer, precisaríamos de cópias do modelo
|
| 323 |
|
| 324 |
# Workers 2 e 3: VAE
|
|
@@ -481,56 +481,6 @@ class VideoService:
|
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
-
class VideoService:
|
| 485 |
-
def __init__(self):
|
| 486 |
-
"""Inicializa o serviço com 4 workers especializados."""
|
| 487 |
-
t0 = time.perf_counter()
|
| 488 |
-
print("[INFO] Inicializando VideoService com 4 Workers...")
|
| 489 |
-
|
| 490 |
-
# Configuração para 4 GPUs
|
| 491 |
-
self.multi_gpu_enabled = GPU_CONFIG["enable_multi_gpu"] and torch.cuda.device_count() >= 4
|
| 492 |
-
|
| 493 |
-
if self.multi_gpu_enabled:
|
| 494 |
-
self.transformer_devices = [f"cuda:{gpu}" for gpu in GPU_CONFIG["transformer_workers"]]
|
| 495 |
-
self.vae_devices = [f"cuda:{gpu}" for gpu in GPU_CONFIG["vae_workers"]]
|
| 496 |
-
self.current_transformer_idx = 0
|
| 497 |
-
self.current_vae_idx = 0
|
| 498 |
-
|
| 499 |
-
print(f"[INFO] Configuração 4-Workers:")
|
| 500 |
-
print(f" Transformer Workers: {self.transformer_devices}")
|
| 501 |
-
print(f" VAE Workers: {self.vae_devices}")
|
| 502 |
-
else:
|
| 503 |
-
self.device_ltx = self.device_vae = "cuda" if torch.cuda.is_available() else "cpu"
|
| 504 |
-
print("[INFO] Usando configuração single-GPU")
|
| 505 |
-
|
| 506 |
-
self.config = self._load_config("ltxv-13b-0.9.8-distilled-fp8.yaml")
|
| 507 |
-
self.pipeline, self.latent_upsampler = self._load_models_from_hub()
|
| 508 |
-
self._setup_4gpu_workers()
|
| 509 |
-
|
| 510 |
-
self.runtime_autocast_dtype = self._get_precision_dtype()
|
| 511 |
-
|
| 512 |
-
# Configurar VAE managers para todas as GPUs VAE
|
| 513 |
-
self.vae_managers = []
|
| 514 |
-
if self.multi_gpu_enabled:
|
| 515 |
-
for vae_device in self.vae_devices:
|
| 516 |
-
# Usar o mesmo VAE manager singleton mas configurar para dispositivos diferentes
|
| 517 |
-
manager = type(vae_manager_singleton)() # Nova instância
|
| 518 |
-
manager.attach_pipeline(
|
| 519 |
-
self.pipeline,
|
| 520 |
-
device=vae_device,
|
| 521 |
-
autocast_dtype=self.runtime_autocast_dtype
|
| 522 |
-
)
|
| 523 |
-
self.vae_managers.append(manager)
|
| 524 |
-
else:
|
| 525 |
-
vae_manager_singleton.attach_pipeline(
|
| 526 |
-
self.pipeline,
|
| 527 |
-
device=self.device_vae,
|
| 528 |
-
autocast_dtype=self.runtime_autocast_dtype
|
| 529 |
-
)
|
| 530 |
-
|
| 531 |
-
self._tmp_dirs = set()
|
| 532 |
-
RESULTS_DIR.mkdir(exist_ok=True)
|
| 533 |
-
print(f"[INFO] VideoService 4-Workers pronto. Tempo: {time.perf_counter()-t0:.2f}s")
|
| 534 |
|
| 535 |
def _set_generation_environment(self):
|
| 536 |
"""Prepara o ambiente para geração (LTX pipeline)."""
|
|
|
|
| 318 |
if i == 0:
|
| 319 |
self.pipeline.transformer.to(device)
|
| 320 |
self.pipeline.text_encoder.to(device)
|
| 321 |
+
#self.pipeline.patchifier.to(device)
|
| 322 |
# Nota: Para multi-worker transformer, precisaríamos de cópias do modelo
|
| 323 |
|
| 324 |
# Workers 2 e 3: VAE
|
|
|
|
| 481 |
|
| 482 |
|
| 483 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 484 |
|
| 485 |
def _set_generation_environment(self):
|
| 486 |
"""Prepara o ambiente para geração (LTX pipeline)."""
|