-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
[Core] Support loading GGUF model #5191
Conversation
Hi @Isotr0py, I can help with this PR if needed. I've already done some work implementing all GGUF quants + related kernels in vLLM. Let me know if you'd like to collaborate on this! |
@AlpinDale Thanks! I'm glad to push this forward by adding quants kernels! I'm not familiar with the quantization in And about this, I have several questions/ideas about the kernel implements:
|
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.
@Isotr0py I'm fine with the initial support being just naive dequantization, as long as we change this to dequant at runtime for each forward pass so there is a memory usage benefit. I think it is worth starting with the CUDA kernels for Linear modules first so it is easily accessible to users, then tackling the CPU implementation. The interesting starting point IMO is supporting the main quantization methods i.e. Q4
, Q8
, and especially the new IQ
methods.
@AlpinDale it would be great if you could help get this into a similar state as you've implemented before!
Great job @Isotr0py, sorry I was away for a while. Would it be better to directly port the dequantization kernels to vLLM instead of relying on the transformers integration? They seem to have only the simple quants, and I don't imagine they're very performant. Aphrodite Engine already implements GGUF loading, so we can pull the kernels directly here if needed. Please see here for the kernels, and here for the GGUF linear method. One of the biggest problems I've had with GGUF (and exllamav2) are the quantized embeddings. If we can find an elegant solution to that, it'd do us a lot of good. GGUF quantizes both input and output embeddings, I believe. For that, please check out the linear.py and the vocab_parallel_embedding.py. Let me know how I can help with the integration. Cheers! |
@AlpinDale I agree that we can directly port the Aphrodite Engine's dequantization kernels to vLLM. But I think we can also keep the transformers integration dequantization for CPU backend until we add the optimized kernel for CPU. (If I haven't missed something, Aphrodite Engine should only have CUDA kernels implemented for GGUF, right?) IMO, I think vocab_parallel_embedding.py in Aphrodite Engine has been a good enough solution for quantized embeddings. I also wonder if we can optimize the kernel's ops for merged linear, because we need to unpack the quantized weights in merged linear layer, collect and re-pack the outputs currently. (If this can be solved, we can support many models without modifying their implementation!) (I will update this PR once I finish the work in another PR.) |
Yeah, the kernels are CUDA only (and they don't work with ROCm for now). It'd be exciting if this PR can be merged with the proper dequant kernels, so I can switch over my implementation to this too. GGUF in particular has made catching up with vLLM upstream a nightmare for me :) Are you on slack or discord? We can discuss this in further depth if you'd like. |
@AlpinDale I think we can discuss this further on discord. How I can communicate with you on discord? |
My username is |
OK, I have added a check to raise exception for |
Thanks for the nice work @Isotr0py and @AlpinDale - let's keep it up with improvements! |
Nice update. I was wondering how I can load my .gguf model directly from my local directory with this new update.
Error: Thanks |
testing this file https://github.com/vllm-project/vllm/blob/main/examples/gguf_inference.py also gave a similar issue: OSError: It looks like the config file at '/root/.cache/huggingface/hub/models--TheBloke--TinyLlama-1.1B-Chat-v1.0-GGUF/snapshots/52e7645ba7c309695bec7ac98f4f005b139cf465/tinyllama-1.1b-chat-v1.0.Q4_0.gguf' is not a valid JSON file. |
@inuwamobarak I have the same message |
Yes @kalebeasilvadev I prefer to load my model locally as .gguf file but it seems not to work. I saw this commit from June but it gave the same JSON error too:
OSError: It looks like the config file at '/content/tinyllama-1.1b-chat-v0.3.Q2_K.gguf' is not a valid JSON file. |
@inuwamobarak @kalebeasilvadev wget https://huggingface.co/TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF/resolve/main/tinyllama-1.1b-chat-v1.0.Q2_K.gguf
vllm serve tinyllama-1.1b-chat-v1.0.Q2_K.gguf --tokenizer TinyLlama/TinyLlama-1.1B-Chat-v1.0 Are you building from source or using the nightly build? This feature is not in a release yet, it didn't make it in 0.5.4 as you can see in the release notes. If you want to try the GGUF support you must build main from source or use the nightly build: export VLLM_VERSION=0.5.4 # vLLM's main branch version is currently set to latest released tag
pip install https://vllm-wheels.s3.us-west-2.amazonaws.com/nightly/vllm-${VLLM_VERSION}-cp38-abi3-manylinux1_x86_64.whl
# You can also access a specific commit
# export VLLM_COMMIT=fd95e026e0f9f50bacf1a63ef419df8bacfc99c0
# pip install https://vllm-wheels.s3.us-west-2.amazonaws.com/${VLLM_COMMIT}/vllm-${VLLM_VERSION}-cp38-abi3-manylinux1_x86_64.whl |
@Isotr0py I changed the code from the function "gguf_quant_weights_iterator" to remove this weight and after that the LLM load and run worked: for tensor in reader.tensors:
if(tensor.name != "rope_freqs.weight"):
weight_type = tensor.tensor_type
name = gguf_to_hf_name_map[tensor.name]
if weight_type.name != "F32":
weight_type_name = name.replace("weight", "qweight_type")
weight_type = torch.tensor(weight_type)
yield weight_type_name, weight_type
for tensor in reader.tensors:
if(tensor.name != "rope_freqs.weight"):
weight = tensor.data
weight_type = tensor.tensor_type
name = gguf_to_hf_name_map[tensor.name]
if weight_type.name != "F32":
name = name.replace("weight", "qweight")
param = torch.tensor(weight)
yield name, param I'm not a specialist in LLM architecture and don't know if this can impact the results, could you evaluate if what I did makes sense? |
Thank you @mgoin it worked now |
@vbiral Thanks for reporting! |
Co-authored-by: Michael Goin <michael@neuralmagic.com>
Has the kernels been verified with ROCm in MI30X machines ? Better to have a micro benchmark datasheet. |
Co-authored-by: Michael Goin <michael@neuralmagic.com>
Co-authored-by: Michael Goin <michael@neuralmagic.com>
Co-authored-by: Michael Goin <michael@neuralmagic.com> Signed-off-by: Alvant <alvasian@yandex.ru>
FIX #1002
Features:
gguf
to requirements.LLaMa
,Mistral
andQwen2
are supported.Some issues:
gguf
installation from source is required.Qwen2
gguf model,gguf
installation from source is required as well.TODO:
Implement dequantizeQ8_0
andQ4_0
tensors during inference instead of pre-dequantize in model loadinggguf
and updatetransformers
in requirements.txtBEFORE SUBMITTING, PLEASE READ THE CHECKLIST BELOW AND FILL IN THE DESCRIPTION ABOVE
PR Checklist (Click to Expand)
Thank you for your contribution to vLLM! Before submitting the pull request, please ensure the PR meets the following criteria. This helps vLLM maintain the code quality and improve the efficiency of the review process.
PR Title and Classification
Only specific types of PRs will be reviewed. The PR title is prefixed appropriately to indicate the type of change. Please use one of the following:
[Bugfix]
for bug fixes.[CI/Build]
for build or continuous integration improvements.[Doc]
for documentation fixes and improvements.[Model]
for adding a new model or improving an existing model. Model name should appear in the title.[Frontend]
For changes on the vLLM frontend (e.g., OpenAI API server,LLM
class, etc.)[Kernel]
for changes affecting CUDA kernels or other compute kernels.[Core]
for changes in the core vLLM logic (e.g.,LLMEngine
,AsyncLLMEngine
,Scheduler
, etc.)[Hardware][Vendor]
for hardware-specific changes. Vendor name should appear in the prefix (e.g.,[Hardware][AMD]
).[Misc]
for PRs that do not fit the above categories. Please use this sparingly.Note: If the PR spans more than one category, please include all relevant prefixes.
Code Quality
The PR need to meet the following code quality standards:
format.sh
to format your code.docs/source/
if the PR modifies the user-facing behaviors of vLLM. It helps vLLM user understand and utilize the new features or changes.Notes for Large Changes
Please keep the changes as concise as possible. For major architectural changes (>500 LOC excluding kernel/data/config/test), we would expect a GitHub issue (RFC) discussing the technical design and justification. Otherwise, we will tag it with
rfc-required
and might not go through the PR.What to Expect for the Reviews
The goal of the vLLM team is to be a transparent reviewing machine. We would like to make the review process transparent and efficient and make sure no contributor feel confused or frustrated. However, the vLLM team is small, so we need to prioritize some PRs over others. Here is what you can expect from the review process:
action-required
label on the PR if there are changes required. The contributor should address the comments and ping the reviewer to re-review the PR.Thank You
Finally, thank you for taking the time to read these guidelines and for your interest in contributing to vLLM. Your contributions make vLLM a great tool for everyone!