-
Notifications
You must be signed in to change notification settings - Fork 571
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
Support multiple tokens locally #2549
Conversation
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
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 for working on it @hanouticelina !
I've not properly tested it locally yet but started to make a pass on the implementation. I think we can regroup some things to avoid multiple utils modules and decouple the low-level logic (e.g. how the config file is structured) from the high-level logic (e.g. how to present stuff to the users).
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.
Hey there! I finally took some time to extensively test things locally. I think you are on the right track to get this feature shipped. I found a few corner cases that I think should be tackled differently. Other than that, it's mostly cosmetic changes in the API design
src/huggingface_hub/_login.py
Outdated
raise ValueError(f"Profile {profile_name} not found in {constants.HF_PROFILES_PATH}") | ||
# Write token to HF_TOKEN_PATH | ||
_set_active_profile(profile_name, add_to_git_credential) | ||
print(f"Switched to profile: {profile_name}") |
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.
TODO in a future PR: remove all print
statement from this module and replace them with proper logs. And then in the CLI set verbosity level to INFO.
(btw, you can set the PR to "ready for review" when it's the case :) ) |
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.
Looking good! As discussed offline, let's use the "token name" returned by the server as profile names :) Once updated we should be good to merge. Thanks for the extensive tests!
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 for the change! Last round of review I think :) I tested everything locally and the UX is really smooth now 🤗
Feel free to merge once the comments below are addressed and CI is green.
thanks a lot @Wauplin and sorry for the lengthy back and forth reviews 🙈 with your detailed feedback on this PR, I'm sure the next ones will be much easier to 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.
All good!
I think we are good with this one, let's merge :) |
nice!! 🎉🎉🎉 |
Closes #2446.
This PR adds a multi-token support allowing users to easily manage and switch between multiple tokens.
List of changes
token-name
argumentlogout
helpers and the corresponding commands.huggingface_hub/src/utils/_auth.py
.huggingface-cli auth switch
andhuggingface-cli auth list
to switch between tokens and list saved tokens respectively. New helpershuggingface_hub._login.auth_switch
andhuggingface_hub._login.auth_list
are also added.get_stored_tokens()
,_save_stored_tokens()
,_get_token_by_name()
,_save_token()
.tests/test_auth.py
.quick-start.md
,guides/cli.md
and login package reference are also updated.Usage
Login
--token
is not provided, prompts the user for token interactively.List locally stored tokens
Example output:
Logout
huggingface-cli logout [--token-name TOKEN_NAME]
--token-name
is not specified, logs out from all tokens.Switching the current active token
--token-name
is not provided, prompts the user to select from locally saved tokens.~/.cache/huggingface/token
(defined byHF_TOKEN_PATH
env variable).How it Works
Token storage
Tokens will be stored in
~/.cache/huggingface/stored_tokens
(orHF_STORED_TOKENS_PATH
env variable if set), which is INI format file:Token Selection Priority
We will keep the same token retrieval priority order
HF_TOKEN
env variable.~/.cache/huggingface/token
. The token stored in this file will be updated when switching between tokens.