Optimize test files by fixing CPU-offloading usage #8409
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request refactors the code to remove unnecessary calls to
to(torch_device)
andto("cuda")
. These calls were redundant and consumed more memory unnecessarily, and can be safely removed without affecting the code's functionality.There are also comparisons between
output_without_offload
andoutput_with_offload
in the test files. I tried with SD-1.5-fp16 in Colab. After two forward passes (w and w/o offloading), the occupied system RAM is ~5.1 GB. But, if I initialize the pipeline again beforepipeline.enable_sequential_cpu_offload()
, the occupied system RAM is ~2.4 GB. 1-1.5 GB RAM is already occupied by the system initially. This difference is ~0.5 GB forpipeline.enable_model_cpu_offload()
. And I couldn't see a difference on GPU vRAM much. The time cost for adding a second initialization was almost zero. What should be done for these places:diffusers/tests/pipelines/test_pipelines_common.py
Lines 1362 to 1384 in 867a2b0
@sayakpaul @yiyixuxu @DN6