Update api/ltx_server.py
Browse files- api/ltx_server.py +15 -18
api/ltx_server.py
CHANGED
|
@@ -584,9 +584,9 @@ class VideoService:
|
|
| 584 |
if not self.latent_upsampler:
|
| 585 |
raise ValueError("Upscaler espacial não carregado.")
|
| 586 |
|
|
|
|
| 587 |
print("[DEBUG] Multi-escala: Iniciando Passo 1 (geração de latentes base).")
|
| 588 |
|
| 589 |
-
# 1. Configurar e executar o primeiro passo
|
| 590 |
first_pass_args = self.config.get("first_pass", {}).copy()
|
| 591 |
first_pass_kwargs = call_kwargs.copy()
|
| 592 |
first_pass_kwargs.update({
|
|
@@ -620,20 +620,17 @@ class VideoService:
|
|
| 620 |
ctx = torch.autocast(device_type="cuda", dtype=self.runtime_autocast_dtype) if self.device == "cuda" else contextlib.nullcontext()
|
| 621 |
with ctx:
|
| 622 |
first_pass_result = self.pipeline(**first_pass_kwargs)
|
| 623 |
-
|
| 624 |
-
|
| 625 |
latents_low_res = first_pass_result.images
|
| 626 |
-
|
| 627 |
-
log_tensor_info(latents_low_res, f"Latentes (Passo 1) {latents_low_res}")
|
| 628 |
|
| 629 |
del first_pass_result
|
| 630 |
gc.collect()
|
| 631 |
if self.device == "cuda": torch.cuda.empty_cache()
|
| 632 |
|
| 633 |
-
#
|
| 634 |
print("[DEBUG] Multi-escala: Fazendo upscale dos latentes com latent_upsampler.")
|
| 635 |
with ctx:
|
| 636 |
-
# Chamada posicional confirmada pelo código-fonte
|
| 637 |
latents_high_res = self.latent_upsampler(latents_low_res)
|
| 638 |
|
| 639 |
log_tensor_info(latents_high_res, "Latentes (Pós-Upscale)")
|
|
@@ -641,20 +638,16 @@ class VideoService:
|
|
| 641 |
gc.collect()
|
| 642 |
if self.device == "cuda": torch.cuda.empty_cache()
|
| 643 |
|
| 644 |
-
#
|
| 645 |
print("[DEBUG] Multi-escala: Iniciando Passo 2 (refinamento em alta resolução).")
|
| 646 |
second_pass_args = self.config.get("second_pass", {}).copy()
|
| 647 |
second_pass_kwargs = call_kwargs.copy()
|
| 648 |
|
| 649 |
-
# ==================== LÓGICA DE DIMENSÃO FINAL ====================
|
| 650 |
-
# As dimensões do Passo 2 DEVEM ser o dobro das dimensões do Passo 1,
|
| 651 |
-
# para corresponder à saída do upsampler.
|
| 652 |
height_p2 = height_p1 * 2
|
| 653 |
width_p2 = width_p1 * 2
|
| 654 |
second_pass_kwargs["height"] = height_p2
|
| 655 |
second_pass_kwargs["width"] = width_p2
|
| 656 |
print(f"[DEBUG] Passo 2: Dimensões definidas para {height_p2}x{width_p2} para corresponder ao upscale.")
|
| 657 |
-
# =================================================================
|
| 658 |
|
| 659 |
second_pass_kwargs.update({
|
| 660 |
"guidance_scale": float(guidance_scale),
|
|
@@ -663,17 +656,21 @@ class VideoService:
|
|
| 663 |
"skip_block_list": second_pass_args.get("skip_block_list"),
|
| 664 |
})
|
| 665 |
|
| 666 |
-
|
| 667 |
-
|
| 668 |
-
|
| 669 |
-
|
| 670 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 671 |
second_pass_kwargs["latents"] = latents_high_res
|
| 672 |
|
| 673 |
with ctx:
|
| 674 |
second_pass_result = self.pipeline(**second_pass_kwargs)
|
| 675 |
|
| 676 |
-
latents = second_pass_result.
|
| 677 |
log_tensor_info(latents, "Latentes Finais (Passo 2)")
|
| 678 |
|
| 679 |
else:
|
|
|
|
| 584 |
if not self.latent_upsampler:
|
| 585 |
raise ValueError("Upscaler espacial não carregado.")
|
| 586 |
|
| 587 |
+
# --- PASSO 1: GERAÇÃO DE LATENTES EM BAIXA RESOLUÇÃO ---
|
| 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({
|
|
|
|
| 620 |
ctx = torch.autocast(device_type="cuda", dtype=self.runtime_autocast_dtype) if self.device == "cuda" else contextlib.nullcontext()
|
| 621 |
with ctx:
|
| 622 |
first_pass_result = self.pipeline(**first_pass_kwargs)
|
| 623 |
+
|
|
|
|
| 624 |
latents_low_res = first_pass_result.images
|
| 625 |
+
log_tensor_info(latents_low_res, "Latentes (Passo 1)")
|
|
|
|
| 626 |
|
| 627 |
del first_pass_result
|
| 628 |
gc.collect()
|
| 629 |
if self.device == "cuda": torch.cuda.empty_cache()
|
| 630 |
|
| 631 |
+
# --- PASSO INTERMEDIÁRIO: UPSCALE DOS LATENTES ---
|
| 632 |
print("[DEBUG] Multi-escala: Fazendo upscale dos latentes com latent_upsampler.")
|
| 633 |
with ctx:
|
|
|
|
| 634 |
latents_high_res = self.latent_upsampler(latents_low_res)
|
| 635 |
|
| 636 |
log_tensor_info(latents_high_res, "Latentes (Pós-Upscale)")
|
|
|
|
| 638 |
gc.collect()
|
| 639 |
if self.device == "cuda": torch.cuda.empty_cache()
|
| 640 |
|
| 641 |
+
# --- PASSO 2: REFINAMENTO EM ALTA RESOLUÇÃO ---
|
| 642 |
print("[DEBUG] Multi-escala: Iniciando Passo 2 (refinamento em alta resolução).")
|
| 643 |
second_pass_args = self.config.get("second_pass", {}).copy()
|
| 644 |
second_pass_kwargs = call_kwargs.copy()
|
| 645 |
|
|
|
|
|
|
|
|
|
|
| 646 |
height_p2 = height_p1 * 2
|
| 647 |
width_p2 = width_p1 * 2
|
| 648 |
second_pass_kwargs["height"] = height_p2
|
| 649 |
second_pass_kwargs["width"] = width_p2
|
| 650 |
print(f"[DEBUG] Passo 2: Dimensões definidas para {height_p2}x{width_p2} para corresponder ao upscale.")
|
|
|
|
| 651 |
|
| 652 |
second_pass_kwargs.update({
|
| 653 |
"guidance_scale": float(guidance_scale),
|
|
|
|
| 656 |
"skip_block_list": second_pass_args.get("skip_block_list"),
|
| 657 |
})
|
| 658 |
|
| 659 |
+
strength = second_pass_args.get("strength", second_pass_args.get("denoising_strength", 0.7))
|
| 660 |
+
second_pass_kwargs["strength"] = strength
|
| 661 |
+
print(f"[DEBUG] Passo 2: Denoising strength definido para {strength}")
|
| 662 |
+
|
| 663 |
+
if "timesteps" in second_pass_kwargs:
|
| 664 |
+
del second_pass_kwargs["timesteps"]
|
| 665 |
+
if "guidance_timesteps" in second_pass_kwargs:
|
| 666 |
+
del second_pass_kwargs["guidance_timesteps"]
|
| 667 |
+
|
| 668 |
second_pass_kwargs["latents"] = latents_high_res
|
| 669 |
|
| 670 |
with ctx:
|
| 671 |
second_pass_result = self.pipeline(**second_pass_kwargs)
|
| 672 |
|
| 673 |
+
latents = second_pass_result.images
|
| 674 |
log_tensor_info(latents, "Latentes Finais (Passo 2)")
|
| 675 |
|
| 676 |
else:
|