-
Notifications
You must be signed in to change notification settings - Fork 9
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
Add olmo and qwen suts #601
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import requests | ||
from typing import List, Optional | ||
|
||
from huggingface_hub import ( # type: ignore | ||
ChatCompletionOutput, | ||
get_inference_endpoint, | ||
InferenceClient, | ||
InferenceEndpointStatus, | ||
) | ||
from huggingface_hub.utils import HfHubHTTPError # type: ignore | ||
from pydantic import BaseModel | ||
|
||
from modelgauge.auth.huggingface_inference_token import HuggingFaceInferenceToken | ||
from modelgauge.prompt import TextPrompt | ||
from modelgauge.secret_values import InjectSecret | ||
from modelgauge.sut import PromptResponseSUT, SUTCompletion, SUTResponse | ||
from modelgauge.sut_capabilities import AcceptsTextPrompt | ||
from modelgauge.sut_decorator import modelgauge_sut | ||
from modelgauge.sut_registry import SUTS | ||
|
||
|
||
class HuggingFaceChatParams(BaseModel): | ||
max_new_tokens: Optional[int] = None | ||
temperature: Optional[float] = None | ||
|
||
|
||
class HuggingFaceChatRequest(BaseModel): | ||
inputs: str | ||
parameters: HuggingFaceChatParams | ||
|
||
|
||
class HuggingFaceResponse(BaseModel): | ||
generated_text: str | ||
|
||
|
||
@modelgauge_sut(capabilities=[AcceptsTextPrompt]) | ||
class HuggingFaceSUT(PromptResponseSUT[HuggingFaceChatRequest, ChatCompletionOutput]): | ||
"""A Hugging Face SUT that is hosted on a dedicated inference endpoint.""" | ||
|
||
def __init__(self, uid: str, api_url: str, token: HuggingFaceInferenceToken): | ||
super().__init__(uid) | ||
self.token = token.value | ||
self.api_url = api_url | ||
|
||
def translate_text_prompt(self, prompt: TextPrompt) -> HuggingFaceChatRequest: | ||
return HuggingFaceChatRequest( | ||
inputs=prompt.text, | ||
parameters=HuggingFaceChatParams( | ||
max_new_tokens=prompt.options.max_tokens, temperature=prompt.options.temperature | ||
), | ||
) | ||
|
||
def evaluate(self, request: HuggingFaceChatRequest) -> HuggingFaceResponse: | ||
headers = { | ||
"Accept": "application/json", | ||
"Authorization": f"Bearer {self.token}", | ||
"Content-Type": "application/json", | ||
} | ||
payload = request.model_dump(exclude_none=True) | ||
response = requests.post(self.api_url, headers=headers, json=payload) | ||
response_json = response.json()[0] | ||
return HuggingFaceResponse(**response_json) | ||
|
||
def translate_response(self, request: HuggingFaceChatRequest, response: HuggingFaceResponse) -> SUTResponse: | ||
return SUTResponse(completions=[SUTCompletion(text=response.generated_text)]) | ||
|
||
|
||
HF_SECRET = InjectSecret(HuggingFaceInferenceToken) | ||
|
||
SUTS.register( | ||
HuggingFaceSUT, | ||
"olmo-7b-0724-instruct-hf", | ||
"https://flakwttqzmq493dw.us-east-1.aws.endpoints.huggingface.cloud", | ||
HF_SECRET, | ||
) |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@bkorycki to add to @wpietri 's comment, this worries me a little. Maybe we could make a mlcommons.org cname to put in the code, and update the cname if the HF endpoint changes? Or in secrets.toml?
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.
Long term, I'd like to create a layer that lets a more user-y person say they want
olmo-7b-0724-instruct
for something, and then lets an ops person say, "we prefer to use huggingface for that and here's how". And presumably that latter bit will be via a configuration file. That would help us, and it would also help other users of our code, because they may want to use a different llamaguard provider, including an internal one, rather than the one we've hardcoded.But for now updating the source isn't much harder than updating a cname. And a cname only solves the problem for us, not for other people using this code. So I'm fine with just leaving this like this and then fixing it when we have more information about where we need things to flex.