google / RB-Modulation

Official code for "RB-Modulation: Training-Free Personalization of Diffusion Models using Stochastic Optimal Control"
https://rb-modulation.github.io/
Apache License 2.0
318 stars 27 forks source link

Add 'low_vram' flag to optimize VRAM usage in rb-modulation.ipynb and fix typo in README.md #1

Closed ChoYongchae closed 3 weeks ago

ChoYongchae commented 3 weeks ago

Thanks for the research and code sharing. I’m submitting a PR to help the notebook run on GPUs with lower VRAM.

Changes:

  1. Add 'low_vram' flag to rb-modulation.ipynb:

    • Introduce flag to optimize the notebook for systems with 24GB of VRAM.
    • Approaches:
      • Offload models.generator to CPU during the plugin RB-modulation stage
      • Offload all modules except generator and previewer during the VRAM-intensive sampling stage
  2. (Minor) Fix typo in README.md:

    • Correct ffty to ftfy.

Benefits:

Disclaimer:

Please review the changes and let me know if any further adjustments are needed.

google-cla[bot] commented 3 weeks ago

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

tema7707 commented 3 weeks ago

Thank you, that's very helpful! Could you also move the SAM model in the Composition block to the CPU? It doesn't need to be stored on the CUDA, and I'm encountering an OOM error without this change.

if low_vram:
    # The sampling process uses more vram, so we offload everything except two modules to the cpu.
    models_to(sam_model, device="cpu")
    models_to(sam_model.sam, device="cpu")
    models_to(models_rbm, device="cpu", excepts=["generator", "previewer"])
ChoYongchae commented 3 weeks ago

Thank you, @tema7707! Your suggestion has helped confirm that an additional 3GB of VRAM used by SAM can be saved. I have included this change in the fix.

LituRout commented 3 weeks ago

Thanks for the PR.