-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Add cuda kernel support for GGUF inference #11869
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
Signed-off-by: Isotr0py <[email protected]>
Signed-off-by: Isotr0py <[email protected]>
Signed-off-by: Isotr0py <[email protected]>
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. |
def forward(self, inputs: torch.Tensor): | ||
if ops is not None and self.weight.is_cuda and inputs.is_cuda: | ||
return self.forward_cuda(inputs) | ||
return self.forward_native(inputs) |
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.
This should be fairly safe as long as we get the same values (upto some tolerance) on both the native and kernels' variants.
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.
Yes, the kernels' variants have been tested in vLLM's kernel tests CI compared with numpy implemented dequantize implementation. (https://github.com/vllm-project/vllm/blob/110df74332785ee749af47c5a3eb634d216b8f3b/tests/kernels/quantization/test_gguf.py#L67-L83)
A comparision about
|
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.
Changes look good to me 👍🏽. Thank you @Isotr0py.
For testing purposes would it be possible to configure whether to use CUDA kernels via an env variable?
And could we add a standalone test to
https://github.com/huggingface/diffusers/blob/15d50f16f2320b669c77eae2034b6612c22bd2ef/tests/quantization/gguf/test_gguf.py
that just compares native forward vs kernel forward using a dummy tensor similar to vLLM?
What does this PR do?
dequantize
ops is used currently, because the MMQ/MMVQ implementation is inefficient with diffusers' 3-dimensional batching (it's designed for vLLM's contiguous batching at first)Test Code
Speed comparison
Native (6.39s/it) vs CUDA kernel (5.32s/it), about 10% speed-up
Before submitting
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.