Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

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

Nilayec77cf62b3e2
diff --git a/tests/test_cli_export_unpacking.py b/tests/test_cli_export_unpacking.py
index f0d60c2c14f..aa89efb29e9 100644
--- a/tests/test_cli_export_unpacking.py
+++ b/tests/test_cli_export_unpacking.py
@@ -5,6 +5,7 @@
from __future__ import annotations
+import importlib
import sys
import types
from pathlib import Path
@@ -18,11 +19,13 @@ class _FakeExportBackend:
"""Stand-in for ExportBackend: export_* return the 3-tuple, load_checkpoint stays a 2-tuple."""
last_call: dict = {}
+ last_load: dict = {}
def __init__(self) -> None:
self.loaded: str | None = None
def load_checkpoint(self, **kwargs):
+ _FakeExportBackend.last_load = dict(kwargs)
self.loaded = kwargs.get("checkpoint_path")
return True, f"Loaded {self.loaded}"
@@ -48,6 +51,10 @@ class _FakeExportBackend:
def _install_fake_studio_backend(monkeypatch: pytest.MonkeyPatch) -> None:
"""Inject a fake studio.backend.core.export into sys.modules so the CLI's lazy import binds to it; parent packages stubbed to skip the structlog-dependent tree."""
+ # Load the real CLI first: unsloth_cli/__init__.py reaches studio.backend.utils through
+ # commands/start.py, and the stubs below shadow it, so whichever test ran first errored.
+ importlib.import_module("unsloth_cli.commands.export")
+
for name in ("studio", "studio.backend", "studio.backend.core"):
monkeypatch.setitem(sys.modules, name, types.ModuleType(name))
@@ -63,6 +70,7 @@ def _install_fake_studio_backend(monkeypatch: pytest.MonkeyPatch) -> None:
def cli_app(monkeypatch: pytest.MonkeyPatch) -> typer.Typer:
"""Typer app wrapping unsloth_cli.commands.export.export."""
_FakeExportBackend.last_call = {}
+ _FakeExportBackend.last_load = {}
_install_fake_studio_backend(monkeypatch)
from unsloth_cli.commands import export as export_cmd
@@ -161,3 +169,20 @@ def test_cli_export_forwards_private_flag(
assert result.exit_code == 0, f"CLI error:\n{result.output}"
assert _FakeExportBackend.last_call.get("method") == expected_method
assert _FakeExportBackend.last_call.get("kwargs", {}).get("private") is True
+
+
+def test_cli_export_forwards_hf_token_to_checkpoint_load(
+ cli_app: typer.Typer, runner: CliRunner, tmp_path: Path
+) -> None:
+ """--hf-token reaches load_checkpoint, not just the Hub push."""
+ ckpt = tmp_path / "ckpt"
+ ckpt.mkdir()
+ out = tmp_path / "out"
+
+ result = runner.invoke(
+ cli_app,
+ ["export", str(ckpt), str(out), "--hf-token", "hf_cli_token"],
+ )
+
+ assert result.exit_code == 0, f"CLI error:\n{result.output}"
+ assert _FakeExportBackend.last_load.get("hf_token") == "hf_cli_token"
diff --git a/unsloth_cli/commands/export.py b/unsloth_cli/commands/export.py
index 10e2580b79e..938389d926d 100644
--- a/unsloth_cli/commands/export.py
+++ b/unsloth_cli/commands/export.py
@@ -57,7 +57,10 @@ def export(
None, "--repo-id", help = "HuggingFace repo ID (username/model-name)."
),
hf_token: Optional[str] = typer.Option(
- None, "--hf-token", envvar = "HF_TOKEN", help = "HuggingFace token."
+ None,
+ "--hf-token",
+ envvar = "HF_TOKEN",
+ help = "HuggingFace token, for gated or private checkpoints and Hub pushes.",
),
private: bool = typer.Option(False, "--private", help = "Make the HuggingFace repo private."),
max_seq_length: int = typer.Option(2048, "--max-seq-length"),
@@ -85,6 +88,7 @@ def export(
checkpoint_path = str(checkpoint),
max_seq_length = max_seq_length,
load_in_4bit = load_in_4bit,
+ hf_token = hf_token,
)
if not success:
typer.echo(f"Error: {message}", err = True)