[Optimization] Use torch.bfloat16 on cuda systems #5410
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.
What type of PR is this? (check all applicable)
Have you discussed this change with the InvokeAI team?
Have you updated all relevant documentation?
Description
On CUDA systems,
torch.bfloat16
is supposed to be ~25% faster thantorch.float16
according to this article: https://pytorch.org/blog/accelerating-generative-ai-3/. This small PR substitutes bfloat16 for float16 when half-precision is requested on a cuda system.Unfortunately I don't see any change in speed in my benchmarking. The article says that the speedup is GPU dependent, so perhaps others will have more luck (I'm using an RTX 4070).
Related Tickets & Documents
QA Instructions, Screenshots, Recordings
Merge Plan
Can merge when tested and approved. Please try on different GPUs and OSs. Should make no difference on Macs.
Added/updated tests?
[optional] Are there any post deployment tasks we need to perform?