Skip to content

Conversation

blueyo0
Copy link
Contributor

@blueyo0 blueyo0 commented Sep 10, 2024

When I attempt to use Gemma2-2b with bitsandbytes quantization, I encounter the error message: AttributeError: Model Gemma2ForCausalLM does not support BitsAndBytes quantization yet. Also, similar issues #6068 and #6186 are reported for Gemma2-9b and Gemma2-27b.

The root cause is that the essential mapping bitsandbytes_stacked_params_mapping is missing in Gemma2.

This PR aims to enable support for bitsandbytes quantization in Gemma2 by simply adding the bitsandbytes_stacked_params_mapping.

I have tested this PR with the model unsloth/gemma-2-27b-it-bnb-4bit, and it works well.

Here's my test scripts:

from vllm.entrypoints.llm import LLM, SamplingParams
import torch

prompts = [
    "Hello, my name is",
    "The president of the United States is",
    "The capital of France is",
    "The future of AI is",
]
sampling_params = SamplingParams(temperature=0.8, top_p=0.95)

llm = LLM(model="unsloth/gemma-2-2b-it-bnb-4bit", 
          dtype=torch.bfloat16, 
          trust_remote_code=True, 
          quantization="bitsandbytes", 
          load_format="bitsandbytes", 
          enforce_eager=True)


outputs = llm.generate(prompts, sampling_params)

# Print the outputs.
for output in outputs:
    prompt = output.prompt
    generated_text = output.outputs[0].text
    print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")

With this PR, I can get the following response:

Prompt: 'Hello, my name is', Generated text: " Liam. \n\nI'm an AI assistant, but I don't"
Prompt: 'The president of the United States is', Generated text: ' considered to be the leader of the free world.\n\nThis statement is true,'
Prompt: 'The capital of France is', Generated text: ' **Paris**. 🇫🇷 \n'
Prompt: 'The future of AI is', Generated text: " exciting, and there are so many possibilities! Here's a glimpse of what"

From my end, I believe this PR works for all scales of Gemma2 models.

FIX #6068

BEFORE 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:

  • We adhere to Google Python style guide and Google C++ style guide.
  • Pass all linter checks. Please use format.sh to format your code.
  • The code need to be well-documented to ensure future contributors can easily understand the code.
  • Include sufficient tests to ensure the project to stay correct and robust. This includes both unit tests and integration tests.
  • Please add documentation to 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:

  • After the PR is submitted, the PR will be assigned to a reviewer. Every reviewer will pick up the PRs based on their expertise and availability.
  • After the PR is assigned, the reviewer will provide status update every 2-3 days. If the PR is not reviewed within 7 days, please feel free to ping the reviewer or the vLLM team.
  • After the review, the reviewer will put an 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.
  • Please respond to all comments within a reasonable time frame. If a comment isn't clear or you disagree with a suggestion, feel free to ask for clarification or discuss the suggestion.

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!

Copy link

👋 Hi! Thank you for contributing to the vLLM project.
Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can do one of these:

  • Add ready label to the PR
  • Enable auto-merge.

🚀

@blueyo0
Copy link
Contributor Author

blueyo0 commented Sep 10, 2024

@mgoin @jeejeelee Would you mind reviewing this PR when you have some free time? Please let me know if any tests are missing for this PR. I would greatly appreciate your feedback.

Copy link
Member

@mgoin mgoin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, this looks straightforward to me. Please run ./format.sh to solve the linter issue

@blueyo0
Copy link
Contributor Author

blueyo0 commented Sep 11, 2024

Hi, fastcheck seems good. Maybe we can test with full CI and try to merge it? 😄

@mgoin mgoin added the ready ONLY add when PR is ready to merge/full CI is needed label Sep 11, 2024
@WoosukKwon WoosukKwon merged commit 1bf2dd9 into vllm-project:main Sep 12, 2024
69 checks passed
Alvant pushed a commit to compressa-ai/vllm that referenced this pull request Oct 26, 2024
LeiWang1999 pushed a commit to LeiWang1999/vllm-bitblas that referenced this pull request Mar 26, 2025
Signed-off-by: LeiWang1999 <leiwang1999@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready ONLY add when PR is ready to merge/full CI is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Usage]: how to initiate the gemma2-27b with a 4-bit quantization?
3 participants