Spaces:
Runtime error
Runtime error
Update upscaler_specialist.py
Browse files- upscaler_specialist.py +39 -18
upscaler_specialist.py
CHANGED
|
@@ -20,30 +20,51 @@ class UpscalerSpecialist:
|
|
| 20 |
self.base_vae = None
|
| 21 |
self.pipe_upsample = None
|
| 22 |
|
|
|
|
| 23 |
def _lazy_init(self):
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
try:
|
| 27 |
-
if ltx_manager_singleton.workers:
|
| 28 |
-
self.base_vae = ltx_manager_singleton.workers[0].pipeline.vae
|
| 29 |
-
logger.info("[Upscaler] VAE base obtido com sucesso.")
|
| 30 |
-
else:
|
| 31 |
-
logger.warning("[Upscaler] Nenhum worker disponível no ltx_manager_singleton.")
|
| 32 |
-
except Exception as e:
|
| 33 |
-
logger.error(f"[Upscaler] Falha ao inicializar VAE: {e}")
|
| 34 |
-
return
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
"linoyts/LTX-Video-spatial-upscaler-0.9.8",
|
| 40 |
-
vae
|
| 41 |
torch_dtype=torch.float16 if self.device == "cuda" else torch.float32
|
| 42 |
).to(self.device)
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
|
|
|
| 47 |
@torch.no_grad()
|
| 48 |
def upscale(self, latents: torch.Tensor) -> torch.Tensor:
|
| 49 |
"""Aplica o upscaling 2x nos tensores latentes fornecidos."""
|
|
|
|
| 20 |
self.base_vae = None
|
| 21 |
self.pipe_upsample = None
|
| 22 |
|
| 23 |
+
|
| 24 |
def _lazy_init(self):
|
| 25 |
+
if self.pipe_upsample is not None:
|
| 26 |
+
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
try:
|
| 29 |
+
# Tenta usar o VAE do ltx_manager
|
| 30 |
+
if ltx_manager_singleton.workers:
|
| 31 |
+
candidate_vae = ltx_manager_singleton.workers[0].pipeline.vae
|
| 32 |
+
if candidate_vae.__class__.__name__ == "AutoencoderKLLTXVideo":
|
| 33 |
+
self.base_vae = candidate_vae
|
| 34 |
+
logger.info("[Upscaler] Usando VAE do ltx_manager (AutoencoderKLLTXVideo).")
|
| 35 |
+
else:
|
| 36 |
+
logger.warning(f"[Upscaler] VAE incompatível: {type(candidate_vae)}. "
|
| 37 |
+
"Carregando AutoencoderKLLTXVideo manualmente...")
|
| 38 |
+
from diffusers.models.autoencoders import AutoencoderKLLTXVideo
|
| 39 |
+
self.base_vae = AutoencoderKLLTXVideo.from_pretrained(
|
| 40 |
"linoyts/LTX-Video-spatial-upscaler-0.9.8",
|
| 41 |
+
subfolder="vae",
|
| 42 |
torch_dtype=torch.float16 if self.device == "cuda" else torch.float32
|
| 43 |
).to(self.device)
|
| 44 |
+
else:
|
| 45 |
+
logger.warning("[Upscaler] Nenhum worker disponível, carregando VAE manualmente...")
|
| 46 |
+
from diffusers.models.autoencoders import AutoencoderKLLTXVideo
|
| 47 |
+
self.base_vae = AutoencoderKLLTXVideo.from_pretrained(
|
| 48 |
+
"linoyts/LTX-Video-spatial-upscaler-0.9.8",
|
| 49 |
+
subfolder="vae",
|
| 50 |
+
torch_dtype=torch.float16 if self.device == "cuda" else torch.float32
|
| 51 |
+
).to(self.device)
|
| 52 |
+
|
| 53 |
+
# Carregar pipeline
|
| 54 |
+
self.pipe_upsample = LTXLatentUpsamplePipeline.from_pretrained(
|
| 55 |
+
"linoyts/LTX-Video-spatial-upscaler-0.9.8",
|
| 56 |
+
vae=self.base_vae,
|
| 57 |
+
torch_dtype=torch.float16 if self.device == "cuda" else torch.float32
|
| 58 |
+
).to(self.device)
|
| 59 |
+
|
| 60 |
+
logger.info("[Upscaler] Pipeline carregado com sucesso.")
|
| 61 |
+
|
| 62 |
+
except Exception as e:
|
| 63 |
+
logger.error(f"[Upscaler] Falha ao carregar pipeline: {e}")
|
| 64 |
+
self.pipe_upsample = None
|
| 65 |
+
|
| 66 |
|
| 67 |
+
|
| 68 |
@torch.no_grad()
|
| 69 |
def upscale(self, latents: torch.Tensor) -> torch.Tensor:
|
| 70 |
"""Aplica o upscaling 2x nos tensores latentes fornecidos."""
|