chore: update output filename format to 2-digit padding (%02d) for all ref2va steps

This commit is contained in:
2026-10-12 21:44:31 +08:00
parent a4fee2d646
commit 2d92745d0c
4 changed files with 21 additions and 21 deletions
+2 -2
View File
@@ -22,7 +22,7 @@ torch.backends.cuda.enable_math_sdp(False) # 關閉最吃顯存的原生 Math
→ 回傳 {"ref_blocks", "ref_visual_anchor", "ref_audio_anchor"}
注意: process 會 pop 掉每個 block 的 visual_clean (已併入 anchor),
所以 ref_blocks 落盤時只剩 metadata + prepared_image。
3. 落盤 result1_ref_{idx}.pt:
3. 落盤 result1_ref_{idx:02d}.pt:
- ref_blocks: 每個 block {kind, latent_t, latent_h, latent_w,
prepared_image(PIL), ref_audio_t}
- ref_visual_anchor: DiT 條件錨點 (加噪後的 rows), step3 replay
@@ -226,7 +226,7 @@ def main():
print(f"\n[STOP] 偵測到 .stop。進度 {last_completed_idx} 已存至 .restart。")
return
save_name = f"result1_ref_{idx}.pt"
save_name = f"result1_ref_{idx:02d}.pt"
if os.path.exists(save_name):
print(f">> [SKIP] Task {idx} 已有 {save_name}。")
last_completed_idx = idx
+6 -6
View File
@@ -15,7 +15,7 @@ processor/tokenizer (幾 MB, 非模型權重)。
不載入 DiT / video VAE / audio VAE。
每個任務 (全部 N 個視頻在這次載入中一次跑完, text encoder 只載入一次):
1. 讀 step1 落盤的 result1_ref_{idx}.pt → ref_blocks (含 prepared_image)
1. 讀 step1 落盤的 result1_ref_{idx:02d}.pt → ref_blocks (含 prepared_image)
2. 直接呼叫 pipeline 內建的 MiniMaxH3Unit_PromptEmbedder.process
(ref2va 主路徑:
preprocess_ref_blocks → image_token_counts(processor, prepared_images)
@@ -25,7 +25,7 @@ processor/tokenizer (幾 MB, 非模型權重)。
⚠️ 不能走 __call__ 的 text_embedding 快速路徑 (那會回全 1 的 tags,
DiT 的 ADALN 靠 0/1 混合 tags 區分 text/vision token)。
3. 落盤 result2_text_{idx}.pt: {hidden, text_token_tags}
3. 落盤 result2_text_{idx:02d}.pt: {hidden, text_token_tags}
單權重策略: 任一時刻 DRAM/VRAM 只有 text encoder 一個權重。
下一階段: ref2va_step3.py (DiT 去噪, replay 本步的 hidden + tags)
@@ -91,8 +91,8 @@ def main():
# 上游檢查
for idx in enabled_ids:
if not os.path.exists(f"result1_ref_{idx}.pt"):
print(f">> [Error] Task {idx} 缺少 result1_ref_{idx}.pt, 請先執行 step1。")
if not os.path.exists(f"result1_ref_{idx:02d}.pt"):
print(f">> [Error] Task {idx} 缺少 result1_ref_{idx:02d}.pt, 請先執行 step1。")
sys.exit(1)
torch.cuda.empty_cache()
@@ -161,7 +161,7 @@ def main():
print(f"\n[STOP] 偵測到 .stop。進度 {last_completed_idx} 已存至 .restart。")
return
save_name = f"result2_text_{idx}.pt"
save_name = f"result2_text_{idx:02d}.pt"
if os.path.exists(save_name):
print(f">> [SKIP] Task {idx} 已有 {save_name}。")
last_completed_idx = idx
@@ -173,7 +173,7 @@ def main():
print(f">> [Error] Task {idx} prompt 為空。")
sys.exit(1)
data = torch.load(f"result1_ref_{idx}.pt", weights_only=False)
data = torch.load(f"result1_ref_{idx:02d}.pt", weights_only=False)
ref_blocks = data["ref_blocks"]
print(f"\n>> [Task {idx}] 編碼 prompt ({len(ref_blocks)} 個 ref blocks)...")
print(f" Prompt: {prompt[:60]}...")
+8 -8
View File
@@ -144,12 +144,12 @@ class SaveLatentVideoVAE(torch.nn.Module):
self.idx = idx
def decode_video(self, *args, **kwargs):
torch.save({"args": move_to_cpu(args), "kwargs": move_to_cpu(kwargs)}, f"result3_video_{self.idx}.pt")
torch.save({"args": move_to_cpu(args), "kwargs": move_to_cpu(kwargs)}, f"result3_video_{self.idx:02d}.pt")
latents = args[0]
# latent [1,24,T,H',W'] -> pixel [1,3,T_dec,H,W]
T, H2, W2 = int(latents.shape[2]), int(latents.shape[3]), int(latents.shape[4])
T_dec = (T - 2) // 5 * 17 + 5
print(f">> [SaveLatentVideoVAE] 已攔截最終 decode -> result3_video_{self.idx}.pt")
print(f">> [SaveLatentVideoVAE] 已攔截最終 decode -> result3_video_{self.idx:02d}.pt")
return torch.zeros((1, 3, T_dec, H2 * 16, W2 * 16))
def decode(self, *args, **kwargs):
@@ -161,11 +161,11 @@ class SaveLatentAudioVAE(torch.nn.Module):
self.idx = idx
def decode_audio(self, *args, **kwargs):
torch.save({"args": move_to_cpu(args), "kwargs": move_to_cpu(kwargs)}, f"result3_audio_{self.idx}.pt")
torch.save({"args": move_to_cpu(args), "kwargs": move_to_cpu(kwargs)}, f"result3_audio_{self.idx:02d}.pt")
latents = args[0]
# latent [2,32,Ta] (40Hz) -> waveform [2, Ta*800] (32kHz)
Ta = int(latents.shape[-1])
print(f">> [SaveLatentAudioVAE] 已攔截最終 decode -> result3_audio_{self.idx}.pt")
print(f">> [SaveLatentAudioVAE] 已攔截最終 decode -> result3_audio_{self.idx:02d}.pt")
return torch.zeros((2, Ta * 800))
def decode(self, *args, **kwargs):
@@ -180,7 +180,7 @@ def main():
enabled_ids = get_enabled_tasks()
for idx in enabled_ids:
if not os.path.exists(f"result1_ref_{idx}.pt") or not os.path.exists(f"result2_text_{idx}.pt"):
if not os.path.exists(f"result1_ref_{idx:02d}.pt") or not os.path.exists(f"result2_text_{idx:02d}.pt"):
print(f">> [Error] Task {idx} 缺少前置 pt 檔案。")
sys.exit(1)
@@ -261,7 +261,7 @@ def main():
# 檔案存在即跳過 (與 step1/step2 一致): 已產出 result3 latent 的 task
# 不再重跑。這樣「只重跑單一 task」(刪掉該 task 的 result3 檔) 時,
# 其餘 task 會自動跳過, 不需要靠 .restart 計數器或改 config。
if os.path.exists(f"result3_video_{idx}.pt") and os.path.exists(f"result3_audio_{idx}.pt"):
if os.path.exists(f"result3_video_{idx:02d}.pt") and os.path.exists(f"result3_audio_{idx:02d}.pt"):
print(f">> [SKIP] Task {idx} 已有 result3_video/audio latent。")
last_completed_idx = idx
continue
@@ -291,9 +291,9 @@ def main():
print(f" 起始 Allocated VRAM: {vram_start:.2f} GB (預期 < 0.10 GB)")
print(f"==================================================")
ref_data = torch.load(f"result1_ref_{idx}.pt", weights_only=False)
ref_data = torch.load(f"result1_ref_{idx:02d}.pt", weights_only=False)
ref_unit.data = ref_data
pipe.text_encoder = ReplayTextEncoder(f"result2_text_{idx}.pt")
pipe.text_encoder = ReplayTextEncoder(f"result2_text_{idx:02d}.pt")
pipe.video_vae = SaveLatentVideoVAE(idx)
pipe.audio_vae = SaveLatentAudioVAE(idx)
+5 -5
View File
@@ -124,8 +124,8 @@ def run_pre_dummy_test(pipe, video_vae, audio_vae, fps):
dummy_out_path = os.path.join(OUTPUT_DIR, f"dummy_test_{target_w}x{target_h}_{target_frames}f.mp4")
video_pt_0 = "result3_video_0.pt"
audio_pt_0 = "result3_audio_0.pt"
video_pt_0 = "result3_video_00.pt"
audio_pt_0 = "result3_audio_00.pt"
if os.path.exists(video_pt_0) and os.path.exists(audio_pt_0):
print(f">> [Dummy] 發現 {video_pt_0},沿用其結構克隆全 0 特徵張量...")
@@ -241,15 +241,15 @@ def main():
done = 0
for task_idx in enabled_ids:
task = TASK_REGISTRY[task_idx]
out_path = os.path.join(OUTPUT_DIR, f"ref2va_output_{task_idx}_l0.mp4")
out_path = os.path.join(OUTPUT_DIR, f"ref2va_output_{task_idx:02d}_l0.mp4")
if os.path.exists(out_path):
print(f"\n>> [SKIP] Task {task_idx}: 輸出已存在: {out_path}")
done += 1
continue
video_pt = f"result3_video_{task_idx}.pt"
audio_pt = f"result3_audio_{task_idx}.pt"
video_pt = f"result3_video_{task_idx:02d}.pt"
audio_pt = f"result3_audio_{task_idx:02d}.pt"
if not os.path.exists(video_pt) or not os.path.exists(audio_pt):
print(f">> [Skip] 缺少 {video_pt} 或 {audio_pt}")