Refactor: add skip-all checks, fix PIL image loading and cfg_scale parameter, and enable xformers attention

This commit is contained in:
2026-11-04 01:54:33 +08:00
parent c6bdb88bd2
commit e51f7e78d4
4 changed files with 42 additions and 4 deletions
+16 -3
View File
@@ -38,6 +38,7 @@ import sys
import gc
import hashlib
import importlib.util
from PIL import Image
# ==============================================================================
# 動態加載專案配置 (與 fl2va 一致: cd 到專案目錄後讀 ./config.py)
@@ -58,11 +59,13 @@ RUN_CONFIG = config.RUN_CONFIG
def get_enabled_tasks():
return config.get_enabled_tasks()
return [idx for idx, task in TASK_REGISTRY.items() if task.enabled]
def load_task_references(idx):
return config.load_task_references(idx)
if idx not in TASK_REGISTRY:
raise KeyError(f"Task index {idx} not found in TASK_REGISTRY")
return TASK_REGISTRY[idx].references
import torch
@@ -135,6 +138,14 @@ def main():
torch.cuda.empty_cache()
gc.collect()
# 檢查所有 result1_ref_*.pt 是否已存在,若全部存在則跳過整個 Step 1
all_ref_pts_exist = all(os.path.exists(f"result1_ref_{idx:02d}.pt") for idx in enabled_ids)
if all_ref_pts_exist:
print(">> [SKIP] 所有 result1_ref_*.pt 已存在,跳過 Step 1。")
print(f"\n========== [REF2VA STAGE 1] 完成 {len(enabled_ids)}/{len(enabled_ids)} 個任務 (全部跳過) ==========")
print(">> 下一步: ref2va_step2.py (text encoder)")
return
# 單一權重: video VAE (1.6GB) 全駐 GPU (1.6G 對 24GB 完全沒壓力,
# 全 cuda 避免 layer-wise hotload 拖慢 N 張參考圖的編碼)
vram_config = {
@@ -237,7 +248,9 @@ def main():
short_edge = getattr(task, "ref_image_short_edge", 2048)
v_shape, a_shape, nf = latent_shapes(task)
references = [{"type": "image", "image": img} for img in refs]
# 載入圖片為 PIL Image 物件 (pipeline 預期輸入)
refs_images = [Image.open(img_path).convert("RGB") for img_path in refs]
references = [{"type": "image", "image": img} for img in refs_images]
print(f"\n>> [Task {idx}] 編碼 {len(refs)} 張參考圖 (短邊 {short_edge}, "
f"目標 {task.width}x{task.height}, {nf}f)..."
+ (f" (原 {task.num_frames}f → snap {nf}f)" if nf != task.num_frames else ""))