Carlos s commited on
Commit
b5542bb
·
verified ·
1 Parent(s): a614adb

Update api/ltx_server.py

Browse files
Files changed (1) hide show
  1. api/ltx_server.py +17 -9
api/ltx_server.py CHANGED
@@ -587,7 +587,6 @@ class VideoService:
587
 
588
  print("[DEBUG] Multi-escala: Iniciando Passo 1 (geração de latentes base).")
589
 
590
- # 1. Configurar e executar o primeiro passo
591
  first_pass_args = self.config.get("first_pass", {}).copy()
592
  first_pass_kwargs = call_kwargs.copy()
593
  first_pass_kwargs.update({
@@ -596,33 +595,41 @@ class VideoService:
596
  "rescaling_scale": first_pass_args.get("rescaling_scale"),
597
  "skip_block_list": first_pass_args.get("skip_block_list"),
598
  })
599
- # Opcional: ajustar timesteps se especificado no config
600
  schedule = first_pass_args.get("timesteps") or first_pass_args.get("guidance_timesteps")
601
  if schedule:
602
  first_pass_kwargs["timesteps"] = schedule
603
  first_pass_kwargs["guidance_timesteps"] = schedule
604
 
605
- # Reduzir dimensões para o primeiro passo
606
  downscale_factor = self.config.get("downscale_factor", 2)
607
  original_height = first_pass_kwargs["height"]
608
  original_width = first_pass_kwargs["width"]
609
- first_pass_kwargs["height"] = original_height // downscale_factor
610
- first_pass_kwargs["width"] = original_width // downscale_factor
 
 
 
 
 
 
 
611
 
612
- print(f"[DEBUG] Passo 1: Dimensões reduzidas para {first_pass_kwargs['height']}x{first_pass_kwargs['width']}")
 
 
 
 
 
613
 
614
  t_p1 = time.perf_counter()
615
  ctx = torch.autocast(device_type="cuda", dtype=self.runtime_autocast_dtype) if self.device == "cuda" else contextlib.nullcontext()
616
  with ctx:
617
- # Executa a pipeline principal para o primeiro passo
618
  first_pass_result = self.pipeline(**first_pass_kwargs)
619
 
620
- # Extrai os latentes do resultado
621
  latents_low_res = first_pass_result.latents if hasattr(first_pass_result, "latents") else first_pass_result
622
  print(f"[DEBUG] Passo 1 concluído em {time.perf_counter()-t_p1:.3f}s. Shape dos latentes de baixa resolução: {tuple(latents_low_res.shape)}")
623
  log_tensor_info(latents_low_res, "Latentes (Passo 1)")
624
 
625
- # Limpeza de memória entre os passos
626
  del first_pass_result, first_pass_kwargs
627
  gc.collect()
628
  if self.device == "cuda": torch.cuda.empty_cache()
@@ -644,6 +651,7 @@ class VideoService:
644
  print("[DEBUG] Multi-escala: Iniciando Passo 2 (refinamento em alta resolução).")
645
  second_pass_args = self.config.get("second_pass", {}).copy()
646
  second_pass_kwargs = call_kwargs.copy()
 
647
  second_pass_kwargs.update({
648
  "guidance_scale": float(guidance_scale),
649
  "stg_scale": second_pass_args.get("stg_scale"),
 
587
 
588
  print("[DEBUG] Multi-escala: Iniciando Passo 1 (geração de latentes base).")
589
 
 
590
  first_pass_args = self.config.get("first_pass", {}).copy()
591
  first_pass_kwargs = call_kwargs.copy()
592
  first_pass_kwargs.update({
 
595
  "rescaling_scale": first_pass_args.get("rescaling_scale"),
596
  "skip_block_list": first_pass_args.get("skip_block_list"),
597
  })
 
598
  schedule = first_pass_args.get("timesteps") or first_pass_args.get("guidance_timesteps")
599
  if schedule:
600
  first_pass_kwargs["timesteps"] = schedule
601
  first_pass_kwargs["guidance_timesteps"] = schedule
602
 
603
+ # ==================== NOVA LÓGICA DE DIMENSÕES AQUI ====================
604
  downscale_factor = self.config.get("downscale_factor", 2)
605
  original_height = first_pass_kwargs["height"]
606
  original_width = first_pass_kwargs["width"]
607
+ divisor = 24
608
+
609
+ # Calcula a altura para o primeiro passo, garantindo divisibilidade
610
+ target_height_p1 = original_height // downscale_factor
611
+ first_pass_kwargs["height"] = round(target_height_p1 / divisor) * divisor
612
+
613
+ # Calcula a largura para o primeiro passo, garantindo divisibilidade
614
+ target_width_p1 = original_width // downscale_factor
615
+ first_pass_kwargs["width"] = round(target_width_p1 / divisor) * divisor
616
 
617
+ # Medida de segurança para evitar dimensões zero
618
+ if first_pass_kwargs["height"] == 0: first_pass_kwargs["height"] = divisor
619
+ if first_pass_kwargs["width"] == 0: first_pass_kwargs["width"] = divisor
620
+ # =======================================================================
621
+
622
+ print(f"[DEBUG] Passo 1: Dimensões reduzidas e ajustadas para {first_pass_kwargs['height']}x{first_pass_kwargs['width']}")
623
 
624
  t_p1 = time.perf_counter()
625
  ctx = torch.autocast(device_type="cuda", dtype=self.runtime_autocast_dtype) if self.device == "cuda" else contextlib.nullcontext()
626
  with ctx:
 
627
  first_pass_result = self.pipeline(**first_pass_kwargs)
628
 
 
629
  latents_low_res = first_pass_result.latents if hasattr(first_pass_result, "latents") else first_pass_result
630
  print(f"[DEBUG] Passo 1 concluído em {time.perf_counter()-t_p1:.3f}s. Shape dos latentes de baixa resolução: {tuple(latents_low_res.shape)}")
631
  log_tensor_info(latents_low_res, "Latentes (Passo 1)")
632
 
 
633
  del first_pass_result, first_pass_kwargs
634
  gc.collect()
635
  if self.device == "cuda": torch.cuda.empty_cache()
 
651
  print("[DEBUG] Multi-escala: Iniciando Passo 2 (refinamento em alta resolução).")
652
  second_pass_args = self.config.get("second_pass", {}).copy()
653
  second_pass_kwargs = call_kwargs.copy()
654
+
655
  second_pass_kwargs.update({
656
  "guidance_scale": float(guidance_scale),
657
  "stg_scale": second_pass_args.get("stg_scale"),