Auto-detect Hugging Face tokens in hosted notebooks#3
Merged
iam-knoit merged 1 commit intoJul 25, 2026
mainSynhalaAI/unsloth:mainfrom
codex/auto-detect-hf_token-in-colab-and-kaggleSynhalaAI/unsloth:codex/auto-detect-hf_token-in-colab-and-kaggleCopy head branch name to clipboard
Merged
Auto-detect Hugging Face tokens in hosted notebooks#3iam-knoit merged 1 commit intomainSynhalaAI/unsloth:mainfrom codex/auto-detect-hf_token-in-colab-and-kaggleSynhalaAI/unsloth:codex/auto-detect-hf_token-in-colab-and-kaggleCopy head branch name to clipboard
iam-knoit merged 1 commit into
mainSynhalaAI/unsloth:mainfrom
codex/auto-detect-hf_token-in-colab-and-kaggleSynhalaAI/unsloth:codex/auto-detect-hf_token-in-colab-and-kaggleCopy head branch name to clipboard
Conversation
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.
Motivation
HF_TOKENduring import.HF_TOKENfrom notebook secret stores at startup so gated model access works in hosted notebooks without manual environment setup.HF_TOKENand treat missing or inaccessible notebook secrets as non-fatal to avoid breaking anonymous access.Description
unsloth/notebook_token.pywhich detects the default secret nameHF_TOKEN, reads it from Colab (google.colab.userdata) and Kaggle (kaggle_secrets.UserSecretsClient), strips whitespace, and setsos.environ['HF_TOKEN']when found.unsloth/__init__.pyso the token is available before Hugging Face libraries freeze their authentication configuration.tests/test_notebook_token.pywith tests for Colab detection, Kaggle fallback after a missing Colab secret, explicitHF_TOKENprecedence, and non-fatal handling of secret-access failures.Testing
pytest -q tests/test_notebook_token.pyand all tests passed (4 passed).python -m compileall unsloth/notebook_token.pyand it succeeded.Codex Task