-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Support BERTModel
(first encoder-only
embedding model)
#9056
Conversation
…n't work tho until new modelrunner is finished
…s related to encoder/decoder
nit: This will reduce the number of line changes and make the code look better. Co-authored-by: Woosuk Kwon <woosuk.kwon@berkeley.edu>
Co-authored-by: Woosuk Kwon <woosuk.kwon@berkeley.edu>
BERTModel
(first encoder-only
embedding model)
We need a follow up to clean up the |
Totally agree with you that it's better design! Also co-author works for me. Thanks for the reply. |
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.
I can't say to the implementation of the model (don't have time to compare it against HF), but nothing really jumps out at me from a brief look. If the tests pass then it's probably fine.
I have a test that compares against the hf implementation (via sentence-transformers) |
prompt_lens = PoolingTensors.from_pooling_metadata( | ||
pooling_metadata, hidden_states.device).prompt_lens | ||
|
||
if self.pooling_type == PoolingType.LAST: | ||
if self.pooling_type is PoolingType.CLS: | ||
first_token_flat_indices = torch.zeros_like(prompt_lens) |
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.
nit: first_token_flat_indices
-> cls_token_flat_indices
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.
I've tested it with BAAI/bge-base-en-v1.5 and get results close to the MTEB benchmark.
) -> None: | ||
super().__init__() | ||
self.model = BertModel(config, cache_config, quant_config) | ||
self._pooler = Pooler(pooling_type=PoolingType.CLS, normalize=True) |
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.
In the transformers
code for this model I don't see normalization being applied: https://github.com/huggingface/transformers/blob/d00f1ca860f19f4c0962882e56044bb6ef7b5626/src/transformers/models/bert/modeling_bert.py#L743
How do we know if it has to be applied or not?
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.
I followed the sentence-transfomers
implementation, which is used in MTEB
. The baseline transformers
model uses a different pooling strategy completely
|
||
# Input embeddings. | ||
inputs_embeds = self.word_embeddings(input_ids) | ||
|
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.
In transformers
, if position_ids
is None, self.position_ids
is used. Should we do the same?
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.
I think position_ids
should never be None for us. But I should double check this
Co-authored-by: Cyrus Leung <tlleungac@connect.ust.hk>
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.
Overall LGTM - remember to add this model to the Supported Models page before you merge.
Is it intentional to not include this on the docs yet? |
Yes I think we should get #9388 in before we advertise this |
SUMMARY:
Note: this PR requires setting the
VLLM_ATTENTION_BACKEND=XFORMERS
variable to run. We throw a loud error if it is not set.TODO:
FOLLOW UPS:
FIX #5179
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:
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.Adding or changing kernels
Each custom kernel needs a schema and one or more implementations to be registered with PyTorch.
Tensors
require meta-functions. Meta-functions should be implemented and registered in python so that dynamic dims can be handled automatically. See above documents for a description of meta-functions.torch.libary.opcheck()
to test the function registration and meta-function for any registered ops. Seetests/kernels
for examples.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!