From c850e1954d8685f10fd7a60017dc30880c50b2d6 Mon Sep 17 00:00:00 2001 From: adrinjalali Date: Thu, 12 Oct 2023 11:34:29 +0200 Subject: [PATCH 1/3] DEPR deprecate hub_utils.get_model_output --- docs/changes.rst | 2 ++ skops/hub_utils/_hf_hub.py | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 3be2a186..09df679c 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -16,6 +16,8 @@ v0.9 estimators. :pr:`384` by :user:`Reid Johnson `. - Fix an issue with visualizing Skops files for `scikit-learn` tree estimators. :pr:`386` by :user:`Reid Johnson `. +- :func:`skops.hug_utils.get_model_output` is deprecated and will be removed in version + 0.10. v0.8 ---- diff --git a/skops/hub_utils/_hf_hub.py b/skops/hub_utils/_hf_hub.py index 41eaa160..eba96992 100644 --- a/skops/hub_utils/_hf_hub.py +++ b/skops/hub_utils/_hf_hub.py @@ -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 ` 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,11 @@ 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." + ) model_info = HfApi().model_info(repo_id=repo_id, use_auth_token=token) # type: ignore if not model_info.pipeline_tag: raise ValueError( From 593242e2ece44a568f8d76cf4f8e7721fddf99c8 Mon Sep 17 00:00:00 2001 From: adrinjalali Date: Thu, 12 Oct 2023 11:41:33 +0200 Subject: [PATCH 2/3] add test --- docs/changes.rst | 2 +- skops/hub_utils/_hf_hub.py | 9 ++++++--- skops/hub_utils/tests/test_hf_hub.py | 9 ++++++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 09df679c..cb63da52 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -17,7 +17,7 @@ v0.9 - Fix an issue with visualizing Skops files for `scikit-learn` tree estimators. :pr:`386` by :user:`Reid Johnson `. - :func:`skops.hug_utils.get_model_output` is deprecated and will be removed in version - 0.10. + 0.10. :pr:`396` by `Adrin Jalali`_. v0.8 ---- diff --git a/skops/hub_utils/_hf_hub.py b/skops/hub_utils/_hf_hub.py index eba96992..c15953a7 100644 --- a/skops/hub_utils/_hf_hub.py +++ b/skops/hub_utils/_hf_hub.py @@ -744,9 +744,12 @@ def get_model_output(repo_id: str, data: Any, token: Optional[str] = None) -> An available. """ 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." + ( + "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, ) model_info = HfApi().model_info(repo_id=repo_id, use_auth_token=token) # type: ignore if not model_info.pipeline_tag: diff --git a/skops/hub_utils/tests/test_hf_hub.py b/skops/hub_utils/tests/test_hf_hub.py index d2ee3931..59b51ebb 100644 --- a/skops/hub_utils/tests/test_hf_hub.py +++ b/skops/hub_utils/tests/test_hf_hub.py @@ -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(): + 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) From 476893c50b5d513e01aa4a79d65504b32064504d Mon Sep 17 00:00:00 2001 From: adrinjalali Date: Thu, 12 Oct 2023 12:01:18 +0200 Subject: [PATCH 3/3] use new black --- skops/hub_utils/_hf_hub.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/skops/hub_utils/_hf_hub.py b/skops/hub_utils/_hf_hub.py index c15953a7..fb161388 100644 --- a/skops/hub_utils/_hf_hub.py +++ b/skops/hub_utils/_hf_hub.py @@ -744,11 +744,9 @@ def get_model_output(repo_id: str, data: Any, token: Optional[str] = None) -> An available. """ 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." - ), + "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, ) model_info = HfApi().model_info(repo_id=repo_id, use_auth_token=token) # type: ignore