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

feat: add initial qwen2.5-vl model and test #2971

Merged
merged 6 commits into from
Feb 19, 2025
Merged

Conversation

drbh
Copy link
Collaborator

@drbh drbh commented Jan 30, 2025

This PR adds support for qwen2.5-vl models and currently loads the weights and supports reasonable responses. Opening early for exposure and any feedback.

These changes are dependent on #2943 and must be rebased/merged after it is merged

items

  • allow qwen2_5_vl models to load in server/router
  • add updated vision model
    • adjust weight names/loading
    • adjust config naming
    • RMSNorm in vision blocks
    • update MLP for up/gate/down
    • add fullatt_block_indexes
  • validation
    • add tests
    • add snapshots
    • tests more outputs locally for edge cases
    • inspect logits for correctness
    • ensure mrope is producing correct ids

small reproducible example:

text-generation-launcher --model-id Qwen/Qwen2.5-VL-3B-Instruct

script

import requests
import json

url = "http://127.0.0.1:3000/generate"
headers = {"Content-Type": "application/json"}
image_urls = [
    "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg",
    "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/tgi/rabbit.png",
]

for image in image_urls:
    query = "Describe the image"
    payload = {
        "inputs": f"<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n<|im_start|>user\n![]({image}){query}<|im_end|>\n<|im_start|>assistant\n",
        "parameters": {"max_new_tokens": 50},
    }
    response = requests.post(url, headers=headers, json=payload)
    print(json.dumps(response.json(), indent=4))

output

{
    "generated_text": "The image showcases the iconic Statue of Liberty in New York City, with the New York City skyline in the background. The statue is a large, green-colored sculpture on a stone pedestal, with the American flag on a flagpole in the foreground. The"
}
{
    "generated_text": "The image depicts a character in a space suit, set in a rocky, desert-like environment with a warm, orange hue. The character is a large, brown, and white rabbit with long, pointed ears and a small, beak-like nose."
}

@drbh drbh force-pushed the add-qwen25vl-support branch from 1adfee4 to e9b5806 Compare January 31, 2025 17:36
@HuggingFaceDocBuilderDev

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.

@drbh drbh force-pushed the add-qwen25vl-support branch from 17c93ff to 1f58577 Compare February 4, 2025 20:06
@drbh drbh marked this pull request as ready for review February 5, 2025 15:43
Narsil
Narsil previously approved these changes Feb 18, 2025
Copy link
Collaborator

@Narsil Narsil left a comment

Choose a reason for hiding this comment

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

LGTM!

Comment on lines +16 to +25
transformers = python-super.transformers.overrideAttrs (
_: _: {
src = final.fetchFromGitHub {
owner = "huggingface";
repo = "transformers";
rev = "8d73a38606bc342b370afe1f42718b4828d95aaa";
hash = "sha256-MxroG6CWqrcmRS+eFt7Ej87TDOInN15aRPBUcaycKTI=";
};
}
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we still need that with 4.49 release ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this should be able to be removed with 4.49

}


class Qwen2_5_VLProcessor(ProcessorMixin):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this not defined in transformers ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this was added in 4.49 so can be be removed with the update too

Comment on lines 433 to 436
if (
self.model.config.model_type == "qwen2_vl"
or self.model.config.model_type == "qwen2_5_vl"
):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (
self.model.config.model_type == "qwen2_vl"
or self.model.config.model_type == "qwen2_5_vl"
):
if self.model.config.model_type in {"qwen2_vl", "qwen2_5_vl"}:

Fixing the chatbot for you :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

wish I could blame it on a bot 😅

thanks!

Comment on lines 239 to 242
if (
config.model_type == "qwen2_vl"
or config.model_type == "qwen2_5_vl"
):
Copy link
Collaborator

Choose a reason for hiding this comment

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

NIT: Simpler condition.

@Narsil Narsil merged commit d6a0c67 into main Feb 19, 2025
21 checks passed
@Narsil Narsil deleted the add-qwen25vl-support branch February 19, 2025 11:38
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.

3 participants