Refactor: add skip-all checks, fix PIL image loading and cfg_scale parameter, and enable xformers attention
This commit is contained in:
@@ -51,6 +51,12 @@ RUN_CONFIG = {
|
|||||||
"default_num_inference_steps": 12,
|
"default_num_inference_steps": 12,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# --- 額外 LoRA (NSFW anatomy) ---
|
||||||
|
EXTRA_LORAS = [
|
||||||
|
("Mini_Dick_Fix_V1.safetensors", 0.55),
|
||||||
|
("MysticXXX_MMH3-V4.safetensors", 0.7),
|
||||||
|
]
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# 🎯 任務配置
|
# 🎯 任務配置
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|||||||
+16
-3
@@ -38,6 +38,7 @@ import sys
|
|||||||
import gc
|
import gc
|
||||||
import hashlib
|
import hashlib
|
||||||
import importlib.util
|
import importlib.util
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
# 動態加載專案配置 (與 fl2va 一致: cd 到專案目錄後讀 ./config.py)
|
# 動態加載專案配置 (與 fl2va 一致: cd 到專案目錄後讀 ./config.py)
|
||||||
@@ -58,11 +59,13 @@ RUN_CONFIG = config.RUN_CONFIG
|
|||||||
|
|
||||||
|
|
||||||
def get_enabled_tasks():
|
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):
|
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
|
import torch
|
||||||
@@ -135,6 +138,14 @@ def main():
|
|||||||
torch.cuda.empty_cache()
|
torch.cuda.empty_cache()
|
||||||
gc.collect()
|
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 完全沒壓力,
|
# 單一權重: video VAE (1.6GB) 全駐 GPU (1.6G 對 24GB 完全沒壓力,
|
||||||
# 全 cuda 避免 layer-wise hotload 拖慢 N 張參考圖的編碼)
|
# 全 cuda 避免 layer-wise hotload 拖慢 N 張參考圖的編碼)
|
||||||
vram_config = {
|
vram_config = {
|
||||||
@@ -237,7 +248,9 @@ def main():
|
|||||||
short_edge = getattr(task, "ref_image_short_edge", 2048)
|
short_edge = getattr(task, "ref_image_short_edge", 2048)
|
||||||
v_shape, a_shape, nf = latent_shapes(task)
|
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}, "
|
print(f"\n>> [Task {idx}] 編碼 {len(refs)} 張參考圖 (短邊 {short_edge}, "
|
||||||
f"目標 {task.width}x{task.height}, {nf}f)..."
|
f"目標 {task.width}x{task.height}, {nf}f)..."
|
||||||
+ (f" (原 {task.num_frames}f → snap {nf}f)" if nf != task.num_frames else ""))
|
+ (f" (原 {task.num_frames}f → snap {nf}f)" if nf != task.num_frames else ""))
|
||||||
|
|||||||
@@ -107,6 +107,14 @@ def main():
|
|||||||
print(f">> [Error] Task {idx} 缺少 result1_ref_{idx:02d}.pt, 請先執行 step1。")
|
print(f">> [Error] Task {idx} 缺少 result1_ref_{idx:02d}.pt, 請先執行 step1。")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
# 檢查所有 result2_text_*.pt 是否已存在,若全部存在則跳過整個 Step 2
|
||||||
|
all_text_pts_exist = all(os.path.exists(f"result2_text_{idx:02d}.pt") for idx in enabled_ids)
|
||||||
|
if all_text_pts_exist:
|
||||||
|
print(">> [SKIP] 所有 result2_text_*.pt 已存在,跳過 Step 2。")
|
||||||
|
print(f"\n========== [REF2VA STAGE 2] 完成 {len(enabled_ids)}/{len(enabled_ids)} 個任務 (全部跳過) ==========")
|
||||||
|
print(">> 下一步: ref2va_step3.py (DiT 去噪)")
|
||||||
|
return
|
||||||
|
|
||||||
torch.cuda.empty_cache()
|
torch.cuda.empty_cache()
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
||||||
|
|||||||
+12
-1
@@ -24,6 +24,7 @@ os.environ["HSA_OVERRIDE_GFX_VERSION"] = "11.0.0"
|
|||||||
os.environ["PYTHONNOUSERSITE"] = "1"
|
os.environ["PYTHONNOUSERSITE"] = "1"
|
||||||
os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "garbage_collection_threshold:0.8"
|
os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "garbage_collection_threshold:0.8"
|
||||||
os.environ["DIFFSYNTH_SKIP_DOWNLOAD"] = "True"
|
os.environ["DIFFSYNTH_SKIP_DOWNLOAD"] = "True"
|
||||||
|
os.environ["DIFFSYNTH_ATTENTION_IMPLEMENTATION"] = "xformers"
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
# 強制啟用 PyTorch ROCm 的記憶體高效與 Flash 注意力後端
|
# 強制啟用 PyTorch ROCm 的記憶體高效與 Flash 注意力後端
|
||||||
@@ -196,6 +197,16 @@ def main():
|
|||||||
print(f">> [Error] Task {idx} 缺少前置 pt 檔案。")
|
print(f">> [Error] Task {idx} 缺少前置 pt 檔案。")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
# 檢查所有 result3_video/audio_*.pt 是否已存在,若全部存在則跳過整個 Step 3
|
||||||
|
all_latents_exist = all(
|
||||||
|
os.path.exists(f"result3_video_{idx:02d}.pt") and os.path.exists(f"result3_audio_{idx:02d}.pt")
|
||||||
|
for idx in enabled_ids
|
||||||
|
)
|
||||||
|
if all_latents_exist:
|
||||||
|
print(">> [SKIP] 所有 result3_video/audio_*.pt 已存在,跳過 Step 3。")
|
||||||
|
print(f"\n========== [REF2VA STAGE 3] 完成 {len(enabled_ids)}/{len(enabled_ids)} 個任務 (全部跳過) ==========")
|
||||||
|
return
|
||||||
|
|
||||||
torch.cuda.empty_cache()
|
torch.cuda.empty_cache()
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
||||||
@@ -324,7 +335,7 @@ def main():
|
|||||||
num_frames=task.num_frames,
|
num_frames=task.num_frames,
|
||||||
num_inference_steps=steps,
|
num_inference_steps=steps,
|
||||||
seed=seed,
|
seed=seed,
|
||||||
**({'guidance_scale': 1.0} if use_turbo_guidance else {}),
|
**({'cfg_scale': 1.0} if use_turbo_guidance else {}),
|
||||||
)
|
)
|
||||||
|
|
||||||
# --- 任務完成:抓取本次任務的 VRAM 峰值 ---
|
# --- 任務完成:抓取本次任務的 VRAM 峰值 ---
|
||||||
|
|||||||
Reference in New Issue
Block a user