caarleexx commited on
Commit
232cc6e
·
verified ·
1 Parent(s): 5227335

Update api/ltx_server_refactored.py

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