Spaces:
Paused
Paused
Update api/ltx_server_refactored_complete.py
Browse files
api/ltx_server_refactored_complete.py
CHANGED
|
@@ -361,11 +361,18 @@ class VideoService:
|
|
| 361 |
|
| 362 |
|
| 363 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 364 |
@log_function_io
|
| 365 |
-
def prepare_condition_items(self, items_list: List, height: int, width: int, num_frames: int) -> List[
|
| 366 |
"""
|
| 367 |
-
[CORRIGIDO] Prepara ConditioningItems,
|
| 368 |
-
|
| 369 |
"""
|
| 370 |
if not items_list: return []
|
| 371 |
height_padded, width_padded = self._align(height), self._align(width)
|
|
@@ -373,47 +380,29 @@ class VideoService:
|
|
| 373 |
|
| 374 |
conditioning_items = []
|
| 375 |
for media_item, frame, weight in items_list:
|
|
|
|
| 376 |
if isinstance(media_item, str):
|
| 377 |
-
# Carrega a imagem
|
|
|
|
| 378 |
tensor = load_image_to_tensor_with_resize_and_crop(media_item, height, width)
|
|
|
|
| 379 |
tensor = torch.nn.functional.pad(tensor, padding_values)
|
| 380 |
-
#
|
|
|
|
|
|
|
| 381 |
elif isinstance(media_item, torch.Tensor):
|
| 382 |
-
# Se for um tensor (
|
| 383 |
-
|
| 384 |
else:
|
| 385 |
logging.warning(f"Unknown conditioning media type: {type(media_item)}. Skipping.")
|
| 386 |
continue
|
| 387 |
|
| 388 |
safe_frame = max(0, min(int(frame), num_frames - 1))
|
| 389 |
-
conditioning_items.append(ConditioningItem(
|
| 390 |
-
|
| 391 |
self._log_conditioning_items(conditioning_items)
|
| 392 |
return conditioning_items
|
| 393 |
-
|
| 394 |
|
| 395 |
-
@log_function_io
|
| 396 |
-
def prepare_condition_items(self, items_list: List, height: int, width: int, num_frames: int) -> List[ConditioningItem]:
|
| 397 |
-
"""[UNIFIED] Prepares ConditioningItems from a mixed list of file paths and tensors."""
|
| 398 |
-
if not items_list: return []
|
| 399 |
-
height_padded, width_padded = self._align(height), self._align(width)
|
| 400 |
-
padding_values = calculate_padding(height, width, height_padded, width_padded)
|
| 401 |
-
|
| 402 |
-
conditioning_items = []
|
| 403 |
-
for media_item, frame, weight in items_list:
|
| 404 |
-
if isinstance(media_item, str):
|
| 405 |
-
tensor = load_image_to_tensor_with_resize_and_crop(media_item, height, width)
|
| 406 |
-
tensor = torch.nn.functional.pad(tensor, padding_values)
|
| 407 |
-
tensor = tensor.to(self.main_device, dtype=self.runtime_autocast_dtype)
|
| 408 |
-
elif isinstance(media_item, torch.Tensor):
|
| 409 |
-
tensor = media_item.to(self.main_device, dtype=self.runtime_autocast_dtype)
|
| 410 |
-
else:
|
| 411 |
-
logging.warning(f"Unknown conditioning media type: {type(media_item)}. Skipping.")
|
| 412 |
-
continue
|
| 413 |
-
|
| 414 |
-
safe_frame = max(0, min(int(frame), num_frames - 1))
|
| 415 |
-
conditioning_items.append(ConditioningItem(tensor, safe_frame, float(weight)))
|
| 416 |
-
return conditioning_items
|
| 417 |
|
| 418 |
def _apply_ui_overrides(self, config_dict: Dict, overrides: Dict):
|
| 419 |
"""Applies advanced settings from the UI to a config dictionary."""
|
|
|
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
+
# FILE: api/ltx_server_refactored_complete.py (Versão com correção de dispositivo DEFINITIVA)
|
| 365 |
+
|
| 366 |
+
# ...
|
| 367 |
+
|
| 368 |
+
class VideoService:
|
| 369 |
+
# ...
|
| 370 |
+
|
| 371 |
@log_function_io
|
| 372 |
+
def prepare_condition_items(self, items_list: List, height: int, width: int, num_frames: int) -> List[ConditioningItem]:
|
| 373 |
"""
|
| 374 |
+
[CORRIGIDO] Prepara ConditioningItems, garantindo que o tensor final
|
| 375 |
+
resida no dispositivo principal do pipeline (main_device).
|
| 376 |
"""
|
| 377 |
if not items_list: return []
|
| 378 |
height_padded, width_padded = self._align(height), self._align(width)
|
|
|
|
| 380 |
|
| 381 |
conditioning_items = []
|
| 382 |
for media_item, frame, weight in items_list:
|
| 383 |
+
final_tensor = None
|
| 384 |
if isinstance(media_item, str):
|
| 385 |
+
# 1. Carrega a imagem. A função pode usar o VAE, então ela pode
|
| 386 |
+
# retornar um tensor em qualquer dispositivo.
|
| 387 |
tensor = load_image_to_tensor_with_resize_and_crop(media_item, height, width)
|
| 388 |
+
# 2. Aplica padding.
|
| 389 |
tensor = torch.nn.functional.pad(tensor, padding_values)
|
| 390 |
+
# 3. GARANTE que o tensor final esteja no dispositivo principal.
|
| 391 |
+
final_tensor = tensor.to(self.main_device, dtype=self.runtime_autocast_dtype)
|
| 392 |
+
|
| 393 |
elif isinstance(media_item, torch.Tensor):
|
| 394 |
+
# Se já for um tensor (ex: overlap), apenas garante que ele está no dispositivo principal.
|
| 395 |
+
final_tensor = media_item.to(self.main_device, dtype=self.runtime_autocast_dtype)
|
| 396 |
else:
|
| 397 |
logging.warning(f"Unknown conditioning media type: {type(media_item)}. Skipping.")
|
| 398 |
continue
|
| 399 |
|
| 400 |
safe_frame = max(0, min(int(frame), num_frames - 1))
|
| 401 |
+
conditioning_items.append(ConditioningItem(final_tensor, safe_frame, float(weight)))
|
| 402 |
+
|
| 403 |
self._log_conditioning_items(conditioning_items)
|
| 404 |
return conditioning_items
|
|
|
|
| 405 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 406 |
|
| 407 |
def _apply_ui_overrides(self, config_dict: Dict, overrides: Dict):
|
| 408 |
"""Applies advanced settings from the UI to a config dictionary."""
|