Skip to content
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

MNT Move to huggingface_hub v0.10 #162

Merged
merged 3 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ v0.3
----
- Utility function to add arbitrary files to be uploaded to the hub by using
:func:`.hub_utils.add_files`. :pr:`123` by `Benjamin Bossan`_.
- Add ``private`` as an optional argument to :meth:`.hub_utils.push` to
- Add ``private`` as an optional argument to :meth:`skops.hub_utils.push` to
optionally set the visibility status of a repo when pushing to the hub.
:pr:`130` by `Adrin Jalali`_.
- First release of the skops secure persistence feature (:pr:`128`) by `Adrin
Expand All @@ -22,6 +22,8 @@ v0.3
receive feedback from users.
- Fix a bug that resulted in markdown tables being rendered incorrectly if
entries contained line breaks. :pr:`156` by `Benjamin Bossan`_.
- Use ``huggingface_hub`` v0.10.1 for model cards, drop ``modelcards``
dependency. :pr:`162` by `Benjamin Bossan`_.

v0.2
----
Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ profile = "black"
filterwarnings = [
"error::DeprecationWarning",
"error::FutureWarning",
# TODO: remove line below once we changed hub calls to use use_auth_token
"ignore:Deprecated argument\\(s\\) used in 'model_info':FutureWarning",
]
markers = [
"network: marks tests as requiring internet (deselect with '-m \"not network\"')",
Expand Down
4 changes: 1 addition & 3 deletions skops/_min_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
# "tomli": ("1.1.0", "install", "python_full_version < '3.11.0a7'"),
dependent_packages = {
"scikit-learn": ("0.24", "install", None),
# TODO: remove '<0.12.0rc0' once we changed hub calls to use use_auth_token
"huggingface_hub": ("0.9.0rc3,<0.11.0rc0", "install", None),
"modelcards": ("0.1.6", "install", None),
"huggingface_hub": ("0.10.1", "install", None),
"tabulate": ("0.8.8", "install", None),
"pytest": (PYTEST_MIN_VERSION, "tests", None),
"pytest-cov": ("2.9.0", "tests", None),
Expand Down
21 changes: 11 additions & 10 deletions skops/card/_model_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from reprlib import Repr
from typing import Any, Optional, Union

from modelcards import CardData, ModelCard
from huggingface_hub import CardData, ModelCard
from sklearn.utils import estimator_html_repr
from tabulate import tabulate # type: ignore

Expand Down Expand Up @@ -110,10 +110,10 @@ def __repr__(self) -> str:
def metadata_from_config(config_path: Union[str, Path]) -> CardData:
"""Construct a ``CardData`` object from a ``config.json`` file.

Most information needed for the metadata section of a ``README.md``
file on Hugging Face Hub is included in the ``config.json`` file. This
utility function constructs a ``CardData`` object which can then be
passed to the :class:`~skops.card.Card` object.
Most information needed for the metadata section of a ``README.md`` file on
Hugging Face Hub is included in the ``config.json`` file. This utility
function constructs a :class:`huggingface_hub.CardData` object which can
then be passed to the :class:`~skops.card.Card` object.

This method populates the following attributes of the instance:

Expand All @@ -133,8 +133,9 @@ def metadata_from_config(config_path: Union[str, Path]) -> CardData:

Returns
-------
card_data: ``modelcards.CardData``
``CardData`` object.
card_data: huggingface_hub.CardData
:class:`huggingface_hub.CardData` object.

"""
config_path = Path(config_path)
if not config_path.is_file():
Expand Down Expand Up @@ -377,9 +378,9 @@ def _generate_card(self) -> ModelCard:

Returns
-------
card : modelcards.ModelCard
The final ``ModelCard`` object with all placeholders filled and all
extra sections inserted.
card : huggingface_hub.ModelCard
The final :class:`huggingface_hub.ModelCard` object with all
placeholders filled and all extra sections inserted.
"""
root = skops.__path__

Expand Down
4 changes: 1 addition & 3 deletions skops/card/tests/test_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import numpy as np
import pytest
import sklearn
from huggingface_hub import metadata_load
from huggingface_hub import CardData, metadata_load
from sklearn.datasets import load_iris
from sklearn.linear_model import LinearRegression, LogisticRegression

Expand Down Expand Up @@ -371,8 +371,6 @@ def test_extra_sections_val_not_str(self, card: Card, meth):

@pytest.mark.parametrize("meth", [repr, str])
def test_with_metadata(self, card: Card, meth):
from modelcards import CardData

metadata = CardData(
language="fr",
license="bsd",
Expand Down
2 changes: 1 addition & 1 deletion skops/hub_utils/_hf_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ 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.
"""
model_info = HfApi().model_info(repo_id=repo_id, token=token)
model_info = HfApi().model_info(repo_id=repo_id, use_auth_token=token)
if not model_info.pipeline_tag:
raise ValueError(
f"Repo {repo_id} has no pipeline tag. You should set a valid 'task' in"
Expand Down
2 changes: 1 addition & 1 deletion skops/hub_utils/tests/test_hf_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def test_push_download(
with pytest.raises(OSError, match="None-empty dst path already exists!"):
download(repo_id=repo_id, dst=destination_path, token=HF_HUB_TOKEN)

files = client.list_repo_files(repo_id=repo_id, token=HF_HUB_TOKEN)
files = client.list_repo_files(repo_id=repo_id, use_auth_token=HF_HUB_TOKEN)
for f_name in [classifier_pickle.name, config_json.name]:
assert f_name in files

Expand Down