Update api/ltx_server.py
Browse files- api/ltx_server.py +39 -10
api/ltx_server.py
CHANGED
|
@@ -396,6 +396,41 @@ class VideoService:
|
|
| 396 |
print(f"[DEBUG] Cond shape={tuple(out.shape)} dtype={out.dtype} device={out.device}")
|
| 397 |
return out
|
| 398 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 399 |
def _dividir_latentes(self, latents_brutos):
|
| 400 |
total = latents_brutos.shape[2] # dimensão temporal (número de latentes)
|
| 401 |
|
|
@@ -609,7 +644,7 @@ class VideoService:
|
|
| 609 |
pass
|
| 610 |
|
| 611 |
# 2) Divide em duas partes
|
| 612 |
-
lat_a, lat_b = self.
|
| 613 |
print(f"[DEBUG] Partição A: {tuple(lat_a.shape)}")
|
| 614 |
print(f"[DEBUG] Partição B: {tuple(lat_b.shape)}")
|
| 615 |
|
|
@@ -653,18 +688,12 @@ class VideoService:
|
|
| 653 |
final_output_path = output_video_path
|
| 654 |
print(f"[DEBUG] Falha no move; usando tmp como final: {e}")
|
| 655 |
|
| 656 |
-
final_concat = os.path.join(results_dir, f"
|
| 657 |
self._concat_mp4s_no_reencode(partes_mp4[0], partes_mp4[1], final_concat)
|
| 658 |
|
| 659 |
-
|
| 660 |
-
shutil.move(output_video_path, final_concat)
|
| 661 |
-
final_output_path = final_concat
|
| 662 |
-
except Exception:
|
| 663 |
-
final_output_path = output_video_path
|
| 664 |
-
self._register_tmp_file(output_video_path)
|
| 665 |
-
|
| 666 |
self._log_gpu_memory("Fim da Geração")
|
| 667 |
-
return
|
| 668 |
|
| 669 |
|
| 670 |
except Exception as e:
|
|
|
|
| 396 |
print(f"[DEBUG] Cond shape={tuple(out.shape)} dtype={out.dtype} device={out.device}")
|
| 397 |
return out
|
| 398 |
|
| 399 |
+
|
| 400 |
+
def dividir_latentes_em_partes(latents_brutos, quantidade: int):
|
| 401 |
+
"""
|
| 402 |
+
Divide um tensor de latentes em `quantidade` partes e retorna uma lista de clones.
|
| 403 |
+
|
| 404 |
+
Args:
|
| 405 |
+
latents_brutos: tensor [B, C, T, H, W]
|
| 406 |
+
quantidade: número de partes que queremos dividir
|
| 407 |
+
|
| 408 |
+
Returns:
|
| 409 |
+
List[Tensor]: lista de `quantidade` partes, cada uma cloneada
|
| 410 |
+
"""
|
| 411 |
+
total = latents_brutos.shape[2] # dimensão temporal
|
| 412 |
+
partes = []
|
| 413 |
+
|
| 414 |
+
if quantidade <= 1 or quantidade > total:
|
| 415 |
+
return [latents_brutos.clone()]
|
| 416 |
+
|
| 417 |
+
# calcular tamanho aproximado de cada parte
|
| 418 |
+
step = total // quantidade
|
| 419 |
+
overlap = 1 # sobreposição mínima de 1 frame entre partes
|
| 420 |
+
|
| 421 |
+
for i in range(quantidade):
|
| 422 |
+
start = i * step
|
| 423 |
+
end = start + step
|
| 424 |
+
if i == quantidade - 1:
|
| 425 |
+
end = total # última parte vai até o final
|
| 426 |
+
else:
|
| 427 |
+
end += overlap # sobreposição
|
| 428 |
+
parte = latents_brutos[:, :, start:end, :, :].clone()
|
| 429 |
+
partes.append(parte)
|
| 430 |
+
|
| 431 |
+
return partes
|
| 432 |
+
|
| 433 |
+
|
| 434 |
def _dividir_latentes(self, latents_brutos):
|
| 435 |
total = latents_brutos.shape[2] # dimensão temporal (número de latentes)
|
| 436 |
|
|
|
|
| 644 |
pass
|
| 645 |
|
| 646 |
# 2) Divide em duas partes
|
| 647 |
+
lat_a, lat_b = self._dividir_latentes_em_partes(latents_cpu, 2)
|
| 648 |
print(f"[DEBUG] Partição A: {tuple(lat_a.shape)}")
|
| 649 |
print(f"[DEBUG] Partição B: {tuple(lat_b.shape)}")
|
| 650 |
|
|
|
|
| 688 |
final_output_path = output_video_path
|
| 689 |
print(f"[DEBUG] Falha no move; usando tmp como final: {e}")
|
| 690 |
|
| 691 |
+
final_concat = os.path.join(results_dir, f"concat_fim_{used_seed}.mp4")
|
| 692 |
self._concat_mp4s_no_reencode(partes_mp4[0], partes_mp4[1], final_concat)
|
| 693 |
|
| 694 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 695 |
self._log_gpu_memory("Fim da Geração")
|
| 696 |
+
return final_concat, used_seed
|
| 697 |
|
| 698 |
|
| 699 |
except Exception as e:
|