-
Notifications
You must be signed in to change notification settings - Fork 570
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 deprecate name and organization in favor of repo_id #733
Conversation
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.
I like this approach for deprecating! I'm all in favour of updating the other params as well.
Thank you very much for this PR! 🚀 🔥
src/huggingface_hub/hf_api.py
Outdated
token: A token to be used for the download. | ||
- If ``True``, the token is read from the HuggingFace config | ||
folder. | ||
- If a string, it's used as the authentication token. |
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.
token
should always be a string, so I would keep that. If not specified, it retrieves the stored token.
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.
_validate_or_retrieve_token
seems to disagree with you I think. Although in this case you're right I guess? I'm not sure if we're being consistent in treatment of token
and use_auth_token
across this file.
This is now ready for another review! |
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.
This looks good to me!
I'm not sure if the failed CI is related to this PR. |
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.
Thanks a lot for solving the issue!
You're solving the issue by adding a new argument repo_id
, which is fine, but I think it's misleading in some cases, as I would expect the name
to work correctly as a positional argument. I personally would use the method as follows:
from huggingface_hub import create_repo
create_repo("my-brand-new-repo")
create_repo("my-brand-new-repo", organization="huggingface")
However with this approach this results in a warning that may be a bit arcane:
>>> create_repo('<repo>')
/.../huggingface_hub/src/huggingface_hub/hf_api.py:65: FutureWarning: `name` and `organization` input arguments are deprecated and will be removed in v0.7. Pass `repo_id` instead.
FutureWarning,
'https://huggingface.co/<user>/<repo>'
I don't really know what's name
and why I'm being prompted to change it here, given I didn't pass it with the keyword.
Furthermore, it makes the following API usage deprecated, even though it is both documented here and feels like the API we're trying to push forward.
>>> create_repo('<org>/<repo>')
/.../huggingface_hub/src/huggingface_hub/hf_api.py:65: FutureWarning: `name` and `organization` input arguments are deprecated and will be removed in v0.7. Pass `repo_id` instead.
FutureWarning,
'https://huggingface.co/<org>/<repo>'
I would prefer doing the following:
- Deprecating the
organization
argument - Replacing the
name
argument byrepo_id
- Adding
name
as an additional kwarg at the bottom, instead of therepo_id
you've added.
This should enable the following usage:
create_repo("<repo>")
create_repo("<org>/<repo>")
create_repo(repo_id="<repo>")
create_repo(repo_id="<org>/<repo>")
create_repo("<name>", organization="<org>")
# Deprecation warning!create_repo(name="<name>", organization="<org>")
# Deprecation warning!
What do you think?
Test failing with
on: def test_push_to_hub(self):
REPO_NAME = repo_name("PUSH_TO_HUB")
model = DummyModel()
model.push_to_hub(
repo_path_or_name=f"{WORKING_REPO_DIR}/{REPO_NAME}",
api_endpoint=ENDPOINT_STAGING,
use_auth_token=self._token,
git_user="ci",
git_email="ci@dummy.com",
config={"num": 7, "act": "gelu_fast"},
) I'm not sure how to fix this. @julien-c seems to have written the test. |
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.
This looks good! Only left a comment regarding a switch between the org and name, it should solve the CI issue.
""" | ||
name, organization = _validate_repo_id_deprecation(repo_id, name, organization) |
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.
I would add a check to ensure that at least repo_id
or name
is passed, since they are now both optional arguments:
>>> from huggingface_hub import create_repo
>>> create_repo()
Traceback (most recent call last):
File "/usr/lib/python3.6/code.py", line 91, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
File "/home/lysandre/Workspaces/Python/huggingface_hub/src/huggingface_hub/hf_api.py", line 1056, in create_repo
name, organization = _validate_repo_id_deprecation(repo_id, name, organization)
File "/home/lysandre/Workspaces/Python/huggingface_hub/src/huggingface_hub/hf_api.py", line 68, in _validate_repo_id_deprecation
if "/" in repo_id:
TypeError: argument of type 'NoneType' is not iterable
Something like the following
name, organization = _validate_repo_id_deprecation(repo_id, name, organization) | |
if name is None and repo_id is None: | |
raise ValueError("Please pass either `name` or `repo_id`") | |
name, organization = _validate_repo_id_deprecation(repo_id, name, organization) |
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.
+1, but since name is deprecated, I would just ask to specify repo_id
.
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.
Indeed, good call!
@LysandreJik if you're happy with the changes, please feel free to merge. |
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.
LGTM, great work!
Resolved conflicts, will merge when tests pass |
would love to be pinged if you do changes in |
Fixes #706
Tests and deprecations on other methods to be added if we're okay with the approach.
cc @LysandreJik @osanseviero