Skip to content

CLI: pass --hf-token to the export checkpoint load - #10218

Merged
oobabooga merged 6 commits into
unslothai:mainfrom
NilayYadav:fix-cli-export-hf-token
Sep 3, 2026
Merged

oobabooga merged 6 commits into
unslothai:mainfrom
NilayYadav:fix-cli-export-hf-token

Conversation

@NilayYadav

@NilayYadav NilayYadav commented Sep 2, 2026 •

Copy link
Copy Markdown
Collaborator

unsloth export sends the token to the Hub push but not to the checkpoint load, so a gated model fails at the load with a 401 even though the token was given. The Studio export page works with the same token, and both the Studio route and the export worker already pass it.

Tested with every Hub request logged: before, 71 requests went out and none carried the token, after, 34 did, including the security check and the weight download.

The test file also needed a small harness fix to carry the new case: it stubs studio.backend in sys.modules, which unsloth_cli/__init__.py needs through commands/start.py, so whichever test ran first errored in setup (6 passed, 2 errors on main for the file on its own). Loading the real CLI before the stubs go in makes the file 9 passed and the new test runnable on its own, which matters because the suite runs sharded.

@NilayYadav
NilayYadav force-pushed the fix-cli-export-hf-token branch from 07c5368 to e03da59 Compare September 2, 2026 20:15
@NilayYadav

NilayYadav commented Sep 2, 2026 •

Copy link
Copy Markdown
Collaborator Author

Review + GitHub Actions reproduction

Pinned head 25deee0ca, base fresh upstream main c9f98dbd5 (the branch sits directly on it, no rebase needed).

Review — no P1. Two items found and pushed:

  • P2 tests/test_cli_export_unpacking.py could not run standalone. _install_fake_studio_backend stubs studio.backend in sys.modules, and unsloth_cli/__init__.py reaches studio.backend.utils.coding_agents through commands/start.py, so whichever test ran first errored in fixture setup — on main, pytest tests/test_cli_export_unpacking.py is 6 passed, 2 errors, and selecting the new test alone errored too. The file only passes today because something earlier in the full tests/ run imports the CLI first, which -n 4 sharding does not guarantee. Loading the real CLI inside _install_fake_studio_backend, before the stubs go in, fixes it: 9 passed for the whole file, and the new test passes selected on its own.
  • P3 --hf-token help still described a push-only token; it now says it covers gated/private checkpoint loads as well.

The formatting-only hunk in studio/backend/tests/test_anthropic_messages.py is a pre-commit.ci autofix, not a hand edit.

A/B on Actions. Two disposable fork branches, same harness, same runner (ubuntu-latest, Python 3.12), differing only in the line under test (hf_token = hf_token, in unsloth_cli/commands/export.py):

negative (fix reverted) PR head
run 33682888536 — failing 33682883826 — passing
pytest tests/test_cli_export_unpacking.py 1 failed, 8 passed 9 passed
Hub requests during the export 6 3
…carrying the token 0 2
…anonymous, answered 401 6 1

The second leg runs the real command — unsloth export <ckpt> <out> --format lora --hf-token <token> — against a mock Hub bound to HF_ENDPOINT that answers 401 to every unauthenticated request, which is what a gated repo does. The checkpoint is a LoRA adapter whose base_model_name_or_path is that gated repo, so the real ExportOrchestrator spawns the real export worker and resolves the base over the Hub.

Negative transcript — every request anonymous, so every one 401s:

[ 401 ] HEAD  /
[ 401 ] GET   /gated-org/gated-base/resolve/main/config.json      (x4)
[ 401 ] GET   /gated-org/gated-base/resolve/main/tokenizer_config.json

PR head — the repo reads authenticate, and the four config.json retries collapse to one:

[ 401 ] HEAD  /                                                    <- endpoint reachability probe, never authenticated
[TOKEN] GET   /gated-org/gated-base/resolve/main/config.json
[TOKEN] GET   /gated-org/gated-base/resolve/main/tokenizer_config.json

Both legs then stop at Failed to import ML libraries: No module named 'transformers', identically on both branches — the runner has no torch stack, and the assertion is the request transcript, which is complete by then.

No UI surface: the change is confined to unsloth_cli, and the Studio export route already passed the token, so there is nothing visible to screenshot.

Upstream checks: 43 pass, 4 skip. The two reds — Repo tests (CPU) and workflow-trigger lint — are the same single test in both, tests/security/test_scan_packages.py::test_context_dependent_unsloth_zoo_findings_are_digest_pinned, whose digest pin for unsloth_zoo/compiler.py no longer matches what the job installs from unsloth-zoo main. Both checks are red on every other open PR right now (#10220, #10222, #10224, #10225), and nothing here touches the scanner, its pins, or unsloth_zoo. Aside from that pin, Repo tests (CPU) is 15825 passed, 365 skipped.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 083d5eaee0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 25deee0caa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed the load call in unsloth_cli/commands/export.py drops the token even though ExportBackend.load_checkpoint accepts it, so a gated checkpoint 401s despite --hf-token being passed. Will get this reviewed.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-03T15:33:04.236765Z 97acd6d New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@unslothai unslothai deleted a comment from NilayYadav Sep 3, 2026
@unslothai unslothai deleted a comment from NilayYadav Sep 3, 2026
@unslothai unslothai deleted a comment from NilayYadav Sep 3, 2026
@oobabooga

Copy link
Copy Markdown
Member

I reproduced the 401 against a real gated repo with --hf-token supplied, and confirmed the export runs to completion with this change, writing the adapter, tokenizer and chat template. With no token passed the request behavior is byte for byte unchanged, and an empty HF_TOKEN behaves the same as no token, so existing flows are unaffected.

One consequence worth recording here: now that the token reaches transformers tier resolution, a gated model whose config asks for a specific version can provision a sidecar venv during a CLI export, which is what the Studio export route has always done for the same model, and the pre-existing case where that install cannot be fetched is a separate issue from this fix.

I also confirmed that tests/test_cli_export_unpacking.py could not run standalone or under sharding before this change, on Linux, macOS and Windows alike, and passes in both modes now.

@oobabooga
oobabooga merged commit ec77cf6 into unslothai:main Sep 3, 2026
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants