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

[Model] Add support for Qwen2 for embeddings #5611

Closed
wants to merge 5 commits into from

Conversation

mgoin
Copy link
Member

@mgoin mgoin commented Jun 17, 2024

FIX #5600
FIX #5827
FIX #6015

This works for ssmits/Qwen2-7B-Instruct-embed-base

>>> from vllm import LLM
>>> model = LLM("ssmits/Qwen2-7B-Instruct-embed-base")
>>> outputs = model.encode("Hello!")
Processed prompts: 100%|█████████████████████████████████████| 1/1 [00:00<00:00,  2.10it/s, est. speed input: 0.00 toks/s, output: 0.00 toks/s]
>>> outputs
[EmbeddingRequestOutput(request_id='0', outputs=EmbeddingOutput(embedding=3584), prompt_token_ids=[9707, 0], finished=True)]

However, this doesn't work for Alibaba-NLP/gte-Qwen2-7B-instruct since its config still says it is a Qwen2ForCausalLM, where we have been relying on embedding models to be of the type XModel: https://huggingface.co/Alibaba-NLP/gte-Qwen2-7B-instruct/blob/main/config.json

@mgoin mgoin changed the title [Model} Add support for Qwen2 for embeddings [Model] Add support for Qwen2 for embeddings Jun 17, 2024
@prattcmp
Copy link

+1 this would be great

@mgoin mgoin linked an issue Jun 20, 2024 that may be closed by this pull request
@waters222
Copy link

I think ppl can edit the config file to change it from Qwen2ForCausalLM to Qwen2Model

@mgoin mgoin marked this pull request as ready for review June 25, 2024 17:50
@Semihal
Copy link

Semihal commented Jul 4, 2024

Should we expect a merge in the near future?

@mgoin
Copy link
Member Author

mgoin commented Jul 4, 2024

@Semihal thanks for the reminder! I just merged with main so if it is green we can land

@0xWelt
Copy link

0xWelt commented Jul 8, 2024

Can you pass "pytest tests/models/test_embedding.py"? I got "AssertionError: Not all values are within 0.01 of 1.0" with model "ssmits/Qwen2-7B-Instruct-embed-base" .

@mgoin
Copy link
Member Author

mgoin commented Jul 8, 2024

@Nickydusk No it does not pass, it seems there is a correctness issue between the implementations so this is not ready to land. This is low on my priority to investigate so if anyone would like to take over this PR, feel welcome and ping me for review.

@starmemda
Copy link

@youkaichao @WoosukKwon @zhuohan123 @simon-mo @DarkLight1337
Could you please check this PR and merge it? gte-Qwen2 is a Qwen2ForCausalLM embedding model which is quite efficient.

if name.startswith(prefix):
name = name[len(prefix):]

if "rotary_emb.inv_freq" in name:

Choose a reason for hiding this comment

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

need to add following line for loading model Alibaba-NLP/gte-Qwen2-7B-instruct

if "lm_head.weight" in name:
  continue

@0xWelt
Copy link

0xWelt commented Jul 10, 2024

@mgoin @prattcmp @waters222 @Semihal @starmemda

I have opened a new PR #6282 to directly support 'gte-Qwen2' embedding models without modifying its Qwen2ForCausalLM architecture. We can collaborate on reviewing the code and merge it in the near future.

@ybbz
Copy link

ybbz commented Aug 1, 2024

Can this feature be merged?

@mgoin
Copy link
Member Author

mgoin commented Aug 1, 2024

@ybbz The output is not correct/matching HF, as seen in the test. Anybody is welcome to debug it!

Copy link

github-actions bot commented Nov 1, 2024

This pull request has been automatically marked as stale because it has not had any activity within 90 days. It will be automatically closed if no further activity occurs within 30 days. Leave a comment if you feel this pull request should remain open. Thank you!

@github-actions github-actions bot added the stale Over 90 days of inactivity label Nov 1, 2024
Copy link

mergify bot commented Nov 1, 2024

This pull request has merge conflicts that must be resolved before it can be
merged. @mgoin please rebase it. https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify bot added the needs-rebase label Nov 1, 2024
@DarkLight1337
Copy link
Member

Ping in case you forgot about this @mgoin . It should be quite straightforward to add embedding models now.

@github-actions github-actions bot removed the stale Over 90 days of inactivity label Nov 4, 2024
@github-actions github-actions bot added the unstale Recieved activity after being labelled stale label Nov 4, 2024
@DarkLight1337
Copy link
Member

Closing as superseded by #10184

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-rebase unstale Recieved activity after being labelled stale
Projects
None yet
9 participants