-
Notifications
You must be signed in to change notification settings - Fork 6k
[docs] Quantization + torch.compile + offloading #11703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for starting this. Will get you the numbers.
Code: https://gist.github.com/sayakpaul/0db9d8eeeb3d2a0e5ed7cf0d9ca19b7d Worth mentioning:
|
``` | ||
|
||
</hfoption> | ||
<hfoption id="group offloading"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it might be better demonstrated with a more compute heavy model like Wan? This way, we can show the actual benefits of group offloading.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, could you get me the updated numbers for Wan with quantization/group offloading/torch.compile please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's okay to have the Flux numbers but for the sake of code and discussions, we could have Wan.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok, don't worry about getting the Wan numbers then!
|
||
Offloading strategies move not currently active layers or models to the CPU to avoid increasing GPU memory. These strategies can be combined with quantization and torch.compile to balance inference speed and memory usage. | ||
|
||
Refer to the [Compile and offloading quantized models](./speed-memory-optims) guide for more details. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think #11731 can be resolved in this PR where I make a note that offloading can be combined with quantization and torch.compile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added your layerwise casting note in here as well :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah feel free to close those :)
pipeline.transformer.enable_group_offload( | ||
onload_device=onload_device, | ||
offload_device=offload_device, | ||
offload_type="block_level", | ||
num_blocks_per_group=4 | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use these args when a component is quantized with bitsandbytes
to mitigate device mismatch issues:
But I am curious. Were you able to run the code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It did not haha 🙃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some more comments. LMK if they make sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let' go!
from diffusers import DiffusionPipeline | ||
from diffusers.quantizers import PipelineQuantizationConfig | ||
|
||
torch._dynamo.config.cache_size_limit = 1000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
torch._dynamo.config.cache_size_limit = 1000 | |
torch._dynamo.config.cache_size_limit = 1000 | |
torch._dynamo.config.capture_dynamic_output_shape_ops = True | |
from diffusers.quantizers import PipelineQuantizationConfig | ||
from transformers import UMT5EncoderModel | ||
|
||
torch._dynamo.config.cache_size_limit = 1000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same suggestion as above.
Follows up on #11670 and #11672 to document combinations of quantization, torch.compile, and offloading.