Add cuda kernel support for GGUF inference#11869
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. |
| 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.
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.
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
|
DN6
left a comment
There was a problem hiding this comment.
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?
|
@Isotr0py Looks like there are numerical differences between native and kernel output. I added a test to check. It produces a slight difference in the generated output The text in the image is different. I've added an option to disable using kernels |


What does this PR do?
dequantizeops 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.