forked from vllm-project/vllm
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Model] Explicit interface for vLLM models and support OOT embedding …
…models (vllm-project#9108)
- Loading branch information
1 parent
f68bcda
commit 9817faa
Showing
10 changed files
with
342 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
tests/plugins/vllm_add_dummy_model/vllm_add_dummy_model/my_gemma_embedding.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from typing import List, Optional, Union | ||
|
||
import torch | ||
|
||
from vllm.attention import AttentionMetadata | ||
from vllm.model_executor.models.gemma2_embedding import Gemma2EmbeddingModel | ||
from vllm.sequence import IntermediateTensors | ||
|
||
|
||
class MyGemma2Embedding(Gemma2EmbeddingModel): | ||
|
||
def forward( | ||
self, | ||
input_ids: torch.Tensor, | ||
positions: torch.Tensor, | ||
kv_caches: List[torch.Tensor], | ||
attn_metadata: AttentionMetadata, | ||
intermediate_tensors: Optional[IntermediateTensors] = None, | ||
inputs_embeds: Optional[torch.Tensor] = None, | ||
) -> Union[torch.Tensor, IntermediateTensors]: | ||
hidden_states = super().forward( | ||
input_ids, | ||
positions, | ||
kv_caches, | ||
attn_metadata, | ||
intermediate_tensors=intermediate_tensors, | ||
inputs_embeds=inputs_embeds, | ||
) | ||
|
||
if isinstance(hidden_states, IntermediateTensors): | ||
return hidden_states | ||
|
||
# Return all-zero embeddings | ||
return torch.zeros_like(hidden_states) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.