Skip to content
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

[Quant] Add SupportsQuant to phi3 and clip #13104

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kylesayrs
Copy link
Contributor

@kylesayrs kylesayrs commented Feb 11, 2025

Purpose

  • Introduce SupportsQuant which
    • Initializes the quant_config attribute and updates the quant_config with the relevant packed_modules_mapping
    • Marks a model as being capable of supporting quantized inference
    • In the future, will check if a model has been correctly defined, for example if prefixes and quant_configs have been passed correctly
  • This mixin will replace the configure_quant_config function after it has been added to a sufficient number of models
  • These changes reflect the issue that configure_quant_config assumes that all packed_modules_mappings will be declared prior to initialization. In reality, some models are submodels of each other, so their mappings can only be determined at init time.
    • Using a mixin which updates after class is initialized but the mapping before the parameters init guarantees that the config is up to date w.r.t. mappings before the parameters init

Changes

  • Implement SupportsQuant with packed_modules_mapping updating and setting the quant_config attribute
  • Add SupportsQuant to Phi3 and Clip models in order to demonstrate usefulness
  • Narrow type hint on QuantizationConfig.packed_modules_mapping

Follow ups

  • Add SupportsQuant mixin to all models which support quantization
  • Add prefix validation checking to SupportsQuant which is checked at runtime similar to LoRA
  • Remove configure_quant_config after models have been updated

Testing

  • This example used to fail because the Clip submodel has specific packed module mappings which were not being passed to the quant config
phi3_example.py
from vllm.assets.image import ImageAsset
from vllm import LLM, SamplingParams

# prepare model
llm = LLM(
    model="neuralmagic/Phi-3-vision-128k-instruct-W4A16-G128",
    trust_remote_code=True,
    max_model_len=4096,
    max_num_seqs=2,
)

# prepare inputs
question = "What is the content of this image?"
inputs = {
    "prompt": f"<|user|>\n<|image_1|>\n{question}<|end|>\n<|assistant|>\n",
    "multi_modal_data": {
        "image": ImageAsset("cherry_blossom").pil_image.convert("RGB")
    },
}

# generate response
print("========== SAMPLE GENERATION ==============")
outputs = llm.generate(inputs, SamplingParams(temperature=0.2, max_tokens=64))
print(f"PROMPT  : {outputs[0].prompt}")
print(f"RESPONSE: {outputs[0].outputs[0].text}")
print("==========================================")

Copy link

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

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 either: Add ready label to the PR or enable auto-merge.

🚀

Copy link
Collaborator

@robertgshaw2-redhat robertgshaw2-redhat left a comment

Choose a reason for hiding this comment

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

I like this idea, but why does it only apply to these two models?

@@ -441,3 +442,16 @@ def supports_cross_encoding(
model: Union[Type[object], object],
) -> Union[TypeIs[Type[SupportsCrossEncoding]], TypeIs[SupportsCrossEncoding]]:
return is_pooling_model(model) and _supports_cross_encoding(model)


class SupportsQuant:
Copy link
Collaborator

Choose a reason for hiding this comment

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

why does it only apply to these two models?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Follow ups

  • Add SupportsQuant mixin to all models which support quantization

This PR just introduces the mixin, separate PRs will be dedicated to integrating the mixin with model-specific tests

Signed-off-by: Kyle Sayers <[email protected]>
@kylesayrs kylesayrs changed the title Add SupportsQuant to phi3 and clip [Quant] Add SupportsQuant to phi3 and clip Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants