GeneFace++ 对 图像分辨率非常敏感。
# 原配置
image_size: 512
# 改为
image_size: 256 # 或 384✅ 效果:
batch_size: 1GeneFace++ 支持 AMP(Automatic Mixed Precision):
--fp16
# 或
--precision 16✅ 优点:
⚠️ 注意:
export PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:128或:
torch.cuda.empty_cache()GeneFace++ 通常包含:
✅ 建议:
for p in audio_encoder.parameters():
p.requires_grad = Falseaccumulate_grad_batches: 4
batch_size: 1✅ 效果:
如果代码支持:
torch.utils.checkpoint.checkpoint(fn, *args)✅ 用 时间换显存
推理时:
with torch.no_grad():
output = model(input)并关闭:
GeneFace++ 的 attention 很吃显存:
pip install xformers然后在模型中启用:
enable_xformers=True✅ 效果:
num_samples: 64 # 原 128
num_importance: 32适合 多卡 / 80G 显存仍不够 的情况。
deepspeed --num_gpus=1 train.py --deepspeed ds_config.json✅ 优势:
image_size: 256
batch_size: 1
fp16: true
xformers: true
num_samples: 64image_size: 256
batch_size: 1
accumulate_grad_batches: 4
fp16: true
freeze_audio_encoder: truetorch.cuda.empty_cache()| 问题 | 原因 | 解决 |
|---|---|---|
| OOM 在第一个 step | 分辨率太大 | 降 image_size |
| OOM 在 5–10 步后 | 显存碎片 | empty_cache() |
| NaN loss | FP16 溢出 | 换 BF16 |
| 推理 OOM | attention 未优化 | xformers |
如果你愿意,可以告诉我:
我可以直接帮你: