Skip to content

Commit

Permalink
Replace ReprMixin with dataclasses (#1788)
Browse files Browse the repository at this point in the history
* Define dataclasses

* Update docs

* Update tests

* Fixes

* Remove InitVar

* Style

* Apply suggestions from code review

Co-authored-by: Lucain <lucainp@gmail.com>

---------

Co-authored-by: Lucain <lucainp@gmail.com>
  • Loading branch information
mariosasko and Wauplin authored Nov 2, 2023
1 parent c7f2a91 commit f590bdf
Show file tree
Hide file tree
Showing 11 changed files with 702 additions and 477 deletions.
14 changes: 9 additions & 5 deletions docs/source/de/guides/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ Während des Filterns können Sie auch die Modelle sortieren und nur die Top-Erg
Zum Beispiel holt das folgende Beispiel die 5 am häufigsten heruntergeladenen Datensätze auf dem Hub:

```py
>>> list_datasets(sort="downloads", direction=-1, limit=5)
[DatasetInfo: {
id: glue
downloads: 897789
(...)
>>> list(list_datasets(sort="downloads", direction=-1, limit=5))
[DatasetInfo(
id='argilla/databricks-dolly-15k-curated-en',
author='argilla',
sha='4dcd1dedbe148307a833c931b21ca456a1fc4281',
last_modified=datetime.datetime(2023, 10, 2, 12, 32, 53, tzinfo=datetime.timezone.utc),
private=False,
downloads=8889377,
(...)
```


Expand Down
42 changes: 19 additions & 23 deletions docs/source/en/guides/collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,26 @@ Let's fetch the collection with, `"TheBloke/recent-models-64f9a55bb3115b4f513ec0
>>> from huggingface_hub import get_collection
>>> collection = get_collection("TheBloke/recent-models-64f9a55bb3115b4f513ec026")
>>> collection
Collection: {
{'description': "Models I've recently quantized.',
'items': [...],
'last_updated': datetime.datetime(2023, 9, 21, 7, 26, 28, 57000, tzinfo=datetime.timezone.utc),
'owner': 'TheBloke',
'position': 1,
'private': False,
'slug': 'TheBloke/recent-models-64f9a55bb3115b4f513ec026',
'theme': 'green',
'title': 'Recent models'}
}
Collection(
slug='TheBloke/recent-models-64f9a55bb3115b4f513ec026',
title='Recent models',
owner='TheBloke',
items=[...],
last_updated=datetime.datetime(2023, 10, 2, 22, 56, 48, 632000, tzinfo=datetime.timezone.utc),
position=1,
private=False,
theme='green',
upvotes=90,
description="Models I've recently quantized. Please note that currently this list has to be updated manually, and therefore is not guaranteed to be up-to-date."
)
>>> collection.items[0]
CollectionItem: {
{'item_object_id': '6507f6d5423b46492ee1413e',
'author': 'TheBloke',
'item_id': 'TheBloke/TigerBot-70B-Chat-GPTQ',
'item_type': 'model',
'lastModified': '2023-09-19T12:55:21.000Z',
'position': 0,
'private': False,
'repoType': 'model'
(...)
}
}
CollectionItem(
item_object_id='651446103cd773a050bf64c2',
item_id='TheBloke/U-Amethyst-20B-AWQ',
item_type='model',
position=88,
note=None
)
```

The [`Collection`] object returned by [`get_collection`] contains:
Expand Down
14 changes: 9 additions & 5 deletions docs/source/en/guides/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ While filtering, you can also sort the models and take only the top results. For
the following example fetches the top 5 most downloaded datasets on the Hub:

```py
>>> list_datasets(sort="downloads", direction=-1, limit=5)
[DatasetInfo: {
id: glue
downloads: 897789
(...)
>>> list(list_datasets(sort="downloads", direction=-1, limit=5))
[DatasetInfo(
id='argilla/databricks-dolly-15k-curated-en',
author='argilla',
sha='4dcd1dedbe148307a833c931b21ca456a1fc4281',
last_modified=datetime.datetime(2023, 10, 2, 12, 32, 53, tzinfo=datetime.timezone.utc),
private=False,
downloads=8889377,
(...)
```


Expand Down
4 changes: 4 additions & 0 deletions docs/source/en/package_reference/hf_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ models = hf_api.list_models()

[[autodoc]] huggingface_hub.hf_api.ModelInfo

### RepoSibling

[[autodoc]] huggingface_hub.hf_api.RepoSibling

### RepoFile

[[autodoc]] huggingface_hub.hf_api.RepoFile
Expand Down
1 change: 1 addition & 0 deletions src/huggingface_hub/_snapshot_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def snapshot_download(
api = HfApi(library_name=library_name, library_version=library_version, user_agent=user_agent, endpoint=endpoint)
repo_info = api.repo_info(repo_id=repo_id, repo_type=repo_type, revision=revision, token=token)
assert repo_info.sha is not None, "Repo info returned from server must have a revision sha."
assert repo_info.siblings is not None, "Repo info returned from server must have a siblings list."

filtered_repo_files = list(
filter_repo_objects(
Expand Down
1 change: 1 addition & 0 deletions src/huggingface_hub/_tensorboard_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from tensorboardX import SummaryWriter

# TODO: clarify: should we import from torch.utils.tensorboard ?

else:
SummaryWriter = object # Dummy class to avoid failing at import. Will raise on instance creation.

Expand Down
1 change: 1 addition & 0 deletions src/huggingface_hub/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

# Possible values for env variables


ENV_VARS_TRUE_VALUES = {"1", "ON", "YES", "TRUE"}
ENV_VARS_TRUE_AND_AUTO_VALUES = ENV_VARS_TRUE_VALUES.union({"AUTO"})

Expand Down
Loading

0 comments on commit f590bdf

Please sign in to comment.