EuuIia commited on
Commit
b0b3098
·
verified ·
1 Parent(s): da4e724

Update api/ltx_server.py

Browse files
Files changed (1) hide show
  1. api/ltx_server.py +43 -16
api/ltx_server.py CHANGED
@@ -437,22 +437,49 @@ class VideoService:
437
  return chunks
438
 
439
 
440
- def dividir_latentes(latents_brutos):
441
- sum_latent = latents_brutos.shape[2] # dimensão temporal (latentes)
442
- cut1 = sum_latent // 2
443
- cut2 = sum_latent-cut1-1
444
- chunk1 = latents_brutos[:, :, :cut1, :, :].clone()
445
- chunk2 = latents_brutos[:, :, cut2:, :, :].clone()
446
- chunk1_sum = primeir.shape[2] # dimensão temporal (latentes1)
447
- chunk2_sum = segunda.shape[2] # dimensão temporal (latentes2)
448
-
449
- print(f"==============PODA CAUSAL==================")
450
- print(f"[DEBUG] TOTAL LATENTES A DIVIDIR = {sum_latent}")
451
- print(f"[DEBUG] chunk1[:, :, :{cut1}, :, :] = {chunk1_sum}")
452
- print(f"[DEBUG] chunk2[:, :, :{cut2}, :, :] = {chunk2_sum}")
453
- print(f"===========================================")
454
-
455
- return primeira, segunda
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
456
 
457
 
458
  def _concat_mp4s_no_reencode(self, mp4_list: List[str], out_path: str):
 
437
  return chunks
438
 
439
 
440
+ def _dividir_latentes_em_partes(self, latents_brutos, min_latentes_por_chunk: int):
441
+ """
442
+ Divide o tensor de latentes em várias partes com base no número mínimo de latentes por chunk.
443
+ Cada parte tem sobreposição causal de 1 frame com a anterior.
444
+
445
+ Args:
446
+ latents_brutos: tensor [B, C, T, H, W]
447
+ min_latentes_por_chunk: número mínimo de latentes em cada parte
448
+
449
+ Returns:
450
+ List[Tensor]: lista de partes do tensor (cada uma cloneada)
451
+ """
452
+ total_latents = latents_brutos.shape[2]
453
+ overlap = 1
454
+ chunks = []
455
+
456
+ print("================PODA CAUSAL=================")
457
+ print(f"[DEBUG] TOTAL LATENTES A DIVIDIR = {total_latents}")
458
+ print(f"[DEBUG] Num LATENTES por chunk = {min_latentes_por_chunk}")
459
+
460
+ start = 0
461
+ i = 0
462
+
463
+ while start < total_latents:
464
+ end = start + min_latentes_por_chunk - 1 # menos 1 por causa da sobreposição
465
+ if end > total_latents:
466
+ end = total_latents
467
+ chunk = latents_brutos[:, :, start:end, :, :].clone()
468
+ chunks.append(chunk)
469
+
470
+ print(f"[DEBUG] chunk{i+1}[:, :, {start}:{end}, :, :] = {chunk.shape[2]}")
471
+
472
+ # Avança com sobreposição
473
+ start = end - overlap
474
+ i += 1
475
+
476
+ # Evita loop infinito se o final for atingido
477
+ if start >= total_latents:
478
+ break
479
+
480
+ print("================PODA CAUSAL=================")
481
+ return chunks
482
+
483
 
484
 
485
  def _concat_mp4s_no_reencode(self, mp4_list: List[str], out_path: str):