Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Auto-detect Hugging Face tokens in hosted notebooks#3

Merged
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
Jul 25, 2026
Merged

Auto-detect Hugging Face tokens in hosted notebooks#3
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

@iam-knoit

Copy link
Copy Markdown

Motivation

  • Hosted notebook platforms (Google Colab, Kaggle) expose secrets via platform secret stores rather than the process environment, preventing Hugging Face libraries from seeing HF_TOKEN during import.
  • Populate the conventional HF_TOKEN from notebook secret stores at startup so gated model access works in hosted notebooks without manual environment setup.
  • Preserve any explicitly configured HF_TOKEN and treat missing or inaccessible notebook secrets as non-fatal to avoid breaking anonymous access.

Description

  • Add unsloth/notebook_token.py which detects the default secret name HF_TOKEN, reads it from Colab (google.colab.userdata) and Kaggle (kaggle_secrets.UserSecretsClient), strips whitespace, and sets os.environ['HF_TOKEN'] when found.
  • Invoke the detection early from unsloth/__init__.py so the token is available before Hugging Face libraries freeze their authentication configuration.
  • Add tests/test_notebook_token.py with tests for Colab detection, Kaggle fallback after a missing Colab secret, explicit HF_TOKEN precedence, and non-fatal handling of secret-access failures.

Testing

  • Ran pytest -q tests/test_notebook_token.py and all tests passed (4 passed).
  • Compiled the new module with python -m compileall unsloth/notebook_token.py and it succeeded.

Codex Task

@iam-knoit
iam-knoit merged commit 6049515 into main Jul 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.