-
Notifications
You must be signed in to change notification settings - Fork 761
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make embedding generation go through inference (#606)
This PR does the following: 1) adds the ability to generate embeddings in all supported inference providers. 2) Moves all the memory providers to use the inference API and improved the memory tests to setup the inference stack correctly and use the embedding models This is a merge from #589 and #598
- Loading branch information
Showing
37 changed files
with
677 additions
and
156 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
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
20 changes: 20 additions & 0 deletions
20
llama_stack/providers/inline/inference/sentence_transformers/__init__.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,20 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the terms described in the LICENSE file in | ||
# the root directory of this source tree. | ||
|
||
from llama_stack.providers.inline.inference.sentence_transformers.config import ( | ||
SentenceTransformersInferenceConfig, | ||
) | ||
|
||
|
||
async def get_provider_impl( | ||
config: SentenceTransformersInferenceConfig, | ||
_deps, | ||
): | ||
from .sentence_transformers import SentenceTransformersInferenceImpl | ||
|
||
impl = SentenceTransformersInferenceImpl(config) | ||
await impl.initialize() | ||
return impl |
10 changes: 10 additions & 0 deletions
10
llama_stack/providers/inline/inference/sentence_transformers/config.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,10 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the terms described in the LICENSE file in | ||
# the root directory of this source tree. | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class SentenceTransformersInferenceConfig(BaseModel): ... |
74 changes: 74 additions & 0 deletions
74
llama_stack/providers/inline/inference/sentence_transformers/sentence_transformers.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,74 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the terms described in the LICENSE file in | ||
# the root directory of this source tree. | ||
|
||
import logging | ||
from typing import AsyncGenerator, List, Optional, Union | ||
|
||
from llama_stack.apis.inference import ( | ||
CompletionResponse, | ||
Inference, | ||
LogProbConfig, | ||
Message, | ||
ResponseFormat, | ||
SamplingParams, | ||
ToolChoice, | ||
ToolDefinition, | ||
ToolPromptFormat, | ||
) | ||
from llama_stack.providers.datatypes import Model, ModelsProtocolPrivate | ||
from llama_stack.providers.utils.inference.embedding_mixin import ( | ||
SentenceTransformerEmbeddingMixin, | ||
) | ||
from .config import SentenceTransformersInferenceConfig | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class SentenceTransformersInferenceImpl( | ||
SentenceTransformerEmbeddingMixin, | ||
Inference, | ||
ModelsProtocolPrivate, | ||
): | ||
def __init__(self, config: SentenceTransformersInferenceConfig) -> None: | ||
self.config = config | ||
|
||
async def initialize(self) -> None: | ||
pass | ||
|
||
async def shutdown(self) -> None: | ||
pass | ||
|
||
async def register_model(self, model: Model) -> None: | ||
_ = self._load_sentence_transformer_model(model.provider_resource_id) | ||
return model | ||
|
||
async def unregister_model(self, model_id: str) -> None: | ||
pass | ||
|
||
async def completion( | ||
self, | ||
model_id: str, | ||
content: str, | ||
sampling_params: Optional[SamplingParams] = SamplingParams(), | ||
response_format: Optional[ResponseFormat] = None, | ||
stream: Optional[bool] = False, | ||
logprobs: Optional[LogProbConfig] = None, | ||
) -> Union[CompletionResponse, AsyncGenerator]: | ||
raise ValueError("Sentence transformers don't support completion") | ||
|
||
async def chat_completion( | ||
self, | ||
model_id: str, | ||
messages: List[Message], | ||
sampling_params: Optional[SamplingParams] = SamplingParams(), | ||
response_format: Optional[ResponseFormat] = None, | ||
tools: Optional[List[ToolDefinition]] = None, | ||
tool_choice: Optional[ToolChoice] = ToolChoice.auto, | ||
tool_prompt_format: Optional[ToolPromptFormat] = ToolPromptFormat.json, | ||
stream: Optional[bool] = False, | ||
logprobs: Optional[LogProbConfig] = None, | ||
) -> AsyncGenerator: | ||
raise ValueError("Sentence transformers don't support chat completion") |
Oops, something went wrong.