perf: implement page cache dropping for large weight files to prevent DRAM double-occupancy
This commit is contained in:
@@ -80,6 +80,18 @@ def move_to_cpu(obj):
|
||||
return obj
|
||||
|
||||
|
||||
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 2] Text Encoder 編碼 Prompt (單權重版) ==========")
|
||||
print(f">> [Config] 專案配置: {config_path}")
|
||||
@@ -128,6 +140,10 @@ def main():
|
||||
vram_limit=18.0,
|
||||
)
|
||||
|
||||
# 釋放權重檔的 Page Cache,避免 DRAM 雙倍佔用
|
||||
text_encoder_path = os.path.join(MODELS_DIR, "text_encoders/minimax-h3-text-encoder-nf4.safetensors")
|
||||
drop_file_cache(text_encoder_path)
|
||||
|
||||
# pipeline 內建的 PromptEmbedder (ref2va 主路徑邏輯與官方完全一致)
|
||||
text_unit = MiniMaxH3Unit_PromptEmbedder()
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user