EuuIia commited on
Commit
82b2143
·
verified ·
1 Parent(s): c0f630d

Update api/ltx_server.py

Browse files
Files changed (1) hide show
  1. api/ltx_server.py +10 -76
api/ltx_server.py CHANGED
@@ -671,7 +671,7 @@ class VideoService:
671
  multi_scale_pipeline = None
672
 
673
  try:
674
- if True: #improve_texture:
675
  if not self.latent_upsampler:
676
  raise ValueError("Upscaler espacial não carregado.")
677
  print("[DEBUG] Multi-escala: construindo pipeline...")
@@ -686,7 +686,7 @@ class VideoService:
686
  {
687
  "downscale_factor": self.config["downscale_factor"],
688
  "first_pass": first_pass_args,
689
- "second_pass": first_pass_args,
690
  }
691
  )
692
  print("[DEBUG] Chamando multi_scale_pipeline...")
@@ -703,84 +703,20 @@ class VideoService:
703
  else:
704
  latents = result
705
  print(f"[DEBUG] Latentes (multi-escala): shape={tuple(latents.shape)}")
706
-
707
- #if true:
708
  single_pass_kwargs = call_kwargs.copy()
709
- first_pass_config = self.config.get("first_pass", {}).copy()
710
-
711
  single_pass_kwargs.update(
712
  {
713
- "skip_final_inference_steps": first_pass_config.get("skip_final_inference_steps"),
714
- "stg_scale": first_pass_config.get("stg_scale"),
715
  "stg_scale": first_pass_config.get("stg_scale"),
716
  "rescaling_scale": first_pass_config.get("rescaling_scale"),
717
- "guidance_timesteps": first_pass_config.get("guidance_timesteps"),
718
  "skip_block_list": first_pass_config.get("skip_block_list"),
719
- "num_inference_steps": first_pass_config.get("num_inference_steps"),
720
- "skip_final_inference_steps": first_pass_config.get("skip_final_inference_steps"),
721
- "cfg_star_rescale": first_pass_config.get("cfg_star_rescale"),
722
- "downscale_factor": self.config["downscale_factor"],
723
-
724
- #"guidance_scale": float(guidance_scale),
725
- #"stg_scale": first_pass_config.get("stg_scale"),
726
- #"rescaling_scale": first_pass_config.get("rescaling_scale"),
727
- #"skip_block_list": first_pass_config.get("skip_block_list"),
728
- }
729
- )
730
- #schedule =
731
- #first_pass_config.get("timesteps") or
732
- #first_pass_config.get("guidance_timesteps")
733
- #if mode == "video-to-video":
734
- # schedule = [0.7]; print("[INFO] Modo video-to-video (etapa única): timesteps=[0.7]")
735
- #if isinstance(schedule, (list, tuple)) and len(schedule) > 0:
736
- # single_pass_kwargs["timesteps"] = schedule
737
- # single_pass_kwargs["guidance_timesteps"] = schedule
738
- #print(f"[DEBUG] Single-pass: timesteps_len={len(schedule) if schedule else 0}")
739
-
740
- #print("\n[INFO] Executando pipeline de etapa única...")
741
- #t_sp = time.perf_counter()
742
- #ctx = torch.autocast(device_type="cuda", dtype=self.runtime_autocast_dtype) if self.device == "cuda" else contextlib.nullcontext()
743
- #with ctx:
744
- # result = self.pipeline(**single_pass_kwargs)
745
- #print(f"[DEBUG] single-pass tempo={time.perf_counter()-t_sp:.3f}s")
746
-
747
- #if hasattr(result, "latents"):
748
- # latents = result.latents
749
- #elif hasattr(result, "images") and isinstance(result.images, torch.Tensor):
750
- # latents = result.images
751
- #else:
752
- # latents = result
753
- #print(f"[DEBUG] Latentes (single-pass) first : shape={tuple(latents.shape)}")
754
-
755
- single_pass_kwargs = call_kwargs.copy()
756
- first_pass_config = self.config.get("first_pass", {}).copy()
757
- second_pass_args = self.config.get("second_pass", {}).copy()
758
- second_pass = self.config.get("second_pass", {}).copy()
759
-
760
- single_pass_kwargs.update(
761
- {
762
- "latents" : latents,
763
- "skip_final_inference_steps": second_pass.get("skip_final_inference_steps"),
764
- "stg_scale": second_pass.get("stg_scale"),
765
- "stg_scale": second_pass.get("stg_scale"),
766
- "rescaling_scale": second_pass.get("rescaling_scale"),
767
- "guidance_timesteps": second_pass.get("guidance_timesteps"),
768
- "skip_block_list": second_pass.get("skip_block_list"),
769
- "num_inference_steps": second_pass.get("num_inference_steps"),
770
- "skip_final_inference_steps": 0, #first_pass_config.get("skip_final_inference_steps"),
771
- "skip_initial_inference_steps": 17,# second_pass.get("skip_initial_inference_steps"),
772
- "cfg_star_rescale": second_pass.get("cfg_star_rescale"),
773
- "downscale_factor": self.config["downscale_factor"],
774
- "second_pass": second_pass_args,
775
- #"guidance_scale": float(guidance_scale),
776
- #"stg_scale": first_pass_config.get("stg_scale"),
777
- #"rescaling_scale": first_pass_config.get("rescaling_scale"),
778
- #"skip_block_list": first_pass_config.get("skip_block_list"),
779
  }
780
  )
781
- schedule = second_pass.get("guidance_timesteps")
782
- #if mode == "video-to-video":
783
- # schedule = [0.7]; print("[INFO] Modo video-to-video (etapa única): timesteps=[0.7]")
784
  if isinstance(schedule, (list, tuple)) and len(schedule) > 0:
785
  single_pass_kwargs["timesteps"] = schedule
786
  single_pass_kwargs["guidance_timesteps"] = schedule
@@ -799,10 +735,8 @@ class VideoService:
799
  latents = result.images
800
  else:
801
  latents = result
802
- print(f"[DEBUG] Latentes (single-pass) segunda: shape={tuple(latents.shape)}")
803
-
804
 
805
-
806
  # Staging e escrita MP4 (simples: VAE → pixels → MP4)
807
 
808
  latents_cpu = latents.detach().to("cpu", non_blocking=True)
@@ -898,4 +832,4 @@ class VideoService:
898
  print(f"[DEBUG] finalize() no finally falhou: {e}")
899
 
900
  print("Criando instância do VideoService. O carregamento do modelo começará agora...")
901
- video_generation_service = VideoService()
 
671
  multi_scale_pipeline = None
672
 
673
  try:
674
+ if improve_texture:
675
  if not self.latent_upsampler:
676
  raise ValueError("Upscaler espacial não carregado.")
677
  print("[DEBUG] Multi-escala: construindo pipeline...")
 
686
  {
687
  "downscale_factor": self.config["downscale_factor"],
688
  "first_pass": first_pass_args,
689
+ "second_pass": second_pass_args,
690
  }
691
  )
692
  print("[DEBUG] Chamando multi_scale_pipeline...")
 
703
  else:
704
  latents = result
705
  print(f"[DEBUG] Latentes (multi-escala): shape={tuple(latents.shape)}")
706
+ else:
 
707
  single_pass_kwargs = call_kwargs.copy()
708
+ first_pass_config = self.config.get("first_pass", {})
 
709
  single_pass_kwargs.update(
710
  {
711
+ "guidance_scale": float(guidance_scale),
 
712
  "stg_scale": first_pass_config.get("stg_scale"),
713
  "rescaling_scale": first_pass_config.get("rescaling_scale"),
 
714
  "skip_block_list": first_pass_config.get("skip_block_list"),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
715
  }
716
  )
717
+ schedule = first_pass_config.get("timesteps") or first_pass_config.get("guidance_timesteps")
718
+ if mode == "video-to-video":
719
+ schedule = [0.7]; print("[INFO] Modo video-to-video (etapa única): timesteps=[0.7]")
720
  if isinstance(schedule, (list, tuple)) and len(schedule) > 0:
721
  single_pass_kwargs["timesteps"] = schedule
722
  single_pass_kwargs["guidance_timesteps"] = schedule
 
735
  latents = result.images
736
  else:
737
  latents = result
738
+ print(f"[DEBUG] Latentes (single-pass): shape={tuple(latents.shape)}")
 
739
 
 
740
  # Staging e escrita MP4 (simples: VAE → pixels → MP4)
741
 
742
  latents_cpu = latents.detach().to("cpu", non_blocking=True)
 
832
  print(f"[DEBUG] finalize() no finally falhou: {e}")
833
 
834
  print("Criando instância do VideoService. O carregamento do modelo começará agora...")
835
+ video_generation_service = VideoService()