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

Improve Mixin #34

Merged
merged 6 commits into from
Apr 22, 2021
Merged

Improve Mixin #34

merged 6 commits into from
Apr 22, 2021

Conversation

LysandreJik
Copy link
Member

@LysandreJik LysandreJik commented Apr 20, 2021

Improves the Mixin in the hub by adding support for api_endpoint, use_auth_token, as well as git_user and git_email.

It updates the tests so that they run in the staging environment. In doing so, I found a bug relative to absolute paths in from_pretrained, this fixes that at the same time.

@LysandreJik LysandreJik requested a review from julien-c April 21, 2021 00:16
Copy link
Member

@julien-c julien-c left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

setup.py Outdated
extras["testing"] = [
"pytest",
]
] + extras["torch"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there value in having a second CI setup with no torch? (to make sure we don't introduce a dependency on torch inadvertently down the road)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I can add that

Comment on lines +247 to +253
if isinstance(use_auth_token, str):
huggingface_token = use_auth_token
elif use_auth_token is None and repo_url is not None:
# If the repo url exists, then no need for a token
huggingface_token = None
else:
huggingface_token = HfFolder.get_token()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if isinstance(use_auth_token, str):
huggingface_token = use_auth_token
elif use_auth_token is None and repo_url is not None:
# If the repo url exists, then no need for a token
huggingface_token = None
else:
huggingface_token = HfFolder.get_token()
if isinstance(use_auth_token, str):
huggingface_token = use_auth_token
elif use_auth_token:
huggingface_token = HfFolder.get_token()
else:
huggingface_token = None

let's use the same logic as elsewhere no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue with using the same logic as elsewhere is that the API becomes weird to use, in order to cover a rare use-case. Namely, the following will never work:

model.push_to_hub("xxx")

it needs to be the following:

model.push_to_hub("xxx", use_auth_token=True)

I fail to see when a user would want to push to the hub without having an auth_token, as it's necessary to create a repo. If the repo already exists and one wants to push to it, then the user already has to specify the repo_url to push to.

I think the API is cleaner by having model.push_to_hub("xxx") work if you already have an authentication token in your HF folder.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

files = os.listdir(f"{WORKING_REPO_DIR}/{REPO_NAME}")
self.assertTrue("config.json" in files)
self.assertTrue("pytorch_model.bin" in files)
self.assertEqual(len(files), 2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

)
self.assertTrue(model.config == {"num": 10, "act": "gelu_fast"})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.assertEqual should work, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed!

@LysandreJik LysandreJik merged commit cec8594 into huggingface:main Apr 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants