perf: implement page cache dropping for large weight files to prevent DRAM double-occupancy
This commit is contained in:
+17
-1
@@ -171,6 +171,18 @@ class SaveLatentAudioVAE(torch.nn.Module):
|
||||
def decode(self, *args, **kwargs):
|
||||
return self.decode_audio(*args, **kwargs)
|
||||
|
||||
def drop_file_cache(filepath):
|
||||
"""
|
||||
告知內核不需要快取該檔案的內容,釋放 Page Cache。
|
||||
"""
|
||||
try:
|
||||
with open(filepath, 'rb') as f:
|
||||
fd = f.fileno()
|
||||
os.posix_fadvise(fd, 0, 0, os.POSIX_FADV_DONTNEED)
|
||||
print(f">> [Cache] Dropped page cache for {filepath}")
|
||||
except Exception as e:
|
||||
print(f">> [Cache] Failed to drop cache for {filepath}: {e}")
|
||||
|
||||
def main():
|
||||
print("\n========== [REF2VA STAGE 3] DiT 去噪生成 (ref2va 權重, 單權重版) ==========")
|
||||
|
||||
@@ -213,6 +225,10 @@ def main():
|
||||
vram_limit=14.0,
|
||||
)
|
||||
|
||||
# 釋放權重檔的 Page Cache,避免 DRAM 雙倍佔用
|
||||
dit_path = os.path.join(MODELS_DIR, "diffusion_models/minimax-h3-ref2va-nf4.safetensors")
|
||||
drop_file_cache(dit_path)
|
||||
|
||||
seed = RUN_CONFIG.get("default_seed", 42)
|
||||
|
||||
# 根據每個任務的 steps 決定是否載入 Turbo LoRA
|
||||
@@ -349,4 +365,4 @@ def main():
|
||||
print(f"\n========== [REF2VA STAGE 3] 全部任務完成 ==========")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user