-
Notifications
You must be signed in to change notification settings - Fork 613
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 get_model_status
to get a model status on InferenceAPI
#1558
Comments
Hello it's a nice issue and I think I solve it following your initial function blueprint. Also I added a @dataclass
class ModelStatus:
loaded: bool
state: str
compute_type: str
framework: str And then after your huggingface_interface_response = request.get(f"https://api-inference.huggingface.co/status/{model}")
huggingface_interface_response.raise_for_status() Finally you can insert couple lines of code one just to check if you have an error in your responsed data. Something like this: response_data = huggingface_interface_response.json()
if "error" in data:
raise ValueError(response_data["error"])
elif response_data["loaded"] == False:
raise ValueError(response_data["state"]) And then you can just return the data through your return ModelStatus(
loaded=data['loaded'],
state=data['state'],
compute_type=data['compute_type'],
framework=data['framework'],
) FYI you need to import some modules. from dataclasses import dataclass
import requests I think this is what you need for this issue 😄 |
Thanks for your comment @sifisKoen! Yes I definitely think this is the way to go. The only think I would do differently is to not raise an issue if model is not loaded. If Would you like to open a PR to put everything together? 🤗 |
Thank you for your reply. Ok I got it. So you think something like: 1st Case
if response_data["loaded"] == False:
raise ValueError(response_data["state"]) 2nd Case
if response_data["loaded"] == False:
return response_data["state"] 3rd Case
if response_data["loaded"] == False:
# Do nothing and just do return?
return I am just asking so to provide you with the most suitable code for the project. Yep I will do it. 😃 |
Ok so my idea would be to return the dataclass, no matter the value of response_data = huggingface_interface_response.json()
if "error" in data:
raise ValueError(response_data["error"])
return ModelStatus(
loaded=data['loaded'],
state=data['state'],
compute_type=data['compute_type'],
framework=data['framework'],
) By doing so, we let the user decide what's best to do with the information. |
Ohhhh, cool got you. I will open a new PR with the new function, and a doc string with function description. No problem I will check other issues if I can help to them too. 🤝 |
Any update on the progress for this issue? Knowing the status of deployed models is specially important as I couldn't find a way to list all the models that are deployed and available through the API. |
@sjjpo2002 Implementation has started in this PR: #1559 |
Hello, these days I am out of office. I am at my vacations. I will be back in 5 days, so I will finish the tests then. @Wauplin |
Great, thanks @sifisKoen. Enjoy your vacation time! 🎉 😄 |
@Wauplin hey mate. I just finished the tests I will upload them now. Sorry for my delay tho. 😞 |
* Add get_model_status function (#1558) * Update src/huggingface_hub/inference/_client.py Accepting the suggestion. Co-authored-by: Lucain <[email protected]> * Update src/huggingface_hub/inference/_client.py Accept the changes get_model_status function doc string. Co-authored-by: Lucain <[email protected]> * Update src/huggingface_hub/inference/_client.py Accept the string inclusion in Error raise. Co-authored-by: Lucain <[email protected]> * Use interface endpoint constant and add get_session Accept the two changes about the INFERENCE_ENDPOINT and get_session(). Co-authored-by: Lucain <[email protected]> * Add dataclass in _common.py * Docstring refactor * Add new comments and modifications. Co-authored-by: Lucain <[email protected]> * Update src/huggingface_hub/inference/_client.py comments. From Wauplin Co-authored-by: Lucain <[email protected]> * Update src/huggingface_hub/inference/_client.py comments so to follow the correct syntax. From Wauplin Co-authored-by: Lucain <[email protected]> * Update src/huggingface_hub/inference/_common.py Co-authored-by: Lucain <[email protected]> * Add the tests for #1558 * fix async get_model_status --------- Co-authored-by: Lucain <[email protected]>
This feature is now available! Thanks @sifisKoen for your work ❤️ |
Thank you @Wauplin loved work with you 😄 |
Related to #1557 but can be implemented separately.
InferenceClient
could have an extra methodget_model_status
to get the status of a deployed model. This only makes sense forInferenceAPI
at least for now. We could think about a status for InferenceEndpoint as well but that will probably be implemented separately (see #1541). API endpoint for a given model ishttps://api-inference.huggingface.co/status/{model_id}
.This
/status
endpoint gives 2 main information:Here is how I see the method signature (can be discussed if needed). Would be good to define a dataclass for the returned value.
The text was updated successfully, but these errors were encountered: