-
Notifications
You must be signed in to change notification settings - Fork 53
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
DEPR deprecate hub_utils.get_model_output #396
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
import json | ||
import os | ||
import shutil | ||
import warnings | ||
from pathlib import Path | ||
from typing import Any, List, Literal, MutableMapping, Optional, Sequence, Union | ||
|
||
|
@@ -702,11 +703,16 @@ def download( | |
shutil.rmtree(path=cached_folder) | ||
|
||
|
||
# TODO(v0.10): remove this function | ||
def get_model_output(repo_id: str, data: Any, token: Optional[str] = None) -> Any: | ||
"""Returns the output of the model using Hugging Face Hub's inference API. | ||
|
||
See the :ref:`User Guide <hf_hub_inference>` for more details. | ||
|
||
.. deprecated:: 0.9 | ||
Will be removed in version 0.10. Use ``huggingface_hub.InferenceClient`` | ||
instead. | ||
|
||
Parameters | ||
---------- | ||
repo_id: str | ||
|
@@ -737,8 +743,12 @@ def get_model_output(repo_id: str, data: Any, token: Optional[str] = None) -> An | |
Also note that if the model repo is private, the inference API would not be | ||
available. | ||
""" | ||
# TODO: the "type: ignore" should eventually become unncessary when hf_hub | ||
# is updated | ||
warnings.warn( | ||
"This feature is no longer free on hf.co and therefore this function will" | ||
" be removed in the next release. Use `huggingface_hub.InferenceClient`" | ||
" instead.", | ||
FutureWarning, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DeprecationWarning is not shown by default, but FutureWarning is, that's why in sklearn we switched to FutureWarning to make sure people actually see it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIL. Makes sense. |
||
) | ||
model_info = HfApi().model_info(repo_id=repo_id, use_auth_token=token) # type: ignore | ||
if not model_info.pipeline_tag: | ||
raise ValueError( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -503,7 +503,8 @@ def test_inference( | |
|
||
X_test = data.data.head(5) | ||
y_pred = model.predict(X_test) | ||
output = get_model_output(repo_id, data=X_test, token=HF_HUB_TOKEN) | ||
with pytest.warns(FutureWarning): | ||
output = get_model_output(repo_id, data=X_test, token=HF_HUB_TOKEN) | ||
|
||
# cleanup | ||
client.delete_repo(repo_id=repo_id, token=HF_HUB_TOKEN) | ||
|
@@ -512,6 +513,12 @@ def test_inference( | |
assert np.allclose(output, y_pred) | ||
|
||
|
||
def test_get_model_output_deprecated(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If, in the test above, you add the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here I'm not passing any token and not passing a valid model name, so the function would fail anyway (hence the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, then it's good. |
||
with pytest.raises(Exception): | ||
with pytest.warns(FutureWarning, match="This feature is no longer free"): | ||
get_model_output("dummy", data=iris.data) | ||
|
||
|
||
def test_get_config(repo_path, config_json): | ||
config_path, file_format = config_json | ||
config = get_config(repo_path) | ||
|
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.
Technically speaking, it's still free, just heavily rate-limited.
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.
So it's not free 😁
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.
A philosophical question...