Fix HF token validation to support Hugging Face CLI cache#4313
Open
Shuwen-Fang wants to merge 1 commit into
Open
Fix HF token validation to support Hugging Face CLI cache#4313Shuwen-Fang wants to merge 1 commit into
Shuwen-Fang wants to merge 1 commit into
Conversation
aac71a0 to
842dea1
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
igorts-git
reviewed
Jul 1, 2026
| # Try to convert checkpoint on the fly | ||
| if not config.hf_access_token: | ||
| raise ValueError("hf_access_token must be provided when not providing a pre-existing checkpoint") | ||
| from huggingface_hub import get_token # pylint: disable=import-outside-toplevel |
Collaborator
There was a problem hiding this comment.
Is there a reason to have this import here? Often AI agents are just lazy.
Collaborator
Author
There was a problem hiding this comment.
good catch, updated
igorts-git
approved these changes
Jul 1, 2026
912d479 to
67597b6
Compare
- Fallback to huggingface_hub.get_token() if config.hf_access_token is missing. - Pass the fallback token to the checkpoint conversion subprocess. - Add unit tests to verify authentication behavior.
06149ac to
0d6925a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes a bug where
train_rl.py(and other post-training scripts) would fail withValueError: hf_access_token must be provided when not providing a pre-existing checkpointeven if the user had authenticated via Hugging Face CLI (hf auth login).Cause
model_creation_utils.py:from_pretrainedstrictly validatedconfig.hf_access_token(which only comes fromHF_TOKENenvironment variable) and did not check the Hugging Face CLI cache.Fix
Updated
from_pretrainedto fallback tohuggingface_hub.get_token()to retrieve the token from the CLI cache ifconfig.hf_access_tokenis not set. The retrieved token is also passed to theto_maxtextsubprocess via theHF_TOKENenvironment variable to ensure it can authenticate.This makes the on-the-fly conversion during training work seamlessly after running
hf auth loginwithout needing to manually exportHF_TOKEN.Buganizer: https://b.corp.google.com/issues/528366193
Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.